annotate 0.3.0/modules/custom/dump_software_versions/templates/dumpsoftwareversions.py @ 92:295c2597a475

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