Skip to content

Commit 9da22dc

Browse files
committed
updated tests for 1) windows-linux compatibility 2) af version difference, 3) restructured functions
1 parent 83312f5 commit 9da22dc

File tree

10 files changed

+31
-14516
lines changed

10 files changed

+31
-14516
lines changed

biopandas/pdb/pandas_pdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def _fetch_af2(uniprot_id: str, af2_version: int = 3):
459459
"""Load PDB file from https://alphafold.ebi.ac.uk/."""
460460
txt = None
461461
url = f"https://alphafold.ebi.ac.uk/files/AF-{uniprot_id.upper()}-F1-model_v{af2_version}.pdb"
462+
print(url)
462463
try:
463464
response = urlopen(url)
464465
txt = response.read()

biopandas/stack/stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def fetch_pdb(self, key: str=None, pdb_id: str=None, uniprot_id: str=None):
118118
if key is None:
119119
key = pdb_id
120120
elif uniprot_id:
121-
pdb.fetch_pdb(uniprot_id=uniprot_id, source="alphafold2-v4")
121+
pdb.fetch_pdb(uniprot_id=uniprot_id, source="alphafold2-v6")
122122
if key is None:
123123
key = uniprot_id
124124
else:

tests/pdb/test_read_pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.pdb"))
2828
TESTDATA_FILENAME2 = str(TEST_DATA.joinpath("4eiy_anisouchunk.pdb"))
2929
TESTDATA_FILENAME_GZ = str(TEST_DATA.joinpath("3eiy.pdb.gz"))
30-
TESTDATA_FILENAME_AF2_V4 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v4.pdb"))
30+
TESTDATA_FILENAME_AF2_V4 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v6.pdb"))
3131

3232
TESTDATA_FILENAME_AF2_V3 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v3.pdb"))
3333

tests/stack/data/3eiy.pdb

Lines changed: 2 additions & 819 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
HEADER MEMBRANE PROTEIN 06-APR-12 4EIY
2-
ATOM 101 CG1 VAL A 12 -5.222 2.059 3.696 1.00 17.98 C
3-
ANISOU 101 CG1 VAL A 12 2231 2335 2262 -42 326 285 C
4-
ATOM 102 CG2 VAL A 12 -5.748 3.603 1.839 1.00 16.30 C
5-
ANISOU 102 CG2 VAL A 12 2409 2061 1722 37 584 238 C
6-
ATOM 103 N GLU A 13 -8.338 2.518 5.470 1.00 16.24 N
7-
ANISOU 103 N GLU A 13 2362 2337 1469 -17 0 0 N
8-
ATOM 104 CA GLU A 13 -8.773 1.934 6.759 1.00 15.34 C
9-
ANISOU 104 CA GLU A 13 2354 2186 1285 -33 -18 -33 C
10-
ATOM 105 C GLU A 13 -9.966 1.026 6.560 1.00 16.90 C
1+
ATOM 101 CG1 VAL A 12 -5.222 2.059 3.696 1.00 17.98 C
2+
ATOM 102 CG2 VAL A 12 -5.748 3.603 1.839 1.00 16.30 C
3+
ATOM 103 N GLU A 13 -8.338 2.518 5.470 1.00 16.24 N
4+
ATOM 104 CA GLU A 13 -8.773 1.934 6.759 1.00 15.34 C
5+
ATOM 105 C GLU A 13 -9.966 1.026 6.560 1.00 16.90 C

tests/stack/data/AF-Q5VSL9-F1-model_v3.pdb

Lines changed: 0 additions & 6832 deletions
This file was deleted.

tests/stack/data/AF-Q5VSL9-F1-model_v4.pdb

Lines changed: 0 additions & 6832 deletions
This file was deleted.

tests/stack/test_read_stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_add_multiple_structures_mixed():
8888
# There are multiple 3eiy, they overwrite each other, hence the length of dict is not 9
8989
assert len(stack.pdbs.keys()) == 6
9090
assert '3eiy' in stack.pdbs
91-
assert 'AF-Q5VSL9-F1-model_v4' in stack.pdbs
91+
assert 'AF-Q5VSL9-F1-model_v6' in stack.pdbs
9292
assert 'Q5VSL9' in stack.pdbs
9393
assert 'P99999' in stack.pdbs
9494

tests/stack/test_stack.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Code Repository: https://github.com/rasbt/biopandas
66

77
from biopandas.stack.stack import PandasPdbStack
8+
from biopandas.align import TMAlign
89
import os
910
from nose.tools import assert_raises
1011

@@ -89,12 +90,6 @@ def test_update_entry_nonexistent():
8990
assert '1YCR' in stack.pdbs
9091
assert '1A2B' in stack.pdbs
9192

92-
def test_tmalign_inside_multiple_chains():
93-
ppdb_stack = PandasPdbStack()
94-
ppdb_stack.add_pdbs([TESTDATA_FILENAME, TESTDATA_FILENAME3, TESTDATA_FILENAME4])
95-
96-
assert_raises(ValueError, ppdb_stack.tmalign_inside)
97-
9893

9994
def filter_by_chains(key, pdb, chains):
10095
# Example function for applying filtering
@@ -111,10 +106,12 @@ def test_tmalign_inside_multiple_chains():
111106
filtered_stack = stack.apply_filter(filter_by_chains, keep_null=False, **args)
112107
chains_lens_filtered = filtered_stack.apply_calculation(calculate_chain_lengths)
113108
assert len(filtered_stack.pdbs) == 4
114-
transformed_structures, tm_scores = filtered_stack.tmalign_inside()
115109

116-
assert tm_scores['3eiy'] == 0.37341
117-
assert tm_scores['2d7t'] == 0.33733
110+
tmalign = TMAlign()
111+
_, transformed_structures, tm_scores = tmalign.tmalign_in_stack(filtered_stack, mobile_chains=args['chains'])
112+
113+
assert tm_scores['3eiy'] == 0.23483
114+
assert tm_scores['2d7t'] == 0.27812
118115
assert tm_scores['1ycr_copy'] == 1
119116

120117
def test_tmalign_inside_multiple_chains_specific_target():
@@ -126,8 +123,10 @@ def test_tmalign_inside_multiple_chains_specific_target():
126123
filtered_stack = stack.apply_filter(filter_by_chains, keep_null=False, **args)
127124
chains_lens_filtered = filtered_stack.apply_calculation(calculate_chain_lengths)
128125
assert len(filtered_stack.pdbs) == 4
129-
transformed_structures, tm_scores = filtered_stack.tmalign_inside('3eiy')
130126

131-
assert tm_scores['1ycr'] == 0.23483
132-
assert tm_scores['2d7t'] == 0.24401
127+
tmalign = TMAlign()
128+
_, transformed_structures, tm_scores = tmalign.tmalign_in_stack(filtered_stack, target='3eiy', mobile_chains=args['chains'])
129+
130+
assert tm_scores['1ycr'] == 0.37341
131+
assert tm_scores['2d7t'] == 0.32871
133132
assert tm_scores['3eiy_copy'] == 1

tests/stack/test_write_stack.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,34 @@
1515
)
1616

1717
TESTDATA_FILENAME_GZ = os.path.join(os.path.dirname(__file__), "data", "3eiy.pdb.gz")
18-
TESTDATA_FILENAME_AF2_V4 = os.path.join(
19-
os.path.dirname(__file__), "data", "AF-Q5VSL9-F1-model_v4.pdb"
18+
TESTDATA_FILENAME_AF2_V6 = os.path.join(
19+
os.path.dirname(__file__), "data", "AF-Q5VSL9-F1-model_v6.pdb"
2020
)
2121

2222
def test_write_pdb():
2323
stack = PandasPdbStack()
2424
stack.add_pdbs([TESTDATA_FILENAME, TESTDATA_FILENAME2,
25-
TESTDATA_FILENAME_AF2_V4])
25+
TESTDATA_FILENAME_AF2_V6])
2626
base_dir = os.path.dirname(__file__)
2727
stack.write_entries(base_dir)
2828

2929
for key, pdb in stack.pdbs.items():
3030
outfile = os.path.join(base_dir, f'{key}.pdb')
3131
infile = os.path.join(base_dir, 'data', f'{key}.pdb')
3232
assert os.path.exists(outfile)
33+
3334
with open(infile, "r") as f:
34-
f1 = f.read().replace('\r\n', '\n').rstrip('\n')
35+
f1 = [line.rstrip() for line in f.read().replace('\r', '\n').split('\n')]
3536
with open(outfile, "r") as f:
36-
f2 = f.read().replace('\r\n', '\n').rstrip('\n')
37+
f2 = [line.rstrip() for line in f.read().replace('\r', '\n').split('\n')]
3738
assert f1 == f2
3839

3940
os.remove(outfile)
4041

4142
def test_write_pdb_no_dir_exists():
4243
stack = PandasPdbStack()
4344
stack.add_pdbs([TESTDATA_FILENAME, TESTDATA_FILENAME2,
44-
TESTDATA_FILENAME_AF2_V4])
45+
TESTDATA_FILENAME_AF2_V6])
4546
base_dir = os.path.dirname(__file__)
4647
test_dir = os.path.join(base_dir, "test_dir")
4748
stack.write_entries(test_dir)
@@ -52,9 +53,9 @@ def test_write_pdb_no_dir_exists():
5253
assert os.path.exists(outfile)
5354

5455
with open(infile, "r") as f:
55-
f1 = f.read().replace('\r\n', '\n').rstrip('\n')
56+
f1 = [line.rstrip() for line in f.read().replace('\r', '\n').split('\n')]
5657
with open(outfile, "r") as f:
57-
f2 = f.read().replace('\r\n', '\n').rstrip('\n')
58+
f2 = [line.rstrip() for line in f.read().replace('\r', '\n').split('\n')]
5859
assert f1 == f2
5960

6061
os.remove(outfile)

0 commit comments

Comments
 (0)