Cooler zoomify (#514)

* add software/cooler

* fix the wrong files uploaded.

* create a branch for cooler/zoomify

* Apply suggestions from code review

* update functions.nf to new version.

* update the test file to test-datasets.

* update the test method of zoomify

* update dump test file.

* update version.txt to version.yml

* Update modules/cooler/dump/main.nf

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* fix the output bug of versions update to pytest_modules.yml

* update the test file path and fix the output versions.

* Update modules/cooler/dump/main.nf

* indent

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
Co-authored-by: Gregor Sturm <mail@gregor-sturm.de>
Co-authored-by: Sébastien Guizard <sguizard@ed.ac.uk>
Co-authored-by: FriederikeHanssen <Friederike.hanssen@qbic.uni-tuebingen.de>
This commit is contained in:
JIANHONG OU 2021-11-15 11:18:02 -05:00 committed by GitHub
parent f93c2f2604
commit 7ad42eae1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 193 additions and 3 deletions

View file

@ -20,18 +20,20 @@ process COOLER_DUMP {
input:
tuple val(meta), path(cool)
val resolution
output:
tuple val(meta), path("*.bedpe"), emit: bedpe
path "versions.yml" , emit: versions
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def suffix = resolution ? "::$resolution" : ""
"""
cooler dump \\
$options.args \\
-o ${prefix}.bedpe \\
$cool
$cool$suffix
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:

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"
}
}

View file

@ -0,0 +1,42 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process COOLER_ZOOMIFY {
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("*.mcool"), emit: mcool
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
cooler zoomify \\
$options.args \\
-n $task.cpus \\
-o ${prefix}.mcool \\
$cool
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$(cooler --version 2>&1 | sed 's/cooler, version //')
END_VERSIONS
"""
}

View file

@ -0,0 +1,41 @@
name: cooler_zoomify
description: Generate a multi-resolution cooler file by coarsening
keywords:
- mcool
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 versions
pattern: "versions.yml"
- mcool:
type: file
description: Output mcool file
pattern: "*.mcool"
authors:
- "@jianhong"

View file

@ -294,6 +294,10 @@ cooler/dump:
- modules/cooler/dump/**
- tests/modules/cooler/dump/**
cooler/zoomify:
- modules/cooler/zoomify/**
- tests/software/cooler/zoomify/**
cooler/merge:
- modules/cooler/merge/**
- tests/modules/cooler/merge/**

View file

@ -260,6 +260,7 @@ params {
'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'{

View file

@ -9,5 +9,5 @@ workflow test_cooler_dump {
input = [ [ id:'test' ], // meta map
file("https://raw.githubusercontent.com/open2c/cooler/master/tests/data/toy.asymm.16.cool", checkIfExists: true) ]
COOLER_DUMP ( input )
COOLER_DUMP ( input, [:] )
}

View file

@ -0,0 +1,14 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { COOLER_ZOOMIFY } from '../../../../modules/cooler/zoomify/main.nf' addParams( options: ['args':'-r 2,4,8', publish_files:[:]] )
include { COOLER_DUMP } from '../../../../modules/cooler/dump/main.nf' addParams( options: [:] )
workflow test_cooler_zoomify {
input = [ [ id:'test' ], // meta map
file(params.test_data['generic']['cooler']['test_merge_cool'], checkIfExists: true)]
COOLER_ZOOMIFY ( input )
COOLER_DUMP(COOLER_ZOOMIFY.out.mcool, "/resolutions/2")
}

View file

@ -0,0 +1,8 @@
- name: cooler zoomify test_cooler_zoomify
command: nextflow run tests/modules/cooler/zoomify -entry test_cooler_zoomify -c tests/config/nextflow.config
tags:
- cooler
- cooler/zoomify
files:
- path: output/cooler/test.bedpe
md5sum: 8d792beb609fff62b536c326661f9507