ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/ba_class.py
(Generate patch)
# Line 2 | Line 2
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 100412 (yymmdd)
5 > Last modified on 100517 (yymmdd)
6  
7   Examples:
8   #ba1 = BiosensorArray(800,1500)     ## Allocate object with 800 spots of 1500 time points.
# Line 10 | Line 10
10   #ba1.roi[799].value[1499] = 0.50    ## Set SPR reflectance signal.
11   #ba1.roi[799].name = "anti-IgG"     ## Set name of microarray feature.
12   """
13 < __version__ = "100412"
13 > __version__ = "100517"
14  
15   ## Import libraries.
16   import numpy as np
17 < import matplotlib.pyplot as plt
17 > #import matplotlib.pyplot as plt
18   from datetime import date
19  
20  
21   class BiosensorArray(object):
22 <    """The Biosensor Array class holds all ROIs/spots from an SPRI microarray run."""
22 >    """
23 >    The Biosensor Array class holds all ROIs (spots)
24 >    from an SPRI microarray run.
25 >    
26 >    Property    Type            Description
27 >    --------    --------------  ---------------------------------------
28 >    roi         list of object  List of RegOfInterest objects.
29 >    rois        integer         Size of roi (Number of ROIs).
30 >    dpoints     integer         Number of datapoints in each ROI.
31 >    primarydatafiles            List of file names.
32 >    comments    list of string  List of comments regarding experiments.
33 >    """
34 >    
35      def __init__(self, roi_size, datapoint_size):
36          """This object is dimensioned upon initialization.""" ## Might improve speed.
37          ## Use a list comprehension to dimension list of classes.
# Line 67 | Line 79
79  
80  
81   class RegOfInterest(object):
82 <    """This Region Of Interest class can hold one SPR sensorgram."""
82 >    """
83 >    This Region Of Interest class can hold one SPR sensorgram.
84 >    
85 >    Property    Type            Description
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.
90 >    value       nparray         Arbitrary units.
91 >    dpoints     integer         Can use for bounds checking.
92 >    name        string          Name of ROI.
93 >    desc        string          Description of ROI
94 >    
95 >    gridx       integer         Can be Block number from GAL file.  
96 >    gridy       integer         Unused?
97 >    spotx       integer         ROI column number.
98 >    spoty       integer         ROI row number.
99 >    bgroi       list of integer One or more background ROIs.
100 >    calibM      float           Slope used for calibration
101 >    calibB      float           Intercept used for calibration.
102 >    plottable   boolean         Whether to plot
103 >    
104 >    injconc     list of float   One or more analyte concentrations.
105 >    injstart    list of float   One or more injection start times.
106 >    injstop     list of float   One or more injection start times.
107 >    injrind     list of float   One or more expected refractive index jumps.
108 >    
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      def __init__(self, i, datapoint_size):
115          """
116          Each ROI in a list needs a unique ID number which will be i+1.
# Line 95 | Line 138
138          self.injstop = [0.0]     ## One or more injection start times.
139          self.injrind = [0.0]     ## One or more expected refractive index jumps.
140          self.flow = 0            ## Flowrate of injection.
141 +        ## Curve fitting information.  Model and model parameters.
142 +        ## Example model is reference to function like data=simple1to1(times,params)
143 +        ## Example params = {'Rmax': {'value':1, 'min':0, 'max':10, 'fixed':False} }
144 +        self.model = None    ## Model describing this roi. Reference to a function.
145 +        self.params = []     ## Parameters for this model. A dictionary of dictionaries.
146          
147      def time2dp(self, t):
148          """Find datapoint closest to given time."""
149 <        pos2 = self.time.searchsorted(t)  ## Time point just after t.
150 <        pos1 = max(pos2-1,0)
151 <        #TEMP! There is a bug here.
104 <        print pos1, pos2
149 >        pos2 = self.time.searchsorted(t)    ## Time point just after t.
150 >        pos2 = min(pos2, len(self.time)-1)  ## Avoid indexing error.
151 >        pos1 = max(pos2-1,0)                ## Time point just before t.
152          t2 = abs(self.time[pos2] - t)
153          t1 = abs(self.time[pos1] - t)
154 +        ## Decide if time point just before or just after is closer.
155          if (t2<t1):
156              return pos2
157          else:
# Line 112 | Line 160
160      def time2val(self, t1, t2):
161          """Return list of SPR values between t1 and t2"""
162          dp1, dp2 = self.time2dp(t1), self.time2dp(t2)
163 <        return [self.value(i) for i in range(dp1, dp2)]
163 >        return [self.value[i] for i in range(dp1, dp2)]
164      
165      ## End of RegOfInterest definition.
166  
167 <
167 > '''
168   ## Here are a few lines to test this class.
169   if __name__ == '__main__':
170      print "Starting demo..."
# Line 137 | Line 185
185      print "Test time2dp... 5.6 =>",
186      print x.roi[9].time2dp(5.6)
187      print "Demo finished."
188 + '''
189      
190      
191   ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines