Skip to content

Commit

Permalink
Merge branch 'master' into krakentools_fixmeta
Browse files Browse the repository at this point in the history
  • Loading branch information
tstoeriko authored Aug 1, 2024
2 parents 68fe086 + dc12c69 commit e039484
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 106 deletions.
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
168 changes: 168 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,168 @@
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(),
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(),
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(),
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(),
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() }
)
}

}

}
125 changes: 125 additions & 0 deletions modules/nf-core/sentieon/readwriter/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"merge bam": {
"content": [
"2f11e4fe3390b8ad0a1852616fd1da04",
"test.bam.bai",
[
"versions.yml:md5,7e0e065f92de4419098841b16968fbed"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.3"
},
"timestamp": "2024-08-01T13:14:43.34615"
},
"cram": {
"content": [
"2f11e4fe3390b8ad0a1852616fd1da04",
"test.cram.crai",
[
"versions.yml:md5,7e0e065f92de4419098841b16968fbed"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.3"
},
"timestamp": "2024-08-01T13:14:53.60186"
},
"merging - output bam": {
"content": [
"ed89d81d2d6adafdbb819a1a4ec86493",
"test.bam.bai",
[
"versions.yml:md5,7e0e065f92de4419098841b16968fbed"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.3"
},
"timestamp": "2024-08-01T13:15:03.780064"
},
"merging - output bam to cram": {
"content": [
"ed89d81d2d6adafdbb819a1a4ec86493",
"test.cram.crai",
[
"versions.yml:md5,7e0e065f92de4419098841b16968fbed"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.3"
},
"timestamp": "2024-08-01T13:15:15.313494"
},
"sentieon readwriter - stub": {
"content": [
{
"0": [
[
{
"id": "test"
},
"test.cram:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"1": [
[
{
"id": "test"
},
"test.cram.crai:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"2": [
[
{
"id": "test"
},
"test.cram:md5,d41d8cd98f00b204e9800998ecf8427e",
"test.cram.crai:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"3": [
"versions.yml:md5,7e0e065f92de4419098841b16968fbed"
],
"index": [
[
{
"id": "test"
},
"test.cram.crai:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"output": [
[
{
"id": "test"
},
"test.cram:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"output_index": [
[
{
"id": "test"
},
"test.cram:md5,d41d8cd98f00b204e9800998ecf8427e",
"test.cram.crai:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"versions": [
"versions.yml:md5,7e0e065f92de4419098841b16968fbed"
]
}
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.3"
},
"timestamp": "2024-08-01T13:15:23.88137"
}
}
9 changes: 9 additions & 0 deletions modules/nf-core/sentieon/readwriter/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
env {
// NOTE This is how pipeline users will use Sentieon in real world use
SENTIEON_LICENSE = "$SENTIEON_LICSRVR_IP"
// NOTE This should only happen in GitHub actions or nf-core MegaTests
SENTIEON_AUTH_MECH = "$SENTIEON_AUTH_MECH"
SENTIEON_AUTH_DATA = secrets.SENTIEON_AUTH_DATA
// NOTE This is how pipeline users will test out Sentieon with a license file
// nextflow secrets set SENTIEON_LICENSE_BASE64 \$(cat <sentieon_license_file.lic> | base64 -w 0)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
env {
// NOTE This is how pipeline users will use Sentieon in real world use
SENTIEON_LICENSE = "$SENTIEON_LICSRVR_IP"
// NOTE This should only happen in GitHub actions or nf-core MegaTests
SENTIEON_AUTH_MECH = "$SENTIEON_AUTH_MECH"
SENTIEON_AUTH_DATA = secrets.SENTIEON_AUTH_DATA
// NOTE This is how pipeline users will test out Sentieon with a license file
// nextflow secrets set SENTIEON_LICENSE_BASE64 \$(cat <sentieon_license_file.lic> | base64 -w 0)
}


process {
withName: "SENTIEON_READWRITER" {
ext.prefix = { "${meta.id}.cram" }
}
}
Loading

0 comments on commit e039484

Please sign in to comment.