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   
18 -class Record:
19 """Holds information for one node in the SCOP hierarchy. 20 21 sunid -- SCOP unique identifiers 22 23 nodetype -- One of 'cl' (class), 'cf' (fold), 'sf' (superfamily), 24 'fa' (family), 'dm' (protein), 'sp' (species), 25 'px' (domain). Additional node types may be added. 26 27 sccs -- SCOP concise classification strings. e.g. b.1.2.1 28 29 name -- The SCOP ID (sid) for domains (e.g. d1anu1), 30 currently empty for other node types 31 32 description -- e.g. "All beta proteins","Fibronectin type III", 33 34 """
35 - def __init__(self, line=None):
36 self.sunid = '' 37 self.nodetype = '' 38 self.sccs = '' 39 self.name = '' 40 self.description ='' 41 if line: 42 self._process(line)
43
44 - def _process(self, line):
45 """Parses DES records. 46 47 Records consist of 5 tab deliminated fields, 48 sunid, node type, sccs, node name, node description. 49 """ 50 #For example :: 51 # 52 #21953 px b.1.2.1 d1dan.1 1dan T:,U:91-106 53 #48724 cl b - All beta proteins 54 #48725 cf b.1 - Immunoglobulin-like beta-sandwich 55 #49265 sf b.1.2 - Fibronectin type III 56 #49266 fa b.1.2.1 - Fibronectin type III 57 58 line = line.rstrip() # no trailing whitespace 59 columns = line.split("\t") # separate the tab-delineated cols 60 if len(columns) != 5: 61 raise ValueError, "I don't understand the format of %s" % line 62 63 sunid, self.nodetype, self.sccs, self.name, self.description = columns 64 if self.name=='-': self.name ='' 65 self.sunid = int(sunid)
66 67
68 - def __str__(self):
69 s = [] 70 s.append(self.sunid) 71 s.append(self.nodetype) 72 s.append(self.sccs) 73 if self.name : 74 s.append(self.name) 75 else : 76 s.append("-") 77 s.append(self.description) 78 return "\t".join(map(str,s)) + "\n"
79 80
81 -def parse(handle):
82 """Iterates over a DES file, returning a Des record for each line 83 in the file. 84 85 Arguments: 86 handle -- file-like object 87 """ 88 for line in handle: 89 yield Record(line)
90 91
92 -class Iterator:
93 """Iterates over a DES file. 94 """
95 - def __init__(self, handle, parser=None):
96 """Create an object that iterates over a DES file. 97 98 handle -- file-like object. 99 100 parser -- an optional Parser object to chang the results into 101 another form. If set to None, then the raw contents 102 of the file will be returned. 103 104 """ 105 import warnings 106 warnings.warn("Bio.SCOP.Des.Iterator is deprecated. Please use Bio.SCOP.Des.parse() instead.", DeprecationWarning) 107 from types import FileType, InstanceType 108 if type(handle) is not FileType and type(handle) is not InstanceType: 109 raise TypeError, "I expected a file handle or file-like object" 110 self._handle = handle 111 self._parser = parser
112
113 - def next(self):
114 """Retrieve the next DES record.""" 115 while 1: 116 line = self._handle.readline() 117 if not line: return None 118 if line[0] !='#': break # Not a comment line 119 if self._parser is not None : 120 return self._parser.parse(line) 121 return line
122
123 - def __iter__(self):
124 return iter(self.next, None)
125 126
127 -class Parser:
128 - def __init__(self):
129 import warnings 130 warnings.warn("""Bio.SCOP.Des.Parser is deprecated. 131 Instead of 132 133 parser = Des.Parser() 134 record = parser.parse(entry) 135 136 please use 137 138 record = Des.Record(entry) 139 """, DeprecationWarning)
140
141 - def parse(self, entry):
142 """Returns a Des Record """ 143 return Record(entry)
144