ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/mdl_module.py
(Generate patch)
# Line 2 | Line 2
2   mdl: Example model functions module for SPRI data.
3   Christopher Lausted, Institute for Systems Biology,
4   OSPRAI developers
5 < Last modified on 100421 (yymmdd)
5 > Last modified on 100423 (yymmdd)
6  
7   Example:
8   #import mdl_module as mdl
9 < #params = {'Rate': {'value':1, 'min':-100.0, 'max':100.0, 'fixed':False} }
10 < #params = dict(Rate = dict(value=1, min=0, max=10, fixed=False))
9 > #params = {'rate': {'value':1, 'min':-100.0, 'max':100.0, 'fixed':False} }
10 > #params = dict(rate = dict(value=1, min=0, max=10, fixed=False))
11   #times = range(100)
12   #data1 = drift(time, data0, params)
13   print data1
14   """
15 < __version__ = "100421"
15 > __version__ = "100423"
16  
17  
18   ## Import libraries
19   import numpy as np
20 < #import ba_class as ba
21 < #from copy import deepcopy
20 > from copy import deepcopy
21  
22  
23 < def drift(time, data0, params):
23 > def drift(time, data, params):
24      """
25      This function simply models a constant signal drift in units/second.
26 <    It requires numpys array of times and starting data values,
26 >    It requires numpy arrays of times and starting data values,
27      It only requires one parameter in the params list.
28 <    params['Rate']['value']
28 >    params['rate']['value']
29      """
30 <    data1 = np.zeros(len(times))
30 >    y = np.zeros(len(time), dtype=float)
31      try:
32 <        rate = params['Rate']['value']
32 >        rate = params['rate']['value']
33      except KeyError:
34          print "Error: Rate parameter not supplied to drift() model."
35 <        return data1
35 >        return y
36      
37 <    ## ToDo: Finish this code.
37 >    ## Numerical integration.
38 >    y[0] = data[0]
39 >    for i in range(1,len(time)):
40 >        dy = rate * (time[i]-time[i-1])
41 >        y[i] = y[i-1] + dy
42 >        
43 >    return y
44 >    ## End of drift() function.
45 >
46 >
47 > def simple1to1(time, data, params):
48 >    """
49 >    This function simply models a 1:1 interaction
50 >    It requires numpy arrays of times and starting data values,
51 >    params['t1']['value']   is time of injection for binding
52 >    params['rmax']['value'] is maximum response.
53 >    params['conc']['value'] is time of concentration of analyte
54 >    params['kon']['value']  is on-rate of analyte
55 >    params['t2']['value']   is time of end binding / begin washing
56 >    params['koff']['value']  is off-rate of analyte
57 >    params['t3']['value']   is time end of washing / data fitting.
58 >    """
59 >    ## Skip parameter validation steps for now.
60 >    t1 = params['t1']['value']
61 >    rmax = params['rmax']['value']
62 >    conc = params['conc']['value']
63 >    kon = params['kon']['value']
64 >    t2 = params['t2']['value']
65 >    koff = params['koff']['value']
66 >    t3 = params['t3']['value']
67      
40    return data1
68 +    y = np.zeros(len(time), dtype=float)
69 +    base = y[0] = data[0]  ## Baseline SPR signal.
70 +    
71 +    ## Must iterate through data, numerical integration.
72 +    for i in range(1,len(time)):
73 +        if (time[i] <= t1):
74 +            ## Pre-binding phase.
75 +            base = y[i] = data[i]
76 +        elif (t1 < time[i] <= t2):
77 +            ## Binding phase
78 +            yb = y[i-1] - base
79 +            dy = conc*kon*(rmax-yb) - koff*yb
80 +            if (abs(y[i-1]) > 999999999): dy = 0  ## Is this useful?
81 +            y[i] = y[i-1] + dy * (time[i] - time[i-1])
82 +        elif (t2 < time[i] <= t3):
83 +            ## Dissociation
84 +            yb = y[i-1]-base
85 +            dy = 0 - koff*yb
86 +            y[i] = y[i-1] + dy * (time[i] - time[i-1])
87 +            
88 +    return y
89 +    ## End of simple1to1() function
90 +
91 +
92 + ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines