annotate 0.4.2/modules/custom/dump_software_versions/templates/dumpsoftwareversions.py @ 105:52045ea4679d

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