add new module pmdtools/filter #847 (#963)

* commit but won't be used because pmdtools should have a submodule

* added submodule pmdtools/filter

* removed pmdtools module created before deciding to design two submodules

* oops forgot to remove a TODO

* removed white space meta.yml, removed v in version and manually added submodule /filter to test

* Update pytest_modules.yml

* Update main.nf

added split_cpus for multi-tools module resources

* Update test.yml

added .pmd extension to match modules/ main.nf

* Update test.yml

update md5sum

* Update singularity and docker build in main.nf

From build 4 to 5 in order to match the conda one

* Update modules/pmdtools/filter/main.nf

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

* Update modules/pmdtools/filter/main.nf

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

* Update modules/pmdtools/filter/main.nf

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

* Update modules/pmdtools/filter/meta.yml

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

* Update modules/pmdtools/filter/meta.yml

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

* Update modules/pmdtools/filter/meta.yml

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

* Update modules/pmdtools/filter/meta.yml

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

* Update modules/pmdtools/filter/main.nf

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

* Update modules/pmdtools/filter/main.nf

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

* Update main.nf adding samtools version

we need both pmdtools and samtools versions

* Update main.nf remove .pmd extension

* Update test.yml md5sum

Because file extension changed

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>
This commit is contained in:
alexandregilardet 2021-11-13 15:09:14 +00:00 committed by GitHub
parent 001d5071c2
commit 94851901d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 220 additions and 0 deletions

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

View file

@ -0,0 +1,60 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process PMDTOOLS_FILTER {
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::pmdtools=0.60" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/pmdtools:0.60--hdfd78af_5"
} else {
container "quay.io/biocontainers/pmdtools:0.60--hdfd78af_5"
}
input:
tuple val(meta), path(bam), path (bai)
val(threshold)
path(reference)
output:
tuple val(meta), path("*.bam"), emit: bam
path "versions.yml" , emit: versions
script:
def split_cpus = Math.floor(task.cpus/2)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
if ("$bam" == "${prefix}.bam") error "[pmdtools/filter] Input and output names are the same, use the suffix option to disambiguate!"
//threshold and header flags activate filtering function of pmdtools
"""
samtools \\
calmd \\
$bam \\
$reference \\
$options.args \\
-@ ${split_cpus} \\
| pmdtools \\
--threshold $threshold \\
--header \\
$options.args2 \\
| samtools \\
view \\
$options.args3 \\
-Sb \\
- \\
-@ ${split_cpus} \\
-o ${prefix}.bam
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
pmdtools: \$( pmdtools --version | cut -f2 -d ' ' | sed 's/v//')
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
END_VERSIONS
"""
}

View file

@ -0,0 +1,55 @@
name: pmdtools_filter
description: pmdtools command to filter ancient DNA molecules from others
keywords:
- pmdtools
- aDNA
- filter
- damage
tools:
- pmdtools:
description: Compute postmortem damage patterns and decontaminate ancient genomes
homepage: https://github.com/pontussk/PMDtools
documentation: https://github.com/pontussk/PMDtools
tool_dev_url: https://github.com/pontussk/PMDtools
doi: "10.1073/pnas.1318934111"
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 file
pattern: "*.bam"
- bai:
type: file
description: BAM index file
pattern: "*.bai"
- threshold:
type: value
description: Post-mortem damage score threshold
- reference:
type: file
description: FASTA file
pattern: "*.{fa,fasta}"
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"
- bam:
type: file
description: Filtered BAM file
pattern: "*.bam"
authors:
- "@alexandregilardet"

View file

@ -956,6 +956,10 @@ plink/vcf:
- modules/plink/vcf/** - modules/plink/vcf/**
- tests/modules/plink/vcf/** - tests/modules/plink/vcf/**
pmdtools/filter:
- modules/pmdtools/filter/**
- tests/modules/pmdtools/filter/**
porechop: porechop:
- modules/porechop/** - modules/porechop/**
- tests/modules/porechop/** - tests/modules/porechop/**

View file

@ -0,0 +1,15 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { PMDTOOLS_FILTER } from '../../../../modules/pmdtools/filter/main.nf' addParams( options: [:] )
workflow test_pmdtools_filter {
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) ]]
threshold = 3
reference = [ file(params.test_data['homo_sapiens']['genome']['genome_fasta'], checkIfExists: true) ]
PMDTOOLS_FILTER ( input, threshold, reference )
}

View file

@ -0,0 +1,8 @@
- name: pmdtools filter
command: nextflow run ./tests/modules/pmdtools/filter -entry test_pmdtools_filter -c tests/config/nextflow.config
tags:
- pmdtools
- pmdtools/filter
files:
- path: output/pmdtools/test.bam
md5sum: 0fa64cb87d0439d4482938a4b6990b9d