Package qubx_testing :: Module stim_peq
[hide private]
[frames] | no frames]

Source Code for Module qubx_testing.stim_peq

  1  import qubx.global_namespace 
  2  import qubx.GTK 
  3  import qubx.modelGTK 
  4  import qubx.pyenv 
  5  import qubx.pyenvGTK 
  6  import qubx.settings 
  7  import qubx.settingsGTK 
  8  import gtk 
  9  from qubx.accept import * 
 10  from qubx.GTK import pack_item, pack_label 
 11  from qubx.settings import * 
 12   
13 -def pick_plot_stim(stim):
14 for k,v in stim.iteritems(): 15 if hasattr(v, '__iter__') and (len(v) > 1): 16 return k 17 for k,v in stim.iteritems(): 18 return k 19 return None
20
21 -def PromptPeqOptions(modelview, stim, tbl_name, ix, ix_type="Class"):
22 defaults = modelview.get_stimulus(qubx.global_namespace.QubX.Data.view) 23 if not defaults: 24 qubx.pyenvGTK.show_message("First, make a rate constant ligand- or voltage-sensitive.", title="Plot Stimulated Peq", parent=qubx.global_namespace.QubX.Models.parent_window) 25 return None, None, None 26 prefs = qubx.settings.SettingsMgr['stim_peq'].active 27 tbl_name = tbl_name or str(prefs['tbl_name'].data) or 'DoseResponse' 28 stim = stim or defaults.copy() 29 for name in stim: 30 p = prefs.find(name) 31 if p.data: 32 stim[name] = p.data[:] 33 order = sorted(stim.keys()) 34 35 instructions = ["Enter a list of numbers separated by commas.", 36 "If the model has more than one stimulus, all", 37 "combinations of stimulus values will be evaluated."] 38 entries = [(ins, None, None, None) for ins in instructions] 39 if ix is None: 40 i = prefs['tbl_ix'].data[0] if prefs['tbl_ix'].data else 1 41 entries.append( (ix_type, i, acceptIntBetween(0, modelview.file.classes.size-1), "%s") ) 42 stim_start = len(entries) 43 entries.extend([(name, stim[name], acceptFloatList(), formatList("%.3f")) for name in order]) 44 entries.append( ('Output list name:', tbl_name, acceptStringNonempty, str) ) 45 result = qubx.pyenvGTK.prompt_entries(entries, "Plot Stimulated Peq - Options", qubx.global_namespace.QubX.Models.parent_window) 46 if result is None: 47 return None, None, None 48 if ix is None: 49 ix = result[stim_start-1] 50 for i, name in enumerate(order): 51 stim[name] = result[i+stim_start] 52 tbl_name = result[-1] 53 54 prefs['tbl_name'].data = tbl_name 55 prefs['tbl_ix'].data = ix 56 for name in stim: 57 prefs[name].data = stim[name] 58 59 return stim, tbl_name, ix
60
61 -def PlotPeqOfState(modelview, idx, stim=None, tbl_name=None, var_name="Peq"):
62 st, tn, ix = stim, tbl_name, idx 63 if (stim is None) or (tbl_name is None): 64 st, tn, ix = PromptPeqOptions(modelview, st, tn, ix) 65 if st is None: 66 return 67 qubx.pyenv.env.OnScriptable('qubx_testing.stim_peq.PlotPeqOfState(QubX.Model.view, %i, stim=%s, tbl_name=%s, var_name=%s)' % (idx, repr(stim), repr(tbl_name), repr(var_name))) 68 t = qubx.global_namespace.QubX.Tables.new_table(tn, False) 69 t.clear() 70 for result in qubx.modelGTK.calc_Pe_of_stim(modelview, st, idx, var_name, calc=qubx.modelGTK.iter_Pe_of_state): 71 t.append(result) 72 xname = pick_plot_stim(st) 73 if xname: 74 qubx.global_namespace.QubX.Figures.Charts.add_two_plot(tn, xname, var_name, False, False) 75 qubx.global_namespace.QubX.show_charts()
76 77 qubx.modelGTK.Tools.register('state', 'Plot Dose-Response of State', PlotPeqOfState) 78
79 -def PlotPeqOfClass(modelview, idx=None, stim=None, tbl_name=None, var_name="Peq"):
80 print modelview, idx 81 mv = qubx.global_namespace.QubX.Models.view if ((modelview is None) or ('MenuItem' in str(modelview.__class__))) else modelview 82 st, tn, ix = stim, tbl_name, idx 83 if not (ix is None): 84 ix = mv.file.states[ix, 'Class'] 85 if (stim is None) or (tbl_name is None): 86 st, tn, ix = PromptPeqOptions(mv, st, tn, ix) 87 if st is None: 88 return 89 qubx.pyenv.env.OnScriptable('qubx_testing.stim_peq.PlotPeqOfClass(QubX.Models.view, %i, stim=%s, tbl_name=%s, var_name=%s)' % (ix, repr(st), repr(tn), repr(var_name))) 90 t = qubx.global_namespace.QubX.Tables.new_table(tn, False) 91 t.clear() 92 for result in qubx.modelGTK.calc_Pe_of_stim(mv, st, ix, var_name): 93 t.append(result) 94 xname = pick_plot_stim(st) 95 if xname: 96 qubx.global_namespace.QubX.Figures.Charts.add_two_plot(tn, xname, var_name, False, False) 97 qubx.global_namespace.QubX.show_charts()
98 99 qubx.modelGTK.Tools.register('state', 'Plot Dose-Response of Class', PlotPeqOfClass) 100 qubx.modelGTK.Tools.register('other', 'Plot Dose-Response...', PlotPeqOfClass) 101
102 -def PromptEC50Options(modelview, stim_name, cls):
103 defaults = modelview.get_stimulus(qubx.global_namespace.QubX.Data.view) 104 if not defaults: 105 qubx.pyenvGTK.show_message("First, make a rate constant ligand- or voltage-sensitive.", title="Plot Stimulated Peq", parent=qubx.global_namespace.QubX.Models.parent_window) 106 return None, None 107 prefs = qubx.settings.SettingsMgr['stim_peq'].active 108 if not (stim_name in defaults): 109 stim_name = str(prefs['ec50_stim'].data) 110 if not (stim_name in defaults): 111 stim_name = defaults.keys()[0] 112 if (cls is None): 113 if prefs.find('ec50_cls').data: 114 cls = prefs['ec50_cls'].data[0] 115 else: 116 cls = 1 117 names = sorted(defaults.keys()) 118 dlg = gtk.Dialog("Find EC50", qubx.global_namespace.QubX.Models.parent_window, gtk.DIALOG_MODAL) 119 pack_label("", dlg.vbox) 120 line = pack_item(gtk.HBox(True), dlg.vbox) 121 pack_label("Stimulus variable:", line) 122 mnu = pack_item(qubx.GTK.StaticComboList(names), line) 123 line = pack_item(gtk.HBox(True), dlg.vbox) 124 pack_label("Class:", line) 125 txt = pack_item(qubx.GTK.NumEntry(cls, acceptIntBetween(0, modelview.file.classes.size-1)), line) 126 dlg.add_buttons('OK', gtk.RESPONSE_OK, 'Cancel', gtk.RESPONSE_CANCEL) 127 response = dlg.run() 128 stim_name = names[mnu.active_i] 129 cls = txt.value 130 dlg.destroy() 131 if response != gtk.RESPONSE_OK: 132 return None, None 133 prefs['ec50_stim'].data = stim_name 134 prefs['ec50_cls'].data = cls 135 return stim_name, cls
136
137 -def FindEC50(modelview=None, stim_name=None, cls=None, modal_output=True):
138 mv = qubx.global_namespace.QubX.Models.view if ((modelview is None) or ('MenuItem' in str(modelview.__class__))) else modelview 139 # in Tools.register('other', f), f is called from menu as f(menuItem) 140 141 st = stim_name 142 c = cls 143 if (st is None) or (c is None): 144 st, c = PromptEC50Options(mv, st, c) 145 if st is None: 146 return 147 148 qubx.pyenv.env.OnScriptable('ec50 = qubx_testing.stim_peq.FindEC50(QubX.Models.view, stim_name=%s, cls=%i, modal_output=False)' % 149 (repr(st), c)) 150 ec50 = qubx.modelGTK.find_ec50(mv, st, c) 151 if modal_output: 152 msg = "No convergence." if (ec50 is None) else ("EC50 = %.4g" % ec50) 153 qubx.pyenvGTK.show_message(msg, title="Find EC50", parent=qubx.global_namespace.QubX.Models.parent_window) 154 return ec50
155 156 qubx.modelGTK.Tools.register('other', 'Find EC50...', FindEC50) 157