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