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.exp; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import affymetrix.gcos.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import java.util.*; |
11 |
13 Sep 07 |
nicklas |
25 |
import java.io.*; |
11 |
13 Sep 07 |
nicklas |
26 |
|
11 |
13 Sep 07 |
nicklas |
/** Provides parsing and storage for EXP file data. */ |
11 |
13 Sep 07 |
nicklas |
28 |
public class EXPFileData { |
11 |
13 Sep 07 |
nicklas |
29 |
|
11 |
13 Sep 07 |
nicklas |
/** The first line of an EXP file */ |
11 |
13 Sep 07 |
nicklas |
31 |
private static final String EXP_HEADER_LINE_1 = "Affymetrix GeneChip Experiment Information"; |
11 |
13 Sep 07 |
nicklas |
32 |
|
11 |
13 Sep 07 |
nicklas |
/** The second line of an EXP file */ |
11 |
13 Sep 07 |
nicklas |
34 |
private static final String EXP_HEADER_LINE_2 = "Version"; |
11 |
13 Sep 07 |
nicklas |
35 |
|
11 |
13 Sep 07 |
nicklas |
/** The sample information section name. */ |
11 |
13 Sep 07 |
nicklas |
37 |
private static final String SAMPLE_SECTION_NAME = "[Sample Info]"; |
11 |
13 Sep 07 |
nicklas |
38 |
|
11 |
13 Sep 07 |
nicklas |
/** The scanner section name. */ |
11 |
13 Sep 07 |
nicklas |
40 |
private static final String SCANNER_SECTION_NAME = "[Scanner]"; |
11 |
13 Sep 07 |
nicklas |
41 |
|
11 |
13 Sep 07 |
nicklas |
/** The fluidics section name. */ |
11 |
13 Sep 07 |
nicklas |
43 |
private static final String FLUIDICS_SECTION_NAME = "[Fluidics]"; |
11 |
13 Sep 07 |
nicklas |
44 |
|
11 |
13 Sep 07 |
nicklas |
/** The array type tag name. */ |
11 |
13 Sep 07 |
nicklas |
46 |
private static final String ARRAY_TYPE_TAG = "Chip Type"; |
11 |
13 Sep 07 |
nicklas |
47 |
|
11 |
13 Sep 07 |
nicklas |
/** The protocol tag name. */ |
11 |
13 Sep 07 |
nicklas |
49 |
private static final String PROTOCOL_TAG = "Protocol"; |
11 |
13 Sep 07 |
nicklas |
50 |
|
11 |
13 Sep 07 |
nicklas |
/** The station tag name. */ |
11 |
13 Sep 07 |
nicklas |
52 |
private static final String STATION_TAG = "Station"; |
11 |
13 Sep 07 |
nicklas |
53 |
|
11 |
13 Sep 07 |
nicklas |
/** The name of the EXP file */ |
11 |
13 Sep 07 |
nicklas |
55 |
private String fileName; |
11 |
13 Sep 07 |
nicklas |
56 |
|
11 |
13 Sep 07 |
nicklas |
/** Sets the file name. |
11 |
13 Sep 07 |
nicklas |
* @param name The name of the EXP file. |
11 |
13 Sep 07 |
nicklas |
59 |
*/ |
11 |
13 Sep 07 |
nicklas |
60 |
public void setFileName(String name) { fileName = name; } |
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 |
/** The array type in the EXP file */ |
11 |
13 Sep 07 |
nicklas |
68 |
private String arrayType; |
11 |
13 Sep 07 |
nicklas |
69 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the array type. |
11 |
13 Sep 07 |
nicklas |
* @return The probe array type in the mask file. |
11 |
13 Sep 07 |
nicklas |
72 |
*/ |
11 |
13 Sep 07 |
nicklas |
73 |
public String getArrayType() { return arrayType; } |
11 |
13 Sep 07 |
nicklas |
74 |
|
11 |
13 Sep 07 |
nicklas |
/** A Vector of scan parameters. */ |
11 |
13 Sep 07 |
nicklas |
76 |
private Vector /*TagValuePair*/ scan; |
11 |
13 Sep 07 |
nicklas |
77 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the number of scan parameters. */ |
11 |
13 Sep 07 |
nicklas |
79 |
public int getNumScanParameters() { |
11 |
13 Sep 07 |
nicklas |
80 |
if (scan == null) |
11 |
13 Sep 07 |
nicklas |
81 |
return 0; |
11 |
13 Sep 07 |
nicklas |
82 |
return scan.size(); |
11 |
13 Sep 07 |
nicklas |
83 |
} |
11 |
13 Sep 07 |
nicklas |
84 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the scan parameter for the given index. |
11 |
13 Sep 07 |
nicklas |
* @param index The zero based index to the parameter vector. |
11 |
13 Sep 07 |
nicklas |
* @return The tag/value parameter. |
11 |
13 Sep 07 |
nicklas |
88 |
*/ |
11 |
13 Sep 07 |
nicklas |
89 |
public TagValuePair getScanParameter(int index) { |
11 |
13 Sep 07 |
nicklas |
90 |
return (TagValuePair) scan.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
91 |
} |
11 |
13 Sep 07 |
nicklas |
92 |
|
11 |
13 Sep 07 |
nicklas |
/** A Vector of hyb parameters. */ |
11 |
13 Sep 07 |
nicklas |
94 |
private Vector /*TagValuePair*/ hyb; |
11 |
13 Sep 07 |
nicklas |
95 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the number of hyb parameters. */ |
11 |
13 Sep 07 |
nicklas |
97 |
public int getNumHybParameters() { |
11 |
13 Sep 07 |
nicklas |
98 |
if (hyb == null) |
11 |
13 Sep 07 |
nicklas |
99 |
return 0; |
11 |
13 Sep 07 |
nicklas |
100 |
return hyb.size(); |
11 |
13 Sep 07 |
nicklas |
101 |
} |
11 |
13 Sep 07 |
nicklas |
102 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the hyb parameter for the given index. |
11 |
13 Sep 07 |
nicklas |
* @param index The zero based index to the parameter vector. |
11 |
13 Sep 07 |
nicklas |
* @return The tag/value parameter. |
11 |
13 Sep 07 |
nicklas |
106 |
*/ |
11 |
13 Sep 07 |
nicklas |
107 |
public TagValuePair getHybParameter(int index) { |
11 |
13 Sep 07 |
nicklas |
108 |
return (TagValuePair) hyb.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
109 |
} |
11 |
13 Sep 07 |
nicklas |
110 |
|
11 |
13 Sep 07 |
nicklas |
/** A Vector of sample parameters. */ |
11 |
13 Sep 07 |
nicklas |
112 |
private Vector /*TagValuePair*/ sample; |
11 |
13 Sep 07 |
nicklas |
113 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the number of sample parameters. */ |
11 |
13 Sep 07 |
nicklas |
115 |
public int getNumSampleParameters() { |
11 |
13 Sep 07 |
nicklas |
116 |
if (sample == null) |
11 |
13 Sep 07 |
nicklas |
117 |
return 0; |
11 |
13 Sep 07 |
nicklas |
118 |
return sample.size(); |
11 |
13 Sep 07 |
nicklas |
119 |
} |
11 |
13 Sep 07 |
nicklas |
120 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the sample parameter for the given index. |
11 |
13 Sep 07 |
nicklas |
* @param index The zero based index to the parameter vector. |
11 |
13 Sep 07 |
nicklas |
* @return The tag/value parameter. |
11 |
13 Sep 07 |
nicklas |
124 |
*/ |
11 |
13 Sep 07 |
nicklas |
125 |
public TagValuePair getSampleParameter(int index) { |
11 |
13 Sep 07 |
nicklas |
126 |
return (TagValuePair) sample.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
127 |
} |
11 |
13 Sep 07 |
nicklas |
128 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the contents of the file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful |
11 |
13 Sep 07 |
nicklas |
131 |
*/ |
11 |
13 Sep 07 |
nicklas |
132 |
public boolean read() { |
11 |
13 Sep 07 |
nicklas |
133 |
clear(); |
11 |
13 Sep 07 |
nicklas |
134 |
try |
11 |
13 Sep 07 |
nicklas |
135 |
{ |
11 |
13 Sep 07 |
nicklas |
136 |
FileReader f = new FileReader(fileName); |
11 |
13 Sep 07 |
nicklas |
137 |
BufferedReader b = new BufferedReader(f); |
11 |
13 Sep 07 |
nicklas |
138 |
|
11 |
13 Sep 07 |
nicklas |
// The first two lines are the header. |
11 |
13 Sep 07 |
nicklas |
140 |
String str = FileIO.ReadNextLine(b); |
11 |
13 Sep 07 |
nicklas |
141 |
if (str.startsWith(EXP_HEADER_LINE_1) == false) |
11 |
13 Sep 07 |
nicklas |
142 |
{ |
11 |
13 Sep 07 |
nicklas |
143 |
return false; |
11 |
13 Sep 07 |
nicklas |
144 |
} |
11 |
13 Sep 07 |
nicklas |
145 |
str = FileIO.ReadNextLine(b); |
11 |
13 Sep 07 |
nicklas |
146 |
if (str.startsWith(EXP_HEADER_LINE_2) == false) |
11 |
13 Sep 07 |
nicklas |
147 |
{ |
11 |
13 Sep 07 |
nicklas |
148 |
return false; |
11 |
13 Sep 07 |
nicklas |
149 |
} |
11 |
13 Sep 07 |
nicklas |
150 |
|
11 |
13 Sep 07 |
nicklas |
// The possible sections. |
11 |
13 Sep 07 |
nicklas |
152 |
final int NO_SECTION=0; |
11 |
13 Sep 07 |
nicklas |
153 |
final int SAMPLE_SECTION=1; |
11 |
13 Sep 07 |
nicklas |
154 |
final int FLUIDICS_SECTION=2; |
11 |
13 Sep 07 |
nicklas |
155 |
final int SCANNER_SECTION=3; |
11 |
13 Sep 07 |
nicklas |
156 |
int currentSection = NO_SECTION; |
11 |
13 Sep 07 |
nicklas |
157 |
|
11 |
13 Sep 07 |
nicklas |
// The remaining are the sample, fluidics and scanner sections |
11 |
13 Sep 07 |
nicklas |
159 |
boolean captureAll = false; |
11 |
13 Sep 07 |
nicklas |
160 |
while ((str = FileIO.ReadNextLine(b)) != null) |
11 |
13 Sep 07 |
nicklas |
161 |
{ |
11 |
13 Sep 07 |
nicklas |
// Check for the start of each section. |
11 |
13 Sep 07 |
nicklas |
163 |
if (str.startsWith(SAMPLE_SECTION_NAME) == true) |
11 |
13 Sep 07 |
nicklas |
164 |
{ |
11 |
13 Sep 07 |
nicklas |
165 |
currentSection = SAMPLE_SECTION; |
11 |
13 Sep 07 |
nicklas |
166 |
continue; |
11 |
13 Sep 07 |
nicklas |
167 |
} |
11 |
13 Sep 07 |
nicklas |
168 |
|
11 |
13 Sep 07 |
nicklas |
169 |
else if (str.startsWith(FLUIDICS_SECTION_NAME) == true) |
11 |
13 Sep 07 |
nicklas |
170 |
{ |
11 |
13 Sep 07 |
nicklas |
171 |
currentSection = FLUIDICS_SECTION; |
11 |
13 Sep 07 |
nicklas |
172 |
continue; |
11 |
13 Sep 07 |
nicklas |
173 |
} |
11 |
13 Sep 07 |
nicklas |
174 |
|
11 |
13 Sep 07 |
nicklas |
175 |
else if (str.startsWith(SCANNER_SECTION_NAME) == true) |
11 |
13 Sep 07 |
nicklas |
176 |
{ |
11 |
13 Sep 07 |
nicklas |
177 |
currentSection = SCANNER_SECTION; |
11 |
13 Sep 07 |
nicklas |
178 |
continue; |
11 |
13 Sep 07 |
nicklas |
179 |
} |
11 |
13 Sep 07 |
nicklas |
180 |
|
11 |
13 Sep 07 |
nicklas |
// Parse the line into a name/value pair. |
11 |
13 Sep 07 |
nicklas |
182 |
TagValuePair param = new TagValuePair(); |
11 |
13 Sep 07 |
nicklas |
183 |
String[] paramStr = str.split("\t"); |
11 |
13 Sep 07 |
nicklas |
184 |
param.setTag(paramStr[0]); |
11 |
13 Sep 07 |
nicklas |
185 |
if (paramStr.length == 1) |
11 |
13 Sep 07 |
nicklas |
186 |
param.setValue(""); |
11 |
13 Sep 07 |
nicklas |
187 |
else |
11 |
13 Sep 07 |
nicklas |
188 |
param.setValue(paramStr[1].trim()); |
11 |
13 Sep 07 |
nicklas |
189 |
|
11 |
13 Sep 07 |
nicklas |
190 |
|
11 |
13 Sep 07 |
nicklas |
// Take everything between the "Protocol" and "Station" tags. These |
11 |
13 Sep 07 |
nicklas |
// may include error messages in the tag name with blank values. |
11 |
13 Sep 07 |
nicklas |
193 |
if (currentSection == FLUIDICS_SECTION && param.getTag().compareTo(PROTOCOL_TAG) == 0) |
11 |
13 Sep 07 |
nicklas |
194 |
captureAll = true; |
11 |
13 Sep 07 |
nicklas |
195 |
else if (currentSection == FLUIDICS_SECTION && param.getTag().compareTo(STATION_TAG) == 0) |
11 |
13 Sep 07 |
nicklas |
196 |
captureAll = false; |
11 |
13 Sep 07 |
nicklas |
197 |
|
11 |
13 Sep 07 |
nicklas |
// If the value is blank then skip it. |
11 |
13 Sep 07 |
nicklas |
199 |
if (param.getValue().length() == 0 && captureAll == false) |
11 |
13 Sep 07 |
nicklas |
200 |
continue; |
11 |
13 Sep 07 |
nicklas |
201 |
|
11 |
13 Sep 07 |
nicklas |
// Double check if the "Protocol" tag is blank and skip it. |
11 |
13 Sep 07 |
nicklas |
203 |
if (param.getTag().compareTo(PROTOCOL_TAG) == 0 && param.getValue().length() == 0) |
11 |
13 Sep 07 |
nicklas |
204 |
continue; |
11 |
13 Sep 07 |
nicklas |
205 |
|
11 |
13 Sep 07 |
nicklas |
// Check for the special array type line |
11 |
13 Sep 07 |
nicklas |
207 |
if (currentSection == SAMPLE_SECTION && param.getTag().compareTo(ARRAY_TYPE_TAG) == 0) |
11 |
13 Sep 07 |
nicklas |
208 |
{ |
11 |
13 Sep 07 |
nicklas |
209 |
arrayType = param.getValue(); |
11 |
13 Sep 07 |
nicklas |
210 |
} |
11 |
13 Sep 07 |
nicklas |
211 |
|
11 |
13 Sep 07 |
nicklas |
// Store the parameter into the sample section. |
11 |
13 Sep 07 |
nicklas |
213 |
else if (currentSection == SAMPLE_SECTION) |
11 |
13 Sep 07 |
nicklas |
214 |
{ |
11 |
13 Sep 07 |
nicklas |
215 |
if (sample == null) |
11 |
13 Sep 07 |
nicklas |
216 |
sample = new Vector(); |
11 |
13 Sep 07 |
nicklas |
217 |
sample.add(param); |
11 |
13 Sep 07 |
nicklas |
218 |
} |
11 |
13 Sep 07 |
nicklas |
219 |
|
11 |
13 Sep 07 |
nicklas |
// Store the parameter into the fluidics section. |
11 |
13 Sep 07 |
nicklas |
221 |
else if (currentSection == FLUIDICS_SECTION) |
11 |
13 Sep 07 |
nicklas |
222 |
{ |
11 |
13 Sep 07 |
nicklas |
223 |
if (hyb == null) |
11 |
13 Sep 07 |
nicklas |
224 |
hyb = new Vector(); |
11 |
13 Sep 07 |
nicklas |
225 |
hyb.add(param); |
11 |
13 Sep 07 |
nicklas |
226 |
} |
11 |
13 Sep 07 |
nicklas |
227 |
|
11 |
13 Sep 07 |
nicklas |
// Store the parameter into the scanner section. |
11 |
13 Sep 07 |
nicklas |
229 |
else if (currentSection == SCANNER_SECTION) |
11 |
13 Sep 07 |
nicklas |
230 |
{ |
11 |
13 Sep 07 |
nicklas |
231 |
if (scan == null) |
11 |
13 Sep 07 |
nicklas |
232 |
scan = new Vector(); |
11 |
13 Sep 07 |
nicklas |
233 |
scan.add(param); |
11 |
13 Sep 07 |
nicklas |
234 |
} |
11 |
13 Sep 07 |
nicklas |
235 |
} |
11 |
13 Sep 07 |
nicklas |
236 |
return true; |
11 |
13 Sep 07 |
nicklas |
237 |
} |
11 |
13 Sep 07 |
nicklas |
238 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
239 |
{ |
11 |
13 Sep 07 |
nicklas |
240 |
} |
11 |
13 Sep 07 |
nicklas |
241 |
return false; |
11 |
13 Sep 07 |
nicklas |
242 |
} |
11 |
13 Sep 07 |
nicklas |
243 |
|
11 |
13 Sep 07 |
nicklas |
/** Checks for the existance of a file. |
11 |
13 Sep 07 |
nicklas |
* @return True if the file exists |
11 |
13 Sep 07 |
nicklas |
246 |
*/ |
11 |
13 Sep 07 |
nicklas |
247 |
public boolean exists() { return new File(fileName).exists(); } |
11 |
13 Sep 07 |
nicklas |
248 |
|
11 |
13 Sep 07 |
nicklas |
/** Clears memory associated with the class */ |
11 |
13 Sep 07 |
nicklas |
250 |
public void clear() { |
11 |
13 Sep 07 |
nicklas |
251 |
arrayType=""; |
11 |
13 Sep 07 |
nicklas |
252 |
scan=null; |
11 |
13 Sep 07 |
nicklas |
253 |
hyb=null; |
11 |
13 Sep 07 |
nicklas |
254 |
sample=null; |
11 |
13 Sep 07 |
nicklas |
255 |
} |
11 |
13 Sep 07 |
nicklas |
256 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of EXPFileData */ |
11 |
13 Sep 07 |
nicklas |
258 |
public EXPFileData() { |
11 |
13 Sep 07 |
nicklas |
259 |
fileName = ""; |
11 |
13 Sep 07 |
nicklas |
260 |
clear(); |
11 |
13 Sep 07 |
nicklas |
261 |
} |
11 |
13 Sep 07 |
nicklas |
262 |
|
11 |
13 Sep 07 |
nicklas |
263 |
} |