1
2
3
4
5
6 """
7 Classes for accessing the information in Affymetrix cel files.
8
9 Functions:
10 read Read a cel file and store its contents in a Record
11
12 Classes:
13 Record Contains the information from a cel file
14
15
16 The following classes are DEPRECATED:
17
18 class CelParser: parses cel files
19 class CelRecord: stores the information from a cel file
20
21 """
22
23 import numpy
24
26 """
27 Stores the information in a cel file
28 """
35
36
38 """
39 Read the information in a cel file, and store it in a Record.
40 """
41
42
43 record = Record()
44 section = ""
45 for line in handle:
46 if not line.strip():
47 continue
48 if line[:8]=="[HEADER]":
49 section = "HEADER"
50 elif line[:11]=="[INTENSITY]":
51 section = "INTENSITY"
52 record.intensities = numpy.zeros((record.nrows, record.ncols))
53 record.stdevs = numpy.zeros((record.nrows, record.ncols))
54 record.npix = numpy.zeros((record.nrows, record.ncols), int)
55 elif line[0]=="[":
56 section = ""
57 elif section=="HEADER":
58 keyword, value = line.split("=", 1)
59 if keyword=="Cols":
60 record.ncols = int(value)
61 elif keyword=="Rows":
62 record.nrows = int(value)
63 elif section=="INTENSITY":
64 if "=" in line:
65 continue
66 words = line.split()
67 y, x = map(int, words[:2])
68 record.intensities[x,y] = float(words[2])
69 record.stdevs[x,y] = float(words[3])
70 record.npix[x,y] = int(words[4])
71 return record
72
73
74
75
76 from Bio.ParserSupport import AbstractConsumer
77 from numpy import *
78
80 """Scanner for Affymetrix CEL files (DEPRECATED)
81
82 Methods:
83 feed Feed data into the scanner.
84
85 The scanner generates (and calls the consumer) the following
86 types of events:
87
88 Rows - the number of rows on the microarray
89 Cols - the number of columns on the microarray
90 StartIntensity - generated when the section [INTENSITY] is found
91 ReadIntensity - one line in the section [INTENSITY]
92
93 This class is DEPRECATED; please use the read() function in this module.
94 """
96 import warnings
97 import Bio
98 warnings.warn("Bio.Affy.CelFile.CelScanner is deprecated; please use the read() function in this module instead",
99 Bio.BiopythonDeprecationWarning)
100
101 - def feed(self, handle, consumer):
102 """scanner.feed(handle, consumer)
103
104 Feed in a handle to a Cel file for scanning. handle is a file-like
105 object that contains the Cel file. consumer is a Consumer
106 object that will receive events as the report is scanned.
107 """
108 section = ""
109 for line in handle:
110 if line.strip()=="": continue
111 if line[0]=="[":
112 section = ""
113 if line[:8]=="[HEADER]":
114 section = "HEADER"
115 elif line[:11]=="[INTENSITY]":
116 section = "INTENSITY"
117 consumer.StartIntensity()
118 continue
119 if section=="HEADER":
120 keyword, value = line.split("=", 1)
121 if keyword=="Cols": consumer.Cols(value)
122 if keyword=="Rows": consumer.Rows(value)
123 continue
124 elif section=="INTENSITY":
125 if "=" in line: continue
126 consumer.ReadIntensity(line)
127
128
130 """Consumer for Affymetrix CEL files (DEPRECATED)
131
132 This class is DEPRECATED; please use the read() function in this module.
133 """
134
136 import warnings
137 import Bio
138 warnings.warn("Bio.Affy.CelFile.CelConsumer is deprecated; please use the read() function in this module instead",
139 Bio.BiopythonDeprecationWarning)
140
141 self._mean = None
142 self._stdev = None
143 self._npix = None
144
145 - def Cols(self, value):
146 self._cols = int(value)
147
148 - def Rows(self, value):
149 self._rows = int(value)
150
152 self._mean = zeros((self._rows, self._cols))
153 self._stdev = zeros((self._rows, self._cols))
154 self._npix = zeros((self._rows, self._cols), int)
155
163
165 """
166 Stores the information in a cel file (DEPRECATED).
167
168 Needs error handling.
169 Needs to know the chip design.
170
171 This class is DEPRECATED; please use the Record class instead.
172 """
173
174
176 """
177 Pass the data attributes as a dictionary.
178 """
179 import warnings
180 import Bio
181 warnings.warn("Bio.Affy.CelFile.CelRecord is deprecated; please use the read() function in this module instead",
182 Bio.BiopythonDeprecationWarning)
183
184 from copy import deepcopy as dcopy
185
186 self._intensities = dcopy(data_dict['intensities'])
187 self._stdevs = dcopy(data_dict['stdevs'])
188 self._npix = dcopy(data_dict['npix'])
189
190 self._nrows, self._ncols = self._intensities.shape
191
192
194 """
195 Return a two dimensional array of probe cell intensities.
196 Dimension 1 -> rows
197 Dimension 2 -> columns
198 """
199 return self._intensities
200
201
203 """
204 Return a two dimensional array of probe cell standard deviations.
205 Dimension 1 -> rows
206 Dimension 2 -> columns
207 """
208 return self._stdevs
209
210
212 """
213 Return a two dimensional array of the number of pixels in a probe cell.
214 Dimension 1 -> rows
215 Dimension 2 -> columns
216 """
217 return self._npix
218
219
221 """
222 The number of rows of probe cells in an array.
223 """
224 return self._nrows
225
227 """
228 The number of columns of probe cells in an array.
229 """
230 return self._ncols
231
233 """
234 The size of the probe cell array as a tuple (nrows,ncols).
235 """
236 return self._nrows, self._ncols
237
238
239
241 """
242 Takes a handle to an Affymetrix cel file, parses the file and
243 returns an instance of a CelRecord
244
245 This class needs error handling.
246
247 This class is DEPRECATED; please use the read() function in this module
248 instead.
249 """
250
252 """
253 Usually load the class with the cel file (not file name) as
254 an argument.
255 """
256 import warnings
257 import Bio
258 warnings.warn("Bio.Affy.CelFile.CelParser is deprecated; please use the read() function in this module instead",
259 Bio.BiopythonDeprecationWarning)
260
261 self._intensities = None
262 self._stdevs = None
263 self._npix = None
264
265 if handle is not None: self.parse(handle)
266
267
268 - def parse(self, handle):
269 """
270 Takes a handle to a cel file, parses it
271 and stores it in the three arrays.
272
273 There is more information in the cel file that could be retrieved
274 and stored in CelRecord. The chip type should be a priority.
275 """
276
277
278 scanner = CelScanner()
279 consumer = CelConsumer()
280 scanner.feed(handle, consumer)
281 self._intensities = consumer._mean
282 self._stdevs = consumer._stdev
283 self._npix = consumer._npix
284 self._nrows = self._intensities.shape[0]
285 self._ncols = self._intensities.shape[1]
286
287
289 """
290 Returns the parsed data as a CelRecord.
291 """
292
293 record_dict = {}
294 record_dict['intensities'] = self._intensities
295 record_dict['stdevs'] = self._stdevs
296 record_dict['npix'] = self._npix
297
298 return CelRecord(record_dict)
299