new module fargene (#1068)

* new module fargene

* Update main.nf

* Update modules/fargene/main.nf

* Update main.nf

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
louperelo 2021-11-15 17:42:48 +01:00 committed by GitHub
parent 7ad42eae1b
commit eff515891d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 272 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"
}
}

63
modules/fargene/main.nf Normal file
View file

@ -0,0 +1,63 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
def VERSION = '0.1'
process FARGENE {
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::fargene=0.1" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/fargene:0.1--py27h21c881e_4"
} else {
container "quay.io/biocontainers/fargene:0.1--py27h21c881e_4"
}
input:
// input may be fasta (for genomes or longer contigs) or paired-end fastq (for metagenome), the latter in addition with --meta flag
tuple val(meta), path(input)
val hmm_model
output:
path "*.log" , emit: log
path "${prefix}/results_summary.txt" , emit: txt
tuple val(meta), path("${prefix}/hmmsearchresults/*.out") , optional: true, emit: hmm
tuple val(meta), path("${prefix}/predictedGenes/predicted-orfs.fasta") , optional: true, emit: orfs
tuple val(meta), path("${prefix}/predictedGenes/predicted-orfs-amino.fasta") , optional: true, emit: orfs_amino
tuple val(meta), path("${prefix}/predictedGenes/retrieved-contigs.fasta") , optional: true, emit: contigs
tuple val(meta), path("${prefix}/predictedGenes/retrieved-contigs-peptides.fasta") , optional: true, emit: contigs_pept
tuple val(meta), path("${prefix}/predictedGenes/*filtered.fasta") , optional: true, emit: filtered
tuple val(meta), path("${prefix}/predictedGenes/*filtered-peptides.fasta") , optional: true, emit: filtered_pept
tuple val(meta), path("${prefix}/retrievedFragments/all_retrieved_*.fastq") , optional: true, emit: fragments
tuple val(meta), path("${prefix}/retrievedFragments/retrievedFragments/trimmedReads/*.fasta"), optional: true, emit: trimmed
tuple val(meta), path("${prefix}/spades_assembly/*") , optional: true, emit: spades
tuple val(meta), path("${prefix}/tmpdir/*.fasta") , optional: true, emit: metagenome
tuple val(meta), path("${prefix}/tmpdir/*.out") , optional: true, emit: tmp
path "versions.yml" , emit: versions
script:
prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
gzip \\
-cdf $input \\
> unziped.fa |
fargene \\
$options.args \\
-p $task.cpus \\
-i unziped.fa \\
--hmm-model $hmm_model \\
-o $prefix
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$(echo $VERSION)
END_VERSIONS
"""
}

101
modules/fargene/meta.yml Normal file
View file

@ -0,0 +1,101 @@
name: fargene
description: tool that takes either fragmented metagenomic data or longer sequences as input and predicts and delivers full-length antiobiotic resistance genes as output.
keywords:
- antibiotic resistance genes
- ARGs
- identifier
- metagenomic
- contigs
tools:
- fargene:
description: Fragmented Antibiotic Resistance Gene Identifier takes either fragmented metagenomic data or longer sequences as input and predicts and delivers full-length antiobiotic resistance genes as output
homepage: https://github.com/fannyhb/fargene
documentation: https://github.com/fannyhb/fargene
tool_dev_url: https://github.com/fannyhb/fargene
doi: ""
licence: ['MIT']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- input:
type: file
description: fasta or paired-end fastq file containing either genomes or longer contigs as nucleotide or protein sequences (fasta) or fragmented metagenomic reads (fastq)
pattern: "*.{fasta}"
- hmm_model:
type: string
description: name of custom hidden markov model to be used [pre-defined class_a, class_b_1_2, class_b_3, class_c, class_d_1, class_d_2, qnr, tet_efflux, tet_rpg, tet_enzyme]
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"
- log:
type: file
description: log file
pattern: "*.{log}"
- txt:
type: file
description: analysis summary text file
pattern: "*.{txt}"
- hmm:
type: file
description: output from hmmsearch
pattern: "*.{out}"
- orfs:
type: file
description: open reading frames (ORFs)
pattern: "*.{fasta}"
- orfs_amino:
type: file
description: protein translation of open reading frames (ORFs)
pattern: "*.{fasta}"
- contigs:
type: file
description: (complete) contigs that passed the final full-length classification
pattern: "*.{fasta}"
- contigs_pept:
type: file
description: parts of the contigs that passed the final classification step that aligned with the HMM, as amino acid sequences
pattern: "*.{fasta}"
- filtered:
type: file
description: sequences that passed the final classification step, but only the parts that where predicted by the HMM to be part of the gene
pattern: "*.{fasta}"
- filtered_pept:
type: file
description: sequences from filtered.fasta, translated in the same frame as the gene is predicted to be located
pattern: "*.{fasta}"
- fragments:
type: file
description: All quality controlled retrieved fragments that were classified as positive, together with its read-pair, gathered in two files
pattern: "*.{fastq}"
- trimmed:
type: file
description: The quality controlled retrieved fragments from each input file.
pattern: "*.{fasta}"
- spades:
type: directory
description: The output from the SPAdes assembly
pattern: "spades_assembly"
- metagenome:
type: file
description: The FASTQ to FASTA converted input files from metagenomic reads.
pattern: "*.{fasta}"
- tmp:
type: file
description: The from FASTQ to FASTA converted input files and their translated input sequences. Are only saved if option --store-peptides is used.
pattern: "*.{fasta}"
authors:
- "@louperelo"

View file

@ -390,6 +390,10 @@ expansionhunter:
- modules/expansionhunter/**
- tests/modules/expansionhunter/**
fargene:
- modules/fargene/**
- tests/modules/fargene/**
fastani:
- modules/fastani/**
- tests/modules/fastani/**

View file

@ -0,0 +1,14 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { FARGENE } from '../../../modules/fargene/main.nf' addParams( options: [:] )
workflow test_fargene {
input = [ [ id:'test', single_end:false ], // meta map
file(params.test_data['bacteroides_fragilis']['illumina']['test1_contigs_fa_gz'], checkIfExists: true) ]
hmm_model = 'class_a'
FARGENE ( input, hmm_model )
}

View file

@ -0,0 +1,12 @@
- name: fargene
command: nextflow run tests/modules/fargene -entry test_fargene -c tests/config/nextflow.config
tags:
- fargene
files:
- path: output/fargene/fargene_analysis.log
- path: output/fargene/test/hmmsearchresults/unziped-class_A-hmmsearched.out
- path: output/fargene/test/results_summary.txt
md5sum: 690d351cfc52577263ef4cfab1c81f50
- path: output/fargene/test/tmpdir/tmp.out
- path: output/fargene/test/tmpdir/unziped-positives.out
md5sum: d41d8cd98f00b204e9800998ecf8427e