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 < Last modified on 100408 (yymmdd)
3 > Christopher Lausted, Institute for Systems Biology,
4 > Yuhang Wan, OSPRAI developers
5 > Last modified on 100421 (yymmdd)
6  
7   Examples:
8   #ba1 = BiosensorArray(800,1500)     ## Allocate object with 800 spots of 1500 time points.
# Line 9 | 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__ = "100408"
13 > __version__ = "100421"
14  
15   ## Import libraries.
16   import numpy as np
# Line 94 | Line 95
95          self.injstop = [0.0]     ## One or more injection start times.
96          self.injrind = [0.0]     ## One or more expected refractive index jumps.
97          self.flow = 0            ## Flowrate of injection.
98 +        ## Curve fitting information.  Model and model parameters.
99 +        ## Example model is reference to function like data=simple1to1(times,params)
100 +        ## Example params = {'Rmax': {'value':1, 'min':0, 'max':10, 'fixed':False} }
101 +        self.model = None    ## Model describing this roi. Reference to a function.
102 +        self.params = []     ## Parameters for this model. A dictionary of dictionaries.
103          
104      def time2dp(self, t):
105          """Find datapoint closest to given time."""
106 <        pos2 = self.time.searchsorted(t)  ## Time point just after t.
107 <        pos1 = max(pos2-1,0)
106 >        pos2 = self.time.searchsorted(t)    ## Time point just after t.
107 >        pos2 = min(pos2, len(self.time)-1)  ## Avoid indexing error.
108 >        pos1 = max(pos2-1,0)                ## Time point just before t.
109          t2 = abs(self.time[pos2] - t)
110          t1 = abs(self.time[pos1] - t)
111 +        ## Decide if time point just before or just after is closer.
112          if (t2<t1):
113              return pos2
114          else:
115              return pos1
116 <        
116 >            
117 >    def time2val(self, t1, t2):
118 >        """Return list of SPR values between t1 and t2"""
119 >        dp1, dp2 = self.time2dp(t1), self.time2dp(t2)
120 >        return [self.value[i] for i in range(dp1, dp2)]
121 >    
122      ## End of RegOfInterest definition.
123  
124  
# Line 131 | Line 144
144      print "Demo finished."
145      
146      
134 ################################# End of module #################################
135 """
136 class classSprArray:
137    time = np.zeros(0, dtype=float)  # 0,5,10...seconds.
138    sproi = []  # List of classSprRoi objects.
139    _calibrated = False  # Private variable.
140    _bgsubtracted = False  # Private variable.
141    
142    ## Apply calibration factors to all data.
143    def calibrate(self):
144        self._calibrated = True
145        for i in self.sproi:
146            i.oldvalue = i.value.copy()
147            i.value = i.value * i.calibM + i.calibB
148    def calibrated(self):
149        return self._calibrated
150        
151    ## Apply background subtraction
152    def bgsubtract(self):
153        self._bgsubtracted = True
154        for i in self.sproi:
155            i.oldvalue = i.value.copy()
156        for i in self.sproi:
157            if (i.bgroi<=len(self.sproi)):
158                i.value = i.value - self.sproi[i.bgroi].oldvalue
159            else:
160                print "Index out of range in classSprArray"
161    def bgsubtracted(self):
162        return self._bgsubtracted
163        
164    def addsproi(self):
165        newroi = classSprRoi()
166        self.sproi.append(newroi)
167
168    ## End classSprArray definition.
169
170 Unused examples:
171
172 class Person(object):
173    def get_full_name(self):
174        return "%s %s" % (self.first_name, self.last_name)
175    def set_full_name(self, full_name):
176        self.first_name, self.last_name = full_name.split()
177    full_name = property(get_full_name, set_full_name)
178
179 class Example(object):
180    def __init__(self):
181        self.data = []
182    
183    @property
184    def something(self):
185        return whatever
186
187 """
147 + ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines