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

Pytest -> Nftest Readwriter #6077

Merged
merged 10 commits into from
Aug 1, 2024
31 changes: 16 additions & 15 deletions modules/nf-core/sentieon/readwriter/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ process SENTIEON_READWRITER {
tuple val(meta3), path(fai)

output:
tuple val(meta), path("*.${format}"), emit: output
tuple val(meta), path("*.${index}") , emit: index
tuple val(meta), path("*.${format}"), path("*.${index}"), emit: output_index
path "versions.yml" , emit: versions
tuple val(meta), path("${prefix}"), emit: output
tuple val(meta), path("${prefix}.${index}"), emit: index
tuple val(meta), path("${prefix}"), path("${prefix}.${index}"), emit: output_index
path "versions.yml", emit: versions

when:
task.ext.when == null || task.ext.when
Expand All @@ -27,11 +27,15 @@ process SENTIEON_READWRITER {

def args = task.ext.args ?: ''
def args2 = task.ext.args2 ?: ''
def input_str = input.sort().collect{"-i $it"}.join(' ')
def input_str = input.sort{ it.getName() }.collect{"-i $it"}.join(' ')
def reference = fasta ? "-r $fasta" : ''
def prefix = task.ext.prefix ?: "${meta.id}"
format = input.extension == "bam" ? "bam" : "cram"
index = format == "bam" ? "bam.bai" : "cram.crai"

// bam -> bam: prefix = "<filename>.bam"
// bam -> cram: prefix = "<filename>.cram"
// cram -> cram: prefix = "<filename>.cram"
prefix = task.ext.prefix ?: "${meta.id}.bam"
index = prefix.tokenize('.')[-1] == "bam" ? "bai" : "crai"

def sentieonLicense = secrets.SENTIEON_LICENSE_BASE64 ?
"export SENTIEON_LICENSE=\$(mktemp);echo -e \"${secrets.SENTIEON_LICENSE_BASE64}\" | base64 -d > \$SENTIEON_LICENSE; " :
""
Expand All @@ -46,7 +50,7 @@ process SENTIEON_READWRITER {
$input_str \\
--algo ReadWriter \\
$args2 \\
${prefix}.${format}
${prefix}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand All @@ -55,14 +59,11 @@ process SENTIEON_READWRITER {
"""

stub:


def prefix = task.ext.prefix ?: "${meta.id}"
format = input.extension == "bam" ? "bam" : "cram"
index = format == "bam" ? "bam.bai" : "cram.crai"
prefix = task.ext.prefix ?: "${meta.id}.cram"
index = prefix.tokenize('.')[-1] == "bam" ? "bai" : "crai"
"""

touch ${prefix}.${format}
touch ${prefix}
touch ${prefix}.${index}

cat <<-END_VERSIONS > versions.yml
Expand Down
2 changes: 1 addition & 1 deletion modules/nf-core/sentieon/readwriter/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ output:
e.g. [ id:'test', single_end:false ]
- output:
type: file
description: BAM/CRAM file
description: BAM/CRAM file. Depends on how ext.prefix is set. BAM "ext.prefix = <filename>.bam", CRAM "ext.prefix = <filename>.cram". Defaults to cram
pattern: "*.{bam,cram}"
- index:
type: file
Expand Down
173 changes: 173 additions & 0 deletions modules/nf-core/sentieon/readwriter/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
nextflow_process {

name "Test Process SENTIEON_READWRITER"
script "../main.nf"
process "SENTIEON_READWRITER"

tag "modules"
tag "modules_nfcore"
tag "sentieon"
tag "sentieon/readwriter"

test("merge bam") {
config "./nextflow.config"

when {
process {
"""
input[0] = [ [id: 'test' ],
file(params.modules_testdata_base_path + '/genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam', checkIfExists: true),
file(params.modules_testdata_base_path + '/genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam.bai', checkIfExists: true)
]
input[1] = [[:],[]]
input[2] = [[:],[]]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
bam(process.out.output[0][1], stringency: "lenient").getReadsMD5(),
bam(process.out.output[0][1], stringency: "lenient").getHeader(),
file(process.out.index.get(0).get(1)).name,
process.out.versions
).match() }

)
}

}

test("cram") {
config "./nextflow_outputcram.config"
when {
process {
"""
input[0] = [ [id: 'test', fasta: params.modules_testdata_base_path + '/genomics/homo_sapiens/genome/genome.fasta' ],
file(params.modules_testdata_base_path + '/genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram', checkIfExists: true),
file(params.modules_testdata_base_path + '/genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram.crai', checkIfExists: true)
]
input[1] = [ [ id:'fasta' ], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true) ]
input[2] = [ [ id:'fasta' ], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta.fai', checkIfExists: true) ]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
bam(process.out.output[0][1], process.out.output[0][0].fasta).getReadsMD5(),
bam(process.out.output[0][1], process.out.output[0][0].fasta).getHeader(),
file(process.out.index.get(0).get(1)).name,
process.out.versions
).match() }

)
}
}

test("merging - output bam") {
config "./nextflow.config"

when {
process {
"""
input[0] = [ [id: 'test' ],
[ file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.methylated.sorted.bam', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.single_end.sorted.bam', checkIfExists: true)
],
[ file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.methylated.sorted.bam.bai', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam.bai', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.single_end.sorted.bam.bai', checkIfExists: true)
],
[]
]
input[1] = [[:],[]]
input[2] = [[:],[]]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
bam(process.out.output[0][1], stringency: "lenient").getReadsMD5(),
bam(process.out.output[0][1], stringency: "lenient").getHeader(),
file(process.out.index.get(0).get(1)).name,
process.out.versions
).match() }

)
}

}

test("merging - output bam to cram") {
config "./nextflow_outputcram.config"

when {
process {
"""
input[0] = [ [id: 'test', fasta: params.modules_testdata_base_path + '/genomics/sarscov2/genome/genome.fasta' ],
[ file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.methylated.sorted.bam', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.single_end.sorted.bam', checkIfExists: true)
],
[ file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.methylated.sorted.bam.bai', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam.bai', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.single_end.sorted.bam.bai', checkIfExists: true)
]
]
input[1] = [ [ id:'fasta' ], file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) ]
input[2] = [ [ id:'fasta' ], file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta.fai', checkIfExists: true) ]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
bam(process.out.output[0][1], process.out.output[0][0].fasta).getReadsMD5(),
bam(process.out.output[0][1], process.out.output[0][0].fasta).getHeader(),
file(process.out.index.get(0).get(1)).name,
process.out.versions
).match() }

)
}

}

test("sentieon readwriter - stub") {
options "-stub"
config "./nextflow.config"

when {
process {
"""
input[0] = [ [id: 'test' ],
file(params.modules_testdata_base_path + '/genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram', checkIfExists: true),
file(params.modules_testdata_base_path + '/genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram.crai', checkIfExists: true)
]
input[1] = [ [ id:'fasta' ], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true) ]
input[2] = [ [ id:'fasta' ], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta.fai', checkIfExists: true) ]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

}
Loading
Loading