Mercurial > repos > galaxy-australia > alphafold2
annotate scripts/outputs.py @ 25:c62f678e5555 draft default tip
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit b0a876ce0f25d96a61251ad8048af533627054a7
author | galaxy-australia |
---|---|
date | Sat, 05 Jul 2025 04:05:18 +0000 |
parents | 31f648b7555a |
children |
rev | line source |
---|---|
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
1 """Generate additional output files not produced by AlphaFold. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
2 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
3 Currently this is includes: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
4 - model confidence scores |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
5 - per-residue confidence scores (pLDDTs - optional output) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
6 - model_*.pkl files renamed with rank order |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
7 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
8 N.B. There have been issues with this script breaking between AlphaFold |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
9 versions due to minor changes in the output directory structure across minor |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
10 versions. It will likely need updating with future releases of AlphaFold. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
11 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
12 This code is more complex than you might expect due to the output files |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
13 'moving around' considerably, depending on run parameters. You will see that |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
14 several output paths are determined dynamically. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
15 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
16 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
17 import argparse |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
18 import json |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
19 import numpy as np |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
20 import os |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
21 import pickle as pk |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
22 import shutil |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
23 from pathlib import Path |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
24 from typing import Dict, List |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
25 |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
26 from matplotlib import pyplot as plt |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
27 |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
28 # Output file paths |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
29 OUTPUT_DIR = 'extra' |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
30 OUTPUTS = { |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
31 'model_pkl': OUTPUT_DIR + '/ranked_{rank}.pkl', |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
32 'model_pae': OUTPUT_DIR + '/pae_ranked_{rank}.csv', |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
33 'model_plot': OUTPUT_DIR + '/ranked_{rank}.png', |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
34 'model_confidence_scores': OUTPUT_DIR + '/model_confidence_scores.tsv', |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
35 'plddts': OUTPUT_DIR + '/plddts.tsv', |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
36 'relax': OUTPUT_DIR + '/relax_metrics_ranked.json', |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
37 'msa': OUTPUT_DIR + '/msa_coverage.png', |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
38 } |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
39 |
20
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
40 HTML_PATH = Path(__file__).parent / "alphafold.html" |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
41 HTML_OUTPUT_FILENAME = 'alphafold.html' |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
42 HTML_BUTTON_ATTR = 'class="btn" id="btn-ranked_{rank}"' |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
43 HTML_BUTTON_ATTR_DISABLED = ( |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
44 'class="btn disabled" id="btn-ranked_{rank}" disabled') |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
45 |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
46 |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
47 class PLDDT_KEY: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
48 """Dict keys for accessing confidence data from JSON/pkl files." |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
49 Changes depending on which model PRESET was used. |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
50 """ |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
51 monomer = 'plddts' |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
52 multimer = 'iptm+ptm' |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
53 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
54 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
55 class PRESETS: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
56 monomer = 'monomer' |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
57 monomer_ptm = 'monomer_ptm' |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
58 multimer = 'multimer' |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
59 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
60 |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
61 class Settings: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
62 """Parse and store settings/config.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
63 def __init__(self): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
64 self.workdir = None |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
65 self.output_confidence_scores = True |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
66 self.output_residue_scores = False |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
67 self.is_multimer = False |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
68 self.parse() |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
69 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
70 def parse(self) -> None: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
71 parser = argparse.ArgumentParser() |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
72 parser.add_argument( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
73 "workdir", |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
74 help="alphafold output directory", |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
75 type=str, |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
76 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
77 parser.add_argument( |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
78 "-s", |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
79 "--confidence-scores", |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
80 help="output per-residue confidence scores (pLDDTs)", |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
81 action="store_true", |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
82 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
83 parser.add_argument( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
84 "--pkl", |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
85 help="rename model pkl outputs with rank order", |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
86 action="store_true", |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
87 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
88 parser.add_argument( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
89 "--pae", |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
90 help="extract PAE from pkl files to CSV format", |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
91 action="store_true", |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
92 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
93 parser.add_argument( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
94 "--plot", |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
95 help="Plot pLDDT and PAE for each model", |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
96 action="store_true", |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
97 ) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
98 parser.add_argument( |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
99 "--plot-msa", |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
100 help="Plot multiple-sequence alignment coverage as a heatmap", |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
101 action="store_true", |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
102 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
103 args = parser.parse_args() |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
104 self.workdir = Path(args.workdir.rstrip('/')) |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
105 self.output_residue_scores = args.confidence_scores |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
106 self.output_model_pkls = args.pkl |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
107 self.output_model_plots = args.plot |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
108 self.output_pae = args.pae |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
109 self.plot_msa = args.plot_msa |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
110 self.model_preset = self._sniff_model_preset() |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
111 self.output_dir = self.workdir / OUTPUT_DIR |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
112 os.makedirs(self.output_dir, exist_ok=True) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
113 |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
114 def _sniff_model_preset(self) -> bool: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
115 """Check if the run was multimer or monomer.""" |
22
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
116 for path in self.workdir.glob('*.pkl'): |
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
117 if 'feature' not in path.name: |
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
118 if '_multimer_' in path.name: |
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
119 return PRESETS.multimer |
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
120 if '_ptm_' in path.name: |
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
121 return PRESETS.monomer_ptm |
3f188450ca4f
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
galaxy-australia
parents:
21
diff
changeset
|
122 return PRESETS.monomer |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
123 |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
124 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
125 class ExecutionContext: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
126 """Collect file paths etc.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
127 def __init__(self, settings: Settings): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
128 self.settings = settings |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
129 if settings.model_preset == PRESETS.multimer: |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
130 self.plddt_key = PLDDT_KEY.multimer |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
131 else: |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
132 self.plddt_key = PLDDT_KEY.monomer |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
133 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
134 def get_model_key(self, ix: int) -> str: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
135 """Return json key for model index. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
136 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
137 The key format changed between minor AlphaFold versions so this |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
138 function determines the correct key. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
139 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
140 with open(self.ranking_debug) as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
141 data = json.load(f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
142 model_keys = list(data[self.plddt_key].keys()) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
143 for k in model_keys: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
144 if k.startswith(f"model_{ix}_"): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
145 return k |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
146 return KeyError( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
147 f'Could not find key for index={ix} in' |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
148 ' ranking_debug.json') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
149 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
150 @property |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
151 def ranking_debug(self) -> str: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
152 return self.settings.workdir / 'ranking_debug.json' |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
153 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
154 @property |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
155 def relax_metrics(self) -> str: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
156 return self.settings.workdir / 'relax_metrics.json' |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
157 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
158 @property |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
159 def relax_metrics_ranked(self) -> str: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
160 return self.settings.workdir / 'relax_metrics_ranked.json' |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
161 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
162 @property |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
163 def model_pkl_paths(self) -> List[str]: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
164 return sorted([ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
165 self.settings.workdir / f |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
166 for f in os.listdir(self.settings.workdir) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
167 if f.startswith('result_model_') and f.endswith('.pkl') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
168 ]) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
169 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
170 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
171 class ResultModelPrediction: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
172 """Load and manipulate data from result_model_*.pkl files.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
173 def __init__(self, path: str, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
174 self.context = context |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
175 self.path = path |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
176 self.name = os.path.basename(path).replace('result_', '').split('.')[0] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
177 with open(path, 'rb') as path: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
178 self.data = pk.load(path) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
179 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
180 @property |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
181 def plddts(self) -> List[float]: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
182 """Return pLDDT scores for each residue.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
183 return list(self.data['plddt']) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
184 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
185 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
186 class ResultRanking: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
187 """Load and manipulate data from ranking_debug.json file.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
188 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
189 def __init__(self, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
190 self.path = context.ranking_debug |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
191 self.context = context |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
192 with open(self.path, 'r') as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
193 self.data = json.load(f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
194 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
195 @property |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
196 def order(self) -> List[str]: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
197 """Return ordered list of model indexes.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
198 return self.data['order'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
199 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
200 def get_plddt_for_rank(self, rank: int) -> List[float]: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
201 """Get pLDDT score for model instance.""" |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
202 return self.data[self.context.plddt_key][self.data['order'][rank]] |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
203 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
204 def get_rank_for_model(self, model_name: str) -> int: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
205 """Return 0-indexed rank for given model name. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
206 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
207 Model names are expressed in result_model_*.pkl file names. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
208 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
209 return self.data['order'].index(model_name) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
210 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
211 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
212 def write_confidence_scores(ranking: ResultRanking, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
213 """Write per-model confidence scores.""" |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
214 outfile = context.settings.workdir / OUTPUTS['model_confidence_scores'] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
215 scores: Dict[str, list] = {} |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
216 header = ['model', context.plddt_key] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
217 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
218 for i, path in enumerate(context.model_pkl_paths): |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
219 model_name = 'model_' + path.stem.split('model_')[1] |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
220 rank = ranking.get_rank_for_model(model_name) |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
221 scores_ls = [ranking.get_plddt_for_rank(rank)] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
222 with open(path, 'rb') as f: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
223 data = pk.load(f) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
224 if 'ptm' in data: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
225 scores_ls.append(data['ptm']) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
226 if i == 0: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
227 header += ['ptm'] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
228 if 'iptm' in data: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
229 scores_ls.append(data['iptm']) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
230 if i == 0: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
231 header += ['iptm'] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
232 scores[rank] = scores_ls |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
233 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
234 with open(outfile, 'w') as f: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
235 f.write('\t'.join(header) + '\n') |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
236 for rank in sorted(scores): |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
237 score_ls = scores[rank] |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
238 row = [f"ranked_{rank}"] + [str(x) for x in score_ls] |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
239 f.write('\t'.join(row) + '\n') |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
240 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
241 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
242 def write_per_residue_scores( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
243 ranking: ResultRanking, |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
244 context: ExecutionContext, |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
245 ): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
246 """Write per-residue plddts for each model. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
247 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
248 A row of plddt values is written for each model in tabular format. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
249 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
250 model_plddts = {} |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
251 for i, path in enumerate(context.model_pkl_paths): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
252 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
253 rank = ranking.get_rank_for_model(model.name) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
254 model_plddts[rank] = model.plddts |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
255 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
256 path = context.settings.workdir / OUTPUTS['plddts'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
257 with open(path, 'w') as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
258 for i in sorted(list(model_plddts.keys())): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
259 row = [f'ranked_{i}'] + [ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
260 str(x) for x in model_plddts[i] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
261 ] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
262 f.write('\t'.join(row) + '\n') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
263 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
264 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
265 def rename_model_pkls(ranking: ResultRanking, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
266 """Rename model.pkl files so the rank order is implicit.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
267 for path in context.model_pkl_paths: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
268 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
269 rank = ranking.get_rank_for_model(model.name) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
270 new_path = ( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
271 context.settings.workdir |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
272 / OUTPUTS['model_pkl'].format(rank=rank) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
273 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
274 shutil.copyfile(path, new_path) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
275 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
276 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
277 def extract_pae_to_csv(ranking: ResultRanking, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
278 """Extract predicted alignment error matrix from pickle files. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
279 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
280 Creates a CSV file for each of five ranked models. |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
281 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
282 for path in context.model_pkl_paths: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
283 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
284 rank = ranking.get_rank_for_model(model.name) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
285 with open(path, 'rb') as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
286 data = pk.load(f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
287 if 'predicted_aligned_error' not in data: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
288 print("Skipping PAE output" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
289 f" - not found in {path}." |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
290 " Running with model_preset=monomer?") |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
291 return |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
292 pae = data['predicted_aligned_error'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
293 out_path = ( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
294 context.settings.workdir |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
295 / OUTPUTS['model_pae'].format(rank=rank) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
296 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
297 with open(out_path, 'w') as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
298 for row in pae: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
299 f.write(','.join([str(x) for x in row]) + '\n') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
300 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
301 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
302 def rekey_relax_metrics(ranking: ResultRanking, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
303 """Replace keys in relax_metrics.json with 0-indexed rank.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
304 with open(context.relax_metrics) as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
305 data = json.load(f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
306 for k in list(data.keys()): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
307 rank = ranking.get_rank_for_model(k) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
308 data[f'ranked_{rank}'] = data.pop(k) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
309 new_path = context.settings.workdir / OUTPUTS['relax'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
310 with open(new_path, 'w') as f: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
311 json.dump(data, f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
312 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
313 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
314 def plddt_pae_plots(ranking: ResultRanking, context: ExecutionContext): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
315 """Generate a pLDDT + PAE plot for each model.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
316 for path in context.model_pkl_paths: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
317 num_plots = 2 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
318 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
319 rank = ranking.get_rank_for_model(model.name) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
320 png_path = ( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
321 context.settings.workdir |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
322 / OUTPUTS['model_plot'].format(rank=rank) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
323 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
324 plddts = model.data['plddt'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
325 if 'predicted_aligned_error' in model.data: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
326 pae = model.data['predicted_aligned_error'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
327 max_pae = model.data['max_predicted_aligned_error'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
328 else: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
329 num_plots = 1 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
330 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
331 plt.figure(figsize=[8 * num_plots, 6]) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
332 plt.subplot(1, num_plots, 1) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
333 plt.plot(plddts) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
334 plt.title('Predicted LDDT') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
335 plt.xlabel('Residue') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
336 plt.ylabel('pLDDT') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
337 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
338 if num_plots == 2: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
339 plt.subplot(1, 2, 2) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
340 plt.imshow(pae, vmin=0., vmax=max_pae, cmap='Greens_r') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
341 plt.colorbar(fraction=0.046, pad=0.04) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
342 plt.title('Predicted Aligned Error') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
343 plt.xlabel('Scored residue') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
344 plt.ylabel('Aligned residue') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
345 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
346 plt.savefig(png_path) |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
347 plt.close() |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
348 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
349 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
350 def plot_msa(wdir: Path, dpi: int = 150): |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
351 """Plot MSA as a heatmap.""" |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
352 with open(wdir / 'features.pkl', 'rb') as f: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
353 features = pk.load(f) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
354 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
355 msa = features.get('msa') |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
356 if msa is None: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
357 print("Could not plot MSA coverage - 'msa' key not found in" |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
358 " features.pkl") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
359 return |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
360 seqid = (np.array(msa[0] == msa).mean(-1)) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
361 seqid_sort = seqid.argsort() |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
362 non_gaps = (msa != 21).astype(float) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
363 non_gaps[non_gaps == 0] = np.nan |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
364 final = non_gaps[seqid_sort] * seqid[seqid_sort, None] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
365 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
366 plt.figure(figsize=(6, 4)) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
367 # plt.subplot(111) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
368 plt.title("Sequence coverage") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
369 plt.imshow(final, |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
370 interpolation='nearest', aspect='auto', |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
371 cmap="rainbow_r", vmin=0, vmax=1, origin='lower') |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
372 plt.plot((msa != 21).sum(0), color='black') |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
373 plt.xlim(-0.5, msa.shape[1] - 0.5) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
374 plt.ylim(-0.5, msa.shape[0] - 0.5) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
375 plt.colorbar(label="Sequence identity to query", ) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
376 plt.xlabel("Positions") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
377 plt.ylabel("Sequences") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
378 plt.tight_layout() |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
379 plt.savefig(wdir / OUTPUTS['msa'], dpi=dpi) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
380 plt.close() |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
381 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
382 |
20
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
383 def template_html(context: ExecutionContext): |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
384 """Template HTML file. |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
385 |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
386 Remove buttons that are redundant with limited model outputs. |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
387 """ |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
388 print("Templating HTML file...") |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
389 with open(HTML_PATH) as f: |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
390 html = f.read() |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
391 for i in range(len(context.model_pkl_paths), 5): |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
392 btn_id = HTML_BUTTON_ATTR.format(rank=i) |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
393 btn_attr_disabled = HTML_BUTTON_ATTR_DISABLED.format(rank=i) |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
394 html = html.replace(btn_id, btn_attr_disabled) |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
395 with open(context.settings.output_dir / HTML_OUTPUT_FILENAME, 'w') as f: |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
396 f.write(html) |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
397 |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
398 |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
399 def main(): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
400 """Parse output files and generate additional output files.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
401 settings = Settings() |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
402 context = ExecutionContext(settings) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
403 ranking = ResultRanking(context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
404 write_confidence_scores(ranking, context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
405 rekey_relax_metrics(ranking, context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
406 template_html(context) |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
407 |
24
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
408 # Optional outputs |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
409 if settings.output_model_pkls: |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
410 rename_model_pkls(ranking, context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
411 if settings.output_model_plots: |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
412 plddt_pae_plots(ranking, context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
413 if settings.output_pae: |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
414 # Only created by monomer_ptm and multimer models |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
415 extract_pae_to_csv(ranking, context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
416 if settings.output_residue_scores: |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
417 write_per_residue_scores(ranking, context) |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
418 if settings.plot_msa: |
31f648b7555a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 44db277529c0e189149235cf60a627193a792fba
galaxy-australia
parents:
23
diff
changeset
|
419 plot_msa(context.settings.workdir) |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
420 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
421 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
422 if __name__ == '__main__': |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
423 main() |