ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/mdl_module.py
Revision: 18
Committed: Thu Apr 22 07:36:31 2010 UTC (9 years, 6 months ago) by clausted
File size: 2843 byte(s)
Log Message:
Add a simple 1to1 model function.
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     Last modified on 100421 (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))
11     #times = range(100)
12     #data1 = drift(time, data0, params)
13     print data1
14     """
15     __version__ = "100421"
16    
17    
18     ## Import libraries
19     import numpy as np
20 clausted 18 from copy import deepcopy
21 clausted 17
22    
23 clausted 18 def drift(time, data, params):
24 clausted 17 """
25     This function simply models a constant signal drift in units/second.
26 clausted 18 It requires numpy arrays of times and starting data values,
27 clausted 17 It only requires one parameter in the params list.
28 clausted 18 params['rate']['value']
29 clausted 17 """
30 clausted 18 y = np.zeros(len(time), dtype=float)
31 clausted 17 try:
32 clausted 18 rate = params['rate']['value']
33 clausted 17 except KeyError:
34     print "Error: Rate parameter not supplied to drift() model."
35 clausted 18 return y
36 clausted 17
37 clausted 18 ## 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    
45    
46     def simple1to1(time, data, params):
47     """
48     This function simply models a 1:1 interaction
49     It requires numpy arrays of times and starting data values,
50     params['t1']['value'] is time of injection for binding
51     params['rmax']['value'] is maximum response.
52     params['conc']['value'] is time of concentration of analyte
53     params['kon']['value'] is on-rate of analyte
54     params['t2']['value'] is time of end binding / begin washing
55     params['koff']['value'] is off-rate of analyte
56     params['t3']['value'] is time end of washing / data fitting.
57     """
58     ## Skip parameter validation steps for now.
59     t1 = params['t1']['value']
60     rmax = params['rmax']['value']
61     conc = params['conc']['value']
62     kon = params['kon']['value']
63     t2 = params['t2']['value']
64     koff = params['koff']['value']
65     t3 = params['t3']['value']
66 clausted 17
67 clausted 18 y = np.zeros(len(time), dtype=float)
68     base = y[0] = data[0] ## Baseline SPR signal.
69    
70     ## Must iterate through data, numerical integration.
71     for i in range(1,len(time)):
72     if (time[i] <= t1):
73     ## Pre-binding phase.
74     base = y[i] = data[i]
75     elif (t1 < time[i] <= t2):
76     ## Binding phase
77     yb = y[i-1] - base
78     dy = conc*kon*(rmax-yb) - koff*yb
79     if (abs(y[i-1]) > 999999999): dy = 0 ## Is this useful?
80     y[i] = y[i-1] + dy * (time[i] - time[i-1])
81     elif (t2 < time[i] <= t3):
82     ## Dissociation
83     yb = y[i-1]-base
84     dy = 0 - koff*yb
85     y[i] = y[i-1] + dy * (time[i] - time[i-1])
86    
87     return y
88