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

Add new module: samtools/consensus #6064

Merged
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"
61 changes: 61 additions & 0 deletions modules/nf-core/samtools/consensus/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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:

LilyAnderssonLee marked this conversation as resolved.
Show resolved Hide resolved
tuple val(meta), path(input)

output:
tuple val(meta), path("*.fasta") , emit: fasta, optional: true
tuple val(meta), path("*.fastq") , emit: fastq, optional: true
LilyAnderssonLee marked this conversation as resolved.
Show resolved Hide resolved
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}_consensus"
LilyAnderssonLee marked this conversation as resolved.
Show resolved Hide resolved
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}_consensus"
LilyAnderssonLee marked this conversation as resolved.
Show resolved Hide resolved
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
SPPearce marked this conversation as resolved.
Show resolved Hide resolved
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
Loading