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 100425 (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 numpy as np
9 < import ba_class as ba
10 < import vu_module as vu
11 < import io_module as io
12 < import cal_module as cal
13 < import mdl_module as mdl
14 < import fit_module as fit
15 < from sys import exit
16 < from copy import deepcopy
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)
17 < reload (vu)
18 < reload(io)
19 < reload(cal)
20 < reload(mdl)
21 < reload(fit)
22 <
23 < print "Test the model module..."
24 < ba0 = ba.BiosensorArray(1,300)  ## Create ba1 with one ROI and 300 datapoints.
25 < roi0 = ba0.roi[0]
26 < roi0.time = np.arange(300, dtype=float)  ## Samples every 1 second.
27 < roi0.value = np.zeros(300, dtype=float) + 20  ## Baseline signal is 20 units.
28 < roi0.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
29 < roi0.params['rmax'] =  {'value': 100.0}
30 < roi0.params['conc'] =  {'value': 1e-6}
31 < roi0.params['kon'] =   {'value': 2e4}
32 < roi0.params['t2'] =    {'value': 150.0}
33 < roi0.params['koff'] =  {'value': 1e-3}
34 < roi0.params['t3'] =    {'value': 270.0}
35 < roi0.model = mdl.simple1to1
36 < roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
37 < vu.linegraph(ba0, "Simulation")
38 <
39 < print "Testing the fitting..."
40 < ba1 = deepcopy(ba0)
41 < roi0 = ba1.roi[0]
42 < roi0.params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':False}
43 < roi0.params['kon'] =  {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':False}
44 < roi0.params['rmax'] =  {'value':50, 'min':1, 'max':90, 'fixed':False}
45 < fit.clma(roi0)
46 < roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
47 < vu.dualgraph(ba0, ba1, "Fitted Data with an incorrect Rmax parameter")
48 < exit()
49 <
50 <
51 < print "Loading an SPR data file..."
52 < #ba1 = io.readbiosensor("example-biosensor.txt")
53 < ba1 = io.readicmtxt("example-icm.txt")
54 < #ba1 = io.readsprit("example-sprit.txt")
55 < #ba1 = io.applykey(ba1, "example-key.tsv")
56 < #ba1.set_plot_all()
57 < #ba1.set_plot_list(range(6))
58 < #ba1.plot()
59 <
60 < #io.writesprit(ba1,"testwritesprit.txt")
61 < #io.writeclamp(ba1,"testwriteclamp.txt")
62 < #io.writebiosensor(ba1, "testwritebiosensor.txt")
63 <
64 < print "Plotting the raw data file..."
65 < vu.linegraph(ba1)
66 < #vu.dotgraph(ba1)
67 < #vu.dualgraph(ba1, ba1)
68 <
69 < print "Plotting the calibrated data..."
70 < ba2 = cal.calibrate(ba1, ba1, 2850, 3120)
71 < vu.linegraph(ba2, "Calibrated SPR Data")
72 <
73 < print "Use ROI #16 as background, subtract, and plot..."
74 < cal.bgset(ba2, 16)
75 < ba2 = cal.bgsubt(ba2)
76 < vu.linegraph(ba2, "Calibrated & Referenced SPR Data")
77 <
78 < print "Test of scatterplot using time points 500, 1000, 1500, 2000"
79 < vu.scatterplot(ba2, 3600, 4200, 3600, 4700, "Scatterplot")
80 <
81 < print "Done with test."
82 < #input("Done with test. Press any key")
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 >    ba0 = BiosensorArray(1,300)  ## Create ba with one ROI and 300 datapoints.
69 >    roi0 = ba0.roi[0]
70 >    roi0.time = arange(300, dtype=float)  ## Samples every 1 second.
71 >    roi0.value = zeros(300, dtype=float) + 20  ## Baseline signal is 20 units.
72 >    roi0.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
73 >    roi0.params['rmax'] =  {'value': 100.0}
74 >    roi0.params['conc'] =  {'value': 1e-6}
75 >    roi0.params['kon'] =   {'value': 2e4}
76 >    roi0.params['t2'] =    {'value': 150.0}
77 >    roi0.params['koff'] =  {'value': 1e-3}
78 >    roi0.params['t3'] =    {'value': 270.0}
79 >    roi0.model = simple1to1
80 >    roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
81 >    linegraph(ba0, "Simulation")
82 >    
83 >    ## Constrain rmax<80 when it really is 100 to show what happens.
84 >    print "Testing the fitting..."
85 >    ba1 = deepcopy(ba0)
86 >    roi0 = ba1.roi[0]
87 >    roi0.params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':False}
88 >    roi0.params['kon'] =  {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':False}
89 >    roi0.params['rmax'] =  {'value':150, 'min':120, 'max':190, 'fixed':False}
90 >    mclma([roi0])
91 >    roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
92 >    dualgraph(ba0, ba1, "Fitted Data with an incorrect Rmax parameter")
93 >    print "Done with test test_mdl_module_fit_module."
94 >    
95 >
96 > def demo_mtl():
97 >    print "Test the model module..."
98 >    ba0 = BiosensorArray(1,300)  ## Create ba1 with one ROI and 300 datapoints.
99 >    roi0 = ba0.roi[0]
100 >    roi0.time = arange(300, dtype=float)  ## Samples every 1 second.
101 >    roi0.value = zeros(300, dtype=float) + 20  ## Baseline signal is 20 units.
102 >    roi0.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
103 >    roi0.params['rmax'] =  {'value': 100.0}
104 >    roi0.params['conc'] =  {'value': 1e-6}
105 >    roi0.params['kon'] =   {'value': 5e4}
106 >    roi0.params['t2'] =    {'value': 150.0}
107 >    roi0.params['koff'] =  {'value': 5e-3}
108 >    roi0.params['t3'] =    {'value': 270.0}
109 >    roi0.params['kmtl'] =  {'value': 2e6}
110 >    roi0.name = "kmtl=2e6"
111 >    roi0.model = simple1to1_mtl
112 >    roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
113 >    
114 >    ba1 = deepcopy(ba0)
115 >    roi0 = ba1.roi[0]
116 >    roi0.name = "No MTL"
117 >    roi0.model = simple1to1
118 >    roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
119 >    dualgraph(ba0, ba1, "With and without MTL")
120 >    print "Done with test demo_mtl."
121 >
122 >
123 > ## Run selected test or tests.
124 > #test_io_module()
125 > #test_cal_module_vu_module()
126 > #demo_mtl()
127 > test_mdl_module_fit_module()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines