1
2
3
4
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.mrc-lmb.cam.ac.uk/scop/release-notes.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.73": http://scop.mrc-lmb.cam.ac.uk/scop/parse/dir.cla.scop.txt_1.73
14 (July 2008)
15
16 """
17
18
19
20 from Residues import *
21
22
24 """Holds information for one SCOP domain
25
26 sid -- SCOP identifier. e.g. d1danl2
27
28 residues -- The domain definition as a Residues object
29
30 sccs -- SCOP concise classification strings. e.g. b.1.2.1
31
32 sunid -- SCOP unique identifier for this domain
33
34 hierarchy -- A sequence of tuples (nodetype, sunid) describing the
35 location of this domain in the SCOP hierarchy.
36 See the Scop module for a description of nodetypes.
37 """
39 self.sid = ''
40 self.residues = None
41 self.sccs = ''
42 self.sunid =''
43 self.hierarchy = []
44 if line:
45 self._process(line)
46
48 line = line.rstrip()
49 columns = line.split('\t')
50 if len(columns) != 6:
51 raise ValueError("I don't understand the format of %s" % line)
52
53 self.sid, pdbid, residues, self.sccs, self.sunid, hierarchy = columns
54 self.residues = Residues(residues)
55 self.residues.pdbid = pdbid
56 self.sunid = int(self.sunid)
57
58 for ht in hierarchy.split(",") :
59 key, value = ht.split('=')
60 value = int(value)
61 self.hierarchy.append([key, value])
62
64 s = []
65 s.append(self.sid)
66 s += str(self.residues).split(" ")
67 s.append(self.sccs)
68 s.append(self.sunid)
69
70 h=[]
71 for ht in self.hierarchy:
72 h.append("=".join(map(str,ht)))
73 s.append(",".join(h))
74
75 return "\t".join(map(str,s)) + "\n"
76
77
79 """Iterates over a CLA file, returning a Cla record for each line
80 in the file.
81
82 Arguments:
83
84 handle -- file-like object.
85 """
86 for line in handle:
87 if line.startswith('#'):
88 continue
89 yield Record(line)
90
91
93 """A CLA file indexed by SCOP identifiers, allowing rapid
94 random access into a file."""
96 """
97 Arguments:
98
99 filename -- The file to index
100 """
101 dict.__init__(self)
102 self.filename = filename
103 f = open(self.filename)
104 try:
105 position = 0
106 while True:
107 line = f.readline()
108 if not line: break
109 record = Record(line)
110 key = record.sid
111 if key != None :
112 self[key] = position
113 position = f.tell()
114 finally:
115 f.close()
116
118 """ Return an item from the indexed file. """
119 position = dict.__getitem__(self,key)
120
121 f = open(self.filename)
122 try:
123 f.seek(position)
124 line = f.readline()
125 record = Record(line)
126 finally:
127 f.close()
128 return record
129