ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/SPRdataclass.py
Revision: 1
Committed: Wed Mar 17 05:34:43 2010 UTC (9 years, 6 months ago) by clausted
File size: 8454 byte(s)
Log Message:
Initial import of Osprai project
Line File contents
1 """
2 Perform the standard data package.
3
4 Yuhang Wan, Feb23,2010
5 __version__ = "1.2.1"
6
7 Description
8
9
10 Inputs:
11 data:
12 the data
13
14 dataformat:
15 to decide the time column and the signal column
16 support 3 dataformats at present, as following:
17
18 # 0(Shaped_data):
19 t s1 s2 s3 ...
20
21 # 1():
22 t1 s1 t2 s2 t3 s3 ...
23
24 # 2(Ndata(Split_data)):
25 t1 ROI1_inj1 ROI2_inj1 ... ROIn_inj1 t2 ROI1_inj2 ... ROIn_inj2
26
27 # 3(data_out):
28 t1 ROI1_inj1 t2 ROI1_inj2 t3 ROI1_inj3 ...
29 t1 ROI2_inj1 t2 ROI2_inj2 t3 ROI2_inj3 ...
30 ..........
31 t1 ROIn_inj1 t2 ROIn_inj2 t3 ROIn_inj3 ...
32
33 ROIinfo:
34 to identify the ROIs, usually in the form of:
35 [{'spot no':1 , 'name':'LinTBA' , 'concentration':'1uM' ,
36 'background':4 , 'block':1 , 'row':1 , 'column':1}]
37
38 sampleinfo:
39 to identify the sample injected, usually in the form of :
40 [{'name':'Sample 1' , 'concentration':5e-9 , 'flowrate':5 ,
41 'association duration':60 , 'dissociation duration':60}]
42
43 status:
44 to indicate the current status of the data, like calibrated and so on
45 usually in the form of :
46 {'calibration':0, 'backgroundsubtraction':0, 'split':0}
47
48 injpara:
49 injection parameters to split the curve
50 usually in the form of :
51 ['1715,2350,2977,3602,4228,4852,5475,6102,6730',100,350]
52 # the injection start time, seconds after/befroe injection,
53
54 Functions(or Attributes?):
55 updateStatus:
56 update the current status of the data after manipulation
57
58 updateInjectinfo:
59 update the injection infomation that used to split the curve
60
61 updateROIinfo:
62 update the ROI information
63
64 updateSampleinfo:
65 update the injected sample information
66
67 viewAll:
68 plot all the data together at one time
69
70 view(ROIid, injid=1):
71 plot one curve at a time
72 for unsplitted data, plot single ROI at one time, input ROI id
73 for splitted data, plot single injection of one ROI at one time, input ROI id and injection id
74
75 """
76
77
78 import numpy as np
79 import pylab as plt
80 import copy
81
82 ##
83 class SPRdataclass(object):
84 def __init__ (self, data, ROInum, dataformat=0, ROIinfo=[], sampleinfo=[], injinfo=[], status={}):
85 self.data = data
86 self.ROInum = ROInum
87 self.dataformat = dataformat
88 self.ROIinfo = ROIinfo
89 self.sampleinfo = sampleinfo
90 self.injinfo = injinfo
91 self.status = status
92
93
94 def updateStatus(self, **kw):
95 # update the pre-processing status during the process
96 'Update the status of the data, which is a dictionary.'
97 for eachKW in kw.keys():
98 self.status[eachKW] = kw[eachKW]
99
100
101 def updateROIinfo(self, ROIinfo):
102 # ROIinfo is a list of dictionaries
103 'Update the ROI information, which is a list of dictionaries.'
104 self.ROIinfo=ROIinfo
105
106 def updateSampleinfo(self, sampleinfo):
107 'Update the sample information, which is a list of dictionaries.'
108 self.sampleinfo = sampleinfo
109
110 def viewSampleinfo(self):
111 'View the basic sample information'
112 print 'Name\t Concentration'
113 for i in self.sampleinfo:
114 print i['Name'],'\t', i['Concentration']
115
116 def viewAll(self,):
117 'View all the data at once'
118 # data viewing function
119 # input the classobject
120 #
121 f = self.dataformat
122 if f == 0:
123 ##self.spotnumber = np.shape(self.data)[0]-1
124 x = self.data[0]
125 for y in self.data[1:]:
126 plt.plot(x,y)
127 plt.show()
128 elif f == 1 or f == 3 or f == 4:
129 spotnumber = np.shape(self.data)[0]/2
130 for i in range(spotnumber):
131 x = self.data[i*2]
132 y = self.data[i*2+1]
133 plt.plot(x,y)
134 plt.show()
135 elif f == 2:
136 injnum = np.shape(self.data)[0]/(self.ROInum+1)
137 for i in range(injnum):
138 for j in range(self.ROInum):
139 x = self.data[i*(self.ROInum+1)]
140 y = self.data[i*(self.ROInum+1)+j+1]
141 plt.plot(x,y)
142 plt.show()
143
144 def view(self, ROIid, injid=1):
145 ##Select a single injection of one ROI to view
146 '''
147 Plot one curve at a time.
148 For unsplitted data, plot single ROI at one time, just input ROI id
149 For splitted data, plot single injection of one ROI at one time, input ROI id and injection id
150 '''
151 # data viewing function, view single data curve
152 f = self.dataformat
153 if f == 0: # Shaped_data format
154 x,y = self.data[0], self.data[ROIid]
155 elif f == 1: #
156 x,y = self.data[(ROIid-1)*2], self.data[(ROIid-1)*2+1]
157 elif f == 2: # Ndata(Split_data) format
158 x,y = self.data[(self.ROInum+1)*(injid-1)], self.data[(self.ROInum+1)*(injid-1)+ROIid]
159 elif f == 3: # data_out format, biosensor format
160 x = self.data[ 2*self.injnum*(ROIid-1)+(injid-1)*2 ]
161 y = self.data[ 2*self.injnum*(ROIid-1)+(injid-1)*2+1 ]
162 elif f == 4: # clamp format
163 x,y = self.data[(injid-1)*2], self.data[(injid-1)*2+1]
164 plt.plot(x,y)
165 plt.show()
166 a = np.zeros([2,len(x)])
167 a[0] = x; a[1] = y; b = map(list,a)
168
169 return b
170
171 ## def savetofit(self, ROIid, ):
172 ##
173 ## f = self.dataformat
174 ## if f == 0: # Shaped_data format
175 ## x,y = self.data[0], self.data[ROIid]
176 ## elif f == 1: #
177 ## x,y = self.data[(ROIid-1)*2], self.data[(ROIid-1)*2+1]
178 ## elif f == 2: # Ndata format
179 ## x,y = self.data[(self.ROInum+1)*(injid-1)], self.data[(self.ROInum+1)*(injid-1)+ROIid]
180 ## elif f == 3: # data_out format
181 ## x = self.data[ 2*self.injnum*(ROIid-1)+(injid-1)*2 ]
182 ## y = self.data[ 2*self.injnum*(ROIid-1)+(injid-1)*2+1 ]
183
184
185 class DataPass(SPRdataclass):
186 def __init__ (self, data, ROInum, dataformat=0, ROIinfo=[], sampleinfo=[], status={}, injpara=[]):
187 SPRdataclass.__init__(self, data, ROInum, dataformat, ROIinfo, sampleinfo, status)
188 self.injpara = injpara # should be in the form of [[tinj,ton,toff],[...],...]
189 self.injnum = len(sampleinfo)
190
191 def selectdatatofit(self, ROIid=1, *injid):
192 # only for clamp or scrubber data at present
193 obj = copy.deepcopy(self)
194 f = obj.dataformat
195 new_sampleinfo = []
196 ## print f, injid
197 d,c = [], []
198 if f == 0 or f == 1: # Shaped_data format
199 print 'please split the whole curve first.'
200 return
201
202 elif f == 2 or f == 3 or f == 4: #
203 for i in injid:
204 print i
205 b=obj.view(ROIid, i)
206 d.append(b[0])
207 d.append(b[1])
208 new_sampleinfo.append(obj.sampleinfo[i-1])
209 ## for j in self.sampleinfo:
210 ## if str(i) in j['Name']:
211 ## c.append(float(j['Concentration']))
212 else:
213 print 'dataformat not support!'
214 obj.data = d
215 obj.updateSampleinfo(new_sampleinfo)
216 obj.ROInum = 1
217 obj.updateROIinfo(self.ROIinfo[ROIid-1])
218
219
220 return obj
221
222 ## def updateInjectinfo(self, injtime, t_a=350, t_b=100):##*kwt1=self.split_parameter[1], t2=self.split_parameter[2]):
223 ## self.injpara[0] = injtime
224 ## self.injpara[1] = t_a
225 ## self.injpara[2] = t_b
226 ## self.injnum = len(injtime)
227
228 ## def assignInjpara(self, )
229 ## for i,t in enumerate(kw):
230 ## self.injpara[i+1] = t