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 100518 (yymmdd)
3 > Last modified on 100519 (yymmdd)
4   Scripts to test various OSPRAI components.
5   """
6  
# Line 35 | Line 35
35      writeclamp(ba1,"testwriteclamp.txt")
36      writebiosensor(ba1, "testwritebiosensor.txt")
37      print "Done with test_io_module."
38 <    
38 >    return
39      
40   def test_cal_module_vu_module():
41      print "Loading an SPR data file..."
# Line 61 | Line 61
61      ba3 = copyinterval(ba3, 2800, 6200)
62      linegraph(ba3)
63      print "Done with test test_cal_module_vu_module."
64 +    return
65  
66  
67   def test_mdl_module_fit_module():
68      print "Test the model module..."
69 <    ## Create ba with two ROIs and 300 datapoints.
70 <    ba0 = BiosensorArray(2,300)  
71 <    ## First ROI.
72 <    roi = ba0.roi[0]
73 <    roi.time = arange(300, dtype=float)  ## Samples every 1 second.
74 <    roi.value = zeros(300, dtype=float) + 20  ## Baseline signal is 20 units.
75 <    roi.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':'fixed'} }
76 <    roi.params['rmax'] =  {'value': 100.0}
77 <    roi.params['conc'] =  {'value': 1e-6}
78 <    roi.params['kon'] =   {'value': 2e4}
79 <    roi.params['t2'] =    {'value': 150.0}
80 <    roi.params['koff'] =  {'value': 1e-3}
81 <    roi.params['t3'] =    {'value': 270.0}
82 <    roi.model = simple1to1
83 <    roi.value =roi.model(roi.time, roi.value, roi.params)
84 <    ## Second ROI
85 <    roi = ba0.roi[1]
86 <    roi.time = arange(300, dtype=float)  
87 <    roi.value = zeros(300, dtype=float) + 20
88 <    roi.params = deepcopy(ba0.roi[0].params)
89 <    roi.params['rmax'] = {'value': 50}
90 <    roi.model = simple1to1
91 <    roi.value = roi.model(roi.time, roi.value, roi.params)
69 >    ## 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      linegraph(ba0, "Simulation")
93      
94 <    ## Constrain rmax away from 100 to show what happens.
94 >    ## Constrain rmax belowtrue value to show what happens.
95      print "Testing the fitting..."
96      ba1 = deepcopy(ba0)
97 <    ## Make rmax too high.
98 <    ba1.roi[0].params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':'float'}
99 <    ba1.roi[0].params['kon'] =  {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':'float'}
100 <    ba1.roi[0].params['rmax'] =  {'value':150, 'min':110, 'max':190, 'fixed':'float'}
101 <    ## Make rmax too low.  Tie koff and kon to other ROI.
102 <    ba1.roi[1].params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':0}
103 <    ba1.roi[1].params['kon'] =  {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':0}
104 <    ba1.roi[1].params['rmax'] =  {'value':20, 'min':10, 'max':40, 'fixed':'float'}
97 >    ## 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      ## Fit and then plot.
108 <    mclma([ba1.roi[0], ba1.roi[1]])
108 >    mclma(ba1.roi)
109      for roi in ba1.roi:
110          roi.value =roi.model(roi.time, roi.value, roi.params)
111 <    dualgraph(ba0, ba1, "Fitted Data with an incorrect Rmax parameter")
111 >    dualgraph(ba0, ba1, "Fitted Data with an incorrect rmax constraint")
112      print "Done with test test_mdl_module_fit_module."
113 +    return
114      
115  
116   def demo_mtl():

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines