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

Source Code for Module Bio.SCOP.Dom

 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-07 : 
 7  #     Interface and comments modified to reflect changes to the SCOP 
 8  #     module, and to SCOP itself. 
 9   
10  """ Handle the SCOP DOMain file. 
11   
12  The DOM file has been officially deprecated. For more information see 
13  the SCOP"release notes.":http://scop.berkeley.edu/release-notes-1.55.html  
14  The DOM files for older releases can be found  
15  "elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/ 
16  """ 
17   
18  from types import * 
19   
20  from Residues import Residues 
21   
22 -class Record:
23 """Holds information for one SCOP domain. 24 25 sid -- The SCOP ID of the entry, e.g. d1anu1 26 27 residues -- The domain definition as a Residues object 28 29 hierarchy -- A string specifying where this domain is in the hierarchy. 30 """
31 - def __init__(self):
32 self.sid = '' 33 self.residues = [] 34 self.hierarchy = ''
35
36 - def __str__(self):
37 s = [] 38 s.append(self.sid) 39 s.append(str(self.residues).replace(" ","\t") ) 40 s.append(self.hierarchy) 41 return "\t".join(s) + "\n"
42
43 -class Iterator:
44 """Iterates over a DOM file. 45 """
46 - def __init__(self, handle, parser=None):
47 """Create an object that iterates over a DES file. 48 49 handle -- file-like object. 50 51 parser -- an optional Parser object to change the results into 52 another form. If set to None, then the raw contents 53 of the file will be returned. 54 55 """ 56 if type(handle) is not FileType and type(handle) is not InstanceType: 57 raise ValueError, "I expected a file handle or file-like object" 58 self._handle = handle 59 self._parser = parser
60
61 - def next(self):
62 line = self._handle.readline() 63 if not line: 64 return None 65 if self._parser is not None: 66 return self._parser.parse(line) 67 return line
68
69 -class Parser:
70 """Parses DOM records. 71 72 Records consist of 4 tab deliminated fields; 73 sid, pdbid, residues, hierarchy 74 """ 75 #For example :: 76 # 77 #d1sctg_ 1sct g: 1.001.001.001.001.001 78 #d1scth_ 1sct h: 1.001.001.001.001.001 79 #d1flp__ 1flp - 1.001.001.001.001.002 80 #d1moh__ 1moh - 1.001.001.001.001.002 81
82 - def parse(self, entry):
83 """Returns a Dom.Record """ 84 entry = entry.rstrip() # no trailing whitespace 85 columns = entry.split("\t") # separate the tab-delineated cols 86 if len(columns) != 4: 87 raise SyntaxError, "I don't understand the format of %s" % entry 88 dom = Record() 89 dom.sid, pdbid, res, dom.hierarchy = columns 90 dom.residues = Residues(res) 91 dom.residues.pdbid =pdbid 92 return dom
93