kkonganti@1: #!/usr/bin/env python kkonganti@1: kkonganti@1: import yaml kkonganti@1: import platform kkonganti@1: import subprocess kkonganti@1: from textwrap import dedent kkonganti@1: kkonganti@1: kkonganti@1: def _make_versions_html(versions): kkonganti@1: html = [ kkonganti@1: dedent( kkonganti@1: """\\ kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: """ kkonganti@1: ) kkonganti@1: ] kkonganti@1: for process, tmp_versions in sorted(versions.items()): kkonganti@1: html.append("") kkonganti@1: for i, (tool, version) in enumerate(sorted(tmp_versions.items())): kkonganti@1: html.append( kkonganti@1: dedent( kkonganti@1: f"""\\ kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: kkonganti@1: """ kkonganti@1: ) kkonganti@1: ) kkonganti@1: html.append("") kkonganti@1: html.append("
Process Name Software Version
{process if (i == 0) else ''}{tool}{version}
") kkonganti@1: return "\\n".join(html) kkonganti@1: kkonganti@1: kkonganti@1: versions_this_module = {} kkonganti@1: versions_this_module["${task.process}"] = { kkonganti@1: "python": platform.python_version(), kkonganti@1: "yaml": yaml.__version__, kkonganti@1: } kkonganti@1: kkonganti@1: with open("$versions") as f: kkonganti@1: versions_by_process = yaml.load(f, Loader=yaml.BaseLoader) kkonganti@1: versions_by_process.update(versions_this_module) kkonganti@1: kkonganti@1: # aggregate versions by the module name (derived from fully-qualified process name) kkonganti@1: versions_by_module = {} kkonganti@1: for process, process_versions in versions_by_process.items(): kkonganti@1: module = process.split(":")[-1] kkonganti@1: try: kkonganti@1: assert versions_by_module[module] == process_versions, ( kkonganti@1: "We assume that software versions are the same between all modules. " kkonganti@1: "If you see this error-message it means you discovered an edge-case " kkonganti@1: "and should open an issue in nf-core/tools. " kkonganti@1: ) kkonganti@1: except KeyError: kkonganti@1: versions_by_module[module] = process_versions kkonganti@1: kkonganti@1: versions_by_module["CPIPES"] = { kkonganti@1: "Nextflow": "$workflow.nextflow.version", kkonganti@1: "$workflow.manifest.name": "$workflow.manifest.version", kkonganti@1: "${params.pipeline}": "${params.workflow_version}", kkonganti@1: } kkonganti@1: kkonganti@1: versions_mqc = { kkonganti@1: "id": "software_versions", kkonganti@1: "section_name": "${workflow.manifest.name} Software Versions", kkonganti@1: "section_href": "https://github.com/CFSAN-Biostatistics/bettercallsal", kkonganti@1: "plot_type": "html", kkonganti@1: "description": "Collected at run time from the software output (STDOUT/STDERR).", kkonganti@1: "data": _make_versions_html(versions_by_module), kkonganti@1: } kkonganti@1: kkonganti@1: with open("software_versions.yml", "w") as f: kkonganti@1: yaml.dump(versions_by_module, f, default_flow_style=False) kkonganti@1: kkonganti@1: # print('sed -i -e "' + "s%'%%g" + '" *.yml') kkonganti@1: subprocess.run('sed -i -e "' + "s%'%%g" + '" software_versions.yml', shell=True) kkonganti@1: kkonganti@1: with open("software_versions_mqc.yml", "w") as f: kkonganti@1: yaml.dump(versions_mqc, f, default_flow_style=False) kkonganti@1: kkonganti@1: with open("versions.yml", "w") as f: kkonganti@1: yaml.dump(versions_this_module, f, default_flow_style=False)