annotate outputs.py @ 14:d00e15139065 draft

planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
author galaxy-australia
date Tue, 28 Feb 2023 01:15:42 +0000
parents
children a58f7eb0df2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
1 """Generate additional output files not produced by AlphaFold.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
2
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
3 Currently this is includes:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
4 - model confidence scores
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
5 - per-residue confidence scores (pLDDTs - optional output)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
6 - model_*.pkl files renamed with rank order
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
7
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
8 N.B. There have been issues with this script breaking between AlphaFold
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
9 versions due to minor changes in the output directory structure across minor
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
10 versions. It will likely need updating with future releases of AlphaFold.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
11
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
12 This code is more complex than you might expect due to the output files
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
13 'moving around' considerably, depending on run parameters. You will see that
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
14 several output paths are determined dynamically.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
15 """
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
16
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
17 import argparse
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
18 import json
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
19 import os
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
20 import pickle as pk
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
21 import shutil
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
22 from pathlib import Path
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
23 from typing import List
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
24
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
25 # Output file names
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
26 OUTPUT_DIR = 'extra'
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
27 OUTPUTS = {
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
28 'model_pkl': OUTPUT_DIR + '/ranked_{rank}.pkl',
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
29 'model_confidence_scores': OUTPUT_DIR + '/model_confidence_scores.tsv',
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
30 'plddts': OUTPUT_DIR + '/plddts.tsv',
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
31 'relax': OUTPUT_DIR + '/relax_metrics_ranked.json',
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
32 }
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
33
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
34 # Keys for accessing confidence data from JSON/pkl files
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
35 # They change depending on whether the run was monomer or multimer
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
36 PLDDT_KEY = {
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
37 'monomer': 'plddts',
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
38 'multimer': 'iptm+ptm',
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
39 }
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
40
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
41
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
42 class Settings:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
43 """Parse and store settings/config."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
44 def __init__(self):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
45 self.workdir = None
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
46 self.output_confidence_scores = True
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
47 self.output_residue_scores = False
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
48 self.is_multimer = False
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
49
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
50 def parse_settings(self) -> None:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
51 parser = argparse.ArgumentParser()
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
52 parser.add_argument(
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
53 "workdir",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
54 help="alphafold output directory",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
55 type=str
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
56 )
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
57 parser.add_argument(
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
58 "-p",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
59 "--plddts",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
60 help="output per-residue confidence scores (pLDDTs)",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
61 action="store_true"
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
62 )
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
63 parser.add_argument(
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
64 "-m",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
65 "--multimer",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
66 help="parse output from AlphaFold multimer",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
67 action="store_true"
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
68 )
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
69 parser.add_argument(
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
70 "--model-pkl",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
71 dest="model_pkl",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
72 help="rename model pkl outputs with rank order",
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
73 action="store_true"
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
74 )
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
75 args = parser.parse_args()
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
76 self.workdir = Path(args.workdir.rstrip('/'))
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
77 self.output_residue_scores = args.plddts
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
78 self.output_model_pkls = args.model_pkl
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
79 self.is_multimer = args.multimer
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
80 self.output_dir = self.workdir / OUTPUT_DIR
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
81 os.makedirs(self.output_dir, exist_ok=True)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
82
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
83
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
84 class ExecutionContext:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
85 """Collect file paths etc."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
86 def __init__(self, settings: Settings):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
87 self.settings = settings
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
88 if settings.is_multimer:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
89 self.plddt_key = PLDDT_KEY['multimer']
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
90 else:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
91 self.plddt_key = PLDDT_KEY['monomer']
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
92
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
93 def get_model_key(self, ix: int) -> str:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
94 """Return json key for model index.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
95
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
96 The key format changed between minor AlphaFold versions so this
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
97 function determines the correct key.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
98 """
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
99 with open(self.ranking_debug) as f:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
100 data = json.load(f)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
101 model_keys = list(data[self.plddt_key].keys())
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
102 for k in model_keys:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
103 if k.startswith(f"model_{ix}_"):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
104 return k
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
105 return KeyError(
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
106 f'Could not find key for index={ix} in'
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
107 ' ranking_debug.json')
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
108
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
109 @property
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
110 def ranking_debug(self) -> str:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
111 return self.settings.workdir / 'ranking_debug.json'
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
112
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
113 @property
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
114 def relax_metrics(self) -> str:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
115 return self.settings.workdir / 'relax_metrics.json'
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
116
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
117 @property
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
118 def relax_metrics_ranked(self) -> str:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
119 return self.settings.workdir / 'relax_metrics_ranked.json'
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
120
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
121 @property
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
122 def model_pkl_paths(self) -> List[str]:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
123 return sorted([
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
124 self.settings.workdir / f
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
125 for f in os.listdir(self.settings.workdir)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
126 if f.startswith('result_model_') and f.endswith('.pkl')
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
127 ])
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
128
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
129
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
130 class ResultModelPrediction:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
131 """Load and manipulate data from result_model_*.pkl files."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
132 def __init__(self, path: str, context: ExecutionContext):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
133 self.context = context
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
134 self.path = path
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
135 self.name = os.path.basename(path).replace('result_', '').split('.')[0]
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
136 with open(path, 'rb') as path:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
137 self.data = pk.load(path)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
138
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
139 @property
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
140 def plddts(self) -> List[float]:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
141 """Return pLDDT scores for each residue."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
142 return list(self.data['plddt'])
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
143
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
144
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
145 class ResultRanking:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
146 """Load and manipulate data from ranking_debug.json file."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
147
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
148 def __init__(self, context: ExecutionContext):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
149 self.path = context.ranking_debug
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
150 self.context = context
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
151 with open(self.path, 'r') as f:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
152 self.data = json.load(f)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
153
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
154 @property
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
155 def order(self) -> List[str]:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
156 """Return ordered list of model indexes."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
157 return self.data['order']
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
158
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
159 def get_plddt_for_rank(self, rank: int) -> List[float]:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
160 """Get pLDDT score for model instance."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
161 return self.data[self.context.plddt_key][self.data['order'][rank - 1]]
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
162
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
163 def get_rank_for_model(self, model_name: str) -> int:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
164 """Return 0-indexed rank for given model name.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
165
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
166 Model names are expressed in result_model_*.pkl file names.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
167 """
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
168 return self.data['order'].index(model_name)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
169
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
170
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
171 def write_confidence_scores(ranking: ResultRanking, context: ExecutionContext):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
172 """Write per-model confidence scores."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
173 path = context.settings.workdir / OUTPUTS['model_confidence_scores']
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
174 with open(path, 'w') as f:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
175 for rank in range(1, 6):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
176 score = ranking.get_plddt_for_rank(rank)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
177 f.write(f'ranked_{rank - 1}\t{score:.2f}\n')
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
178
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
179
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
180 def write_per_residue_scores(
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
181 ranking: ResultRanking,
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
182 context: ExecutionContext,
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
183 ):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
184 """Write per-residue plddts for each model.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
185
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
186 A row of plddt values is written for each model in tabular format.
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
187 """
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
188 model_plddts = {}
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
189 for i, path in enumerate(context.model_pkl_paths):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
190 model = ResultModelPrediction(path, context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
191 rank = ranking.get_rank_for_model(model.name)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
192 model_plddts[rank] = model.plddts
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
193
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
194 path = context.settings.workdir / OUTPUTS['plddts']
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
195 with open(path, 'w') as f:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
196 for i in sorted(list(model_plddts.keys())):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
197 row = [f'ranked_{i}'] + [
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
198 str(x) for x in model_plddts[i]
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
199 ]
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
200 f.write('\t'.join(row) + '\n')
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
201
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
202
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
203 def rename_model_pkls(ranking: ResultRanking, context: ExecutionContext):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
204 """Rename model.pkl files so the rank order is implicit."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
205 for path in context.model_pkl_paths:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
206 model = ResultModelPrediction(path, context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
207 rank = ranking.get_rank_for_model(model.name)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
208 new_path = (
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
209 context.settings.workdir
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
210 / OUTPUTS['model_pkl'].format(rank=rank)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
211 )
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
212 shutil.copyfile(path, new_path)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
213
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
214
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
215 def rekey_relax_metrics(ranking: ResultRanking, context: ExecutionContext):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
216 """Replace keys in relax_metrics.json with 0-indexed rank."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
217 with open(context.relax_metrics) as f:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
218 data = json.load(f)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
219 for k in list(data.keys()):
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
220 rank = ranking.get_rank_for_model(k)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
221 data[f'ranked_{rank}'] = data.pop(k)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
222 new_path = context.settings.workdir / OUTPUTS['relax']
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
223 with open(new_path, 'w') as f:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
224 json.dump(data, f)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
225
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
226
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
227 def main():
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
228 """Parse output files and generate additional output files."""
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
229 settings = Settings()
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
230 settings.parse_settings()
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
231 context = ExecutionContext(settings)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
232 ranking = ResultRanking(context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
233 write_confidence_scores(ranking, context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
234 rekey_relax_metrics(ranking, context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
235
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
236 # Optional outputs
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
237 if settings.output_model_pkls:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
238 rename_model_pkls(ranking, context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
239
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
240 if settings.output_residue_scores:
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
241 write_per_residue_scores(ranking, context)
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
242
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
243
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
244 if __name__ == '__main__':
d00e15139065 planemo upload for repository https://github.com/usegalaxy-au/tools-au commit d490defa32d9c318137d2d781243b392cb14110d-dirty
galaxy-australia
parents:
diff changeset
245 main()