Skip to content

Commit

Permalink
code health
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Apr 2, 2017
1 parent 8d9beed commit 0aecfbc
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 164 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ So, why don't we take pandas to the structural biology world? Working with molec
![3eiy](./docs/sources/img/index/3eiy.png)

```python
# Initialize a new PandasPDB object
# Initialize a new PandasPdb object
# and fetch the PDB file from rcsb.org
>>> from biopandas.pdb import PandasPDB
>>> ppdb = PandasPDB().fetch_pdb('3eiy')
>>> from biopandas.pdb import PandasPdb
>>> ppdb = PandasPdb().fetch_pdb('3eiy')
>>> ppdb.df['ATOM'].head()
```

Expand All @@ -53,10 +53,10 @@ So, why don't we take pandas to the structural biology world? Working with molec
```python
# Load structures from your drive and compute the
# Root Mean Square Deviation
>>> from biopandas.pdb import PandasPDB
>>> pl1 = PandasPDB().read_pdb('./docking_pose_1.pdb')
>>> pl2 = PandasPDB().read_pdb('./docking_pose_2.pdb')
>>> r = PandasPDB.rmsd(pl1.df['HETATM'], pl2.df['HETATM'],
>>> from biopandas.pdb import PandasPdb
>>> pl1 = PandasPdb().read_pdb('./docking_pose_1.pdb')
>>> pl2 = PandasPdb().read_pdb('./docking_pose_2.pdb')
>>> r = PandasPdb.rmsd(pl1.df['HETATM'], pl2.df['HETATM'],
s='hydrogen', invert=True)
>>> print('RMSD: %.4f Angstrom' % r)

Expand Down
4 changes: 2 additions & 2 deletions biopandas/mol2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
files in pandas DataFrames.
"""

from .pandas_mol2 import PandasMOL2
from .pandas_mol2 import PandasMol2
from .mol2_io import split_multimol2

__all__ = ["PandasMOL2", "split_multimol2"]
__all__ = ["PandasMol2", "split_multimol2"]
2 changes: 1 addition & 1 deletion biopandas/mol2/pandas_mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
COLUMN_TYPES = (int, str, float, float, float, str, int, str, float)


class PandasMOL2(object):
class PandasMol2(object):
""" Object for working with Tripos Mol2 structure files.
Attributes
Expand Down
12 changes: 6 additions & 6 deletions biopandas/mol2/tests/test_pandas_mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Code Repository: https://github.com/rasbt/biopandas

import os
from biopandas.mol2 import PandasMOL2
from biopandas.mol2 import PandasMol2
from biopandas.mol2.mol2_io import split_multimol2

this_dir = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -17,7 +17,7 @@ def test_read_mol2():
data_path_2 = os.path.join(this_dir, 'data', '40_mol2_files.mol2.gz')

for data_path in (data_path_1, data_path_2):
pdmol = PandasMOL2().read_mol2(data_path)
pdmol = PandasMol2().read_mol2(data_path)
assert pdmol.df.shape == (65, 9)
assert pdmol.code == 'ZINC38611810'

Expand All @@ -32,7 +32,7 @@ def test_read_mol2_from_list():
data_path = os.path.join(this_dir, 'data', '40_mol2_files.mol2')
mol2 = next(split_multimol2(data_path))

pdmol = PandasMOL2().read_mol2_from_list(mol2_lines=mol2[1],
pdmol = PandasMol2().read_mol2_from_list(mol2_lines=mol2[1],
mol2_code=mol2[0])
assert pdmol.df.shape == (65, 9)
assert pdmol.code == 'ZINC38611810'
Expand All @@ -42,8 +42,8 @@ def test_rmsd():
data_path_1 = os.path.join(this_dir, 'data', '1b5e_1.mol2')
data_path_2 = os.path.join(this_dir, 'data', '1b5e_2.mol2')

pdmol_1 = PandasMOL2().read_mol2(data_path_1)
pdmol_2 = PandasMOL2().read_mol2(data_path_2)
pdmol_1 = PandasMol2().read_mol2(data_path_1)
pdmol_2 = PandasMol2().read_mol2(data_path_2)

assert pdmol_1.rmsd(pdmol_1.df, pdmol_2.df, heavy_only=False) == 1.5523
assert pdmol_1.rmsd(pdmol_1.df, pdmol_2.df) == 1.1609
Expand All @@ -52,5 +52,5 @@ def test_rmsd():
def test_distance():
data_path = os.path.join(this_dir, 'data', '1b5e_1.mol2')

pdmol = PandasMOL2().read_mol2(data_path)
pdmol = PandasMol2().read_mol2(data_path)
assert round(pdmol.distance().values[0], 3) == 31.185
4 changes: 2 additions & 2 deletions biopandas/pdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
files in pandas DataFrames.
"""

from .pandas_pdb import PandasPDB
from .pandas_pdb import PandasPdb

__all__ = ["PandasPDB"]
__all__ = ["PandasPdb"]
18 changes: 9 additions & 9 deletions biopandas/pdb/pandas_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .engines import amino3to1dict


class PandasPDB(object):
class PandasPdb(object):
""" Object for working with Protein Databank structure files.
Attributes
Expand Down Expand Up @@ -117,12 +117,12 @@ def get(self, s, df=None, invert=False):
df = self._df['ATOM']
return self._get_dict[s](df, invert=invert)

def impute_element(self, sections=['ATOM', 'HETATM'], inplace=False):
def impute_element(self, sections=('ATOM', 'HETATM'), inplace=False):
"""Impute element_symbol from atom_name section.
Parameters
----------
sections : iterable (default: ['ATOM', 'HETATM'])
sections : iterable (default: ('ATOM', 'HETATM'))
Coordinate sections for which the element symbols should be
imputed.
Expand Down Expand Up @@ -181,7 +181,7 @@ def rmsd(df1, df2, s=None, invert=False):
"""
if df1.shape[0] != df2.shape[0]:
raise AttributeError('DataFrames have unequal lengths')
get_dict = PandasPDB._init_get_dict()
get_dict = PandasPdb._init_get_dict()
if s:
if s not in get_dict.keys():
raise AttributeError('s must be in '
Expand All @@ -198,11 +198,11 @@ def rmsd(df1, df2, s=None, invert=False):
@staticmethod
def _init_get_dict():
"""Initialize dictionary for filter operations."""
get_dict = {'main chain': PandasPDB._get_mainchain,
'hydrogen': PandasPDB._get_hydrogen,
'c-alpha': PandasPDB._get_calpha,
'carbon': PandasPDB._get_carbon,
'heavy': PandasPDB._get_heavy}
get_dict = {'main chain': PandasPdb._get_mainchain,
'hydrogen': PandasPdb._get_hydrogen,
'c-alpha': PandasPdb._get_calpha,
'carbon': PandasPdb._get_carbon,
'heavy': PandasPdb._get_heavy}
return get_dict

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions biopandas/pdb/tests/test_amino3to1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# Project Website: http://rasbt.github.io/biopandas/
# Code Repository: https://github.com/rasbt/biopandas

from biopandas.pdb import PandasPDB
from biopandas.pdb import PandasPdb
import os


def test_defaults():
TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), 'data',
'1t48_995.pdb')
p1t48 = PandasPDB()
p1t48 = PandasPdb()
p1t48.read_pdb(TESTDATA_1t48)
expect = ['M', 'E', 'M', 'E', 'K', 'E', 'F', 'E', 'Q',
'I', 'D', 'K', 'S', 'G', 'S', 'W', 'A', 'A',
Expand Down
4 changes: 2 additions & 2 deletions biopandas/pdb/tests/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Code Repository: https://github.com/rasbt/biopandas

import pandas as pd
from biopandas.pdb import PandasPDB
from biopandas.pdb import PandasPdb
import os
from nose.tools import raises

Expand All @@ -14,7 +14,7 @@ def test_equal():
TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), 'data',
'1t48_995.pdb')

p1t48 = PandasPDB()
p1t48 = PandasPdb()
p1t48.read_pdb(TESTDATA_1t48)
dist = p1t48.distance(xyz=(70.785, 15.477, 23.359), record='ATOM')

Expand Down
4 changes: 2 additions & 2 deletions biopandas/pdb/tests/test_impute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Code Repository: https://github.com/rasbt/biopandas


from biopandas.pdb import PandasPDB
from biopandas.pdb import PandasPdb
import os
import numpy as np
import pandas as pd
Expand All @@ -14,7 +14,7 @@
TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'data',
'3eiy_stripped_no_ele.pdb')

ppdb = PandasPDB()
ppdb = PandasPdb()
ppdb.read_pdb(TESTDATA_FILENAME)


Expand Down
20 changes: 10 additions & 10 deletions biopandas/pdb/tests/test_read_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Code Repository: https://github.com/rasbt/biopandas


from biopandas.pdb import PandasPDB
from biopandas.pdb import PandasPdb
import os
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -50,7 +50,7 @@

def test__read_pdb():
"""Test private _read_pdb"""
ppdb = PandasPDB()
ppdb = PandasPdb()
txt = ppdb._read_pdb(TESTDATA_FILENAME)
print(txt)
assert txt == three_eiy
Expand All @@ -60,7 +60,7 @@ def test_fetch_pdb():
"""Test fetch_pdb"""

try:
ppdb = PandasPDB()
ppdb = PandasPdb()
txt = ppdb._fetch_pdb('3eiy')
except HTTPError:
pass
Expand All @@ -73,14 +73,14 @@ def test_fetch_pdb():

def test__read_pdb_gz():
"""Test public _read_pdb with gzip files"""
ppdb = PandasPDB()
ppdb = PandasPdb()
txt = ppdb._read_pdb(TESTDATA_FILENAME_GZ)
assert txt == three_eiy


def test__construct_df():
"""Test pandas dataframe construction"""
ppdb = PandasPDB()
ppdb = PandasPdb()
dfs = ppdb._construct_df(three_eiy.splitlines())
assert set(dfs.keys()) == {'OTHERS', 'ATOM', 'ANISOU', 'HETATM'}
assert set(dfs['ATOM'].columns) == set(ATOM_DF_COLUMNS)
Expand All @@ -102,36 +102,36 @@ def test__construct_df():

def test_read_pdb():
"""Test public read_pdb"""
ppdb = PandasPDB()
ppdb = PandasPdb()
ppdb.read_pdb(TESTDATA_FILENAME)
assert ppdb.pdb_text == three_eiy
assert ppdb.code == '3eiy', ppdb.code


def test_anisou_input_handling():
"""Test public read_pdb"""
ppdb = PandasPDB()
ppdb = PandasPdb()
ppdb.read_pdb(TESTDATA_FILENAME2)
assert ppdb.pdb_text == four_eiy
assert ppdb.code == '4eiy', ppdb.code


@raises(AttributeError)
def test_get_exceptions():
ppdb = PandasPDB()
ppdb = PandasPdb()
ppdb.read_pdb(TESTDATA_FILENAME)
ppdb.get('main-chai')


def test_get_all():
ppdb = PandasPDB()
ppdb = PandasPdb()
ppdb.read_pdb(TESTDATA_FILENAME)
for i in ['c-alpha', 'hydrogen', 'main chain']:
ppdb.get(i)


def test_get_df():
ppdb = PandasPDB()
ppdb = PandasPdb()
ppdb.read_pdb(TESTDATA_FILENAME)

shape = ppdb.get('c-alpha').shape
Expand Down
24 changes: 12 additions & 12 deletions biopandas/pdb/tests/test_rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Project Website: http://rasbt.github.io/biopandas/
# Code Repository: https://github.com/rasbt/biopandas

from biopandas.pdb import PandasPDB
from biopandas.pdb import PandasPdb
import os
from nose.tools import raises

Expand All @@ -18,50 +18,50 @@
TESTDATA_lig2 = os.path.join(os.path.dirname(__file__), 'data',
'lig_conf_2.pdb')

p1t48 = PandasPDB()
p1t48 = PandasPdb()
p1t48.read_pdb(TESTDATA_1t48)
p1t49 = PandasPDB()
p1t49 = PandasPdb()
p1t49.read_pdb(TESTDATA_1t49)

pl1 = PandasPDB()
pl1 = PandasPdb()
pl1.read_pdb(TESTDATA_lig1)
pl2 = PandasPDB()
pl2 = PandasPdb()
pl2.read_pdb(TESTDATA_lig2)


def test_equal():
r = PandasPDB.rmsd(p1t48.df['ATOM'], p1t48.df['ATOM'], s=None)
r = PandasPdb.rmsd(p1t48.df['ATOM'], p1t48.df['ATOM'], s=None)
assert r == 0.000, r


@raises(AttributeError)
def test_wrong_arg():
PandasPDB.rmsd(p1t48.df['ATOM'].loc[1:, :], p1t48.df['ATOM'], s='bla')
PandasPdb.rmsd(p1t48.df['ATOM'].loc[1:, :], p1t48.df['ATOM'], s='bla')


@raises(AttributeError)
def test_incompatible():
PandasPDB.rmsd(p1t48.df['ATOM'].loc[1:, :], p1t48.df['ATOM'], s=None)
PandasPdb.rmsd(p1t48.df['ATOM'].loc[1:, :], p1t48.df['ATOM'], s=None)


@raises(AttributeError)
def test_invalid_query():
PandasPDB.rmsd(p1t48.df['ATOM'].loc[1:, :], p1t48.df['ATOM'], s='bla')
PandasPdb.rmsd(p1t48.df['ATOM'].loc[1:, :], p1t48.df['ATOM'], s='bla')


def test_protein():
r = PandasPDB.rmsd(p1t48.df['ATOM'], p1t49.df['ATOM'],
r = PandasPdb.rmsd(p1t48.df['ATOM'], p1t49.df['ATOM'],
s='c-alpha', invert=False)
assert r == 0.4785, r


def test_ligand():
r = PandasPDB.rmsd(pl1.df['HETATM'], pl2.df['HETATM'],
r = PandasPdb.rmsd(pl1.df['HETATM'], pl2.df['HETATM'],
s='hydrogen', invert=True)
assert r == 1.9959, r


def test_ligand_default():
r = PandasPDB.rmsd(pl1.df['HETATM'], pl2.df['HETATM'],
r = PandasPdb.rmsd(pl1.df['HETATM'], pl2.df['HETATM'],
s=None)
assert r == 2.6444, r

0 comments on commit 0aecfbc

Please sign in to comment.