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