Skip to content

Commit 2bc018a

Browse files
authored
amino3to1 index improvement (#25)
1 parent fb1296f commit 2bc018a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

biopandas/pdb/pandas_pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def amino3to1(self, record='ATOM',
373373
cmp = 'placeholder'
374374
indices = []
375375

376-
for num, ind in zip(tmp['residue_number'], tmp.index):
376+
for num, ind in zip(tmp['residue_number'], np.arange(tmp.shape[0])):
377377
if num != cmp:
378378
indices.append(ind)
379379
cmp = num

biopandas/pdb/tests/test_amino3to1.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Project Website: http://rasbt.github.io/biopandas/
55
# Code Repository: https://github.com/rasbt/biopandas
66

7+
import numpy as np
78
from biopandas.pdb import PandasPdb
89
import os
910

@@ -37,6 +38,38 @@ def test_defaults():
3738
assert expect_res == got_res
3839

3940

41+
def test_sameindex():
42+
TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), 'data',
43+
'1t48_995.pdb')
44+
p1t48 = PandasPdb()
45+
p1t48.read_pdb(TESTDATA_1t48)
46+
print(p1t48)
47+
p1t48.df['ATOM'].index = np.zeros(p1t48.df['ATOM'].shape[0], dtype=int)
48+
49+
expect_res = ['M', 'E', 'M', 'E', 'K', 'E', 'F', 'E', 'Q',
50+
'I', 'D', 'K', 'S', 'G', 'S', 'W', 'A', 'A',
51+
'I', 'Y', 'Q', 'D', 'I', 'R', 'H', 'E', 'A',
52+
'S', 'D', 'F', 'P', 'C', 'R', 'V', 'A', 'K',
53+
'L', 'P', 'K', 'N', 'K', 'N', 'R', 'N', 'R',
54+
'Y', 'R', 'D', 'V', 'S', 'P', 'F', 'D', 'H',
55+
'S', 'R', 'I', 'K', 'L', 'H', 'Q', 'E', 'D',
56+
'N', 'D', 'Y', 'I', 'N', 'A', 'S', 'L', 'I',
57+
'K', 'M', 'E', 'E', 'A', 'Q', 'R', 'S', 'Y',
58+
'I', 'L', 'T', 'Q', 'G', 'P', 'L', 'P', 'N',
59+
'T', 'C', 'G', 'H', 'F', 'W', 'E', 'M', 'V',
60+
'W', 'E', 'Q', 'K', 'S', 'R', 'G', 'V', 'V',
61+
'M', 'L', 'N', 'R', 'V', 'M', 'E', 'K', 'G',
62+
'S', 'L', 'K']
63+
64+
transl = p1t48.amino3to1()
65+
expect_chain = ['A' for _ in range(transl.shape[0])]
66+
got_chain = list(transl['chain_id'].values)
67+
got_res = list(transl['residue_name'].values)
68+
69+
assert expect_chain == got_chain
70+
assert expect_res == got_res
71+
72+
4073
def test_multichain():
4174
TESTDATA_5mtn = os.path.join(os.path.dirname(__file__),
4275
'data', '5mtn_multichain.pdb')

docs/sources/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ The CHANGELOG for the current development version is available at
1717
##### Changes
1818

1919
- The `amino3to1` method of `biopandas.pdb.PandasPDB` objects now returns a pandas `DataFrame` instead of a pandas `Series` object. The returned data frame has two columns, `'chain_id'` and `'residue_name'`, where the former contains the chain ID of the amino acid and the latter contains the 1-letter amino acid code, respectively.
20-
- Significant speed improvements of the `distance` method of both `PandasPdb` and `PandasMol2` (now about 300 percent faster than previously)
20+
- Significant speed improvements of the `distance` method of both `PandasPdb` and `PandasMol2` (now about 300 percent faster than previously).
2121

2222
##### Bug Fixes
2323

2424
- The `amino3to1` method of `biopandas.pdb.PandasPDB` objects now handles multi-chain proteins correctly.
25+
- The `amino3to1` method of `biopandas.pdb.PandasPDB` objects now also works as expected if the `'ATOM'` entry DataFrame contains disordered DataFrame indices or duplicate DataFrame index values.
2526

2627

2728

0 commit comments

Comments
 (0)