ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/vu_module.py
(Generate patch)
# Line 3 | Line 3
3   This uses the old Tk GUI toolkit.
4   Christopher Lausted, Institute for Systems Biology,
5   OSPRAI developers
6 < Last modified on 100412 (yymmdd)
6 > Last modified on 100413 (yymmdd)
7  
8   Example:
9   #import vu_module as vu
10   #io_module as io
11   #ba1 = io.readsprit("spritdata.txt")
12 < #vu.show(ba1, "line")
13 < #vu.dotgraph(ba1)
14 < #vu.linegraph(ba1)
15 < #vu.dualgraph(ba1, ba2)
12 > #vu.dotgraph(ba1, "Title")
13 > #vu.linegraph(ba1, "Title")
14 > #vu.dualgraph(ba1, ba2, "Title")
15 > #vu.scatterplot(ba1, t1, t2, t3, t4, title)
16   """
17 < __version__ = "100412"
17 > __version__ = "100413"
18  
19  
20   ## Import libraries
21   import ba_class as ba               ## Our Biosensor Array class.
22 + import numpy as np
23   from datetime import date
24   import Tkinter as Tk
25   import tkSimpleDialog as dialog
# Line 28 | Line 29
29   from matplotlib.figure import Figure
30  
31  
32 < def linegraph(baLine):
32 > def linegraph(baLine, title=""):
33      """Graph data of baLine using lines."""
34      global root, fig, ax, canvas  ## Tk/mpl globals.
35      global ba0, ba1, ba2   ## Ref to ba for roilist, dotgraph, linegraph
36 +    global gTitle          ## Title for graph.
37      ba0, ba1, ba2 = baLine, 0, baLine
38 <    createTkWindow()
38 >    gTitle = title
39 >    createSensorgramTkWindow()
40      show()
41      root.mainloop()
42      return
43      ## End of linegraph().
44      
45 < def dotgraph(baDot):
45 > def dotgraph(baDot, title=""):
46      """Graph data of baDot using dots."""
47      global root, fig, ax, canvas  ## Tk/mpl globals..
48      global ba0, ba1, ba2   ## Ref to ba for roilist, dotgraph, linegraph
49 +    global gTitle          ## Title for graph.
50      ba0, ba1, ba2 = baDot, baDot, 0
51 <    createTkWindow()
51 >    gTitle = title
52 >    createSensorgramTkWindow()
53      show()
54      root.mainloop()
55      return
56      ## End of dotgraph().
57      
58 < def dualgraph(baDot, baLine):
58 > def dualgraph(baDot, baLine, title=""):
59      """Graph data using dots and lines."""
60      global root, fig, ax, canvas  ## Tk/mpl globals.
61      global ba0, ba1, ba2   ## Ref to ba for roilist, dotgraph, linegraph
62 +    global gTitle          ## Title for graph.
63      ba0, ba1, ba2 = baDot, baDot, baLine
64 <    createTkWindow()
64 >    gTitle = title
65 >    createSensorgramTkWindow()
66      show()
67      root.mainloop()
68      return
# Line 65 | Line 72
72      """Graph data of ba using Tk window."""
73      global root, fig, ax, canvas
74      global ba1, ba2
75 +    global gTitle
76      
77      ## Prepare graph labels.
78      ax.clear()
79 <    ax.set_title('SPR Data plotted %s' % date.today().isoformat())
79 >    if (gTitle==""): gTitle='SPR Data plotted %s' % date.today().isoformat()
80 >    ax.set_title(gTitle)
81      ax.set_xlabel('Time (s)')
82      ax.set_ylabel('SPR Response')
83      ax.grid(True)
# Line 139 | Line 148
148      return x[:6]
149  
150  
151 < def createTkWindow():
152 <    ## Create a Tk window for the Matplotlib graph.
151 > def createSensorgramTkWindow():
152 >    """
153 >    Create a Tk window for the Matplotlib graph.
154 >    This window has three buttons which will allow the user to
155 >    """
156      global root, fig, ax, canvas
157      root = Tk.Tk()
158 <    root.wm_title("TK matplotlib Osprai")
158 >    root.wm_title("TK matplotlib Osprai Sensorgram")
159      ## Prepare a matplotlib Figure/Axes.
160      fig = Figure(figsize=(6,4), dpi=100)
161      ax = fig.add_subplot(111)
# Line 165 | Line 177
177      button3 = Tk.Button(master=root, text='Prev6', command=btnPrev)
178      button3.pack(side=Tk.RIGHT)
179      return
180 <    ## End of createTkWindow.
180 >    ## End of createSensorgramTkWindow().
181 >    
182 >    
183 > ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
184 >
185 >
186 > def scatterplot(ba0, t1, t2, t3, t4, title):
187 >    """
188 >    Plot binding changes between (t4-t3) versus (t2-t1).
189 >    Also print the results to the standard output.
190 >    """
191 >     ## Create a Tk window for the ccatterplot graph.
192 >     ## Variables root, fig, ax, canvas are local here, not global.
193 >    root = Tk.Tk()
194 >    root.wm_title("TK matplotlib Osprai Sensorgram")
195 >    ## Prepare a matplotlib Figure/Axes.
196 >    fig = Figure(figsize=(6,4), dpi=100)
197 >    ax = fig.add_subplot(111)
198 >    ax.hold(True)  # Hold data until ax.clear().
199 >    ## Define tk.DrawingArea
200 >    canvas = FigureCanvasTkAgg(fig, master=root)
201 >    canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
202 >    ## Add a pylab-style toolbar.
203 >    toolbar = NavigationToolbar2TkAgg( canvas, root )
204 >    toolbar.update()
205 >    canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
206 >    
207 >    ## Prepare graph labels.
208 >    ax.clear()
209 >    if (title==""): title='Scatterplot of %s' % date.today().isoformat()
210 >    ax.set_title(title)
211 >    ax.set_xlabel('Binding12')
212 >    ax.set_ylabel('Binding34')
213 >    ax.grid(True)
214 >    
215 >    ## Get array of values at each of the four time points.
216 >    y1 = np.array([np.average(iroi.time2val(t1-15, t1+15)) for iroi in ba0.roi])
217 >    y2 = np.array([np.average(iroi.time2val(t2-15, t2+15)) for iroi in ba0.roi])
218 >    y3 = np.array([np.average(iroi.time2val(t3-15, t3+15)) for iroi in ba0.roi])
219 >    y4 = np.array([np.average(iroi.time2val(t4-15, t4+15)) for iroi in ba0.roi])
220 >    dx, dy = (y2-y1), (y4-y3)
221 >    
222 >    ## Print to stdout
223 >    print "Name", "Binding12", "Binding34"
224 >    for i in range(len(dx)): print ba0.roi[i].name, dx[i], dy[i]
225 >    
226 >    ## Plot
227 >    ax.plot(dx, dy, 'bo')  ## Blue circles with 'bo'.
228 >    canvas.draw()
229 >    root.mainloop()
230 >    return
231 >    ## End of scatterplot()
232  
233  
171 ## Run the following lines once upon loading.  Setup Tk.
234   ## Print a message to the users so they see this module is loaded.
235   print "Loaded vu_module.py version ", __version__
236  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines