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 all 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
28 changes: 19 additions & 9 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 correct_meta_data = { meta, data, pathway ->
def meta_clone = meta.clone() + pathway
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 @@ -27,19 +34,22 @@ workflow CORRELATION {

ch_counts
.combine(ch_tools_single.propr)
.map {
metacounts, counts, metatools ->
[ metacounts+metatools, counts ]
.multiMap {
metacounts, counts, pathway, metatools ->
input: [ metacounts+metatools, counts ]
pathway: [ metacounts+metatools, pathway ]
}
.set { ch_counts_propr }

PROPR(ch_counts_propr)
ch_matrix = ch_matrix.mix(PROPR.out.matrix)
ch_adjacency = ch_adjacency.mix(PROPR.out.adjacency)
PROPR(ch_counts_propr.input.unique())
ch_matrix = PROPR.out.matrix
.join(ch_counts_propr.pathway).map(correct_meta_data).mix(ch_matrix)
ch_adjacency = PROPR.out.adjacency
.join(ch_counts_propr.pathway).map(correct_meta_data).mix(ch_adjacency)

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

emit:
matrix = ch_matrix
matrix = ch_matrix
adjacency = ch_adjacency
}
40 changes: 26 additions & 14 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 correct_meta_data = { meta, data, pathway ->
def meta_clone = meta.clone() + pathway
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 @@ -36,20 +43,25 @@ workflow DIFFERENTIAL {
.join(ch_samplesheet)
.combine(ch_contrasts)
.combine(ch_tools_single.propd)
.map {
meta_data, counts, samplesheet, meta_contrast, contrast_variable, reference, target, meta_tools ->
.multiMap {
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()
[ meta, counts, samplesheet, contrast_variable, reference, target ]
input: [ meta, counts, samplesheet, contrast_variable, reference, target ]
pathway: [ meta, pathway ]
}
.unique()
.set { 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)
ch_results_genewise_filtered = ch_results_genewise_filtered.mix(PROPD.out.hub_genes)
ch_adjacency = ch_adjacency.mix(PROPD.out.adjacency)
PROPD(ch_propd.input.unique())
ch_results_pairwise = PROPD.out.results
.join(ch_propd.pathway).map(correct_meta_data).mix(ch_results_pairwise)
ch_results_pairwise_filtered = PROPD.out.results_filtered
.join(ch_propd.pathway).map(correct_meta_data).mix(ch_results_pairwise_filtered)
ch_results_genewise = PROPD.out.connectivity
.join(ch_propd.pathway).map(correct_meta_data).mix(ch_results_genewise)
ch_results_genewise_filtered = PROPD.out.hub_genes
.join(ch_propd.pathway).map(correct_meta_data).mix(ch_results_genewise_filtered)
ch_adjacency = PROPD.out.adjacency
.join(ch_propd.pathway).map(correct_meta_data).mix(ch_adjacency)

// ----------------------------------------------------
// Perform differential analysis with DESeq2
Expand Down
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