diff --git a/prody/atomic/atomic.py b/prody/atomic/atomic.py index b4a6700f4..fcebf30a7 100644 --- a/prody/atomic/atomic.py +++ b/prody/atomic/atomic.py @@ -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 diff --git a/prody/atomic/chain.py b/prody/atomic/chain.py index d5534f783..ea5f73518 100644 --- a/prody/atomic/chain.py +++ b/prody/atomic/chain.py @@ -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]) @@ -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 diff --git a/prody/proteins/header.py b/prody/proteins/header.py index 1a64132c6..b22e6483b 100644 --- a/prody/proteins/header.py +++ b/prody/proteins/header.py @@ -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. @@ -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.""" @@ -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' @@ -555,7 +558,7 @@ def _getReference(lines): return ref -def _getPolymers(lines): +def _getPolymers(lines, **kwargs): """Returns list of polymers (macromolecules).""" pdbid = lines['pdbid'] @@ -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