annotate gen_extra_outputs.py @ 10:072c324f20fc draft

planemo upload for repository https://github.com/usegalaxy-au/tools-au commit c8f9b460b5c5f2ef0344719d38f6be9d1a3da573
author galaxy-australia
date Fri, 16 Sep 2022 02:19:37 +0000
parents 3bd420ec162d
children c0e71cb2bd1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
1 """Generate additional output files not produced by AlphaFold."""
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
2
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
3 import json
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
4 import pickle
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
5 import argparse
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
6 from typing import Any, Dict, List
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
7
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
8 # Keys for accessing confidence data from JSON/pkl files
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
9 # They change depending on whether the run was monomer or multimer
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
10 CONTEXT_KEY = {
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
11 'monomer': 'plddts',
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
12 'multimer': 'iptm+ptm',
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
13 }
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
14
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
15
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
16 class Settings:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
17 """parses then keeps track of program settings"""
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
18 def __init__(self):
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
19 self.workdir = None
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
20 self.output_confidence_scores = True
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
21 self.output_residue_scores = False
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
22 self.is_multimer = False
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
23
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
24 def parse_settings(self) -> None:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
25 parser = argparse.ArgumentParser()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
26 parser.add_argument(
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
27 "workdir",
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
28 help="alphafold output directory",
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
29 type=str
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
30 )
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
31 parser.add_argument(
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
32 "-p",
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
33 "--plddts",
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
34 help="output per-residue confidence scores (pLDDTs)",
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
35 action="store_true"
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
36 )
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
37 parser.add_argument(
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
38 "--multimer",
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
39 help="parse output from AlphaFold multimer",
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
40 action="store_true"
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
41 )
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
42 args = parser.parse_args()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
43 self.workdir = args.workdir.rstrip('/')
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
44 self.output_residue_scores = args.plddts
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
45 self.is_multimer = False
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
46 self.is_multimer = args.multimer
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
47
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
48
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
49 class ExecutionContext:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
50 """uses program settings to get paths to files etc"""
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
51 def __init__(self, settings: Settings):
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
52 self.settings = settings
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
53
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
54 @property
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
55 def ranking_debug(self) -> str:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
56 return f'{self.settings.workdir}/ranking_debug.json'
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
57
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
58 @property
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
59 def model_pkls(self) -> List[str]:
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
60 ext = '.pkl'
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
61 if self.settings.is_multimer:
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
62 ext = '_multimer.pkl'
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
63 return [
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
64 f'{self.settings.workdir}/result_model_{i}{ext}'
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
65 for i in range(1, 6)
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
66 ]
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
67
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
68 @property
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
69 def model_conf_score_output(self) -> str:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
70 return f'{self.settings.workdir}/model_confidence_scores.tsv'
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
71
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
72 @property
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
73 def plddt_output(self) -> str:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
74 return f'{self.settings.workdir}/plddts.tsv'
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
75
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
76
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
77 class FileLoader:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
78 """loads file data for use by other classes"""
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
79
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
80 def __init__(self, context: ExecutionContext):
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
81 self.context = context
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
82
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
83 @property
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
84 def confidence_key(self) -> str:
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
85 """Return the correct key for confidence data."""
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
86 if self.context.settings.is_multimer:
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
87 return CONTEXT_KEY['multimer']
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
88 return CONTEXT_KEY['monomer']
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
89
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
90 def get_model_mapping(self) -> Dict[str, int]:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
91 data = self.load_ranking_debug()
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
92 return {name: int(rank) + 1
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
93 for (rank, name) in enumerate(data['order'])}
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
94
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
95 def get_conf_scores(self) -> Dict[str, float]:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
96 data = self.load_ranking_debug()
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
97 return {
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
98 name: float(f'{score:.2f}')
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
99 for name, score in data[self.confidence_key].items()
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
100 }
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
101
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
102 def load_ranking_debug(self) -> Dict[str, Any]:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
103 with open(self.context.ranking_debug, 'r') as fp:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
104 return json.load(fp)
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
105
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
106 def get_model_plddts(self) -> Dict[str, List[float]]:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
107 plddts: Dict[str, List[float]] = {}
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
108 model_pkls = self.context.model_pkls
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
109 for i in range(len(model_pkls)):
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
110 pklfile = model_pkls[i]
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
111 with open(pklfile, 'rb') as fp:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
112 data = pickle.load(fp)
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
113 plddts[f'model_{i+1}'] = [
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
114 float(f'{x:.2f}')
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
115 for x in data['plddt']
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
116 ]
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
117 return plddts
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
118
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
119
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
120 class OutputGenerator:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
121 """generates the output data we are interested in creating"""
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
122 def __init__(self, loader: FileLoader):
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
123 self.loader = loader
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
124
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
125 def gen_conf_scores(self):
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
126 mapping = self.loader.get_model_mapping()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
127 scores = self.loader.get_conf_scores()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
128 ranked = list(scores.items())
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
129 ranked.sort(key=lambda x: x[1], reverse=True)
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
130 return {f'model_{mapping[name]}': score
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
131 for name, score in ranked}
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
132
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
133 def gen_residue_scores(self) -> Dict[str, List[float]]:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
134 mapping = self.loader.get_model_mapping()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
135 model_plddts = self.loader.get_model_plddts()
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
136 return {f'model_{mapping[name]}': plddts
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
137 for name, plddts in model_plddts.items()}
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
138
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
139
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
140 class OutputWriter:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
141 """writes generated data to files"""
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
142 def __init__(self, context: ExecutionContext):
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
143 self.context = context
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
144
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
145 def write_conf_scores(self, data: Dict[str, float]) -> None:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
146 outfile = self.context.model_conf_score_output
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
147 with open(outfile, 'w') as fp:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
148 for model, score in data.items():
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
149 fp.write(f'{model}\t{score}\n')
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
150
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
151 def write_residue_scores(self, data: Dict[str, List[float]]) -> None:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
152 outfile = self.context.plddt_output
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
153 model_plddts = list(data.items())
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
154 model_plddts.sort()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
155
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
156 with open(outfile, 'w') as fp:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
157 for model, plddts in model_plddts:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
158 plddt_str_list = [str(x) for x in plddts]
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
159 plddt_str = ','.join(plddt_str_list)
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
160 fp.write(f'{model}\t{plddt_str}\n')
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
161
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
162
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
163 def main():
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
164 # setup
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
165 settings = Settings()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
166 settings.parse_settings()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
167 context = ExecutionContext(settings)
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
168 loader = FileLoader(context)
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
169
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
170 # generate & write outputs
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
171 generator = OutputGenerator(loader)
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
172 writer = OutputWriter(context)
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
173
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
174 # confidence scores
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
175 conf_scores = generator.gen_conf_scores()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
176 writer.write_conf_scores(conf_scores)
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
177
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
178 # per-residue plddts
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
179 if settings.output_residue_scores:
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
180 residue_scores = generator.gen_residue_scores()
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
181 writer.write_residue_scores(residue_scores)
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
182
9
3bd420ec162d planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 7726c3cba165bdc8fc6366ec0ce6596e55657468
galaxy-australia
parents: 0
diff changeset
183
0
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
184 if __name__ == '__main__':
7ae9d78b06f5 "planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff changeset
185 main()