-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore_tests_chain.py
133 lines (114 loc) · 6.79 KB
/
core_tests_chain.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
import unittest
from abpytools import Chain, ChainCollection
from abpytools.core.flags import *
from parameterized import parameterized
from . import read_sequence, check_connection, ABNUM_URL
class ChainCore(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.test_sequence = read_sequence('./tests/Data/chain_collection_fasta_test.fasta')
cls.heavy_chain_collection_object = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_1_heavy.json',
show_progressbar=False, verbose=False)
cls.heavy_chain_object = cls.heavy_chain_collection_object[0]
cls.light_chain_collection_object = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_1_light.json',
show_progressbar=False, verbose=False)
cls.light_chain_object = cls.light_chain_collection_object[0]
def test_Chain_load(self):
chain = Chain(sequence=self.test_sequence)
chain.load()
self.assertIsInstance(chain, Chain)
@parameterized.expand([
("light_chain", "light_chain_object", "light"),
("heavy_chain", "heavy_chain_object", "heavy")
])
def test_Chain_chain(self, name, input, expected):
self.assertEqual(getattr(self, input).chain, expected)
@parameterized.expand([
(f"{HYDROPHOBICITY_FLAGS.EW}_hydrophobicity_set", HYDROPHOBICITY_FLAGS.EW, -8.01),
(f"{HYDROPHOBICITY_FLAGS.HH}_hydrophobicity_set", HYDROPHOBICITY_FLAGS.HH, 109.15),
(f"{HYDROPHOBICITY_FLAGS.KD}_hydrophobicity_set", HYDROPHOBICITY_FLAGS.KD, -22.2),
(f"{HYDROPHOBICITY_FLAGS.MF}_hydrophobicity_set", HYDROPHOBICITY_FLAGS.MF, 40.55),
(f"{HYDROPHOBICITY_FLAGS.WW}_hydrophobicity_set", HYDROPHOBICITY_FLAGS.WW, -4.96)
])
def test_Chain_hydrophobicity(self, name, input, expected):
self.assertAlmostEqual(self.heavy_chain_object.ab_hydrophobicity_matrix(input).sum(), expected)
def test_Chain_hydrophobicity_raise_error(self):
self.assertRaises(ValueError, self.heavy_chain_object.ab_hydrophobicity_matrix, "TEST_I_DONT_EXIST")
def test_Chain_hydrophobicity_not_loaded(self):
test_sequence = read_sequence(
'./tests/Data/chain_collection_fasta_test.fasta')
obj = Chain(sequence=test_sequence, name="test")
self.assertAlmostEqual(obj.ab_hydrophobicity_matrix(HYDROPHOBICITY_FLAGS.EW).sum(), -8.01)
@parameterized.expand([
(f"{PI_FLAGS.EMBOSS}_pka_set", PI_FLAGS.EMBOSS, 1.9497227766014302),
(f"{PI_FLAGS.DTASELECT}_pka_set", PI_FLAGS.DTASELECT, 1.9404670785960516),
(f"{PI_FLAGS.SOLOMON}_pka_set", PI_FLAGS.SOLOMON, 1.7993251336784457),
(f"{PI_FLAGS.SILLERO}_pka_set", PI_FLAGS.SILLERO, 2.0235864050746666),
(f"{PI_FLAGS.RODWELL}_pka_set", PI_FLAGS.RODWELL, 1.8135202627308433),
(f"{PI_FLAGS.WIKIPEDIA}_pka_set", PI_FLAGS.WIKIPEDIA, 1.7497642167513607),
(f"{PI_FLAGS.LEHNINGER}_pka_set", PI_FLAGS.LEHNINGER, 1.8081589709221348),
(f"{PI_FLAGS.GRIMSLEY}_pka_set", PI_FLAGS.GRIMSLEY, 0.5277757339608096)
])
def test_Chain_charge(self, name, input, expected):
self.assertAlmostEqual(self.heavy_chain_object.ab_charge(pka_database=input).sum(), expected)
def test_Chain_charge_not_aligned(self):
# this number is different from above since unaligned sequences can
# include amino acids that are not found in the CDR and FR definitions
self.assertAlmostEqual(self.heavy_chain_object.ab_charge(pka_database=PI_FLAGS.EMBOSS, align=False).sum(),
1.8015020954105214)
@parameterized.expand([
(f"{CHAIN_FLAGS.CDR1}", CHAIN_FLAGS.CDR1, 7),
(f"{CHAIN_FLAGS.CDR2}", CHAIN_FLAGS.CDR2, 5),
(f"{CHAIN_FLAGS.CDR3}", CHAIN_FLAGS.CDR3, 15),
(f"{CHAIN_FLAGS.FR1}", CHAIN_FLAGS.FR1, 25),
(f"{CHAIN_FLAGS.FR2}", CHAIN_FLAGS.FR2, 19),
(f"{CHAIN_FLAGS.FR3}", CHAIN_FLAGS.FR3, 41),
(f"{CHAIN_FLAGS.FR4}", CHAIN_FLAGS.FR4, 11),
])
def test_Chain_numbering_table_np(self, name, input, expected):
self.assertEqual((self.heavy_chain_object.ab_numbering_table(as_array=True, region=input) != '-').sum(),
expected)
def test_Chain_numbering_table_pd(self):
self.assertEqual((self.heavy_chain_object.ab_numbering_table(as_array=False,
region='CDR1').values != '-').sum(), 7)
@parameterized.expand([
("reduced_normalise", [True, True], 2.6041130777737154),
("notreduced_normalise", [False, True], 2.6165944479701),
("notreduced_notnormalise", [False, False], 52410),
("reduced_notnormalise", [True, False], 52160)
])
def test_Chain_extinction_coefficient(self, name, input, expected):
self.assertAlmostEqual(self.heavy_chain_object.ab_ec(reduced=input[0], normalise=input[1]), expected)
def test_Chain_sequence_len(self):
self.assertEqual(len(self.heavy_chain_object), 184)
def test_Chain_set_name(self):
heavy_chain_object = ChainCollection.load_from_file(
path='./tests/Data/chain_collection_1_heavy.json',
show_progressbar=False, verbose=False)
heavy_chain_object[0].set_name("new_name")
self.assertEqual(heavy_chain_object[0].name, "new_name")
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_Chain_unnumbered_sequence(self):
test_seq = Chain(sequence='TEST')
test_seq.load()
self.assertEqual(test_seq.status, 'Unnumbered')
@parameterized.expand([
(f"{NUMBERING_FLAGS.CHOTHIA}_numbering", NUMBERING_FLAGS.CHOTHIA, "H82A"),
(f"{NUMBERING_FLAGS.CHOTHIA_EXT}_numbering", NUMBERING_FLAGS.CHOTHIA_EXT, "H82"),
(f"{NUMBERING_FLAGS.KABAT}_numbering", NUMBERING_FLAGS.KABAT, "H82A")
])
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_numbering_scheme_alignment(self, name, input, expected):
test = Chain(sequence=self.test_sequence, name="test", numbering_scheme=input)
self.assertEqual(test.ab_numbering()[82], expected)
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_numbering_scheme_alignment_unknown_scheme(self):
test = Chain(sequence=self.test_sequence, name="test", numbering_scheme="MyNumberingScheme123")
self.assertRaises(ValueError, test.ab_numbering)
@unittest.skipUnless(check_connection(URL=ABNUM_URL), 'No internet connection, skipping test.')
def test_load_from_string(self):
test = Chain.load_from_string(sequence=self.test_sequence, name="test",
numbering_scheme=NUMBERING_FLAGS.CHOTHIA)
self.assertEqual(test.ab_numbering()[82], "H82A")