add bedtools bamtobed module (from nanoseq modules) (#466)

* add bedtools bamtobed module

* fix erros

* fix linting problem
This commit is contained in:
Yuk Kei Wan 2021-04-30 20:20:31 +08:00 committed by GitHub
parent a8720463ac
commit 3f804ee667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 171 additions and 0 deletions

View file

@ -0,0 +1,70 @@
/*
* -----------------------------------------------------
* 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_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) {
if (!args.filename.endsWith('.version.txt')) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
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,34 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
def options = initOptions(params.options)
process BEDTOOLS_BAMTOBED {
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), meta:meta, publish_by_meta:['id']) }
conda (params.enable_conda ? "bioconda::bedtools=2.29.2" : null)
container "quay.io/biocontainers/bedtools:2.29.2--hc088bd4_0"
input:
tuple val(meta), path(sizes), path(bam), path(bai)
output:
tuple val(meta), path(sizes), path("*.bed12"), emit: bed12
path "*.version.txt" , emit: version
script:
"""
bedtools \\
bamtobed \\
-bed12 \\
-cigar \\
-i ${bam[0]} \\
| bedtools sort > ${meta.id}.bed12
bedtools --version | sed -e "s/bedtools v//g" > bedtools.version.txt
"""
}

View file

@ -0,0 +1,40 @@
name: bedtools_bamtobed
description: Converts a bam file to a bed12 file.
keywords:
- bam
- bed
tools:
- bedtools:
description: |
A set of tools for genomic analysis tasks, specifically enabling genome arithmetic (merge, count, complement) on various file types.
documentation: https://bedtools.readthedocs.io/en/latest/content/tools/complement.html
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: Input BAM file
pattern: "*.{bam}"
- sizes:
type: file
description: File which defines the chromosome lengths for a given genome
pattern: "*.{sizes}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bed12:
type: file
description: Bed file with 12 columns containing all genomic intervals.
pattern: "*.{bed}"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@yuukiiwa"

View file

@ -42,6 +42,10 @@ bcftools/stats:
- software/bcftools/stats/**
- tests/software/bcftools/stats/**
bedtools/bamtobed:
- software/bedtools/bamtobed/**
- tests/software/bedtools/bamtobed/**
bedtools/complement:
- software/bedtools/complement/**
- tests/software/bedtools/complement/**

View file

@ -0,0 +1,15 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { BEDTOOLS_BAMTOBED } from '../../../../software/bedtools/bamtobed/main.nf' addParams( options: [:] )
workflow test_bedtools_bamtobed {
input = [ [ id:'test'], //meta map
file(params.test_data['sarscov2']['genome']['genome_sizes'], checkIfExists: true),
file(params.test_data['sarscov2']['nanopore']['test_sorted_bam'], checkIfExists: true),
file(params.test_data['sarscov2']['nanopore']['test_sorted_bam_bai'], checkIfExists: true)
]
BEDTOOLS_BAMTOBED ( input )
}

View file

@ -0,0 +1,8 @@
- name: bedtools bamtobed
command: nextflow run ./tests/software/bedtools/bamtobed -entry test_bedtools_bamtobed -c tests/config/nextflow.config
tags:
- bedtools
- bedtools/bamtobed
files:
- path: ./output/bedtools/test.bed12
md5sum: d41d8cd98f00b204e9800998ecf8427e