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 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 == '-': 65 self.name = '' 66 self.sunid = int(sunid)
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 if line.startswith('#'): 90 continue 91 yield Record(line)
92