Skip to content

Commit 3368920

Browse files
committed
Add truncq parameter to support DADA2 quality score-based read truncation
1 parent 0e7289d commit 3368920

7 files changed

Lines changed: 22 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
## nf-core/ampliseq version 2.15.0dev
77

88
### `Added`
9+
- [#909](https://github.com/nf-core/ampliseq/pull/909) - Parameter `--truncq` allows read truncation by quality score, where each read is truncated at the first instance of a quality score less than or equal to `truncq` (default value is 2). This quality score-based truncation occurs before read length truncation. If `--trunc_qmin` and `--trunc_rmin` are used to automatically calculate the values for `trunclenf` and `trunclenr` used for read length truncation, those calculations are based on the read metrics before quality score-based truncation (using `truncq`) is performed. `truncq` is passed directly as `truncQ` into DADA2's [filterAndTrim](https://rdrr.io/bioc/dada2/man/filterAndTrim.html) method.
910

1011
### `Changed`
1112

assets/report_template.Rmd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ params:
3030
barplot: FALSE
3131
abundance_tables: FALSE
3232
alpha_rarefaction: FALSE
33+
truncq: ""
3334
trunclenf: ""
3435
trunclenr: ""
3536
max_ee: ""
@@ -299,6 +300,9 @@ Additional quality filtering can improve sequence recovery.
299300
Often it is advised trimming the last few nucleotides to avoid less well-controlled errors that can arise there.
300301
"))
301302
303+
if (params$truncq) {
304+
cat("Each read was truncated at the first instance of a quality score less than or equal to ", params$truncq, ". ", sep = "")
305+
}
302306
if (params$trunc_qmin) {
303307
f_and_tr_args <- readLines(params$dada_filtntrim_args)
304308
trunc_len <- strsplit(gsub(".*truncLen = c\\((.+)\\),maxN.*", "\\1",
@@ -313,7 +317,7 @@ if (params$trunc_qmin) {
313317
"forward reads at ", tr_len_f, " bp and reverse ",
314318
"reads at ", tr_len_r, " bp, reads shorter than this were discarded. ", sep = "")
315319
} else if (params$trunclenf == "null" && params$trunclenr == "null") {
316-
cat("Reads were not trimmed. ")
320+
cat("Reads were not trimmed to a specific length. ")
317321
} else if (params$trunclenf != 0 && params$trunclenr != 0) {
318322
cat("Forward reads were trimmed at ", params$trunclenf,
319323
" bp and reverse reads were trimmed at ", params$trunclenr,
@@ -1700,6 +1704,9 @@ if ( params$dada_sample_inference == "independent" ) {
17001704
17011705
cat("with DADA2 ([Callahan et al., 2016](https://pubmed.ncbi.nlm.nih.gov/27214047/)) to eliminate PhiX contamination, ")
17021706
1707+
if (params$truncq) {
1708+
cat("truncate reads at the first instance of a quality score less than or equal to ", params$truncq, ", ", sep = "")
1709+
}
17031710
if (params$trunc_qmin) {
17041711
cat("trim reads (before median quality drops below ", params$trunc_qmin,
17051712
" and at least ",params$trunc_rmin*100, "% of reads are retained; ",

conf/modules.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ process {
139139
max_len = params.max_len ?: "Inf"
140140
withName: DADA2_FILTNTRIM {
141141
ext.args = [
142-
'maxN = 0, truncQ = 2, trimRight = 0, minQ = 0, rm.lowcomplex = 0, orient.fwd = NULL, matchIDs = FALSE, id.sep = "\\\\s", id.field = NULL, n = 1e+05, OMP = TRUE',
142+
'maxN = 0, trimRight = 0, minQ = 0, rm.lowcomplex = 0, orient.fwd = NULL, matchIDs = FALSE, id.sep = "\\\\s", id.field = NULL, n = 1e+05, OMP = TRUE',
143143
"qualityType = \"${params.quality_type}\"",
144+
"truncQ = ${params.truncq}",
144145
params.pacbio || params.iontorrent || params.single_end ? "maxEE = ${params.max_ee}" : "maxEE = c(${params.max_ee}, ${params.max_ee})",
145146
params.pacbio ? "trimLeft = 0, minLen = ${params.min_len}, maxLen = $max_len, rm.phix = FALSE" :
146147
params.iontorrent ? "trimLeft = 15, minLen = ${params.min_len}, maxLen = $max_len, rm.phix = TRUE" :

modules/local/summary_report.nf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ process SUMMARY_REPORT {
8686
cutadapt_summary ?
8787
params.retain_untrimmed ? "flag_retain_untrimmed=TRUE,cutadapt_summary='$cutadapt_summary'" :
8888
"cutadapt_summary='$cutadapt_summary'" : "",
89+
"truncq=$params.truncq",
8990
find_truncation_values ? "trunc_qmin=$params.trunc_qmin,trunc_rmin=$params.trunc_rmin" : "",
9091
"trunclenf='$params.trunclenf'",
9192
"trunclenr='$params.trunclenr'",

nextflow.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ params {
2929
trunc_rmin = 0.75
3030
trunclenf = null
3131
trunclenr = null
32+
truncq = 2
3233
max_ee = 2
3334
max_len = null
3435
ignore_failed_filtering = false

nextflow_schema.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@
203203
"description": "Read trimming and quality filtering is supposed to reduce spurious results and aid error correction",
204204
"default": "",
205205
"properties": {
206+
"truncq": {
207+
"type": "integer",
208+
"default": 2,
209+
"fa_icon": "fas fa-greater-than-equal",
210+
"minimum": 0,
211+
"description": "Truncate each read at the first instance of a quality score less than or equal to truncq. Applied before read length truncation."
212+
},
206213
"trunclenf": {
207214
"type": "integer",
208215
"description": "DADA2 read truncation value for forward strand, set this to 0 for no truncation",
@@ -219,7 +226,7 @@
219226
"type": "integer",
220227
"default": 25,
221228
"description": "If --trunclenf and --trunclenr are not set, these values will be automatically determined using this median quality score",
222-
"help_text": "Automatically determine `--trunclenf` and `--trunclenr` before the median quality score drops below `--trunc_qmin`. The fraction of reads retained is defined by `--trunc_rmin`, which might override the quality cutoff.\n\nFor example:\n\n```bash\n--trunc_qmin 35\n```\n\nPlease note:\n\n1. The code choosing `--trunclenf` and `--trunclenr` using `--trunc_qmin` automatically cannot take amplicon length or overlap requirements for merging into account, therefore use with caution.\n2. A minimum value of 25 is recommended. However, high quality data with a large paired sequence overlap might justify a higher value (e.g. 35). Also, very low quality data might require a lower value.\n3. If the quality cutoff is too low to include a certain fraction of reads that is specified by `--trunc_rmin` (e.g. 0.75 means at least 75% percent of reads are retained), a lower cutoff according to `--trunc_rmin` superseeds the quality cutoff.",
229+
"help_text": "Automatically determine `--trunclenf` and `--trunclenr` before the median quality score drops below `--trunc_qmin`. The fraction of reads retained is defined by `--trunc_rmin`, which might override the quality cutoff.\n\nFor example:\n\n```bash\n--trunc_qmin 35\n```\n\nPlease note:\n\n1. The code choosing `--trunclenf` and `--trunclenr` using `--trunc_qmin` automatically cannot take amplicon length or overlap requirements for merging into account, therefore use with caution.\n2. A minimum value of 25 is recommended. However, high quality data with a large paired sequence overlap might justify a higher value (e.g. 35). Also, very low quality data might require a lower value.\n3. If the quality cutoff is too low to include a certain fraction of reads that is specified by `--trunc_rmin` (e.g. 0.75 means at least 75% percent of reads are retained), a lower cutoff according to `--trunc_rmin` superseeds the quality cutoff.\n4. The calculations for the values of `--trunclenf` and `--trunclenr` are made before any quality score-based read truncation (using `--truncq`) is performed.",
223230
"fa_icon": "fas fa-greater-than-equal"
224231
},
225232
"trunc_rmin": {

workflows/ampliseq.nf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ workflow AMPLISEQ {
202202
trunclenr = params.trunclenr ?: 0
203203
if ( !single_end && !params.illumina_pe_its && (params.trunclenf == null || params.trunclenr == null) && !params.input_fasta ) {
204204
find_truncation_values = true
205-
log.warn "No DADA2 cutoffs were specified (`--trunclenf` & `--trunclenr`), therefore reads will be truncated where median quality drops below ${params.trunc_qmin} (defined by `--trunc_qmin`) but at least a fraction of ${params.trunc_rmin} (defined by `--trunc_rmin`) of the reads will be retained.\nThe chosen cutoffs do not account for required overlap for merging, therefore DADA2 might have poor merging efficiency or even fail.\n"
205+
log.warn "No DADA2 read truncation cutoffs were specified (`--trunclenf` & `--trunclenr`), therefore reads will be truncated where median quality drops below ${params.trunc_qmin} (defined by `--trunc_qmin`) but at least a fraction of ${params.trunc_rmin} (defined by `--trunc_rmin`) of the reads will be retained.\nThe chosen cutoffs do not account for required overlap for merging, therefore DADA2 might have poor merging efficiency or even fail.\nThe cutoffs are chosen before any quality score-based read truncation (using `--truncq`) is performed.\n"
206206
} else { find_truncation_values = false }
207207

208208
// save params to values to be able to overwrite it

0 commit comments

Comments
 (0)