mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 11:08:17 +00:00
module: picard sortsam (#603)
* Add picard/sortsam module * Fix container links * Changes after code review * Input meta in the right place
This commit is contained in:
parent
f892f273fe
commit
1a26d48104
6 changed files with 190 additions and 0 deletions
68
modules/picard/sortsam/functions.nf
Normal file
68
modules/picard/sortsam/functions.nf
Normal file
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// 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"
|
||||
}
|
||||
}
|
||||
}
|
49
modules/picard/sortsam/main.nf
Normal file
49
modules/picard/sortsam/main.nf
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process PICARD_SORTSAM {
|
||||
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::picard=2.25.6" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/picard:2.25.6--hdfd78af_0"
|
||||
} else {
|
||||
container "quay.io/biocontainers/picard:2.25.6--hdfd78af_0"
|
||||
}
|
||||
|
||||
input:
|
||||
tuple val(meta), path(bam)
|
||||
val sort_order
|
||||
|
||||
output:
|
||||
tuple val(meta), path("*.sorted.bam"), emit: bam
|
||||
path "*.version.txt" , emit: version
|
||||
|
||||
script:
|
||||
def software = getSoftwareName(task.process)
|
||||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||
def avail_mem = 3
|
||||
if (!task.memory) {
|
||||
log.info '[Picard SortSam] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.'
|
||||
} else {
|
||||
avail_mem = task.memory.giga
|
||||
}
|
||||
"""
|
||||
picard \\
|
||||
SortSam \\
|
||||
-Xmx${avail_mem}g \\
|
||||
--INPUT $bam \\
|
||||
--OUTPUT ${prefix}.sorted.bam \\
|
||||
--SORT_ORDER $sort_order
|
||||
|
||||
echo \$(picard SortSam --version 2>&1) | grep -o 'Version:.*' | cut -f2- -d: > ${software}.version.txt
|
||||
"""
|
||||
}
|
47
modules/picard/sortsam/meta.yml
Normal file
47
modules/picard/sortsam/meta.yml
Normal file
|
@ -0,0 +1,47 @@
|
|||
name: picard_sortsam
|
||||
description: Sorts BAM/SAM files based on a variety of picard specific criteria
|
||||
keywords:
|
||||
- sort
|
||||
- bam
|
||||
- sam
|
||||
tools:
|
||||
- picard:
|
||||
description: |
|
||||
A set of command line tools (in Java) for manipulating high-throughput sequencing (HTS)
|
||||
data and formats such as SAM/BAM/CRAM and VCF.
|
||||
homepage: https://broadinstitute.github.io/picard/
|
||||
documentation: https://broadinstitute.github.io/picard/
|
||||
|
||||
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,sam}"
|
||||
- sort_order:
|
||||
type: value
|
||||
description: Picard sort order type
|
||||
pattern: "unsorted|queryname|coordinate|duplicate|unknown"
|
||||
|
||||
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.txt}"
|
||||
- bam:
|
||||
type: file
|
||||
description: Sorted BAM/CRAM/SAM file
|
||||
pattern: "*sorted.{bam}"
|
||||
|
||||
|
||||
authors:
|
||||
- "@jfy133"
|
|
@ -567,6 +567,10 @@ picard/mergesamfiles:
|
|||
- modules/picard/mergesamfiles/**
|
||||
- tests/modules/picard/mergesamfiles/**
|
||||
|
||||
picard/sortsam:
|
||||
- modules/picard/sortsam/**
|
||||
- tests/modules/picard/sortsam/**
|
||||
|
||||
plasmidid:
|
||||
- modules/plasmidid/**
|
||||
- tests/modules/plasmidid/**
|
||||
|
|
14
tests/modules/picard/sortsam/main.nf
Normal file
14
tests/modules/picard/sortsam/main.nf
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { PICARD_SORTSAM } from '../../../../modules/picard/sortsam/main.nf' addParams( options: [:] )
|
||||
|
||||
workflow test_picard_sortsam {
|
||||
|
||||
input = [ [ id:'test', single_end:false ], // meta map
|
||||
file(params.test_data['sarscov2']['illumina']['test_single_end_bam'], checkIfExists: true) ]
|
||||
sort_order = "queryname"
|
||||
|
||||
PICARD_SORTSAM ( input, sort_order )
|
||||
}
|
8
tests/modules/picard/sortsam/test.yml
Normal file
8
tests/modules/picard/sortsam/test.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
- name: picard sortsam
|
||||
command: nextflow run ./tests/modules/picard/sortsam -entry test_picard_sortsam -c tests/config/nextflow.config
|
||||
tags:
|
||||
- picard
|
||||
- picard/sortsam
|
||||
files:
|
||||
- path: output/picard/test.sorted.bam
|
||||
md5sum: b44a6ca04811a9470c7813c3c9465fd5
|
Loading…
Reference in a new issue