Package Bio :: Package SCOP :: Module Residues
[hide private]
[frames] | no frames]

Source Code for Module Bio.SCOP.Residues

 1  # Copyright 2000 by Jeffrey Chang.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  # Gavin E. Crooks 2001-11-03 
 7  # Minor extensions, some bug fixes, and major changes to the interface 
 8   
 9  import re 
10   
11  """A collection of residues from a PDB structure.""" 
12   
13  _pdbid_re = re.compile(r"^(\w\w\w\w)(?:$|\s+|_)(.*)") 
14  _fragment_re = re.compile(r"\(?(\w:)?(-?\w*)-?(-?\w*)\)?(.*)") 
15   
16   
17 -class Residues(object):
18 """A collection of residues from a PDB structure. 19 20 This class provides code to work with SCOP domain definitions. These 21 are concisely expressed as one or more chain fragments. For example, 22 "(1bba A:10-20,B:)" indicates residue 10 through 20 (inclusive) of 23 chain A, and every residue of chain B in the pdb structure 1bba. The pdb 24 id and brackets are optional. In addition "-" indicates every residue of 25 a pbd structure with one unnamed chain. 26 27 Start and end residue ids consist of the residue sequence number and an 28 optional single letter insertion code. e.g. "12", "-1", "1a", "1000" 29 30 31 pdbid -- An optional PDB id, e.g. "1bba" 32 33 fragments -- A sequence of tuples (chainID, startResID, endResID) 34 35 """ 36
37 - def __init__(self, str=None):
38 self.pdbid = '' 39 self.fragments = () 40 if str is not None: 41 self._parse(str)
42
43 - def _parse(self, str):
44 str = str.strip() 45 46 # Is there a pdbid at the front? e.g. 1bba A:1-100 47 m = _pdbid_re.match(str) 48 if m is not None: 49 self.pdbid = m.group(1) 50 str = m.group(2) # Everything else 51 52 if str=='' or str == '-' or str=='(-)': # no fragments, whole sequence 53 return 54 55 fragments = [] 56 for l in str.split(","): 57 m = _fragment_re.match(l) 58 if m is None: 59 raise ValueError("I don't understand the format of %s" % l) 60 chain, start, end, postfix = m.groups() 61 62 if postfix != "": 63 raise ValueError("I don't understand the format of %s" % l) 64 65 if chain: 66 if chain[-1] != ':': 67 raise ValueError("I don't understand the chain in %s" % l) 68 chain = chain[:-1] # chop off the ':' 69 else: 70 chain = "" 71 72 fragments.append((chain, start, end)) 73 self.fragments = tuple(fragments)
74
75 - def __str__(self):
76 prefix = "" 77 if self.pdbid: 78 prefix = self.pdbid +' ' 79 80 if not self.fragments: 81 return prefix + '-' 82 strs = [] 83 for chain, start, end in self.fragments: 84 s = [] 85 if chain: 86 s.append("%s:" % chain) 87 if start: 88 s.append("%s-%s" % (start, end)) 89 strs.append("".join(s)) 90 return prefix + ",".join(strs)
91