forked from pierrepo/PBxplore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_functions.py
executable file
·213 lines (189 loc) · 9.04 KB
/
test_functions.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unit tests for PBxplore.
Tests functions from different programs.
2014 - P. Poulain
"""
#===============================================================================
# load modules
#===============================================================================
import unittest
import collections
import PBlib as PB
import PDBlib as PDB
#===============================================================================
# classes for tests
#===============================================================================
class TestPDBlib(unittest.TestCase):
"""
Tests for PDBlib
"""
def test_get_dihedral(self):
"""
Test for get_dihedral()
"""
Result = collections.namedtuple('Result', ['A', 'B', 'C', 'D', 'torsion'])
results = (Result((-7.28, -9.262, 5.077),
(-7.526, -10.643, 5.529),
(-6.221, -11.438, 5.555),
(-6.289, -12.685, 5.931),
-179.663656153),
Result((-1.373, -8.817, -4.389),
(-1.203, -8.335, -5.792),
(-1.891, -6.977, -5.927),
(-1.918, -6.429, -7.107),
-176.048770127),
Result((-0.533, -8.42, -3.47 ),
(-1.373, -8.817, -4.389),
(-1.203, -8.335, -5.792),
(-1.891, -6.977, -5.927),
-84.8356057692),
Result((-1.918, -6.429, -7.107),
(-2.609, -5.125, -7.305),
(-4.108, -5.392, -7.331),
(-4.469, -6.494, -7.911),
-36.8942888266),
Result((-11.285, 6.472, -7.44 ),
(-12.62, 5.829, -7.425 ),
(-13.585, 6.626, -6.544),
(-13.098, 7.621, -5.858),
-6.58786169376),
Result((-11.284, -0.971, -2.679),
(-12.65, -0.794, -3.226),
(-13.665, -1.664, -2.479),
(-13.262, -2.363, -1.452),
3.91626706556),
Result((-2.004, -10.892, -2.611),
(-1.87, -9.835, -1.853),
(-0.726, -8.877, -2.011),
(-0.533, -8.42, -3.47),
50.065196067),
Result((11.174, -6.725, 0.458),
(10.732, -7.258, -0.86),
(9.27, -6.869, -1.096),
(8.741, -7.185, -2.245),
175.872397707))
for res in results:
torsion = PDB.get_dihedral(res.A, res.B, res.C, res.D)
self.assertAlmostEqual(torsion, res.torsion)
class TestAtomClass(unittest.TestCase):
"""
Tests for the Atom class in PDBlib
"""
def test_read_from_PDB(self):
"""
Tests for read_from_PDB()
"""
a = PDB.Atom()
a.read_from_PDB("ATOM 512 N GLU A 32 -1.870 -9.835 -1.853 1.00 0.56 N ")
self.assertAlmostEqual(a.coords(), [-1.87, -9.835, -1.853])
a.read_from_PDB("ATOM 1424 CA SER A 89 7.604 11.308 1.435 1.00 0.62 C ")
self.assertAlmostEqual(a.coords(), [7.604, 11.308, 1.435])
a.read_from_PDB("ATOM 1167 CG2 VAL B 50 9.294 44.541 -4.830 1.00 27.62 C ")
self.assertAlmostEqual(a.coords(), [9.294, 44.541, -4.83])
def test_read_from_PDBx(self):
"""
Tests for read_from_PDBx()
"""
a = PDB.Atom()
fields = ['group_PDB', 'id', 'type_symbol', 'label_atom_id',
'label_alt_id', 'label_comp_id', 'label_asym_id', 'label_entity_id',
'label_seq_id', 'pdbx_PDB_ins_code', 'Cartn_x', 'Cartn_y', 'Cartn_z',
'occupancy', 'B_iso_or_equiv', 'Cartn_x_esd', 'Cartn_y_esd',
'Cartn_z_esd', 'occupancy_esd', 'B_iso_or_equiv_esd',
'pdbx_formal_charge', 'auth_seq_id', 'auth_comp_id', 'auth_asym_id',
'auth_atom_id', 'pdbx_PDB_model_num']
line = "ATOM 4769 H HB . ILE A 1 35 ? -20.422 5.104 -0.207 1.00 0.00 ? ? ? ? ? ? 277 ILE A HB 3"
a.read_from_PDBx(line, fields)
self.assertAlmostEqual(a.coords(), [-20.422, 5.104, -0.207])
line = "ATOM 18201 H HG21 . THR A 1 140 ? 11.080 -12.466 -8.977 1.00 0.00 ? ? ? ? ? ? 382 THR A HG21 8"
a.read_from_PDBx(line, fields)
self.assertAlmostEqual(a.coords(), [11.08, -12.466, -8.977])
line = "ATOM 23720 H HE2 . HIS A 1 193 ? 13.974 24.297 0.352 1.00 0.00 ? ? ? ? ? ? 435 HIS A HE2 10"
a.read_from_PDBx(line, fields)
self.assertAlmostEqual(a.coords(), [13.974, 24.297, 0.352])
class TestChainClass(unittest.TestCase):
"""
Tests for Chain class in PDBlib
"""
def test_size(self):
"""
Tests for size()
"""
lines = ("ATOM 840 C ARG B 11 22.955 23.561 -4.012 1.00 28.07 C ",
"ATOM 849 N SER B 12 22.623 24.218 -2.883 1.00 24.77 N ",
"ATOM 850 CA SER B 12 22.385 23.396 -1.637 1.00 21.99 C ",
"ATOM 851 C SER B 12 21.150 24.066 -0.947 1.00 32.67 C ",
"ATOM 855 N ILE B 13 20.421 23.341 -0.088 1.00 30.25 N ")
ch = PDB.Chain()
for line in lines:
at = PDB.Atom()
at.read_from_PDB(line)
ch.add_atom( at )
self.assertEqual(ch.size(), 5)
def test_get_phi_psi_angles(self):
"""
Tests for get_phi_psi_angles()
"""
results = {11: {'phi': None, 'psi': None},
12: {'phi': -139.77684605036447, 'psi': 157.94348570201197},
13: {'phi': None, 'psi': None}}
lines = ("ATOM 840 C ARG B 11 22.955 23.561 -4.012 1.00 28.07 C ",
"ATOM 849 N SER B 12 22.623 24.218 -2.883 1.00 24.77 N ",
"ATOM 850 CA SER B 12 22.385 23.396 -1.637 1.00 21.99 C ",
"ATOM 851 C SER B 12 21.150 24.066 -0.947 1.00 32.67 C ",
"ATOM 855 N ILE B 13 20.421 23.341 -0.088 1.00 30.25 N ")
ch = PDB.Chain()
for line in lines:
at = PDB.Atom()
at.read_from_PDB(line)
ch.add_atom(at)
self.assertAlmostEqual(ch.get_phi_psi_angles(), results)
class TestPBlib(unittest.TestCase):
"""
Tests for PBlib
"""
def test_read_fasta(self):
headers, sequences = PB.read_fasta("test_data/1BTA.pdb.PB.fasta")
self.assertEqual(headers, ['test_data/1BTA.pdb | chain A'])
self.assertEqual(sequences, ['ZZdddfklonbfklmmmmmmmmnopafklnoiakl'
'mmmmmnoopacddddddehkllmmmmngoilmmmm'
'mmmmmmmmnopacdcddZZ'])
def test_count_to_transfac(self):
"""
Test if the count_to_transfac function works.
"""
ref_input = [' a b c d\n', # header
'1 0 0 0 0\n',
'2 2 789 99999 89\n', # one value is written
# on 5 characters
'3 99999 8888 2 2\n', # the first value is
# written on 5 characters
'4 99 0 999999 0\n', # one value is written
# on more than 5
# characters
'5 0 0 0 0\n',
]
identifier = 'identifier'
ref_output = ("ID identifier\n"
"BF unknown\n"
"P0 a b c d\n"
"00001 0 0 0 0 X\n"
"00002 2 789 99999 89 X\n"
"00003 99999 8888 2 2 X\n"
"00004 99 0 999999 0 X\n"
"00005 0 0 0 0 X\n"
"XX\n"
"//")
output = PB.count_to_transfac(identifier, ref_input)
ref_output_lines = ref_output.split('\n')
output_lines = output.split('\n')
self.assertEqual(len(ref_output_lines), len(output_lines),
'Not the right number of lines')
for ref_line, line in zip(ref_output_lines, output_lines):
print('ref:', ref_line)
print('out:', line)
self.assertEqual(ref_line, line)
if __name__ == '__main__':
unittest.main()