Add PyDamage filter (#713)

* 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

* update resource requirement

* Update modules/pydamage/filter/main.nf

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

* Update modules/pydamage/filter/meta.yml

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

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>
This commit is contained in:
Maxime Borry 2021-09-16 15:05:49 +02:00 committed by GitHub
parent d9dfbe9d9d
commit 7e45cbf4d1
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_FILTER {
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::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(csv)
output:
tuple val(meta), path("pydamage_results/pydamage_filtered_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 \\
filter \\
$options.args \\
$csv
echo \$(pydamage --version 2>&1) | sed -e 's/pydamage, version //g' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,51 @@
name: pydamage_filter
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 ]
- csv:
type: file
description: csv file from pydamage analyze
pattern: "*.csv"
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 filtered results as csv file
pattern: "*.csv"
authors:
- "@maxibor"

View file

@ -707,6 +707,10 @@ pydamage/analyze:
- modules/pydamage/analyze/**
- tests/modules/pydamage/analyze/**
pydamage/filter:
- modules/pydamage/filter/**
- tests/modules/pydamage/filter/**
qcat:
- modules/qcat/**
- tests/modules/qcat/**

View file

@ -0,0 +1,16 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { PYDAMAGE_ANALYZE } from '../../../../modules/pydamage/analyze/main.nf' addParams( options: [:] )
include { PYDAMAGE_FILTER } from '../../../../modules/pydamage/filter/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 )
PYDAMAGE_FILTER (PYDAMAGE_ANALYZE.out.csv)
}

View file

@ -0,0 +1,10 @@
- name: test_pydamage_filter
command: nextflow run tests/modules/pydamage/filter -entry test_pydamage -c tests/config/nextflow.config
tags:
- pydamage
- pydamage/filter
files:
- path: output/pydamage/pydamage_results/pydamage_filtered_results.csv
md5sum: 9f297233cf4932d7d7e52cc72d4727dc
- path: output/pydamage/pydamage_results/pydamage_results.csv
md5sum: 6847e0d5aa6dba85bbd2dd509772b7a0