affyfusion-109/src/affymetrix/calvin/data/CHPQuantificationDetectionData.java

Code
Comments
Other
Rev Date Author Line
11 13 Sep 07 nicklas 1 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 2 //
11 13 Sep 07 nicklas 3 // Copyright (C) 2006 Affymetrix, Inc.
11 13 Sep 07 nicklas 4 //
11 13 Sep 07 nicklas 5 // This library is free software; you can redistribute it and/or modify
11 13 Sep 07 nicklas 6 // it under the terms of the GNU Lesser General Public License as published
11 13 Sep 07 nicklas 7 // by the Free Software Foundation; either version 2.1 of the License,
11 13 Sep 07 nicklas 8 // or (at your option) any later version.
11 13 Sep 07 nicklas 9 //
11 13 Sep 07 nicklas 10 // This library is distributed in the hope that it will be useful, but
11 13 Sep 07 nicklas 11 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 13 Sep 07 nicklas 12 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 13 Sep 07 nicklas 13 // for more details.
11 13 Sep 07 nicklas 14 //
11 13 Sep 07 nicklas 15 // You should have received a copy of the GNU Lesser General Public License
11 13 Sep 07 nicklas 16 // along with this library; if not, write to the Free Software Foundation, Inc.,
11 13 Sep 07 nicklas 17 // 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 26 /** Holds data associated with quantification/detection array CHP files. */
11 13 Sep 07 nicklas 27 public class CHPQuantificationDetectionData
11 13 Sep 07 nicklas 28 {
11 13 Sep 07 nicklas 29     /** 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 32     /** 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 35     /** 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 38     /** 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 41     /** The identifier to identify a quantification/detection CHP file. */
11 13 Sep 07 nicklas 42     public static final String CHP_QUANTIFICATION_DETECTION_TYPE = "affymetrix-quantification-detection-analysis";
11 13 Sep 07 nicklas 43
11 13 Sep 07 nicklas 44     /** The group and data set to store the quantification/detection data. */
11 13 Sep 07 nicklas 45     public static final String QUANTIFICATION_DETECTION_NAME = "QuantificationDetection";
11 13 Sep 07 nicklas 46
11 13 Sep 07 nicklas 47     /** The column name for the probe set name. */
11 13 Sep 07 nicklas 48     public static final String QUANTIFICATION_DETECTION_PROBE_SET_NAME = "ProbesetName";
11 13 Sep 07 nicklas 49     
11 13 Sep 07 nicklas 50     /** The column name for the probe set id. */
11 13 Sep 07 nicklas 51     public static final String QUANTIFICATION_DETECTION_PROBE_SET_ID = "ProbeSetId";
11 13 Sep 07 nicklas 52
11 13 Sep 07 nicklas 53     /** The column name for the quantification value. */
11 13 Sep 07 nicklas 54     public static final String QUANTIFICATION_DETECTION_QUANTIFICATION_NAME = "Quantification";
11 13 Sep 07 nicklas 55
11 13 Sep 07 nicklas 56     /** The column name for the detection value. */
11 13 Sep 07 nicklas 57     public static final String QUANTIFICATION_DETECTION_DETECTION_NAME = "Detection";
11 13 Sep 07 nicklas 58
11 13 Sep 07 nicklas 59     /** Constructor */
11 13 Sep 07 nicklas 60     public CHPQuantificationDetectionData() {
11 13 Sep 07 nicklas 61         entries = null;
11 13 Sep 07 nicklas 62         maxProbesetName = -1;
11 13 Sep 07 nicklas 63   firstColumnType = ColumnInfo.UnicodeCharColType;
11 13 Sep 07 nicklas 64   clear();
11 13 Sep 07 nicklas 65         genericData = new GenericData();
11 13 Sep 07 nicklas 66     }
11 13 Sep 07 nicklas 67
11 13 Sep 07 nicklas 68     /**ructor with file name.
11 13 Sep 07 nicklas 69      * @param filename The name of the CHP file.
11 13 Sep 07 nicklas 70      */
11 13 Sep 07 nicklas 71     public CHPQuantificationDetectionData(String filename) {
11 13 Sep 07 nicklas 72         entries = null;
11 13 Sep 07 nicklas 73   firstColumnType = ColumnInfo.UnicodeCharColType;
11 13 Sep 07 nicklas 74         maxProbesetName = -1;
11 13 Sep 07 nicklas 75   clear();
11 13 Sep 07 nicklas 76         genericData = new GenericData();
11 13 Sep 07 nicklas 77   setFilename(filename);
11 13 Sep 07 nicklas 78   DataGroupHeader dcHdr = new DataGroupHeader(QUANTIFICATION_DETECTION_NAME);
11 13 Sep 07 nicklas 79   genericData.getHeader().addDataGroupHdr(dcHdr);
11 13 Sep 07 nicklas 80   genericData.getHeader().getGenericDataHdr().setFileTypeId(CHP_QUANTIFICATION_DETECTION_TYPE);
11 13 Sep 07 nicklas 81     }
11 13 Sep 07 nicklas 82
11 13 Sep 07 nicklas 83     /** Flag indicating if the probe set names were stored in wide character format. */
11 13 Sep 07 nicklas 84     private int firstColumnType;
11 13 Sep 07 nicklas 85     
11 13 Sep 07 nicklas 86     /** The generic data item. */
11 13 Sep 07 nicklas 87     private GenericData genericData;
11 13 Sep 07 nicklas 88
11 13 Sep 07 nicklas 89     /** chp data sets */
11 13 Sep 07 nicklas 90     private DataSet entries;
11 13 Sep 07 nicklas 91
11 13 Sep 07 nicklas 92     /** The maximum length of a probe set name. */
11 13 Sep 07 nicklas 93     private int maxProbesetName;
11 13 Sep 07 nicklas 94
11 13 Sep 07 nicklas 95     /** The maximum length of a probe set name. */
11 13 Sep 07 nicklas 96     public int getMaxProbesetName() { return maxProbesetName; }
11 13 Sep 07 nicklas 97
11 13 Sep 07 nicklas 98     /** Clears the members. */
11 13 Sep 07 nicklas 99     public void clear() {
11 13 Sep 07 nicklas 100          if (entries != null){ entries.delete();  entries = null; }
11 13 Sep 07 nicklas 101   if (genericData != null)
11 13 Sep 07 nicklas 102             genericData.getHeader().clear(); 
11 13 Sep 07 nicklas 103     }
11 13 Sep 07 nicklas 104
11 13 Sep 07 nicklas 105     /** sets the file name.
11 13 Sep 07 nicklas 106      * @param p The name of the CHP file
11 13 Sep 07 nicklas 107      */
11 13 Sep 07 nicklas 108     public void setFilename(String p) {
11 13 Sep 07 nicklas 109         genericData.getHeader().setFilename(p);
11 13 Sep 07 nicklas 110     }
11 13 Sep 07 nicklas 111
11 13 Sep 07 nicklas 112     /** gets the file name.
11 13 Sep 07 nicklas 113      * @return The file name.
11 13 Sep 07 nicklas 114      */
11 13 Sep 07 nicklas 115     public String getFilename() {
11 13 Sep 07 nicklas 116         return ((GenericData)genericData).getHeader().getFilename();
11 13 Sep 07 nicklas 117     }
11 13 Sep 07 nicklas 118
11 13 Sep 07 nicklas 119     /** sets the array type */
11 13 Sep 07 nicklas 120     public String getArrayType() {
11 13 Sep 07 nicklas 121         return getWStringFromGenericHdr(AffymetrixParameterConsts.ARRAY_TYPE_PARAM_NAME);
11 13 Sep 07 nicklas 122     }
11 13 Sep 07 nicklas 123
11 13 Sep 07 nicklas 124     /** gets the number of entries (probe sets) */
11 13 Sep 07 nicklas 125     public int getEntryCount() {
11 13 Sep 07 nicklas 126         DataGroupHeader dcHdr = genericData.getHeader().getDataGroup(0);
11 13 Sep 07 nicklas 127   DataSetHeader dpHdr = dcHdr.getDataSet(0);
11 13 Sep 07 nicklas 128   return dpHdr.getRowCnt();
11 13 Sep 07 nicklas 129     }
11 13 Sep 07 nicklas 130
11 13 Sep 07 nicklas 131     /** gets the name of the algorithm.
11 13 Sep 07 nicklas 132      * @return The algorithm name.
11 13 Sep 07 nicklas 133      */
11 13 Sep 07 nicklas 134     public String getAlgName() {
11 13 Sep 07 nicklas 135         return getWStringFromGenericHdr(CHP_ALG_NAME);
11 13 Sep 07 nicklas 136     }
11 13 Sep 07 nicklas 137
11 13 Sep 07 nicklas 138     /** gets the algorithm version.
11 13 Sep 07 nicklas 139      * @return The version.
11 13 Sep 07 nicklas 140      */
11 13 Sep 07 nicklas 141     public String getAlgVersion() {
11 13 Sep 07 nicklas 142         return getWStringFromGenericHdr(CHP_ALG_VERSION);
11 13 Sep 07 nicklas 143     }
11 13 Sep 07 nicklas 144
11 13 Sep 07 nicklas 145     /** gets the algorithm parameters
11 13 Sep 07 nicklas 146      * @return The algoirhtm parameters.
11 13 Sep 07 nicklas 147      */
11 13 Sep 07 nicklas 148     public Vector/*ParameterNameValueType*/ getAlgParams() {
11 13 Sep 07 nicklas 149         Vector algParams = new Vector();
11 13 Sep 07 nicklas 150         Vector allParams = genericData.getHeader().getGenericDataHdr().getNameValParams();
11 13 Sep 07 nicklas 151         for (int i=0; i<allParams.size(); i++)
11 13 Sep 07 nicklas 152         {
11 13 Sep 07 nicklas 153             ParameterNameValue param = (ParameterNameValue) allParams.elementAt(i);
11 13 Sep 07 nicklas 154             String name = param.getName();
11 13 Sep 07 nicklas 155             if (name.startsWith(CHP_ALG_PARAM) == true)
11 13 Sep 07 nicklas 156             {
11 13 Sep 07 nicklas 157                 ParameterNameValue algParam = new ParameterNameValue(param);
11 13 Sep 07 nicklas 158                 algParam.setName( name.substring(CHP_ALG_PARAM.length(), name.length()));
11 13 Sep 07 nicklas 159                 algParams.add(algParam);
11 13 Sep 07 nicklas 160             }
11 13 Sep 07 nicklas 161         }
11 13 Sep 07 nicklas 162         return algParams;
11 13 Sep 07 nicklas 163     }
11 13 Sep 07 nicklas 164
11 13 Sep 07 nicklas 165     /** gets the summary parameters
11 13 Sep 07 nicklas 166      * @return The summary parameters.
11 13 Sep 07 nicklas 167      */
11 13 Sep 07 nicklas 168     public Vector /*ParameterNameValueType*/ getSummaryParams() {
11 13 Sep 07 nicklas 169         Vector algParams = new Vector();
11 13 Sep 07 nicklas 170         Vector allParams = genericData.getHeader().getGenericDataHdr().getNameValParams();
11 13 Sep 07 nicklas 171         for (int i=0; i<allParams.size(); i++)
11 13 Sep 07 nicklas 172         {
11 13 Sep 07 nicklas 173             ParameterNameValue param = (ParameterNameValue) allParams.elementAt(i);
11 13 Sep 07 nicklas 174             String name = param.getName();
11 13 Sep 07 nicklas 175             if (name.startsWith(CHP_CHIP_SUM) == true)
11 13 Sep 07 nicklas 176             {
11 13 Sep 07 nicklas 177                 ParameterNameValue algParam = new ParameterNameValue(param);
11 13 Sep 07 nicklas 178                 algParam.setName( name.substring(CHP_CHIP_SUM.length(), name.length()));
11 13 Sep 07 nicklas 179                 algParams.add(algParam);
11 13 Sep 07 nicklas 180             }
11 13 Sep 07 nicklas 181         }
11 13 Sep 07 nicklas 182         return algParams;
11 13 Sep 07 nicklas 183     }
11 13 Sep 07 nicklas 184
11 13 Sep 07 nicklas 185     /** gets the file header.
11 13 Sep 07 nicklas 186      * @return The file header.
11 13 Sep 07 nicklas 187      */
11 13 Sep 07 nicklas 188     public FileHeader getFileHeader() { return genericData.getHeader(); }
11 13 Sep 07 nicklas 189
11 13 Sep 07 nicklas 190     /** gets the generic data object.
11 13 Sep 07 nicklas 191      * @return The data object.
11 13 Sep 07 nicklas 192      */
11 13 Sep 07 nicklas 193     public GenericData getGenericData() { return genericData; }
11 13 Sep 07 nicklas 194
11 13 Sep 07 nicklas 195     /** gets the sequence data.
11 13 Sep 07 nicklas 196      * @param index The row index.
11 13 Sep 07 nicklas 197      * @return The quantification value.
11 13 Sep 07 nicklas 198      */
11 13 Sep 07 nicklas 199     public ProbeSetQuantificationDetectionData getQuantificationDetectionEntry(int index) {
11 13 Sep 07 nicklas 200         ProbeSetQuantificationDetectionData entry = null;
11 13 Sep 07 nicklas 201         openQuantificationDetectionDataSet();
11 13 Sep 07 nicklas 202   if (entries != null && entries.isOpen())
11 13 Sep 07 nicklas 203   {
11 13 Sep 07 nicklas 204             entry = new ProbeSetQuantificationDetectionData();
11 13 Sep 07 nicklas 205             if (firstColumnType == ColumnInfo.ASCIICharColType)
11 13 Sep 07 nicklas 206                 entry.setName(entries.getDataString8(index, 0));
11 13 Sep 07 nicklas 207             else if (firstColumnType == ColumnInfo.UnicodeCharColType)
11 13 Sep 07 nicklas 208                 entry.setName(entries.getDataString16(index, 0));
11 13 Sep 07 nicklas 209             else if (firstColumnType == ColumnInfo.IntColType)
11 13 Sep 07 nicklas 210                 entry.setId(entries.getDataInt(index, 0));
11 13 Sep 07 nicklas 211             entry.setQuantification(entries.getDataFloat(index, 1));
11 13 Sep 07 nicklas 212             entry.setPValue(entries.getDataFloat(index, 2));
11 13 Sep 07 nicklas 213   }
11 13 Sep 07 nicklas 214         return entry;
11 13 Sep 07 nicklas 215     }
11 13 Sep 07 nicklas 216
11 13 Sep 07 nicklas 217     /** Opens a group for reading. */
11 13 Sep 07 nicklas 218     public void openQuantificationDetectionDataSet() {
11 13 Sep 07 nicklas 219         if (entries == null)
11 13 Sep 07 nicklas 220   {
11 13 Sep 07 nicklas 221             try
11 13 Sep 07 nicklas 222             {
11 13 Sep 07 nicklas 223                 entries = genericData.getDataSet(0, 0);
11 13 Sep 07 nicklas 224                 if (entries != null)
11 13 Sep 07 nicklas 225                 {
11 13 Sep 07 nicklas 226                         entries.open();           
11 13 Sep 07 nicklas 227                         firstColumnType = entries.getHeader().getColumnInfo(0).getColumnType();
11 13 Sep 07 nicklas 228                 }
11 13 Sep 07 nicklas 229             }
11 13 Sep 07 nicklas 230             catch (Throwable t)
11 13 Sep 07 nicklas 231             {
11 13 Sep 07 nicklas 232                 entries = null;
11 13 Sep 07 nicklas 233             }
11 13 Sep 07 nicklas 234   }
11 13 Sep 07 nicklas 235     }
11 13 Sep 07 nicklas 236
11 13 Sep 07 nicklas 237     /** gets a parameter value as a string.
11 13 Sep 07 nicklas 238      * @param name The name of the parameter.
11 13 Sep 07 nicklas 239      * @return The string representation.
11 13 Sep 07 nicklas 240      */
11 13 Sep 07 nicklas 241     private String getWStringFromGenericHdr(String name) {
11 13 Sep 07 nicklas 242   GenericDataHeader hdr = genericData.getHeader().getGenericDataHdr();
11 13 Sep 07 nicklas 243         if (hdr == null)
11 13 Sep 07 nicklas 244             return null;
11 13 Sep 07 nicklas 245   ParameterNameValue paramType = hdr.findNameValParam(name);
11 13 Sep 07 nicklas 246         if (paramType != null)
11 13 Sep 07 nicklas 247             return paramType.getValueText();
11 13 Sep 07 nicklas 248   return null;
11 13 Sep 07 nicklas 249     }
11 13 Sep 07 nicklas 250
11 13 Sep 07 nicklas 251 };