ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/ba_class.py
(Generate patch)
# Line 1 | Line 1
1   """
2 < ba: Biosensor Array class for storing SPRI data.
3 < Christopher Lausted, Institute for Systems Biology,
4 < Yuhang Wan, OSPRAI developers
5 < Last modified on 100517 (yymmdd)
6 <
7 < Examples:
8 < #ba1 = BiosensorArray(800,1500)     ## Allocate object with 800 spots of 1500 time points.
9 < #ba1.roi[799].time[1499] = 7502.1   ## Set time in seconds.
10 < #ba1.roi[799].value[1499] = 0.50    ## Set SPR reflectance signal.
11 < #ba1.roi[799].name = "anti-IgG"     ## Set name of microarray feature.
2 > ba_class
3 > --------
4 >
5 > Biosensor Array class for storing SPRI data.
6 > This contains an array of SPR sensorgrams with their
7 > associated models and parameters.
8 > This can also contain the microarray geometery.
9 >
10 > .. moduleauthor:: Christopher Lausted,
11 >                  Institute for Systems Biology,
12 >                  Yuhang Wan,
13 >                  OSPRAI developers.  
14 >                  
15 > Examples::
16 >
17 >  >>> ba1 = BiosensorArray(800,1500)     ## Allocate object with 800 spots of 1500 time points.
18 >  >>> ba1.roi[799].time[1499] = 7502.1   ## Set time in seconds.
19 >  >>> ba1.roi[799].value[1499] = 0.50    ## Set SPR reflectance signal.
20 >  >>> ba1.roi[799].name = "anti-IgG"     ## Set name of microarray feature.
21   """
22 < __version__ = "100517"
22 > __version__ = "110208"
23 >
24  
25   ## Import libraries.
26   import numpy as np
17 #import matplotlib.pyplot as plt
27   from datetime import date
28  
29  
# Line 23 | Line 32
32      The Biosensor Array class holds all ROIs (spots)
33      from an SPRI microarray run.
34      
35 <    Property    Type            Description
36 <    --------    --------------  ---------------------------------------
37 <    roi         list of object  List of RegOfInterest objects.
38 <    rois        integer         Size of roi (Number of ROIs).
39 <    dpoints     integer         Number of datapoints in each ROI.
40 <    primarydatafiles            List of file names.
41 <    comments    list of string  List of comments regarding experiments.
35 >    ================ =============== =======================================
36 >    Property         Type            Description
37 >    ---------------- --------------- ---------------------------------------
38 >    roi              list of object  List of RegOfInterest objects.
39 >    rois             integer         Size of roi (Number of ROIs).
40 >    dpoints          integer         Number of datapoints in each ROI.
41 >    primarydatafiles list of string  List of file names.
42 >    comments         list of string  List of comments regarding experiments.
43 >    ================ =============== =======================================
44      """
45      
46      def __init__(self, roi_size, datapoint_size):
# Line 42 | Line 53
53          ## Use these to keep track of laboratory notes.
54          self.primarydatafiles = [""]  ## Like "spritdata.txt"
55          self.comments = [""]          ## Like "Antibody data from 1 Jan 2010"
56 +        return
57          
58      def xy2uid(self, gx, gy, x, y):
59          """Given roi coordinates, find corresponding uid (index)."""
60          coor1 = (gx, gy, x, y)
61 <        for ob in self.roi:
62 <            coor2 = (ob.gridx, ob.gridy, ob.spotx, ob.spoty)
63 <            if (coor1==coor2): return ob.uid  ## Success.
61 >        for roi in self.roi:
62 >            coor2 = (roi.gridx, roi.gridy, roi.spotx, roi.spoty)
63 >            if (coor1==coor2): return roi.uid  ## Success.
64          return -1  ## Failure.
65          
66      def set_plot_all(self):
67          """Choose to plot every sensorgram."""
68 <        for ob in self.roi: ob.plottable = True
68 >        for roi in self.roi: roi.plottable = True
69 >        return
70          
71      def set_plot_list(self, ilist):
72          """Choose a list of sensorgrams to plot"""
73 <        for ob in self.roi: ob.plottable = False
73 >        for roi in self.roi: roi.plottable = False
74          for i in ilist: self.roi[i].plottable = True
75 <    
76 <    ## A pyplot feature for testing purposes.
77 <    def plot(self):
65 <        """Show plot of the selected sensorgrams."""
66 <        plt.clf()
67 <        plt.title('SPR Data plotted %s' % date.today().isoformat())
68 <        plt.xlabel('Time (s)')
69 <        plt.ylabel('SPR Response')
70 <        plt.grid(True)
71 <        ## Plot traces.
72 <        for ob in self.roi:
73 <            if (ob.plottable==True):
74 <                mylabel = "%i:%s" % (ob.index,ob.name)
75 <                plt.plot(ob.time, ob.value, label=mylabel)
76 <        plt.legend(loc='best')
77 <        plt.show()
78 <    ### End of BiosensorArray class definition.
75 >        return
76 >        
77 >    """End of BiosensorArray class definition."""
78  
79  
80   class RegOfInterest(object):
81      """
82      This Region Of Interest class can hold one SPR sensorgram.
83      
84 +    =========== =============== =============================================
85      Property    Type            Description
86 <    --------    --------------  ---------------------------------------------
86 >    ----------- --------------- ---------------------------------------------
87      uid         integer         Unique ID integer. Never changes.
88      index       integer         Changes if ba size changes (add/remove rois).
89      time        nparray         Usually seconds.
# Line 109 | Line 109
109      flow        float           Flowrate of injection.
110      model       ref to funct    Model describing this ROI.
111      params      dict of dict    Parameters for this model.
112 +    =========== =============== =============================================
113      """
114      
115      def __init__(self, i, datapoint_size):
# Line 162 | Line 163
163          dp1, dp2 = self.time2dp(t1), self.time2dp(t2)
164          return [self.value[i] for i in range(dp1, dp2)]
165      
166 <    ## End of RegOfInterest definition.
166 >    """End of RegOfInterest definition."""
167 >
168  
167 '''
168 ## Here are a few lines to test this class.
169 if __name__ == '__main__':
170    print "Starting demo..."
171    print "Test plotting..."
172    x = BiosensorArray(10,10)
173    x.roi[0].time = np.arange(10)
174    x.roi[0].value = np.arange(10)**2
175    x.roi[1].time = np.arange(10)
176    x.roi[1].value = np.arange(10)**1.5
177    x.roi[9].time = np.arange(10)
178    x.roi[9].value = np.arange(10)**1
179    #x.set_plot_all()
180    x.set_plot_list([0,1,9])
181    x.plot()
182    print "Test xy2uid... 9 =",
183    x.roi[9].gridx = 2
184    print x.xy2uid(2,0,0,0)
185    print "Test time2dp... 5.6 =>",
186    print x.roi[9].time2dp(5.6)
187    print "Demo finished."
188 '''
189    
190    
169   ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines