new module: samtools/fastq (#316)

* new module: samtools/fastq

* solve conflict: pytest_software.yml

* solve linting conflicts

* solved EditorConfig linting problem
This commit is contained in:
suzannejin 2021-03-23 12:13:07 +01:00 committed by GitHub
parent 569ff03af9
commit 9115c12f88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 169 additions and 0 deletions

View file

@ -0,0 +1,60 @@
/*
* -----------------------------------------------------
* 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.args3 = args.args3 ?: ''
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,40 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process SAMTOOLS_FASTQ {
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), publish_id:meta.id) }
conda (params.enable_conda ? "bioconda::samtools=1.12" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/samtools:1.12--hd5e65b6_0"
} else {
container "quay.io/biocontainers/samtools:1.12--hd5e65b6_0"
}
input:
tuple val(meta), path(bam)
output:
tuple val(meta), path("*.fastq"), emit: fastq
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
"""
samtools \\
fastq \\
$options.args \\
-@ $task.cpus \\
$bam \\
> ${bam}.fastq
echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,43 @@
name: samtools_fastq
description: Converts a SAM/BAM/CRAM file to FASTA or FASTQ
keywords:
- bam
- sam
- cram
- fasta
- fastq
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: hhttp://www.htslib.org/doc/samtools.html
doi: 10.1093/bioinformatics/btp352
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}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- fasta:
type: file
description: FASTA/FASTQ file
pattern: "*.{fasta,fastq}"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@suzannejin"

View file

@ -307,6 +307,10 @@ samtools_faidx:
- software/samtools/faidx/**
- tests/software/samtools/faidx/**
samtools_fastq:
- software/samtools/fastq/**
- tests/software/samtools/fastq/**
samtools_flagstat:
- software/samtools/flagstat/**
- tests/software/samtools/flagstat/**

View file

@ -0,0 +1,14 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { SAMTOOLS_FASTQ } from '../../../../software/samtools/fastq/main.nf' addParams( options: [:] )
workflow test_samtools_fastq {
def input = []
input = [ [ id:'test', single_end:false ], // meta map
file("${launchDir}/tests/data/genomics/sarscov2/bam/test_paired_end.sorted.bam", checkIfExists: true) ]
SAMTOOLS_FASTQ ( input )
}

View file

@ -0,0 +1,8 @@
- name: samtools fastq test_samtools_fastq
command: nextflow run tests/software/samtools/fastq -entry test_samtools_fastq -c tests/config/nextflow.config
tags:
- samtools_fastq
- samtools
files:
- path: output/samtools/test_paired_end.sorted.bam.fastq
md5sum: 4863ac55a2781962dba179a929673535