mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 19:18:17 +00:00
add samtools merge (#296)
* add samtools merge * Update pytest_software.yml * get it back to 20.11.0-edge * Update test.yml * Update test.yml * Update test.yml * Update test.yml
This commit is contained in:
parent
f9ce8664ba
commit
134c8ef6ce
5 changed files with 121 additions and 0 deletions
59
software/samtools/merge/functions.nf
Normal file
59
software/samtools/merge/functions.nf
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* -----------------------------------------------------
|
||||||
|
* 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.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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
software/samtools/merge/main.nf
Normal file
35
software/samtools/merge/main.nf
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// Import generic module functions
|
||||||
|
include { initOptions; saveFiles; getSoftwareName } from './functions'
|
||||||
|
|
||||||
|
params.options = [:]
|
||||||
|
options = initOptions(params.options)
|
||||||
|
|
||||||
|
process SAMTOOLS_MERGE {
|
||||||
|
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.10" : null)
|
||||||
|
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||||
|
container "https://depot.galaxyproject.org/singularity/samtools:1.10--h9402c20_2"
|
||||||
|
} else {
|
||||||
|
container "quay.io/biocontainers/samtools:1.10--h9402c20_2"
|
||||||
|
}
|
||||||
|
|
||||||
|
input:
|
||||||
|
tuple val(meta),path(bams)
|
||||||
|
|
||||||
|
output:
|
||||||
|
tuple val(meta), path("*merged.bam"), emit: merged_bam
|
||||||
|
path "*.version.txt" , emit: version
|
||||||
|
|
||||||
|
script:
|
||||||
|
def software = getSoftwareName(task.process)
|
||||||
|
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||||
|
"""
|
||||||
|
samtools merge ${prefix}_merged.bam $bams
|
||||||
|
echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' > ${software}.version.txt
|
||||||
|
"""
|
||||||
|
}
|
|
@ -295,6 +295,10 @@ samtools_mpileup:
|
||||||
- software/samtools/mpileup/**
|
- software/samtools/mpileup/**
|
||||||
- tests/software/samtools/mpileup/**
|
- tests/software/samtools/mpileup/**
|
||||||
|
|
||||||
|
samtools_merge:
|
||||||
|
- software/samtools/merge/**
|
||||||
|
- tests/software/samtools/merge/**
|
||||||
|
|
||||||
samtools_sort:
|
samtools_sort:
|
||||||
- software/samtools/sort/**
|
- software/samtools/sort/**
|
||||||
- tests/software/samtools/sort/**
|
- tests/software/samtools/sort/**
|
||||||
|
|
16
tests/software/samtools/merge/main.nf
Normal file
16
tests/software/samtools/merge/main.nf
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env nextflow
|
||||||
|
|
||||||
|
nextflow.enable.dsl = 2
|
||||||
|
|
||||||
|
include { SAMTOOLS_MERGE } from '../../../../software/samtools/merge/main.nf' addParams( options: [:] )
|
||||||
|
|
||||||
|
workflow test_samtools_merge {
|
||||||
|
|
||||||
|
def input = []
|
||||||
|
input = [ [ id: 'test' ], // meta map
|
||||||
|
[ file("${launchDir}/tests/data/genomics/sarscov2/bam/test_methylated_paired_end.sorted.bam", checkIfExists: true ),
|
||||||
|
file("${launchDir}/tests/data/genomics/sarscov2/bam/test_paired_end.sorted.bam", checkIfExists: true),
|
||||||
|
file("${launchDir}/tests/data/genomics/sarscov2/bam/test_single_end.sorted.bam", checkIfExists: true) ] ]
|
||||||
|
|
||||||
|
SAMTOOLS_MERGE ( input )
|
||||||
|
}
|
7
tests/software/samtools/merge/test.yml
Normal file
7
tests/software/samtools/merge/test.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- name: samtools merge
|
||||||
|
command: nextflow run ./tests/software/samtools/merge -entry test_samtools_merge -c tests/config/nextflow.config
|
||||||
|
tags:
|
||||||
|
- samtools
|
||||||
|
- samtools_merge
|
||||||
|
files:
|
||||||
|
- path: output/samtools/test_merged.bam
|
Loading…
Reference in a new issue