mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 02:58:17 +00:00
module: unzip (#642)
* Specify more guidelines on input channels * Linting * Updates based on code review * Update README.md * Fix broken sentence * Add unzip module * Remove missing TODOs update mtea * Apply changes after code-review from @grst * Account for user trying to supply two input archives * Remove debugging test * Update modules/unzip/main.nf Co-authored-by: Jose Espinosa-Carrasco <kadomu@gmail.com> * Correct output path Co-authored-by: Jose Espinosa-Carrasco <kadomu@gmail.com>
This commit is contained in:
parent
2a7c60e965
commit
e01a98a704
7 changed files with 166 additions and 0 deletions
68
modules/unzip/functions.nf
Normal file
68
modules/unzip/functions.nf
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
43
modules/unzip/main.nf
Normal file
43
modules/unzip/main.nf
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process UNZIP {
|
||||
tag "$archive"
|
||||
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:[:], publish_by_meta:[]) }
|
||||
|
||||
|
||||
conda (params.enable_conda ? "bioconda::p7zip=15.09" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/p7zip:15.09--h2d50403_4"
|
||||
} else {
|
||||
container "quay.io/biocontainers/p7zip:15.09--h2d50403_4"
|
||||
}
|
||||
|
||||
input:
|
||||
path archive
|
||||
|
||||
output:
|
||||
path "${archive.baseName}/" , emit: unzipped_archive
|
||||
path "*.version.txt" , emit: version
|
||||
|
||||
script:
|
||||
def software = getSoftwareName(task.process)
|
||||
|
||||
if ( archive instanceof List && archive.name.size > 1 ) { exit 1, "[UNZIP] error: 7za only accepts a single archive as input. Please check module input." }
|
||||
|
||||
"""
|
||||
7za \\
|
||||
e \\
|
||||
-o"${archive.baseName}"/ \\
|
||||
$options.args \\
|
||||
$archive
|
||||
|
||||
echo \$(7za --help) | grep Version | sed 's/.*p7zip Version//; s/(.*//' 1> ${software}.version.txt
|
||||
"""
|
||||
}
|
31
modules/unzip/meta.yml
Normal file
31
modules/unzip/meta.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
name: unzip
|
||||
description: Unzip ZIP archive files
|
||||
keywords:
|
||||
- unzip
|
||||
- decompression
|
||||
tools:
|
||||
- unzip:
|
||||
description: p7zip is a quick port of 7z.exe and 7za.exe (command line version of 7zip, see www.7-zip.org) for Unix.
|
||||
homepage: https://sourceforge.net/projects/p7zip/
|
||||
documentation: https://sourceforge.net/projects/p7zip/
|
||||
tool_dev_url: https://sourceforge.net/projects/p7zip"
|
||||
licence: "GNU LPGL"
|
||||
|
||||
input:
|
||||
- archive:
|
||||
type: file
|
||||
description: ZIP file
|
||||
pattern: "*.zip"
|
||||
|
||||
output:
|
||||
- version:
|
||||
type: file
|
||||
description: File or directory of decompressed archive
|
||||
pattern: "*.{version.txt}"
|
||||
- unzipped_archive:
|
||||
type: directory
|
||||
description: Directory contents of the unzipped archive
|
||||
pattern: '${archive.baseName}/'
|
||||
|
||||
authors:
|
||||
- "@jfy133"
|
|
@ -835,6 +835,10 @@ untar:
|
|||
- modules/untar/**
|
||||
- tests/modules/untar/**
|
||||
|
||||
unzip:
|
||||
- modules/unzip/**
|
||||
- tests/modules/unzip/**
|
||||
|
||||
variantbam:
|
||||
- modules/variantbam/**
|
||||
- tests/modules/variantbam/**
|
||||
|
|
|
@ -7,6 +7,7 @@ params {
|
|||
'genome' {
|
||||
genome_fasta = "${test_data_dir}/genomics/sarscov2/genome/genome.fasta"
|
||||
genome_fasta_fai = "${test_data_dir}/genomics/sarscov2/genome/genome.fasta.fai"
|
||||
genome_fasta_zip = "${test_data_dir}/genomics/sarscov2/genome/genome.fasta.zip"
|
||||
genome_dict = "${test_data_dir}/genomics/sarscov2/genome/genome.dict"
|
||||
genome_gff3 = "${test_data_dir}/genomics/sarscov2/genome/genome.gff3"
|
||||
genome_gff3_gz = "${test_data_dir}/genomics/sarscov2/genome/genome.gff3.gz"
|
||||
|
|
12
tests/modules/unzip/main.nf
Normal file
12
tests/modules/unzip/main.nf
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { UNZIP } from '../../../modules/unzip/main.nf' addParams( options: [:] )
|
||||
|
||||
workflow test_unzip {
|
||||
|
||||
archive = file(params.test_data['sarscov2']['genome']['genome_fasta_zip'], checkIfExists: true)
|
||||
|
||||
UNZIP ( archive )
|
||||
}
|
7
tests/modules/unzip/test.yml
Normal file
7
tests/modules/unzip/test.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
- name: unzip
|
||||
command: nextflow run ./tests/modules/unzip -entry test_unzip -c tests/config/nextflow.config
|
||||
tags:
|
||||
- unzip
|
||||
files:
|
||||
- path: output/unzip/genome.fasta/genome.fasta
|
||||
md5sum: 6e9fe4042a72f2345f644f239272b7e6
|
Loading…
Reference in a new issue