Add pydamage analyze module (#705)

* add pydamage module

* remove TODOs

* split module by subcommands

* update version parsing

* remove forgotten TODOs

* update module names

* remove old holistic module

* Update modules/pydamage/analyze/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* add keywords

* simplify PR to analyze subcommand

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>
This commit is contained in:
Maxime Borry 2021-09-16 14:03:51 +02:00 committed by GitHub
parent bbf268c5d3
commit d9dfbe9d9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 189 additions and 0 deletions

View 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"
}
}
}

View file

@ -0,0 +1,40 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process PYDAMAGE_ANALYZE {
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::pydamage=0.62" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/pydamage:0.62--pyhdfd78af_0"
} else {
container "quay.io/biocontainers/pydamage:0.62--pyhdfd78af_0"
}
input:
tuple val(meta), path(bam), path(bai)
output:
tuple val(meta), path("pydamage_results/pydamage_results.csv"), emit: csv
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
pydamage \\
analyze \\
$options.args \\
-p $task.cpus \\
$bam
echo \$(pydamage --version 2>&1) | sed -e 's/pydamage, version //g' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,55 @@
name: pydamage_analyze
description: Damage parameter estimation for ancient DNA
keywords:
- ancient DNA
- aDNA
- de novo assembly
- filtering
- damage
- deamination
- miscoding lesions
- C to T
- palaeogenomics
- archaeogenomics
- palaeogenetics
- archaeogenetics
tools:
- pydamage:
description: Damage parameter estimation for ancient DNA
homepage: https://github.com/maxibor/pydamage
documentation: https://pydamage.readthedocs.io/
tool_dev_url: https://github.com/maxibor/pydamage
licence: ['GPL v3']
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,cram,sam}"
- bai:
type: file
description: BAM/CRAM/SAM index file
pattern: "*.{bai,crai,sai}"
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}"
- csv:
type: file
description: PyDamage results as csv files
pattern: "*.csv"
authors:
- "@maxibor"

View file

@ -703,6 +703,10 @@ pycoqc:
- modules/pycoqc/**
- tests/modules/pycoqc/**
pydamage/analyze:
- modules/pydamage/analyze/**
- tests/modules/pydamage/analyze/**
qcat:
- modules/qcat/**
- tests/modules/qcat/**

View file

@ -0,0 +1,14 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { PYDAMAGE_ANALYZE } from '../../../../modules/pydamage/analyze/main.nf' addParams( options: [:] )
workflow test_pydamage {
input = [ [ id:'test', single_end:false ], // meta map
file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
PYDAMAGE_ANALYZE ( input )
}

View file

@ -0,0 +1,8 @@
- name: test_pydamage_analyze
command: nextflow run tests/modules/pydamage/analyze -entry test_pydamage -c tests/config/nextflow.config
tags:
- pydamage
- pydamage/analyze
files:
- path: output/pydamage/pydamage_results/pydamage_results.csv
md5sum: 6847e0d5aa6dba85bbd2dd509772b7a0