ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/test.py
(Generate patch)
# Line 1 | Line 1
1   """
2   Christopher Lausted, Institute for Systems Biology
3 < Last modified on 100408 (yymmdd)
4 < Small script to test ba_class, io_module, etc.
3 > Last modified on 100518 (yymmdd)
4 > Scripts to test various OSPRAI components.
5   """
6  
7 < ## Import modules.
8 < import vu_module as vu
9 < import io_module as io
10 < import cal_module as cal
11 < ## Reload in case code has changed.
12 < reload (vu)
13 < reload(io)
14 < reload(cal)
15 <
16 < #ba1 = io.readbiosensor("example-biosensor.txt")
17 < ba1 = io.readicmtxt("example-icm.txt")
18 < #ba1 = io.readsprit("example-sprit.txt")
19 < #ba1 = io.applykey(ba1, "example-key.tsv")
20 < #ba1.set_plot_all()
21 < #ba1.set_plot_list(range(6))
22 < #ba1.plot()
23 <
24 < #io.writesprit(ba1,"testwritesprit.txt")
25 < #io.writeclamp(ba1,"testwriteclamp.txt")
26 < #io.writebiosensor(ba1, "testwritebiosensor.txt")
27 <
28 < vu.linegraph(ba1)
29 < #vu.dotgraph(ba1)
30 < #vu.dualgraph(ba1, ba1)
31 <
32 < ba2 = cal.calibrate(ba1, ba1, 1950, 2025)
33 < vu.linegraph(ba2)
34 <
35 < input("Done with test. Press any key")
7 > ## 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 > import osprai_one
15 > ## Reload Osprai libraries in case code has changed.
16 > reload(ba_class)
17 > reload (vu_module)
18 > reload(io_module)
19 > reload(cal_module)
20 > reload(mdl_module)
21 > reload(fit_module)
22 > reload(osprai_one)
23 > ## Or just import this next one...
24 > from osprai_one import *
25 >
26 >
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 >    
39 >    
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 >
65 >
66 > def test_mdl_module_fit_module():
67 >    print "Test the model module..."
68 >    ## Create ba with two ROIs and 300 datapoints.
69 >    ba0 = BiosensorArray(2,300)  
70 >    ## First ROI.
71 >    roi = ba0.roi[0]
72 >    roi.time = arange(300, dtype=float)  ## Samples every 1 second.
73 >    roi.value = zeros(300, dtype=float) + 20  ## Baseline signal is 20 units.
74 >    roi.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':'fixed'} }
75 >    roi.params['rmax'] =  {'value': 100.0}
76 >    roi.params['conc'] =  {'value': 1e-6}
77 >    roi.params['kon'] =   {'value': 2e4}
78 >    roi.params['t2'] =    {'value': 150.0}
79 >    roi.params['koff'] =  {'value': 1e-3}
80 >    roi.params['t3'] =    {'value': 270.0}
81 >    roi.model = simple1to1
82 >    roi.value =roi.model(roi.time, roi.value, roi.params)
83 >    ## Second ROI
84 >    roi = ba0.roi[1]
85 >    roi.time = arange(300, dtype=float)  
86 >    roi.value = zeros(300, dtype=float) + 20
87 >    roi.params = deepcopy(ba0.roi[0].params)
88 >    roi.params['rmax'] = {'value': 50}
89 >    roi.model = simple1to1
90 >    roi.value = roi.model(roi.time, roi.value, roi.params)
91 >    linegraph(ba0, "Simulation")
92 >    
93 >    ## Constrain rmax away from 100 to show what happens.
94 >    print "Testing the fitting..."
95 >    ba1 = deepcopy(ba0)
96 >    ## Make rmax too high.
97 >    ba1.roi[0].params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':'float'}
98 >    ba1.roi[0].params['kon'] =  {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':'float'}
99 >    ba1.roi[0].params['rmax'] =  {'value':150, 'min':110, 'max':190, 'fixed':'float'}
100 >    ## Make rmax too low.  Tie koff and kon to other ROI.
101 >    ba1.roi[1].params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':0}
102 >    ba1.roi[1].params['kon'] =  {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':0}
103 >    ba1.roi[1].params['rmax'] =  {'value':20, 'min':10, 'max':40, 'fixed':'float'}
104 >    ## Fit and then plot.
105 >    mclma([ba1.roi[0], ba1.roi[1]])
106 >    for roi in ba1.roi:
107 >        roi.value =roi.model(roi.time, roi.value, roi.params)
108 >    dualgraph(ba0, ba1, "Fitted Data with an incorrect Rmax parameter")
109 >    print "Done with test test_mdl_module_fit_module."
110 >    
111 >
112 > def demo_mtl():
113 >    print "Test the model module..."
114 >    ba0 = BiosensorArray(1,300)  ## Create ba1 with one ROI and 300 datapoints.
115 >    roi0 = ba0.roi[0]
116 >    roi0.time = arange(300, dtype=float)  ## Samples every 1 second.
117 >    roi0.value = zeros(300, dtype=float) + 20  ## Baseline signal is 20 units.
118 >    roi0.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
119 >    roi0.params['rmax'] =  {'value': 100.0}
120 >    roi0.params['conc'] =  {'value': 1e-6}
121 >    roi0.params['kon'] =   {'value': 5e4}
122 >    roi0.params['t2'] =    {'value': 150.0}
123 >    roi0.params['koff'] =  {'value': 5e-3}
124 >    roi0.params['t3'] =    {'value': 270.0}
125 >    roi0.params['kmtl'] =  {'value': 2e6}
126 >    roi0.name = "kmtl=2e6"
127 >    roi0.model = simple1to1_mtl
128 >    roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
129 >    
130 >    ba1 = deepcopy(ba0)
131 >    roi0 = ba1.roi[0]
132 >    roi0.name = "No MTL"
133 >    roi0.model = simple1to1
134 >    roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
135 >    dualgraph(ba0, ba1, "With and without MTL")
136 >    print "Done with test demo_mtl."
137 >
138 >
139 > ## Run selected test or tests.
140 > #test_io_module()
141 > #test_cal_module_vu_module()
142 > #demo_mtl()
143 > test_mdl_module_fit_module()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines