ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/test.py
Revision: 29
Committed: Thu May 20 01:14:55 2010 UTC (9 years ago) by clausted
File size: 5417 byte(s)
Log Message:
Add a parameter ('cofa') to the 1to1 models that represents a concentration factor.  This allows for easier analysis of a dilution series.  For example, if two ROIs contain data for the same sample but at a dilutions of 1:2 and 1:4, the set 'conc' value to the molar stock concentration and set the two 'cofa' values to 0.5 and 0.25.
Line User Rev File contents
1 clausted 7 """
2     Christopher Lausted, Institute for Systems Biology
3 clausted 29 Last modified on 100519 (yymmdd)
4 clausted 27 Scripts to test various OSPRAI components.
5 clausted 7 """
6    
7 clausted 23 ## Import libaries
8     import ba_class
9     import vu_module
10     import io_module
11     import cal_module
12     import mdl_module
13     import fit_module
14 clausted 26 import osprai_one
15 clausted 19 ## Reload Osprai libraries in case code has changed.
16 clausted 23 reload(ba_class)
17     reload (vu_module)
18     reload(io_module)
19     reload(cal_module)
20     reload(mdl_module)
21     reload(fit_module)
22 clausted 26 reload(osprai_one)
23 clausted 23 ## Or just import this next one...
24     from osprai_one import *
25 clausted 7
26 clausted 23
27 clausted 27 def test_io_module():
28     print "Loading SPR data files..."
29     ba1 = readbiosensor("example-biosensor.txt")
30     ba1 = readicmtxt("example-icm.txt")
31     ba1 = readsprit("example-sprit.txt")
32     ba1 = applykey(ba1, "example-key.tsv")
33     print "Writing SPR data files..."
34     writesprit(ba1,"testwritesprit.txt")
35     writeclamp(ba1,"testwriteclamp.txt")
36     writebiosensor(ba1, "testwritebiosensor.txt")
37     print "Done with test_io_module."
38 clausted 29 return
39 clausted 27
40     def test_cal_module_vu_module():
41     print "Loading an SPR data file..."
42     ba1 = readicmtxt("example-icm.txt")
43    
44     print "Plotting the raw data file..."
45     dotgraph(ba1)
46    
47     print "Plotting the calibrated data..."
48     ba2 = calibrate(ba1, ba1, 2850, 3120)
49     linegraph(ba2, "Calibrated SPR Data")
50     dualgraph(ba1, ba2, "Uncalibrated and Calibrated SPR Data")
51    
52     print "Use ROI #16 as background, subtract, and plot..."
53     bgset(ba2, 16)
54     ba3 = bgsubt(ba2)
55     linegraph(ba3, "Calibrated Referenced SPR Data")
56    
57     print "Test of scatterplot using time points 500, 1000, 1500, 2000"
58     scatterplot(ba3, 3600, 4200, 3600, 4700, "Scatterplot")
59    
60     print "Cutting out an interval..."
61     ba3 = copyinterval(ba3, 2800, 6200)
62     linegraph(ba3)
63     print "Done with test test_cal_module_vu_module."
64 clausted 29 return
65 clausted 19
66 clausted 24
67 clausted 27 def test_mdl_module_fit_module():
68     print "Test the model module..."
69 clausted 29 ## Set some default parameters.
70     dpar = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':'fixed'} }
71     dpar['rmax'] = {'value':100.0, 'min':1.0, 'max':1000.0, 'fixed':'fixed'}
72     dpar['conc'] = {'value':1e-5, 'min':1e-12, 'max':1e1, 'fixed':'fixed'}
73     dpar['cofa'] = {'value':1.0, 'min':1e-10, 'max':1e10, 'fixed':'fixed'}
74     dpar['kon'] = {'value':2e4, 'min':1e1, 'max':1e8, 'fixed':'fixed'}
75     dpar['t2'] = {'value':150.0, 'min':10.0, 'max':1000.0, 'fixed':'fixed'}
76     dpar['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':'fixed'}
77     dpar['t3'] = {'value':270.0, 'min':270.0, 'max':270.0, 'fixed':'fixed'}
78     ## Create ba with three ROIs and 300 datapoints.
79     ba0 = BiosensorArray(3,300)
80     for roi in ba0.roi:
81     roi.time = arange(300, dtype=float) ## Samples every 1 second.
82     roi.value = zeros(300, dtype=float) + 20 ## Baseline signal is 20 units.
83     roi.params = deepcopy(dpar)
84     roi.model = simple1to1
85     ## Set the dilution factors
86     ba0.roi[0].params['cofa']['value'] = 1.0 / 27
87     ba0.roi[1].params['cofa']['value'] = 1.0 / 9
88     ba0.roi[2].params['cofa']['value'] = 1.0 / 3
89     ## Simulate the data and plot it.
90     for roi in ba0.roi:
91     roi.value = roi.model(roi.time, roi.value, roi.params)
92 clausted 27 linegraph(ba0, "Simulation")
93    
94 clausted 29 ## Constrain rmax belowtrue value to show what happens.
95 clausted 27 print "Testing the fitting..."
96     ba1 = deepcopy(ba0)
97 clausted 29 ## Set one kon, koff, rmax to float.
98     ba1.roi[0].params['koff']['fixed'] = 'float'
99     ba1.roi[0].params['kon']['fixed'] = 'float'
100     ba1.roi[0].params['rmax'] = {'value':10.0, 'min':1.0, 'max':80.0, 'fixed':'float'}
101     ba1.roi[1].params['koff']['fixed'] = 0
102     ba1.roi[1].params['kon']['fixed'] = 0
103     ba1.roi[1].params['rmax']['fixed'] = 0
104     ba1.roi[2].params['koff']['fixed'] = 0
105     ba1.roi[2].params['kon']['fixed'] = 0
106     ba1.roi[2].params['rmax']['fixed'] = 0
107 clausted 28 ## Fit and then plot.
108 clausted 29 mclma(ba1.roi)
109 clausted 28 for roi in ba1.roi:
110     roi.value =roi.model(roi.time, roi.value, roi.params)
111 clausted 29 dualgraph(ba0, ba1, "Fitted Data with an incorrect rmax constraint")
112 clausted 27 print "Done with test test_mdl_module_fit_module."
113 clausted 29 return
114 clausted 27
115 clausted 19
116 clausted 27 def demo_mtl():
117     print "Test the model module..."
118     ba0 = BiosensorArray(1,300) ## Create ba1 with one ROI and 300 datapoints.
119     roi0 = ba0.roi[0]
120     roi0.time = arange(300, dtype=float) ## Samples every 1 second.
121     roi0.value = zeros(300, dtype=float) + 20 ## Baseline signal is 20 units.
122     roi0.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
123     roi0.params['rmax'] = {'value': 100.0}
124     roi0.params['conc'] = {'value': 1e-6}
125     roi0.params['kon'] = {'value': 5e4}
126     roi0.params['t2'] = {'value': 150.0}
127     roi0.params['koff'] = {'value': 5e-3}
128     roi0.params['t3'] = {'value': 270.0}
129     roi0.params['kmtl'] = {'value': 2e6}
130     roi0.name = "kmtl=2e6"
131     roi0.model = simple1to1_mtl
132     roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
133    
134     ba1 = deepcopy(ba0)
135     roi0 = ba1.roi[0]
136     roi0.name = "No MTL"
137     roi0.model = simple1to1
138     roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
139     dualgraph(ba0, ba1, "With and without MTL")
140     print "Done with test demo_mtl."
141 clausted 19
142 clausted 7
143 clausted 27 ## Run selected test or tests.
144     #test_io_module()
145     #test_cal_module_vu_module()
146     #demo_mtl()
147     test_mdl_module_fit_module()