ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/mdl_module.py
Revision: 22
Committed: Tue Apr 27 07:17:58 2010 UTC (9 years, 2 months ago) by clausted
File size: 3301 byte(s)
Log Message:
The new module osprai_one provides access to the important functions in all of the other modules.  Documentation has been started with osprai_one.html.
Line User Rev File contents
1 clausted 17 """
2     mdl: Example model functions module for SPRI data.
3     Christopher Lausted, Institute for Systems Biology,
4     OSPRAI developers
5 clausted 22 Last modified on 100425 (yymmdd)
6 clausted 17
7 clausted 22 Examples:
8 clausted 17 #import mdl_module as mdl
9 clausted 22 #import numpy as np
10     #times = np.arange(100)
11     #data = np.zeros(100)
12     #
13     #params1 = dict(rate=dict(value=1.0, min=-100.0, max=100.0, fixed=True))
14     #data1 = drift(time, data, param1)
15     #
16     #param2 = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
17     #param2['rmax'] = {'value': 100.0}
18     #param2['conc'] = {'value': 1e-6}
19     #param2['kon'] = {'value': 2e4}
20     #param2['t2'] = {'value': 150.0}
21     #param2['koff'] = {'value': 1e-3}
22     #param2['t3'] = {'value': 270.0}
23     #data2 = simple1to1(time, data, param2)
24 clausted 17 """
25 clausted 22 __version__ = "100425"
26 clausted 17
27    
28     ## Import libraries
29     import numpy as np
30 clausted 18 from copy import deepcopy
31 clausted 17
32    
33 clausted 18 def drift(time, data, params):
34 clausted 17 """
35     This function simply models a constant signal drift in units/second.
36 clausted 18 It requires numpy arrays of times and starting data values,
37 clausted 17 It only requires one parameter in the params list.
38 clausted 18 params['rate']['value']
39 clausted 17 """
40 clausted 18 y = np.zeros(len(time), dtype=float)
41 clausted 17 try:
42 clausted 18 rate = params['rate']['value']
43 clausted 17 except KeyError:
44     print "Error: Rate parameter not supplied to drift() model."
45 clausted 18 return y
46 clausted 17
47 clausted 18 ## Numerical integration.
48     y[0] = data[0]
49     for i in range(1,len(time)):
50     dy = rate * (time[i]-time[i-1])
51     y[i] = y[i-1] + dy
52    
53     return y
54 clausted 19 ## End of drift() function.
55 clausted 18
56    
57     def simple1to1(time, data, params):
58     """
59     This function simply models a 1:1 interaction
60     It requires numpy arrays of times and starting data values,
61     params['t1']['value'] is time of injection for binding
62     params['rmax']['value'] is maximum response.
63     params['conc']['value'] is time of concentration of analyte
64     params['kon']['value'] is on-rate of analyte
65     params['t2']['value'] is time of end binding / begin washing
66     params['koff']['value'] is off-rate of analyte
67     params['t3']['value'] is time end of washing / data fitting.
68     """
69     ## Skip parameter validation steps for now.
70     t1 = params['t1']['value']
71     rmax = params['rmax']['value']
72     conc = params['conc']['value']
73     kon = params['kon']['value']
74     t2 = params['t2']['value']
75     koff = params['koff']['value']
76     t3 = params['t3']['value']
77 clausted 17
78 clausted 18 y = np.zeros(len(time), dtype=float)
79     base = y[0] = data[0] ## Baseline SPR signal.
80    
81     ## Must iterate through data, numerical integration.
82     for i in range(1,len(time)):
83     if (time[i] <= t1):
84     ## Pre-binding phase.
85     base = y[i] = data[i]
86     elif (t1 < time[i] <= t2):
87     ## Binding phase
88     yb = y[i-1] - base
89     dy = conc*kon*(rmax-yb) - koff*yb
90     if (abs(y[i-1]) > 999999999): dy = 0 ## Is this useful?
91     y[i] = y[i-1] + dy * (time[i] - time[i-1])
92     elif (t2 < time[i] <= t3):
93     ## Dissociation
94     yb = y[i-1]-base
95     dy = 0 - koff*yb
96     y[i] = y[i-1] + dy * (time[i] - time[i-1])
97    
98     return y
99 clausted 19 ## End of simple1to1() function
100 clausted 18
101 clausted 19
102     ################################# End of module #################################