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(object):
19 """Holds information for one node in the SCOP hierarchy. 20 21 Attributes: 22 23 - sunid - SCOP unique identifiers 24 - nodetype - One of 'cl' (class), 'cf' (fold), 'sf' (superfamily), 25 'fa' (family), 'dm' (protein), 'sp' (species), 'px' (domain). 26 Additional node types may be added. 27 - sccs - SCOP concise classification strings. e.g. b.1.2.1 28 - name - The SCOP ID (sid) for domains (e.g. d1anu1), currently empty for other node types 29 - description - e.g. "All beta proteins","Fibronectin type III", 30 31 """
32 - def __init__(self, line=None):
33 self.sunid = '' 34 self.nodetype = '' 35 self.sccs = '' 36 self.name = '' 37 self.description = '' 38 if line: 39 self._process(line)
40
41 - def _process(self, line):
42 """Parses DES records. 43 44 Records consist of 5 tab deliminated fields, 45 sunid, node type, sccs, node name, node description. 46 """ 47 # For example :: 48 # 49 # 21953 px b.1.2.1 d1dan.1 1dan T:,U:91-106 50 # 48724 cl b - All beta proteins 51 # 48725 cf b.1 - Immunoglobulin-like beta-sandwich 52 # 49265 sf b.1.2 - Fibronectin type III 53 # 49266 fa b.1.2.1 - Fibronectin type III 54 55 line = line.rstrip() # no trailing whitespace 56 columns = line.split("\t") # separate the tab-delineated cols 57 if len(columns) != 5: 58 raise ValueError("I don't understand the format of %s" % line) 59 60 sunid, self.nodetype, self.sccs, self.name, self.description = columns 61 if self.name == '-': 62 self.name = '' 63 self.sunid = int(sunid)
64
65 - def __str__(self):
66 s = [] 67 s.append(self.sunid) 68 s.append(self.nodetype) 69 s.append(self.sccs) 70 if self.name: 71 s.append(self.name) 72 else: 73 s.append("-") 74 s.append(self.description) 75 return "\t".join(map(str, s)) + "\n"
76 77
78 -def parse(handle):
79 """Iterates over a DES file as a Des record for each line 80 81 Arguments: 82 83 - handle - file-like object 84 """ 85 for line in handle: 86 if line.startswith('#'): 87 continue 88 yield Record(line)
89