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

--output-unselected option in samtools view #2674

Merged
merged 15 commits into from
Jun 21, 2024
Merged
40 changes: 21 additions & 19 deletions modules/nf-core/samtools/view/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@ process SAMTOOLS_VIEW {
path qname

output:
tuple val(meta), path("*.bam"), emit: bam, optional: true
tuple val(meta), path("*.cram"), emit: cram, optional: true
tuple val(meta), path("*.sam"), emit: sam, optional: true
tuple val(meta), path("*.bai"), emit: bai, optional: true
tuple val(meta), path("*.csi"), emit: csi, optional: true
tuple val(meta), path("*.crai"), emit: crai, optional: true
path "versions.yml", emit: versions
tuple val(meta), path("${prefix}.bam"), emit: bam, optional: true
tuple val(meta), path("${prefix}.cram"), emit: cram, optional: true
tuple val(meta), path("${prefix}.sam"), emit: sam, optional: true
tuple val(meta), path("${prefix}.${file_type}.bai"), emit: bai, optional: true
tuple val(meta), path("${prefix}.${file_type}.csi"), emit: csi, optional: true
tuple val(meta), path("${prefix}.${file_type}.crai"), emit: crai, optional: true
tuple val(meta), path("${prefix}.unselected.${file_type}"), emit: unselected, optional: true
tuple val(meta), path("${prefix}.unselected.${file_type}.{bai,csi,crsi}"), emit: unselected_index, optional: true
path "versions.yml", emit: versions

when:
task.ext.when == null || task.ext.when

script:
def args = task.ext.args ?: ''
def args2 = task.ext.args2 ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
prefix = task.ext.prefix ?: "${meta.id}"
def reference = fasta ? "--reference ${fasta}" : ""
def readnames = qname ? "--qname-file ${qname}": ""
def file_type = args.contains("--output-fmt sam") ? "sam" :
args.contains("--output-fmt bam") ? "bam" :
args.contains("--output-fmt cram") ? "cram" :
input.getExtension()
file_type = args.contains("--output-fmt sam") ? "sam" :
args.contains("--output-fmt bam") ? "bam" :
args.contains("--output-fmt cram") ? "cram" :
input.getExtension()
readnames = qname ? "--qname-file ${qname} --output-unselected ${prefix}.unselected.${file_type}": ""
if ("$input" == "${prefix}.${file_type}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
"""
samtools \\
Expand All @@ -54,14 +56,14 @@ process SAMTOOLS_VIEW {

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def file_type = args.contains("--output-fmt sam") ? "sam" :
args.contains("--output-fmt bam") ? "bam" :
args.contains("--output-fmt cram") ? "cram" :
input.getExtension()
prefix = task.ext.prefix ?: "${meta.id}"
file_type = args.contains("--output-fmt sam") ? "sam" :
args.contains("--output-fmt bam") ? "bam" :
args.contains("--output-fmt cram") ? "cram" :
input.getExtension()
if ("$input" == "${prefix}.${file_type}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"

def index = args.contains("--write-index") ? "touch ${prefix}.csi" : ""
def index = args.contains("--write-index") ? "touch ${prefix}.${file_type}.csi" : ""

"""
touch ${prefix}.${file_type}
Expand Down
9 changes: 9 additions & 0 deletions modules/nf-core/samtools/view/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ output:
type: file
description: optional CRAM file index
pattern: "*.{crai}"
# unselected and unselected_index are created when passing a qname
- unselected:
type: file
description: optional file with unselected alignments
pattern: "*.unselected.{bam,cram,sam}"
- unselected_index:
type: file
description: index for the "unselected" file
pattern: "*.unselected.{bai,csi,crai}"
- versions:
type: file
description: File containing software versions
Expand Down
2 changes: 2 additions & 0 deletions modules/nf-core/samtools/view/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ nextflow_process {
{ assert snapshot(process.out.crai).match("cram_to_bam_index_qname_crai") },
{ assert snapshot(process.out.cram).match("cram_to_bam_index_qname_cram") },
{ assert snapshot(process.out.sam).match("cram_to_bam_index_qname_sam") },
{ assert snapshot(file(process.out.unselected[0][1]).name).match("cram_to_bam_index_qname_unselected") },
{ assert snapshot(file(process.out.unselected_index[0][1]).name).match("cram_to_bam_index_qname_unselected_csi") },
{ assert snapshot(process.out.versions).match("cram_to_bam_index_qname_versions") }
)
}
Expand Down
22 changes: 21 additions & 1 deletion modules/nf-core/samtools/view/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@
},
"timestamp": "2024-02-12T19:38:23.322874"
},
"cram_to_bam_index_qname_unselected": {
"content": [
"test.unselected.bam"
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.04.3"
},
"timestamp": "2024-02-12T19:38:23.322874"
},
"cram_to_bam_index_qname_unselected_csi": {
"content": [
"test.unselected.bam.csi"
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.04.3"
},
"timestamp": "2024-02-12T19:38:23.328458"
},
"bam_versions": {
"content": [
[
Expand Down Expand Up @@ -477,7 +497,7 @@
},
"bam_stub_csi": {
"content": [
"test.csi"
"test.bam.csi"
],
"meta": {
"nf-test": "0.8.4",
Expand Down
Loading