Skip to content

Commit

Permalink
feat: Use newest software version handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jvfe committed Sep 18, 2023
1 parent 1d8dcae commit 4f20af4
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 56 deletions.
6 changes: 6 additions & 0 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"installed_by": ["modules"],
"patch": "modules/nf-core/checkm/lineagewf/checkm-lineagewf.diff"
},
"custom/dumpsoftwareversions": {
"branch": "master",
"git_sha": "05c280924b6c768d484c7c443dad5e605c4ff4b4",
"installed_by": ["modules"],
"patch": "modules/nf-core/custom/dumpsoftwareversions/custom-dumpsoftwareversions.diff"
},
"diamond/blastp": {
"branch": "master",
"git_sha": "c8e35eb2055c099720a75538d1b8adb3fb5a464c",
Expand Down
24 changes: 18 additions & 6 deletions modules/local/rgi.nf
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ process UPDATE_RGI_DB {

output:
path "card.json", emit: card_json
path "card.version.txt", emit: card_version
path "versions.yml", emit: card_version

script:
"""
curl https://card.mcmaster.ca/latest/data --output card.tar.bz2
tar xvf card.tar.bz2
python -c "import json;fh = open('card.json');card=json.load(fh);print(card['_version'])" > card.version.txt
cat <<-END_VERSIONS > versions.yml
"${task.process}":
card: \$(echo \$(python -c "import json;fh = open('card.json');card=json.load(fh);print(card['_version'])"))
END_VERSIONS
"""

stub:
"""
touch card.json
touch card.version.txt
cat <<-END_VERSIONS > versions.yml
"${task.process}":
card: 1.0
END_VERSIONS
"""
}

Expand All @@ -48,7 +54,7 @@ process RGI {

output:
tuple val(meta), path("${meta.id}_rgi.txt"), emit: tsv
path "*.version.txt", emit: version
path "versions.yml", emit: version

script:
def software = getSoftwareName(task.process)
Expand All @@ -58,13 +64,19 @@ process RGI {
rgi load -i $card_db --local
rgi main --local --input_sequence $fasta --output_file ${meta.id}_rgi --input_type contig --clean --include_loose
echo \$(rgi main --version 2>&1) > ${software}.version.txt
cat <<-END_VERSIONS > versions.yml
"${task.process}":
rgi: \$(echo \$(rgi main --version 2>&1))
END_VERSIONS
"""
stub:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
touch ${prefix}_rgi.txt
echo \$(rgi main --version 2>&1) > ${software}.version.txt
cat <<-END_VERSIONS > versions.yml
"${task.process}":
rgi: \$(echo \$(rgi main --version 2>&1))
END_VERSIONS
"""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Changes in module 'nf-core/custom/dumpsoftwareversions'
--- modules/nf-core/custom/dumpsoftwareversions/main.nf
+++ modules/nf-core/custom/dumpsoftwareversions/main.nf
@@ -2,10 +2,10 @@
label 'process_single'

// Requires `pyyaml` which does not have a dedicated container but is in the MultiQC container
- conda "bioconda::multiqc=1.15"
+ conda (params.enable_conda ? "bioconda::multiqc=1.15" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/multiqc:1.15--pyhdfd78af_0' :
- 'biocontainers/multiqc:1.15--pyhdfd78af_0' }"
+ 'quay.io/biocontainers/multiqc:1.15--pyhdfd78af_0' }"

input:
path versions

************************************************************
24 changes: 24 additions & 0 deletions modules/nf-core/custom/dumpsoftwareversions/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
process CUSTOM_DUMPSOFTWAREVERSIONS {
label 'process_single'

// Requires `pyyaml` which does not have a dedicated container but is in the MultiQC container
conda (params.enable_conda ? "bioconda::multiqc=1.15" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/multiqc:1.15--pyhdfd78af_0' :
'quay.io/biocontainers/multiqc:1.15--pyhdfd78af_0' }"

input:
path versions

output:
path "software_versions.yml" , emit: yml
path "software_versions_mqc.yml", emit: mqc_yml
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
def args = task.ext.args ?: ''
template 'dumpsoftwareversions.py'
}
36 changes: 36 additions & 0 deletions modules/nf-core/custom/dumpsoftwareversions/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/yaml-schema.json
name: custom_dumpsoftwareversions
description: Custom module used to dump software versions within the nf-core pipeline template
keywords:
- custom
- dump
- version
tools:
- custom:
description: Custom module used to dump software versions within the nf-core pipeline template
homepage: https://github.com/nf-core/tools
documentation: https://github.com/nf-core/tools
licence: ["MIT"]
input:
- versions:
type: file
description: YML file containing software versions
pattern: "*.yml"

output:
- yml:
type: file
description: Standard YML file containing software versions
pattern: "software_versions.yml"
- mqc_yml:
type: file
description: MultiQC custom content YML file containing software versions
pattern: "software_versions_mqc.yml"
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"

authors:
- "@drpatelh"
- "@grst"
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env python


"""Provide functions to merge multiple versions.yml files."""


import yaml
import platform
from textwrap import dedent


def _make_versions_html(versions):
"""Generate a tabular HTML output of all versions for MultiQC."""
html = [
dedent(
"""\\
<style>
#nf-core-versions tbody:nth-child(even) {
background-color: #f2f2f2;
}
</style>
<table class="table" style="width:100%" id="nf-core-versions">
<thead>
<tr>
<th> Process Name </th>
<th> Software </th>
<th> Version </th>
</tr>
</thead>
"""
)
]
for process, tmp_versions in sorted(versions.items()):
html.append("<tbody>")
for i, (tool, version) in enumerate(sorted(tmp_versions.items())):
html.append(
dedent(
f"""\\
<tr>
<td><samp>{process if (i == 0) else ''}</samp></td>
<td><samp>{tool}</samp></td>
<td><samp>{version}</samp></td>
</tr>
"""
)
)
html.append("</tbody>")
html.append("</table>")
return "\\n".join(html)


def main():
"""Load all version files and generate merged output."""
versions_this_module = {}
versions_this_module["${task.process}"] = {
"python": platform.python_version(),
"yaml": yaml.__version__,
}

with open("$versions") as f:
versions_by_process = yaml.load(f, Loader=yaml.BaseLoader) | versions_this_module

# aggregate versions by the module name (derived from fully-qualified process name)
versions_by_module = {}
for process, process_versions in versions_by_process.items():
module = process.split(":")[-1]
try:
if versions_by_module[module] != process_versions:
raise AssertionError(
"We assume that software versions are the same between all modules. "
"If you see this error-message it means you discovered an edge-case "
"and should open an issue in nf-core/tools. "
)
except KeyError:
versions_by_module[module] = process_versions

versions_by_module["Workflow"] = {
"Nextflow": "$workflow.nextflow.version",
"$workflow.manifest.name": "$workflow.manifest.version",
}

versions_mqc = {
"id": "software_versions",
"section_name": "${workflow.manifest.name} Software Versions",
"section_href": "https://github.com/${workflow.manifest.name}",
"plot_type": "html",
"description": "are collected at run time from the software output.",
"data": _make_versions_html(versions_by_module),
}

with open("software_versions.yml", "w") as f:
yaml.dump(versions_by_module, f, default_flow_style=False)
with open("software_versions_mqc.yml", "w") as f:
yaml.dump(versions_mqc, f, default_flow_style=False)

with open("versions.yml", "w") as f:
yaml.dump(versions_this_module, f, default_flow_style=False)


if __name__ == "__main__":
main()
Loading

0 comments on commit 4f20af4

Please sign in to comment.