2
2
import tarfile
3
3
import tempfile
4
4
from io import BufferedReader , TextIOWrapper
5
- from os import devnull
6
5
from os .path import basename , dirname , join , splitext
7
6
from pathlib import Path
8
- from sys import stderr , version_info
7
+ from sys import version_info
9
8
10
9
import pytest
11
10
from Bio .PDB .PDBParser import PDBParser
12
11
from Bio .PDB .Residue import Residue
13
12
from Bio .PDB .Structure import Structure
14
13
15
- from prodigy_prot .modules .freesasa_tools import stdchannel_redirected
16
14
from prodigy_prot .modules .parsers import validate_structure
17
15
from prodigy_prot .modules .prodigy import (
18
16
Prodigy ,
@@ -175,23 +173,6 @@ def test_print_pymol_script(input_pdb_structure, prodigy_class):
175
173
Path (outfile .name ).unlink ()
176
174
177
175
178
- def get_data_path (path ):
179
- """
180
- Get the path of a file in data for file input
181
-
182
- Args:
183
- path: path within data folder
184
-
185
- Returns:
186
- The path to the data file in unix notation
187
- """
188
- try :
189
- return join (dirname (__file__ ), ".." , "data" , * path .split ("/" ))
190
- except NameError :
191
- #
192
- return join ("data" , * path .split ("/" ))
193
-
194
-
195
176
@pytest .mark .integration
196
177
def test_dataset_prediction (compressed_dataset_f , expected_dataset_json ):
197
178
"""
@@ -212,39 +193,40 @@ def test_dataset_prediction(compressed_dataset_f, expected_dataset_json):
212
193
# run prodigy for each dataset in the PDB
213
194
for entry in dataset :
214
195
s_name , s_ext = splitext (basename (entry .name ))
196
+
215
197
# skip system files in archive
216
198
if not s_name .isalnum () or s_ext != ".pdb" :
217
199
continue
218
- # chains = expected_data[s_name]["Interacting_chains"]
200
+
219
201
handle = dataset .extractfile (entry )
202
+
220
203
# Wrap filehandle to ensure string file handle in Python 3
221
204
if version_info [0 ] >= 3 :
222
205
handle = TextIOWrapper (BufferedReader (handle )) # type: ignore
223
- # Suppress gap warnings when parsing structure
224
- with stdchannel_redirected (stderr , devnull ):
225
- s = validate_structure (
226
- parser .get_structure (s_name , handle ), selection = ["A" , "B" ]
227
- )
206
+
207
+ parsed_structure = parser .get_structure (s_name , handle )
208
+ assert isinstance (parsed_structure , Structure )
209
+
210
+ s = validate_structure (parsed_structure , selection = ["A" , "B" ])
211
+
228
212
# Test for structure object
229
213
assert isinstance (s , Structure )
230
- # self.assertIsInstance(s, Structure.Structure)
231
- # instantiate Prdigy object,
214
+
232
215
# run prediction and retrieve result dict
233
216
prod = Prodigy (s , selection = ["A" , "B" ])
234
217
prod .predict ()
235
218
results = prod .as_dict ()
219
+
236
220
# check for equality of prdicted interface residues
237
221
for k in keys_equal :
238
222
observed_value = results [k ]
239
223
expected_value = expected_data [s_name ][k ]
240
-
241
224
assert observed_value == pytest .approx (expected_value )
242
225
243
226
# check that NIS and binding afinity values are within 2% of
244
227
# expected values and add diffs for summary
245
228
for k in diffs .keys ():
246
229
delta = abs (results [k ] / expected_data [s_name ][k ] - 1 )
247
230
# assume a difference of less then 2%
248
- # self.assertAlmostEqual(delta, 0, delta=0.02)
249
231
assert delta == pytest .approx (0 , abs = 0.02 )
250
232
diffs [k ].append (delta )
0 commit comments