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 |
|
11 |
13 Sep 07 |
nicklas |
/** This class reads the all the DataGroupHeader information from a file into a FileHeader object.*/ |
11 |
13 Sep 07 |
nicklas |
27 |
public class DataGroupHeaderReader { |
11 |
13 Sep 07 |
nicklas |
28 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of DataGroupHeaderReader */ |
11 |
13 Sep 07 |
nicklas |
30 |
public DataGroupHeaderReader() { |
11 |
13 Sep 07 |
nicklas |
31 |
} |
11 |
13 Sep 07 |
nicklas |
32 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads all the DataGroupHeaders in a file and the minimum information for each DataSetHeader in every DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file. |
11 |
13 Sep 07 |
nicklas |
* @param fh FileHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @param dataGroupCnt Number of DataGroup in the file. |
11 |
13 Sep 07 |
nicklas |
37 |
*/ |
11 |
13 Sep 07 |
nicklas |
38 |
public void readAllMinimumInfo(FileInputStream fileStream, FileHeader fh, int dataGroupCnt) { |
11 |
13 Sep 07 |
nicklas |
// Get the first data group offset |
11 |
13 Sep 07 |
nicklas |
40 |
int nextDataGroupFilePos = fh.getFirstDataGroupFilePos(); |
11 |
13 Sep 07 |
nicklas |
41 |
|
11 |
13 Sep 07 |
nicklas |
42 |
for (int i = 0; i < dataGroupCnt; ++i) |
11 |
13 Sep 07 |
nicklas |
43 |
{ |
11 |
13 Sep 07 |
nicklas |
// Read the DataGroupHeader |
11 |
13 Sep 07 |
nicklas |
45 |
DataGroupHeader dch = new DataGroupHeader(); |
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(nextDataGroupFilePos); |
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 |
nextDataGroupFilePos = readMinimumInfo(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
56 |
fh.addDataGroupHdr(dch); |
11 |
13 Sep 07 |
nicklas |
57 |
} |
11 |
13 Sep 07 |
nicklas |
58 |
} |
11 |
13 Sep 07 |
nicklas |
59 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads all the DataGroupHeaders in a file and all information for each DataSetHeader in every DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file. |
11 |
13 Sep 07 |
nicklas |
* @param fh FileHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @param dataGroupCnt Number of DataGroup in the file. |
11 |
13 Sep 07 |
nicklas |
64 |
*/ |
11 |
13 Sep 07 |
nicklas |
65 |
public void readAll(FileInputStream fileStream, FileHeader fh, int dataGroupCnt) { |
11 |
13 Sep 07 |
nicklas |
// Get the first data group offset |
11 |
13 Sep 07 |
nicklas |
67 |
int nextDataGroupFilePos = fh.getFirstDataGroupFilePos(); |
11 |
13 Sep 07 |
nicklas |
68 |
|
11 |
13 Sep 07 |
nicklas |
69 |
for (int i = 0; i < dataGroupCnt; ++i) |
11 |
13 Sep 07 |
nicklas |
70 |
{ |
11 |
13 Sep 07 |
nicklas |
// Read the DataGroupHeader |
11 |
13 Sep 07 |
nicklas |
72 |
DataGroupHeader dch = new DataGroupHeader(); |
11 |
13 Sep 07 |
nicklas |
73 |
|
11 |
13 Sep 07 |
nicklas |
// Move to the indicated position in the file |
11 |
13 Sep 07 |
nicklas |
75 |
try |
11 |
13 Sep 07 |
nicklas |
76 |
{ |
11 |
13 Sep 07 |
nicklas |
77 |
fileStream.getChannel().position(nextDataGroupFilePos); |
11 |
13 Sep 07 |
nicklas |
78 |
} |
11 |
13 Sep 07 |
nicklas |
79 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
80 |
{ |
11 |
13 Sep 07 |
nicklas |
81 |
} |
11 |
13 Sep 07 |
nicklas |
82 |
nextDataGroupFilePos = read(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
83 |
fh.addDataGroupHdr(dch); |
11 |
13 Sep 07 |
nicklas |
84 |
} |
11 |
13 Sep 07 |
nicklas |
85 |
} |
11 |
13 Sep 07 |
nicklas |
86 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the DataGroupHeader and the minimum information for all DataSetHeaders associated with this DataGroupHeader |
11 |
13 Sep 07 |
nicklas |
* from the file. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @return The file position of the next data group |
11 |
13 Sep 07 |
nicklas |
92 |
*/ |
11 |
13 Sep 07 |
nicklas |
93 |
public int readMinimumInfo(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
94 |
int dataSetCnt = readHeader(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
95 |
|
11 |
13 Sep 07 |
nicklas |
// Read the DataSets |
11 |
13 Sep 07 |
nicklas |
97 |
DataSetHeaderReader dphReader = new DataSetHeaderReader(); |
11 |
13 Sep 07 |
nicklas |
98 |
dphReader.readAllMinimumInfo(fileStream, dch, dataSetCnt); |
11 |
13 Sep 07 |
nicklas |
99 |
return dch.getNextGroupPos(); |
11 |
13 Sep 07 |
nicklas |
100 |
} |
11 |
13 Sep 07 |
nicklas |
101 |
|
11 |
13 Sep 07 |
nicklas |
/** Read the DataGroupHeader and all DataSetHeaders associated with this DataGroupHeader |
11 |
13 Sep 07 |
nicklas |
* from the file. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to fill. |
11 |
13 Sep 07 |
nicklas |
* @return The file position of the next data group |
11 |
13 Sep 07 |
nicklas |
107 |
*/ |
11 |
13 Sep 07 |
nicklas |
108 |
public int read(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
109 |
int dataSetCnt = readHeader(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
110 |
|
11 |
13 Sep 07 |
nicklas |
// Read the DataSets |
11 |
13 Sep 07 |
nicklas |
112 |
DataSetHeaderReader dphReader = new DataSetHeaderReader(); |
11 |
13 Sep 07 |
nicklas |
113 |
dphReader.readAll(fileStream, dch, dataSetCnt); |
11 |
13 Sep 07 |
nicklas |
114 |
return dch.getNextGroupPos(); |
11 |
13 Sep 07 |
nicklas |
115 |
} |
11 |
13 Sep 07 |
nicklas |
116 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the DataGroupHeader from the file. Doesn't read all DataSetHeader information. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of a DataGroupHeader in the file. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to fill with the header information. |
11 |
13 Sep 07 |
nicklas |
* @return The number of DataSetHeaders associated with the current DataGroupHeader. |
11 |
13 Sep 07 |
nicklas |
121 |
*/ |
11 |
13 Sep 07 |
nicklas |
122 |
public int readHeader(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
123 |
readNextDataGroupFilePos(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
124 |
readFirstDataSetFilePos(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
125 |
int dataSetCnt = readDataSetCnt(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
126 |
readDataGroupName(fileStream, dch); |
11 |
13 Sep 07 |
nicklas |
127 |
return dataSetCnt; |
11 |
13 Sep 07 |
nicklas |
128 |
} |
11 |
13 Sep 07 |
nicklas |
129 |
|
11 |
13 Sep 07 |
nicklas |
/** reads the file position of the next DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the file position of a DataGroupHeader. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object in which to write the file position. |
11 |
13 Sep 07 |
nicklas |
133 |
*/ |
11 |
13 Sep 07 |
nicklas |
134 |
protected void readNextDataGroupFilePos(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
135 |
dch.setNextGroupPos(FileInput.ReadUInt32(fileStream)); |
11 |
13 Sep 07 |
nicklas |
136 |
} |
11 |
13 Sep 07 |
nicklas |
137 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the file position of the first DataSet associated with the current DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the file position of the first DataSetHeader in the DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to which to add the DataSetHeader information. |
11 |
13 Sep 07 |
nicklas |
141 |
*/ |
11 |
13 Sep 07 |
nicklas |
142 |
protected void readFirstDataSetFilePos(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
143 |
dch.setDataSetPos(FileInput.ReadUInt32(fileStream)); |
11 |
13 Sep 07 |
nicklas |
144 |
} |
11 |
13 Sep 07 |
nicklas |
145 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the number of DataSets associated with the current DataGroup. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataGroupHeader count. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object in which to add the DataSet count. |
11 |
13 Sep 07 |
nicklas |
149 |
*/ |
11 |
13 Sep 07 |
nicklas |
150 |
protected int readDataSetCnt(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
151 |
return FileInput.ReadUInt32(fileStream); |
11 |
13 Sep 07 |
nicklas |
152 |
|
11 |
13 Sep 07 |
nicklas |
153 |
} |
11 |
13 Sep 07 |
nicklas |
154 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the number of DataGroup name. |
11 |
13 Sep 07 |
nicklas |
* @param fileStream Open fstream positioned at the start of the DataGroupHeader name. |
11 |
13 Sep 07 |
nicklas |
* @param dch DataGroupHeader object to which to add the DataGroup name. |
11 |
13 Sep 07 |
nicklas |
158 |
*/ |
11 |
13 Sep 07 |
nicklas |
159 |
protected void readDataGroupName(FileInputStream fileStream, DataGroupHeader dch) { |
11 |
13 Sep 07 |
nicklas |
160 |
dch.setName(FileInput.ReadString16(fileStream)); |
11 |
13 Sep 07 |
nicklas |
161 |
|
11 |
13 Sep 07 |
nicklas |
162 |
} |
11 |
13 Sep 07 |
nicklas |
163 |
|
11 |
13 Sep 07 |
nicklas |
164 |
} |