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

Source Code for Module Bio.SCOP.Cla

  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  """ Handle the SCOP CLAssification file, which describes SCOP domains. 
  7   
  8  The file format is described in the scop 
  9  "release notes.":http://scop.berkeley.edu/release-notes-1.55.html  
 10  The latest CLA file can be found 
 11  "elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/ 
 12     
 13  "Release 1.55":http://scop.berkeley.edu/parse/dir.cla.scop.txt_1.55 (July 2001) 
 14   
 15  """ 
 16   
 17   
 18  from types import * 
 19   
 20  from Residues import *  
 21  from FileIndex import FileIndex 
 22   
 23   
24 -class Record:
25 """Holds information for one SCOP domain 26 27 sid -- SCOP identifier. e.g. d1danl2 28 29 residues -- The domain definition as a Residues object 30 31 sccs -- SCOP concise classification strings. e.g. b.1.2.1 32 33 sunid -- SCOP unique identifier for this domain 34 35 hierarchy -- A sequence of tuples (nodetype, sunid) describing the 36 location of this domain in the SCOP hierarchy. 37 See the Scop module for a description of nodetypes. 38 """
39 - def __init__(self):
40 self.sid = '' 41 self.residues = None 42 self.sccs = '' 43 self.sunid ='' 44 self.hierarchy = []
45
46 - def __str__(self):
47 s = [] 48 s.append(self.sid) 49 s += str(self.residues).split(" ") 50 s.append(self.sccs) 51 s.append(self.sunid) 52 53 h=[] 54 for ht in self.hierarchy: 55 h.append("=".join(map(str,ht))) 56 s.append(",".join(h)) 57 58 return "\t".join(map(str,s)) + "\n"
59
60 -class Iterator:
61 """Iterates over a CLA file. 62 """
63 - def __init__(self, handle, parser=None):
64 """Create an object that iterates over a DES file. 65 66 handle -- file-like object. 67 68 parser -- an optional Parser object to chang the results into 69 another form. If set to None, then the raw contents 70 of the file will be returned. 71 72 """ 73 if type(handle) is not FileType and type(handle) is not InstanceType: 74 raise TypeError, "I expected a file handle or file-like object" 75 self._handle = handle 76 self._parser = parser
77
78 - def next(self):
79 """Retrieve the next CLA record.""" 80 while 1: 81 line = self._handle.readline() 82 if not line: return None 83 if line[0] !='#': break # Not a comment line 84 if self._parser is not None : 85 return self._parser.parse(line) 86 return line
87
88 - def __iter__(self):
89 return iter(self.next, None)
90 91
92 -class Parser:
93 """Parses tab-deliminated CLA records. 94 """
95 - def parse(self, entry):
96 """Returns a Cla Record """ 97 entry = entry.rstrip() # no trailing whitespace 98 columns = entry.split('\t') # separate the tab-delineated cols 99 if len(columns) != 6: 100 raise SyntaxError, "I don't understand the format of %s" % entry 101 102 rec = Record() 103 rec.sid, pdbid, residues, rec.sccs, rec.sunid, hierarchy = columns 104 rec.residues = Residues(residues) 105 rec.residues.pdbid = pdbid 106 rec.sunid = int(rec.sunid) 107 108 h = [] 109 for ht in hierarchy.split(",") : 110 h.append( ht.split('=')) 111 for ht in h: 112 ht[1] = int(ht[1]) 113 rec.hierarchy = h 114 115 116 return rec
117 118
119 -class Index(FileIndex):
120 """A CLA file indexed by SCOP identifiers."""
121 - def __init__(self, filename, ) :
122 iterator = lambda f : Iterator(f, Parser()) 123 key_gen = lambda rec : rec.sid 124 125 FileIndex.__init__(self, filename, iterator, key_gen)
126