mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-11-14 05:43:08 +00:00
New module: freebayes (#818)
* add pydamage module Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>
This commit is contained in:
parent
97fe899f79
commit
eb04a0f1f6
6 changed files with 289 additions and 0 deletions
78
modules/freebayes/functions.nf
Normal file
78
modules/freebayes/functions.nf
Normal file
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// 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()
|
||||
}
|
||||
|
||||
//
|
||||
// Extract name of module from process name using $task.process
|
||||
//
|
||||
def getProcessName(task_process) {
|
||||
return task_process.tokenize(':')[-1]
|
||||
}
|
||||
|
||||
//
|
||||
// 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.args3 = args.args3 ?: ''
|
||||
options.publish_by_meta = args.publish_by_meta ?: []
|
||||
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) {
|
||||
def ioptions = initOptions(args.options)
|
||||
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
|
||||
|
||||
// Do not publish versions.yml unless running from pytest workflow
|
||||
if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) {
|
||||
return null
|
||||
}
|
||||
if (ioptions.publish_by_meta) {
|
||||
def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta
|
||||
for (key in key_list) {
|
||||
if (args.meta && key instanceof String) {
|
||||
def path = key
|
||||
if (args.meta.containsKey(key)) {
|
||||
path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key]
|
||||
}
|
||||
path = path instanceof String ? path : ''
|
||||
path_list.add(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
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"
|
||||
}
|
||||
}
|
79
modules/freebayes/main.nf
Normal file
79
modules/freebayes/main.nf
Normal file
|
@ -0,0 +1,79 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getProcessName; getSoftwareName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process FREEBAYES {
|
||||
tag "$meta.id"
|
||||
label 'process_low'
|
||||
publishDir "${params.outdir}",
|
||||
mode: params.publish_dir_mode,
|
||||
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) }
|
||||
|
||||
conda (params.enable_conda ? "bioconda::freebayes=1.3.5" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/freebayes:1.3.5--py38ha193a2f_3"
|
||||
} else {
|
||||
container "quay.io/biocontainers/freebayes:1.3.5--py38ha193a2f_3"
|
||||
}
|
||||
|
||||
input:
|
||||
tuple val(meta), path(bam), path(bai)
|
||||
tuple path(fasta), path(fai)
|
||||
path(targets)
|
||||
path(samples)
|
||||
path(populations)
|
||||
path(cnv)
|
||||
|
||||
|
||||
output:
|
||||
tuple val(meta), path("*.vcf.gz") , emit: vcf
|
||||
path "versions.yml" , emit: versions
|
||||
|
||||
script:
|
||||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||
def targets_file = targets ? "--target ${targets}" : ""
|
||||
def samples_file = samples ? "--samples ${samples}" : ""
|
||||
def populations_file = populations ? "--populations ${populations}" : ""
|
||||
def cnv_file = cnv ? "--cnv-map ${cnv}" : ""
|
||||
if (task.cpus > 1) {
|
||||
"""
|
||||
freebayes-parallel \\
|
||||
<(fasta_generate_regions.py ${fasta}.fai 10000) ${task.cpus} \\
|
||||
-f $fasta \\
|
||||
$targets_file \\
|
||||
$samples_file \\
|
||||
$populations_file \\
|
||||
$cnv_file \\
|
||||
$options.args \\
|
||||
$bam > ${prefix}.vcf
|
||||
|
||||
gzip --no-name ${prefix}.vcf
|
||||
|
||||
cat <<-END_VERSIONS > versions.yml
|
||||
${getProcessName(task.process)}:
|
||||
${getSoftwareName(task.process)}: \$(echo \$(freebayes --version 2>&1) | sed 's/version:\s*v//g' )
|
||||
END_VERSIONS
|
||||
"""
|
||||
|
||||
} else {
|
||||
"""
|
||||
freebayes \\
|
||||
-f $fasta \\
|
||||
$targets_file \\
|
||||
$samples_file \\
|
||||
$populations_file \\
|
||||
$cnv_file \\
|
||||
$options.args \\
|
||||
$bam > ${prefix}.vcf
|
||||
|
||||
gzip --no-name ${prefix}.vcf
|
||||
|
||||
cat <<-END_VERSIONS > versions.yml
|
||||
${getProcessName(task.process)}:
|
||||
${getSoftwareName(task.process)}: \$(echo \$(freebayes --version 2>&1) | sed 's/version:\s*v//g' )
|
||||
END_VERSIONS
|
||||
"""
|
||||
}
|
||||
}
|
78
modules/freebayes/meta.yml
Normal file
78
modules/freebayes/meta.yml
Normal file
|
@ -0,0 +1,78 @@
|
|||
name: freebayes
|
||||
description: A haplotype-based variant detector
|
||||
keywords:
|
||||
- variant caller
|
||||
- SNP
|
||||
- genotyping
|
||||
- variant calling
|
||||
- bayesian
|
||||
tools:
|
||||
- freebayes:
|
||||
description: Bayesian haplotype-based polymorphism discovery and genotyping
|
||||
homepage: https://github.com/freebayes/freebayes
|
||||
documentation: https://github.com/freebayes/freebayes
|
||||
tool_dev_url: https://github.com/freebayes/freebayes
|
||||
doi: ""
|
||||
licence: ['MIT']
|
||||
|
||||
input:
|
||||
- meta:
|
||||
type: map
|
||||
description: |
|
||||
Groovy Map containing sample information
|
||||
e.g. [ id:'test', single_end:false ]
|
||||
- bam:
|
||||
type: file
|
||||
description: BAM/CRAM/SAM file
|
||||
pattern: "*.{bam,cram,sam}"
|
||||
- bai:
|
||||
type: file
|
||||
description: BAM/CRAM/SAM index file
|
||||
pattern: "*.bam.bai"
|
||||
- fasta:
|
||||
type: file
|
||||
description: reference fasta file
|
||||
pattern: ".{fa,fa.gz,fasta,fasta.gz}"
|
||||
- fai:
|
||||
type: file
|
||||
description: reference fasta file index
|
||||
pattern: "*.fai"
|
||||
- targets:
|
||||
type: file
|
||||
description: Optional - Limit analysis to targets listed in this BED-format FILE.
|
||||
pattern: "*.bed"
|
||||
- samples:
|
||||
type: file
|
||||
description: Optional - Limit analysis to samples listed (one per line) in the FILE.
|
||||
pattern: "*.txt"
|
||||
- populations:
|
||||
type: file
|
||||
description: Optional - Each line of FILE should list a sample and a population which it is part of.
|
||||
pattern: "*.txt"
|
||||
- cnv:
|
||||
type: file
|
||||
description: |
|
||||
A copy number map BED file, which has
|
||||
either a sample-level ploidy:
|
||||
sample_name copy_number
|
||||
or a region-specific format:
|
||||
seq_name start end sample_name copy_number
|
||||
pattern: "*.bed"
|
||||
|
||||
|
||||
output:
|
||||
- meta:
|
||||
type: map
|
||||
description: |
|
||||
Groovy Map containing sample information
|
||||
e.g. [ id:'test', single_end:false ]
|
||||
- version:
|
||||
type: file
|
||||
description: File containing software version
|
||||
pattern: "*.{version.txt}"
|
||||
- vcf:
|
||||
type: file
|
||||
description: Compressed VCF file
|
||||
pattern: "*.vcf.gz"
|
||||
authors:
|
||||
- "@maxibor"
|
|
@ -382,6 +382,10 @@ flash:
|
|||
- modules/flash/**
|
||||
- tests/modules/flash/**
|
||||
|
||||
freebayes:
|
||||
- modules/freebayes/**
|
||||
- tests/modules/freebayes/**
|
||||
|
||||
gatk4/applybqsr:
|
||||
- modules/gatk4/applybqsr/**
|
||||
- tests/modules/gatk4/applybqsr/**
|
||||
|
|
35
tests/modules/freebayes/main.nf
Normal file
35
tests/modules/freebayes/main.nf
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { FREEBAYES } from '../../../modules/freebayes/main.nf' addParams( options: [:] )
|
||||
|
||||
workflow test_freebayes {
|
||||
|
||||
input = [ [ id:'test', single_end:false ], // meta map
|
||||
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
|
||||
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true)]
|
||||
reference = [file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true),
|
||||
file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true)]
|
||||
targets = []
|
||||
samples = []
|
||||
populations = []
|
||||
cnv = []
|
||||
|
||||
FREEBAYES ( input, reference, targets, samples, populations, cnv)
|
||||
}
|
||||
|
||||
workflow test_freebayes_bed {
|
||||
|
||||
input = [ [ id:'test', single_end:false ], // meta map
|
||||
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
|
||||
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true)]
|
||||
reference = [file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true),
|
||||
file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true)]
|
||||
targets = file(params.test_data['sarscov2']['genome']['test_bed'], checkIfExists: true)
|
||||
samples = []
|
||||
populations = []
|
||||
cnv = []
|
||||
|
||||
FREEBAYES ( input, reference, targets, samples, populations, cnv)
|
||||
}
|
15
tests/modules/freebayes/test.yml
Normal file
15
tests/modules/freebayes/test.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
- name: freebayes test_freebayes
|
||||
command: nextflow run tests/modules/freebayes -entry test_freebayes -c tests/config/nextflow.config
|
||||
tags:
|
||||
- freebayes
|
||||
files:
|
||||
- path: output/freebayes/test.vcf.gz
|
||||
md5sum: e8de5fe0025e331b939c2a849290f325
|
||||
|
||||
- name: freebayes test_freebayes_bed
|
||||
command: nextflow run tests/modules/freebayes -entry test_freebayes_bed -c tests/config/nextflow.config
|
||||
tags:
|
||||
- freebayes
|
||||
files:
|
||||
- path: output/freebayes/test.vcf.gz
|
||||
md5sum: 1c41cbec0cfa15002ce91b869ce9d519
|
Loading…
Reference in a new issue