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

Source Code for Module Bio.SCOP.Des

  1  # Copyright 2001 by Gavin E. Crooks.  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   
  7  """ Handle the SCOP DEScription file. 
  8   
  9  The file format is described in the scop 
 10  "release notes.":http://scop.berkeley.edu/release-notes-1.55.html  
 11  The latest DES file can be found 
 12  "elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/ 
 13     
 14  "Release 1.55":http://scop.berkeley.edu/parse/des.cla.scop.txt_1.55 (July 2001) 
 15  """ 
 16   
 17  from types import * 
 18   
19 -class Record:
20 """Holds information for one node in the SCOP hierarchy. 21 22 sunid -- SCOP unique identifiers 23 24 nodetype -- One of 'cl' (class), 'cf' (fold), 'sf' (superfamily), 25 'fa' (family), 'dm' (protein), 'sp' (species), 26 'px' (domain). Additional node types may be added. 27 28 sccs -- SCOP concise classification strings. e.g. b.1.2.1 29 30 name -- The SCOP ID (sid) for domains (e.g. d1anu1), 31 currently empty for other node types 32 33 description -- e.g. "All beta proteins","Fibronectin type III", 34 35 """
36 - def __init__(self):
37 self.sunid = '' 38 self.nodetype = '' 39 self.sccs = '' 40 self.name = '' 41 self.description =''
42
43 - def __str__(self):
44 s = [] 45 s.append(self.sunid) 46 s.append(self.nodetype) 47 s.append(self.sccs) 48 if self.name : 49 s.append(self.name) 50 else : 51 s.append("-") 52 s.append(self.description) 53 return "\t".join(map(str,s)) + "\n"
54
55 -class Iterator:
56 """Iterates over a DES file. 57 """
58 - def __init__(self, handle, parser=None):
59 """Create an object that iterates over a DES file. 60 61 handle -- file-like object. 62 63 parser -- an optional Parser object to chang the results into 64 another form. If set to None, then the raw contents 65 of the file will be returned. 66 67 """ 68 if type(handle) is not FileType and type(handle) is not InstanceType: 69 raise TypeError, "I expected a file handle or file-like object" 70 self._handle = handle 71 self._parser = parser
72
73 - def next(self):
74 """Retrieve the next DES record.""" 75 while 1: 76 line = self._handle.readline() 77 if not line: return None 78 if line[0] !='#': break # Not a comment line 79 if self._parser is not None : 80 return self._parser.parse(line) 81 return line
82
83 - def __iter__(self):
84 return iter(self.next, None)
85 86
87 -class Parser:
88 """Parses DES records. 89 90 Records consist of 5 tab deliminated fields, 91 sunid, node type, sccs, node name, node description. 92 """ 93 #For example :: 94 # 95 #21953 px b.1.2.1 d1dan.1 1dan T:,U:91-106 96 #48724 cl b - All beta proteins 97 #48725 cf b.1 - Immunoglobulin-like beta-sandwich 98 #49265 sf b.1.2 - Fibronectin type III 99 #49266 fa b.1.2.1 - Fibronectin type III 100
101 - def parse(self, entry):
102 """Returns a Des Record """ 103 entry = entry.rstrip() # no trailing whitespace 104 columns = entry.split("\t") # separate the tab-delineated cols 105 if len(columns) != 5: 106 raise SyntaxError, "I don't understand the format of %s" % entry 107 108 rec = Record() 109 rec.sunid, rec.nodetype, rec.sccs, rec.name, rec.description = columns 110 if rec.name == '-' : rec.name ='' 111 rec.sunid = int(rec.sunid) 112 return rec
113