Skip to content

Commit e03a47f

Browse files
authored
Merge pull request #12 from rasbt/0.1.5
0.1.5
2 parents 42e0e33 + bd1ed4d commit e03a47f

File tree

16 files changed

+2498
-84
lines changed

16 files changed

+2498
-84
lines changed

.appveyor.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
build: false
2+
3+
environment:
4+
matrix:
5+
- PYTHON_VERSION: 2.7
6+
MINICONDA: C:\Miniconda
7+
- PYTHON_VERSION: 3.5
8+
MINICONDA: C:\Miniconda3
9+
10+
init:
11+
- ECHO %PYTHON_VERSION% %MINICONDA%
12+
- ECHO conda --version
13+
14+
install:
15+
- set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%
16+
- conda config --set always_yes yes --set changeps1 no
17+
- conda update -q conda
18+
- conda info -a
19+
- conda create -q -n test-environment python=%PYTHON_VERSION% numpy scipy pandas nose
20+
- activate test-environment
21+
22+
test_script:
23+
- nosetests -s -v

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!-- Please read the following guidelines for new Pull Requests -- thank you! -->
2+
3+
<!--
4+
Make sure that you submit this pull request as a separate topic branch (and not to "master")
5+
-->
6+
7+
<!-- Provide a small summary describing the Pull Request below -->
8+
9+
### Description
10+
11+
Insert Description Here
12+
13+
### Related issues or pull requests
14+
15+
<!-- Please provide a link to the respective issue on the [Issue Tracker](https://github.com/rasbt/mlxtend/issues) if one exists. E.g.,
16+
17+
Fixes #<ISSUE_NUMBER> -->
18+
19+
Link related issues/pull requests here
20+
21+
<!-- Below is a general todo list for typical pull request -->
22+
23+
### Pull Request requirements
24+
25+
- [ ] Added appropriate unit test functions in the `./mlxtend/*/tests` directories
26+
- [ ] Ran `nosetests ./mlxtend -sv` and make sure that all unit tests pass
27+
- [ ] Checked the test coverage by running `nosetests ./mlxtend --with-coverage`
28+
- [ ] Checked for style issues by running `flake8 ./mlxtend`
29+
- [ ] Added a note about the modification or contribution to the `./docs/sources/`CHANGELOG.md` file
30+
- [ ] Modify documentation in the appropriate location under `mlxtend/docs/sources/` (optional)
31+
- [ ] Checked that the Travis-CI build passed at https://travis-ci.org/rasbt/mlxtend
32+
33+
34+
35+
36+
<!--
37+
NOTE
38+
39+
Due to the improved GitHub UI, the squashing of commits is no longer necessary.
40+
Please DO NOT SQUASH commits since they help with keeping track of the changes during the discussion).
41+
42+
For more information and instructions, please see http://rasbt.github.io/mlxtend/contributing/
43+
-->

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
[![Continuous Integration](https://travis-ci.org/rasbt/biopandas.svg?branch=master)](https://travis-ci.org/rasbt/biopandas)
7+
[![Build status](https://ci.appveyor.com/api/projects/status/jcp91fvbgmqws30p/branch/master?svg=true)](https://ci.appveyor.com/project/rasbt/biopandas/branch/master)
78
[![Code Coverage](https://coveralls.io/repos/rasbt/biopandas/badge.svg?branch=master&service=github)](https://coveralls.io/github/rasbt/biopandas?branch=master)
89
[![Code Health](https://landscape.io/github/rasbt/biopandas/master/landscape.svg?style=flat)](https://landscape.io/github/rasbt/biopandas/master)
910
[![PyPI Version](https://img.shields.io/pypi/v/biopandas.svg)](https://pypi.python.org/pypi/biopandas/)

biopandas/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# Project Website: http://rasbt.github.io/biopandas/
55
# Code Repository: https://github.com/rasbt/biopandas
66

7-
__version__ = '0.1.5.dev0'
7+
__version__ = '0.1.5'
88
__author__ = "Sebastian Raschka <[email protected]>"

biopandas/pdb/pandas_pdb.py

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get(self, s, df=None, invert=False):
9090
9191
Parameters
9292
----------
93-
s : str in {'main chain', 'hydrogen', 'c-alpha'}
93+
s : str in {'main chain', 'hydrogen', 'c-alpha', 'heavy'}
9494
String to specify which entries to return
9595
9696
df : pandas.DataFrame, default: None
@@ -115,8 +115,41 @@ def get(self, s, df=None, invert=False):
115115
df = self._df['ATOM']
116116
return self._get_dict[s](df, invert=invert)
117117

118+
def impute_element(self, sections=['ATOM', 'HETATM'], inplace=False):
119+
"""Impute element_symbol from atom_name section.
120+
121+
Parameters
122+
----------
123+
sections : iterable (default: ['ATOM', 'HETATM'])
124+
Coordinate sections for which the element symbols should be
125+
imputed.
126+
127+
inplace : bool (default: False)
128+
Performs the operation in-place if True and returns a copy of the
129+
PDB DataFrame otherwise.
130+
131+
Returns
132+
---------
133+
DataFrame
134+
135+
"""
136+
if inplace:
137+
t = self.df
138+
else:
139+
t = self.df.copy()
140+
for d in self.df:
141+
t[d] = self.df[d].copy()
142+
143+
for sec in sections:
144+
t[sec]['element_symbol'] = \
145+
t[sec][['atom_name', 'element_symbol']].\
146+
apply(lambda x: x[0][1]
147+
if len(x[1]) == 3
148+
else x[0][0], axis=1)
149+
return t
150+
118151
@staticmethod
119-
def rmsd(df1, df2, s='main chain', invert=False):
152+
def rmsd(df1, df2, s=None, invert=False):
120153
"""Compute the Root Mean Square Deviation between molecules.
121154
122155
Parameters
@@ -128,8 +161,10 @@ def rmsd(df1, df2, s='main chain', invert=False):
128161
Second DataFrame for RMSD computation against df1. Must have the
129162
same number of entries as df1
130163
131-
s : str in {'main chain', 'hydrogen', 'c-alpha'}, default: 'main chain'
132-
String to specify which entries to consider.
164+
s : {'main chain', 'hydrogen', 'c-alpha', 'heavy', 'carbon'} or None,
165+
default: None
166+
String to specify which entries to consider. If None, considers
167+
all atoms for comparison.
133168
134169
invert : bool, default: False
135170
Inverts the string query if true. For example, the setting
@@ -163,7 +198,9 @@ def _init_get_dict():
163198
"""Initialize dictionary for filter operations."""
164199
get_dict = {'main chain': PandasPDB._get_mainchain,
165200
'hydrogen': PandasPDB._get_hydrogen,
166-
'c-alpha': PandasPDB._get_calpha}
201+
'c-alpha': PandasPDB._get_calpha,
202+
'carbon': PandasPDB._get_carbon,
203+
'heavy': PandasPDB._get_heavy}
167204
return get_dict
168205

169206
@staticmethod
@@ -234,9 +271,17 @@ def _get_mainchain(df, invert):
234271
def _get_hydrogen(df, invert):
235272
"""Return only hydrogen atom entries from a DataFrame"""
236273
if invert:
237-
return df[(df['atom_name'] != 'H')]
274+
return df[(df['element_symbol'] != 'H')]
275+
else:
276+
return df[(df['element_symbol'] == 'H')]
277+
278+
@staticmethod
279+
def _get_heavy(df, invert):
280+
"""Return only heavy atom entries from a DataFrame"""
281+
if invert:
282+
return df[df['element_symbol'] == 'H']
238283
else:
239-
return df[(df['atom_name'] == 'H')]
284+
return df[df['element_symbol'] != 'H']
240285

241286
@staticmethod
242287
def _get_calpha(df, invert):
@@ -246,6 +291,14 @@ def _get_calpha(df, invert):
246291
else:
247292
return df[df['atom_name'] == 'CA']
248293

294+
@staticmethod
295+
def _get_carbon(df, invert):
296+
"""Return c-alpha atom entries from a DataFrame"""
297+
if invert:
298+
return df[df['element_symbol'] == 'C']
299+
else:
300+
return df[df['element_symbol'] != 'C']
301+
249302
@staticmethod
250303
def _construct_df(pdb_lines):
251304
"""Construct DataFrames from list of PDB lines."""
@@ -256,7 +309,8 @@ def _construct_df(pdb_lines):
256309
if line.strip():
257310
if line.startswith(valids):
258311
record = line[:6].rstrip()
259-
line_ele = ['' for _ in range(len(pdb_records[record])+1)]
312+
line_ele = ['' for _ in range(len(
313+
pdb_records[record]) + 1)]
260314
for idx, ele in enumerate(pdb_records[record]):
261315
line_ele[idx] = (line[ele['line'][0]:ele['line'][1]]
262316
.strip())
@@ -269,7 +323,7 @@ def _construct_df(pdb_lines):
269323
dfs = {}
270324
for r in line_lists.items():
271325
df = pd.DataFrame(r[1], columns=[c['id'] for c in
272-
pdb_records[r[0]]]+['line_idx'])
326+
pdb_records[r[0]]] + ['line_idx'])
273327
for c in pdb_records[r[0]]:
274328
try:
275329
df[c['id']] = df[c['id']].astype(c['type'])

0 commit comments

Comments
 (0)