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.fusion.chp; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import affymetrix.gcos.chp.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import affymetrix.calvin.data.*; |
11 |
13 Sep 07 |
nicklas |
25 |
import affymetrix.calvin.parsers.*; |
11 |
13 Sep 07 |
nicklas |
26 |
import affymetrix.calvin.utils.*; |
11 |
13 Sep 07 |
nicklas |
27 |
import java.io.*; |
11 |
13 Sep 07 |
nicklas |
28 |
import java.util.*; |
11 |
13 Sep 07 |
nicklas |
29 |
|
11 |
13 Sep 07 |
nicklas |
/** Provides storage for data in a GCOS CHP file. */ |
11 |
13 Sep 07 |
nicklas |
31 |
public class FusionCHPLegacyData extends FusionCHPData { |
11 |
13 Sep 07 |
nicklas |
32 |
|
11 |
13 Sep 07 |
nicklas |
/** The file header object */ |
11 |
13 Sep 07 |
nicklas |
34 |
private FusionCHPHeader header; |
11 |
13 Sep 07 |
nicklas |
35 |
|
11 |
13 Sep 07 |
nicklas |
/** The GCOS CHP file object. */ |
11 |
13 Sep 07 |
nicklas |
37 |
private CHPFileData gcosFile; |
11 |
13 Sep 07 |
nicklas |
38 |
|
11 |
13 Sep 07 |
nicklas |
/** The Calvin CHP file object. */ |
11 |
13 Sep 07 |
nicklas |
40 |
private CHPData calvinFile; |
11 |
13 Sep 07 |
nicklas |
41 |
|
11 |
13 Sep 07 |
nicklas |
/** An error message when failed to read a file.*/ |
11 |
13 Sep 07 |
nicklas |
43 |
private String errorMessage; |
11 |
13 Sep 07 |
nicklas |
44 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of FusionCHPData */ |
11 |
13 Sep 07 |
nicklas |
46 |
private FusionCHPLegacyData() { |
11 |
13 Sep 07 |
nicklas |
47 |
errorMessage = ""; |
11 |
13 Sep 07 |
nicklas |
48 |
clear(); |
11 |
13 Sep 07 |
nicklas |
49 |
} |
11 |
13 Sep 07 |
nicklas |
50 |
|
11 |
13 Sep 07 |
nicklas |
/** Accessors to header. |
11 |
13 Sep 07 |
nicklas |
* @return The header data object |
11 |
13 Sep 07 |
nicklas |
53 |
*/ |
11 |
13 Sep 07 |
nicklas |
54 |
public FusionCHPHeader getHeader() { return header; } |
11 |
13 Sep 07 |
nicklas |
55 |
|
11 |
13 Sep 07 |
nicklas |
/** Returns the expression probe set result |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the result object of interest. |
11 |
13 Sep 07 |
nicklas |
* @param entry The expression result. |
11 |
13 Sep 07 |
nicklas |
59 |
*/ |
11 |
13 Sep 07 |
nicklas |
60 |
public void getExpressionResults(int index, FusionExpressionProbeSetResults entry) { |
11 |
13 Sep 07 |
nicklas |
61 |
entry.clear(); |
11 |
13 Sep 07 |
nicklas |
62 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
63 |
entry.setGCOSObject(gcosFile.getExpressionResults(index)); |
11 |
13 Sep 07 |
nicklas |
64 |
else if (calvinFile != null) |
11 |
13 Sep 07 |
nicklas |
65 |
{ |
11 |
13 Sep 07 |
nicklas |
66 |
CHPExpressionEntry calvinEntry = new CHPExpressionEntry(); |
11 |
13 Sep 07 |
nicklas |
67 |
calvinFile.getEntry(index, calvinEntry); |
11 |
13 Sep 07 |
nicklas |
68 |
entry.setCalvinObject(calvinEntry); |
11 |
13 Sep 07 |
nicklas |
69 |
} |
11 |
13 Sep 07 |
nicklas |
70 |
} |
11 |
13 Sep 07 |
nicklas |
71 |
|
11 |
13 Sep 07 |
nicklas |
/** Returns the genotyping probe set result |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the result object of interest. |
11 |
13 Sep 07 |
nicklas |
* @param entry The genotyping result. |
11 |
13 Sep 07 |
nicklas |
75 |
*/ |
11 |
13 Sep 07 |
nicklas |
76 |
public void getGenotypingResults(int index, FusionGenotypeProbeSetResults entry) { |
11 |
13 Sep 07 |
nicklas |
77 |
entry.clear(); |
11 |
13 Sep 07 |
nicklas |
78 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
79 |
entry.setGCOSObject(gcosFile.getGenotypingResults(index)); |
11 |
13 Sep 07 |
nicklas |
80 |
else if (calvinFile != null) |
11 |
13 Sep 07 |
nicklas |
81 |
{ |
11 |
13 Sep 07 |
nicklas |
82 |
CHPGenotypeEntry calvinEntry = new CHPGenotypeEntry(); |
11 |
13 Sep 07 |
nicklas |
83 |
calvinFile.getEntry(index, calvinEntry); |
11 |
13 Sep 07 |
nicklas |
84 |
entry.setCalvinObject(calvinEntry); |
11 |
13 Sep 07 |
nicklas |
85 |
} |
11 |
13 Sep 07 |
nicklas |
86 |
} |
11 |
13 Sep 07 |
nicklas |
87 |
|
11 |
13 Sep 07 |
nicklas |
/** Returns the universal (tag array) probe set result |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the result object of interest. |
11 |
13 Sep 07 |
nicklas |
* @param entry The universal result. |
11 |
13 Sep 07 |
nicklas |
91 |
*/ |
11 |
13 Sep 07 |
nicklas |
92 |
public void getUniversalResults(int index, FusionUniversalProbeSetResults entry) { |
11 |
13 Sep 07 |
nicklas |
93 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
94 |
entry.setGCOSObject(gcosFile.getUniversalResults(index)); |
11 |
13 Sep 07 |
nicklas |
95 |
else if (calvinFile != null) |
11 |
13 Sep 07 |
nicklas |
96 |
{ |
11 |
13 Sep 07 |
nicklas |
97 |
CHPUniversalEntry calvinEntry = new CHPUniversalEntry(); |
11 |
13 Sep 07 |
nicklas |
98 |
calvinFile.getEntry(index, calvinEntry); |
11 |
13 Sep 07 |
nicklas |
99 |
entry.setCalvinObject(calvinEntry); |
11 |
13 Sep 07 |
nicklas |
100 |
} |
11 |
13 Sep 07 |
nicklas |
101 |
} |
11 |
13 Sep 07 |
nicklas |
102 |
|
11 |
13 Sep 07 |
nicklas |
/** Returns the resequencing results. |
11 |
13 Sep 07 |
nicklas |
* @param entry The resequencing results. |
11 |
13 Sep 07 |
nicklas |
105 |
*/ |
11 |
13 Sep 07 |
nicklas |
106 |
public void getResequencingResults(FusionResequencingResults entry) { |
11 |
13 Sep 07 |
nicklas |
107 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
108 |
entry.setGCOSObject(gcosFile.getResequencingResults()); |
11 |
13 Sep 07 |
nicklas |
109 |
else if (calvinFile != null) |
11 |
13 Sep 07 |
nicklas |
110 |
entry.setCalvinObject(calvinFile); |
11 |
13 Sep 07 |
nicklas |
111 |
} |
11 |
13 Sep 07 |
nicklas |
112 |
|
11 |
13 Sep 07 |
nicklas |
/** Error string when the read functions fail. |
11 |
13 Sep 07 |
nicklas |
* @return A string message describing a read error |
11 |
13 Sep 07 |
nicklas |
115 |
*/ |
11 |
13 Sep 07 |
nicklas |
116 |
public String getError() { |
11 |
13 Sep 07 |
nicklas |
117 |
return errorMessage; |
11 |
13 Sep 07 |
nicklas |
118 |
} |
11 |
13 Sep 07 |
nicklas |
119 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads a calvin file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
122 |
*/ |
11 |
13 Sep 07 |
nicklas |
123 |
private boolean readCalvinFile() { |
11 |
13 Sep 07 |
nicklas |
124 |
CHPFileReader calvinReader = new CHPFileReader(); |
11 |
13 Sep 07 |
nicklas |
125 |
try |
11 |
13 Sep 07 |
nicklas |
126 |
{ |
11 |
13 Sep 07 |
nicklas |
127 |
calvinFile = new CHPData(); |
11 |
13 Sep 07 |
nicklas |
128 |
calvinReader.setFilename(filename); |
11 |
13 Sep 07 |
nicklas |
129 |
calvinReader.read(calvinFile); |
11 |
13 Sep 07 |
nicklas |
130 |
header = new FusionCHPHeader(); |
11 |
13 Sep 07 |
nicklas |
131 |
header.setCalvinObject(calvinFile); |
11 |
13 Sep 07 |
nicklas |
132 |
return true; |
11 |
13 Sep 07 |
nicklas |
133 |
} |
11 |
13 Sep 07 |
nicklas |
134 |
catch (affymetrix.calvin.parsers.FileNotFoundException e) |
11 |
13 Sep 07 |
nicklas |
135 |
{ |
11 |
13 Sep 07 |
nicklas |
136 |
errorMessage = "File not found"; |
11 |
13 Sep 07 |
nicklas |
137 |
} |
11 |
13 Sep 07 |
nicklas |
138 |
catch (InvalidVersionException e) |
11 |
13 Sep 07 |
nicklas |
139 |
{ |
11 |
13 Sep 07 |
nicklas |
140 |
errorMessage = "Invalid file version"; |
11 |
13 Sep 07 |
nicklas |
141 |
} |
11 |
13 Sep 07 |
nicklas |
142 |
catch (InvalidFileTypeException e) |
11 |
13 Sep 07 |
nicklas |
143 |
{ |
11 |
13 Sep 07 |
nicklas |
144 |
errorMessage = "Invalid file type"; |
11 |
13 Sep 07 |
nicklas |
145 |
} |
11 |
13 Sep 07 |
nicklas |
146 |
clear(); |
11 |
13 Sep 07 |
nicklas |
147 |
return false; |
11 |
13 Sep 07 |
nicklas |
148 |
} |
11 |
13 Sep 07 |
nicklas |
149 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the entire file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
152 |
*/ |
11 |
13 Sep 07 |
nicklas |
153 |
protected boolean read() { |
11 |
13 Sep 07 |
nicklas |
154 |
gcosFile = new CHPFileData(); |
11 |
13 Sep 07 |
nicklas |
155 |
gcosFile.setFileName(filename); |
11 |
13 Sep 07 |
nicklas |
156 |
if (gcosFile.read() == true) |
11 |
13 Sep 07 |
nicklas |
157 |
{ |
11 |
13 Sep 07 |
nicklas |
158 |
header = new FusionCHPHeader(); |
11 |
13 Sep 07 |
nicklas |
159 |
header.setGCOSHeader(gcosFile.getHeader()); |
11 |
13 Sep 07 |
nicklas |
160 |
return true; |
11 |
13 Sep 07 |
nicklas |
161 |
} |
11 |
13 Sep 07 |
nicklas |
162 |
else |
11 |
13 Sep 07 |
nicklas |
163 |
errorMessage = gcosFile.getError(); |
11 |
13 Sep 07 |
nicklas |
164 |
gcosFile = null; |
11 |
13 Sep 07 |
nicklas |
165 |
return readCalvinFile(); |
11 |
13 Sep 07 |
nicklas |
166 |
} |
11 |
13 Sep 07 |
nicklas |
167 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the header of the CHP file |
11 |
13 Sep 07 |
nicklas |
* @return True if successful |
11 |
13 Sep 07 |
nicklas |
170 |
*/ |
11 |
13 Sep 07 |
nicklas |
171 |
protected boolean readHeader() { |
11 |
13 Sep 07 |
nicklas |
172 |
gcosFile = new CHPFileData(); |
11 |
13 Sep 07 |
nicklas |
173 |
gcosFile.setFileName(filename); |
11 |
13 Sep 07 |
nicklas |
174 |
if (gcosFile.readHeader() == true) |
11 |
13 Sep 07 |
nicklas |
175 |
{ |
11 |
13 Sep 07 |
nicklas |
176 |
header = new FusionCHPHeader(); |
11 |
13 Sep 07 |
nicklas |
177 |
header.setGCOSHeader(gcosFile.getHeader()); |
11 |
13 Sep 07 |
nicklas |
178 |
return true; |
11 |
13 Sep 07 |
nicklas |
179 |
} |
11 |
13 Sep 07 |
nicklas |
180 |
else |
11 |
13 Sep 07 |
nicklas |
181 |
errorMessage = gcosFile.getError(); |
11 |
13 Sep 07 |
nicklas |
182 |
gcosFile = null; |
11 |
13 Sep 07 |
nicklas |
183 |
return readCalvinFile(); |
11 |
13 Sep 07 |
nicklas |
184 |
} |
11 |
13 Sep 07 |
nicklas |
185 |
|
11 |
13 Sep 07 |
nicklas |
/** Get the id of the file (only valid for Command Console "calvin" files) |
11 |
13 Sep 07 |
nicklas |
* @return The unique file id. |
11 |
13 Sep 07 |
nicklas |
188 |
*/ |
11 |
13 Sep 07 |
nicklas |
189 |
public AffymetrixGuidType getFileId() { |
11 |
13 Sep 07 |
nicklas |
190 |
if (calvinFile != null) |
11 |
13 Sep 07 |
nicklas |
191 |
return calvinFile.getGenericData().getFileIdentifier(); |
11 |
13 Sep 07 |
nicklas |
192 |
return null; |
11 |
13 Sep 07 |
nicklas |
193 |
} |
11 |
13 Sep 07 |
nicklas |
194 |
|
11 |
13 Sep 07 |
nicklas |
/** Determines if the file specified by the FileName property exists. |
11 |
13 Sep 07 |
nicklas |
* @return True if the file exists. |
11 |
13 Sep 07 |
nicklas |
197 |
*/ |
11 |
13 Sep 07 |
nicklas |
198 |
public boolean exists() { |
11 |
13 Sep 07 |
nicklas |
199 |
return new File(filename).exists(); |
11 |
13 Sep 07 |
nicklas |
200 |
} |
11 |
13 Sep 07 |
nicklas |
201 |
|
11 |
13 Sep 07 |
nicklas |
/** Deallocates any memory used by the class object */ |
11 |
13 Sep 07 |
nicklas |
203 |
public void clear() { |
11 |
13 Sep 07 |
nicklas |
204 |
header = null; |
11 |
13 Sep 07 |
nicklas |
205 |
gcosFile = null; |
11 |
13 Sep 07 |
nicklas |
206 |
calvinFile = null; |
11 |
13 Sep 07 |
nicklas |
207 |
} |
11 |
13 Sep 07 |
nicklas |
208 |
|
11 |
13 Sep 07 |
nicklas |
/**A class to register the legacy CHP reader. */ |
11 |
13 Sep 07 |
nicklas |
210 |
private static class Reg extends FusionCHPDataReg |
11 |
13 Sep 07 |
nicklas |
211 |
{ |
11 |
13 Sep 07 |
nicklas |
/** Constructor - register the legacy file type. */ |
11 |
13 Sep 07 |
nicklas |
213 |
public Reg() { |
11 |
13 Sep 07 |
nicklas |
214 |
super(); |
11 |
13 Sep 07 |
nicklas |
215 |
Vector ids = new Vector(); |
11 |
13 Sep 07 |
nicklas |
216 |
AffymetrixGuidType guid; |
11 |
13 Sep 07 |
nicklas |
217 |
guid = new AffymetrixGuidType(); |
11 |
13 Sep 07 |
nicklas |
218 |
guid.setGuid(CHPData.CHP_EXPRESSION_ASSAY_TYPE); |
11 |
13 Sep 07 |
nicklas |
219 |
ids.add(guid); |
11 |
13 Sep 07 |
nicklas |
220 |
guid = new AffymetrixGuidType(); |
11 |
13 Sep 07 |
nicklas |
221 |
guid.setGuid(CHPData.CHP_RESEQUENCING_ASSAY_TYPE); |
11 |
13 Sep 07 |
nicklas |
222 |
ids.add(guid); |
11 |
13 Sep 07 |
nicklas |
223 |
guid = new AffymetrixGuidType(); |
11 |
13 Sep 07 |
nicklas |
224 |
guid.setGuid(CHPData.CHP_GENOTYPING_ASSAY_TYPE); |
11 |
13 Sep 07 |
nicklas |
225 |
ids.add(guid); |
11 |
13 Sep 07 |
nicklas |
226 |
guid = new AffymetrixGuidType(); |
11 |
13 Sep 07 |
nicklas |
227 |
guid.setGuid(CHPData.CHP_UNIVERSAL_ASSAY_TYPE); |
11 |
13 Sep 07 |
nicklas |
228 |
ids.add(guid); |
11 |
13 Sep 07 |
nicklas |
229 |
guid = new AffymetrixGuidType(); |
11 |
13 Sep 07 |
nicklas |
230 |
guid.setGuid(""); |
11 |
13 Sep 07 |
nicklas |
231 |
ids.add(guid); |
11 |
13 Sep 07 |
nicklas |
232 |
setFileTypeIds(ids); |
11 |
13 Sep 07 |
nicklas |
233 |
} |
11 |
13 Sep 07 |
nicklas |
234 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a legacy CHP object. |
11 |
13 Sep 07 |
nicklas |
* @return The legacy CHP object. |
11 |
13 Sep 07 |
nicklas |
237 |
*/ |
11 |
13 Sep 07 |
nicklas |
238 |
public FusionCHPData makeObject() { return new FusionCHPLegacyData(); } |
11 |
13 Sep 07 |
nicklas |
239 |
}; |
11 |
13 Sep 07 |
nicklas |
240 |
|
11 |
13 Sep 07 |
nicklas |
/** The one and only registration object. This registers the class as a CHP reader. */ |
11 |
13 Sep 07 |
nicklas |
242 |
private static Reg reg = null; |
11 |
13 Sep 07 |
nicklas |
243 |
|
11 |
13 Sep 07 |
nicklas |
/** Register the reader with the system. */ |
11 |
13 Sep 07 |
nicklas |
245 |
public static void registerReader() { |
11 |
13 Sep 07 |
nicklas |
246 |
if (FusionCHPLegacyData.reg == null) |
11 |
13 Sep 07 |
nicklas |
247 |
FusionCHPLegacyData.reg = new Reg(); |
11 |
13 Sep 07 |
nicklas |
248 |
} |
11 |
13 Sep 07 |
nicklas |
249 |
|
11 |
13 Sep 07 |
nicklas |
/** Converts the type to the legacy CHP type. |
11 |
13 Sep 07 |
nicklas |
* @param chip The pointer to the CHP data object. |
11 |
13 Sep 07 |
nicklas |
* @return The legacy CHP data type or NULL if not compatible. |
11 |
13 Sep 07 |
nicklas |
253 |
*/ |
11 |
13 Sep 07 |
nicklas |
254 |
public static FusionCHPLegacyData fromBase(FusionCHPData chip) { |
11 |
13 Sep 07 |
nicklas |
255 |
if (chip == null) |
11 |
13 Sep 07 |
nicklas |
256 |
return null; |
11 |
13 Sep 07 |
nicklas |
257 |
String chipName = chip.getClass().getName(); |
11 |
13 Sep 07 |
nicklas |
258 |
String genName = FusionCHPLegacyData.class.getName(); |
11 |
13 Sep 07 |
nicklas |
259 |
if (chipName.compareTo(genName) == 0) |
11 |
13 Sep 07 |
nicklas |
260 |
return (FusionCHPLegacyData) chip; |
11 |
13 Sep 07 |
nicklas |
261 |
return null; |
11 |
13 Sep 07 |
nicklas |
262 |
} |
11 |
13 Sep 07 |
nicklas |
263 |
} |