Skip to content

Commit

Permalink
Fix tests; add version channels; remove params access in subworkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlang committed Nov 15, 2024
1 parent 6d0d3b8 commit 846ca55
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
9 changes: 6 additions & 3 deletions subworkflows/local/correlation/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ workflow CORRELATION {
main:

// initialize empty results channels
ch_matrix = Channel.empty()
ch_matrix = Channel.empty()
ch_adjacency = Channel.empty()
ch_versions = Channel.empty()

// branch tools to select the correct correlation analysis method
ch_counts
Expand All @@ -26,10 +27,12 @@ workflow CORRELATION {
PROPR(ch_counts.propr.unique())
ch_matrix = PROPR.out.matrix.mix(ch_matrix)
ch_adjacency = PROPR.out.adjacency.mix(ch_adjacency)
ch_versions = ch_versions.mix(PROPR.out.versions)

// TODO: divide propr module into cor, propr, pcor, pcorbshrink, etc.

emit:
matrix = ch_matrix
adjacency = ch_adjacency
matrix = ch_matrix // channel: [ csv ]
adjacency = ch_adjacency // channel: [ csv ]
versions = ch_versions // channel: [ versions.yml ]
}
46 changes: 24 additions & 22 deletions subworkflows/local/differential/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ workflow DIFFERENTIAL {
ch_counts // [ meta_exp, counts ] with meta keys: method, args_diff
ch_samplesheet // [ meta_exp, samplesheet ]
ch_contrasts // [ meta_contrast, contrast_variable, reference, target ]
ch_transcript_lengths
ch_control_features

main:

Expand All @@ -22,6 +24,7 @@ workflow DIFFERENTIAL {
ch_results_genewise = Channel.empty()
ch_results_genewise_filtered = Channel.empty()
ch_adjacency = Channel.empty()
ch_versions = Channel.empty()

// branch tools to select the correct differential analysis method
ch_counts
Expand Down Expand Up @@ -56,28 +59,25 @@ workflow DIFFERENTIAL {
ch_results_genewise = PROPD.out.connectivity.mix(ch_results_genewise)
ch_results_genewise_filtered = PROPD.out.hub_genes.mix(ch_results_genewise_filtered)
ch_adjacency = PROPD.out.adjacency.mix(ch_adjacency)
ch_versions = PROPD.out.versions.mix(ch_versions)

// ----------------------------------------------------
// Perform differential analysis with DESeq2
// ----------------------------------------------------

if (params.transcript_length_matrix) { ch_transcript_lengths = Channel.of([ exp_meta, file(params.transcript_length_matrix, checkIfExists: true)]).first() } else { ch_transcript_lengths = Channel.of([[],[]]) }
if (params.control_features) { ch_control_features = Channel.of([ exp_meta, file(params.control_features, checkIfExists: true)]).first() } else { ch_control_features = Channel.of([[],[]]) }

ch_counts
.join(ch_samplesheet)
ch_counts.deseq2
.combine(ch_samplesheet)
.filter{ meta_counts, counts, meta_samplesheet, samplesheet -> meta_counts.subMap(meta_samplesheet.keySet()) == meta_samplesheet }
.combine(ch_contrasts)
.combine(ch_transcript_lengths)
.combine(ch_control_features)
.combine(ch_tools_single.deseq2)
.multiMap {
meta_data, counts, samplesheet, meta_contrast, contrast_variable, reference, target, meta_lengths, lengths, meta_control, control, pathway, meta_tools ->
def meta = meta_data.clone() + meta_contrast.clone() + meta_lengths.clone() + meta_control.clone() + meta_tools.clone()
meta_data, counts, meta_samplesheet, samplesheet, meta_contrast, contrast_variable, reference, target, meta_lengths, lengths, meta_control, control ->
def meta = meta_data.clone() + meta_contrast.clone() + meta_lengths.clone() + meta_control.clone()
contrast: [ meta, contrast_variable, reference, target ]
samples_and_matrix: [ meta, samplesheet, counts ]
control_features: [ meta, control ]
transcript_lengths: [ meta, lengths ]
pathway: [ meta, pathway ]
}
.set { ch_deseq2 }

Expand All @@ -96,9 +96,10 @@ workflow DIFFERENTIAL {
ch_deseq2.transcript_lengths
)

ch_norm_deseq2 = DESEQ2_NORM.out.normalised_counts
ch_norm_deseq2 = DESEQ2_NORM.out.normalised_counts
ch_differential_deseq2 = DESEQ2_DIFFERENTIAL.out.results
ch_model_deseq2 = DESEQ2_DIFFERENTIAL.out.model
ch_model_deseq2 = DESEQ2_DIFFERENTIAL.out.model
ch_versions = DESEQ2_DIFFERENTIAL.out.versions.mix(ch_versions)

ch_processed_matrices = ch_norm_deseq2
if ('rlog' in params.deseq2_vs_method){
Expand All @@ -120,11 +121,9 @@ workflow DIFFERENTIAL {
ch_padj_deseq2
)

ch_results_genewise = DESEQ2_DIFFERENTIAL.out.results
.join(ch_deseq2.pathway).map(correct_meta_data).mix(ch_results_genewise)

ch_results_genewise_filtered = FILTER_DIFFTABLE_DESEQ2.out.filtered
.join(ch_deseq2.pathway).map(correct_meta_data).mix(ch_results_genewise_filtered)
ch_results_genewise = DESEQ2_DIFFERENTIAL.out.results.mix(ch_results_genewise)
ch_results_genewise_filtered = FILTER_DIFFTABLE_DESEQ2.out.filtered.mix(ch_results_genewise_filtered)
ch_versions = FILTER_DIFFTABLE_DESEQ2.out.versions.mix(ch_versions)

// ----------------------------------------------------
// Perform differential analysis with limma
Expand All @@ -148,6 +147,7 @@ workflow DIFFERENTIAL {

// run limma
LIMMA_DIFFERENTIAL(ch_limma.input1, ch_limma.input2)
ch_versions = LIMMA_DIFFERENTIAL.out.versions.mix(ch_versions)

// filter results
// note that these are column names specific for limma output table
Expand All @@ -161,13 +161,15 @@ workflow DIFFERENTIAL {
)

// collect results
ch_results_genewise = LIMMA_DIFFERENTIAL.out.results.mix(ch_results_genewise)
ch_results_genewise = LIMMA_DIFFERENTIAL.out.results.mix(ch_results_genewise)
ch_results_genewise_filtered = FILTER_DIFFTABLE_LIMMA.out.filtered.mix(ch_results_genewise_filtered)
ch_versions = FILTER_DIFFTABLE_LIMMA.out.versions.mix(ch_versions)

emit:
results_pairwise = ch_results_pairwise
results_pairwise_filtered = ch_results_pairwise_filtered
results_genewise = ch_results_genewise
results_genewise_filtered = ch_results_genewise_filtered
adjacency = ch_adjacency
results_pairwise = ch_results_pairwise // channel: [ tsv ]
results_pairwise_filtered = ch_results_pairwise_filtered // channel: [ tsv ]
results_genewise = ch_results_genewise // channel: [ tsv ]
results_genewise_filtered = ch_results_genewise_filtered // channel: [ tsv ]
adjacency = ch_adjacency // channel: [ tsv ]
versions = ch_versions // channel: [ versions.yml ]
}
9 changes: 7 additions & 2 deletions subworkflows/local/enrichment/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workflow ENRICHMENT {
// initialize empty results channels
ch_enriched = Channel.empty()
ch_gmt = Channel.empty()
ch_versions = Channel.empty()

ch_adjacency
.branch {
Expand All @@ -32,14 +33,16 @@ workflow ENRICHMENT {
// TODO this should be optional, only run when there is no gene set data provided by user

MYGENE(ch_counts.take(1)) // only one data is provided to this pipeline
ch_gmt = MYGENE.out.gmt
ch_gmt = MYGENE.out.gmt
ch_versions = ch_versions.mix(MYGENE.out.versions)

// ----------------------------------------------------
// Perform enrichment analysis with GREA
// ----------------------------------------------------

GREA(ch_adjacency.grea.unique(), ch_gmt.collect())
ch_enriched = ch_enriched.mix(GREA.out.results)
ch_versions = ch_versions.mix(GREA.out.versions)

// ----------------------------------------------------
// Perform enrichment analysis with GSEA
Expand Down Expand Up @@ -74,7 +77,9 @@ workflow ENRICHMENT {
.set { ch_results_genewise_filtered }

GPROFILER2_GOST(ch_results_genewise_filtered, ch_gmt, ch_background)
ch_versions = ch_versions.mix(GPROFILER2_GOST.out.versions)

emit:
enriched = ch_enriched
enriched = ch_enriched // channel: [ tsv ]
versions = ch_versions // channel: [ versions.yml ]
}
13 changes: 10 additions & 3 deletions subworkflows/local/experimental/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ workflow EXPERIMENTAL {
ch_samplesheet // [ meta, samplesheet ]
ch_counts // [ meta, counts]
ch_tools // [ pathway_name, differential_map, correlation_map, enrichment_map ]
ch_transcript_lengths
ch_control_features

main:

Expand All @@ -54,8 +56,8 @@ workflow EXPERIMENTAL {
ch_results_genewise = Channel.empty() // differential results for genewise analysis - it should be a table
ch_results_genewise_filtered = Channel.empty() // differential results for genewise analysis - filtered - it should be a table
ch_adjacency = Channel.empty() // adjacency matrix showing the connections between the genes, with values 1|0
ch_matrix = Channel.empty() // correlation matrix
ch_enriched = Channel.empty() // output table from enrichment analysis
ch_matrix = Channel.empty() // correlation matrix
ch_enriched = Channel.empty() // output table from enrichment analysis

// ----------------------------------------------------
// DIFFERENTIAL ANALYSIS BLOCK
Expand All @@ -66,7 +68,9 @@ workflow EXPERIMENTAL {
DIFFERENTIAL(
ch_counts_diff,
ch_samplesheet,
ch_contrasts
ch_contrasts,
ch_transcript_lengths,
ch_control_features
)
ch_results_pairwise = postprocess_subworkflow_output(DIFFERENTIAL.out.results_pairwise,["method", "args_diff"]).mix(ch_results_pairwise)
ch_results_pairwise_filtered = postprocess_subworkflow_output(DIFFERENTIAL.out.results_pairwise_filtered,["method", "args_diff"]).mix(ch_results_pairwise_filtered)
Expand Down Expand Up @@ -113,4 +117,7 @@ workflow EXPERIMENTAL {
// ----------------------------------------------------

// TODO: call visualization stuff here

emit:
versions = ch_versions
}
4 changes: 3 additions & 1 deletion workflows/differentialabundance.nf
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ workflow DIFFERENTIALABUNDANCE {
ch_contrasts,
VALIDATOR.out.sample_meta,
CUSTOM_MATRIXFILTER.out.filtered,
ch_tools
ch_tools,
ch_transcript_lengths,
ch_control_features
)

// TODO for the moment, these channels are allocated to not breaking the next part.
Expand Down

0 comments on commit 846ca55

Please sign in to comment.