1
2
3
4
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
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 """
37 self.sunid = ''
38 self.nodetype = ''
39 self.sccs = ''
40 self.name = ''
41 self.description =''
42
54
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
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
79 if self._parser is not None :
80 return self._parser.parse(line)
81 return line
82
84 return iter(self.next, None)
85
86
88 """Parses DES records.
89
90 Records consist of 5 tab deliminated fields,
91 sunid, node type, sccs, node name, node description.
92 """
93
94
95
96
97
98
99
100
102 """Returns a Des Record """
103 entry = entry.rstrip()
104 columns = entry.split("\t")
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