comparison scripts/outputs.py @ 20:6ab1a261520a draft default tip

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
comparison
equal deleted inserted replaced
19:2f7702fd0a4c 20:6ab1a261520a
39 # They change depending on whether the run was monomer or multimer 39 # They change depending on whether the run was monomer or multimer
40 PLDDT_KEY = { 40 PLDDT_KEY = {
41 'monomer': 'plddts', 41 'monomer': 'plddts',
42 'multimer': 'iptm+ptm', 42 'multimer': 'iptm+ptm',
43 } 43 }
44
45 HTML_PATH = Path(__file__).parent / "alphafold.html"
46 HTML_OUTPUT_FILENAME = 'alphafold.html'
47 HTML_BUTTON_ATTR = 'class="btn" id="btn-ranked_{rank}"'
48 HTML_BUTTON_ATTR_DISABLED = (
49 'class="btn disabled" id="btn-ranked_{rank}" disabled')
44 50
45 51
46 class Settings: 52 class Settings:
47 """Parse and store settings/config.""" 53 """Parse and store settings/config."""
48 def __init__(self): 54 def __init__(self):
186 192
187 def write_confidence_scores(ranking: ResultRanking, context: ExecutionContext): 193 def write_confidence_scores(ranking: ResultRanking, context: ExecutionContext):
188 """Write per-model confidence scores.""" 194 """Write per-model confidence scores."""
189 path = context.settings.workdir / OUTPUTS['model_confidence_scores'] 195 path = context.settings.workdir / OUTPUTS['model_confidence_scores']
190 with open(path, 'w') as f: 196 with open(path, 'w') as f:
191 for rank in range(1, 6): 197 for rank in range(1, len(context.model_pkl_paths) + 1):
192 score = ranking.get_plddt_for_rank(rank) 198 score = ranking.get_plddt_for_rank(rank)
193 f.write(f'ranked_{rank - 1}\t{score:.2f}\n') 199 f.write(f'ranked_{rank - 1}\t{score:.2f}\n')
194 200
195 201
196 def write_per_residue_scores( 202 def write_per_residue_scores(
298 plt.ylabel('Aligned residue') 304 plt.ylabel('Aligned residue')
299 305
300 plt.savefig(png_path) 306 plt.savefig(png_path)
301 307
302 308
309 def template_html(context: ExecutionContext):
310 """Template HTML file.
311
312 Remove buttons that are redundant with limited model outputs.
313 """
314 print("Templating HTML file...")
315 with open(HTML_PATH) as f:
316 html = f.read()
317 for i in range(len(context.model_pkl_paths), 5):
318 btn_id = HTML_BUTTON_ATTR.format(rank=i)
319 btn_attr_disabled = HTML_BUTTON_ATTR_DISABLED.format(rank=i)
320 html = html.replace(btn_id, btn_attr_disabled)
321 with open(context.settings.output_dir / HTML_OUTPUT_FILENAME, 'w') as f:
322 f.write(html)
323
324
303 def main(): 325 def main():
304 """Parse output files and generate additional output files.""" 326 """Parse output files and generate additional output files."""
305 settings = Settings() 327 settings = Settings()
306 context = ExecutionContext(settings) 328 context = ExecutionContext(settings)
307 ranking = ResultRanking(context) 329 ranking = ResultRanking(context)
308 write_confidence_scores(ranking, context) 330 write_confidence_scores(ranking, context)
309 rekey_relax_metrics(ranking, context) 331 rekey_relax_metrics(ranking, context)
332 template_html(context)
310 333
311 # Optional outputs 334 # Optional outputs
312 if settings.output_model_pkls: 335 if settings.output_model_pkls:
313 rename_model_pkls(ranking, context) 336 rename_model_pkls(ranking, context)
314 if settings.output_model_plots: 337 if settings.output_model_plots: