Rewritten module fgbio/fastqtobam (#916)

* added template for fastqtobam

* porting old code into new template

* update with missing getprocessname function

* test completed - updating all

* fixed linting issues

* improved reading

Co-authored-by: FriederikeHanssen <Friederike.hanssen@qbic.uni-tuebingen.de>

Co-authored-by: FriederikeHanssen <Friederike.hanssen@qbic.uni-tuebingen.de>
This commit is contained in:
Francesco L 2021-10-27 19:06:06 +02:00 committed by GitHub
parent 80d8e87fa4
commit a0bc08732c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 206 additions and 0 deletions

View 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"
}
}

View file

@ -0,0 +1,51 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process FGBIO_FASTQTOBAM {
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::fgbio=1.4.0" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/fgbio:1.4.0--hdfd78af_0"
} else {
container "quay.io/biocontainers/fgbio:1.4.0--hdfd78af_0"
}
input:
tuple val(meta), path(reads)
val(read_structure)
output:
tuple val(meta), path("*_umi_converted.bam"), emit: umibam
path "versions.yml" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
mkdir tmpFolder
fgbio \\
--tmp-dir=${PWD}/tmpFolder \\
FastqToBam \\
-i $reads \\
-o "${prefix}_umi_converted.bam" \\
--read-structures $read_structure \\
--sample $meta.id \\
--library $meta.id \\
$options.args
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( echo \$(fgbio --version 2>&1 | tr -d '[:cntrl:]' ) | sed -e 's/^.*Version: //;s/\\[.*\$//')
END_VERSIONS
"""
}

View file

@ -0,0 +1,47 @@
name: fgbio_fastqtobam
description: |
Using the FGBIO tools, converts FASTQ files sequenced with UMIs into BAM files, moving the UMI barcode into the RX field of the BAM file
keywords:
- fastqtobam
- fgbio
tools:
- fgbio:
description: A set of tools for working with genomic and high throughput sequencing data, including UMIs
homepage: http://fulcrumgenomics.github.io/fgbio/
documentation: http://fulcrumgenomics.github.io/fgbio/tools/latest/
tool_dev_url: https://github.com/fulcrumgenomics/fgbio
doi: ""
licence: ['MIT']
input:
- reads:
type: file
description: pair of reads to be converted into BAM file
pattern: "*.{fastq.gz}"
- read_structure:
type: string
description: |
A read structure should always be provided for each of the fastq files.
If single end, the string will contain only one structure (i.e. "2M11S+T"), if paired-end the string
will contain two structures separated by a blank space (i.e. "2M11S+T 2M11S+T").
If the read does not contain any UMI, the structure will be +T (i.e. only template of any length).
https://github.com/fulcrumgenomics/fgbio/wiki/Read-Structures
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.yml}"
- umibam:
type: file
description: Converted, unsorted BAM file with RX tag reporting UMI sequence (if any)
pattern: "*.{bam}"
authors:
- "@lescai"

View file

@ -378,6 +378,10 @@ fgbio/callmolecularconsensusreads:
- modules/fgbio/callmolecularconsensusreads/** - modules/fgbio/callmolecularconsensusreads/**
- tests/modules/fgbio/callmolecularconsensusreads/** - tests/modules/fgbio/callmolecularconsensusreads/**
fgbio/fastqtobam:
- modules/fgbio/fastqtobam/**
- tests/modules/fgbio/fastqtobam/**
fgbio/sortbam: fgbio/sortbam:
- modules/fgbio/sortbam/** - modules/fgbio/sortbam/**
- tests/modules/fgbio/sortbam/** - tests/modules/fgbio/sortbam/**

View file

@ -0,0 +1,16 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
params.read_structure = "+T 12M11S+T"
include { FGBIO_FASTQTOBAM } from '../../../../modules/fgbio/fastqtobam/main.nf' addParams( options: [:] )
workflow test_fgbio_fastqtobam {
input = [ [ id:'test', single_end:false ], // meta map
[ file(params.test_data['homo_sapiens']['illumina']['test_umi_1_fastq_gz'], checkIfExists: true),
file(params.test_data['homo_sapiens']['illumina']['test_umi_2_fastq_gz'], checkIfExists: true) ]
]
FGBIO_FASTQTOBAM ( input, "${params.read_structure}" )
}

View file

@ -0,0 +1,10 @@
- name: fgbio fastqtobam test_fgbio_fastqtobam
command: nextflow run tests/modules/fgbio/fastqtobam -entry test_fgbio_fastqtobam -c tests/config/nextflow.config
tags:
- fgbio/fastqtobam
- fgbio
files:
- path: output/fgbio/test_umi_converted.bam
md5sum: 9510735554e5eff29244077a72075fb6
- path: output/fgbio/versions.yml
md5sum: 524815093b96759060d0d800fc6a3f25