-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
153 lines (128 loc) · 5.19 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# from michelanglo_app.transplier import PyMolTranspiler
#
# transpiler = PyMolTranspiler(file='michelanglo_app/demo/1gfl.pse')
# #print(transpiler.get_view())
# #print(transpiler.get_reps())
# print(transpiler.get_loadfun_js(tag_wrapped=True, viewport='viewport', funname='loadfun'))
from michelanglo_protein import ProteinAnalyser, Structure, Mutation, global_settings
from michelanglo_protein.analyse import Mutator
from michelanglo_protein.protein_analyser.subprocess import run_subprocess
import unittest, requests, json, time, pyrosetta
def fun(sleep_time: int):
time.sleep(sleep_time)
return {'status': 'slept'}
class SubTest(unittest.TestCase):
def test_short(self):
out = run_subprocess(fun, timeout=5, sleep_time=1)
self.assertEqual(out['status'], 'slept')
def test_long(self):
try:
run_subprocess(fun, timeout=1, sleep_time=5)
except Exception as e:
self.assertIn('Timeout', str(e))
class MutatorTest(unittest.TestCase):
def setUp(self):
# 1SFT is alanine racemase
self.pdbblock = requests.get('https://files.rcsb.org/download/1SFT.pdb').text
def tearDown(self):
pass
def test_basic(self):
# formerly from michelanglo_protein.analyse.pyrosetta_modifier import test
# 1SFT/A/A/HIS`166
tick = time.time()
m = Mutator(pdbblock=self.pdbblock, target_resi=166, target_chain='A', cycles=1, radius=3)
tock = time.time()
print('LOAD', tock - tick)
m.do_relax()
m.mark('relaxed')
tack = time.time()
print('RELAX', tack - tock)
native = m.pose.clone()
m.mutate('P')
m.mark('mutate')
m.do_relax()
m.mark('mutarelax')
teck = time.time()
print('MutaRelax', teck - tack)
print(m.scores)
muta = m.target_pdb2pose(m.target)
print(pyrosetta.rosetta.core.scoring.CA_rmsd(native, m.pose, muta - 1, muta + 1))
def test_main_mutator(self):
pa = ProteinAnalyser()
pa.structural = Structure('test', 'test w alaR',
1, 999, 'test',
type='custom',
coordinates=self.pdbblock
)
pa.mutation = Mutation('A166W')
pa.analyse_FF(spit_process=False)
def test_sub_mutator(self):
pa = ProteinAnalyser()
pa.structural = Structure('test', 'test w alaR',
1, 999, 'test',
type='custom',
coordinates=self.pdbblock
)
pa.mutation = Mutation('A166W')
pa.analyse_FF(spit_process=True)
class FullTest(unittest.TestCase):
def enable_logging(self):
import logging
from michelanglo_protein.analyse.pyrosetta_modifier import log
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
log.setLevel(logging.DEBUG)
log.addHandler(handler)
return log
def get_protein(self, uniprot_id:str, mutation:str) -> ProteinAnalyser:
protein = ProteinAnalyser(uniprot=uniprot_id, taxid=9606)
protein.load()
protein.add_alphafold2()
protein.mutation = Mutation(mutation)
protein.predict_effect()
return protein
def setUp(self):
self.log = self.enable_logging()
global_settings.startup('../protein-data')
def tearDown(self):
pass
def test_legacy(self):
protein:ProteinAnalyser = self.get_protein('Q8WXF1', 'A175D')
protein.predict_effect(full=True)
def test_full(self):
protein:ProteinAnalyser = self.get_protein('Q8WXF1', 'A175D')
# protein.retrieve_structures_from_swissmodel()
structure = protein.get_best_model()
protein.analyse_structure(structure)
out = protein.analyse_FF(spit_process=True) # calls analyse_mutation
self.log.info(out)
self.assertIsInstance(out['ddG'], float)
self.assertLess(out['ddG'], 5)
def test_gnomad(self):
protein:ProteinAnalyser = self.get_protein('Q8WXF1', 'A175D')
protein.analyse_structure()
out = protein.analyse_gnomad_FF(spit_process=True)
self.log.info(out)
def test_alpha(self):
protein:ProteinAnalyser = self.get_protein('O75911', 'L273D')
protein.add_alphafold2()
protein.pdbs =[]
protein.swissmodel = []
protein.predict_effect()
# protein.retrieve_structures_from_swissmodel()
# protein.add_alphafold2()
protein.analyse_structure()
out = protein.analyse_FF(spit_process=True) # calls analyse_mutation
self.log.info(out)
self.assertIsInstance(out['ddG'], float)
self.assertLess(out['ddG'], 5)
def untest_adhoc(self):
# test to try with sefault settings
# add to `.analyse_FF` this:
# with open('/Users/matteo/Desktop/test.json', 'w') as f:
# json.dump(init_settings, f)
with open('/Users/matteo/Desktop/test.json', 'r') as f:
settings = json.load(f)
Mutator(**settings).analyse_mutation('D')
if __name__ == '__main__':
unittest.main()