mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-11-10 20:23:10 +00:00
Add module get_chrom_sizes (#1063)
* hifiasm copied from fastqc * hifiasm tests init from fastqc * meta.yml init; test.yml and main.nf for printing version * Add hifiasm version printing * Removed spaced on an empty line * Reverted hifiasm from main * init getchromsizes * add tests for getchromsizes * Included meta.yml * removed whitespace * Moved getchromsizes to custom folder * Update modules/custom/getchromsizes/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> Co-authored-by: Sviatoslav Sidorov <sviatoslav.sidorov@crick.ac.uk> Co-authored-by: Svyatoslav Sidorov <svet.sidorov@gmail.com> Co-authored-by: Chris Cheshire <chris.j.cheshire@gmail.com> Co-authored-by: Tamara Hodgetts <hodgett@crick.ac.uk> Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
parent
2294ff7826
commit
13b8a16f4a
6 changed files with 182 additions and 0 deletions
78
modules/custom/getchromsizes/functions.nf
Normal file
78
modules/custom/getchromsizes/functions.nf
Normal 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"
|
||||
}
|
||||
}
|
39
modules/custom/getchromsizes/main.nf
Normal file
39
modules/custom/getchromsizes/main.nf
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process CUSTOM_GETCHROMSIZES {
|
||||
tag "$fasta"
|
||||
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::samtools=1.14" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/samtools:1.14--hb421002_0"
|
||||
} else {
|
||||
container "quay.io/biocontainers/samtools:1.14--hb421002_0"
|
||||
}
|
||||
|
||||
input:
|
||||
path fasta
|
||||
|
||||
output:
|
||||
path '*.sizes' , emit: sizes
|
||||
path '*.fai' , emit: fai
|
||||
path "versions.yml", emit: versions
|
||||
|
||||
script:
|
||||
"""
|
||||
samtools faidx $fasta
|
||||
cut -f 1,2 ${fasta}.fai > ${fasta}.sizes
|
||||
|
||||
cat <<-END_VERSIONS > versions.yml
|
||||
${getProcessName(task.process)}:
|
||||
${getSoftwareName(task.process)}: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
|
||||
END_VERSIONS
|
||||
"""
|
||||
}
|
39
modules/custom/getchromsizes/meta.yml
Normal file
39
modules/custom/getchromsizes/meta.yml
Normal file
|
@ -0,0 +1,39 @@
|
|||
name: custom_getchromsizes
|
||||
description: Generates a FASTA file of chromosome sizes and a fasta index file
|
||||
keywords:
|
||||
- fasta
|
||||
- chromosome
|
||||
- indexing
|
||||
tools:
|
||||
- samtools:
|
||||
description: Tools for dealing with SAM, BAM and CRAM files
|
||||
homepage: http://www.htslib.org/
|
||||
documentation: http://www.htslib.org/doc/samtools.html
|
||||
tool_dev_url: https://github.com/samtools/samtools
|
||||
doi: 10.1093/bioinformatics/btp352
|
||||
licence: ['MIT']
|
||||
|
||||
input:
|
||||
- fasta:
|
||||
type: file
|
||||
description: FASTA file
|
||||
pattern: "*.{fasta}"
|
||||
|
||||
output:
|
||||
- sizes:
|
||||
type: file
|
||||
description: File containing chromosome lengths
|
||||
pattern: "*.{sizes}"
|
||||
- fai:
|
||||
type: file
|
||||
description: FASTA index file
|
||||
pattern: "*.{fai}"
|
||||
- versions:
|
||||
type: file
|
||||
description: File containing software version
|
||||
pattern: "versions.yml"
|
||||
|
||||
|
||||
authors:
|
||||
- "@tamara-hodgetts"
|
||||
- "@chris-cheshire"
|
|
@ -318,6 +318,10 @@ custom/dumpsoftwareversions:
|
|||
- modules/custom/dumpsoftwareversions/**
|
||||
- tests/modules/custom/dumpsoftwareversions/**
|
||||
|
||||
custom/getchromsizes:
|
||||
- modules/custom/getchromsizes/**
|
||||
- tests/modules/custom/getchromsizes/**
|
||||
|
||||
cutadapt:
|
||||
- modules/cutadapt/**
|
||||
- tests/modules/cutadapt/**
|
||||
|
|
12
tests/modules/custom/getchromsizes/main.nf
Normal file
12
tests/modules/custom/getchromsizes/main.nf
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { CUSTOM_GETCHROMSIZES } from '../../../../modules/custom/getchromsizes/main.nf' addParams( options: [:] )
|
||||
|
||||
workflow test_custom_getchromsizes {
|
||||
|
||||
input = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
|
||||
|
||||
CUSTOM_GETCHROMSIZES ( input )
|
||||
}
|
10
tests/modules/custom/getchromsizes/test.yml
Normal file
10
tests/modules/custom/getchromsizes/test.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
- name: custom getchromsizes
|
||||
command: nextflow run ./tests/modules/custom/getchromsizes -entry test_custom_getchromsizes -c tests/config/nextflow.config
|
||||
tags:
|
||||
- custom
|
||||
- custom/getchromsizes
|
||||
files:
|
||||
- path: output/custom/genome.fasta.fai
|
||||
md5sum: 9da2a56e2853dc8c0b86a9e7229c9fe5
|
||||
- path: output/custom/genome.fasta.sizes
|
||||
md5sum: a57c401f27ae5133823fb09fb21c8a3c
|
Loading…
Reference in a new issue