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