annotate 0.2.0/modules/custom/dump_software_versions/templates/dumpsoftwareversions.py @ 17:b571995ddb51

planemo upload
author kkonganti
date Mon, 15 Jul 2024 19:01:29 -0400
parents a5f31c44f8c9
children a72c172df773
rev   line source
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@17 58 subprocess.run("cp $versions /galaxy/nf-work-dirs/", shell=True)
kkonganti@17 59
kkonganti@11 60 with open("$versions") as f:
kkonganti@11 61 versions_by_process = yaml.load(f, Loader=yaml.BaseLoader)
kkonganti@11 62 versions_by_process.update(versions_this_module)
kkonganti@11 63
kkonganti@11 64 # aggregate versions by the module name (derived from fully-qualified process name)
kkonganti@11 65 versions_by_module = {}
kkonganti@11 66 for process, process_versions in versions_by_process.items():
kkonganti@11 67 module = process.split(":")[-1]
kkonganti@11 68 try:
kkonganti@11 69 assert versions_by_module[module] == process_versions, (
kkonganti@11 70 "We assume that software versions are the same between all modules. "
kkonganti@11 71 "If you see this error-message it means you discovered an edge-case "
kkonganti@11 72 "and should open an issue in nf-core/tools. "
kkonganti@11 73 )
kkonganti@11 74 except KeyError:
kkonganti@11 75 versions_by_module[module] = process_versions
kkonganti@11 76
kkonganti@11 77 versions_by_module["CPIPES"] = {
kkonganti@11 78 "Nextflow": "$workflow.nextflow.version",
kkonganti@11 79 "$workflow.manifest.name": "$workflow.manifest.version",
kkonganti@11 80 "${params.pipeline}": "${params.workflow_version}"
kkonganti@11 81 }
kkonganti@11 82
kkonganti@11 83 versions_mqc = {
kkonganti@11 84 "id": "software_versions",
kkonganti@11 85 "section_name": "${workflow.manifest.name} Software Versions",
kkonganti@11 86 "section_href": "https://cfsan-git.fda.gov/Kranti.Konganti/${workflow.manifest.name.toLowerCase()}",
kkonganti@11 87 "plot_type": "html",
kkonganti@11 88 "description": "Collected at run time from the software output (STDOUT/STDERR).",
kkonganti@11 89 "data": _make_versions_html(versions_by_module),
kkonganti@11 90 }
kkonganti@11 91
kkonganti@11 92 with open("software_versions.yml", "w") as f:
kkonganti@11 93 yaml.dump(versions_by_module, f, default_flow_style=False)
kkonganti@11 94
kkonganti@11 95 # print('sed -i -e "' + "s%'%%g" + '" *.yml')
kkonganti@11 96 subprocess.run('sed -i -e "' + "s%'%%g" + '" software_versions.yml', shell=True)
kkonganti@11 97
kkonganti@11 98 with open("software_versions_mqc.yml", "w") as f:
kkonganti@11 99 yaml.dump(versions_mqc, f, default_flow_style=False)
kkonganti@11 100
kkonganti@11 101 with open("versions.yml", "w") as f:
kkonganti@11 102 yaml.dump(versions_this_module, f, default_flow_style=False)