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