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 -class Residues :
17 """A collection of residues from a PDB structure. 18 19 This class provides code to work with SCOP domain definitions. These 20 are concisely expressed as a one or more chain fragments. For example, 21 "(1bba A:10-20,B:)" indicates residue 10 through 20 (inclusive) of 22 chain A, and every residue of chain B in the pdb structure 1bba. The pdb 23 id and brackets are optional. In addition "-" indicates every residue of 24 a pbd structure with one unnamed chain. 25 26 Start and end residue ids consist of the residue sequence number and an 27 optional single letter insertion code. e.g. "12", "-1", "1a", "1000" 28 29 30 pdbid -- An optional PDB id, e.g. "1bba" 31 32 fragments -- A sequence of tuples (chainID, startResID, endResID) 33 34 """ 35 36
37 - def __init__(self, str=None) :
38 self.pdbid = '' 39 self.fragments = () 40 if str is not None : self._parse(str)
41 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 SyntaxError, "I don't understand the format of %s" % l 60 chain, start, end, postfix = m.groups() 61 62 if postfix != "" : 63 raise SyntaxError, "I don't understand the format of %s" % l 64 65 if chain: 66 if chain[-1] != ':': 67 raise SyntaxError, "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: return prefix+'-' 81 strs = [] 82 for chain, start, end in self.fragments: 83 s = [] 84 if chain: s.append("%s:" % chain) 85 if start: s.append("%s-%s" % (start, end)) 86 strs.append("".join(s)) 87 return prefix+ ",".join(strs)
88