mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 11:08:17 +00:00
Cooler merge (#515)
* add software/cooler * fix the wrong files uploaded. * create a branch for cooler/merge * remove the bin_size from metadata. * update the test_data to test-datasets * update pytest_modules.yml * update the test file from single input file to two input file. update the output file from hdf5 to bedpe. * update the version.txt to version.yml and functions.nf * change version.yml to versions * update the test file path and fix the output versions. * Update meta.yml Correct "version" to "versions" * Update main.nf Fix typo * Update main.nf Remove some spaces Co-authored-by: Gregor Sturm <mail@gregor-sturm.de> Co-authored-by: Sébastien Guizard <sguizard@ed.ac.uk>
This commit is contained in:
parent
73a09850fb
commit
a6ca2b006b
7 changed files with 192 additions and 0 deletions
78
modules/cooler/merge/functions.nf
Normal file
78
modules/cooler/merge/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"
|
||||||
|
}
|
||||||
|
}
|
41
modules/cooler/merge/main.nf
Normal file
41
modules/cooler/merge/main.nf
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Import generic module functions
|
||||||
|
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
|
||||||
|
|
||||||
|
params.options = [:]
|
||||||
|
options = initOptions(params.options)
|
||||||
|
|
||||||
|
process COOLER_MERGE {
|
||||||
|
tag "$meta.id"
|
||||||
|
label 'process_high'
|
||||||
|
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::cooler=0.8.11" : null)
|
||||||
|
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||||
|
container "https://depot.galaxyproject.org/singularity/cooler:0.8.11--pyh3252c3a_0"
|
||||||
|
} else {
|
||||||
|
container "quay.io/biocontainers/cooler:0.8.11--pyh3252c3a_0"
|
||||||
|
}
|
||||||
|
|
||||||
|
input:
|
||||||
|
tuple val(meta), path(cool)
|
||||||
|
|
||||||
|
output:
|
||||||
|
tuple val(meta), path("*.cool"), emit: cool
|
||||||
|
path "versions.yml" , emit: versions
|
||||||
|
|
||||||
|
script:
|
||||||
|
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||||
|
"""
|
||||||
|
cooler merge \\
|
||||||
|
$options.args \\
|
||||||
|
${prefix}.cool \\
|
||||||
|
${cool}
|
||||||
|
|
||||||
|
cat <<-END_VERSIONS > versions.yml
|
||||||
|
${getProcessName(task.process)}:
|
||||||
|
${getSoftwareName(task.process)}: \$(cooler --version 2>&1 | sed 's/cooler, version //')
|
||||||
|
END_VERSIONS
|
||||||
|
"""
|
||||||
|
}
|
41
modules/cooler/merge/meta.yml
Normal file
41
modules/cooler/merge/meta.yml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
name: cooler_merge
|
||||||
|
description: Merge multiple coolers with identical axes
|
||||||
|
keywords:
|
||||||
|
- merge
|
||||||
|
tools:
|
||||||
|
- cooler:
|
||||||
|
description: Sparse binary format for genomic interaction matrices
|
||||||
|
homepage: https://cooler.readthedocs.io/en/latest/index.html
|
||||||
|
documentation: https://cooler.readthedocs.io/en/latest/index.html
|
||||||
|
tool_dev_url: https://github.com/open2c/cooler
|
||||||
|
doi: "10.1093/bioinformatics/btz540"
|
||||||
|
licence: ['BSD-3-clause']
|
||||||
|
|
||||||
|
input:
|
||||||
|
- meta:
|
||||||
|
type: map
|
||||||
|
description: |
|
||||||
|
Groovy Map containing sample information
|
||||||
|
e.g. [ id:'test', single_end:false ]
|
||||||
|
- cool:
|
||||||
|
type: file
|
||||||
|
description: Path to COOL file
|
||||||
|
pattern: "*.{cool,mcool}"
|
||||||
|
|
||||||
|
output:
|
||||||
|
- meta:
|
||||||
|
type: map
|
||||||
|
description: |
|
||||||
|
Groovy Map containing sample information
|
||||||
|
e.g. [ id:'test', single_end:false ]
|
||||||
|
- versions:
|
||||||
|
type: file
|
||||||
|
description: File containing software version
|
||||||
|
pattern: "versions.yml"
|
||||||
|
- cool:
|
||||||
|
type: file
|
||||||
|
description: Path to COOL file
|
||||||
|
pattern: "*.cool"
|
||||||
|
|
||||||
|
authors:
|
||||||
|
- "@jianhong"
|
|
@ -294,6 +294,10 @@ cooler/dump:
|
||||||
- modules/cooler/dump/**
|
- modules/cooler/dump/**
|
||||||
- tests/modules/cooler/dump/**
|
- tests/modules/cooler/dump/**
|
||||||
|
|
||||||
|
cooler/merge:
|
||||||
|
- modules/cooler/merge/**
|
||||||
|
- tests/modules/cooler/merge/**
|
||||||
|
|
||||||
csvtk/concat:
|
csvtk/concat:
|
||||||
- modules/csvtk/concat/**
|
- modules/csvtk/concat/**
|
||||||
- tests/modules/csvtk/concat/**
|
- tests/modules/csvtk/concat/**
|
||||||
|
|
|
@ -255,6 +255,10 @@ params {
|
||||||
'txt' {
|
'txt' {
|
||||||
hello = "${test_data_dir}/generic/txt/hello.txt"
|
hello = "${test_data_dir}/generic/txt/hello.txt"
|
||||||
}
|
}
|
||||||
|
'cooler' {
|
||||||
|
test_merge_cool = "${test_data_dir}/genomics/homo_sapiens/cooler/merge/toy/toy.symm.upper.2.cool"
|
||||||
|
test_merge_cool_cp2 = "${test_data_dir}/genomics/homo_sapiens/cooler/merge/toy/toy.symm.upper.2.cp2.cool"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
'bacteroides_fragilis'{
|
'bacteroides_fragilis'{
|
||||||
'genome' {
|
'genome' {
|
||||||
|
|
16
tests/modules/cooler/merge/main.nf
Normal file
16
tests/modules/cooler/merge/main.nf
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env nextflow
|
||||||
|
|
||||||
|
nextflow.enable.dsl = 2
|
||||||
|
|
||||||
|
include { COOLER_MERGE } from '../../../../modules/cooler/merge/main.nf' addParams( options: [publish_files:[:]] )
|
||||||
|
include { COOLER_DUMP } from '../../../../modules/cooler/dump/main.nf' addParams( options: [:] )
|
||||||
|
|
||||||
|
workflow test_cooler_merge {
|
||||||
|
|
||||||
|
input = [ [ id:'test' ], // meta map
|
||||||
|
[ file(params.test_data['generic']['cooler']['test_merge_cool'], checkIfExists: true),
|
||||||
|
file(params.test_data['generic']['cooler']['test_merge_cool_cp2'], checkIfExists: true)]
|
||||||
|
]
|
||||||
|
|
||||||
|
COOLER_MERGE ( input ).cool | COOLER_DUMP
|
||||||
|
}
|
8
tests/modules/cooler/merge/test.yml
Normal file
8
tests/modules/cooler/merge/test.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
- name: cooler merge test_cooler_merge
|
||||||
|
command: nextflow run tests/modules/cooler/merge -entry test_cooler_merge -c tests/config/nextflow.config
|
||||||
|
tags:
|
||||||
|
- cooler/merge
|
||||||
|
- cooler
|
||||||
|
files:
|
||||||
|
- path: output/cooler/test.bedpe
|
||||||
|
md5sum: 0ce5e715bfc4674cdda02f2d7e7e3170
|
Loading…
Reference in a new issue