11 |
13 Sep 07 |
nicklas |
1 |
///////////////////////////////////////////////////////////////// |
11 |
13 Sep 07 |
nicklas |
2 |
// |
11 |
13 Sep 07 |
nicklas |
// Copyright (C) 2005 Affymetrix, Inc. |
11 |
13 Sep 07 |
nicklas |
4 |
// |
11 |
13 Sep 07 |
nicklas |
// This library is free software; you can redistribute it and/or modify |
11 |
13 Sep 07 |
nicklas |
// it under the terms of the GNU Lesser General Public License as published |
11 |
13 Sep 07 |
nicklas |
// by the Free Software Foundation; either version 2.1 of the License, |
11 |
13 Sep 07 |
nicklas |
// or (at your option) any later version. |
11 |
13 Sep 07 |
nicklas |
9 |
// |
11 |
13 Sep 07 |
nicklas |
// This library is distributed in the hope that it will be useful, but |
11 |
13 Sep 07 |
nicklas |
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
11 |
13 Sep 07 |
nicklas |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
11 |
13 Sep 07 |
nicklas |
// for more details. |
11 |
13 Sep 07 |
nicklas |
14 |
// |
11 |
13 Sep 07 |
nicklas |
// You should have received a copy of the GNU Lesser General Public License |
11 |
13 Sep 07 |
nicklas |
// along with this library; if not, write to the Free Software Foundation, Inc., |
11 |
13 Sep 07 |
nicklas |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
11 |
13 Sep 07 |
nicklas |
18 |
// |
11 |
13 Sep 07 |
nicklas |
19 |
///////////////////////////////////////////////////////////////// |
11 |
13 Sep 07 |
nicklas |
20 |
|
11 |
13 Sep 07 |
nicklas |
21 |
package affymetrix.gcos.cel; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import affymetrix.portability.*; |
15 |
17 Sep 07 |
nicklas |
24 |
import affymetrix.calvin.parsers.FileHeaderReader; |
11 |
13 Sep 07 |
nicklas |
25 |
import affymetrix.gcos.*; |
15 |
17 Sep 07 |
nicklas |
26 |
|
11 |
13 Sep 07 |
nicklas |
27 |
import java.util.*; |
11 |
13 Sep 07 |
nicklas |
28 |
import java.io.*; |
11 |
13 Sep 07 |
nicklas |
29 |
import java.nio.channels.*; |
11 |
13 Sep 07 |
nicklas |
30 |
import java.nio.channels.FileChannel.*; |
11 |
13 Sep 07 |
nicklas |
31 |
import java.nio.*; |
11 |
13 Sep 07 |
nicklas |
32 |
|
11 |
13 Sep 07 |
nicklas |
/** Provides parsing and data storage for GCOS CEL files. */ |
11 |
13 Sep 07 |
nicklas |
34 |
public class CELFileData { |
11 |
13 Sep 07 |
nicklas |
35 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag to read all of the data in a CEL file. */ |
11 |
13 Sep 07 |
nicklas |
37 |
public static final int CEL_ALL=1; |
11 |
13 Sep 07 |
nicklas |
38 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag to read only the data from a CEL file. */ |
11 |
13 Sep 07 |
nicklas |
40 |
public static final int CEL_DATA=2; |
11 |
13 Sep 07 |
nicklas |
41 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag to read the outlier and data sections from a CEL file. */ |
11 |
13 Sep 07 |
nicklas |
43 |
public static final int CEL_OUTLIER=4; |
11 |
13 Sep 07 |
nicklas |
44 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag to read the mask and data sections from a CEL file. */ |
11 |
13 Sep 07 |
nicklas |
46 |
public static final int CEL_MASK=8; |
11 |
13 Sep 07 |
nicklas |
47 |
|
11 |
13 Sep 07 |
nicklas |
/** The magic number for XDA CEL files. */ |
11 |
13 Sep 07 |
nicklas |
49 |
public static final int CELL_FILE_MAGIC_NUMBER = 64; |
11 |
13 Sep 07 |
nicklas |
50 |
|
11 |
13 Sep 07 |
nicklas |
/** Error string */ |
11 |
13 Sep 07 |
nicklas |
52 |
private String strError; |
11 |
13 Sep 07 |
nicklas |
53 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the error. |
11 |
13 Sep 07 |
nicklas |
* @return The last error message. |
11 |
13 Sep 07 |
nicklas |
56 |
*/ |
11 |
13 Sep 07 |
nicklas |
57 |
public String getError() { return strError; } |
11 |
13 Sep 07 |
nicklas |
58 |
|
11 |
13 Sep 07 |
nicklas |
/** The file name. */ |
11 |
13 Sep 07 |
nicklas |
60 |
private String fileName; |
11 |
13 Sep 07 |
nicklas |
61 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the file name. |
11 |
13 Sep 07 |
nicklas |
* @return The file name. |
11 |
13 Sep 07 |
nicklas |
64 |
*/ |
11 |
13 Sep 07 |
nicklas |
65 |
public String getFileName() { return fileName; } |
11 |
13 Sep 07 |
nicklas |
66 |
|
11 |
13 Sep 07 |
nicklas |
/** Sets the file name. |
11 |
13 Sep 07 |
nicklas |
* @param value The name of the CEL file to read. |
11 |
13 Sep 07 |
nicklas |
69 |
*/ |
11 |
13 Sep 07 |
nicklas |
70 |
public void setFileName(String value) { fileName = value; } |
15 |
17 Sep 07 |
nicklas |
71 |
|
15 |
17 Sep 07 |
nicklas |
72 |
/** |
15 |
17 Sep 07 |
nicklas |
* If set, we will read data from this input stream instead of |
15 |
17 Sep 07 |
nicklas |
* from the file specified by fileName |
15 |
17 Sep 07 |
nicklas |
75 |
*/ |
15 |
17 Sep 07 |
nicklas |
76 |
private InputStream in; |
19 |
15 Nov 07 |
nicklas |
77 |
|
19 |
15 Nov 07 |
nicklas |
78 |
/** |
19 |
15 Nov 07 |
nicklas |
* Temporary file in case we need to copy the entire InputStream |
19 |
15 Nov 07 |
nicklas |
80 |
*/ |
19 |
15 Nov 07 |
nicklas |
81 |
private File tempFile; |
11 |
13 Sep 07 |
nicklas |
82 |
|
15 |
17 Sep 07 |
nicklas |
83 |
/** |
15 |
17 Sep 07 |
nicklas |
* A reader wrapping the input stream when reading text CDF files. |
15 |
17 Sep 07 |
nicklas |
85 |
*/ |
15 |
17 Sep 07 |
nicklas |
86 |
private BufferedReader textReader; |
15 |
17 Sep 07 |
nicklas |
87 |
|
15 |
17 Sep 07 |
nicklas |
88 |
/** |
18 |
15 Nov 07 |
nicklas |
* A reader wrapping the input stream when reading binary CDF files. |
18 |
15 Nov 07 |
nicklas |
90 |
*/ |
18 |
15 Nov 07 |
nicklas |
91 |
private FileInputStream xdaReader; |
18 |
15 Nov 07 |
nicklas |
92 |
|
18 |
15 Nov 07 |
nicklas |
93 |
/** |
15 |
17 Sep 07 |
nicklas |
* So we know if the file format has been checked or not, since |
15 |
17 Sep 07 |
nicklas |
* if we use an InputStream it can only be read once. |
15 |
17 Sep 07 |
nicklas |
96 |
*/ |
15 |
17 Sep 07 |
nicklas |
97 |
private boolean hasCheckedFileFormat; |
15 |
17 Sep 07 |
nicklas |
98 |
|
15 |
17 Sep 07 |
nicklas |
99 |
/** |
15 |
17 Sep 07 |
nicklas |
* If the file is a version 3 text file |
15 |
17 Sep 07 |
nicklas |
101 |
*/ |
15 |
17 Sep 07 |
nicklas |
102 |
private boolean isVersion3CompatibleFile; |
15 |
17 Sep 07 |
nicklas |
103 |
|
15 |
17 Sep 07 |
nicklas |
104 |
/** |
15 |
17 Sep 07 |
nicklas |
* If the file is an XDA binary file |
15 |
17 Sep 07 |
nicklas |
106 |
*/ |
15 |
17 Sep 07 |
nicklas |
107 |
private boolean isXDACompatibleFile; |
15 |
17 Sep 07 |
nicklas |
108 |
|
15 |
17 Sep 07 |
nicklas |
109 |
/** |
15 |
17 Sep 07 |
nicklas |
* If the file is a Calvin binary file |
15 |
17 Sep 07 |
nicklas |
111 |
*/ |
15 |
17 Sep 07 |
nicklas |
112 |
private boolean isCalvinCompatibleFile; |
15 |
17 Sep 07 |
nicklas |
113 |
|
15 |
17 Sep 07 |
nicklas |
114 |
/** |
15 |
17 Sep 07 |
nicklas |
* To keep track if headers have been read or not, since we can't do that twice |
15 |
17 Sep 07 |
nicklas |
* if using an input stream. |
15 |
17 Sep 07 |
nicklas |
117 |
*/ |
15 |
17 Sep 07 |
nicklas |
118 |
private boolean hasReadHeaders = false; |
15 |
17 Sep 07 |
nicklas |
119 |
|
15 |
17 Sep 07 |
nicklas |
120 |
/** |
15 |
17 Sep 07 |
nicklas |
* If reading the headers was successful (true) or not (false) |
15 |
17 Sep 07 |
nicklas |
122 |
*/ |
15 |
17 Sep 07 |
nicklas |
123 |
private boolean headerResult; |
15 |
17 Sep 07 |
nicklas |
124 |
|
15 |
17 Sep 07 |
nicklas |
125 |
/** |
15 |
17 Sep 07 |
nicklas |
* To keep track if data have been read or not, since we can't do that twice |
15 |
17 Sep 07 |
nicklas |
* if using an input stream. |
15 |
17 Sep 07 |
nicklas |
128 |
*/ |
15 |
17 Sep 07 |
nicklas |
129 |
private boolean hasReadData = false; |
15 |
17 Sep 07 |
nicklas |
130 |
|
15 |
17 Sep 07 |
nicklas |
131 |
/** |
15 |
17 Sep 07 |
nicklas |
* If reading the data was successful (true) or not (false) |
15 |
17 Sep 07 |
nicklas |
133 |
*/ |
15 |
17 Sep 07 |
nicklas |
134 |
private boolean dataResult; |
15 |
17 Sep 07 |
nicklas |
135 |
|
15 |
17 Sep 07 |
nicklas |
136 |
/** |
15 |
17 Sep 07 |
nicklas |
* Set the input stream to read from. If set |
15 |
17 Sep 07 |
nicklas |
* we use the stream instead of the file given by filename |
15 |
17 Sep 07 |
nicklas |
139 |
*/ |
15 |
17 Sep 07 |
nicklas |
140 |
public void setInputStream(InputStream in) |
15 |
17 Sep 07 |
nicklas |
141 |
{ |
15 |
17 Sep 07 |
nicklas |
142 |
this.in = in; |
15 |
17 Sep 07 |
nicklas |
143 |
} |
15 |
17 Sep 07 |
nicklas |
144 |
|
15 |
17 Sep 07 |
nicklas |
145 |
/** |
15 |
17 Sep 07 |
nicklas |
* Get the InputStream. Peeking at the input stream with |
15 |
17 Sep 07 |
nicklas |
* {@link #checkFileFormat()} have replaced the original stream |
15 |
17 Sep 07 |
nicklas |
* with a PushBackInputStream |
15 |
17 Sep 07 |
nicklas |
* @return |
15 |
17 Sep 07 |
nicklas |
150 |
*/ |
15 |
17 Sep 07 |
nicklas |
151 |
public InputStream getInputStream() |
15 |
17 Sep 07 |
nicklas |
152 |
{ |
15 |
17 Sep 07 |
nicklas |
153 |
return in; |
15 |
17 Sep 07 |
nicklas |
154 |
} |
15 |
17 Sep 07 |
nicklas |
155 |
|
11 |
13 Sep 07 |
nicklas |
/** CEL file header data object. */ |
11 |
13 Sep 07 |
nicklas |
157 |
private CELFileHeaderData headerData; |
11 |
13 Sep 07 |
nicklas |
158 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the header. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file header object. |
11 |
13 Sep 07 |
nicklas |
161 |
*/ |
11 |
13 Sep 07 |
nicklas |
162 |
public CELFileHeaderData getHeader() { return headerData; } |
11 |
13 Sep 07 |
nicklas |
163 |
|
11 |
13 Sep 07 |
nicklas |
/** The entries for each cell (used for text format). */ |
11 |
13 Sep 07 |
nicklas |
165 |
private Vector /*CELFileEntryType*/ entries; |
11 |
13 Sep 07 |
nicklas |
166 |
|
11 |
13 Sep 07 |
nicklas |
/** Map for masked cell coordinates. */ |
11 |
13 Sep 07 |
nicklas |
168 |
private Map /*<int, bool>*/ maskedCells; |
11 |
13 Sep 07 |
nicklas |
169 |
|
11 |
13 Sep 07 |
nicklas |
/** Map for outlier coordinates. */ |
11 |
13 Sep 07 |
nicklas |
171 |
private Map /*<int, bool>*/ outliers; |
11 |
13 Sep 07 |
nicklas |
172 |
|
11 |
13 Sep 07 |
nicklas |
/** CEL file reading state. */ |
11 |
13 Sep 07 |
nicklas |
174 |
private int nReadState; |
11 |
13 Sep 07 |
nicklas |
175 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag to determine if masked cell data should be read */ |
11 |
13 Sep 07 |
nicklas |
177 |
private boolean bReadMaskedCells; |
11 |
13 Sep 07 |
nicklas |
178 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag to determine if outlier data should be read */ |
11 |
13 Sep 07 |
nicklas |
180 |
private boolean bReadOutliers; |
11 |
13 Sep 07 |
nicklas |
181 |
|
11 |
13 Sep 07 |
nicklas |
/** A mapped byte buffer for XDA files. */ |
11 |
13 Sep 07 |
nicklas |
183 |
private MappedByteBuffer xdaBuffer; |
11 |
13 Sep 07 |
nicklas |
184 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the X coordinates from index. |
11 |
13 Sep 07 |
nicklas |
* @param index The 0 based index to the entry array. |
11 |
13 Sep 07 |
nicklas |
* @return X coordinate |
11 |
13 Sep 07 |
nicklas |
188 |
*/ |
11 |
13 Sep 07 |
nicklas |
189 |
public int indexToX(int index) { return index % headerData.getCols(); } |
11 |
13 Sep 07 |
nicklas |
190 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the Y coordinates from index. |
11 |
13 Sep 07 |
nicklas |
* @param index The 0 based index to the entry array. |
11 |
13 Sep 07 |
nicklas |
* @return Y coordinate |
11 |
13 Sep 07 |
nicklas |
194 |
*/ |
11 |
13 Sep 07 |
nicklas |
195 |
public int indexToY(int index) { return index / headerData.getCols(); } |
11 |
13 Sep 07 |
nicklas |
196 |
|
11 |
13 Sep 07 |
nicklas |
/** Maps X/Y coordinates to CEL file index. |
11 |
13 Sep 07 |
nicklas |
* @param x The x coordinate |
11 |
13 Sep 07 |
nicklas |
* @param y The y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @return The index to the entry array. |
11 |
13 Sep 07 |
nicklas |
201 |
*/ |
11 |
13 Sep 07 |
nicklas |
202 |
public int xyToIndex(int x, int y) { return xyToIndex(x,y, headerData.getRows(), headerData.getCols()); } |
11 |
13 Sep 07 |
nicklas |
203 |
|
11 |
13 Sep 07 |
nicklas |
/** Maps X/Y coordinates to CEL file index. |
11 |
13 Sep 07 |
nicklas |
* @param x The x coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param r The number of rows. |
11 |
13 Sep 07 |
nicklas |
* @param c The number of columns. |
11 |
13 Sep 07 |
nicklas |
* @return The index to the intensity arrays. |
11 |
13 Sep 07 |
nicklas |
210 |
*/ |
11 |
13 Sep 07 |
nicklas |
211 |
public static int xyToIndex(int x, int y, int r, int c) { return ((y*c) + x); } |
11 |
13 Sep 07 |
nicklas |
212 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file entry. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the CEL file entries. |
11 |
13 Sep 07 |
nicklas |
* @param entry The CEL file entry. |
11 |
13 Sep 07 |
nicklas |
216 |
*/ |
11 |
13 Sep 07 |
nicklas |
217 |
public void getEntry(int index, CELFileEntryType entry) { |
11 |
13 Sep 07 |
nicklas |
218 |
entry.setIntensity( getIntensity(index)); |
11 |
13 Sep 07 |
nicklas |
219 |
entry.setStdv( getStdv(index)); |
11 |
13 Sep 07 |
nicklas |
220 |
entry.setPixels( getPixels(index)); |
11 |
13 Sep 07 |
nicklas |
221 |
} |
11 |
13 Sep 07 |
nicklas |
222 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file entry. |
11 |
13 Sep 07 |
nicklas |
* @param x The X coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The Y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param entry The CEL file entry. |
11 |
13 Sep 07 |
nicklas |
227 |
*/ |
11 |
13 Sep 07 |
nicklas |
228 |
public void getEntry(int x, int y, CELFileEntryType entry) { getEntry(xyToIndex(x,y), entry); } |
11 |
13 Sep 07 |
nicklas |
229 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file intensity. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the CEL file entries. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file intensity. |
11 |
13 Sep 07 |
nicklas |
233 |
*/ |
11 |
13 Sep 07 |
nicklas |
234 |
public float getIntensity(int index) { |
11 |
13 Sep 07 |
nicklas |
235 |
assert((index >= 0) && (index < headerData.getCells())); |
11 |
13 Sep 07 |
nicklas |
236 |
if (xdaBuffer != null) |
11 |
13 Sep 07 |
nicklas |
237 |
{ |
11 |
13 Sep 07 |
nicklas |
238 |
ByteBuffer entry = (ByteBuffer)xdaBuffer.position(index * CELFileEntryType.CEL_FILE_ENTRY_SIZE); |
11 |
13 Sep 07 |
nicklas |
239 |
return entry.getFloat(); |
11 |
13 Sep 07 |
nicklas |
240 |
} |
11 |
13 Sep 07 |
nicklas |
241 |
else if (entries != null) |
11 |
13 Sep 07 |
nicklas |
242 |
{ |
11 |
13 Sep 07 |
nicklas |
243 |
CELFileEntryType entry = (CELFileEntryType) entries.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
244 |
return entry.getIntensity(); |
11 |
13 Sep 07 |
nicklas |
245 |
} |
11 |
13 Sep 07 |
nicklas |
246 |
assert(true); |
11 |
13 Sep 07 |
nicklas |
247 |
return 0.0f; |
11 |
13 Sep 07 |
nicklas |
248 |
} |
11 |
13 Sep 07 |
nicklas |
249 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file intensity. |
11 |
13 Sep 07 |
nicklas |
* @param x The X coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The Y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file intensity. |
11 |
13 Sep 07 |
nicklas |
254 |
*/ |
11 |
13 Sep 07 |
nicklas |
255 |
public float getIntensity(int x, int y) { return getIntensity(xyToIndex(x,y)); } |
11 |
13 Sep 07 |
nicklas |
256 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file stdv value. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the CEL file entries. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file stdv value. |
11 |
13 Sep 07 |
nicklas |
260 |
*/ |
11 |
13 Sep 07 |
nicklas |
261 |
public float getStdv(int index) { |
11 |
13 Sep 07 |
nicklas |
262 |
assert((index >= 0) && (index < headerData.getCells())); |
11 |
13 Sep 07 |
nicklas |
263 |
if (xdaBuffer != null) |
11 |
13 Sep 07 |
nicklas |
264 |
{ |
11 |
13 Sep 07 |
nicklas |
265 |
ByteBuffer entry = (ByteBuffer)xdaBuffer.position((index * CELFileEntryType.CEL_FILE_ENTRY_SIZE) + DataSizes.FLOAT_SIZE); |
11 |
13 Sep 07 |
nicklas |
266 |
return entry.getFloat(); |
11 |
13 Sep 07 |
nicklas |
267 |
} |
11 |
13 Sep 07 |
nicklas |
268 |
else if (entries != null) |
11 |
13 Sep 07 |
nicklas |
269 |
{ |
11 |
13 Sep 07 |
nicklas |
270 |
CELFileEntryType entry = (CELFileEntryType) entries.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
271 |
return entry.getStdv(); |
11 |
13 Sep 07 |
nicklas |
272 |
} |
11 |
13 Sep 07 |
nicklas |
273 |
assert(true); |
11 |
13 Sep 07 |
nicklas |
274 |
return 0.0f; |
11 |
13 Sep 07 |
nicklas |
275 |
} |
11 |
13 Sep 07 |
nicklas |
276 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file stdv value. |
11 |
13 Sep 07 |
nicklas |
* @param x The X coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The Y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file stdv value. |
11 |
13 Sep 07 |
nicklas |
281 |
*/ |
11 |
13 Sep 07 |
nicklas |
282 |
public float getStdv(int x, int y) { return getStdv(xyToIndex(x,y)); } |
11 |
13 Sep 07 |
nicklas |
283 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file pixel count. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the CEL file entries. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file pixel count. |
11 |
13 Sep 07 |
nicklas |
287 |
*/ |
11 |
13 Sep 07 |
nicklas |
288 |
public short getPixels(int index) { |
11 |
13 Sep 07 |
nicklas |
289 |
assert((index >= 0) && (index < headerData.getCells())); |
11 |
13 Sep 07 |
nicklas |
290 |
if (xdaBuffer != null) |
11 |
13 Sep 07 |
nicklas |
291 |
{ |
11 |
13 Sep 07 |
nicklas |
292 |
ByteBuffer entry = (ByteBuffer)xdaBuffer.position((index * CELFileEntryType.CEL_FILE_ENTRY_SIZE) + DataSizes.FLOAT_SIZE + DataSizes.FLOAT_SIZE); |
11 |
13 Sep 07 |
nicklas |
293 |
return entry.getShort(); |
11 |
13 Sep 07 |
nicklas |
294 |
} |
11 |
13 Sep 07 |
nicklas |
295 |
else if (entries != null) |
11 |
13 Sep 07 |
nicklas |
296 |
{ |
11 |
13 Sep 07 |
nicklas |
297 |
CELFileEntryType entry = (CELFileEntryType) entries.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
298 |
return entry.getPixels(); |
11 |
13 Sep 07 |
nicklas |
299 |
} |
11 |
13 Sep 07 |
nicklas |
300 |
assert(true); |
11 |
13 Sep 07 |
nicklas |
301 |
return 0; |
11 |
13 Sep 07 |
nicklas |
302 |
} |
11 |
13 Sep 07 |
nicklas |
303 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file pixel count. |
11 |
13 Sep 07 |
nicklas |
* @param x The X coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The Y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @return The CEL file pixel count. |
11 |
13 Sep 07 |
nicklas |
308 |
*/ |
11 |
13 Sep 07 |
nicklas |
309 |
public short getPixels(int x, int y) { return getPixels(xyToIndex(x,y)); } |
11 |
13 Sep 07 |
nicklas |
310 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file mask flag. |
11 |
13 Sep 07 |
nicklas |
* @param x The X coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The Y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @return True if the feature is masked. |
11 |
13 Sep 07 |
nicklas |
315 |
*/ |
11 |
13 Sep 07 |
nicklas |
316 |
public boolean isMasked(int x, int y) { return isMasked(xyToIndex(x,y)); } |
11 |
13 Sep 07 |
nicklas |
317 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file mask flag. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the CEL file entries. |
11 |
13 Sep 07 |
nicklas |
* @return True if the feature is masked. |
11 |
13 Sep 07 |
nicklas |
321 |
*/ |
11 |
13 Sep 07 |
nicklas |
322 |
public boolean isMasked(int index) { |
11 |
13 Sep 07 |
nicklas |
323 |
Boolean masked = (Boolean)maskedCells.get(new Integer(index)); |
11 |
13 Sep 07 |
nicklas |
324 |
if (masked != null ) |
11 |
13 Sep 07 |
nicklas |
325 |
return masked.booleanValue(); |
11 |
13 Sep 07 |
nicklas |
326 |
return false; |
11 |
13 Sep 07 |
nicklas |
327 |
} |
11 |
13 Sep 07 |
nicklas |
328 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file outlier flag. |
11 |
13 Sep 07 |
nicklas |
* @param x The X coordinate. |
11 |
13 Sep 07 |
nicklas |
* @param y The Y coordinate. |
11 |
13 Sep 07 |
nicklas |
* @return True if the feature is an outlier. |
11 |
13 Sep 07 |
nicklas |
333 |
*/ |
11 |
13 Sep 07 |
nicklas |
334 |
public boolean isOutlier(int x, int y) { return isOutlier(xyToIndex(x,y)); } |
11 |
13 Sep 07 |
nicklas |
335 |
|
11 |
13 Sep 07 |
nicklas |
/** Retrieves a CEL file outlier flag. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the CEL file entries. |
11 |
13 Sep 07 |
nicklas |
* @return True if the feature is an outlier. |
11 |
13 Sep 07 |
nicklas |
339 |
*/ |
11 |
13 Sep 07 |
nicklas |
340 |
public boolean isOutlier(int index) { |
11 |
13 Sep 07 |
nicklas |
341 |
Boolean outlier = (Boolean)outliers.get(new Integer(index)); |
11 |
13 Sep 07 |
nicklas |
342 |
if (outlier != null ) |
11 |
13 Sep 07 |
nicklas |
343 |
return outlier.booleanValue(); |
11 |
13 Sep 07 |
nicklas |
344 |
return false; |
11 |
13 Sep 07 |
nicklas |
345 |
} |
11 |
13 Sep 07 |
nicklas |
346 |
|
15 |
17 Sep 07 |
nicklas |
347 |
/** |
15 |
17 Sep 07 |
nicklas |
* Checks if the file exists or if an input stream has been specified. |
11 |
13 Sep 07 |
nicklas |
* @return True if the file exists. |
11 |
13 Sep 07 |
nicklas |
350 |
*/ |
15 |
17 Sep 07 |
nicklas |
351 |
public boolean exists() { |
15 |
17 Sep 07 |
nicklas |
352 |
return in != null || new File(fileName).exists(); |
11 |
13 Sep 07 |
nicklas |
353 |
} |
11 |
13 Sep 07 |
nicklas |
354 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the header of the CEL file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
357 |
*/ |
11 |
13 Sep 07 |
nicklas |
358 |
public boolean readHeader() { |
11 |
13 Sep 07 |
nicklas |
// Read the header, close if failed. |
11 |
13 Sep 07 |
nicklas |
360 |
if (open(true) == false) |
11 |
13 Sep 07 |
nicklas |
361 |
{ |
11 |
13 Sep 07 |
nicklas |
362 |
clear(); |
11 |
13 Sep 07 |
nicklas |
363 |
return false; |
11 |
13 Sep 07 |
nicklas |
364 |
} |
11 |
13 Sep 07 |
nicklas |
365 |
return true; |
11 |
13 Sep 07 |
nicklas |
366 |
} |
11 |
13 Sep 07 |
nicklas |
367 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the CEL file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
370 |
*/ |
11 |
13 Sep 07 |
nicklas |
371 |
public boolean read() { |
11 |
13 Sep 07 |
nicklas |
372 |
return read(true); |
11 |
13 Sep 07 |
nicklas |
373 |
} |
11 |
13 Sep 07 |
nicklas |
374 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the CEL file. |
11 |
13 Sep 07 |
nicklas |
* @param bIncludeMaskAndOutliers Flag to indicate if the mask and outlier sections should also be read. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
378 |
*/ |
11 |
13 Sep 07 |
nicklas |
379 |
public boolean read(boolean bIncludeMaskAndOutliers) { |
11 |
13 Sep 07 |
nicklas |
380 |
bReadMaskedCells = bIncludeMaskAndOutliers; |
11 |
13 Sep 07 |
nicklas |
381 |
bReadOutliers = bIncludeMaskAndOutliers; |
11 |
13 Sep 07 |
nicklas |
382 |
|
11 |
13 Sep 07 |
nicklas |
// Open the file |
11 |
13 Sep 07 |
nicklas |
384 |
if (open(false) == false) |
11 |
13 Sep 07 |
nicklas |
385 |
{ |
11 |
13 Sep 07 |
nicklas |
386 |
clear(); |
11 |
13 Sep 07 |
nicklas |
387 |
return false; |
11 |
13 Sep 07 |
nicklas |
388 |
} |
11 |
13 Sep 07 |
nicklas |
389 |
return true; |
11 |
13 Sep 07 |
nicklas |
390 |
} |
11 |
13 Sep 07 |
nicklas |
391 |
|
11 |
13 Sep 07 |
nicklas |
/** Opens and reads the contents of the CEL file. |
11 |
13 Sep 07 |
nicklas |
* @param bReadHeaderOnly Flag to indicate if the header is only to be read. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
395 |
*/ |
11 |
13 Sep 07 |
nicklas |
396 |
private boolean open(boolean bReadHeaderOnly) |
11 |
13 Sep 07 |
nicklas |
397 |
{ |
11 |
13 Sep 07 |
nicklas |
398 |
if (isXDACompatibleFile()) |
11 |
13 Sep 07 |
nicklas |
399 |
return readXDACel(bReadHeaderOnly); |
11 |
13 Sep 07 |
nicklas |
400 |
else if (isVersion3CompatibleFile()) |
11 |
13 Sep 07 |
nicklas |
401 |
return readTextCel(bReadHeaderOnly); |
11 |
13 Sep 07 |
nicklas |
402 |
return false; |
11 |
13 Sep 07 |
nicklas |
403 |
} |
11 |
13 Sep 07 |
nicklas |
404 |
|
11 |
13 Sep 07 |
nicklas |
/** Clears the members. */ |
11 |
13 Sep 07 |
nicklas |
406 |
public void clear() { |
11 |
13 Sep 07 |
nicklas |
407 |
xdaBuffer = null; |
11 |
13 Sep 07 |
nicklas |
408 |
headerData = null; |
11 |
13 Sep 07 |
nicklas |
409 |
entries = null; |
11 |
13 Sep 07 |
nicklas |
410 |
outliers = null; |
11 |
13 Sep 07 |
nicklas |
411 |
maskedCells = null; |
11 |
13 Sep 07 |
nicklas |
412 |
} |
11 |
13 Sep 07 |
nicklas |
413 |
|
11 |
13 Sep 07 |
nicklas |
/** Checks if the file type is XDA. |
11 |
13 Sep 07 |
nicklas |
* @return True if XDA type. |
11 |
13 Sep 07 |
nicklas |
416 |
*/ |
11 |
13 Sep 07 |
nicklas |
417 |
public boolean isXDACompatibleFile() { |
15 |
17 Sep 07 |
nicklas |
418 |
if (!hasCheckedFileFormat) |
11 |
13 Sep 07 |
nicklas |
419 |
{ |
15 |
17 Sep 07 |
nicklas |
420 |
checkFileFormat(); |
11 |
13 Sep 07 |
nicklas |
421 |
} |
15 |
17 Sep 07 |
nicklas |
422 |
return isXDACompatibleFile; |
11 |
13 Sep 07 |
nicklas |
423 |
} |
11 |
13 Sep 07 |
nicklas |
424 |
|
11 |
13 Sep 07 |
nicklas |
/** Checks if the file type is version 3. |
11 |
13 Sep 07 |
nicklas |
* @return True if version 3 type. |
11 |
13 Sep 07 |
nicklas |
427 |
*/ |
11 |
13 Sep 07 |
nicklas |
428 |
public boolean isVersion3CompatibleFile() { |
15 |
17 Sep 07 |
nicklas |
429 |
if (!hasCheckedFileFormat) |
11 |
13 Sep 07 |
nicklas |
430 |
{ |
15 |
17 Sep 07 |
nicklas |
431 |
checkFileFormat(); |
11 |
13 Sep 07 |
nicklas |
432 |
} |
15 |
17 Sep 07 |
nicklas |
433 |
return isVersion3CompatibleFile; |
15 |
17 Sep 07 |
nicklas |
434 |
} |
15 |
17 Sep 07 |
nicklas |
435 |
|
15 |
17 Sep 07 |
nicklas |
/** Checks if the file type is Calvin file. |
15 |
17 Sep 07 |
nicklas |
* @return True if Calvin file. |
15 |
17 Sep 07 |
nicklas |
438 |
*/ |
15 |
17 Sep 07 |
nicklas |
439 |
public boolean isCalvinCompatibleFile() { |
15 |
17 Sep 07 |
nicklas |
440 |
if (!hasCheckedFileFormat) |
11 |
13 Sep 07 |
nicklas |
441 |
{ |
15 |
17 Sep 07 |
nicklas |
442 |
checkFileFormat(); |
11 |
13 Sep 07 |
nicklas |
443 |
} |
15 |
17 Sep 07 |
nicklas |
444 |
return isCalvinCompatibleFile; |
11 |
13 Sep 07 |
nicklas |
445 |
} |
15 |
17 Sep 07 |
nicklas |
446 |
private void checkFileFormat() |
15 |
17 Sep 07 |
nicklas |
447 |
{ |
15 |
17 Sep 07 |
nicklas |
448 |
int magicNumber = 0; |
15 |
17 Sep 07 |
nicklas |
449 |
hasCheckedFileFormat = true; |
15 |
17 Sep 07 |
nicklas |
450 |
isVersion3CompatibleFile = false; |
15 |
17 Sep 07 |
nicklas |
451 |
isXDACompatibleFile = false; |
15 |
17 Sep 07 |
nicklas |
452 |
try |
15 |
17 Sep 07 |
nicklas |
453 |
{ |
15 |
17 Sep 07 |
nicklas |
454 |
PushbackInputStream pin = null; |
15 |
17 Sep 07 |
nicklas |
455 |
if (in != null) |
15 |
17 Sep 07 |
nicklas |
456 |
{ |
15 |
17 Sep 07 |
nicklas |
// Read data from input stream |
15 |
17 Sep 07 |
nicklas |
458 |
pin = new PushbackInputStream(in, 5); |
15 |
17 Sep 07 |
nicklas |
459 |
in = pin; |
15 |
17 Sep 07 |
nicklas |
460 |
} |
15 |
17 Sep 07 |
nicklas |
461 |
else |
15 |
17 Sep 07 |
nicklas |
462 |
{ |
15 |
17 Sep 07 |
nicklas |
// Read from file |
15 |
17 Sep 07 |
nicklas |
464 |
pin = new PushbackInputStream(new FileInputStream(fileName), 5); |
15 |
17 Sep 07 |
nicklas |
465 |
} |
15 |
17 Sep 07 |
nicklas |
// Check if the file is an XDA file |
15 |
17 Sep 07 |
nicklas |
467 |
magicNumber = FileIO.PeekInt32_I(pin); |
15 |
17 Sep 07 |
nicklas |
468 |
isXDACompatibleFile = (magicNumber == CELFileData.CELL_FILE_MAGIC_NUMBER); |
15 |
17 Sep 07 |
nicklas |
469 |
if (isXDACompatibleFile) return; |
15 |
17 Sep 07 |
nicklas |
470 |
|
15 |
17 Sep 07 |
nicklas |
// Check if the file is a Calvin file |
15 |
17 Sep 07 |
nicklas |
472 |
magicNumber = FileIO.PeekInt8(pin); |
15 |
17 Sep 07 |
nicklas |
473 |
isCalvinCompatibleFile = magicNumber == FileHeaderReader.DATA_FILE_MAGIC_NUMBER; |
15 |
17 Sep 07 |
nicklas |
474 |
if (isCalvinCompatibleFile) return; |
15 |
17 Sep 07 |
nicklas |
475 |
|
15 |
17 Sep 07 |
nicklas |
// Check if the file is a text file |
15 |
17 Sep 07 |
nicklas |
477 |
byte[] peekInFile = new byte[5]; |
15 |
17 Sep 07 |
nicklas |
478 |
byte[] celAsBytes = "[CEL]".getBytes(); |
15 |
17 Sep 07 |
nicklas |
479 |
pin.read(peekInFile); |
15 |
17 Sep 07 |
nicklas |
480 |
pin.unread(peekInFile); |
15 |
17 Sep 07 |
nicklas |
481 |
isVersion3CompatibleFile = Arrays.equals(peekInFile, celAsBytes); |
15 |
17 Sep 07 |
nicklas |
482 |
} |
15 |
17 Sep 07 |
nicklas |
483 |
catch (Throwable t) |
15 |
17 Sep 07 |
nicklas |
484 |
{} |
15 |
17 Sep 07 |
nicklas |
485 |
} |
11 |
13 Sep 07 |
nicklas |
486 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of CELFileData */ |
11 |
13 Sep 07 |
nicklas |
488 |
public CELFileData() { |
11 |
13 Sep 07 |
nicklas |
489 |
clear(); |
11 |
13 Sep 07 |
nicklas |
490 |
} |
11 |
13 Sep 07 |
nicklas |
491 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads an XDA CEL file. |
11 |
13 Sep 07 |
nicklas |
* @param bReadHeaderOnly Flag to indicate if only the header is to be read. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
495 |
*/ |
18 |
15 Nov 07 |
nicklas |
496 |
private boolean readXDACel(boolean bReadHeaderOnly) |
18 |
15 Nov 07 |
nicklas |
497 |
{ |
18 |
15 Nov 07 |
nicklas |
// Read the header |
18 |
15 Nov 07 |
nicklas |
499 |
if (!hasReadHeaders) |
11 |
13 Sep 07 |
nicklas |
500 |
{ |
18 |
15 Nov 07 |
nicklas |
501 |
hasReadHeaders = true; |
18 |
15 Nov 07 |
nicklas |
502 |
headerResult = false; |
11 |
13 Sep 07 |
nicklas |
503 |
|
18 |
15 Nov 07 |
nicklas |
504 |
InputStream readHeaders = in; |
18 |
15 Nov 07 |
nicklas |
505 |
if (in == null) |
18 |
15 Nov 07 |
nicklas |
506 |
{ |
18 |
15 Nov 07 |
nicklas |
507 |
if (xdaReader == null) |
18 |
15 Nov 07 |
nicklas |
508 |
{ |
18 |
15 Nov 07 |
nicklas |
509 |
try |
18 |
15 Nov 07 |
nicklas |
510 |
{ |
18 |
15 Nov 07 |
nicklas |
511 |
xdaReader = new FileInputStream(fileName); |
18 |
15 Nov 07 |
nicklas |
512 |
readHeaders = xdaReader; |
18 |
15 Nov 07 |
nicklas |
513 |
} |
18 |
15 Nov 07 |
nicklas |
514 |
catch (Throwable t) |
18 |
15 Nov 07 |
nicklas |
515 |
{ |
18 |
15 Nov 07 |
nicklas |
516 |
t.printStackTrace(); |
18 |
15 Nov 07 |
nicklas |
517 |
strError = t.getMessage(); |
18 |
15 Nov 07 |
nicklas |
518 |
return false; |
18 |
15 Nov 07 |
nicklas |
519 |
} |
18 |
15 Nov 07 |
nicklas |
520 |
} |
18 |
15 Nov 07 |
nicklas |
521 |
} |
18 |
15 Nov 07 |
nicklas |
522 |
headerResult = readXDAHeader(readHeaders); |
18 |
15 Nov 07 |
nicklas |
523 |
} |
18 |
15 Nov 07 |
nicklas |
524 |
if (headerResult == false) return false; |
18 |
15 Nov 07 |
nicklas |
525 |
|
18 |
15 Nov 07 |
nicklas |
// Stop if just reading the header. |
18 |
15 Nov 07 |
nicklas |
527 |
if (bReadHeaderOnly) return true; |
11 |
13 Sep 07 |
nicklas |
528 |
|
18 |
15 Nov 07 |
nicklas |
529 |
if (hasReadData) return dataResult; |
11 |
13 Sep 07 |
nicklas |
530 |
|
18 |
15 Nov 07 |
nicklas |
531 |
hasReadData = true; |
18 |
15 Nov 07 |
nicklas |
532 |
dataResult = false; |
18 |
15 Nov 07 |
nicklas |
533 |
|
18 |
15 Nov 07 |
nicklas |
// Open the file. |
18 |
15 Nov 07 |
nicklas |
535 |
FileChannel fc = null; |
18 |
15 Nov 07 |
nicklas |
536 |
int headerOffset = 0; |
18 |
15 Nov 07 |
nicklas |
537 |
if (in != null) |
18 |
15 Nov 07 |
nicklas |
538 |
{ |
18 |
15 Nov 07 |
nicklas |
// We must copy data to a temporary file, before we can read them |
18 |
15 Nov 07 |
nicklas |
540 |
try |
11 |
13 Sep 07 |
nicklas |
541 |
{ |
19 |
15 Nov 07 |
nicklas |
542 |
tempFile = File.createTempFile(fileName, null); |
18 |
15 Nov 07 |
nicklas |
543 |
OutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile)); |
18 |
15 Nov 07 |
nicklas |
544 |
FileIO.copy(in, out); |
18 |
15 Nov 07 |
nicklas |
545 |
out.close(); |
18 |
15 Nov 07 |
nicklas |
546 |
fc = new FileInputStream(tempFile).getChannel(); |
18 |
15 Nov 07 |
nicklas |
547 |
tempFile.deleteOnExit(); |
18 |
15 Nov 07 |
nicklas |
548 |
} |
18 |
15 Nov 07 |
nicklas |
549 |
catch (Throwable t) |
18 |
15 Nov 07 |
nicklas |
550 |
{ |
18 |
15 Nov 07 |
nicklas |
551 |
t.printStackTrace(); |
18 |
15 Nov 07 |
nicklas |
552 |
strError = t.getMessage(); |
11 |
13 Sep 07 |
nicklas |
553 |
return false; |
11 |
13 Sep 07 |
nicklas |
554 |
} |
18 |
15 Nov 07 |
nicklas |
555 |
} |
18 |
15 Nov 07 |
nicklas |
556 |
else |
18 |
15 Nov 07 |
nicklas |
557 |
{ |
18 |
15 Nov 07 |
nicklas |
// Read directly from file |
18 |
15 Nov 07 |
nicklas |
559 |
try |
18 |
15 Nov 07 |
nicklas |
560 |
{ |
18 |
15 Nov 07 |
nicklas |
561 |
fc = xdaReader.getChannel(); |
18 |
15 Nov 07 |
nicklas |
562 |
} |
18 |
15 Nov 07 |
nicklas |
563 |
catch (Throwable t) |
18 |
15 Nov 07 |
nicklas |
564 |
{ |
18 |
15 Nov 07 |
nicklas |
565 |
t.printStackTrace(); |
18 |
15 Nov 07 |
nicklas |
566 |
strError = t.getMessage(); |
18 |
15 Nov 07 |
nicklas |
567 |
return false; |
18 |
15 Nov 07 |
nicklas |
568 |
} |
18 |
15 Nov 07 |
nicklas |
569 |
} |
11 |
13 Sep 07 |
nicklas |
570 |
|
18 |
15 Nov 07 |
nicklas |
// Get a pointer to the memory map. |
18 |
15 Nov 07 |
nicklas |
572 |
try |
18 |
15 Nov 07 |
nicklas |
573 |
{ |
18 |
15 Nov 07 |
nicklas |
574 |
headerOffset = (int)fc.position(); |
11 |
13 Sep 07 |
nicklas |
575 |
long fileSize = fc.size(); |
18 |
15 Nov 07 |
nicklas |
576 |
xdaBuffer = fc.map(MapMode.READ_ONLY, headerOffset, fileSize-headerOffset); |
11 |
13 Sep 07 |
nicklas |
577 |
xdaBuffer.order(ByteOrder.LITTLE_ENDIAN); |
18 |
15 Nov 07 |
nicklas |
578 |
} |
18 |
15 Nov 07 |
nicklas |
579 |
catch(Throwable t) |
18 |
15 Nov 07 |
nicklas |
580 |
{ |
18 |
15 Nov 07 |
nicklas |
581 |
t.printStackTrace(); |
18 |
15 Nov 07 |
nicklas |
582 |
strError = t.getMessage(); |
18 |
15 Nov 07 |
nicklas |
583 |
return false; |
18 |
15 Nov 07 |
nicklas |
584 |
} |
18 |
15 Nov 07 |
nicklas |
585 |
|
18 |
15 Nov 07 |
nicklas |
586 |
|
18 |
15 Nov 07 |
nicklas |
587 |
try |
18 |
15 Nov 07 |
nicklas |
588 |
{ |
11 |
13 Sep 07 |
nicklas |
589 |
|
18 |
15 Nov 07 |
nicklas |
// Read the mask and outlier sections |
11 |
13 Sep 07 |
nicklas |
591 |
int iOffset = headerData.getCells() * (CELFileEntryType.CEL_FILE_ENTRY_SIZE); |
11 |
13 Sep 07 |
nicklas |
592 |
if (bReadMaskedCells) |
11 |
13 Sep 07 |
nicklas |
593 |
{ |
11 |
13 Sep 07 |
nicklas |
594 |
ByteBuffer entry = (ByteBuffer)xdaBuffer.position(iOffset); |
11 |
13 Sep 07 |
nicklas |
595 |
maskedCells = new HashMap(); |
11 |
13 Sep 07 |
nicklas |
596 |
for (int iCell=0; iCell<headerData.getMasked(); iCell++) |
11 |
13 Sep 07 |
nicklas |
597 |
{ |
11 |
13 Sep 07 |
nicklas |
598 |
maskedCells.put(new Integer(xyToIndex(entry.getShort(),entry.getShort())), new Boolean(true)); |
11 |
13 Sep 07 |
nicklas |
599 |
} |
11 |
13 Sep 07 |
nicklas |
600 |
} |
11 |
13 Sep 07 |
nicklas |
601 |
iOffset += (headerData.getMasked()*(DataSizes.SHORT_SIZE+DataSizes.SHORT_SIZE)); |
11 |
13 Sep 07 |
nicklas |
602 |
if (bReadOutliers) |
11 |
13 Sep 07 |
nicklas |
603 |
{ |
11 |
13 Sep 07 |
nicklas |
604 |
outliers = new HashMap(); |
11 |
13 Sep 07 |
nicklas |
605 |
ByteBuffer entry = (ByteBuffer)xdaBuffer.position(iOffset); |
18 |
15 Nov 07 |
nicklas |
606 |
for (int iCell=0; iCell<headerData.getOutliers(); iCell++) |
18 |
15 Nov 07 |
nicklas |
607 |
{ |
11 |
13 Sep 07 |
nicklas |
608 |
outliers.put(new Integer(xyToIndex(entry.getShort(),entry.getShort())), new Boolean(true)); |
18 |
15 Nov 07 |
nicklas |
609 |
} |
11 |
13 Sep 07 |
nicklas |
610 |
} |
11 |
13 Sep 07 |
nicklas |
611 |
|
18 |
15 Nov 07 |
nicklas |
612 |
dataResult = true; |
11 |
13 Sep 07 |
nicklas |
613 |
return true; |
11 |
13 Sep 07 |
nicklas |
614 |
} |
11 |
13 Sep 07 |
nicklas |
615 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
616 |
{ |
18 |
15 Nov 07 |
nicklas |
617 |
t.printStackTrace(); |
11 |
13 Sep 07 |
nicklas |
618 |
strError = t.getMessage(); |
18 |
15 Nov 07 |
nicklas |
619 |
dataResult = false; |
11 |
13 Sep 07 |
nicklas |
620 |
return false; |
11 |
13 Sep 07 |
nicklas |
621 |
} |
11 |
13 Sep 07 |
nicklas |
622 |
} |
18 |
15 Nov 07 |
nicklas |
623 |
|
18 |
15 Nov 07 |
nicklas |
/** Reads the header of an XDA format CDF file. |
18 |
15 Nov 07 |
nicklas |
* @param instr The file stream object. |
18 |
15 Nov 07 |
nicklas |
* @return True if successful. |
18 |
15 Nov 07 |
nicklas |
627 |
*/ |
18 |
15 Nov 07 |
nicklas |
628 |
private boolean readXDAHeader(InputStream fis) |
18 |
15 Nov 07 |
nicklas |
629 |
{ |
18 |
15 Nov 07 |
nicklas |
630 |
try |
18 |
15 Nov 07 |
nicklas |
631 |
{ |
18 |
15 Nov 07 |
nicklas |
// Read the magic number. |
18 |
15 Nov 07 |
nicklas |
633 |
headerData = new CELFileHeaderData(); |
18 |
15 Nov 07 |
nicklas |
634 |
headerData.setMagic(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
635 |
|
18 |
15 Nov 07 |
nicklas |
// Check if new type. |
18 |
15 Nov 07 |
nicklas |
637 |
if (!(headerData.getMagic()==CELFileData.CELL_FILE_MAGIC_NUMBER)) |
18 |
15 Nov 07 |
nicklas |
638 |
{ |
18 |
15 Nov 07 |
nicklas |
639 |
strError = "The file does not appear to be the correct format."; |
18 |
15 Nov 07 |
nicklas |
640 |
return false; |
18 |
15 Nov 07 |
nicklas |
641 |
} |
18 |
15 Nov 07 |
nicklas |
642 |
|
18 |
15 Nov 07 |
nicklas |
// Read the version |
18 |
15 Nov 07 |
nicklas |
644 |
headerData.setVersion(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
645 |
|
18 |
15 Nov 07 |
nicklas |
// Read the dimensions of the array |
18 |
15 Nov 07 |
nicklas |
647 |
headerData.setRows(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
648 |
headerData.setCols(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
649 |
headerData.setCells(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
// Read the other members. |
18 |
15 Nov 07 |
nicklas |
651 |
headerData.setHeader(FileIO.ReadString_I(fis)); |
18 |
15 Nov 07 |
nicklas |
652 |
headerData.setAlg(FileIO.ReadString_I(fis)); |
18 |
15 Nov 07 |
nicklas |
653 |
headerData.setParameters(FileIO.ReadString_I(fis)); |
18 |
15 Nov 07 |
nicklas |
654 |
headerData.setMargin(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
655 |
headerData.setOutliers(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
656 |
headerData.setMasked(FileIO.ReadInt32_I(fis)); |
18 |
15 Nov 07 |
nicklas |
657 |
int ival = FileIO.ReadInt32_I(fis); // ignore this value. |
18 |
15 Nov 07 |
nicklas |
658 |
|
18 |
15 Nov 07 |
nicklas |
// Parse the information from the header. |
18 |
15 Nov 07 |
nicklas |
660 |
headerData.parseChipType(); |
18 |
15 Nov 07 |
nicklas |
661 |
headerData.parseDatHeader(); |
18 |
15 Nov 07 |
nicklas |
662 |
headerData.parseGrid(); |
18 |
15 Nov 07 |
nicklas |
663 |
} |
18 |
15 Nov 07 |
nicklas |
664 |
catch (Throwable t) |
18 |
15 Nov 07 |
nicklas |
665 |
{ |
18 |
15 Nov 07 |
nicklas |
666 |
strError = t.getMessage(); |
18 |
15 Nov 07 |
nicklas |
667 |
t.printStackTrace(); |
18 |
15 Nov 07 |
nicklas |
668 |
return false; |
18 |
15 Nov 07 |
nicklas |
669 |
} |
18 |
15 Nov 07 |
nicklas |
670 |
return true; |
18 |
15 Nov 07 |
nicklas |
671 |
} |
18 |
15 Nov 07 |
nicklas |
672 |
|
18 |
15 Nov 07 |
nicklas |
673 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads an ASCII CEL file. |
11 |
13 Sep 07 |
nicklas |
* @param bReadHeaderOnly Flag to indicate if only the header is to be read. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
677 |
*/ |
11 |
13 Sep 07 |
nicklas |
678 |
private boolean readTextCel(boolean bReadHeaderOnly) |
11 |
13 Sep 07 |
nicklas |
679 |
{ |
11 |
13 Sep 07 |
nicklas |
680 |
try |
11 |
13 Sep 07 |
nicklas |
681 |
{ |
15 |
17 Sep 07 |
nicklas |
682 |
if (textReader == null) |
15 |
17 Sep 07 |
nicklas |
683 |
{ |
15 |
17 Sep 07 |
nicklas |
684 |
if (in != null) |
15 |
17 Sep 07 |
nicklas |
685 |
{ |
15 |
17 Sep 07 |
nicklas |
686 |
textReader = new BufferedReader(new InputStreamReader(in)); |
15 |
17 Sep 07 |
nicklas |
687 |
} |
15 |
17 Sep 07 |
nicklas |
688 |
else |
15 |
17 Sep 07 |
nicklas |
689 |
{ |
15 |
17 Sep 07 |
nicklas |
// Read from file |
15 |
17 Sep 07 |
nicklas |
691 |
textReader = new BufferedReader(new FileReader(fileName)); |
15 |
17 Sep 07 |
nicklas |
692 |
} |
15 |
17 Sep 07 |
nicklas |
693 |
} |
15 |
17 Sep 07 |
nicklas |
694 |
} |
15 |
17 Sep 07 |
nicklas |
695 |
catch (Throwable t) |
15 |
17 Sep 07 |
nicklas |
696 |
{ |
15 |
17 Sep 07 |
nicklas |
697 |
strError = t.getMessage(); |
15 |
17 Sep 07 |
nicklas |
698 |
return false; |
15 |
17 Sep 07 |
nicklas |
699 |
} |
15 |
17 Sep 07 |
nicklas |
700 |
|
15 |
17 Sep 07 |
nicklas |
701 |
if (!hasReadHeaders) |
15 |
17 Sep 07 |
nicklas |
702 |
{ |
15 |
17 Sep 07 |
nicklas |
703 |
hasReadHeaders = true; |
15 |
17 Sep 07 |
nicklas |
704 |
hasReadHeaders = true; |
15 |
17 Sep 07 |
nicklas |
705 |
headerResult = readTextHeader(textReader); |
15 |
17 Sep 07 |
nicklas |
706 |
} |
15 |
17 Sep 07 |
nicklas |
707 |
if (headerResult == false) return false; |
15 |
17 Sep 07 |
nicklas |
708 |
|
15 |
17 Sep 07 |
nicklas |
// Don't continue if just reading the header. |
15 |
17 Sep 07 |
nicklas |
710 |
if (bReadHeaderOnly) return true; |
11 |
13 Sep 07 |
nicklas |
711 |
|
15 |
17 Sep 07 |
nicklas |
712 |
if (!hasReadData) |
15 |
17 Sep 07 |
nicklas |
713 |
{ |
15 |
17 Sep 07 |
nicklas |
714 |
hasReadData = true; |
15 |
17 Sep 07 |
nicklas |
715 |
dataResult = readTextData(textReader); |
15 |
17 Sep 07 |
nicklas |
716 |
} |
15 |
17 Sep 07 |
nicklas |
717 |
return dataResult; |
15 |
17 Sep 07 |
nicklas |
718 |
} |
15 |
17 Sep 07 |
nicklas |
719 |
|
15 |
17 Sep 07 |
nicklas |
720 |
private boolean readTextHeader(BufferedReader b) |
15 |
17 Sep 07 |
nicklas |
721 |
{ |
15 |
17 Sep 07 |
nicklas |
722 |
try |
15 |
17 Sep 07 |
nicklas |
723 |
{ |
11 |
13 Sep 07 |
nicklas |
// Extract a line of header |
11 |
13 Sep 07 |
nicklas |
725 |
String str = b.readLine(); |
15 |
17 Sep 07 |
nicklas |
726 |
|
11 |
13 Sep 07 |
nicklas |
//Determine the version number |
11 |
13 Sep 07 |
nicklas |
728 |
headerData = new CELFileHeaderData(); |
11 |
13 Sep 07 |
nicklas |
729 |
if (str.startsWith("[CEL]") == true) |
11 |
13 Sep 07 |
nicklas |
730 |
headerData.setVersion(3); |
11 |
13 Sep 07 |
nicklas |
731 |
else if (str.indexOf("COLS/ROWS=")==0) |
11 |
13 Sep 07 |
nicklas |
732 |
headerData.setVersion(2); |
11 |
13 Sep 07 |
nicklas |
733 |
else |
11 |
13 Sep 07 |
nicklas |
734 |
{ |
11 |
13 Sep 07 |
nicklas |
735 |
strError = "Unrecognized CEL file format."; |
11 |
13 Sep 07 |
nicklas |
736 |
return false; |
11 |
13 Sep 07 |
nicklas |
737 |
} |
15 |
17 Sep 07 |
nicklas |
738 |
|
11 |
13 Sep 07 |
nicklas |
//read and store the header |
11 |
13 Sep 07 |
nicklas |
740 |
if (headerData.getVersion() == 2) |
11 |
13 Sep 07 |
nicklas |
741 |
{ |
11 |
13 Sep 07 |
nicklas |
742 |
headerData.setHeader(str); |
11 |
13 Sep 07 |
nicklas |
743 |
str = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
744 |
headerData.setHeader(headerData.getHeader() + "\r\n" + str); |
11 |
13 Sep 07 |
nicklas |
745 |
str = b.readLine(); |
15 |
17 Sep 07 |
nicklas |
746 |
|
11 |
13 Sep 07 |
nicklas |
// Store rows and columns |
11 |
13 Sep 07 |
nicklas |
748 |
int iCols = 0; |
11 |
13 Sep 07 |
nicklas |
749 |
int iRows = 0; |
11 |
13 Sep 07 |
nicklas |
750 |
int len = ("COLS/ROWS=").length(); |
11 |
13 Sep 07 |
nicklas |
751 |
String[] s = headerData.getHeader().substring(headerData.getHeader().indexOf('=')+1).split(" "); |
11 |
13 Sep 07 |
nicklas |
752 |
if (s == null) |
11 |
13 Sep 07 |
nicklas |
753 |
s = headerData.getHeader().substring(headerData.getHeader().indexOf('=')+1).split("\t"); |
11 |
13 Sep 07 |
nicklas |
754 |
iCols = Integer.parseInt(s[0].trim()); |
11 |
13 Sep 07 |
nicklas |
755 |
iRows = Integer.parseInt(s[1].trim()); |
11 |
13 Sep 07 |
nicklas |
756 |
headerData.setCols(iCols); |
11 |
13 Sep 07 |
nicklas |
757 |
headerData.setRows(iRows); |
11 |
13 Sep 07 |
nicklas |
758 |
headerData.setCells(iCols*iRows); |
11 |
13 Sep 07 |
nicklas |
759 |
} |
11 |
13 Sep 07 |
nicklas |
760 |
else |
11 |
13 Sep 07 |
nicklas |
761 |
{ |
11 |
13 Sep 07 |
nicklas |
762 |
boolean moreSpace=true; |
11 |
13 Sep 07 |
nicklas |
//Read past [HEADER] to first line of header data |
11 |
13 Sep 07 |
nicklas |
764 |
while ((str = b.readLine()) != null) |
11 |
13 Sep 07 |
nicklas |
765 |
{ |
11 |
13 Sep 07 |
nicklas |
766 |
if (str.startsWith("[HEADER]") == true) |
11 |
13 Sep 07 |
nicklas |
767 |
break; |
11 |
13 Sep 07 |
nicklas |
768 |
} |
11 |
13 Sep 07 |
nicklas |
769 |
int iCols = 0; |
11 |
13 Sep 07 |
nicklas |
770 |
int iRows = 0; |
11 |
13 Sep 07 |
nicklas |
771 |
str = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
772 |
String[] s = str.split("="); |
11 |
13 Sep 07 |
nicklas |
773 |
iCols = Integer.parseInt(s[1].trim()); |
11 |
13 Sep 07 |
nicklas |
774 |
headerData.setCols(iCols); |
11 |
13 Sep 07 |
nicklas |
775 |
headerData.setHeader(str); |
11 |
13 Sep 07 |
nicklas |
776 |
str = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
777 |
s = str.split("="); |
11 |
13 Sep 07 |
nicklas |
778 |
iRows = Integer.parseInt(s[1].trim()); |
11 |
13 Sep 07 |
nicklas |
779 |
headerData.setRows(iRows); |
11 |
13 Sep 07 |
nicklas |
780 |
headerData.setHeader(headerData.getHeader() + "\r\n" + str); |
11 |
13 Sep 07 |
nicklas |
781 |
headerData.setCells(iRows*iCols); |
15 |
17 Sep 07 |
nicklas |
782 |
|
11 |
13 Sep 07 |
nicklas |
//Now read the rest of the header |
11 |
13 Sep 07 |
nicklas |
784 |
boolean moreHeader=true; |
11 |
13 Sep 07 |
nicklas |
785 |
while (moreHeader) |
11 |
13 Sep 07 |
nicklas |
786 |
{ |
11 |
13 Sep 07 |
nicklas |
787 |
str = b.readLine(); |
15 |
17 Sep 07 |
nicklas |
788 |
|
11 |
13 Sep 07 |
nicklas |
789 |
if (str.startsWith("DatHeader=") == true) //Last line of the header |
11 |
13 Sep 07 |
nicklas |
790 |
{ |
11 |
13 Sep 07 |
nicklas |
791 |
headerData.setDatHeader(str.substring(10)); |
11 |
13 Sep 07 |
nicklas |
792 |
} |
15 |
17 Sep 07 |
nicklas |
793 |
|
11 |
13 Sep 07 |
nicklas |
794 |
if (str.startsWith("Algorithm=") ==true) //Last line of the header |
11 |
13 Sep 07 |
nicklas |
795 |
{ |
11 |
13 Sep 07 |
nicklas |
796 |
headerData.setAlg(str.substring(10)); |
11 |
13 Sep 07 |
nicklas |
797 |
} |
15 |
17 Sep 07 |
nicklas |
798 |
|
11 |
13 Sep 07 |
nicklas |
799 |
if (str.startsWith("AlgorithmParameters=") == true) //Last line of the header |
11 |
13 Sep 07 |
nicklas |
800 |
{ |
11 |
13 Sep 07 |
nicklas |
801 |
headerData.setParameters(str.substring(20)); |
11 |
13 Sep 07 |
nicklas |
802 |
moreHeader=false; |
11 |
13 Sep 07 |
nicklas |
803 |
} |
11 |
13 Sep 07 |
nicklas |
804 |
headerData.setHeader(headerData.getHeader() + "\r\n" + str); |
11 |
13 Sep 07 |
nicklas |
805 |
} |
11 |
13 Sep 07 |
nicklas |
806 |
} |
11 |
13 Sep 07 |
nicklas |
807 |
|
11 |
13 Sep 07 |
nicklas |
// Parse information from the header string. |
11 |
13 Sep 07 |
nicklas |
809 |
headerData.parseChipType(); |
11 |
13 Sep 07 |
nicklas |
810 |
headerData.parseMargin(); |
11 |
13 Sep 07 |
nicklas |
811 |
headerData.parseGrid(); |
15 |
17 Sep 07 |
nicklas |
812 |
} |
15 |
17 Sep 07 |
nicklas |
813 |
catch (Throwable t) |
15 |
17 Sep 07 |
nicklas |
814 |
{ |
15 |
17 Sep 07 |
nicklas |
815 |
return false; |
15 |
17 Sep 07 |
nicklas |
816 |
} |
15 |
17 Sep 07 |
nicklas |
817 |
return true; |
15 |
17 Sep 07 |
nicklas |
818 |
} |
15 |
17 Sep 07 |
nicklas |
819 |
|
15 |
17 Sep 07 |
nicklas |
820 |
private boolean readTextData(BufferedReader b) |
15 |
17 Sep 07 |
nicklas |
821 |
{ |
15 |
17 Sep 07 |
nicklas |
822 |
try |
15 |
17 Sep 07 |
nicklas |
823 |
{ |
11 |
13 Sep 07 |
nicklas |
// Create memory for Mean data. |
11 |
13 Sep 07 |
nicklas |
825 |
entries = new Vector(); |
11 |
13 Sep 07 |
nicklas |
826 |
entries.setSize(headerData.getCells()); |
15 |
17 Sep 07 |
nicklas |
827 |
|
11 |
13 Sep 07 |
nicklas |
828 |
int t_x,t_y,t_pixels; |
11 |
13 Sep 07 |
nicklas |
829 |
float t_mean,t_stdv; |
15 |
17 Sep 07 |
nicklas |
830 |
|
11 |
13 Sep 07 |
nicklas |
// Read v2 CEL files |
11 |
13 Sep 07 |
nicklas |
832 |
if (headerData.getVersion() == 2) |
11 |
13 Sep 07 |
nicklas |
833 |
{ |
11 |
13 Sep 07 |
nicklas |
// Write the Mean data |
11 |
13 Sep 07 |
nicklas |
835 |
CELFileEntryType entry; |
11 |
13 Sep 07 |
nicklas |
836 |
for (int iCell=0; iCell < headerData.getCells(); iCell++) |
11 |
13 Sep 07 |
nicklas |
837 |
{ |
11 |
13 Sep 07 |
nicklas |
838 |
String[] s = b.readLine().split("\t"); |
11 |
13 Sep 07 |
nicklas |
839 |
entry = new CELFileEntryType(); |
11 |
13 Sep 07 |
nicklas |
840 |
entry.setIntensity(Float.parseFloat(s[2].trim())); |
11 |
13 Sep 07 |
nicklas |
841 |
entry.setStdv(Float.parseFloat(s[3].trim())); |
11 |
13 Sep 07 |
nicklas |
842 |
entry.setPixels(Short.parseShort(s[4].trim())); |
11 |
13 Sep 07 |
nicklas |
843 |
entries.set(iCell, entry); |
11 |
13 Sep 07 |
nicklas |
844 |
} |
11 |
13 Sep 07 |
nicklas |
845 |
} |
11 |
13 Sep 07 |
nicklas |
846 |
else |
11 |
13 Sep 07 |
nicklas |
847 |
{ |
15 |
17 Sep 07 |
nicklas |
848 |
String str; |
11 |
13 Sep 07 |
nicklas |
//Advance to the beginning of the Mean data |
11 |
13 Sep 07 |
nicklas |
850 |
while ((str = b.readLine()) != null) |
11 |
13 Sep 07 |
nicklas |
851 |
{ |
11 |
13 Sep 07 |
nicklas |
852 |
if (str.startsWith("[INTENSITY]") == true) |
11 |
13 Sep 07 |
nicklas |
853 |
break; |
11 |
13 Sep 07 |
nicklas |
854 |
} |
11 |
13 Sep 07 |
nicklas |
855 |
str = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
856 |
str = b.readLine(); |
15 |
17 Sep 07 |
nicklas |
857 |
|
11 |
13 Sep 07 |
nicklas |
//Read the Mean data |
11 |
13 Sep 07 |
nicklas |
859 |
CELFileEntryType entry; |
11 |
13 Sep 07 |
nicklas |
860 |
for (int iCell=0; iCell < headerData.getCells(); iCell++) |
11 |
13 Sep 07 |
nicklas |
861 |
{ |
11 |
13 Sep 07 |
nicklas |
862 |
String[] s = b.readLine().split("\t"); |
11 |
13 Sep 07 |
nicklas |
863 |
entry = new CELFileEntryType(); |
11 |
13 Sep 07 |
nicklas |
864 |
entry.setIntensity(Float.parseFloat(s[2].trim())); |
11 |
13 Sep 07 |
nicklas |
865 |
entry.setStdv(Float.parseFloat(s[3].trim())); |
11 |
13 Sep 07 |
nicklas |
866 |
entry.setPixels(Short.parseShort(s[4].trim())); |
11 |
13 Sep 07 |
nicklas |
867 |
entries.set(iCell, entry); |
11 |
13 Sep 07 |
nicklas |
868 |
} |
15 |
17 Sep 07 |
nicklas |
869 |
|
11 |
13 Sep 07 |
nicklas |
//Advance to the Masked data |
11 |
13 Sep 07 |
nicklas |
871 |
while ((str = b.readLine()) != null) |
11 |
13 Sep 07 |
nicklas |
872 |
{ |
11 |
13 Sep 07 |
nicklas |
873 |
if (str.startsWith("[MASKS]") == true) |
11 |
13 Sep 07 |
nicklas |
874 |
break; |
11 |
13 Sep 07 |
nicklas |
875 |
} |
11 |
13 Sep 07 |
nicklas |
876 |
if (str == null) |
11 |
13 Sep 07 |
nicklas |
877 |
return true; |
15 |
17 Sep 07 |
nicklas |
878 |
|
15 |
17 Sep 07 |
nicklas |
879 |
|
11 |
13 Sep 07 |
nicklas |
//Read the masked data |
11 |
13 Sep 07 |
nicklas |
881 |
if (bReadMaskedCells) |
11 |
13 Sep 07 |
nicklas |
882 |
{ |
11 |
13 Sep 07 |
nicklas |
//Read number of masked cells |
11 |
13 Sep 07 |
nicklas |
884 |
str = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
885 |
int nMasked = Integer.parseInt(str.substring( str.indexOf('=')+1 ).trim()); |
11 |
13 Sep 07 |
nicklas |
886 |
maskedCells = new HashMap(); |
11 |
13 Sep 07 |
nicklas |
887 |
headerData.setMasked(nMasked); |
11 |
13 Sep 07 |
nicklas |
888 |
str = b.readLine(); // skip over the header |
11 |
13 Sep 07 |
nicklas |
889 |
for (int iCell=0; iCell<nMasked; iCell++) |
11 |
13 Sep 07 |
nicklas |
890 |
{ |
11 |
13 Sep 07 |
nicklas |
891 |
String[] s = b.readLine().split("\t"); |
11 |
13 Sep 07 |
nicklas |
892 |
maskedCells.put(new Integer(xyToIndex(Integer.parseInt(s[0].trim()),Integer.parseInt(s[1].trim()))), new Boolean(true)); |
11 |
13 Sep 07 |
nicklas |
893 |
} |
11 |
13 Sep 07 |
nicklas |
894 |
} |
11 |
13 Sep 07 |
nicklas |
895 |
else |
11 |
13 Sep 07 |
nicklas |
896 |
headerData.setMasked(0); |
15 |
17 Sep 07 |
nicklas |
897 |
|
15 |
17 Sep 07 |
nicklas |
898 |
|
11 |
13 Sep 07 |
nicklas |
//Advance to the Masked data |
11 |
13 Sep 07 |
nicklas |
900 |
while ((str = b.readLine()) != null) |
11 |
13 Sep 07 |
nicklas |
901 |
{ |
11 |
13 Sep 07 |
nicklas |
902 |
if (str.startsWith("[OUTLIERS]") == true) |
11 |
13 Sep 07 |
nicklas |
903 |
break; |
11 |
13 Sep 07 |
nicklas |
904 |
} |
11 |
13 Sep 07 |
nicklas |
905 |
if (str == null) |
11 |
13 Sep 07 |
nicklas |
906 |
return true; |
15 |
17 Sep 07 |
nicklas |
907 |
|
11 |
13 Sep 07 |
nicklas |
//Read the outlier data |
11 |
13 Sep 07 |
nicklas |
909 |
if (bReadOutliers) |
11 |
13 Sep 07 |
nicklas |
910 |
{ |
11 |
13 Sep 07 |
nicklas |
//Read number of outlier cells |
11 |
13 Sep 07 |
nicklas |
912 |
str = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
913 |
int nOutliers = Integer.parseInt(str.substring(str.indexOf('=')+1).trim()); |
11 |
13 Sep 07 |
nicklas |
914 |
outliers = new HashMap(); |
11 |
13 Sep 07 |
nicklas |
915 |
headerData.setOutliers(nOutliers); |
11 |
13 Sep 07 |
nicklas |
916 |
str = b.readLine(); // skip over the header |
11 |
13 Sep 07 |
nicklas |
917 |
for (int iCell=0; iCell<nOutliers; iCell++) |
11 |
13 Sep 07 |
nicklas |
918 |
{ |
11 |
13 Sep 07 |
nicklas |
919 |
String[] s = b.readLine().split("\t"); |
11 |
13 Sep 07 |
nicklas |
920 |
outliers.put(new Integer(xyToIndex(Integer.parseInt(s[0].trim()),Integer.parseInt(s[1].trim()))), new Boolean(true)); |
11 |
13 Sep 07 |
nicklas |
921 |
} |
11 |
13 Sep 07 |
nicklas |
922 |
} |
11 |
13 Sep 07 |
nicklas |
923 |
else |
11 |
13 Sep 07 |
nicklas |
924 |
headerData.setOutliers(0); |
15 |
17 Sep 07 |
nicklas |
925 |
|
11 |
13 Sep 07 |
nicklas |
926 |
} |
11 |
13 Sep 07 |
nicklas |
927 |
} |
11 |
13 Sep 07 |
nicklas |
928 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
929 |
{ |
11 |
13 Sep 07 |
nicklas |
930 |
return false; |
11 |
13 Sep 07 |
nicklas |
931 |
} |
15 |
17 Sep 07 |
nicklas |
932 |
return true; |
11 |
13 Sep 07 |
nicklas |
933 |
} |
15 |
17 Sep 07 |
nicklas |
934 |
|
19 |
15 Nov 07 |
nicklas |
935 |
@Override |
19 |
15 Nov 07 |
nicklas |
936 |
protected void finalize() |
19 |
15 Nov 07 |
nicklas |
937 |
throws Throwable |
19 |
15 Nov 07 |
nicklas |
938 |
{ |
19 |
15 Nov 07 |
nicklas |
939 |
super.finalize(); |
19 |
15 Nov 07 |
nicklas |
940 |
if (tempFile != null && tempFile.exists()) |
19 |
15 Nov 07 |
nicklas |
941 |
{ |
19 |
15 Nov 07 |
nicklas |
942 |
tempFile.delete(); |
19 |
15 Nov 07 |
nicklas |
943 |
} |
19 |
15 Nov 07 |
nicklas |
944 |
} |
19 |
15 Nov 07 |
nicklas |
945 |
|
11 |
13 Sep 07 |
nicklas |
946 |
} |
11 |
13 Sep 07 |
nicklas |
947 |
|
11 |
13 Sep 07 |
nicklas |
948 |
|