Merge pull request #172 from andersgs/ivar-variant

Add ivar variants
This commit is contained in:
Harshil Patel 2021-02-16 23:20:30 +00:00 committed by GitHub
commit a282ecd8c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 283 additions and 0 deletions

4
.github/filters.yml vendored
View file

@ -148,6 +148,10 @@ ivar_trim:
- software/ivar/trim/**
- tests/software/ivar/trim/**
ivar_variants:
- software/ivar/variants/**
- tests/software/ivar/variants/**
minimap2_align:
- software/minimap2/align/**
- tests/software/minimap2/align/**

View file

@ -0,0 +1,59 @@
/*
* -----------------------------------------------------
* Utility functions used in nf-core DSL2 module files
* -----------------------------------------------------
*/
/*
* Extract name of software tool from process name using $task.process
*/
def getSoftwareName(task_process) {
return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()
}
/*
* Function to initialise default values and to generate a Groovy Map of available options for nf-core modules
*/
def initOptions(Map args) {
def Map options = [:]
options.args = args.args ?: ''
options.args2 = args.args2 ?: ''
options.publish_by_id = args.publish_by_id ?: false
options.publish_dir = args.publish_dir ?: ''
options.publish_files = args.publish_files
options.suffix = args.suffix ?: ''
return options
}
/*
* Tidy up and join elements of a list to return a path string
*/
def getPathFromList(path_list) {
def paths = path_list.findAll { item -> !item?.trim().isEmpty() } // Remove empty entries
paths = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes
return paths.join('/')
}
/*
* Function to save/publish module results
*/
def saveFiles(Map args) {
if (!args.filename.endsWith('.version.txt')) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
if (ioptions.publish_by_id) {
path_list.add(args.publish_id)
}
if (ioptions.publish_files instanceof Map) {
for (ext in ioptions.publish_files) {
if (args.filename.endsWith(ext.key)) {
def ext_list = path_list.collect()
ext_list.add(ext.value)
return "${getPathFromList(ext_list)}/$args.filename"
}
}
} else if (ioptions.publish_files == null) {
return "${getPathFromList(path_list)}/$args.filename"
}
}
}

View file

@ -0,0 +1,50 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
def options = initOptions(params.options)
process IVAR_VARIANTS {
tag "$meta.id"
label 'process_medium'
publishDir "${params.outdir}",
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:meta.id) }
conda (params.enable_conda ? "bioconda::ivar=1.3.1" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/ivar:1.3.1--h089eab3_0"
} else {
container "quay.io/biocontainers/ivar:1.3.1--h089eab3_0"
}
input:
tuple val(meta), path(bam)
path fasta
path gff
output:
tuple val(meta), path("*.tsv") , emit: tsv
tuple val(meta), path("*.mpileup"), optional:true, emit: mpileup
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def save_mpileup = params.save_mpileup ? "tee ${prefix}.mpileup |" : ""
def features = params.gff ? "-g $gff" : ""
"""
samtools mpileup \\
$options.args2 \\
--reference $fasta \\
$bam | \\
$save_mpileup \\
ivar variants \\
$options.args \\
$features \\
-r $fasta \\
-p $prefix
ivar version | head -n1 2>&1 | sed 's/^.*iVar version //g' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,72 @@
name: ivar_variants
description: Call variants from a BAM file using iVar
keywords:
- amplicon sequencing
- variants
- fasta
tools:
- ivar:
description: |
iVar - a computational package that contains functions broadly useful for viral amplicon-based sequencing.
homepage: https://github.com/andersen-lab/ivar
documentation: https://andersen-lab.github.io/ivar/html/manualpage.html
params:
- outdir:
type: string
description: |
The pipeline's output directory. By default, the module will
output files into `$params.outdir/<SOFTWARE>`
- publish_dir_mode:
type: string
description: |
Value for the Nextflow `publishDir` mode parameter.
Available: symlink, rellink, link, copy, copyNoFollow, move.
- enable_conda:
type: boolean
description: |
Run the module with Conda using the software specified
via the `conda` directive
- singularity_pull_docker_container:
type: boolean
description: |
Instead of directly downloading Singularity images for use with Singularity,
force the workflow to pull and convert Docker containers instead.
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: A sorted (with samtools sort) and trimmed (with iVar trim) bam file
pattern: "*.bam"
- fasta:
type: file
description: The reference sequence used for mapping and generating the BAM file
pattern: "*.fa"
- gff:
type: file
description: A GFF file in the GFF3 format can be supplied to specify coordinates of open reading frames (ORFs). In absence of GFF file, amino acid translation will not be done.
patter: "*.gff"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- tsv:
type: file
description: iVar generated TSV file with the variants
pattern: "*.tsv"
- mpileup:
type: file
description: mpileup output from samtools mpileup [OPTIONAL]
pattern: "*.mpileup"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@andersgs"
- "@drpatelh"

View file

@ -0,0 +1,27 @@
##sequence-region MN908947.3 1 29903
##species https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=2697049
MN908947.3 Genbank region 1 29903 . + . ID=MN908947.3:1..29903;Dbxref=taxon:2697049;collection-date=Dec-2019;country=China;gb-acronym=SARS-CoV-2;gbkey=Src;genome=genomic;isolate=Wuhan-Hu-1;mol_type=genomic RNA;nat-host=Homo sapiens;old-name=Wuhan seafood market pneumonia virus
MN908947.3 Genbank five_prime_UTR 1 265 . + . ID=id-MN908947.3:1..265;gbkey=5'UTR
MN908947.3 Genbank gene 266 21555 . + . ID=gene-orf1ab;Name=orf1ab;gbkey=Gene;gene=orf1ab;gene_biotype=protein_coding
MN908947.3 Genbank CDS 266 13468 . + 0 ID=cds-QHD43415.1;Parent=gene-orf1ab;Dbxref=NCBI_GP:QHD43415.1;Name=QHD43415.1;Note=translated by -1 ribosomal frameshift;exception=ribosomal slippage;gbkey=CDS;gene=orf1ab;part=1;product=orf1ab polyprotein;protein_id=QHD43415.1
MN908947.3 Genbank CDS 13468 21555 . + 0 ID=cds-QHD43415.1;Parent=gene-orf1ab;Dbxref=NCBI_GP:QHD43415.1;Name=QHD43415.1;Note=translated by -1 ribosomal frameshift;exception=ribosomal slippage;gbkey=CDS;gene=orf1ab;part=2;product=orf1ab polyprotein;protein_id=QHD43415.1
MN908947.3 Genbank gene 21563 25384 . + . ID=gene-S;Name=S;gbkey=Gene;gene=S;gene_biotype=protein_coding
MN908947.3 Genbank CDS 21563 25384 . + 0 ID=cds-QHD43416.1;Parent=gene-S;Dbxref=NCBI_GP:QHD43416.1;Name=QHD43416.1;Note=structural protein;gbkey=CDS;gene=S;product=surface glycoprotein;protein_id=QHD43416.1
MN908947.3 Genbank gene 25393 26220 . + . ID=gene-ORF3a;Name=ORF3a;gbkey=Gene;gene=ORF3a;gene_biotype=protein_coding
MN908947.3 Genbank CDS 25393 26220 . + 0 ID=cds-QHD43417.1;Parent=gene-ORF3a;Dbxref=NCBI_GP:QHD43417.1;Name=QHD43417.1;gbkey=CDS;gene=ORF3a;product=ORF3a protein;protein_id=QHD43417.1
MN908947.3 Genbank gene 26245 26472 . + . ID=gene-E;Name=E;gbkey=Gene;gene=E;gene_biotype=protein_coding
MN908947.3 Genbank CDS 26245 26472 . + 0 ID=cds-QHD43418.1;Parent=gene-E;Dbxref=NCBI_GP:QHD43418.1;Name=QHD43418.1;Note=structural protein%3B E protein;gbkey=CDS;gene=E;product=envelope protein;protein_id=QHD43418.1
MN908947.3 Genbank gene 26523 27191 . + . ID=gene-M;Name=M;gbkey=Gene;gene=M;gene_biotype=protein_coding
MN908947.3 Genbank CDS 26523 27191 . + 0 ID=cds-QHD43419.1;Parent=gene-M;Dbxref=NCBI_GP:QHD43419.1;Name=QHD43419.1;Note=structural protein;gbkey=CDS;gene=M;product=membrane glycoprotein;protein_id=QHD43419.1
MN908947.3 Genbank gene 27202 27387 . + . ID=gene-ORF6;Name=ORF6;gbkey=Gene;gene=ORF6;gene_biotype=protein_coding
MN908947.3 Genbank CDS 27202 27387 . + 0 ID=cds-QHD43420.1;Parent=gene-ORF6;Dbxref=NCBI_GP:QHD43420.1;Name=QHD43420.1;gbkey=CDS;gene=ORF6;product=ORF6 protein;protein_id=QHD43420.1
MN908947.3 Genbank gene 27394 27759 . + . ID=gene-ORF7a;Name=ORF7a;gbkey=Gene;gene=ORF7a;gene_biotype=protein_coding
MN908947.3 Genbank CDS 27394 27759 . + 0 ID=cds-QHD43421.1;Parent=gene-ORF7a;Dbxref=NCBI_GP:QHD43421.1;Name=QHD43421.1;gbkey=CDS;gene=ORF7a;product=ORF7a protein;protein_id=QHD43421.1
MN908947.3 Genbank gene 27894 28259 . + . ID=gene-ORF8;Name=ORF8;gbkey=Gene;gene=ORF8;gene_biotype=protein_coding
MN908947.3 Genbank CDS 27894 28259 . + 0 ID=cds-QHD43422.1;Parent=gene-ORF8;Dbxref=NCBI_GP:QHD43422.1;Name=QHD43422.1;gbkey=CDS;gene=ORF8;product=ORF8 protein;protein_id=QHD43422.1
MN908947.3 Genbank gene 28274 29533 . + . ID=gene-N;Name=N;gbkey=Gene;gene=N;gene_biotype=protein_coding
MN908947.3 Genbank CDS 28274 29533 . + 0 ID=cds-QHD43423.2;Parent=gene-N;Dbxref=NCBI_GP:QHD43423.2;Name=QHD43423.2;Note=structural protein;gbkey=CDS;gene=N;product=nucleocapsid phosphoprotein;protein_id=QHD43423.2
MN908947.3 Genbank gene 29558 29674 . + . ID=gene-ORF10;Name=ORF10;gbkey=Gene;gene=ORF10;gene_biotype=protein_coding
MN908947.3 Genbank CDS 29558 29674 . + 0 ID=cds-QHI42199.1;Parent=gene-ORF10;Dbxref=NCBI_GP:QHI42199.1;Name=QHI42199.1;gbkey=CDS;gene=ORF10;product=ORF10 protein;protein_id=QHI42199.1
MN908947.3 Genbank three_prime_UTR 29675 29903 . + . ID=id-MN908947.3:29675..29903;gbkey=3'UTR

View file

@ -0,0 +1,41 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { IVAR_VARIANTS } from '../../../../software/ivar/variants/main.nf' addParams([:])
workflow test_ivar_variants_no_gff_no_mpileup {
params.gff = false
params.save_mpileup = false
def ref = file("${launchDir}/tests/data/fasta/sarscov2/MN908947.3.fa", checkIfExists: true)
def dummy = file("${launchDir}/tests/data/dummy/dummy_file.txt", checkIfExists: true)
def input = []
input = [ [ id:'test'],
file("${launchDir}/tests/data/bam/test-sc2-artic-v3-sorted-trimmed.bam", checkIfExists: true) ]
IVAR_VARIANTS ( input, ref, dummy )
}
workflow test_ivar_variants_no_gff_with_mpileup {
params.gff = false
params.save_mpileup = true
def ref = file("${launchDir}/tests/data/fasta/sarscov2/MN908947.3.fa", checkIfExists: true)
def dummy = file("${launchDir}/tests/data/dummy/dummy_file.txt", checkIfExists: true)
def input = []
input = [ [ id:'test'],
file("${launchDir}/tests/data/bam/test-sc2-artic-v3-sorted-trimmed.bam", checkIfExists: true) ]
IVAR_VARIANTS ( input, ref, dummy )
}
workflow test_ivar_variants_with_gff_with_mpileup {
params.gff = "${launchDir}/tests/data/gff/sarscov2/MN908947.3.gff3"
params.save_mpileup = true
def ref = file("${launchDir}/tests/data/fasta/sarscov2/MN908947.3.fa", checkIfExists: true)
def gff = file(params.gff, checkIfExists: true)
def input = []
input = [ [ id:'test'],
file("${launchDir}/tests/data/bam/test-sc2-artic-v3-sorted-trimmed.bam", checkIfExists: true) ]
IVAR_VARIANTS ( input, ref, gff )
}

View file

@ -0,0 +1,30 @@
- name: ivar variants no gff no mpileup
command: nextflow run ./tests/software/ivar/variants -entry test_ivar_variants_no_gff_no_mpileup -c tests/config/nextflow.config
tags:
- ivar
- ivar_variants
files:
- path: output/ivar/test.tsv
md5sum: 3fd376b8ad80f27a999edf3345d2014a
- name: ivar variants no gff with mpileup
command: nextflow run ./tests/software/ivar/variants -entry test_ivar_variants_no_gff_with_mpileup -c tests/config/nextflow.config --save_mpileup
tags:
- ivar
- ivar_variants
files:
- path: output/ivar/test.tsv
md5sum: 3fd376b8ad80f27a999edf3345d2014a
- path: output/ivar/test.mpileup
md5sum: b3dfd337dfcd313d6cc9680d7e796fe6
- name: ivar variants with gff with mpileup
command: nextflow run ./tests/software/ivar/variants -entry test_ivar_variants_with_gff_with_mpileup -c tests/config/nextflow.config --gff tests/data/gff/sarscov2/MN908947.3.gff3 --save_mpileup
tags:
- ivar
- ivar_variants
files:
- path: output/ivar/test.tsv
md5sum: 3fd376b8ad80f27a999edf3345d2014a
- path: output/ivar/test.mpileup
md5sum: b3dfd337dfcd313d6cc9680d7e796fe6