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.calvin.parsers; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import java.io.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import affymetrix.calvin.data.*; |
11 |
13 Sep 07 |
nicklas |
25 |
import affymetrix.calvin.parameter.*; |
11 |
13 Sep 07 |
nicklas |
26 |
|
11 |
13 Sep 07 |
nicklas |
/** This class reads the all DataSetHeader information associated with a DataGroup from a file. */ |
11 |
13 Sep 07 |
nicklas |
28 |
public class DataSetHeaderReader { |
11 |
13 Sep 07 |
nicklas |
29 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of DataSetHeaderReader */ |
11 |
13 Sep 07 |
nicklas |
31 |
public DataSetHeaderReader() { |
11 |
13 Sep 07 |
nicklas |
32 |
} |
11 |
13 Sep 07 |
nicklas |
33 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the minimum DataSetHeader information for all DataSets associated with a DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the first DataSetHeader in a DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to which to add the DataSetHeader information. |
11 |
13 Sep 07 |
nicklas |
* @param dataSetCnt Number of DataSets in the DataGroup. |
11 |
13 Sep 07 |
nicklas |
38 |
*/ |
11 |
13 Sep 07 |
nicklas |
39 |
public void readAllMinimumInfo(FileInputStream fileStream, DataGroupHeader dch, int dataSetCnt) { |
11 |
13 Sep 07 |
nicklas |
// Get the first dataSet offset |
11 |
13 Sep 07 |
nicklas |
41 |
int nextDataSetFilePos = dch.getDataSetPos(); |
11 |
13 Sep 07 |
nicklas |
42 |
|
11 |
13 Sep 07 |
nicklas |
43 |
for (int i = 0; i < dataSetCnt; ++i) |
11 |
13 Sep 07 |
nicklas |
44 |
{ |
11 |
13 Sep 07 |
nicklas |
45 |
DataSetHeader dph = new DataSetHeader(); |
11 |
13 Sep 07 |
nicklas |
46 |
|
11 |
13 Sep 07 |
nicklas |
// Move to the indicated position in the file |
11 |
13 Sep 07 |
nicklas |
48 |
try |
11 |
13 Sep 07 |
nicklas |
49 |
{ |
11 |
13 Sep 07 |
nicklas |
50 |
fileStream.getChannel().position(nextDataSetFilePos); |
11 |
13 Sep 07 |
nicklas |
51 |
} |
11 |
13 Sep 07 |
nicklas |
52 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
53 |
{ |
11 |
13 Sep 07 |
nicklas |
54 |
} |
11 |
13 Sep 07 |
nicklas |
55 |
nextDataSetFilePos = readMinimumInfo(fileStream, dph); |
11 |
13 Sep 07 |
nicklas |
56 |
|
11 |
13 Sep 07 |
nicklas |
// Add the DataSetHeader to the file header |
11 |
13 Sep 07 |
nicklas |
58 |
dch.addDataSetHdr(dph); |
11 |
13 Sep 07 |
nicklas |
59 |
} |
11 |
13 Sep 07 |
nicklas |
60 |
} |
11 |
13 Sep 07 |
nicklas |
61 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the complete DataSetHeader information for all DataSets associated with a DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the first DataSetHeader in a DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to which to add the DataSetHeader information. |
11 |
13 Sep 07 |
nicklas |
* @param dataSetCnt Number of DataSets in the DataGroup. |
11 |
13 Sep 07 |
nicklas |
66 |
*/ |
11 |
13 Sep 07 |
nicklas |
67 |
public void readAll(FileInputStream fileStream, DataGroupHeader dch, int dataSetCnt) { |
11 |
13 Sep 07 |
nicklas |
68 |
|
11 |
13 Sep 07 |
nicklas |
// Get the first dataSet offset |
11 |
13 Sep 07 |
nicklas |
70 |
int nextDataSetFilePos = dch.getDataSetPos(); |
11 |
13 Sep 07 |
nicklas |
71 |
|
11 |
13 Sep 07 |
nicklas |
72 |
for (int i = 0; i < dataSetCnt; ++i) |
11 |
13 Sep 07 |
nicklas |
73 |
{ |
11 |
13 Sep 07 |
nicklas |
74 |
DataSetHeader dph = new DataSetHeader(); |
11 |
13 Sep 07 |
nicklas |
75 |
|
11 |
13 Sep 07 |
nicklas |
// Move to the indicated position in the file |
11 |
13 Sep 07 |
nicklas |
77 |
try |
11 |
13 Sep 07 |
nicklas |
78 |
{ |
11 |
13 Sep 07 |
nicklas |
79 |
fileStream.getChannel().position(nextDataSetFilePos); |
11 |
13 Sep 07 |
nicklas |
80 |
} |
11 |
13 Sep 07 |
nicklas |
81 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
82 |
{ |
11 |
13 Sep 07 |
nicklas |
83 |
} |
11 |
13 Sep 07 |
nicklas |
84 |
|
11 |
13 Sep 07 |
nicklas |
85 |
nextDataSetFilePos = read(fileStream, dph); |
11 |
13 Sep 07 |
nicklas |
86 |
|
11 |
13 Sep 07 |
nicklas |
// Add the DataSetHeader to the file header |
11 |
13 Sep 07 |
nicklas |
88 |
dch.addDataSetHdr(dph); |
11 |
13 Sep 07 |
nicklas |
89 |
} |
11 |
13 Sep 07 |
nicklas |
90 |
} |
11 |
13 Sep 07 |
nicklas |
91 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the minimum DataSetHeader information. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @return The file position of the next DataSet. |
11 |
13 Sep 07 |
nicklas |
96 |
*/ |
11 |
13 Sep 07 |
nicklas |
97 |
public int readMinimumInfo(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
98 |
readDataSetStartFilePos(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
99 |
readDataFilePos(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
100 |
int nextDataSetFilePos = readNextDataSetFilePos(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
101 |
readName(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
102 |
return nextDataSetFilePos; |
11 |
13 Sep 07 |
nicklas |
103 |
} |
11 |
13 Sep 07 |
nicklas |
104 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the complete DataSetHeader information. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @return The file position of the next DataSet. |
11 |
13 Sep 07 |
nicklas |
109 |
*/ |
11 |
13 Sep 07 |
nicklas |
110 |
public int read(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
111 |
readDataSetStartFilePos(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
112 |
readDataFilePos(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
113 |
int nextDataSetFilePos = readNextDataSetFilePos(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
114 |
readName(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
115 |
readParameters(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
116 |
readColumns(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
117 |
readRowCount(fileStream, dsh); |
11 |
13 Sep 07 |
nicklas |
118 |
return nextDataSetFilePos; |
11 |
13 Sep 07 |
nicklas |
119 |
|
11 |
13 Sep 07 |
nicklas |
120 |
} |
11 |
13 Sep 07 |
nicklas |
121 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the file position of the start of the DataSet. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
125 |
*/ |
11 |
13 Sep 07 |
nicklas |
126 |
protected void readDataSetStartFilePos(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
127 |
try |
11 |
13 Sep 07 |
nicklas |
128 |
{ |
11 |
13 Sep 07 |
nicklas |
129 |
int pos = (int)fileStream.getChannel().position(); |
11 |
13 Sep 07 |
nicklas |
130 |
dsh.setHeaderStartFilePos(pos); } |
11 |
13 Sep 07 |
nicklas |
131 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
132 |
{ |
11 |
13 Sep 07 |
nicklas |
133 |
} |
11 |
13 Sep 07 |
nicklas |
134 |
} |
11 |
13 Sep 07 |
nicklas |
135 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the file position to the start of the data. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the data file position. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
139 |
*/ |
11 |
13 Sep 07 |
nicklas |
140 |
protected void readDataFilePos(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
141 |
dsh.setDataStartFilePos(FileInput.ReadUInt32(fileStream)); |
11 |
13 Sep 07 |
nicklas |
142 |
} |
11 |
13 Sep 07 |
nicklas |
143 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the file position to the next DataSet. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the next DataSet file position. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @return The file position of the next data set. |
11 |
13 Sep 07 |
nicklas |
148 |
*/ |
11 |
13 Sep 07 |
nicklas |
149 |
protected int readNextDataSetFilePos(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
150 |
int nextDataSetFilePos = FileInput.ReadUInt32(fileStream); |
11 |
13 Sep 07 |
nicklas |
151 |
dsh.setNextSetFilePos(nextDataSetFilePos); |
11 |
13 Sep 07 |
nicklas |
152 |
return nextDataSetFilePos; |
11 |
13 Sep 07 |
nicklas |
153 |
} |
11 |
13 Sep 07 |
nicklas |
154 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the DataSetHeader name. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader name. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
158 |
*/ |
11 |
13 Sep 07 |
nicklas |
159 |
protected void readName(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
160 |
String name = FileInput.ReadString16(fileStream); |
11 |
13 Sep 07 |
nicklas |
161 |
dsh.setName(name); |
11 |
13 Sep 07 |
nicklas |
162 |
} |
11 |
13 Sep 07 |
nicklas |
163 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the parameter list (name-value-type). |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader parameter list count. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
167 |
*/ |
11 |
13 Sep 07 |
nicklas |
168 |
protected void readParameters(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
169 |
int params = FileInput.ReadUInt32(fileStream); |
11 |
13 Sep 07 |
nicklas |
170 |
for (int iparam = 0; iparam < params; ++iparam) |
11 |
13 Sep 07 |
nicklas |
171 |
{ |
11 |
13 Sep 07 |
nicklas |
172 |
String paramName = FileInput.ReadString16(fileStream); |
11 |
13 Sep 07 |
nicklas |
173 |
byte[] mimeValue = FileInput.ReadBlob(fileStream); |
11 |
13 Sep 07 |
nicklas |
174 |
String paramType = FileInput.ReadString16(fileStream); |
11 |
13 Sep 07 |
nicklas |
175 |
ParameterNameValue nvt= new ParameterNameValue(paramName, mimeValue, mimeValue.length, paramType); |
11 |
13 Sep 07 |
nicklas |
176 |
dsh.addNameValParam(nvt); |
11 |
13 Sep 07 |
nicklas |
177 |
} |
11 |
13 Sep 07 |
nicklas |
178 |
} |
11 |
13 Sep 07 |
nicklas |
179 |
|
11 |
13 Sep 07 |
nicklas |
/** Read column information. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader column count. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
183 |
*/ |
11 |
13 Sep 07 |
nicklas |
184 |
protected void readColumns(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
// Read the number of columns |
11 |
13 Sep 07 |
nicklas |
186 |
int columns = FileInput.ReadUInt32(fileStream); |
11 |
13 Sep 07 |
nicklas |
187 |
|
11 |
13 Sep 07 |
nicklas |
188 |
for (int icol = 0; icol < columns; ++icol) |
11 |
13 Sep 07 |
nicklas |
189 |
{ |
11 |
13 Sep 07 |
nicklas |
// Read the name |
11 |
13 Sep 07 |
nicklas |
191 |
String name = FileInput.ReadString16(fileStream); |
11 |
13 Sep 07 |
nicklas |
// Read the type |
11 |
13 Sep 07 |
nicklas |
193 |
int type = (int) FileInput.ReadInt8(fileStream); |
11 |
13 Sep 07 |
nicklas |
// Read the size |
11 |
13 Sep 07 |
nicklas |
195 |
int size = FileInput.ReadInt32(fileStream); |
11 |
13 Sep 07 |
nicklas |
196 |
|
11 |
13 Sep 07 |
nicklas |
197 |
dsh.addColumn(new ColumnInfo(name, type, size)); |
11 |
13 Sep 07 |
nicklas |
198 |
} |
11 |
13 Sep 07 |
nicklas |
199 |
} |
11 |
13 Sep 07 |
nicklas |
200 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the number of rows. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataSetHeader row count. |
11 |
13 Sep 07 |
nicklas |
* @param dsh Reference to the DataSetHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
204 |
*/ |
11 |
13 Sep 07 |
nicklas |
205 |
protected void readRowCount(FileInputStream fileStream, DataSetHeader dsh) { |
11 |
13 Sep 07 |
nicklas |
206 |
int numRows = FileInput.ReadInt32(fileStream); |
11 |
13 Sep 07 |
nicklas |
207 |
dsh.setRowCnt(numRows); |
11 |
13 Sep 07 |
nicklas |
208 |
} |
11 |
13 Sep 07 |
nicklas |
209 |
|
11 |
13 Sep 07 |
nicklas |
210 |
} |