Skip to content

Commit

Permalink
--output-unselected option in samtools view (#2674)
Browse files Browse the repository at this point in the history
* add unoutput option

* trying to fix emit

* CI fixed, tests still incorrect

* Fixed the checksums

* Fixed the syntax

* Call this "unselected" rather than "unoutput"

* Alignment rocks

* bugfix: the variable needs to be visible by the output declaration

* bugfix: this was not the regular file name

* Updated the test case

* fixup! Alignment rocks

* Updated the meta.yml

---------

Co-authored-by: Matthieu Muffato <mm49@sanger.ac.uk>
  • Loading branch information
priyanka-surana and muffato authored Jun 21, 2024
1 parent 8ed9774 commit 6c2309a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
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

0 comments on commit 6c2309a

Please sign in to comment.