diff scripts/outputs.py @ 20:6ab1a261520a draft

planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
author galaxy-australia
date Sun, 28 Jul 2024 20:09:55 +0000
parents f9eb041c518c
children e7f1b552a695
line wrap: on
line diff
--- a/scripts/outputs.py	Wed May 08 06:26:55 2024 +0000
+++ b/scripts/outputs.py	Sun Jul 28 20:09:55 2024 +0000
@@ -42,6 +42,12 @@
     'multimer': 'iptm+ptm',
 }
 
+HTML_PATH = Path(__file__).parent / "alphafold.html"
+HTML_OUTPUT_FILENAME = 'alphafold.html'
+HTML_BUTTON_ATTR = 'class="btn" id="btn-ranked_{rank}"'
+HTML_BUTTON_ATTR_DISABLED = (
+    'class="btn disabled" id="btn-ranked_{rank}" disabled')
+
 
 class Settings:
     """Parse and store settings/config."""
@@ -188,7 +194,7 @@
     """Write per-model confidence scores."""
     path = context.settings.workdir / OUTPUTS['model_confidence_scores']
     with open(path, 'w') as f:
-        for rank in range(1, 6):
+        for rank in range(1, len(context.model_pkl_paths) + 1):
             score = ranking.get_plddt_for_rank(rank)
             f.write(f'ranked_{rank - 1}\t{score:.2f}\n')
 
@@ -300,6 +306,22 @@
         plt.savefig(png_path)
 
 
+def template_html(context: ExecutionContext):
+    """Template HTML file.
+
+    Remove buttons that are redundant with limited model outputs.
+    """
+    print("Templating HTML file...")
+    with open(HTML_PATH) as f:
+        html = f.read()
+    for i in range(len(context.model_pkl_paths), 5):
+        btn_id = HTML_BUTTON_ATTR.format(rank=i)
+        btn_attr_disabled = HTML_BUTTON_ATTR_DISABLED.format(rank=i)
+        html = html.replace(btn_id, btn_attr_disabled)
+    with open(context.settings.output_dir / HTML_OUTPUT_FILENAME, 'w') as f:
+        f.write(html)
+
+
 def main():
     """Parse output files and generate additional output files."""
     settings = Settings()
@@ -307,6 +329,7 @@
     ranking = ResultRanking(context)
     write_confidence_scores(ranking, context)
     rekey_relax_metrics(ranking, context)
+    template_html(context)
 
     # Optional outputs
     if settings.output_model_pkls: