annotate 0.5.0/modules/custom/dump_software_versions/templates/dumpsoftwareversions.py @ 1:365849f031fd

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