1  from os import system 
  2  from re import match 
  3  from string import split 
  4  import sys 
  5   
  6   
  9                  "Operations, functions, etc common to the different model-free analysis methods." 
 10   
 11                  self.mf = mf 
  12   
 19   
 20   
 22                  "Initialise the next row of the results data structure." 
 23   
 24                  results = {} 
 25                  results['res_num'] = data['res_num'] 
 26                  results['model'] = model 
 27                  if match('0', model) or match('2\+3', model) or match('4\+5', model): 
 28                          results['s2']      = '' 
 29                          results['s2_err']  = '' 
 30                          results['s2f']     = '' 
 31                          results['s2f_err'] = '' 
 32                          results['s2s']     = '' 
 33                          results['s2s_err'] = '' 
 34                          results['te']      = '' 
 35                          results['te_err']  = '' 
 36                          results['rex']     = '' 
 37                          results['rex_err'] = '' 
 38                          results['chi2']    = data['chi2'] 
 39                  else: 
 40                          results['s2']      = data['s2'] 
 41                          results['s2_err']  = data['s2_err'] 
 42                          results['s2f']     = data['s2f'] 
 43                          results['s2f_err'] = data['s2f_err'] 
 44                          results['s2s']     = data['s2s'] 
 45                          results['s2s_err'] = data['s2s_err'] 
 46                          results['te']      = data['te'] 
 47                          results['te_err']  = data['te_err'] 
 48                          results['rex']     = data['rex'] 
 49                          results['rex_err'] = data['rex_err'] 
 50                          results['chi2']    = data['chi2'] 
 51                  return results 
  52   
 53   
 54 -        def grace(self, file_name, type, subtitle): 
  55                  "Create grace files for the results." 
 56   
 57                  file = open(file_name, 'w') 
 58   
 59                  if match('Chi2', type): 
 60                          file.write(self.grace_header(type + ' values', subtitle, 'Residue Number', type, 'xy')) 
 61                  else: 
 62                          file.write(self.grace_header(type + ' values', subtitle, 'Residue Number', type, 'xydy')) 
 63   
 64                  for res in range(len(self.mf.data.results)): 
 65                          if match('S2', type) and self.mf.data.results[res]['s2']: 
 66                                  file.write(self.mf.data.results[res]['res_num'] + " ") 
 67                                  file.write(`self.mf.data.results[res]['s2']` + " ") 
 68                                  file.write(`self.mf.data.results[res]['s2_err']` + "\n") 
 69                          elif match('S2s', type) and self.mf.data.results[res]['s2s']: 
 70                                  file.write(self.mf.data.results[res]['res_num'] + " ") 
 71                                  file.write(`self.mf.data.results[res]['s2s']` + " ") 
 72                                  file.write(`self.mf.data.results[res]['s2s_err']` + "\n") 
 73                          elif match('S2f', type) and self.mf.data.results[res]['s2f']: 
 74                                  file.write(self.mf.data.results[res]['res_num'] + " ") 
 75                                  file.write(`self.mf.data.results[res]['s2f']` + " ") 
 76                                  file.write(`self.mf.data.results[res]['s2f_err']` + "\n") 
 77                          elif match('te', type) and self.mf.data.results[res]['te']: 
 78                                  file.write(self.mf.data.results[res]['res_num'] + " ") 
 79                                  file.write(`self.mf.data.results[res]['te']` + " ") 
 80                                  file.write(`self.mf.data.results[res]['te_err']` + "\n") 
 81                          elif match('Rex', type) and self.mf.data.results[res]['rex']: 
 82                                  file.write(self.mf.data.results[res]['res_num'] + " ") 
 83                                  file.write(`self.mf.data.results[res]['rex']` + " ") 
 84                                  file.write(`self.mf.data.results[res]['rex_err']` + "\n") 
 85                          elif match('Chi2', type) and self.mf.data.results[res]['chi2']: 
 86                                  file.write(self.mf.data.results[res]['res_num'] + " ") 
 87                                  file.write(`self.mf.data.results[res]['chi2']` + "\n") 
 88                  file.write("&\n") 
 89                  file.close() 
  90   
 91   
 93                  "Create and return a grace header." 
 94   
 95                  text = "@version 50100\n" 
 96                  text = text + "@with g0\n" 
 97                  if match('Residue Number', x): 
 98                          text = text + "@    world xmax 165\n" 
 99                  if match('R1', x) and match('Chi2', y): 
100                          text = text + "@    world xmin 0.8\n" 
101                          text = text + "@    world xmax 2\n" 
102                          text = text + "@    world ymin 0\n" 
103                          text = text + "@    world ymax 2000\n" 
104                  if match('R2', x) and match('Chi2', y): 
105                          text = text + "@    world xmin 5\n" 
106                          text = text + "@    world xmax 45\n" 
107                          text = text + "@    world ymin 0\n" 
108                          text = text + "@    world ymax 2000\n" 
109                  if match('NOE', x) and match('Chi2', y): 
110                          text = text + "@    world xmin 0\n" 
111                          text = text + "@    world xmax 1\n" 
112                          text = text + "@    world ymin 0\n" 
113                          text = text + "@    world ymax 2000\n" 
114                  text = text + "@    view xmax 1.22\n" 
115                  text = text + "@    title \"" + title + "\"\n" 
116                  text = text + "@    subtitle \"" + subtitle + "\"\n" 
117                  text = text + "@    xaxis  label \"" + x + "\"\n" 
118                  if match('Residue Number', x): 
119                          text = text + "@    xaxis  tick major 10\n" 
120                  if match('R1', x) and match('Chi2', y): 
121                          text = text + "@    xaxis  tick major 0.2\n" 
122                  if match('R2', x) and match('Chi2', y): 
123                          text = text + "@    xaxis  tick major 5\n" 
124                  if match('NOE', x) and match('Chi2', y): 
125                          text = text + "@    xaxis  tick major 0.1\n" 
126                  text = text + "@    xaxis  tick major size 0.480000\n" 
127                  text = text + "@    xaxis  tick major linewidth 0.5\n" 
128                  text = text + "@    xaxis  tick minor linewidth 0.5\n" 
129                  text = text + "@    xaxis  tick minor size 0.240000\n" 
130                  text = text + "@    xaxis  ticklabel char size 0.790000\n" 
131                  text = text + "@    yaxis  label \"" + y + "\"\n" 
132                  if match('R1', x) and match('Chi2', y): 
133                          text = text + "@    yaxis  tick major 200\n" 
134                  if match('R2', x) and match('Chi2', y): 
135                          text = text + "@    yaxis  tick major 200\n" 
136                  if match('NOE', x) and match('Chi2', y): 
137                          text = text + "@    yaxis  tick major 200\n" 
138                  text = text + "@    yaxis  tick major size 0.480000\n" 
139                  text = text + "@    yaxis  tick major linewidth 0.5\n" 
140                  text = text + "@    yaxis  tick minor linewidth 0.5\n" 
141                  text = text + "@    yaxis  tick minor size 0.240000\n" 
142                  text = text + "@    yaxis  ticklabel char size 0.790000\n" 
143                  text = text + "@    frame linewidth 0.5\n" 
144                  text = text + "@    s0 symbol 1\n" 
145                  text = text + "@    s0 symbol size 0.49\n" 
146                  text = text + "@    s0 symbol fill pattern 1\n" 
147                  text = text + "@    s0 symbol linewidth 0.5\n" 
148                  text = text + "@    s0 line linestyle 0\n" 
149                  text = text + "@target G0.S0\n@type " + type + "\n" 
150                  return text 
 151   
152   
161   
162   
164                  "Put the parameter data structures into the log file." 
165   
166                  self.mf.log.write("\n" + name + " data structure\n") 
167                  for param in ['tloc', 'theta', 'ss2', 'sf2', 'te', 'rex']: 
168                          self.mf.log.write('%-10s' % ( param + ":" )) 
169                          self.mf.log.write('%-15s' % ( "start = " + mdx[param]['start'] )) 
170                          self.mf.log.write('%-11s' % ( "flag = " + mdx[param]['flag'] )) 
171                          self.mf.log.write('%-13s' % ( "bound = " + mdx[param]['bound'] )) 
172                          self.mf.log.write('%-20s' % ( "lower = " + mdx[param]['lower'] )) 
173                          self.mf.log.write('%-20s' % ( "upper = " + mdx[param]['upper'] )) 
174                          self.mf.log.write('%-10s\n' % ( "steps = " + mdx[param]['steps'] )) 
 175   
176   
178                  "Print the results into the results file." 
179   
180                  file = open('results', 'w') 
181   
182                  file.write('%-6s%-6s%-13s%-13s%-13s' % ( 'ResNo', 'Model', '    S2', '    S2f', '    S2s' )) 
183                  file.write('%-19s%-13s%-10s\n' % ( '       te', '    Rex', '    Chi2' )) 
184                  sys.stdout.write("[") 
185                  for res in range(len(self.mf.data.results)): 
186                          sys.stdout.write("-") 
187                          file.write('%-6s' % self.mf.data.results[res]['res_num']) 
188                          file.write('%-6s' % self.mf.data.results[res]['model']) 
189   
190                          if self.mf.data.results[res]['model'] in ["1", "2", "3", "4", "5"]: 
191                                  file.write('%5.3f%1s%-5.3f  ' % ( self.mf.data.results[res]['s2'], '±', self.mf.data.results[res]['s2_err'] )) 
192                          else: 
193                                  file.write('%13s' % '') 
194                          if self.mf.data.results[res]['model'] in ["5"]: 
195                                  file.write('%5.3f%1s%-5.3f  ' % ( self.mf.data.results[res]['s2f'], '±', self.mf.data.results[res]['s2f_err'] )) 
196                                  file.write('%5.3f%1s%-5.3f  ' % ( self.mf.data.results[res]['s2s'], '±', self.mf.data.results[res]['s2s_err'] )) 
197                          else: 
198                                  file.write('%26s' % '') 
199                          if self.mf.data.results[res]['model'] in ["2", "4", "5"]: 
200                                  file.write('%8.2f%1s%-8.2f  ' % ( self.mf.data.results[res]['te'], '±', self.mf.data.results[res]['te_err'] )) 
201                          else: 
202                                  file.write('%19s' % '') 
203                          if self.mf.data.results[res]['model'] in ["3", "4"]: 
204                                  file.write('%5.3f%1s%-5.3f  ' % ( self.mf.data.results[res]['rex'], '±', self.mf.data.results[res]['rex_err'] )) 
205                          else: 
206                                  file.write('%13s' % '') 
207                          file.write('%10.3f\n' % self.mf.data.results[res]['chi2']) 
208                  sys.stdout.write("]\n") 
209   
210                  file.close() 
 211   
212   
214                  "The stage for model selection common to all techniques." 
215   
216                  print "\n[ Model-free data extraction ]\n" 
217                  self.extract_mf_data() 
218   
219                  print "\n[ " + self.mf.usr_param.method + " model selection ]\n" 
220                  self.model_selection.run() 
221   
222                  print "\n[ Printing results ]\n" 
223                  self.print_results() 
224   
225                  print "\n[ Placing data structures into \"data_all\" ]\n" 
226                  self.print_data() 
227   
228                  print "\n[ Grace file creation ]\n" 
229                  self.mf.file_ops.mkdir('grace') 
230                  self.grace('grace/S2.agr', 'S2', subtitle="After model selection, unoptimised") 
231                  self.grace('grace/S2f.agr', 'S2f', subtitle="After model selection, unoptimised") 
232                  self.grace('grace/S2s.agr', 'S2s', subtitle="After model selection, unoptimised") 
233                  self.grace('grace/te.agr', 'te', subtitle="After model selection, unoptimised") 
234                  self.grace('grace/Rex.agr', 'Rex', subtitle="After model selection, unoptimised") 
235                  self.grace('grace/Chi2.agr', 'Chi2', subtitle="After model selection, unoptimised") 
 236   
237   
239                  "Extract all the information from the input info." 
240   
241   
242                  trans_table = [] 
243                  trans_frq_table = [] 
244                  last_frq = 0.0 
245                  self.mf.data.num_ri = len(self.mf.usr_param.input_info) 
246   
247                   
248                  for i in range(self.mf.data.num_ri): 
249                          flag = 1 
250                          if len(self.mf.data.frq) > 0: 
251                                  for frq in range(len(self.mf.data.frq)): 
252                                          if self.mf.usr_param.input_info[i][2] == self.mf.data.frq[frq]: 
253                                                  flag = 0 
254                           
255                          if flag: 
256                                  self.mf.data.num_frq = self.mf.data.num_frq + 1 
257                                  self.mf.data.frq_label.append(self.mf.usr_param.input_info[i][1]) 
258                                  self.mf.data.frq.append(float(self.mf.usr_param.input_info[i][2])) 
259                          trans_frq_table.append(self.mf.data.num_frq + 1) 
260                          last_frq = self.mf.usr_param.input_info[i][2] 
261   
262                           
263                          self.mf.data.data_types.append(None) 
264                          self.mf.data.data_files.append(None) 
265                          self.mf.data.remap_table.append(None) 
266                          self.mf.data.noe_r1_table.append(None) 
267                          trans_table.append(None) 
268   
269                   
270                  counter = 0 
271                  for frq in range(len(self.mf.data.frq)): 
272                          for i in range(self.mf.data.num_ri): 
273                                  if self.mf.data.frq[frq] == self.mf.usr_param.input_info[i][2]: 
274                                          if match('R1', self.mf.usr_param.input_info[i][0]): 
275                                                  trans_table[i] = counter 
276                                                  counter = counter + 1 
277                          for i in range(self.mf.data.num_ri): 
278                                  if self.mf.data.frq[frq] == self.mf.usr_param.input_info[i][2]: 
279                                          if match('R2', self.mf.usr_param.input_info[i][0]): 
280                                                  trans_table[i] = counter 
281                                                  counter = counter + 1 
282                          for i in range(self.mf.data.num_ri): 
283                                  if self.mf.data.frq[frq] == self.mf.usr_param.input_info[i][2]: 
284                                          if match('NOE', self.mf.usr_param.input_info[i][0]): 
285                                                  trans_table[i] = counter 
286                                                  counter = counter + 1 
287   
288                   
289                  for i in range(self.mf.data.num_ri): 
290                          self.mf.data.data_types[trans_table[i]] = self.mf.usr_param.input_info[i][0] 
291                          self.mf.data.data_files[trans_table[i]] = self.mf.usr_param.input_info[i][3] 
292                          for frq in range(len(self.mf.data.frq)): 
293                                  if self.mf.data.frq[frq] == self.mf.usr_param.input_info[i][2]: 
294                                          self.mf.data.remap_table[trans_table[i]] = frq 
295                          if match('NOE', self.mf.usr_param.input_info[i][0]): 
296                                  for j in range(self.mf.data.num_ri): 
297                                          if match('R1', self.mf.usr_param.input_info[j][0]) and self.mf.usr_param.input_info[i][2] == self.mf.usr_param.input_info[j][2]: 
298                                                  self.mf.data.noe_r1_table[trans_table[i]] = trans_table[j] 
299   
300                  if self.mf.debug: 
301                          print "%-20s%-20s" % ("Input info:", `self.mf.usr_param.input_info`) 
302                          print "%-20s%-20s" % ("Trans frq table:", `trans_frq_table`) 
303                          print "%-20s%-20s" % ("Trans table:", `trans_table`) 
304                          print "%-20s%-20i" % ("Num ri:", self.mf.data.num_ri) 
305                          print "%-20s%-20i" % ("Num frq:", self.mf.data.num_frq) 
306                          print "%-20s%-20s" % ("Data types:", `self.mf.data.data_types`) 
307                          print "%-20s%-20s" % ("Data files:", `self.mf.data.data_files`) 
308                          print "%-20s%-20s" % ("Remap table:", `self.mf.data.remap_table`) 
309                          print "%-20s%-20s" % ("NOE to R1 table:", `self.mf.data.noe_r1_table`) 
310                          print "%-20s%-20s" % ("Frq labels:", `self.mf.data.frq_label`) 
311                          print "%-20s%-20s" % ("Frqs:", `self.mf.data.frq`) 
312                          print "\n"