Skip to content

Commit

Permalink
Add new module: samtools/consensus (nf-core#6064)
Browse files Browse the repository at this point in the history
* Add new module: samtools/consensus

* Update modules/nf-core/samtools/consensus/main.nf

Co-authored-by: Simon Pearce <[email protected]>

* add thread option

* Add more test modes to the test

* Update modules/nf-core/samtools/consensus/main.nf

Co-authored-by: Simon Pearce <[email protected]>

* Update modules/nf-core/samtools/consensus/main.nf

Co-authored-by: Simon Pearce <[email protected]>

* Update modules/nf-core/samtools/consensus/main.nf

Co-authored-by: Simon Pearce <[email protected]>

* Update modules/nf-core/samtools/consensus/main.nf

Co-authored-by: Simon Pearce <[email protected]>

* update snapshot of the test

---------

Co-authored-by: Simon Pearce <[email protected]>
  • Loading branch information
LilyAnderssonLee and SPPearce authored Jul 31, 2024
1 parent 416e4b8 commit 4133cae
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/nf-core/samtools/consensus/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json
name: "samtools_consensus"
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- "bioconda::samtools=1.20"
60 changes: 60 additions & 0 deletions modules/nf-core/samtools/consensus/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
process SAMTOOLS_CONSENSUS {
tag "$meta.id"
label 'process_low'

conda "${moduleDir}/environment.yml"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/samtools:1.20--h50ea8bc_1':
'biocontainers/samtools:1.20--h50ea8bc_1' }"

input:
tuple val(meta), path(input)

output:
tuple val(meta), path("*.fasta") , emit: fasta , optional: true
tuple val(meta), path("*.fastq") , emit: fastq , optional: true
tuple val(meta), path("*.pileup"), emit: pileup, optional: true
path "versions.yml" , emit: versions

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

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def extension = args.contains("-f fastq") ? "fastq" :
args.contains("-f pileup") ? "pileup" :
args.contains("-f fasta") ? "fasta" :
"fasta"

"""
samtools \\
consensus \\
$args \\
-@ $task.cpus \\
-o ${prefix}.${extension} \\
$input
cat <<-END_VERSIONS > versions.yml
"${task.process}":
samtools: \$(samtools --version |& sed '1!d ; s/samtools //')
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def extension = args.contains("-f fastq") ? "fastq" :
args.contains("-f pileup") ? "pileup" :
args.contains("-f fasta") ? "fasta" :
"fasta"

"""
touch ${prefix}.${extension}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
samtools: \$(samtools --version |& sed '1!d ; s/samtools //')
END_VERSIONS
"""
}
54 changes: 54 additions & 0 deletions modules/nf-core/samtools/consensus/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json
name: "samtools_consensus"
description: Produces a consensus FASTA/FASTQ/PILEUP
keywords:
- consensus
- bam
- fastq
- fasta
- pileup
tools:
- samtools:
description: |
SAMtools is a set of utilities for interacting with and post-processing
short DNA sequence read alignments in the SAM, BAM and CRAM formats, written by Heng Li.
These files are generated as output by short read aligners like BWA.
homepage: http://www.htslib.org/
documentation: http://www.htslib.org/doc/samtools.html
tool_dev_url: "https://github.com/samtools/samtools"
doi: "10.1093/bioinformatics/btp352"
licence: ["MIT"]

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- input:
type: file
description: Sorted BAM/CRAM/SAM file
pattern: "*.{bam,cram,sam}"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"
- output:
type: file
description: Consensus sequences
pattern: "*.{fasta,fastq,pileup}"

authors:
- "@LilyAnderssonLee"
maintainers:
- "@LilyAnderssonLee"
5 changes: 5 additions & 0 deletions modules/nf-core/samtools/consensus/tests/fastq.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: SAMTOOLS_CONSENSUS {
ext.args2 = '-f fastq'
}
}
106 changes: 106 additions & 0 deletions modules/nf-core/samtools/consensus/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
nextflow_process {

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

tag "modules"
tag "modules_nfcore"
tag "samtools"
tag "samtools/consensus"

test("sarscov2 - bam - fasta") {

when {
process {
"""
input[0] = Channel.of([
[id: 'test', single_end: false], // meta map
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.paired_end.sorted.bam.bai', checkIfExists: true)
])
"""
}
}

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

}
test("sarscov2 - bam - fastq") {

config "./fastq.config"
when {
process {
"""
input[0] = Channel.of([
[id: 'test', single_end: false], // meta map
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.paired_end.sorted.bam.bai', checkIfExists: true)
])
"""
}
}

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

}
test("sarscov2 - bam - pileup") {

config "./pileup.config"
when {
process {
"""
input[0] = Channel.of([
[id: 'test', single_end: false], // meta map
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.paired_end.sorted.bam.bai', checkIfExists: true)
])
"""
}
}

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

}

test("sarscov2 - bam - stub") {

options "-stub"

when {
process {
"""
input[0] = Channel.of([
[id: 'test', single_end: false], // meta map
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.paired_end.sorted.bam.bai', checkIfExists: true)
])
"""
}
}

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

}

}
Loading

0 comments on commit 4133cae

Please sign in to comment.