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   
 19  from Residues import Residues 
 20   
21 -class Record:
22 """Holds information for one SCOP domain. 23 24 sid -- The SCOP ID of the entry, e.g. d1anu1 25 26 residues -- The domain definition as a Residues object 27 28 hierarchy -- A string specifying where this domain is in the hierarchy. 29 """
30 - def __init__(self, line=None):
31 self.sid = '' 32 self.residues = [] 33 self.hierarchy = '' 34 if line: 35 self._process(line)
36
37 - def _process(self, line):
38 """Parses DOM records. 39 40 Records consist of 4 tab deliminated fields; 41 sid, pdbid, residues, hierarchy 42 """ 43 #For example :: 44 # 45 #d1sctg_ 1sct g: 1.001.001.001.001.001 46 #d1scth_ 1sct h: 1.001.001.001.001.001 47 #d1flp__ 1flp - 1.001.001.001.001.002 48 #d1moh__ 1moh - 1.001.001.001.001.002 49 50 line = line.rstrip() # no trailing whitespace 51 columns = line.split("\t") # separate the tab-delineated cols 52 if len(columns) != 4: 53 raise ValueError("I don't understand the format of %s" % line) 54 self.sid, pdbid, res, self.hierarchy = columns 55 self.residues = Residues(res) 56 self.residues.pdbid =pdbid
57 58
59 - def __str__(self):
60 s = [] 61 s.append(self.sid) 62 s.append(str(self.residues).replace(" ","\t") ) 63 s.append(self.hierarchy) 64 return "\t".join(s) + "\n"
65 66
67 -def parse(handle):
68 """Iterates over a DOM file, returning a Dom record for each line 69 in the file. 70 71 Arguments: 72 73 handle -- file-like object. 74 """ 75 for line in handle: 76 if line.startswith('#'): 77 continue 78 yield Record(line)
79 80
81 -class Iterator:
82 """Iterates over a DOM file. 83 """
84 - def __init__(self, handle, parser=None):
85 """Create an object that iterates over a DES file. 86 87 handle -- file-like object. 88 89 parser -- an optional Parser object to change the results into 90 another form. If set to None, then the raw contents 91 of the file will be returned. 92 93 """ 94 import warnings 95 warnings.warn("Bio.SCOP.Dom.Iterator is deprecated. Please use Bio.SCOP.Dom.parse() instead.", DeprecationWarning) 96 from types import FileType, InstanceType 97 if type(handle) is not FileType and type(handle) is not InstanceType: 98 raise ValueError("I expected a file handle or file-like object") 99 self._handle = handle 100 self._parser = parser
101
102 - def next(self):
103 line = self._handle.readline() 104 if not line: 105 return None 106 if line.startswith('#'): 107 return self.next() 108 if self._parser is not None: 109 return self._parser.parse(line) 110 return line
111
112 -class Parser:
113 - def parse(self, entry):
114 """Returns a Dom.Record """ 115 import warnings 116 warnings.warn("""Bio.SCOP.Dom.Parser is deprecated. 117 Instead of 118 119 parser = Dom.Parser() 120 record = parser.parse(entry) 121 122 please use 123 124 record = Dom.Record(entry) 125 """, DeprecationWarning) 126 return Record(entry)
127