mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 11:08:17 +00:00
Picard/collecthsmetrics (#927)
* added template
* integrated module
* added fasta index info
* test works, have placeholder data for baits until test-data PR is merged
* added new files to config
* updated test files
* fixing fails ✨
* okay final fix here on the md5sum :face_palm:
* md5sum variable
* update meta.yml to reflect consistency to main.nf
* reverted version so conda works
* Apply suggestions from code review
Co-authored-by: Sébastien Guizard <sguizard@ed.ac.uk>
* md5sum can't be generated consistently for output
Co-authored-by: Sébastien Guizard <sguizard@ed.ac.uk>
This commit is contained in:
parent
1abe23e159
commit
7fdeed5b79
7 changed files with 235 additions and 0 deletions
78
modules/picard/collecthsmetrics/functions.nf
Normal file
78
modules/picard/collecthsmetrics/functions.nf
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
58
modules/picard/collecthsmetrics/main.nf
Normal file
58
modules/picard/collecthsmetrics/main.nf
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// Import generic module functions
|
||||||
|
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
|
||||||
|
|
||||||
|
params.options = [:]
|
||||||
|
options = initOptions(params.options)
|
||||||
|
|
||||||
|
process PICARD_COLLECTHSMETRICS {
|
||||||
|
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::picard=2.26.2" : null)
|
||||||
|
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||||
|
container "https://depot.galaxyproject.org/singularity/picard:2.26.2--hdfd78af_0"
|
||||||
|
} else {
|
||||||
|
container "quay.io/biocontainers/picard:2.26.2--hdfd78af_0"
|
||||||
|
}
|
||||||
|
|
||||||
|
input:
|
||||||
|
tuple val(meta), path(bam)
|
||||||
|
path fasta
|
||||||
|
path fai
|
||||||
|
path bait_intervals
|
||||||
|
path target_intervals
|
||||||
|
|
||||||
|
output:
|
||||||
|
tuple val(meta), path("*collecthsmetrics.txt"), emit: hs_metrics
|
||||||
|
path "versions.yml" , emit: versions
|
||||||
|
|
||||||
|
script:
|
||||||
|
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||||
|
def reference = fasta ? "-R $fasta" : ""
|
||||||
|
|
||||||
|
def avail_mem = 3
|
||||||
|
if (!task.memory) {
|
||||||
|
log.info '[Picard CollectHsMetrics] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.'
|
||||||
|
} else {
|
||||||
|
avail_mem = task.memory.giga
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
picard \\
|
||||||
|
-Xmx${avail_mem}g \\
|
||||||
|
CollectHsMetrics \\
|
||||||
|
$options.args \\
|
||||||
|
$reference \\
|
||||||
|
-BAIT_INTERVALS $bait_intervals \\
|
||||||
|
-TARGET_INTERVALS $target_intervals \\
|
||||||
|
-INPUT $bam \\
|
||||||
|
-OUTPUT ${prefix}_collecthsmetrics.txt
|
||||||
|
|
||||||
|
cat <<-END_VERSIONS > versions.yml
|
||||||
|
${getProcessName(task.process)}:
|
||||||
|
${getSoftwareName(task.process)}: \$(echo \$(picard CollectHsMetrics --version 2>&1) | grep -o 'Version:.*' | cut -f2- -d:)
|
||||||
|
END_VERSIONS
|
||||||
|
"""
|
||||||
|
}
|
66
modules/picard/collecthsmetrics/meta.yml
Normal file
66
modules/picard/collecthsmetrics/meta.yml
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
name: picard_collecthsmetrics
|
||||||
|
description: Collects hybrid-selection (HS) metrics for a SAM or BAM file.
|
||||||
|
keywords:
|
||||||
|
- alignment
|
||||||
|
- metrics
|
||||||
|
- statistics
|
||||||
|
- insert
|
||||||
|
- hybrid-selection
|
||||||
|
- quality
|
||||||
|
- bam
|
||||||
|
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/
|
||||||
|
tool_dev_url: https://github.com/broadinstitute/picard/
|
||||||
|
licence: ["MIT"]
|
||||||
|
|
||||||
|
input:
|
||||||
|
- meta:
|
||||||
|
type: map
|
||||||
|
description: |
|
||||||
|
Groovy Map containing sample information
|
||||||
|
e.g. [ id:'test', single_end:false ]
|
||||||
|
- bam:
|
||||||
|
type: file
|
||||||
|
description: An aligned BAM/SAM file
|
||||||
|
pattern: "*.{bam,sam}"
|
||||||
|
- fasta:
|
||||||
|
type: file
|
||||||
|
description: |
|
||||||
|
A reference file to calculate dropout metrics measuring reduced representation of reads.
|
||||||
|
Optional input.
|
||||||
|
pattern: "*.fasta"
|
||||||
|
- fai:
|
||||||
|
type: file
|
||||||
|
description: Index of FASTA file. Only needed when fasta is supplied.
|
||||||
|
pattern: "*.fai"
|
||||||
|
- bait_intervals:
|
||||||
|
type: file
|
||||||
|
description: An interval list file that contains the locations of the baits used.
|
||||||
|
pattern: "baits.interval_list"
|
||||||
|
- target_intervals:
|
||||||
|
type: file
|
||||||
|
description: An interval list file that contains the locations of the targets.
|
||||||
|
pattern: "targets.interval_list"
|
||||||
|
|
||||||
|
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"
|
||||||
|
- hs_metrics:
|
||||||
|
type: file
|
||||||
|
description: The metrics file.
|
||||||
|
pattern: "*_collecthsmetrics.txt"
|
||||||
|
|
||||||
|
authors:
|
||||||
|
- "@projectoriented"
|
|
@ -908,6 +908,10 @@ pbccs:
|
||||||
- modules/pbccs/**
|
- modules/pbccs/**
|
||||||
- tests/modules/pbccs/**
|
- tests/modules/pbccs/**
|
||||||
|
|
||||||
|
picard/collecthsmetrics:
|
||||||
|
- modules/picard/collecthsmetrics/**
|
||||||
|
- tests/modules/picard/collecthsmetrics/**
|
||||||
|
|
||||||
picard/collectmultiplemetrics:
|
picard/collectmultiplemetrics:
|
||||||
- modules/picard/collectmultiplemetrics/**
|
- modules/picard/collectmultiplemetrics/**
|
||||||
- tests/modules/picard/collectmultiplemetrics/**
|
- tests/modules/picard/collectmultiplemetrics/**
|
||||||
|
|
|
@ -34,6 +34,9 @@ params {
|
||||||
contigs_genome_maf_gz = "${test_data_dir}/genomics/sarscov2/genome/alignment/last/contigs.genome.maf.gz"
|
contigs_genome_maf_gz = "${test_data_dir}/genomics/sarscov2/genome/alignment/last/contigs.genome.maf.gz"
|
||||||
contigs_genome_par = "${test_data_dir}/genomics/sarscov2/genome/alignment/last/contigs.genome.par"
|
contigs_genome_par = "${test_data_dir}/genomics/sarscov2/genome/alignment/last/contigs.genome.par"
|
||||||
lastdb_tar_gz = "${test_data_dir}/genomics/sarscov2/genome/alignment/last/lastdb.tar.gz"
|
lastdb_tar_gz = "${test_data_dir}/genomics/sarscov2/genome/alignment/last/lastdb.tar.gz"
|
||||||
|
|
||||||
|
baits_interval_list = "${test_data_dir}/genomics/sarscov2/genome/picard/baits.interval_list"
|
||||||
|
targets_interval_list = "${test_data_dir}/genomics/sarscov2/genome/picard/targets.interval_list"
|
||||||
}
|
}
|
||||||
'illumina' {
|
'illumina' {
|
||||||
test_single_end_bam = "${test_data_dir}/genomics/sarscov2/illumina/bam/test.single_end.bam"
|
test_single_end_bam = "${test_data_dir}/genomics/sarscov2/illumina/bam/test.single_end.bam"
|
||||||
|
|
18
tests/modules/picard/collecthsmetrics/main.nf
Normal file
18
tests/modules/picard/collecthsmetrics/main.nf
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env nextflow
|
||||||
|
|
||||||
|
nextflow.enable.dsl = 2
|
||||||
|
|
||||||
|
include { PICARD_COLLECTHSMETRICS } from '../../../../modules/picard/collecthsmetrics/main.nf' addParams( options: [:] )
|
||||||
|
|
||||||
|
workflow test_picard_collecthsmetrics {
|
||||||
|
|
||||||
|
input = [ [ id:'test', single_end:false ], // meta map
|
||||||
|
file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) ]
|
||||||
|
|
||||||
|
fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
|
||||||
|
fai = file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true)
|
||||||
|
bait_intervals = file(params.test_data['sarscov2']['genome']['baits_interval_list'], checkIfExists: true)
|
||||||
|
target_intervals = file(params.test_data['sarscov2']['genome']['targets_interval_list'], checkIfExists: true)
|
||||||
|
|
||||||
|
PICARD_COLLECTHSMETRICS ( input, fasta, fai, bait_intervals, target_intervals )
|
||||||
|
}
|
8
tests/modules/picard/collecthsmetrics/test.yml
Normal file
8
tests/modules/picard/collecthsmetrics/test.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
- name: picard collecthsmetrics test_picard_collecthsmetrics
|
||||||
|
command: nextflow run tests/modules/picard/collecthsmetrics -entry test_picard_collecthsmetrics -c tests/config/nextflow.config
|
||||||
|
tags:
|
||||||
|
- picard
|
||||||
|
- picard/collecthsmetrics
|
||||||
|
files:
|
||||||
|
# The file can't be md5'd consistently
|
||||||
|
- path: output/picard/test_collecthsmetrics.txt
|
Loading…
Reference in a new issue