Skip to content

Commit 945eeb5

Browse files
Move self-contained channel construction into PIPELINE_INITIALISATION
Part of #1029: params used only to build a channel, with no other logic depending on how that channel is constructed, should be built once in PIPELINE_INITIALISATION and threaded down as explicit arguments rather than workflows/ampliseq.nf reaching into global params directly. Moves 9 such channels (metadata, report_template/css/logo/abstract, pplace_sheet's initial value, expected_sequences/abundances, metadata_category) through PIPELINE_INITIALISATION -> NFCORE_AMPLISEQ -> AMPLISEQ via take:/emit:. Behavior is unchanged; this is a pure plumbing refactor covered by the existing nf-test snapshot suite. Adds a second test case to tests/default.nf.test for --report_abstract and --metadata_category, the two params among these that weren't exercised by any existing test profile. Deliberately out of scope (left for follow-up): the ~90 remaining scalar params.X reads in workflows/ampliseq.nf, the 6 per-classifier reference-taxonomy channels (entangled with catalog-download logic), and params.X reaches inside subworkflows/local and modules/local.
1 parent 7b7658e commit 945eeb5

4 files changed

Lines changed: 128 additions & 37 deletions

File tree

main.nf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ include { PIPELINE_COMPLETION } from './subworkflows/local/utils_nfcore_ampl
3030
//
3131
workflow NFCORE_AMPLISEQ {
3232

33+
take:
34+
ch_metadata // channel: [ path(metadata) ] or empty
35+
ch_report_template // channel: [ path(report_template) ]
36+
ch_report_css // channel: [ path(report_css) ]
37+
ch_report_logo // channel: [ path(report_logo) ]
38+
ch_report_abstract // channel: [ path(report_abstract) ] or []
39+
ch_pplace_sheet // channel: parsed pplace_sheet rows, or empty
40+
ch_expected_sequences // channel: [ path(expected_sequences) ] or empty
41+
ch_expected_abundances // channel: [ path(expected_abundances) ] or empty
42+
ch_metadata_category // channel: tokenized metadata_category, or empty
43+
3344
main:
3445

3546
//
@@ -41,6 +52,15 @@ workflow NFCORE_AMPLISEQ {
4152
params.multiqc_logo,
4253
params.multiqc_methods_description,
4354
params.outdir,
55+
ch_metadata,
56+
ch_report_template,
57+
ch_report_css,
58+
ch_report_logo,
59+
ch_report_abstract,
60+
ch_pplace_sheet,
61+
ch_expected_sequences,
62+
ch_expected_abundances,
63+
ch_metadata_category,
4464
)
4565
emit:
4666
multiqc_report = AMPLISEQ.out.multiqc_report // channel: /path/to/multiqc_report.html
@@ -251,7 +271,17 @@ workflow {
251271
//
252272
// WORKFLOW: Run main workflow
253273
//
254-
NFCORE_AMPLISEQ ()
274+
NFCORE_AMPLISEQ (
275+
PIPELINE_INITIALISATION.out.metadata,
276+
PIPELINE_INITIALISATION.out.report_template,
277+
PIPELINE_INITIALISATION.out.report_css,
278+
PIPELINE_INITIALISATION.out.report_logo,
279+
PIPELINE_INITIALISATION.out.report_abstract,
280+
PIPELINE_INITIALISATION.out.pplace_sheet,
281+
PIPELINE_INITIALISATION.out.expected_sequences,
282+
PIPELINE_INITIALISATION.out.expected_abundances,
283+
PIPELINE_INITIALISATION.out.metadata_category,
284+
)
255285

256286
//
257287
// SUBWORKFLOW: Run completion tasks

subworkflows/local/utils_nfcore_ampliseq_pipeline/main.nf

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,52 @@ workflow PIPELINE_INITIALISATION {
4040

4141
ch_versions = channel.empty()
4242

43+
//
44+
// Build channels from self-contained parameters
45+
// (params only used to construct these channels; no other logic depends on how they're built)
46+
//
47+
if (params.metadata) {
48+
ch_metadata = channel.fromPath( params.metadata )
49+
} else { ch_metadata = channel.empty() }
50+
51+
// report sources
52+
ch_report_template = channel.fromPath("${params.report_template}", checkIfExists: true)
53+
ch_report_css = channel.fromPath("${params.report_css}", checkIfExists: true)
54+
ch_report_logo = channel.fromPath("${params.report_logo}", checkIfExists: true)
55+
ch_report_abstract = params.report_abstract ? channel.fromPath(params.report_abstract) : []
56+
57+
// Parse the --pplace_sheet file if present (may be overwritten later in AMPLISEQ based on --dada_ref_taxonomy)
58+
ch_pplace_sheet = channel.empty()
59+
if ( params.pplace_sheet ) {
60+
ch_pplace_sheet = channel.fromPath(params.pplace_sheet)
61+
.splitCsv(header: true)
62+
.map { it ->
63+
[
64+
meta: [
65+
id: it.target,
66+
min_bitscore: it.min_bitscore
67+
],
68+
data: [
69+
alignmethod: it.alignmethod ?: 'clustalo',
70+
hmm: file(it.hmm, checkIfExists: true),
71+
extract_hmm: it.extract_hmm,
72+
refseqfile: it.refseqfile ? file(it.refseqfile, checkIfExists: true) : [],
73+
refphylogeny: it.refphylogeny ? file(it.refphylogeny, checkIfExists: true) : [],
74+
model: it.model,
75+
taxonomy: it.taxonomy ? file(it.taxonomy, checkIfExists: true) : []
76+
]
77+
]
78+
}
79+
}
80+
81+
ch_expected_sequences = params.expected_sequences ? channel.fromPath( params.expected_sequences ) : channel.empty()
82+
ch_expected_abundances = params.expected_abundances ? channel.fromPath( params.expected_abundances ) : channel.empty()
83+
84+
// Select metadata categories for diversity analysis & ancom, if explicitly specified
85+
if (params.metadata_category) {
86+
ch_metadata_category = channel.fromList(params.metadata_category.tokenize(','))
87+
} else { ch_metadata_category = channel.empty() }
88+
4389
//
4490
// Print version and exit if required and dump pipeline parameters to JSON file
4591
//
@@ -124,7 +170,16 @@ workflow PIPELINE_INITIALISATION {
124170
}
125171

126172
emit:
127-
versions = ch_versions
173+
versions = ch_versions
174+
metadata = ch_metadata // channel: [ path(metadata) ] or empty
175+
report_template = ch_report_template // channel: [ path(report_template) ]
176+
report_css = ch_report_css // channel: [ path(report_css) ]
177+
report_logo = ch_report_logo // channel: [ path(report_logo) ]
178+
report_abstract = ch_report_abstract // channel: [ path(report_abstract) ] or []
179+
pplace_sheet = ch_pplace_sheet // channel: parsed pplace_sheet rows, or empty
180+
expected_sequences = ch_expected_sequences // channel: [ path(expected_sequences) ] or empty
181+
expected_abundances = ch_expected_abundances // channel: [ path(expected_abundances) ] or empty
182+
metadata_category = ch_metadata_category // channel: tokenized metadata_category, or empty
128183
}
129184

130185
/*

tests/default.nf.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,31 @@ nextflow_pipeline {
6363
)
6464
}
6565
}
66+
67+
test("-profile test, --report_abstract, --metadata_category") {
68+
// Covers 2 params whose channel construction (in PIPELINE_INITIALISATION) isn't
69+
// exercised by any other test profile: --report_abstract and --metadata_category.
70+
// By default (no --metadata_category), all suitable metadata columns are auto-detected
71+
// for diversity/ancom (e.g. both "treatment1" and "mix8" beta-diversity dirs, see
72+
// tests/default.nf.test.snap); restricting to "treatment1" here should exclude "mix8".
73+
// (Note: alpha-rarefaction plots every metadata column regardless of --metadata_category,
74+
// since QIIME2 reads the metadata file directly there, so it isn't a useful signal.)
75+
76+
when {
77+
params {
78+
outdir = "$outputDir"
79+
report_abstract = "$projectDir/tower.yml"
80+
metadata_category = "treatment1"
81+
}
82+
}
83+
84+
then {
85+
assert workflow.success
86+
assertAll(
87+
{ assert path("$outputDir/summary_report/summary_report.html").text.contains("MultiQC HTML report") },
88+
{ assert path("$outputDir/qiime2/diversity/beta_diversity/bray_curtis_distance_matrix-treatment1/index.html").exists() },
89+
{ assert !file("$outputDir/qiime2/diversity/beta_diversity/bray_curtis_distance_matrix-mix8").exists() },
90+
)
91+
}
92+
}
6693
}

workflows/ampliseq.nf

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ workflow AMPLISEQ {
124124
multiqc_logo
125125
multiqc_methods_description
126126
outdir
127+
ch_metadata // channel: [ path(metadata) ] or empty
128+
ch_report_template // channel: [ path(report_template) ]
129+
ch_report_css // channel: [ path(report_css) ]
130+
ch_report_logo // channel: [ path(report_logo) ]
131+
ch_report_abstract // channel: [ path(report_abstract) ] or []
132+
ch_pplace_sheet // channel: parsed pplace_sheet rows, or empty (may be overwritten below based on --dada_ref_taxonomy)
133+
ch_expected_sequences // channel: [ path(expected_sequences) ] or empty
134+
ch_expected_abundances // channel: [ path(expected_abundances) ] or empty
135+
ch_metadata_category // channel: tokenized metadata_category, or empty
127136

128137
main:
129138
// set empty channels
@@ -134,15 +143,6 @@ workflow AMPLISEQ {
134143
//
135144
// INPUT AND VARIABLES
136145
//
137-
if (params.metadata) {
138-
ch_metadata = channel.fromPath( params.metadata )
139-
} else { ch_metadata = channel.empty() }
140-
141-
// report sources
142-
ch_report_template = channel.fromPath("${params.report_template}", checkIfExists: true)
143-
ch_report_css = channel.fromPath("${params.report_css}", checkIfExists: true)
144-
ch_report_logo = channel.fromPath("${params.report_logo}", checkIfExists: true)
145-
ch_report_abstract = params.report_abstract ? channel.fromPath(params.report_abstract) : []
146146

147147
// Set non-params Variables
148148

@@ -203,29 +203,8 @@ workflow AMPLISEQ {
203203
error("One of `--input`, `--input_fasta`, `--input_folder` must be provided!")
204204
}
205205

206-
// Parse the --pplace_sheet file if present
207-
ch_pplace_sheet = channel.empty()
208-
if ( params.pplace_sheet ) {
209-
ch_pplace_sheet = channel.fromPath(params.pplace_sheet)
210-
.splitCsv(header: true)
211-
.map { it ->
212-
[
213-
meta: [
214-
id: it.target,
215-
min_bitscore: it.min_bitscore
216-
],
217-
data: [
218-
alignmethod: it.alignmethod ?: 'clustalo',
219-
hmm: file(it.hmm, checkIfExists: true),
220-
extract_hmm: it.extract_hmm,
221-
refseqfile: it.refseqfile ? file(it.refseqfile, checkIfExists: true) : [],
222-
refphylogeny: it.refphylogeny ? file(it.refphylogeny, checkIfExists: true) : [],
223-
model: it.model,
224-
taxonomy: it.taxonomy ? file(it.taxonomy, checkIfExists: true) : []
225-
]
226-
]
227-
}
228-
}
206+
// ch_pplace_sheet: initial value built in PIPELINE_INITIALISATION from --pplace_sheet;
207+
// may be overwritten below based on --dada_ref_taxonomy database config (the "pplace" key)
229208

230209
//
231210
// Add primer info to sequencing files
@@ -1113,7 +1092,7 @@ workflow AMPLISEQ {
11131092

11141093
//Select metadata categories for diversity analysis & ancom
11151094
if (params.metadata_category) {
1116-
ch_metacolumn_all = channel.fromList(params.metadata_category.tokenize(','))
1095+
ch_metacolumn_all = ch_metadata_category
11171096
ch_metacolumn_pairwise = METADATA_PAIRWISE ( ch_metadata ).category.splitCsv().flatten()
11181097
ch_metacolumn_pairwise = ch_metacolumn_all.join(ch_metacolumn_pairwise)
11191098
} else if (params.ancom || params.ancombc || params.ancombc2 || !params.skip_diversity_indices) {
@@ -1221,8 +1200,8 @@ workflow AMPLISEQ {
12211200
params.expected_sequences_region,
12221201
run_qiime2 && !params.skip_abundance_tables ? QIIME2_EXPORT.out.abs_fasta : ch_asv_fasta, // observed sequences (fasta)
12231202
run_qiime2 && !params.skip_abundance_tables ? QIIME2_EXPORT.out.rel_tsv : ch_asv_table, // observed sequences (abundance table)
1224-
params.expected_sequences ? channel.fromPath( params.expected_sequences ) : channel.empty(), // expected sequences (fasta)
1225-
params.expected_abundances ? channel.fromPath( params.expected_abundances ) : channel.empty() // expected sequences (abundance table)
1203+
ch_expected_sequences, // expected sequences (fasta)
1204+
ch_expected_abundances // expected sequences (abundance table)
12261205
)
12271206
}
12281207

0 commit comments

Comments
 (0)