-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore_tests_fab_collection.py
259 lines (215 loc) · 14.2 KB
/
core_tests_fab_collection.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import unittest
from abpytools import FabCollection, ChainCollection, Fab
import os
from glob import glob
from . import ABNUM_URL, check_connection
class FabCollectionCore(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.light_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_light_2_sequences.json',
verbose=False, show_progressbar=False)
cls.heavy_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_heavy_2_sequences.json',
verbose=False, show_progressbar=False)
cls.heavy_chain_1 = cls.heavy_chain_collection[0]
cls.light_chain_1 = cls.light_chain_collection[0]
cls.heavy_chain_2 = cls.heavy_chain_collection[1]
cls.light_chain_2 = cls.light_chain_collection[1]
cls.fab_1 = Fab(heavy_chain=cls.heavy_chain_1, light_chain=cls.light_chain_1, name='Fab1')
cls.fab_2 = Fab(heavy_chain=cls.heavy_chain_2, light_chain=cls.light_chain_2, name='Fab2')
def test_FabCollection_input_exception_1(self):
self.assertRaises(ValueError, FabCollection, None, 0, 0)
def test_FabCollection_input_exception_2(self):
self.assertRaises(ValueError, FabCollection, None, [0, 0], [0, 0])
def test_FabCollection_input_exception_3(self):
self.assertRaises(ValueError, FabCollection, None, self.heavy_chain_1, [0, 0])
def test_FabCollection_input_exception_4(self):
self.assertRaises(ValueError, FabCollection, None, [0, 0], self.light_chain_1)
def test_FabCollection_input_exception_5(self):
self.assertRaises(ValueError, FabCollection)
def test_FabCollection_input_exception_6(self):
# instantiation of FabCollection checks if there are as many heavy as light chains
self.assertRaises(ValueError, FabCollection, None, [self.heavy_chain_1, self.heavy_chain_2],
[self.light_chain_1])
def test_FabCollection_input_exception_7(self):
# instantiation of FabCollection checks if there are as many names as fabs
self.assertRaises(ValueError, FabCollection, [self.fab_1], None, None, ['foo', 'bar'])
def test_FabCollection_input_exception_8(self):
# instantiation of FabCollection checks if names is a list of strings
self.assertRaises(ValueError, FabCollection, [self.fab_1], None, None, [1])
def test_FabCollection_input_1(self):
self.assertIsInstance(FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.light_chain_collection),
FabCollection)
def test_FabCollection_input_2(self):
# check if input with a list with fab objects works
self.assertIsInstance(FabCollection(fab=[self.fab_1, self.fab_2]),
FabCollection)
def test_FabCollection_input_3(self):
# check if input with a list of Chain objects
self.assertIsInstance(FabCollection(heavy_chains=[self.heavy_chain_1, self.heavy_chain_2],
light_chains=[self.light_chain_1, self.light_chain_2]),
FabCollection)
def test_FabCollection_input4(self):
light_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_light_2_sequences.json')
heavy_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_heavy_2_sequences.json')
fab_collection = FabCollection(light_chains=light_chain_collection,
heavy_chains=heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertEqual(fab_collection.numbering_table()['Light']['CDR3']['L89'].loc['Fab1'], 'Q')
def test_FabCollection_json1(self):
light_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_light_2_sequences.json')
heavy_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_heavy_2_sequences.json')
fab_collection = FabCollection(light_chains=light_chain_collection,
heavy_chains=heavy_chain_collection,
names=['Fab1', 'Fab2'])
fab_collection.save(file_format='json', path='./tests/fab_1')
self.assertTrue(os.path.isfile('./tests/fab_1.json'))
def test_FabCollection_json2(self):
fab_collection = FabCollection.load_from_file(path='./tests/fab_1.json',
show_progressbar=False,
verbose=False)
light_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_light_2_sequences.json')
heavy_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_heavy_2_sequences.json')
self.assertEqual(fab_collection._light_chains.sequences[0], light_chain_collection.sequences[0])
self.assertEqual(fab_collection._heavy_chains.sequences[0], heavy_chain_collection.sequences[0])
def test_FabCollection_pb2_1(self):
light_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_light_2_sequences.json')
heavy_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_heavy_2_sequences.json')
fab_collection = FabCollection(light_chains=light_chain_collection,
heavy_chains=heavy_chain_collection,
names=['Fab1', 'Fab2'])
fab_collection.save(file_format='pb2', path='./tests/fab_1')
self.assertTrue(os.path.isfile('./tests/fab_1.pb2'))
def test_FabCollection_pb2_2(self):
fab_collection = FabCollection.load_from_file(path='./tests/fab_1.pb2',
show_progressbar=False,
verbose=False)
light_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_light_2_sequences.json')
heavy_chain_collection = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_heavy_2_sequences.json')
self.assertEqual(fab_collection._light_chains.sequences[0], light_chain_collection.sequences[0])
self.assertEqual(fab_collection._heavy_chains.sequences[0], heavy_chain_collection.sequences[0])
self.assertEqual(fab_collection._light_chains.names[0], light_chain_collection.names[0])
self.assertEqual(fab_collection._heavy_chains.names[0], heavy_chain_collection.names[0])
def test_FabCollection_MW(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertAlmostEqual(fab_collection.molecular_weights()[0], 25078.143331999992)
def test_FabCollection_ec_1(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection.extinction_coefficients()[0], 52870)
def test_FabCollection_ec_2(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertAlmostEqual(fab_collection.extinction_coefficients(normalise=True)[0], 2.1082102969136987)
def test_FabCollection_charge(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertAlmostEqual(fab_collection.charge().sum(), -2.0354649111988743)
def test_FabCollection_total_charge(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertAlmostEqual(fab_collection.total_charge()[0], 3.3658691836339365)
def test_FabCollection_name_1(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection._heavy_chains.names[0], 'Seq1')
def test_FabCollection_name_2(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection._heavy_chains.names[1], 'Seq2')
def test_FabCollection_name_3(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection._light_chains.names[0], 'LightSeq1')
def test_FabCollection_name_4(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection._light_chains.names[1], 'LightSeq2')
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_FabCollection_igblast_query_1(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
fab_collection.igblast_server_query()
self.assertAlmostEqual(fab_collection.germline_identity['Heavy', 'Total'].iloc[0], 93.8)
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_FabCollection_igblast_query_1(self):
# check germline assignment
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
fab_collection.igblast_server_query()
self.assertEqual(fab_collection.germline['Heavy', 'Assignment']['Fab1'], 'IGHV1-8*01')
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_FabCollection_igblast_query_1(self):
# check germline assignment score
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
fab_collection.igblast_server_query()
self.assertAlmostEqual(fab_collection.germline['Heavy', 'Score'].loc['Fab1'], 1.82e-66)
def test_FabCollection_HMatrix(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection.hydrophobicity_matrix().shape, (2, 296))
def test_FabCollection_names(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertEqual(fab_collection.names[0], 'Fab1')
def test_FabCollection_n_ab(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(fab_collection.n_ab, 2)
def test_FabCollection_len(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection)
self.assertEqual(len(fab_collection), 2)
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_FabCollection_germline_identity(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertAlmostEqual(fab_collection.germline_identity['Average']['CDR3'].loc['Fab1'], 78.55)
def test_FabCollection_slicing_1(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertIsInstance(fab_collection[0], Fab)
def test_FabCollection_slicing_2(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertEqual(fab_collection[0].name, 'Fab1')
def test_FabCollection_slicing_3(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertEqual(fab_collection[[0, 1]].names, ['Fab1', 'Fab2'])
def test_FabCollection_slicing_4(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertEqual(fab_collection[[0, 1]]._heavy_chains.names, ['Seq1', 'Seq2'])
def test_FabCollection_slicing_5(self):
fab_collection = FabCollection(light_chains=self.light_chain_collection,
heavy_chains=self.heavy_chain_collection,
names=['Fab1', 'Fab2'])
self.assertEqual(fab_collection[[0, 1]]._light_chains.names, ['LightSeq1', 'LightSeq2'])
@classmethod
def tearDownClass(cls):
for name in glob('./tests/*'):
if name.split('.')[-1] != 'py' and os.path.isfile(name):
os.remove(name)