Fgbio group reads by umi (#952)

* adding template for module groupreadsbyumi

* update modules with code

* strategy is required argument so moving it to input rather than options.args

* tests successful committing yml

* added meta to output

Co-authored-by: Gregor Sturm <mail@gregor-sturm.de>
This commit is contained in:
Francesco L 2021-10-29 14:00:54 +02:00 committed by GitHub
parent 84cb78cc98
commit 460a3ed87b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 216 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,50 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process FGBIO_GROUPREADSBYUMI {
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(taggedbam)
val(strategy)
output:
tuple val(meta), path("*_umi-grouped.bam") , emit: bam
tuple val(meta), path("*_umi_histogram.txt"), emit: histogram
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
mkdir tmp
fgbio \\
--tmp-dir=${PWD}/tmp \\
GroupReadsByUmi \\
-s $strategy \\
${options.args} \\
-i $taggedbam \\
-o ${prefix}_umi-grouped.bam \\
-f ${prefix}_umi_histogram.txt
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,59 @@
name: fgbio_groupreadsbyumi
description: |
Groups reads together that appear to have come from the same original molecule.
Reads are grouped by template, and then templates are sorted by the 5 mapping positions
of the reads from the template, used from earliest mapping position to latest.
Reads that have the same end positions are then sub-grouped by UMI sequence.
(!) Note: the MQ tag is required on reads with mapped mates (!)
This can be added using samblaster with the optional argument --addMateTags.
keywords:
- UMI
- groupreads
- 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:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: |
BAM file. Note: the MQ tag is required on reads with mapped mates (!)
pattern: "*.bam"
- strategy:
type: value
description: |
Reguired argument: defines the UMI assignment strategy.
Must be chosen among: Identity, Edit, Adjacency, Paired.
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"
- bam:
type: file
description: UMI-grouped BAM
pattern: "*.bam"
- histogram:
type: file
description: A text file containing the tag family size counts
pattern: "*.txt"
authors:
- "@lescai"

View file

@ -394,6 +394,10 @@ fgbio/fastqtobam:
- modules/fgbio/fastqtobam/** - modules/fgbio/fastqtobam/**
- tests/modules/fgbio/fastqtobam/** - tests/modules/fgbio/fastqtobam/**
fgbio/groupreadsbyumi:
- modules/fgbio/groupreadsbyumi/**
- tests/modules/fgbio/groupreadsbyumi/**
fgbio/sortbam: fgbio/sortbam:
- modules/fgbio/sortbam/** - modules/fgbio/sortbam/**
- tests/modules/fgbio/sortbam/** - tests/modules/fgbio/sortbam/**

View file

@ -0,0 +1,15 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { FGBIO_GROUPREADSBYUMI } from '../../../../modules/fgbio/groupreadsbyumi/main.nf' addParams( options: [:] )
workflow test_fgbio_groupreadsbyumi {
input = [ [ id:'test', single_end:false ], // meta map
file(params.test_data['homo_sapiens']['illumina']['test_paired_end_umi_unsorted_tagged_bam'], checkIfExists: true) ]
strategy = "Adjacency"
FGBIO_GROUPREADSBYUMI ( input, strategy )
}

View file

@ -0,0 +1,10 @@
- name: fgbio groupreadsbyumi test_fgbio_groupreadsbyumi
command: nextflow run tests/modules/fgbio/groupreadsbyumi -entry test_fgbio_groupreadsbyumi -c tests/config/nextflow.config
tags:
- fgbio
- fgbio/groupreadsbyumi
files:
- path: output/fgbio/test_umi-grouped.bam
md5sum: f1e53fc845fd99a3da172eb8063dff0b
- path: output/fgbio/test_umi_histogram.txt
md5sum: d17fd167b2a765d46e4b01bf08ece01b