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.data; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import java.util.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import affymetrix.calvin.parameter.*; |
11 |
13 Sep 07 |
nicklas |
25 |
|
11 |
13 Sep 07 |
nicklas |
/** Holds data associated with quantification array CHP files. */ |
11 |
13 Sep 07 |
nicklas |
27 |
public class CHPQuantificationData |
11 |
13 Sep 07 |
nicklas |
28 |
{ |
11 |
13 Sep 07 |
nicklas |
/** The id for the algorithm name. */ |
11 |
13 Sep 07 |
nicklas |
30 |
public static final String CHP_ALG_NAME = "affymetrix-algorithm-name"; |
11 |
13 Sep 07 |
nicklas |
31 |
|
11 |
13 Sep 07 |
nicklas |
/** The id for the algorithm version. */ |
11 |
13 Sep 07 |
nicklas |
33 |
public static final String CHP_ALG_VERSION = "affymetrix-algorithm-version"; |
11 |
13 Sep 07 |
nicklas |
34 |
|
11 |
13 Sep 07 |
nicklas |
/** A prefix for algorithm parameter ids. */ |
11 |
13 Sep 07 |
nicklas |
36 |
public static final String CHP_ALG_PARAM = "affymetrix-algorithm-param-"; |
11 |
13 Sep 07 |
nicklas |
37 |
|
11 |
13 Sep 07 |
nicklas |
/** A prefix for chip summary parameter ids. */ |
11 |
13 Sep 07 |
nicklas |
39 |
public static final String CHP_CHIP_SUM = "affymetrix-chipsummary-"; |
11 |
13 Sep 07 |
nicklas |
40 |
|
11 |
13 Sep 07 |
nicklas |
/** The identifier to identify a quantification CHP file. */ |
11 |
13 Sep 07 |
nicklas |
42 |
public static final String CHP_QUANTIFICATION_TYPE = "affymetrix-quantification-analysis"; |
11 |
13 Sep 07 |
nicklas |
43 |
|
11 |
13 Sep 07 |
nicklas |
/** The group and data set and column name to store the quantification data. */ |
11 |
13 Sep 07 |
nicklas |
45 |
public static final String QUANTIFICATION_QUANTIFICATION_NAME = "Quantification"; |
11 |
13 Sep 07 |
nicklas |
46 |
|
11 |
13 Sep 07 |
nicklas |
/** The column name for the probe set name. */ |
11 |
13 Sep 07 |
nicklas |
48 |
public static final String QUANTIFICATION_PROBE_SET_NAME = "ProbesetName"; |
11 |
13 Sep 07 |
nicklas |
49 |
|
11 |
13 Sep 07 |
nicklas |
/** The column name for the probe set id. */ |
11 |
13 Sep 07 |
nicklas |
51 |
public static final String QUANTIFICATION_PROBE_SET_ID = "ProbeSetId"; |
11 |
13 Sep 07 |
nicklas |
52 |
|
11 |
13 Sep 07 |
nicklas |
/** Constructor */ |
11 |
13 Sep 07 |
nicklas |
54 |
public CHPQuantificationData() { |
11 |
13 Sep 07 |
nicklas |
55 |
entries = null; |
11 |
13 Sep 07 |
nicklas |
56 |
maxProbesetName = -1; |
11 |
13 Sep 07 |
nicklas |
57 |
firstColumnType = ColumnInfo.UnicodeCharColType; |
11 |
13 Sep 07 |
nicklas |
58 |
clear(); |
11 |
13 Sep 07 |
nicklas |
59 |
genericData = new GenericData(); |
11 |
13 Sep 07 |
nicklas |
60 |
} |
11 |
13 Sep 07 |
nicklas |
61 |
|
11 |
13 Sep 07 |
nicklas |
/**ructor with file name. |
11 |
13 Sep 07 |
nicklas |
* @param filename The name of the CHP file. |
11 |
13 Sep 07 |
nicklas |
64 |
*/ |
11 |
13 Sep 07 |
nicklas |
65 |
public CHPQuantificationData(String filename) { |
11 |
13 Sep 07 |
nicklas |
66 |
entries = null; |
11 |
13 Sep 07 |
nicklas |
67 |
firstColumnType = ColumnInfo.UnicodeCharColType; |
11 |
13 Sep 07 |
nicklas |
68 |
maxProbesetName = -1; |
11 |
13 Sep 07 |
nicklas |
69 |
clear(); |
11 |
13 Sep 07 |
nicklas |
70 |
genericData = new GenericData(); |
11 |
13 Sep 07 |
nicklas |
71 |
setFilename(filename); |
11 |
13 Sep 07 |
nicklas |
72 |
DataGroupHeader dcHdr = new DataGroupHeader(QUANTIFICATION_QUANTIFICATION_NAME); |
11 |
13 Sep 07 |
nicklas |
73 |
genericData.getHeader().addDataGroupHdr(dcHdr); |
11 |
13 Sep 07 |
nicklas |
74 |
genericData.getHeader().getGenericDataHdr().setFileTypeId(CHP_QUANTIFICATION_TYPE); |
11 |
13 Sep 07 |
nicklas |
75 |
} |
11 |
13 Sep 07 |
nicklas |
76 |
|
11 |
13 Sep 07 |
nicklas |
/** Flag indicating if the probe set names were stored in wide character format. */ |
11 |
13 Sep 07 |
nicklas |
78 |
private int firstColumnType; |
11 |
13 Sep 07 |
nicklas |
79 |
|
11 |
13 Sep 07 |
nicklas |
/** The generic data item. */ |
11 |
13 Sep 07 |
nicklas |
81 |
private GenericData genericData; |
11 |
13 Sep 07 |
nicklas |
82 |
|
11 |
13 Sep 07 |
nicklas |
/** chp data sets */ |
11 |
13 Sep 07 |
nicklas |
84 |
private DataSet entries; |
11 |
13 Sep 07 |
nicklas |
85 |
|
11 |
13 Sep 07 |
nicklas |
/** The maximum length of a probe set name. */ |
11 |
13 Sep 07 |
nicklas |
87 |
private int maxProbesetName; |
11 |
13 Sep 07 |
nicklas |
88 |
|
11 |
13 Sep 07 |
nicklas |
/** The maximum length of a probe set name. */ |
11 |
13 Sep 07 |
nicklas |
90 |
public int getMaxProbesetName() { return maxProbesetName; } |
11 |
13 Sep 07 |
nicklas |
91 |
|
11 |
13 Sep 07 |
nicklas |
/** Clears the members. */ |
11 |
13 Sep 07 |
nicklas |
93 |
public void clear() { |
11 |
13 Sep 07 |
nicklas |
94 |
if (entries != null){ entries.delete(); entries = null; } |
11 |
13 Sep 07 |
nicklas |
95 |
if (genericData != null) |
11 |
13 Sep 07 |
nicklas |
96 |
genericData.getHeader().clear(); |
11 |
13 Sep 07 |
nicklas |
97 |
} |
11 |
13 Sep 07 |
nicklas |
98 |
|
11 |
13 Sep 07 |
nicklas |
/** sets the file name. |
11 |
13 Sep 07 |
nicklas |
* @param p The name of the CHP file |
11 |
13 Sep 07 |
nicklas |
101 |
*/ |
11 |
13 Sep 07 |
nicklas |
102 |
public void setFilename(String p) { |
11 |
13 Sep 07 |
nicklas |
103 |
genericData.getHeader().setFilename(p); |
11 |
13 Sep 07 |
nicklas |
104 |
} |
11 |
13 Sep 07 |
nicklas |
105 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the file name. |
11 |
13 Sep 07 |
nicklas |
* @return The file name. |
11 |
13 Sep 07 |
nicklas |
108 |
*/ |
11 |
13 Sep 07 |
nicklas |
109 |
public String getFilename() { |
11 |
13 Sep 07 |
nicklas |
110 |
return ((GenericData)genericData).getHeader().getFilename(); |
11 |
13 Sep 07 |
nicklas |
111 |
} |
11 |
13 Sep 07 |
nicklas |
112 |
|
11 |
13 Sep 07 |
nicklas |
/** sets the array type */ |
11 |
13 Sep 07 |
nicklas |
114 |
public String getArrayType() { |
11 |
13 Sep 07 |
nicklas |
115 |
return getWStringFromGenericHdr(AffymetrixParameterConsts.ARRAY_TYPE_PARAM_NAME); |
11 |
13 Sep 07 |
nicklas |
116 |
} |
11 |
13 Sep 07 |
nicklas |
117 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the number of entries (probe sets) */ |
11 |
13 Sep 07 |
nicklas |
119 |
public int getEntryCount() { |
11 |
13 Sep 07 |
nicklas |
120 |
DataGroupHeader dcHdr = genericData.getHeader().getDataGroup(0); |
11 |
13 Sep 07 |
nicklas |
121 |
DataSetHeader dpHdr = dcHdr.getDataSet(0); |
11 |
13 Sep 07 |
nicklas |
122 |
return dpHdr.getRowCnt(); |
11 |
13 Sep 07 |
nicklas |
123 |
} |
11 |
13 Sep 07 |
nicklas |
124 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the name of the algorithm. |
11 |
13 Sep 07 |
nicklas |
* @return The algorithm name. |
11 |
13 Sep 07 |
nicklas |
127 |
*/ |
11 |
13 Sep 07 |
nicklas |
128 |
public String getAlgName() { |
11 |
13 Sep 07 |
nicklas |
129 |
return getWStringFromGenericHdr(CHP_ALG_NAME); |
11 |
13 Sep 07 |
nicklas |
130 |
} |
11 |
13 Sep 07 |
nicklas |
131 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the algorithm version. |
11 |
13 Sep 07 |
nicklas |
* @return The version. |
11 |
13 Sep 07 |
nicklas |
134 |
*/ |
11 |
13 Sep 07 |
nicklas |
135 |
public String getAlgVersion() { |
11 |
13 Sep 07 |
nicklas |
136 |
return getWStringFromGenericHdr(CHP_ALG_VERSION); |
11 |
13 Sep 07 |
nicklas |
137 |
} |
11 |
13 Sep 07 |
nicklas |
138 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the algorithm parameters |
11 |
13 Sep 07 |
nicklas |
* @return The algoirhtm parameters. |
11 |
13 Sep 07 |
nicklas |
141 |
*/ |
11 |
13 Sep 07 |
nicklas |
142 |
public Vector/*ParameterNameValue*/ getAlgParams() { |
11 |
13 Sep 07 |
nicklas |
143 |
Vector algParams = new Vector(); |
11 |
13 Sep 07 |
nicklas |
144 |
Vector allParams = genericData.getHeader().getGenericDataHdr().getNameValParams(); |
11 |
13 Sep 07 |
nicklas |
145 |
for (int i=0; i<allParams.size(); i++) |
11 |
13 Sep 07 |
nicklas |
146 |
{ |
11 |
13 Sep 07 |
nicklas |
147 |
ParameterNameValue param = (ParameterNameValue) allParams.elementAt(i); |
11 |
13 Sep 07 |
nicklas |
148 |
String name = param.getName(); |
11 |
13 Sep 07 |
nicklas |
149 |
if (name.startsWith(CHP_ALG_PARAM) == true) |
11 |
13 Sep 07 |
nicklas |
150 |
{ |
11 |
13 Sep 07 |
nicklas |
151 |
ParameterNameValue algParam = new ParameterNameValue(param); |
11 |
13 Sep 07 |
nicklas |
152 |
algParam.setName( name.substring(CHP_ALG_PARAM.length(), name.length())); |
11 |
13 Sep 07 |
nicklas |
153 |
algParams.add(algParam); |
11 |
13 Sep 07 |
nicklas |
154 |
} |
11 |
13 Sep 07 |
nicklas |
155 |
} |
11 |
13 Sep 07 |
nicklas |
156 |
return algParams; |
11 |
13 Sep 07 |
nicklas |
157 |
} |
11 |
13 Sep 07 |
nicklas |
158 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the summary parameters |
11 |
13 Sep 07 |
nicklas |
* @return The summary parameters. |
11 |
13 Sep 07 |
nicklas |
161 |
*/ |
11 |
13 Sep 07 |
nicklas |
162 |
public Vector /*ParameterNameValue*/ getSummaryParams() { |
11 |
13 Sep 07 |
nicklas |
163 |
Vector algParams = new Vector(); |
11 |
13 Sep 07 |
nicklas |
164 |
Vector allParams = genericData.getHeader().getGenericDataHdr().getNameValParams(); |
11 |
13 Sep 07 |
nicklas |
165 |
for (int i=0; i<allParams.size(); i++) |
11 |
13 Sep 07 |
nicklas |
166 |
{ |
11 |
13 Sep 07 |
nicklas |
167 |
ParameterNameValue param = (ParameterNameValue) allParams.elementAt(i); |
11 |
13 Sep 07 |
nicklas |
168 |
String name = param.getName(); |
11 |
13 Sep 07 |
nicklas |
169 |
if (name.startsWith(CHP_CHIP_SUM) == true) |
11 |
13 Sep 07 |
nicklas |
170 |
{ |
11 |
13 Sep 07 |
nicklas |
171 |
ParameterNameValue algParam = new ParameterNameValue(param); |
11 |
13 Sep 07 |
nicklas |
172 |
algParam.setName( name.substring(CHP_CHIP_SUM.length(), name.length())); |
11 |
13 Sep 07 |
nicklas |
173 |
algParams.add(algParam); |
11 |
13 Sep 07 |
nicklas |
174 |
} |
11 |
13 Sep 07 |
nicklas |
175 |
} |
11 |
13 Sep 07 |
nicklas |
176 |
return algParams; |
11 |
13 Sep 07 |
nicklas |
177 |
} |
11 |
13 Sep 07 |
nicklas |
178 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the file header. |
11 |
13 Sep 07 |
nicklas |
* @return The file header. |
11 |
13 Sep 07 |
nicklas |
181 |
*/ |
11 |
13 Sep 07 |
nicklas |
182 |
public FileHeader getFileHeader() { return genericData.getHeader(); } |
11 |
13 Sep 07 |
nicklas |
183 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the generic data object. |
11 |
13 Sep 07 |
nicklas |
* @return The data object. |
11 |
13 Sep 07 |
nicklas |
186 |
*/ |
11 |
13 Sep 07 |
nicklas |
187 |
public GenericData getGenericData() { return genericData; } |
11 |
13 Sep 07 |
nicklas |
188 |
|
11 |
13 Sep 07 |
nicklas |
/** gets the sequence data. |
11 |
13 Sep 07 |
nicklas |
* @param index The row index. |
11 |
13 Sep 07 |
nicklas |
* @return The quantification value. |
11 |
13 Sep 07 |
nicklas |
192 |
*/ |
11 |
13 Sep 07 |
nicklas |
193 |
public ProbeSetQuantificationData getQuantificationEntry(int index) { |
11 |
13 Sep 07 |
nicklas |
194 |
ProbeSetQuantificationData entry = null; |
11 |
13 Sep 07 |
nicklas |
195 |
openQuantificationDataSet(); |
11 |
13 Sep 07 |
nicklas |
196 |
if (entries != null && entries.isOpen()) |
11 |
13 Sep 07 |
nicklas |
197 |
{ |
11 |
13 Sep 07 |
nicklas |
198 |
entry = new ProbeSetQuantificationData(); |
11 |
13 Sep 07 |
nicklas |
199 |
if (firstColumnType == ColumnInfo.ASCIICharColType) |
11 |
13 Sep 07 |
nicklas |
200 |
entry.setName(entries.getDataString8(index, 0)); |
11 |
13 Sep 07 |
nicklas |
201 |
else if (firstColumnType == ColumnInfo.UnicodeCharColType) |
11 |
13 Sep 07 |
nicklas |
202 |
entry.setName(entries.getDataString16(index, 0)); |
11 |
13 Sep 07 |
nicklas |
203 |
else if (firstColumnType == ColumnInfo.IntColType) |
11 |
13 Sep 07 |
nicklas |
204 |
entry.setId(entries.getDataInt(index, 0)); |
11 |
13 Sep 07 |
nicklas |
205 |
entry.setQuantification(entries.getDataFloat(index, 1)); |
11 |
13 Sep 07 |
nicklas |
206 |
} |
11 |
13 Sep 07 |
nicklas |
207 |
return entry; |
11 |
13 Sep 07 |
nicklas |
208 |
} |
11 |
13 Sep 07 |
nicklas |
209 |
|
11 |
13 Sep 07 |
nicklas |
/** Opens a group for reading. */ |
11 |
13 Sep 07 |
nicklas |
211 |
public void openQuantificationDataSet() { |
11 |
13 Sep 07 |
nicklas |
212 |
if (entries == null) |
11 |
13 Sep 07 |
nicklas |
213 |
{ |
11 |
13 Sep 07 |
nicklas |
214 |
try |
11 |
13 Sep 07 |
nicklas |
215 |
{ |
11 |
13 Sep 07 |
nicklas |
216 |
entries = genericData.getDataSet(0, 0); |
11 |
13 Sep 07 |
nicklas |
217 |
if (entries != null) |
11 |
13 Sep 07 |
nicklas |
218 |
{ |
11 |
13 Sep 07 |
nicklas |
219 |
entries.open(); |
11 |
13 Sep 07 |
nicklas |
220 |
firstColumnType = entries.getHeader().getColumnInfo(0).getColumnType(); |
11 |
13 Sep 07 |
nicklas |
221 |
} |
11 |
13 Sep 07 |
nicklas |
222 |
} |
11 |
13 Sep 07 |
nicklas |
223 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
224 |
{ |
11 |
13 Sep 07 |
nicklas |
225 |
entries = null; |
11 |
13 Sep 07 |
nicklas |
226 |
} |
11 |
13 Sep 07 |
nicklas |
227 |
} |
11 |
13 Sep 07 |
nicklas |
228 |
} |
11 |
13 Sep 07 |
nicklas |
229 |
|
11 |
13 Sep 07 |
nicklas |
/** gets a parameter value as a string. |
11 |
13 Sep 07 |
nicklas |
* @param name The name of the parameter. |
11 |
13 Sep 07 |
nicklas |
* @return The string representation. |
11 |
13 Sep 07 |
nicklas |
233 |
*/ |
11 |
13 Sep 07 |
nicklas |
234 |
private String getWStringFromGenericHdr(String name) { |
11 |
13 Sep 07 |
nicklas |
235 |
GenericDataHeader hdr = genericData.getHeader().getGenericDataHdr(); |
11 |
13 Sep 07 |
nicklas |
236 |
if (hdr == null) |
11 |
13 Sep 07 |
nicklas |
237 |
return null; |
11 |
13 Sep 07 |
nicklas |
238 |
ParameterNameValue paramType = hdr.findNameValParam(name); |
11 |
13 Sep 07 |
nicklas |
239 |
if (paramType != null) |
11 |
13 Sep 07 |
nicklas |
240 |
return paramType.getValueText(); |
11 |
13 Sep 07 |
nicklas |
241 |
return null; |
11 |
13 Sep 07 |
nicklas |
242 |
} |
11 |
13 Sep 07 |
nicklas |
243 |
|
11 |
13 Sep 07 |
nicklas |
244 |
}; |