Mercurial > repos > galaxy-australia > alphafold2
annotate scripts/outputs.py @ 22:3f188450ca4f draft default tip
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d626bb28203543a70d3fc60d662cb054bc3cef7c
author | galaxy-australia |
---|---|
date | Wed, 30 Oct 2024 21:46:34 +0000 |
parents | e7f1b552a695 |
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 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
26 from matplotlib import pyplot as plt |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
27 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
28 # Output file paths |
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 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
67 self.is_multimer = False |
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 |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
129 if settings.model_preset == PRESETS.multimer: |
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.""" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
202 return self.data[self.context.plddt_key][self.data['order'][rank - 1]] |
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): |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
219 rank = int(path.name.split('model_')[-1][0]) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 if i == 0: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
226 header += ['ptm'] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
227 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
|
228 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
|
229 if i == 0: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
230 header += ['iptm'] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
231 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
|
232 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
233 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
|
234 f.write('\t'.join(header) + '\n') |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
235 for rank, score_ls in scores.items(): |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
236 row = [f"ranked_{rank - 1}"] + [str(x) for x in score_ls] |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
237 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
|
238 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
239 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
240 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
|
241 ranking: ResultRanking, |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
242 context: ExecutionContext, |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
243 ): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
244 """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
|
245 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
246 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
|
247 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
248 model_plddts = {} |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
249 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
|
250 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
251 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
|
252 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
|
253 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 row = [f'ranked_{i}'] + [ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
258 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
|
259 ] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
260 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
|
261 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
262 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
263 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
|
264 """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
|
265 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
|
266 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
267 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
|
268 new_path = ( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
269 context.settings.workdir |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
270 / 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
|
271 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
272 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
|
273 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
274 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
275 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
|
276 """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
|
277 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
278 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
|
279 """ |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
280 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
|
281 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
282 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
|
283 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
|
284 data = pk.load(f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
285 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
|
286 print("Skipping PAE output" |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
287 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
|
288 " 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
|
289 return |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
290 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
|
291 out_path = ( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
292 context.settings.workdir |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
293 / 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
|
294 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
295 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
|
296 for row in pae: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
297 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
|
298 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
299 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
300 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
|
301 """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
|
302 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
|
303 data = json.load(f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 json.dump(data, f) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
310 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
311 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
312 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
|
313 """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
|
314 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
|
315 num_plots = 2 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
316 model = ResultModelPrediction(path, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
317 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
|
318 png_path = ( |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
319 context.settings.workdir |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
320 / 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
|
321 ) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
322 plddts = model.data['plddt'] |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 else: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
327 num_plots = 1 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
328 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
329 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
|
330 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
|
331 plt.plot(plddts) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
332 plt.title('Predicted LDDT') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
333 plt.xlabel('Residue') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
334 plt.ylabel('pLDDT') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
335 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
336 if num_plots == 2: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 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
|
341 plt.xlabel('Scored residue') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
342 plt.ylabel('Aligned residue') |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
343 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
344 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
|
345 plt.close() |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
346 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
347 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
348 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
|
349 """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
|
350 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
|
351 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
|
352 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 " features.pkl") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
357 return |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
364 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
|
365 # plt.subplot(111) |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
366 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
|
367 plt.imshow(final, |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 plt.xlabel("Positions") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
375 plt.ylabel("Sequences") |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
376 plt.tight_layout() |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
377 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
|
378 plt.close() |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
379 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
380 |
20
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
381 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
|
382 """Template HTML file. |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
383 |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
384 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
|
385 """ |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
386 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
|
387 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
|
388 html = f.read() |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 f.write(html) |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
395 |
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
396 |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
397 def main(): |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
398 """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
|
399 settings = Settings() |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
400 context = ExecutionContext(settings) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
401 ranking = ResultRanking(context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
402 write_confidence_scores(ranking, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
403 rekey_relax_metrics(ranking, context) |
20
6ab1a261520a
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c3a90eb12ada44d477541baa4dd6182be29cd554-dirty
galaxy-australia
parents:
16
diff
changeset
|
404 template_html(context) |
16
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
405 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
406 # Optional outputs |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
407 if settings.output_model_pkls: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
408 rename_model_pkls(ranking, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
409 if settings.output_model_plots: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
410 plddt_pae_plots(ranking, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
411 if settings.output_pae: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
412 # Only created by monomer_ptm and multimer models |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
413 extract_pae_to_csv(ranking, context) |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
414 if settings.output_residue_scores: |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
415 write_per_residue_scores(ranking, context) |
21
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
416 if settings.plot_msa: |
e7f1b552a695
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 628c9fdcb77489063145a2307b6bb6a450416dd6-dirty
galaxy-australia
parents:
20
diff
changeset
|
417 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
|
418 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
419 |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
420 if __name__ == '__main__': |
f9eb041c518c
planemo upload for repository https://github.com/usegalaxy-au/tools-au commit ee77734f1800350fa2a6ef28b2b8eade304a456f-dirty
galaxy-australia
parents:
diff
changeset
|
421 main() |