Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split ch_tools into subworkflow relevant subchannels #308

Merged
merged 8 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions assets/schema_tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
},
"diff_method": {
"type": "string",
"errorMessage": "choose a differential analysis method (eg. deseq2, propd, limme, etc) or none",
"meta": ["diff_method"]
"errorMessage": "choose a differential analysis method (eg. deseq2, propd) or none",
"meta": ["diff_method"],
"enum": ["propd", "deseq2", "none"]
},
"args_diff": {
"type": "string",
Expand All @@ -22,7 +23,8 @@
"cor_method": {
"type": "string",
"meta": ["cor_method"],
"errorMessage": "choose a correlation method (eg. propr) or none"
"errorMessage": "choose a correlation method (eg. propr) or none",
"enum": ["propr", "none"]
},
"args_cor": {
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions assets/tools_samplesheet.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pcorbshrink,,,propr,--metric pcor.bshrink,,
propr,,,propr,--metric rho,,
cor,,,propr,--metric cor,,
propd_grea,propd,,,,grea,
deseq2,deseq2,,,,gsea,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deseq2 does not do anything yet here no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just a placeholder for how it would look like. And with your new additions it would become functional, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, with the new additions it would be good!

1 change: 0 additions & 1 deletion conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ process {
saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
]
}

withName: "MYGENE" {
ext.args = [
"--columname ${params.features_id_col}"
Expand Down
2 changes: 1 addition & 1 deletion conf/test_experimental.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ params {
input = 'https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/mus_musculus/rnaseq_expression/SRP254919.samplesheet.csv'
matrix = 'https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/mus_musculus/rnaseq_expression/SRP254919.salmon.merged.gene_counts.top1000cov.tsv'
contrasts = 'https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/mus_musculus/rnaseq_expression/SRP254919.contrasts.csv'
pathway = "propd,propd_grea,propr,cor"
pathway = "propd,propd_fdr,pcorbshrink,propr,cor,propd_grea"

//Features
features_metadata_cols = 'gene_id,gene_name'
Expand Down
19 changes: 13 additions & 6 deletions subworkflows/local/correlation/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
//
include {PROPR_PROPR as PROPR} from "../../../modules/local/propr/propr/main.nf"

def clean_meta = { meta, data ->
def meta_clone = meta.clone()
meta_clone.remove('cor_method')
meta_clone.remove('args_cor')
return [meta_clone, data]
}

workflow CORRELATION {
take:
ch_tools
ch_tools // [ pathway_name, correlation_map ]
ch_counts

main:
Expand All @@ -17,7 +24,7 @@ workflow CORRELATION {
// branch tools to select the correct correlation analysis method
ch_tools
.branch {
propr: it[0]["cor_method"] == "propr"
propr: it[1]["cor_method"] == "propr"
}
.set { ch_tools_single }

Expand All @@ -28,8 +35,8 @@ workflow CORRELATION {
ch_counts
.combine(ch_tools_single.propr)
.map {
metacounts, counts, metatools ->
[ metacounts+metatools, counts ]
metacounts, counts, pathway, metatools ->
[ metacounts+metatools+pathway, counts ]
}
.set { ch_counts_propr }

Expand All @@ -40,6 +47,6 @@ workflow CORRELATION {
// TODO: divide propr module into cor, propr, pcor, pcorbshrink, etc.

emit:
matrix = ch_matrix
adjacency = ch_adjacency
matrix = ch_matrix.map(clean_meta)
adjacency = ch_adjacency.map(clean_meta)
}
31 changes: 19 additions & 12 deletions subworkflows/local/differential/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
include { PROPR_PROPD as PROPD } from "../../../modules/local/propr/propd/main.nf"
include { DESEQ2_DIFFERENTIAL } from '../../../modules/nf-core/deseq2/differential/main'

def clean_meta = { meta, data ->
def meta_clone = meta.clone()
meta_clone.remove('diff_method')
meta_clone.remove('args_diff')
return [meta_clone, data]
}

workflow DIFFERENTIAL {
take:
ch_tools
ch_tools // [ pathway_name, differential_map ]
ch_counts
ch_samplesheet
ch_contrasts
ch_contrasts // [meta, contrast_variable, reference, target]

main:

Expand All @@ -23,8 +30,8 @@ workflow DIFFERENTIAL {
// branch tools to select the correct differential analysis method
ch_tools
.branch {
propd: it[0]["diff_method"] == "propd"
deseq2: it[0]["diff_method"] == "deseq2"
propd: it[1]["diff_method"] == "propd"
deseq2: it[1]["diff_method"] == "deseq2"
}
.set { ch_tools_single }

Expand All @@ -37,14 +44,14 @@ workflow DIFFERENTIAL {
.combine(ch_contrasts)
.combine(ch_tools_single.propd)
.map {
meta_data, counts, samplesheet, meta_contrast, contrast_variable, reference, target, meta_tools ->
def meta = meta_data.clone() + ['contrast': meta_contrast.id] + meta_tools.clone()
meta_data, counts, samplesheet, meta_contrast, contrast_variable, reference, target, pathway, meta_tools ->
def meta = meta_data.clone() + ['contrast': meta_contrast.id] + meta_tools.clone() + pathway
[ meta, counts, samplesheet, contrast_variable, reference, target ]
}
.unique()
.set { ch_propd }
PROPD(ch_propd)

PROPD(ch_propd)
ch_results_pairwise = ch_results_pairwise.mix(PROPD.out.results)
ch_results_pairwise_filtered = ch_results_pairwise_filtered.mix(PROPD.out.results_filtered)
ch_results_genewise = ch_results_genewise.mix(PROPD.out.connectivity)
Expand Down Expand Up @@ -75,9 +82,9 @@ workflow DIFFERENTIAL {
// .mix(DESEQ2_DIFFERENTIAL.out.results)

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.map(clean_meta)
results_pairwise_filtered = ch_results_pairwise_filtered.map(clean_meta)
results_genewise = ch_results_genewise.map(clean_meta)
results_genewise_filtered = ch_results_genewise_filtered.map(clean_meta)
adjacency = ch_adjacency.map(clean_meta)
}
17 changes: 14 additions & 3 deletions subworkflows/local/enrichment/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include { PROPR_GREA as GREA } from "../../../modules/local/propr/grea/main.nf"

workflow ENRICHMENT {
take:
ch_tools // [ pathway_name, enrichment_map ]
ch_counts
ch_results_genewise
ch_results_genewise_filtered
Expand All @@ -31,10 +32,20 @@ workflow ENRICHMENT {
// ----------------------------------------------------

ch_adjacency
.filter { it[0]["enr_method"] == "grea" }
.set { ch_adjacency_grea }
.map { meta, matrix -> [meta.subMap(["pathway_name"]), meta, matrix] }
.join(ch_tools, by: [0])
.map {
pathway_name, meta, matrix, meta_tools ->
def new_meta = meta.clone() + meta_tools.clone()
[ new_meta, matrix ]
}
.branch {
grea: it[0]["enr_method"] == "grea"
gsea: it[0]["enr_method"] == "gsea"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gsea dont use ch_adjacency as input.
So we can maybe just branch ch_tools into grea and gsea at the beginning, and use ch_tools.grea in the GREA section to combine it with ch_adjacency

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yes, that sounds good to me. But I'd would change it then when we include gsea.

}
.set { ch_adjacency }

GREA(ch_adjacency_grea, ch_gmt.collect())
GREA(ch_adjacency.grea, ch_gmt.collect())
ch_enriched = ch_enriched.mix(GREA.out.results)

// ----------------------------------------------------
Expand Down
25 changes: 17 additions & 8 deletions subworkflows/local/experimental/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ include { ENRICHMENT } from '../enrichment/main.nf'

workflow EXPERIMENTAL {
take:
ch_contrasts
ch_samplesheet
ch_counts
ch_tools
ch_contrasts // [ meta, contrast_variable, reference, target ]
ch_samplesheet // [ meta, samplesheet ]
ch_counts // [ meta, counts]
ch_tools // [ pathway_name, differential_map, correlation_map, enrichment_map ]

main:

// check tools
ch_tools.view()
// split toolsheet into channels
ch_tools
.multiMap{
pathway_name, differential_map, correlation_map, enrichment_map ->
diff: [ pathway_name, differential_map ]
corr: [ pathway_name, correlation_map ]
enr: [ pathway_name, enrichment_map ]
}
.set{ ch_tools }


// initialize empty results channels
ch_results_pairwise = Channel.empty() // differential results for pairwise analysis - it should be a table
Expand All @@ -31,7 +39,7 @@ workflow EXPERIMENTAL {
// ----------------------------------------------------

DIFFERENTIAL(
ch_tools,
ch_tools.diff,
ch_counts,
ch_samplesheet,
ch_contrasts
Expand All @@ -47,7 +55,7 @@ workflow EXPERIMENTAL {
// ----------------------------------------------------

CORRELATION(
ch_tools,
ch_tools.corr,
ch_counts
)
ch_matrix = ch_matrix.mix(CORRELATION.out.matrix)
Expand All @@ -58,6 +66,7 @@ workflow EXPERIMENTAL {
// ----------------------------------------------------

ENRICHMENT(
ch_tools.enr,
ch_counts,
ch_results_genewise,
ch_results_genewise_filtered,
Expand Down
10 changes: 9 additions & 1 deletion workflows/differentialabundance.nf
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,16 @@ workflow DIFFERENTIALABUNDANCE {
.first()
} else if (params.study_type == 'experimental') {

// Convert the samplesheet.csv in a channel with the proper format
// Convert the toolsheet.csv in a channel with the proper format
ch_tools = Channel.fromList(samplesheetToList(params.tools, './assets/schema_tools.json'))
.map {
it ->
def pathway_name = it[0].subMap(["pathway_name"])
def differential_map = it[0].subMap(["diff_method","args_diff"])
def correlation_map = it[0].subMap(["cor_method","args_cor"])
def enrichment_map = it[0].subMap(["enr_method","args_enr"])
[ pathway_name, differential_map, correlation_map, enrichment_map ]
}.unique()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super clean! I like it!


// Filter the tools to the pathway(s) of interest, or run everything if requested
if (params.pathway == "all") {
Expand Down
Loading