Skip to content

Commit

Permalink
optimise add_mmcif_atom_altloc by replacing DataFrame.apply with …
Browse files Browse the repository at this point in the history
…direct column manipulation.
  • Loading branch information
stuartmac committed Sep 27, 2017
1 parent 788f5df commit 4ca33ff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions prointvar/pdbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,16 +675,16 @@ def add_mmcif_atom_altloc(data):
def join_atom_altloc(data, category='label'):
atom = data['{}_atom_id'.format(category)]
altloc = data['label_alt_id']
if altloc == "." or altloc == '' or altloc == ' ':
return atom
else:
return atom + '.' + altloc

data.is_copy = False
data['label_atom_altloc_id'] = data.apply(join_atom_altloc,
axis=1, args=('label',))
data['auth_atom_altloc_id'] = data.apply(join_atom_altloc,
axis=1, args=('auth',))
new_column = (atom + '.' + altloc)
has_no_alt = altloc.isin(['.', '', ' '])
new_column[has_no_alt] = atom.loc[has_no_alt]

return new_column

# NB. Use of assign prevents inplace modification
data = data.assign(label_atom_altloc_id=join_atom_altloc(data, 'label'))
data = data.assign(auth_atom_altloc_id=join_atom_altloc(data, 'auth'))
return data


Expand Down

0 comments on commit 4ca33ff

Please sign in to comment.