ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/mdl_module.py
Revision: 20
Committed: Mon Apr 26 21:59:45 2010 UTC (9 years, 1 month ago) by clausted
File size: 2996 byte(s)
Log Message:
Added clma(), a constrained LMA fitting function.  We can now set a lower and upper bound for fitting.  Be sure that the initial estimate is between, not at, the bounds.  It transforms the parameters using x1 = ((b-a)*tanh(x0)+b+a)/2 for the interval (a,b).  
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 20 Last modified on 100423 (yymmdd)
6 clausted 17
7     Example:
8     #import mdl_module as mdl
9 clausted 19 #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 clausted 17 #times = range(100)
12     #data1 = drift(time, data0, params)
13     print data1
14     """
15 clausted 20 __version__ = "100423"
16 clausted 17
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 clausted 19 ## End of drift() function.
45 clausted 18
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 clausted 17
68 clausted 18 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 clausted 19 ## End of simple1to1() function
90 clausted 18
91 clausted 19
92     ################################# End of module #################################