Skip to content

Commit 74fb871

Browse files
committed
cleaning
1 parent 1ef390d commit 74fb871

File tree

2 files changed

+14
-42
lines changed

2 files changed

+14
-42
lines changed

src/prodigy_prot/modules/freesasa_tools.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,20 @@
33
"""
44

55
import os
6-
import sys
76

87
from Bio.PDB.Structure import Structure
98

109
from prodigy_prot import NACCESS_CONFIG
1110
from prodigy_prot.modules.aa_properties import rel_asa
1211

12+
from freesasa import Classifier, calc, structureFromBioPDB
13+
1314

1415
def execute_freesasa_api(structure: Structure) -> tuple[dict, dict]:
1516
"""
1617
Calls freesasa using its Python API and returns
1718
per-residue accessibilities.
1819
"""
19-
try:
20-
from freesasa import Classifier, calc, structureFromBioPDB
21-
except ImportError as err:
22-
print(
23-
(
24-
"[!] The binding affinity prediction tools require the "
25-
"'freesasa' Python API"
26-
),
27-
file=sys.stderr,
28-
)
29-
raise ImportError(err)
3020

3121
asa_data = {}
3222
rsa_data: dict[tuple[str, int, str], float] = {}

tests/test_prodigy.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
import tarfile
33
import tempfile
44
from io import BufferedReader, TextIOWrapper
5-
from os import devnull
65
from os.path import basename, dirname, join, splitext
76
from pathlib import Path
8-
from sys import stderr, version_info
7+
from sys import version_info
98

109
import pytest
1110
from Bio.PDB.PDBParser import PDBParser
1211
from Bio.PDB.Residue import Residue
1312
from Bio.PDB.Structure import Structure
1413

15-
from prodigy_prot.modules.freesasa_tools import stdchannel_redirected
1614
from prodigy_prot.modules.parsers import validate_structure
1715
from prodigy_prot.modules.prodigy import (
1816
Prodigy,
@@ -175,23 +173,6 @@ def test_print_pymol_script(input_pdb_structure, prodigy_class):
175173
Path(outfile.name).unlink()
176174

177175

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-
195176
@pytest.mark.integration
196177
def test_dataset_prediction(compressed_dataset_f, expected_dataset_json):
197178
"""
@@ -212,39 +193,40 @@ def test_dataset_prediction(compressed_dataset_f, expected_dataset_json):
212193
# run prodigy for each dataset in the PDB
213194
for entry in dataset:
214195
s_name, s_ext = splitext(basename(entry.name))
196+
215197
# skip system files in archive
216198
if not s_name.isalnum() or s_ext != ".pdb":
217199
continue
218-
# chains = expected_data[s_name]["Interacting_chains"]
200+
219201
handle = dataset.extractfile(entry)
202+
220203
# Wrap filehandle to ensure string file handle in Python 3
221204
if version_info[0] >= 3:
222205
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+
228212
# Test for structure object
229213
assert isinstance(s, Structure)
230-
# self.assertIsInstance(s, Structure.Structure)
231-
# instantiate Prdigy object,
214+
232215
# run prediction and retrieve result dict
233216
prod = Prodigy(s, selection=["A", "B"])
234217
prod.predict()
235218
results = prod.as_dict()
219+
236220
# check for equality of prdicted interface residues
237221
for k in keys_equal:
238222
observed_value = results[k]
239223
expected_value = expected_data[s_name][k]
240-
241224
assert observed_value == pytest.approx(expected_value)
242225

243226
# check that NIS and binding afinity values are within 2% of
244227
# expected values and add diffs for summary
245228
for k in diffs.keys():
246229
delta = abs(results[k] / expected_data[s_name][k] - 1)
247230
# assume a difference of less then 2%
248-
# self.assertAlmostEqual(delta, 0, delta=0.02)
249231
assert delta == pytest.approx(0, abs=0.02)
250232
diffs[k].append(delta)

0 commit comments

Comments
 (0)