ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/test.py
Revision: 20
Committed: Mon Apr 26 21:59:45 2010 UTC (9 years, 3 months ago) by clausted
File size: 2701 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 7 """
2     Christopher Lausted, Institute for Systems Biology
3 clausted 20 Last modified on 100425 (yymmdd)
4 clausted 7 Small script to test ba_class, io_module, etc.
5     """
6    
7 clausted 11 ## Import modules.
8 clausted 19 import numpy as np
9     import ba_class as ba
10 clausted 11 import vu_module as vu
11 clausted 7 import io_module as io
12 clausted 12 import cal_module as cal
13 clausted 19 import mdl_module as mdl
14     import fit_module as fit
15     from sys import exit
16     from copy import deepcopy
17     ## Reload Osprai libraries in case code has changed.
18     reload(ba)
19 clausted 11 reload (vu)
20     reload(io)
21 clausted 12 reload(cal)
22 clausted 19 reload(mdl)
23     reload(fit)
24 clausted 7
25 clausted 19 print "Test the model module..."
26     ba0 = ba.BiosensorArray(1,300) ## Create ba1 with one ROI and 300 datapoints.
27     roi0 = ba0.roi[0]
28     roi0.time = np.arange(300, dtype=float) ## Samples every 1 second.
29     roi0.value = np.zeros(300, dtype=float) + 20 ## Baseline signal is 20 units.
30 clausted 20 roi0.params = {'t1': {'value':30.0, 'min':30.0, 'max':30.0, 'fixed':True} }
31 clausted 19 roi0.params['rmax'] = {'value': 100.0}
32     roi0.params['conc'] = {'value': 1e-6}
33     roi0.params['kon'] = {'value': 2e4}
34     roi0.params['t2'] = {'value': 150.0}
35     roi0.params['koff'] = {'value': 1e-3}
36     roi0.params['t3'] = {'value': 270.0}
37     roi0.model = mdl.simple1to1
38     roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
39     vu.linegraph(ba0, "Simulation")
40    
41     print "Testing the fitting..."
42     ba1 = deepcopy(ba0)
43     roi0 = ba1.roi[0]
44 clausted 20 roi0.params['koff'] = {'value':1.0e-2, 'min':1e-8, 'max':1e-1, 'fixed':False}
45     roi0.params['kon'] = {'value':1.0e2, 'min':1e1, 'max':1e8, 'fixed':False}
46     roi0.params['rmax'] = {'value':50, 'min':1, 'max':90, 'fixed':False}
47     fit.clma(roi0)
48 clausted 19 roi0.value =roi0.model(roi0.time, roi0.value, roi0.params)
49     vu.dualgraph(ba0, ba1, "Fitted Data with an incorrect Rmax parameter")
50     exit()
51    
52    
53 clausted 14 print "Loading an SPR data file..."
54 clausted 11 #ba1 = io.readbiosensor("example-biosensor.txt")
55     ba1 = io.readicmtxt("example-icm.txt")
56 clausted 9 #ba1 = io.readsprit("example-sprit.txt")
57     #ba1 = io.applykey(ba1, "example-key.tsv")
58 clausted 11 #ba1.set_plot_all()
59     #ba1.set_plot_list(range(6))
60     #ba1.plot()
61 clausted 7
62     #io.writesprit(ba1,"testwritesprit.txt")
63     #io.writeclamp(ba1,"testwriteclamp.txt")
64 clausted 11 #io.writebiosensor(ba1, "testwritebiosensor.txt")
65 clausted 7
66 clausted 14 print "Plotting the raw data file..."
67 clausted 11 vu.linegraph(ba1)
68 clausted 12 #vu.dotgraph(ba1)
69     #vu.dualgraph(ba1, ba1)
70 clausted 11
71 clausted 14 print "Plotting the calibrated data..."
72     ba2 = cal.calibrate(ba1, ba1, 2850, 3120)
73     vu.linegraph(ba2, "Calibrated SPR Data")
74 clausted 12
75 clausted 14 print "Use ROI #16 as background, subtract, and plot..."
76     cal.bgset(ba2, 16)
77     ba2 = cal.bgsubt(ba2)
78     vu.linegraph(ba2, "Calibrated & Referenced SPR Data")
79    
80     print "Test of scatterplot using time points 500, 1000, 1500, 2000"
81     vu.scatterplot(ba2, 3600, 4200, 3600, 4700, "Scatterplot")
82    
83     print "Done with test."
84     #input("Done with test. Press any key")