Skip to content
Open
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
22 changes: 14 additions & 8 deletions modules/nf-core/gsea/gsea/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,34 @@ process GSEA_GSEA {
script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def rpt_label = prefix.replaceAll('\\.$', '') // Remove any trailing dots from prefix when passed as report label, so GSEA doesn't produce double-dotted top-level outputs
def chip_command = chip ? "-chip $chip -collapse true" : ''
def rpt_label = prefix.replaceAll('\\.$', '')
def chip_command = chip ? "-chip \"$chip\" -collapse true" : ''
// gsea-cli takes a comma-delimited -gmx value to pool multiple gene set files into one run.
def gmx = gene_sets instanceof List ? gene_sets.join(',') : gene_sets

"""
# Run GSEA

gsea-cli GSEA \\
-res $gct \\
-cls ${cls}#${target}_versus_${reference} \\
-gmx $gene_sets \\
-res "$gct" \\
-cls "${cls}#${target}_versus_${reference}" \\
-gmx "$gmx" \\
$chip_command \\
-out . \\
--rpt_label $rpt_label \\
--rpt_label "$rpt_label" \\
$args

# Un-timestamp the outputs for path consistency
mv ${rpt_label}.Gsea.*/* .
# Only rmdir actual directories: the .rpt file's name also matches "${rpt_label}.Gsea.*".
mv "$rpt_label".Gsea.*/* .
for gsea_dir in "$rpt_label".Gsea.*/; do
[ -d "\$gsea_dir" ] && rmdir "\$gsea_dir"
done
timestamp=\$(cat *.rpt | grep producer_timestamp | awk '{print \$2}')

for pattern in _\${timestamp} .\${timestamp}; do
find . -name "*\${pattern}*" | sed "s|^\\./||" | while read -r f; do
mv \$f \${f//\$pattern/}
mv "\$f" "\${f//\$pattern/}"
done
done
sed -i.bak "s/[_\\.]\$timestamp//g" *.rpt *.html && rm *.bak
Expand Down
49 changes: 49 additions & 0 deletions modules/nf-core/gsea/gsea/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,55 @@ nextflow_process {
}
}

test("test_multiple_gmt") {

config "./nextflow.config"

when {
process {
"""
input[0] = [['id':'Condition_genotype_WT_KO', 'variable':'Condition genotype', 'reference':'WT', 'target':'KO', 'blocking':'batch'], file("https://github.com/nf-core/test-datasets/raw/refs/heads/modules/data/genomics/mus_musculus/gene_set_analysis/Condition_treatment_Control_Treated.gct", checkIfExists:true), file("https://github.com/nf-core/test-datasets/raw/refs/heads/modules/data/genomics/mus_musculus/gene_set_analysis/Condition_genotype_WT_KO.cls", checkIfExists:true), [file("https://github.com/nf-core/test-datasets/raw/refs/heads/modules/data/genomics/mus_musculus/gene_set_analysis/mh.all.v2022.1.Mm.symbols.gmt", checkIfExists:true), file("https://github.com/nf-core/test-datasets/raw/refs/heads/modules/data/genomics/mus_musculus/gene_set_analysis/m5.mpt.v2022.1.Mm.symbols.gmt", checkIfExists:true)]]
input[1] = ['WT', 'KO']
input[2] = [
['id': 'test'],
file("https://github.com/nf-core/test-datasets/raw/refs/heads/modules/data/genomics/mus_musculus/gene_set_analysis/Mus_musculus.anno.feature_metadata.chip", checkIfExists:true)
]
"""
}
}

then {
assertAll (
{ assert process.success },
{ assert snapshot(
process.out.rpt.collect{ meta,rpt -> file(rpt).name }, //assert unstable file
process.out.index_html.collect{ meta,index_html -> file(index_html).name }, //assert unstable file
process.out.heat_map_corr_plot,
process.out.report_tsvs_ref,
process.out.report_htmls_ref.collect{ meta,report_htmls_ref -> file(report_htmls_ref).name }, //assert unstable file
process.out.report_tsvs_target,
process.out.report_htmls_target.collect{ meta,report_htmls_target -> file(report_htmls_target).name }, //assert unstable file
process.out.ranked_gene_list,
process.out.gene_set_sizes,
process.out.histogram.collect{ meta,histogram -> file(histogram).name }, //assert unstable file
process.out.heatmap.collect{ meta,heatmap -> file(heatmap).name }, //assert unstable file
process.out.pvalues_vs_nes_plot.collect{ meta,pvalues_vs_nes_plot -> file(pvalues_vs_nes_plot).name }, //assert unstable file
process.out.ranked_list_corr.collect{ meta,ranked_list_corr -> file(ranked_list_corr).name }, //assert unstable file
process.out.butterfly_plot.collect{ meta,butterfly_plot -> file(butterfly_plot).name }, //assert unstable file
process.out.gene_set_tsv,
process.out.gene_set_html[0][1].collect{ file(it).name }, //assert unstable file
process.out.gene_set_heatmap[0][1].collect{ file(it).name }, // unstable file and unstable name
process.out.snapshot[0][1].collect{ file(it).name }, //assert unstable file
process.out.gene_set_enplot[0][1].collect{ file(it).name }, // unstable file and unstable name
process.out.gene_set_dist[0][1].collect{ file(it).name }, //assert unstable file
process.out.archive,
process.out.findAll { key, val -> key.startsWith('versions') }
).match()
}
)
}
}

test("stub") {

options "-stub"
Expand Down
Loading