Skip to content

Commit

Permalink
Merge branch 'dev-ratio' into dev-ratio-genesets
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlang authored Oct 23, 2024
2 parents 9111891 + a594ebf commit 4343c6b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 40 deletions.
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
2 changes: 1 addition & 1 deletion assets/tools_samplesheet.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cor,,,propr,--metric cor,,
propd_grea,propd,,,,grea,
propd_ora,propd,,,,gprofiler2,
deseq2,deseq2,,,,,
deseq2_ora,deseq2,,,,gprofiler2,
deseq2_ora,deseq2,,,,gprofiler2,
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
}
41 changes: 26 additions & 15 deletions subworkflows/local/differential/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ include { PROPR_PROPD as PROPD } from "../../../modules/local/propr/propd/main.n
include { DESEQ2_DIFFERENTIAL as DESEQ2 } from '../../../modules/nf-core/deseq2/differential/main'
include { FILTER_DIFFTABLE as FILTER_DESEQ2 } from '../../../modules/local/filter_difftable'

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]
ch_control_features
ch_transcript_lengths

Expand All @@ -26,8 +33,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 @@ -39,21 +46,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 @@ -7,6 +7,7 @@ include { GPROFILER2_GOST } from "../../../modules/nf-core/gprofiler2/gost/main.

workflow ENRICHMENT {
take:
ch_tools // [ pathway_name, enrichment_map ]
ch_counts
ch_results_genewise
ch_results_genewise_filtered
Expand Down Expand Up @@ -47,10 +48,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"
}
.set { ch_adjacency }

GREA(ch_adjacency_grea, ch_gene_sets.collect())
GREA(ch_adjacency.grea, ch_gene_sets.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 Down Expand Up @@ -44,7 +52,7 @@ workflow EXPERIMENTAL {
}

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

CORRELATION(
ch_tools,
ch_tools.corr,
ch_counts
)
ch_matrix = ch_matrix.mix(CORRELATION.out.matrix)
Expand All @@ -73,6 +81,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 @@ -363,8 +363,16 @@ workflow DIFFERENTIALABUNDANCE {
// TODO the experimental branch should be independent from this file
} 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()

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

0 comments on commit 4343c6b

Please sign in to comment.