annotate 0.7.0/modules/custom/dump_software_versions/templates/dumpsoftwareversions.py @ 20:133571bf891f

planemo upload
author kkonganti
date Mon, 15 Jul 2024 11:42:00 -0400
parents 0e7a0053e4a6
children
rev   line source
kkonganti@17 1 #!/usr/bin/env python
kkonganti@17 2
kkonganti@17 3 import yaml
kkonganti@17 4 import platform
kkonganti@17 5 import subprocess
kkonganti@17 6 from textwrap import dedent
kkonganti@17 7
kkonganti@17 8
kkonganti@17 9 def _make_versions_html(versions):
kkonganti@17 10 html = [
kkonganti@17 11 dedent(
kkonganti@17 12 """\\
kkonganti@17 13 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.12.1/b-2.2.3/b-colvis-2.2.3/b-html5-2.2.3/b-print-2.2.3/fc-4.1.0/r-2.3.0/sc-2.0.6/sb-1.3.3/sp-2.0.1/datatables.min.css"/>
kkonganti@17 14 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
kkonganti@17 15 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
kkonganti@17 16 <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.12.1/b-2.2.3/b-colvis-2.2.3/b-html5-2.2.3/b-print-2.2.3/fc-4.1.0/r-2.3.0/sc-2.0.6/sb-1.3.3/sp-2.0.1/datatables.min.js"></script>
kkonganti@17 17 <style>
kkonganti@17 18 #cpipes-software-versions tbody:nth-child(even) {
kkonganti@17 19 background-color: #f2f2f2;
kkonganti@17 20 }
kkonganti@17 21 </style>
kkonganti@17 22 <table class="table" style="width:100%" id="cpipes-software-versions">
kkonganti@17 23 <thead>
kkonganti@17 24 <tr>
kkonganti@17 25 <th> Process Name </th>
kkonganti@17 26 <th> Software </th>
kkonganti@17 27 <th> Version </th>
kkonganti@17 28 </tr>
kkonganti@17 29 </thead>
kkonganti@17 30 """
kkonganti@17 31 )
kkonganti@17 32 ]
kkonganti@17 33 for process, tmp_versions in sorted(versions.items()):
kkonganti@17 34 html.append("<tbody>")
kkonganti@17 35 for i, (tool, version) in enumerate(sorted(tmp_versions.items())):
kkonganti@17 36 html.append(
kkonganti@17 37 dedent(
kkonganti@17 38 f"""\\
kkonganti@17 39 <tr>
kkonganti@17 40 <td><samp>{process if (i == 0) else ''}</samp></td>
kkonganti@17 41 <td><samp>{tool}</samp></td>
kkonganti@17 42 <td><samp>{version}</samp></td>
kkonganti@17 43 </tr>
kkonganti@17 44 """
kkonganti@17 45 )
kkonganti@17 46 )
kkonganti@17 47 html.append("</tbody>")
kkonganti@17 48 html.append("</table>")
kkonganti@17 49 return "\\n".join(html)
kkonganti@17 50
kkonganti@17 51
kkonganti@17 52 versions_this_module = {}
kkonganti@17 53 versions_this_module["${task.process}"] = {
kkonganti@17 54 "python": platform.python_version(),
kkonganti@17 55 "yaml": yaml.__version__,
kkonganti@17 56 }
kkonganti@17 57
kkonganti@17 58 with open("$versions") as f:
kkonganti@17 59 versions_by_process = yaml.load(f, Loader=yaml.BaseLoader)
kkonganti@17 60 versions_by_process.update(versions_this_module)
kkonganti@17 61
kkonganti@17 62 # aggregate versions by the module name (derived from fully-qualified process name)
kkonganti@17 63 versions_by_module = {}
kkonganti@17 64 for process, process_versions in versions_by_process.items():
kkonganti@17 65 module = process.split(":")[-1]
kkonganti@17 66 try:
kkonganti@17 67 assert versions_by_module[module] == process_versions, (
kkonganti@17 68 "We assume that software versions are the same between all modules. "
kkonganti@17 69 "If you see this error-message it means you discovered an edge-case "
kkonganti@17 70 "and should open an issue in nf-core/tools. "
kkonganti@17 71 )
kkonganti@17 72 except KeyError:
kkonganti@17 73 versions_by_module[module] = process_versions
kkonganti@17 74
kkonganti@17 75 versions_by_module["CPIPES"] = {
kkonganti@17 76 "Nextflow": "$workflow.nextflow.version",
kkonganti@17 77 "$workflow.manifest.name": "$workflow.manifest.version",
kkonganti@17 78 "${params.pipeline}": "${params.workflow_version}",
kkonganti@17 79 }
kkonganti@17 80
kkonganti@17 81 versions_mqc = {
kkonganti@17 82 "id": "software_versions",
kkonganti@17 83 "section_name": "${workflow.manifest.name} Software Versions",
kkonganti@17 84 "section_href": "https://github.com/CFSAN-Biostatistics/bettercallsal",
kkonganti@17 85 "plot_type": "html",
kkonganti@17 86 "description": "Collected at run time from the software output (STDOUT/STDERR).",
kkonganti@17 87 "data": _make_versions_html(versions_by_module),
kkonganti@17 88 }
kkonganti@17 89
kkonganti@17 90 with open("software_versions.yml", "w") as f:
kkonganti@17 91 yaml.dump(versions_by_module, f, default_flow_style=False)
kkonganti@17 92
kkonganti@17 93 # print('sed -i -e "' + "s%'%%g" + '" *.yml')
kkonganti@17 94 subprocess.run('sed -i -e "' + "s%'%%g" + '" software_versions.yml', shell=True)
kkonganti@17 95
kkonganti@17 96 with open("software_versions_mqc.yml", "w") as f:
kkonganti@17 97 yaml.dump(versions_mqc, f, default_flow_style=False)
kkonganti@17 98
kkonganti@17 99 with open("versions.yml", "w") as f:
kkonganti@17 100 yaml.dump(versions_this_module, f, default_flow_style=False)