ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/ba_class.py
(Generate patch)
# Line 18 | Line 18
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 +  >>> print ba1.roi[799].name
22 +  anti-IgG
23 +  >>> ba1 = BiosensorArray(1, 300)
24 +  >>> ba1.roi[0].simulate(bulkRI=1000, kon=1e4, koff=1e-2, conc=1e-6)
25 +  >>> print round(ba1.roi[0].value[299], 2)
26 +  160.64
27   """
28 < __version__ = "110208"
28 > __version__ = "110425"
29  
30  
31   ## Import libraries.
# Line 162 | Line 168
168          """Return list of SPR values between t1 and t2"""
169          dp1, dp2 = self.time2dp(t1), self.time2dp(t2)
170          return [self.value[i] for i in range(dp1, dp2)]
171 +
172 +    def simulate(self, bulkRI=1000, kon=1e4, koff=1e-2, conc=1e-6):
173 +        """
174 +        Fill ROI with simulated data from simple 1:1 binding.
175 +        The following parameters are hard-coded:
176 +          Time 35-65 features jump of bulkRI.
177 +          Time 100-200 has binding using kon, conc.
178 +          Also jump of bulkRI/10.
179 +          Time 200-300 has dissociation using koff.
180 +        The model formulas are:
181 +          alpha = c*kon+koff
182 +          Req = Rmax*c*kon / alpha
183 +          R = Req * [1 - exp(-t*alpha)]
184 +        """
185 +        ## Error checking.
186 +        if (koff <= 0): raise Exception, "Simulation koff must be >0"
187 +        if (kon < 0): raise Exception, "Simulation kon must be >=0"
188 +        if (conc < 0): raise Exception, "Simulation conc must be >=0"
189 +        ## Start with flat line for 300 sec.
190 +        self.time = np.arange(300)
191 +        self.value = np.zeros(300)
192 +        ## Add bulk refractive index jumps.
193 +        self.value[35:65] += bulkRI
194 +        self.value[100:199] += (0.1 * bulkRI)
195 +        ## Add binding.
196 +        rmax = 1000
197 +        alpha = conc * kon + koff
198 +        req = rmax * conc * kon / alpha
199 +        for t in range(100):
200 +             self.value[t+100] += req * (1 - np.exp(-t * alpha))
201 +        ## Add dissociation
202 +        response = req * (1 - np.exp(-100 * alpha))
203 +        for t in range(100):
204 +            self.value[t+200] += response * np.exp(-t * koff)
205 +        return
206      
207      """End of RegOfInterest definition."""
208  
209  
210 < ################################# End of module #################################
210 > def _test():
211 >    """
212 >    Automatic Code testing with doctest.
213 >    Doctest runs the example code in the docstrings.
214 >    Enable use of ellipses as wildcard for returned text.
215 >    """
216 >    import doctest
217 >    doctest.testmod(optionflags=doctest.ELLIPSIS)
218 >
219 >
220 > if __name__ == "__main__":
221 >    """
222 >    Code testing.  
223 >    Simply execute 'python ba_class.py'.
224 >    """
225 >    _test()
226 >
227 >
228 > ########################### End of module ############################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines