mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 11:08:17 +00:00
Request to review code for seqtk/sample module (#488)
* added files * removed file * added file * changed files * changed files * edited file * edited file * edited files * edited files * edited files * edited tags * edited tags * edited tags * edited tags Co-authored-by: kaurravneet4123 <kaurravneet4123@yahoo.com@users.noreply.github.com>
This commit is contained in:
parent
f8ea9828cd
commit
12ebce50f7
6 changed files with 223 additions and 0 deletions
70
software/seqtk/sample/functions.nf
Normal file
70
software/seqtk/sample/functions.nf
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* -----------------------------------------------------
|
||||
* 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"
|
||||
}
|
||||
}
|
||||
}
|
62
software/seqtk/sample/main.nf
Normal file
62
software/seqtk/sample/main.nf
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process SEQTK_SAMPLE {
|
||||
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::seqtk=1.3" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/seqtk:1.3--h5bf99c6_3"
|
||||
} else {
|
||||
container "quay.io/biocontainers/seqtk:1.3--h5bf99c6_3"
|
||||
}
|
||||
|
||||
input:
|
||||
tuple val(meta), path(reads)
|
||||
val sample_size
|
||||
|
||||
output:
|
||||
tuple val(meta), path("*.fastq.gz"), emit: reads
|
||||
path "*.version.txt" , emit: version
|
||||
|
||||
script:
|
||||
def software = getSoftwareName(task.process)
|
||||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||
if (meta.single_end) {
|
||||
"""
|
||||
seqtk \\
|
||||
sample \\
|
||||
$options.args \\
|
||||
$reads \\
|
||||
$sample_size \\
|
||||
| gzip > ${prefix}.fastq.gz \\
|
||||
|
||||
echo \$(seqtk 2>&1) | sed 's/^.*Version: //; s/ .*\$//' > ${software}.version.txt
|
||||
"""
|
||||
} else {
|
||||
"""
|
||||
seqtk \\
|
||||
sample \\
|
||||
$options.args \\
|
||||
$reads[0] \\
|
||||
$sample_size \\
|
||||
| gzip > ${prefix}_1.fastq.gz \\
|
||||
|
||||
seqtk \\
|
||||
sample \\
|
||||
$options.args \\
|
||||
$reads[1] \\
|
||||
$sample_size \\
|
||||
| gzip > ${prefix}_2.fastq.gz \\
|
||||
|
||||
echo \$(seqtk 2>&1) | sed 's/^.*Version: //; s/ .*\$//' > ${software}.version.txt
|
||||
"""
|
||||
}
|
||||
}
|
39
software/seqtk/sample/meta.yml
Normal file
39
software/seqtk/sample/meta.yml
Normal file
|
@ -0,0 +1,39 @@
|
|||
name: seqtk_sample
|
||||
description: Subsample reads from FASTQ files
|
||||
keywords:
|
||||
- sample
|
||||
tools:
|
||||
- seqtk:
|
||||
description: Seqtk is a fast and lightweight tool for processing sequences in the FASTA or FASTQ format. Seqtk sample command subsamples sequences.
|
||||
homepage: https://github.com/lh3/seqtk
|
||||
documentation: https://docs.csc.fi/apps/seqtk/
|
||||
licence: ['MIT']
|
||||
|
||||
input:
|
||||
- meta:
|
||||
type: map
|
||||
description: |
|
||||
Groovy Map containing sample information
|
||||
e.g. [ id:'test', single_end:false ]
|
||||
- reads:
|
||||
type: file
|
||||
description: List of input FastQ files of size 1 and 2 for single-end and paired-end data,respectively.
|
||||
pattern: "*.{fastq.gz}"
|
||||
|
||||
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}"
|
||||
- reads:
|
||||
type: file
|
||||
description: Subsampled FastQ files of size 1 and 2 for single-end and paired-end data,respectively.
|
||||
pattern: "*.{fastq.gz}"
|
||||
|
||||
authors:
|
||||
- "@kaurravneet4123"
|
|
@ -563,6 +563,10 @@ seqkit/split2:
|
|||
- software/seqkit/split2/**
|
||||
- tests/software/seqkit/split2/**
|
||||
|
||||
seqtk/sample:
|
||||
- software/seqtk/sample/**
|
||||
- tests/software/seqtk/sample/**
|
||||
|
||||
sequenzautils/bam2seqz:
|
||||
- software/sequenzautils/bam2seqz/**
|
||||
- tests/software/sequenzautils/bam2seqz/**
|
||||
|
|
29
tests/software/seqtk/sample/main.nf
Normal file
29
tests/software/seqtk/sample/main.nf
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { SEQTK_SAMPLE } from '../../../../software/seqtk/sample/main.nf' addParams( options: [ 'args': '-s100', 'suffix':'.sampled' ] )
|
||||
|
||||
/*
|
||||
* Test with single-end data
|
||||
*/
|
||||
workflow test_seqtk_sample_single_end {
|
||||
|
||||
input = [ [ id:'test', single_end:true ], // meta map
|
||||
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) ]
|
||||
|
||||
SEQTK_SAMPLE ( input, 250000 )
|
||||
}
|
||||
|
||||
/*
|
||||
* Test with paired-end data
|
||||
*/
|
||||
workflow test_seqtk_sample_paired_end {
|
||||
|
||||
input = [ [ id:'test', single_end:false ], // meta map
|
||||
[ file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
|
||||
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) ]
|
||||
]
|
||||
|
||||
SEQTK_SAMPLE ( input, 250000 )
|
||||
}
|
19
tests/software/seqtk/sample/test.yml
Normal file
19
tests/software/seqtk/sample/test.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
- name: seqtk sample single-end
|
||||
command: nextflow run ./tests/software/seqtk/sample -entry test_seqtk_sample_single_end -c tests/config/nextflow.config
|
||||
tags:
|
||||
- seqtk
|
||||
- seqtk/sample
|
||||
files:
|
||||
- path: output/seqtk/test.sampled.fastq.gz
|
||||
md5sum: 875863b402f67403dac63ef59b9c9a8a
|
||||
|
||||
- name: seqtk sample paired-end
|
||||
command: nextflow run ./tests/software/seqtk/sample -entry test_seqtk_sample_paired_end -c tests/config/nextflow.config
|
||||
tags:
|
||||
- seqtk
|
||||
- seqtk/sample
|
||||
files:
|
||||
- path: output/seqtk/test.sampled_1.fastq.gz
|
||||
md5sum: 7029066c27ac6f5ef18d660d5741979a
|
||||
- path: output/seqtk/test.sampled_2.fastq.gz
|
||||
md5sum: 7029066c27ac6f5ef18d660d5741979a
|
Loading…
Reference in a new issue