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.cdf; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import affymetrix.gcos.cdf.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import java.io.*; |
11 |
13 Sep 07 |
nicklas |
25 |
|
11 |
13 Sep 07 |
nicklas |
/** This class provides reading and storage capabilities for the CDF file. */ |
11 |
13 Sep 07 |
nicklas |
27 |
public class FusionCDFData { |
11 |
13 Sep 07 |
nicklas |
28 |
|
11 |
13 Sep 07 |
nicklas |
/** The file header object. */ |
11 |
13 Sep 07 |
nicklas |
30 |
private FusionCDFHeader header; |
11 |
13 Sep 07 |
nicklas |
31 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the header. */ |
11 |
13 Sep 07 |
nicklas |
33 |
public FusionCDFHeader getHeader() { return header; } |
11 |
13 Sep 07 |
nicklas |
34 |
|
11 |
13 Sep 07 |
nicklas |
/** The GCOS CDF file object. */ |
11 |
13 Sep 07 |
nicklas |
36 |
private CDFFileData gcosFile; |
11 |
13 Sep 07 |
nicklas |
37 |
|
11 |
13 Sep 07 |
nicklas |
/** The CDF file name (full path). */ |
11 |
13 Sep 07 |
nicklas |
39 |
private String fileName; |
11 |
13 Sep 07 |
nicklas |
40 |
|
13 |
14 Sep 07 |
nicklas |
41 |
/** |
13 |
14 Sep 07 |
nicklas |
* If set, we will read data from this input stream instead of |
13 |
14 Sep 07 |
nicklas |
* from the file specified by fileName |
13 |
14 Sep 07 |
nicklas |
44 |
*/ |
13 |
14 Sep 07 |
nicklas |
45 |
private InputStream in; |
13 |
14 Sep 07 |
nicklas |
46 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the file name. */ |
11 |
13 Sep 07 |
nicklas |
48 |
public String getFileName() { return fileName; } |
11 |
13 Sep 07 |
nicklas |
49 |
|
11 |
13 Sep 07 |
nicklas |
/** Sets the file name. */ |
11 |
13 Sep 07 |
nicklas |
51 |
public void setFileName(String value) { fileName = value; } |
13 |
14 Sep 07 |
nicklas |
52 |
|
13 |
14 Sep 07 |
nicklas |
53 |
/** |
13 |
14 Sep 07 |
nicklas |
* Set the input stream to read from. If set |
13 |
14 Sep 07 |
nicklas |
* we use the stream instead of the file given by filename |
13 |
14 Sep 07 |
nicklas |
56 |
*/ |
13 |
14 Sep 07 |
nicklas |
57 |
public void setInputStream(InputStream in) |
13 |
14 Sep 07 |
nicklas |
58 |
{ |
13 |
14 Sep 07 |
nicklas |
59 |
this.in = in; |
13 |
14 Sep 07 |
nicklas |
60 |
} |
11 |
13 Sep 07 |
nicklas |
61 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the error message. */ |
11 |
13 Sep 07 |
nicklas |
63 |
public String getError() { |
11 |
13 Sep 07 |
nicklas |
64 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
65 |
return gcosFile.getError(); |
11 |
13 Sep 07 |
nicklas |
66 |
return null; |
11 |
13 Sep 07 |
nicklas |
67 |
} |
11 |
13 Sep 07 |
nicklas |
68 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the name of a probe set. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the probe set name of interest. |
11 |
13 Sep 07 |
nicklas |
* @return The probe set name. |
11 |
13 Sep 07 |
nicklas |
72 |
*/ |
11 |
13 Sep 07 |
nicklas |
73 |
public String getProbeSetName(int index) { |
11 |
13 Sep 07 |
nicklas |
74 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
75 |
return gcosFile.getProbeSetName(index); |
11 |
13 Sep 07 |
nicklas |
76 |
return null; |
11 |
13 Sep 07 |
nicklas |
77 |
} |
11 |
13 Sep 07 |
nicklas |
78 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the chip type (probe array type) of the CDF file. |
11 |
13 Sep 07 |
nicklas |
* @return The chip type. This is just the name (without extension) of the CDF file. |
11 |
13 Sep 07 |
nicklas |
81 |
*/ |
11 |
13 Sep 07 |
nicklas |
82 |
public String getChipType() { |
11 |
13 Sep 07 |
nicklas |
83 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
84 |
return gcosFile.getChipType(); |
11 |
13 Sep 07 |
nicklas |
85 |
return null; |
11 |
13 Sep 07 |
nicklas |
86 |
} |
11 |
13 Sep 07 |
nicklas |
87 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates the GCOS objects for reading the files. */ |
11 |
13 Sep 07 |
nicklas |
89 |
private void prepareGCOSObjectsForReading() |
11 |
13 Sep 07 |
nicklas |
90 |
{ |
11 |
13 Sep 07 |
nicklas |
91 |
header = new FusionCDFHeader(); |
11 |
13 Sep 07 |
nicklas |
92 |
gcosFile.setFileName(fileName); |
13 |
14 Sep 07 |
nicklas |
93 |
gcosFile.setInputStream(in); |
11 |
13 Sep 07 |
nicklas |
94 |
} |
11 |
13 Sep 07 |
nicklas |
95 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the entire file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
98 |
*/ |
11 |
13 Sep 07 |
nicklas |
99 |
public boolean read() { |
11 |
13 Sep 07 |
nicklas |
100 |
prepareGCOSObjectsForReading(); |
11 |
13 Sep 07 |
nicklas |
101 |
boolean status = gcosFile.read(); |
11 |
13 Sep 07 |
nicklas |
102 |
if (status == true) |
11 |
13 Sep 07 |
nicklas |
103 |
header.setGCOSObject(gcosFile.getHeader()); |
11 |
13 Sep 07 |
nicklas |
104 |
return status; |
11 |
13 Sep 07 |
nicklas |
105 |
} |
11 |
13 Sep 07 |
nicklas |
106 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the header of the file only. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
109 |
*/ |
11 |
13 Sep 07 |
nicklas |
110 |
public boolean readHeader() { |
11 |
13 Sep 07 |
nicklas |
111 |
prepareGCOSObjectsForReading(); |
11 |
13 Sep 07 |
nicklas |
112 |
boolean status = gcosFile.readHeader(); |
11 |
13 Sep 07 |
nicklas |
113 |
if (status == true) |
11 |
13 Sep 07 |
nicklas |
114 |
header.setGCOSObject(gcosFile.getHeader()); |
11 |
13 Sep 07 |
nicklas |
115 |
return status; |
11 |
13 Sep 07 |
nicklas |
116 |
} |
11 |
13 Sep 07 |
nicklas |
117 |
|
13 |
14 Sep 07 |
nicklas |
118 |
/** |
13 |
14 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 |
121 |
*/ |
13 |
14 Sep 07 |
nicklas |
122 |
public boolean exists() { |
13 |
14 Sep 07 |
nicklas |
123 |
return in != null || new File(fileName).exists(); |
13 |
14 Sep 07 |
nicklas |
124 |
} |
11 |
13 Sep 07 |
nicklas |
125 |
|
11 |
13 Sep 07 |
nicklas |
/** Determines if a CDF file is of the XDA (binary) format. |
11 |
13 Sep 07 |
nicklas |
* @return True if XDA format. |
11 |
13 Sep 07 |
nicklas |
128 |
*/ |
11 |
13 Sep 07 |
nicklas |
129 |
public boolean isXDACompatibleFile() { |
13 |
14 Sep 07 |
nicklas |
130 |
prepareGCOSObjectsForReading(); |
11 |
13 Sep 07 |
nicklas |
131 |
return gcosFile.isXDACompatibleFile(); |
11 |
13 Sep 07 |
nicklas |
132 |
} |
11 |
13 Sep 07 |
nicklas |
133 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the probe set type for non-qc probe sets. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the probe set of interest. |
11 |
13 Sep 07 |
nicklas |
* @return The type of probe set. |
11 |
13 Sep 07 |
nicklas |
137 |
*/ |
11 |
13 Sep 07 |
nicklas |
138 |
public int getProbeSetType(int index) { |
11 |
13 Sep 07 |
nicklas |
139 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
140 |
return gcosFile.getProbeSetType(index); |
11 |
13 Sep 07 |
nicklas |
141 |
return FusionGeneChipProbeSetType.UnknownProbeSetType; |
11 |
13 Sep 07 |
nicklas |
142 |
} |
11 |
13 Sep 07 |
nicklas |
143 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the probe set information. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the probe set of interest. |
11 |
13 Sep 07 |
nicklas |
* @param info The probe set information. |
11 |
13 Sep 07 |
nicklas |
147 |
*/ |
11 |
13 Sep 07 |
nicklas |
148 |
public void getProbeSetInformation(int index, FusionCDFProbeSetInformation info) { |
11 |
13 Sep 07 |
nicklas |
149 |
info.clear(); |
11 |
13 Sep 07 |
nicklas |
150 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
151 |
{ |
11 |
13 Sep 07 |
nicklas |
152 |
CDFProbeSetInformation probeSet = gcosFile.getProbeSetInformation(index); |
11 |
13 Sep 07 |
nicklas |
153 |
info.setGCOSObject(probeSet); |
11 |
13 Sep 07 |
nicklas |
154 |
} |
11 |
13 Sep 07 |
nicklas |
155 |
} |
11 |
13 Sep 07 |
nicklas |
156 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the QC probe set information by index. |
11 |
13 Sep 07 |
nicklas |
* @param index The index to the QC probe set of interest. |
11 |
13 Sep 07 |
nicklas |
* @param info The QC probe set information. |
11 |
13 Sep 07 |
nicklas |
160 |
*/ |
11 |
13 Sep 07 |
nicklas |
161 |
public void getQCProbeSetInformation(int index, FusionCDFQCProbeSetInformation info) { |
11 |
13 Sep 07 |
nicklas |
162 |
info.clear(); |
11 |
13 Sep 07 |
nicklas |
163 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
164 |
{ |
11 |
13 Sep 07 |
nicklas |
165 |
CDFQCProbeSetInformation probeSet = gcosFile.getQCProbeSetInformation(index); |
11 |
13 Sep 07 |
nicklas |
166 |
info.setGCOSObject(probeSet); |
11 |
13 Sep 07 |
nicklas |
167 |
} |
11 |
13 Sep 07 |
nicklas |
168 |
} |
11 |
13 Sep 07 |
nicklas |
169 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the QC probe set information by type. |
11 |
13 Sep 07 |
nicklas |
* @param qcType The type of QC probe set to retrieve. |
11 |
13 Sep 07 |
nicklas |
* @param info The QC probe set information. |
11 |
13 Sep 07 |
nicklas |
173 |
*/ |
11 |
13 Sep 07 |
nicklas |
174 |
public void getQCProbeSetInformationByType(int qcType, FusionCDFQCProbeSetInformation info) { |
11 |
13 Sep 07 |
nicklas |
175 |
info.clear(); |
11 |
13 Sep 07 |
nicklas |
176 |
if (gcosFile != null) |
11 |
13 Sep 07 |
nicklas |
177 |
{ |
11 |
13 Sep 07 |
nicklas |
178 |
CDFQCProbeSetInformation probeSet = gcosFile.getQCProbeSetInformationByType(qcType); |
11 |
13 Sep 07 |
nicklas |
179 |
info.setGCOSObject(probeSet); |
11 |
13 Sep 07 |
nicklas |
180 |
} |
11 |
13 Sep 07 |
nicklas |
181 |
} |
11 |
13 Sep 07 |
nicklas |
182 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of CDFFileData */ |
11 |
13 Sep 07 |
nicklas |
184 |
public FusionCDFData() { |
11 |
13 Sep 07 |
nicklas |
185 |
fileName = ""; |
13 |
14 Sep 07 |
nicklas |
186 |
gcosFile = new CDFFileData(); |
11 |
13 Sep 07 |
nicklas |
187 |
clear(); |
11 |
13 Sep 07 |
nicklas |
188 |
} |
11 |
13 Sep 07 |
nicklas |
189 |
|
11 |
13 Sep 07 |
nicklas |
/** Clears the members. */ |
11 |
13 Sep 07 |
nicklas |
191 |
public void clear() { |
11 |
13 Sep 07 |
nicklas |
192 |
} |
11 |
13 Sep 07 |
nicklas |
193 |
|
11 |
13 Sep 07 |
nicklas |
194 |
} |