1
2
3
4
5
6
7
8
9
10
11 import sys
12
13
14 HEADERLEN = 6
15
16
17
18 -class XpkEntry(object):
19
20
21
22
23
24
25
26
27 - def __init__(self, entry, headline):
28 self.fields = {}
29
30 datlist = entry.split()
31 headlist = headline.split()
32
33 i = 0
34 for i in range(len(datlist) - 1):
35 self.fields[headlist[i]] = datlist[i+1]
36 i = i + 1
37
38 try:
39 self.fields["entrynum"] = datlist[0]
40 except IndexError, e:
41 pass
42
43
45
46
47
67
69
70
71
72
73 maxres = -1
74 minres = -1
75
76
77 self.dict = {}
78 for i in range(len(self.data)):
79 line = self.data[i]
80 ind = XpkEntry(line, self.datalabels).fields[index + ".L"]
81 key = ind.split(".")[0]
82
83 res = int(key)
84
85 if (maxres == -1):
86 maxres = res
87 if (minres == -1):
88 minres = res
89
90 maxres = max([maxres, res])
91 minres = min([minres, res])
92
93 if str(res) in self.dict:
94
95 templst = self.dict[str(res)]
96 templst.append(line)
97 self.dict[str(res)] = templst
98
99 else:
100
101 self.dict[str(res)] = [line]
102
103 self.dict["maxres"] = maxres
104 self.dict["minres"] = minres
105
106 return self.dict
107
109 outfile = _try_open_write(outfn)
110 outfile.write(self.firstline)
111 outfile.write("\012")
112 outfile.write(self.axislabels)
113 outfile.write("\012")
114 outfile.write(self.dataset)
115 outfile.write("\012")
116 outfile.write(self.sw)
117 outfile.write("\012")
118 outfile.write(self.sf)
119 outfile.write("\012")
120 outfile.write(self.datalabels)
121 outfile.write("\012")
122 outfile.close()
123
124
126
127 try:
128 infile = open(fn, 'r')
129 except IOError, e:
130 print "file", fn, "could not be opened for reading - quitting."
131 sys.exit(0)
132 return infile
133
134
136
137 try:
138 infile = open(fn, 'w')
139 except IOError, e:
140 print "file", fn, "could not be opened for writing - quitting."
141 sys.exit(0)
142 return infile
143
144
145 -def replace_entry(line, fieldn, newentry):
146
147
148
149
150
151
152 start = _find_start_entry(line, fieldn)
153 leng = len(line[start:].split()[0])
154 newline = line[:start] + str(newentry) + line[(start+leng):]
155 return newline
156
157
158 -def _find_start_entry(line, n):
159
160
161
162
163
164 infield = 0
165
166 if (n == 1):
167 return 0
168
169
170 c = 1
171 leng = len(line)
172
173
174
175 if (line[0] == " "):
176 infield = 0
177 field = 0
178 else:
179 infield = 1
180 field = 1
181
182 while (c < leng and field < n):
183 if (infield):
184 if (line[c] == " " and not (line[c-1] == " ")):
185 infield = 0
186 else:
187 if (not line[c] == " "):
188 infield = 1
189 field = field + 1
190
191 c = c + 1
192
193 return c - 1
194
195
197
198
199
200
201
202 outlist = []
203
204 [dict_list, label_line_list] = _read_dicts(fn_list, keyatom)
205
206
207 minr = dict_list[0]["minres"]
208 maxr = dict_list[0]["maxres"]
209
210 for dictionary in dict_list:
211 if (maxr < dictionary["maxres"]):
212 maxr = dictionary["maxres"]
213 if (minr > dictionary["minres"]):
214 minr = dictionary["minres"]
215
216 res = minr
217 while res <= maxr:
218 count = 0
219 line = str(res)
220 for dictionary in dict_list:
221 label = label_line_list[count]
222 if str(res) in dictionary:
223 line = line + "\t" + XpkEntry(dictionary[str(res)][0], label).fields[datalabel]
224 else:
225 line = line + "\t" + "*"
226 count = count + 1
227 line = line + "\n"
228 outlist.append(line)
229 res = res + 1
230
231 return outlist
232
233
235 keys = dictionary.keys()
236 sorted_keys = keys.sort()
237 return sorted_keys
238
239
241
242 dict_list = []
243 datalabel_list = []
244 for fn in fn_list:
245 peaklist = Peaklist(fn)
246 dict = peaklist.residue_dict(keyatom)
247 dict_list.append(dict)
248 datalabel_list.append(peaklist.datalabels)
249
250 return [dict_list, datalabel_list]
251