Skip to content
Merged
36 changes: 31 additions & 5 deletions modules/nf-core/rsem/calculateexpression/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ process RSEM_CALCULATEEXPRESSION {
'community.wave.seqera.io/library/rsem_star:5acb4e8c03239c32' }"

input:
tuple val(meta), path(reads)
tuple val(meta), path(reads) // FASTQ files or BAM file for --alignments mode
path index

output:
tuple val(meta), path("*.genes.results") , emit: counts_gene
tuple val(meta), path("*.isoforms.results"), emit: counts_transcript
tuple val(meta), path("*.stat") , emit: stat
tuple val(meta), path("*.log") , emit: logs
tuple val(meta), path("*.log") , emit: logs, optional:true
path "versions.yml" , emit: versions

tuple val(meta), path("*.STAR.genome.bam") , optional:true, emit: bam_star
Expand All @@ -35,14 +35,34 @@ process RSEM_CALCULATEEXPRESSION {
} else if (meta.strandedness == 'reverse') {
strandedness = '--strandedness reverse'
}
def paired_end = meta.single_end ? "" : "--paired-end"

// Detect if input is BAM file(s)
def is_bam = reads.toString().toLowerCase().endsWith('.bam')
def alignment_mode = is_bam ? '--alignments' : ''

// Use metadata for paired-end detection if available, otherwise empty (auto-detect)
def paired_end = meta.containsKey('single_end') ? (meta.single_end ? "" : "--paired-end") : "unknown"

"""
INDEX=`find -L ./ -name "*.grp" | sed 's/\\.grp\$//'`

# Use metadata-based paired-end detection, or auto-detect if no metadata provided
PAIRED_END_FLAG="$paired_end"
if [ "${paired_end}" == "unknown" ]; then
# Auto-detect only if no metadata provided
if [ "${is_bam}" == "true" ]; then
samtools flagstat $reads | grep -q 'paired in sequencing' && PAIRED_END_FLAG="--paired-end"
else
[ ${reads.size()} -gt 1 ] && PAIRED_END_FLAG="--paired-end"
fi
fi

rsem-calculate-expression \\
--num-threads $task.cpus \\
--temporary-folder ./tmp/ \\
$alignment_mode \\
$strandedness \\
$paired_end \\
\$PAIRED_END_FLAG \\
$args \\
$reads \\
\$INDEX \\
Expand All @@ -57,12 +77,18 @@ process RSEM_CALCULATEEXPRESSION {

stub:
prefix = task.ext.prefix ?: "${meta.id}"
def is_bam = reads.toString().toLowerCase().endsWith('.bam')
"""
touch ${prefix}.genes.results
touch ${prefix}.isoforms.results
touch ${prefix}.stat
touch ${prefix}.log
touch ${prefix}.STAR.genome.bam

# Only create STAR BAM output when not in alignment mode
if [ "${is_bam}" == "false" ]; then
touch ${prefix}.STAR.genome.bam
fi

touch ${prefix}.genome.bam
touch ${prefix}.transcript.bam

Expand Down
5 changes: 3 additions & 2 deletions modules/nf-core/rsem/calculateexpression/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ input:
e.g. [ id:'test', single_end:false ]
- reads:
type: file
description: Input reads for quantification
pattern: "*.fastq.gz"
description: Input reads for quantification (FASTQ files or BAM file for --alignments mode)
pattern: "*.{fastq.gz,bam}"
ontologies:
- edam: http://edamontology.org/format_3989 # GZIP format
- edam: http://edamontology.org/format_2572 # BAM format
- index:
type: file
description: RSEM index
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {

publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

}
73 changes: 64 additions & 9 deletions modules/nf-core/rsem/calculateexpression/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,59 @@ nextflow_process {
name "Test Process RSEM_CALCULATEEXPRESSION"
script "../main.nf"
process "RSEM_CALCULATEEXPRESSION"
config "./nextflow.config"
tag "modules"
tag "modules_nfcore"
tag "rsem"
tag "rsem/calculateexpression"
tag "rsem/preparereference"

test("homo_sapiens") {

test("homo_sapiens - bam") {

config "./alignment.config"

setup {
run("RSEM_PREPAREREFERENCE") {
script "../../../rsem/preparereference/main.nf"
process {
"""
input[0] = Channel.of(file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true))
input[1] = Channel.of(file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.gtf', checkIfExists: true))
"""
}
}
}

when {
params {
outdir = "$outputDir"
}
process {
"""
input[0] = Channel.of([
[ id:'test', strandedness: 'forward' ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/rsem.transcript.bam', checkIfExists: true)
])
input[1] = RSEM_PREPAREREFERENCE.out.index
"""
}
}
then {
assertAll(
{ assert process.success },
{ assert snapshot(
process.out.counts_gene,
process.out.counts_transcript,
process.out.stat,
process.out.versions
).match() }
)
}
}

test("homo_sapiens - fastq") {

config "./nextflow.config"

setup {
run("RSEM_PREPAREREFERENCE") {
Expand Down Expand Up @@ -44,18 +89,22 @@ nextflow_process {
then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.counts_gene).match("counts_gene") },
{ assert snapshot(process.out.counts_transcript).match("counts_transcript") },
{ assert snapshot(process.out.stat).match("stat") },
{ assert path(process.out.logs.get(0).get(1)).exists() },
{ assert snapshot(process.out.versions).match("versions") }
{ assert snapshot(
process.out.counts_gene,
process.out.counts_transcript,
process.out.stat,
process.out.versions
).match() },
{ assert path(process.out.logs.get(0).get(1)).exists() }
)
}
}

test("homo_sapiens - stub") {

options "-stub"
config "./nextflow.config"

options "-stub"

setup {
run("RSEM_PREPAREREFERENCE") {
Expand Down Expand Up @@ -86,7 +135,13 @@ nextflow_process {
then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
{ assert path(process.out.counts_gene.get(0).get(1)).exists() },
{ assert path(process.out.counts_transcript.get(0).get(1)).exists() },
{ assert path(process.out.stat.get(0).get(1)).exists() },
{ assert path(process.out.logs.get(0).get(1)).exists() },
{ assert snapshot(
process.out.versions
).match() }
)
}
}
Expand Down
Loading
Loading