Skip to content

Commit

Permalink
add threeLetter to pdb header and atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Sep 10, 2024
1 parent 2a11d0a commit 48ee58f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
12 changes: 10 additions & 2 deletions prody/atomic/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,20 @@ def getSequence(self, **kwargs):
residues (e.g. water molecules) in the chain and **X** will be used for
non-standard residue names."""

threeLetter = kwargs.get('threeLetter', False)

get = AAMAP.get
if hasattr(self, 'getResnames'):
seq = ''.join([get(res, 'X') for res in self.getResnames()])
if threeLetter:
seq = ' '.join(self.getResnames())
else:
seq = ''.join([get(res, 'X') for res in self.getResnames()])
else:
res = self.getResname()
seq = get(res, 'X')
if threeLetter:
seq = res
else:
seq = get(res, 'X')

return seq

Expand Down
8 changes: 6 additions & 2 deletions prody/atomic/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

__all__ = ['Chain']

def getSequence(resnames):
def getSequence(resnames, **kwargs):
"""Returns polypeptide sequence as from list of *resnames* (residue
name abbreviations)."""

threeLetter = kwargs.get('threeLetter', False)
if threeLetter:
return ' '.join(resnames)

get = AAMAP.get
return ''.join([get(rn, 'X') for rn in resnames])

Expand Down Expand Up @@ -140,7 +144,7 @@ def getSequence(self, **kwargs):
else:
calpha = self.calpha
if calpha:
seq = getSequence(calpha.getResnames())
seq = getSequence(calpha.getResnames(), **kwargs)
else:
seq = ''
self._seq = seq
Expand Down
22 changes: 16 additions & 6 deletions prody/proteins/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def cleanString(string, nows=False):
return ' '.join(string.strip().split())


def parsePDBHeader(pdb, *keys):
def parsePDBHeader(pdb, *keys, **kwargs):
"""Returns header data dictionary for *pdb*. This function is equivalent to
``parsePDB(pdb, header=True, model=0, meta=False)``, likewise *pdb* may be
an identifier or a filename.
Expand Down Expand Up @@ -297,12 +297,12 @@ def parsePDBHeader(pdb, *keys):
raise IOError('{0} is not a valid filename or a valid PDB '
'identifier.'.format(pdb))
pdb = openFile(pdb, 'rt')
header, _ = getHeaderDict(pdb, *keys)
header, _ = getHeaderDict(pdb, *keys, **kwargs)
pdb.close()
return header


def getHeaderDict(stream, *keys):
def getHeaderDict(stream, *keys, **kwargs):
"""Returns header data in a dictionary. *stream* may be a list of PDB lines
or a stream."""

Expand All @@ -325,7 +325,10 @@ def getHeaderDict(stream, *keys):
keys = list(keys)
for k, key in enumerate(keys):
if key in _PDB_HEADER_MAP:
value = _PDB_HEADER_MAP[key](lines)
if key == 'polymers':
value = _PDB_HEADER_MAP[key](lines, **kwargs)
else:
value = _PDB_HEADER_MAP[key](lines)
keys[k] = value
else:
raise KeyError('{0} is not a valid header data identifier'
Expand Down Expand Up @@ -555,7 +558,7 @@ def _getReference(lines):
return ref


def _getPolymers(lines):
def _getPolymers(lines, **kwargs):
"""Returns list of polymers (macromolecules)."""

pdbid = lines['pdbid']
Expand All @@ -564,7 +567,14 @@ def _getPolymers(lines):
ch = line[11]
poly = polymers.get(ch, Polymer(ch))
polymers[ch] = poly
poly.sequence += ''.join(getSequence(line[19:].split()))

threeLetter = kwargs.get('threeLetter', False)
if threeLetter:
if poly.sequence != '':
poly.sequence += ' '
poly.sequence += getSequence(line[19:].split(), **kwargs)
else:
poly.sequence += ''.join(getSequence(line[19:].split(), **kwargs))

for i, line in lines['DBREF ']:
i += 1
Expand Down

0 comments on commit 48ee58f

Please sign in to comment.