affyfusion-109/src/affymetrix/gcos/chp/CHPFileData.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) 2005 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
11 13 Sep 07 nicklas 22 package affymetrix.gcos.chp;
11 13 Sep 07 nicklas 23
11 13 Sep 07 nicklas 24 import affymetrix.gcos.*;
11 13 Sep 07 nicklas 25 import affymetrix.vector.*;
11 13 Sep 07 nicklas 26 import affymetrix.portability.*;
11 13 Sep 07 nicklas 27 import java.util.*;
11 13 Sep 07 nicklas 28 import java.io.*;
11 13 Sep 07 nicklas 29 import java.nio.*;
11 13 Sep 07 nicklas 30 import java.nio.channels.*;
11 13 Sep 07 nicklas 31 import java.nio.channels.FileChannel.*;
11 13 Sep 07 nicklas 32
11 13 Sep 07 nicklas 33 /** Provides storage for data in a GCOS CHP file. */
11 13 Sep 07 nicklas 34 public class CHPFileData {
11 13 Sep 07 nicklas 35     
11 13 Sep 07 nicklas 36     /** The CHP file magic number */
11 13 Sep 07 nicklas 37     private static final int CHP_FILE_MAGIC_NUMBER = 65;
11 13 Sep 07 nicklas 38
11 13 Sep 07 nicklas 39     /** The max CHP file version the parser can read */
11 13 Sep 07 nicklas 40     private static final int CHP_FILE_VERSION_NUMBER = 2;
11 13 Sep 07 nicklas 41
11 13 Sep 07 nicklas 42     /** Identifier to indicate absolute expression analysis results stored. */
11 13 Sep 07 nicklas 43     private static final int EXPRESSION_ABSOLUTE_STAT_ANALYSIS = 2;
11 13 Sep 07 nicklas 44
11 13 Sep 07 nicklas 45     /** Identifier to indicate comparison expression analysis results stored. */
11 13 Sep 07 nicklas 46     private static final int EXPRESSION_COMPARISON_STAT_ANALYSIS = 3;
11 13 Sep 07 nicklas 47
11 13 Sep 07 nicklas 48     /** Used to convert floating point values stored as ints in older CHP files. */
11 13 Sep 07 nicklas 49     private static final int ROUNDFLOAT = 1000;
11 13 Sep 07 nicklas 50
11 13 Sep 07 nicklas 51     /** The file header object */
11 13 Sep 07 nicklas 52     private CHPFileHeader header;
11 13 Sep 07 nicklas 53
11 13 Sep 07 nicklas 54     /** The full path of the CHP file */
11 13 Sep 07 nicklas 55     private String fileName;
11 13 Sep 07 nicklas 56
11 13 Sep 07 nicklas 57     /** A string to hold an error message associated with a read operation */
11 13 Sep 07 nicklas 58     private String strError;
11 13 Sep 07 nicklas 59
11 13 Sep 07 nicklas 60     /** The vector of probe set results */
11 13 Sep 07 nicklas 61     private Vector /*xyzProbeSetResults*/ probeSetResults;
11 13 Sep 07 nicklas 62
11 13 Sep 07 nicklas 63     /** The resequencing results. */
11 13 Sep 07 nicklas 64     private ResequencingResults reseqResults;
11 13 Sep 07 nicklas 65
11 13 Sep 07 nicklas 66     /** Creates a new instance of CHPFileData */
11 13 Sep 07 nicklas 67     public CHPFileData() {
11 13 Sep 07 nicklas 68         fileName = "";
11 13 Sep 07 nicklas 69         clear();
11 13 Sep 07 nicklas 70     }
11 13 Sep 07 nicklas 71
11 13 Sep 07 nicklas 72     /** Opens the file for reading.
11 13 Sep 07 nicklas 73      * @param bReadHeaderOnly Flag to indicate if the header is to be read only.
11 13 Sep 07 nicklas 74      * @return True if successful.
11 13 Sep 07 nicklas 75      */
11 13 Sep 07 nicklas 76     private boolean open(boolean bReadHeaderOnly) {
11 13 Sep 07 nicklas 77        
11 13 Sep 07 nicklas 78         // Clear and read the data
11 13 Sep 07 nicklas 79         clear();
11 13 Sep 07 nicklas 80         if (isXDACompatibleFile() == true)
11 13 Sep 07 nicklas 81             return readXDAFile(bReadHeaderOnly);
11 13 Sep 07 nicklas 82         else
11 13 Sep 07 nicklas 83             return readNonXDAFile(bReadHeaderOnly);
11 13 Sep 07 nicklas 84     }
11 13 Sep 07 nicklas 85         
11 13 Sep 07 nicklas 86     /** Read an XDA file.
11 13 Sep 07 nicklas 87      * @param bReadHeaderOnly Flag to indicate if the header is to be read only.
11 13 Sep 07 nicklas 88      * @return True if successful.
11 13 Sep 07 nicklas 89      */
11 13 Sep 07 nicklas 90     private boolean readXDAFile(boolean bReadHeaderOnly)
11 13 Sep 07 nicklas 91     {
11 13 Sep 07 nicklas 92         try
11 13 Sep 07 nicklas 93         {
11 13 Sep 07 nicklas 94             // Open the file.
11 13 Sep 07 nicklas 95             FileInputStream fis = new FileInputStream(fileName);
11 13 Sep 07 nicklas 96      
11 13 Sep 07 nicklas 97             // Read the header.
11 13 Sep 07 nicklas 98             if (readHeaderXDA(fis) == false)
11 13 Sep 07 nicklas 99                 return false;
11 13 Sep 07 nicklas 100             
11 13 Sep 07 nicklas 101             // Return if only reading the header.
11 13 Sep 07 nicklas 102             if (bReadHeaderOnly == true)
11 13 Sep 07 nicklas 103                 return true;
11 13 Sep 07 nicklas 104
11 13 Sep 07 nicklas 105             // Only continue if genotyping or expression
11 13 Sep 07 nicklas 106             int assayType = header.getAssayType();
11 13 Sep 07 nicklas 107             if (assayType != CHPFileHeader.EXPRESSION_ASSAY &&
11 13 Sep 07 nicklas 108                 assayType != CHPFileHeader.GENOTYPING_ASSAY &&
11 13 Sep 07 nicklas 109                 assayType != CHPFileHeader.UNIVERSAL_ASSAY &&
11 13 Sep 07 nicklas 110                 assayType != CHPFileHeader.RESEQUENCING_ASSAY)
11 13 Sep 07 nicklas 111             {
11 13 Sep 07 nicklas 112                 strError = "The software only supports reading expression, genotyping, tag or resequencing CHP files.";
11 13 Sep 07 nicklas 113                 return false;
11 13 Sep 07 nicklas 114             }
11 13 Sep 07 nicklas 115
11 13 Sep 07 nicklas 116             // Read the probe set data
11 13 Sep 07 nicklas 117             if (assayType == CHPFileHeader.EXPRESSION_ASSAY)
11 13 Sep 07 nicklas 118             {
11 13 Sep 07 nicklas 119                 return readExpressionXDA(fis);
11 13 Sep 07 nicklas 120             }
11 13 Sep 07 nicklas 121             else if (assayType == CHPFileHeader.GENOTYPING_ASSAY)
11 13 Sep 07 nicklas 122             {
11 13 Sep 07 nicklas 123                 return readGenotypingXDA(fis);
11 13 Sep 07 nicklas 124             }
11 13 Sep 07 nicklas 125             else if (assayType == CHPFileHeader.UNIVERSAL_ASSAY)
11 13 Sep 07 nicklas 126             {
11 13 Sep 07 nicklas 127                 return readUniversalXDA(fis);
11 13 Sep 07 nicklas 128             }
11 13 Sep 07 nicklas 129             else if (assayType == CHPFileHeader.RESEQUENCING_ASSAY)
11 13 Sep 07 nicklas 130             {
11 13 Sep 07 nicklas 131                 return readReseqXDA(fis);
11 13 Sep 07 nicklas 132             }
11 13 Sep 07 nicklas 133             else
11 13 Sep 07 nicklas 134             {
11 13 Sep 07 nicklas 135                 return false;
11 13 Sep 07 nicklas 136             }
11 13 Sep 07 nicklas 137         }
11 13 Sep 07 nicklas 138         catch (Throwable t)
11 13 Sep 07 nicklas 139         {
11 13 Sep 07 nicklas 140             strError = t.getMessage();
11 13 Sep 07 nicklas 141             return false;
11 13 Sep 07 nicklas 142         }
11 13 Sep 07 nicklas 143     }           
11 13 Sep 07 nicklas 144
11 13 Sep 07 nicklas 145     /** Read the header from an XDA file.
11 13 Sep 07 nicklas 146      * @param fis The input file stream.
11 13 Sep 07 nicklas 147      * @return True if successful.
11 13 Sep 07 nicklas 148      */
11 13 Sep 07 nicklas 149     private boolean readHeaderXDA(FileInputStream fis)
11 13 Sep 07 nicklas 150     {
11 13 Sep 07 nicklas 151         // Read the magic number.
11 13 Sep 07 nicklas 152         header = new CHPFileHeader();
11 13 Sep 07 nicklas 153         header.setMagic(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 154
11 13 Sep 07 nicklas 155         // Check if new type.
11 13 Sep 07 nicklas 156         if (header.getMagic() != CHP_FILE_MAGIC_NUMBER)
11 13 Sep 07 nicklas 157         {
11 13 Sep 07 nicklas 158                 strError = "The file does not appear to be the correct format.";
11 13 Sep 07 nicklas 159                 return false;
11 13 Sep 07 nicklas 160         }
11 13 Sep 07 nicklas 161
11 13 Sep 07 nicklas 162         // Read the version
11 13 Sep 07 nicklas 163         header.setVersion(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 164
11 13 Sep 07 nicklas 165         // Check for version 1 or 2
11 13 Sep 07 nicklas 166         if (header.getVersion() > CHP_FILE_VERSION_NUMBER)
11 13 Sep 07 nicklas 167         {
11 13 Sep 07 nicklas 168                 strError = "Unable to read this version of the CHP file.";
11 13 Sep 07 nicklas 169                 return false;
11 13 Sep 07 nicklas 170         }
11 13 Sep 07 nicklas 171
11 13 Sep 07 nicklas 172         // Get the dimensions of the array
11 13 Sep 07 nicklas 173         header.setCols(FileIO.ReadUInt16_I(fis));
11 13 Sep 07 nicklas 174         header.setRows(FileIO.ReadUInt16_I(fis));
11 13 Sep 07 nicklas 175
11 13 Sep 07 nicklas 176         // Number of probe sets.
11 13 Sep 07 nicklas 177         header.setNumProbeSets(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 178         int ival = FileIO.ReadInt32_I(fis); // no qc data extracted.
11 13 Sep 07 nicklas 179
11 13 Sep 07 nicklas 180         // Assay type
11 13 Sep 07 nicklas 181         header.setAssayType(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 182
11 13 Sep 07 nicklas 183         // Prog ID.
11 13 Sep 07 nicklas 184         header.setProgID(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 185
11 13 Sep 07 nicklas 186         // Parent cell file.
11 13 Sep 07 nicklas 187         header.setParentCellFile(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 188
11 13 Sep 07 nicklas 189         // Chip type
11 13 Sep 07 nicklas 190         header.setChipType(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 191
11 13 Sep 07 nicklas 192         // Algorithm
11 13 Sep 07 nicklas 193         header.setAlgName(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 194
11 13 Sep 07 nicklas 195         // Algorithm version
11 13 Sep 07 nicklas 196         header.setAlgVersion(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 197
11 13 Sep 07 nicklas 198         // Algorithm parameters.
11 13 Sep 07 nicklas 199         int nParams=FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 200         if (nParams > 0)
11 13 Sep 07 nicklas 201         {
11 13 Sep 07 nicklas 202             Vector algParams = new Vector();
11 13 Sep 07 nicklas 203             algParams.setSize(nParams);
11 13 Sep 07 nicklas 204             for (int iParam=0; iParam<nParams; iParam++)
11 13 Sep 07 nicklas 205             {
11 13 Sep 07 nicklas 206                 TagValuePair param = new TagValuePair();
11 13 Sep 07 nicklas 207                 param.setTag(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 208                 param.setValue(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 209                 algParams.set(iParam, param);
11 13 Sep 07 nicklas 210             }
11 13 Sep 07 nicklas 211             header.setAlgorithmParameters(algParams);
11 13 Sep 07 nicklas 212         }
11 13 Sep 07 nicklas 213         
11 13 Sep 07 nicklas 214         // Summary parameters
11 13 Sep 07 nicklas 215         nParams=FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 216         if (nParams > 0)
11 13 Sep 07 nicklas 217         {
11 13 Sep 07 nicklas 218             Vector chipSummary = new Vector();
11 13 Sep 07 nicklas 219             chipSummary.setSize(nParams);
11 13 Sep 07 nicklas 220             for (int iParam=0; iParam<nParams; iParam++)
11 13 Sep 07 nicklas 221             {
11 13 Sep 07 nicklas 222                 TagValuePair param = new TagValuePair();
11 13 Sep 07 nicklas 223                 param.setTag(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 224                 param.setValue(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 225                 chipSummary.set(iParam, param);
11 13 Sep 07 nicklas 226             }
11 13 Sep 07 nicklas 227             header.setSummaryParameters(chipSummary);
11 13 Sep 07 nicklas 228         }
11 13 Sep 07 nicklas 229
11 13 Sep 07 nicklas 230         // Background info    
11 13 Sep 07 nicklas 231         nParams = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 232         float sf = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 233         if (nParams > 0)
11 13 Sep 07 nicklas 234         {
11 13 Sep 07 nicklas 235             BackgroundZoneInfo zones = new BackgroundZoneInfo();
11 13 Sep 07 nicklas 236             zones.setSmoothFactor(sf);
11 13 Sep 07 nicklas 237             for (int iParam=0; iParam<nParams; iParam++)
11 13 Sep 07 nicklas 238             {
11 13 Sep 07 nicklas 239                 BackgroundZoneType zone = new BackgroundZoneType();
11 13 Sep 07 nicklas 240                 zone.setCenterX(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 241                 zone.setCenterY(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 242                 zone.setBackground(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 243                 zones.addZone(zone);
11 13 Sep 07 nicklas 244             }
11 13 Sep 07 nicklas 245             header.setBackgroundZoneInfo(zones);
11 13 Sep 07 nicklas 246         }
11 13 Sep 07 nicklas 247         return true;
11 13 Sep 07 nicklas 248     }
11 13 Sep 07 nicklas 249     
11 13 Sep 07 nicklas 250     /** Read the universal data from the XDA file.
11 13 Sep 07 nicklas 251      * @param fis The input file stream.
11 13 Sep 07 nicklas 252      * @return True if successful.
11 13 Sep 07 nicklas 253      */
11 13 Sep 07 nicklas 254     private boolean readUniversalXDA(FileInputStream fis)
11 13 Sep 07 nicklas 255     {
11 13 Sep 07 nicklas 256         // Read each probe set result.
11 13 Sep 07 nicklas 257         int n = header.getNumProbeSets();
11 13 Sep 07 nicklas 258         probeSetResults = new Vector();
11 13 Sep 07 nicklas 259         probeSetResults.setSize(n);        
11 13 Sep 07 nicklas 260         int dataSize = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 261         for (int iset=0; iset<n; iset++)
11 13 Sep 07 nicklas 262         {
11 13 Sep 07 nicklas 263             UniversalProbeSetResults results = new UniversalProbeSetResults();
11 13 Sep 07 nicklas 264
11 13 Sep 07 nicklas 265             // Read probe set result.
11 13 Sep 07 nicklas 266             results.setBackground(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 267             probeSetResults.set(iset, results);
11 13 Sep 07 nicklas 268         }
11 13 Sep 07 nicklas 269         return true;
11 13 Sep 07 nicklas 270     }
11 13 Sep 07 nicklas 271
11 13 Sep 07 nicklas 272     /** Read the resequencing data from the XDA file.
11 13 Sep 07 nicklas 273      * @param fis The input file stream.
11 13 Sep 07 nicklas 274      * @return True if successful.
11 13 Sep 07 nicklas 275      */
11 13 Sep 07 nicklas 276     private boolean readReseqXDA(FileInputStream fis)
11 13 Sep 07 nicklas 277     {
11 13 Sep 07 nicklas 278         int dataSize = FileIO.ReadInt32_I(fis); // not used.
11 13 Sep 07 nicklas 279
11 13 Sep 07 nicklas 280         // Read the base calls and scores.
11 13 Sep 07 nicklas 281         reseqResults = new ResequencingResults();
11 13 Sep 07 nicklas 282         dataSize = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 283         reseqResults.resizeCalledBases(dataSize);
11 13 Sep 07 nicklas 284         reseqResults.resizeScores(dataSize);
11 13 Sep 07 nicklas 285         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 286         {
11 13 Sep 07 nicklas 287             reseqResults.setCalledBase(index, (char)FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 288         }
11 13 Sep 07 nicklas 289         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 290         {
11 13 Sep 07 nicklas 291             reseqResults.setScore(index, FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 292         }
11 13 Sep 07 nicklas 293
11 13 Sep 07 nicklas 294         // Read the force and original calls.
11 13 Sep 07 nicklas 295         if (header.getVersion() >= 2)
11 13 Sep 07 nicklas 296         {
11 13 Sep 07 nicklas 297             // Read the force calls
11 13 Sep 07 nicklas 298             dataSize = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 299             reseqResults.resizeForceCalls(dataSize);
11 13 Sep 07 nicklas 300             for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 301             {
11 13 Sep 07 nicklas 302                 ForceCallType forceCall = new ForceCallType();
11 13 Sep 07 nicklas 303                 forceCall.setPosition(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 304                 forceCall.setCall((char)FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 305                 forceCall.setReason(FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 306                 reseqResults.setForceCall(index, forceCall);
11 13 Sep 07 nicklas 307             }
11 13 Sep 07 nicklas 308
11 13 Sep 07 nicklas 309             // Read the orig calls
11 13 Sep 07 nicklas 310             dataSize = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 311             reseqResults.resizeOrigCalls(dataSize);
11 13 Sep 07 nicklas 312             for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 313             {
11 13 Sep 07 nicklas 314                 BaseCallType baseCall= new BaseCallType();
11 13 Sep 07 nicklas 315                 baseCall.setPosition(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 316                 baseCall.setCall((char)FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 317                 reseqResults.setOrigCall(index, baseCall);
11 13 Sep 07 nicklas 318             }
11 13 Sep 07 nicklas 319         }
11 13 Sep 07 nicklas 320         return true;
11 13 Sep 07 nicklas 321     }
11 13 Sep 07 nicklas 322
11 13 Sep 07 nicklas 323     /** Read the expression data from the XDA file.
11 13 Sep 07 nicklas 324      * @param fis The input file stream.
11 13 Sep 07 nicklas 325      * @return True if successful.
11 13 Sep 07 nicklas 326      */
11 13 Sep 07 nicklas 327     private boolean readExpressionXDA(FileInputStream fis)
11 13 Sep 07 nicklas 328     {
11 13 Sep 07 nicklas 329         // Get the type of analysis
11 13 Sep 07 nicklas 330         byte analysisType = FileIO.ReadInt8(fis); // EXPRESSION_ABSOLUTE_STAT_ANALYSIS or EXPRESSION_COMPARISON_STAT_ANALYSIS
11 13 Sep 07 nicklas 331         int ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 332         if (analysisType != EXPRESSION_ABSOLUTE_STAT_ANALYSIS && analysisType != EXPRESSION_COMPARISON_STAT_ANALYSIS)
11 13 Sep 07 nicklas 333         {
11 13 Sep 07 nicklas 334                 strError = "The software only supports reading MAS 5 and above expression CHP files.";
11 13 Sep 07 nicklas 335                 return false;
11 13 Sep 07 nicklas 336         }
11 13 Sep 07 nicklas 337
11 13 Sep 07 nicklas 338         // Read each probe set result.
11 13 Sep 07 nicklas 339         int n = header.getNumProbeSets();
11 13 Sep 07 nicklas 340         probeSetResults = new Vector();
11 13 Sep 07 nicklas 341         probeSetResults.setSize(n);
11 13 Sep 07 nicklas 342         for (int iset=0; iset<n; iset++)
11 13 Sep 07 nicklas 343         {
11 13 Sep 07 nicklas 344             ExpressionProbeSetResults results = new ExpressionProbeSetResults();
11 13 Sep 07 nicklas 345
11 13 Sep 07 nicklas 346             // Read the absolute data.
11 13 Sep 07 nicklas 347             results.setDetection(FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 348             results.setDetectionPValue(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 349             results.setSignal(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 350             results.setNumPairs((short)FileIO.ReadUInt16_I(fis));
11 13 Sep 07 nicklas 351             results.setNumUsedPairs((short)FileIO.ReadUInt16_I(fis));
11 13 Sep 07 nicklas 352             results.setHasCompResults(false);
11 13 Sep 07 nicklas 353
11 13 Sep 07 nicklas 354             // Read the comparison data
11 13 Sep 07 nicklas 355             if (analysisType == EXPRESSION_COMPARISON_STAT_ANALYSIS)
11 13 Sep 07 nicklas 356             {
11 13 Sep 07 nicklas 357                     results.setHasCompResults(true);
11 13 Sep 07 nicklas 358                     results.setChange(FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 359                     results.setChangePValue(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 360                     results.setSignalLogRatio(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 361                     results.setSignalLogRatioLow(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 362                     results.setSignalLogRatioHigh(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 363                     results.setNumCommonPairs((short)FileIO.ReadUInt16_I(fis));
11 13 Sep 07 nicklas 364             }
11 13 Sep 07 nicklas 365             probeSetResults.set(iset, results);
11 13 Sep 07 nicklas 366         }
11 13 Sep 07 nicklas 367         return true;
11 13 Sep 07 nicklas 368     }
11 13 Sep 07 nicklas 369
11 13 Sep 07 nicklas 370     /** Read the genotyping data from the XDA file.
11 13 Sep 07 nicklas 371      * @param fis The input file stream.
11 13 Sep 07 nicklas 372      * @return True if successful.
11 13 Sep 07 nicklas 373      */
11 13 Sep 07 nicklas 374     private boolean readGenotypingXDA(FileInputStream fis)
11 13 Sep 07 nicklas 375     {
11 13 Sep 07 nicklas 376         final int DM_ALG_RESULT_SIZE = 21;
11 13 Sep 07 nicklas 377
11 13 Sep 07 nicklas 378         // Read each probe set result.
11 13 Sep 07 nicklas 379         int n = header.getNumProbeSets();
11 13 Sep 07 nicklas 380         probeSetResults = new Vector();
11 13 Sep 07 nicklas 381         probeSetResults.setSize(n);
11 13 Sep 07 nicklas 382         int dataSize=FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 383         for (int iset=0; iset<n; iset++)
11 13 Sep 07 nicklas 384         {
11 13 Sep 07 nicklas 385             GenotypeProbeSetResults results = new GenotypeProbeSetResults();
11 13 Sep 07 nicklas 386
11 13 Sep 07 nicklas 387             // Read probe set result.
11 13 Sep 07 nicklas 388             results.setAlleleCall(FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 389
11 13 Sep 07 nicklas 390             results.setConfidence(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 391             
11 13 Sep 07 nicklas 392             results.setRAS1(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 393             results.setPValue_AA(results.getRAS1());
11 13 Sep 07 nicklas 394
11 13 Sep 07 nicklas 395             results.setRAS2(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 396             results.setPValue_AB(results.getRAS2());
11 13 Sep 07 nicklas 397
11 13 Sep 07 nicklas 398             if (dataSize == DM_ALG_RESULT_SIZE)
11 13 Sep 07 nicklas 399             {
11 13 Sep 07 nicklas 400                     results.setPValue_BB(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 401                     results.setPValue_NoCall(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 402             }
11 13 Sep 07 nicklas 403             probeSetResults.set(iset, results);
11 13 Sep 07 nicklas 404         }
11 13 Sep 07 nicklas 405         return true;
11 13 Sep 07 nicklas 406     }
11 13 Sep 07 nicklas 407
11 13 Sep 07 nicklas 408
11 13 Sep 07 nicklas 409     /** Read the non-XDA file header.
11 13 Sep 07 nicklas 410      * @param fis The file input stream.
11 13 Sep 07 nicklas 411      * @return True if successful.
11 13 Sep 07 nicklas 412      */
11 13 Sep 07 nicklas 413     private boolean readHeaderNonXDA(FileInputStream fis, AffxIntVector tagCells) {
11 13 Sep 07 nicklas 414         // Read the string that defines the CHP file (older format).
11 13 Sep 07 nicklas 415         String appName="GeneChip Sequence File";
11 13 Sep 07 nicklas 416         String strMagic = FileIO.ReadFixedString(fis, appName.length());
11 13 Sep 07 nicklas 417         if (strMagic.compareTo(appName) != 0)
11 13 Sep 07 nicklas 418         {
11 13 Sep 07 nicklas 419             strError = "The file does not appear to be the correct format.";
11 13 Sep 07 nicklas 420             return false;
11 13 Sep 07 nicklas 421         }
11 13 Sep 07 nicklas 422
11 13 Sep 07 nicklas 423         // Read the version number
11 13 Sep 07 nicklas 424         header = new CHPFileHeader();
11 13 Sep 07 nicklas 425         header.setVersion(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 426
11 13 Sep 07 nicklas 427         // Read algorithm type string.
11 13 Sep 07 nicklas 428         header.setAlgName(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 429         header.setAlgVersion(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 430         
11 13 Sep 07 nicklas 431         // Read parameters.
11 13 Sep 07 nicklas 432         String strParam = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 433         header.setAlgorithmParameters(parseString(strParam, " ", "="));
11 13 Sep 07 nicklas 434
11 13 Sep 07 nicklas 435         // Read summary
11 13 Sep 07 nicklas 436         strParam = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 437         header.setSummaryParameters(parseString(strParam, " ", "="));
11 13 Sep 07 nicklas 438
11 13 Sep 07 nicklas 439         // rows
11 13 Sep 07 nicklas 440         header.setRows(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 441
11 13 Sep 07 nicklas 442         // cols
11 13 Sep 07 nicklas 443         header.setCols(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 444
11 13 Sep 07 nicklas 445         // #probe sets
11 13 Sep 07 nicklas 446         header.setNumProbeSets(FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 447
11 13 Sep 07 nicklas 448         // the maximum probe set number in the array
11 13 Sep 07 nicklas 449         int maxvalue = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 450
11 13 Sep 07 nicklas 451         // #qc probe sets
11 13 Sep 07 nicklas 452         int nqc = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 453
11 13 Sep 07 nicklas 454         // probe set numbers
11 13 Sep 07 nicklas 455         int ival;
11 13 Sep 07 nicklas 456         int nsets = header.getNumProbeSets();
11 13 Sep 07 nicklas 457         for (int j=0; j<nsets; j++)
11 13 Sep 07 nicklas 458                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 459
11 13 Sep 07 nicklas 460         // #probe pairs in each probe set.
11 13 Sep 07 nicklas 461         for (int j=0; j<maxvalue; j++)
11 13 Sep 07 nicklas 462                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 463
11 13 Sep 07 nicklas 464         // type of probe set
11 13 Sep 07 nicklas 465         for (int j=0; j<maxvalue; j++)
11 13 Sep 07 nicklas 466         {
11 13 Sep 07 nicklas 467             ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 468             if (j == 0)
11 13 Sep 07 nicklas 469             {
11 13 Sep 07 nicklas 470                 switch (ival)
11 13 Sep 07 nicklas 471                 {
11 13 Sep 07 nicklas 472                 case 1:
11 13 Sep 07 nicklas 473                     header.setAssayType(CHPFileHeader.RESEQUENCING_ASSAY);
11 13 Sep 07 nicklas 474                     break;
11 13 Sep 07 nicklas 475
11 13 Sep 07 nicklas 476                 case 2:
11 13 Sep 07 nicklas 477                     header.setAssayType(CHPFileHeader.GENOTYPING_ASSAY);
11 13 Sep 07 nicklas 478                     break;
11 13 Sep 07 nicklas 479
11 13 Sep 07 nicklas 480                 case 3:
11 13 Sep 07 nicklas 481                     header.setAssayType(CHPFileHeader.EXPRESSION_ASSAY);
11 13 Sep 07 nicklas 482                     break;
11 13 Sep 07 nicklas 483
11 13 Sep 07 nicklas 484                 case 7:
11 13 Sep 07 nicklas 485                     header.setAssayType(CHPFileHeader.UNIVERSAL_ASSAY);
11 13 Sep 07 nicklas 486                     break;
11 13 Sep 07 nicklas 487
11 13 Sep 07 nicklas 488                 default:
11 13 Sep 07 nicklas 489                     header.setAssayType(CHPFileHeader.UNKNOWN_ASSAY);
11 13 Sep 07 nicklas 490                     break;
11 13 Sep 07 nicklas 491                 }
11 13 Sep 07 nicklas 492             }
11 13 Sep 07 nicklas 493         }
11 13 Sep 07 nicklas 494
11 13 Sep 07 nicklas 495         // This must be a resequencing design if there are no probe sets.
11 13 Sep 07 nicklas 496         if (nsets == 0)
11 13 Sep 07 nicklas 497             header.setAssayType(CHPFileHeader.RESEQUENCING_ASSAY);
11 13 Sep 07 nicklas 498
11 13 Sep 07 nicklas 499         // Check for valid versions.
11 13 Sep 07 nicklas 500         if ((header.getVersion() < 12 && (header.getAssayType() == CHPFileHeader.EXPRESSION_ASSAY || header.getAssayType() == CHPFileHeader.GENOTYPING_ASSAY)) ||
11 13 Sep 07 nicklas 501             (header.getVersion() < 10 && header.getAssayType() == CHPFileHeader.UNIVERSAL_ASSAY))
11 13 Sep 07 nicklas 502         {
11 13 Sep 07 nicklas 503             strError = "This version of the CHP file is not supported by the parser.";
11 13 Sep 07 nicklas 504             return false;
11 13 Sep 07 nicklas 505         }
11 13 Sep 07 nicklas 506
11 13 Sep 07 nicklas 507
11 13 Sep 07 nicklas 508         // # probe probes per element (probe pair, probe quartet, etc).
11 13 Sep 07 nicklas 509         boolean readTagCells = false;
11 13 Sep 07 nicklas 510         if (header.getAssayType() == CHPFileHeader.UNIVERSAL_ASSAY)
11 13 Sep 07 nicklas 511         {
11 13 Sep 07 nicklas 512             readTagCells = true;
11 13 Sep 07 nicklas 513             tagCells.setSize(nsets);
11 13 Sep 07 nicklas 514         }
11 13 Sep 07 nicklas 515         for (int j=0; j<nsets; j++)
11 13 Sep 07 nicklas 516         {
11 13 Sep 07 nicklas 517             ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 518             if (readTagCells == true)
11 13 Sep 07 nicklas 519                 tagCells.setInt(j, ival);
11 13 Sep 07 nicklas 520         }
11 13 Sep 07 nicklas 521
11 13 Sep 07 nicklas 522         // Get the chip type
11 13 Sep 07 nicklas 523         header.setChipType(FileIO.ReadFixedString(fis, 256));
11 13 Sep 07 nicklas 524
11 13 Sep 07 nicklas 525         // The parent CEL file.
11 13 Sep 07 nicklas 526         header.setParentCellFile(FileIO.ReadFixedString(fis, 256));
11 13 Sep 07 nicklas 527
11 13 Sep 07 nicklas 528         // The prog ID.
11 13 Sep 07 nicklas 529         header.setProgID(FileIO.ReadString_I(fis));
11 13 Sep 07 nicklas 530
11 13 Sep 07 nicklas 531         return true;
11 13 Sep 07 nicklas 532     }
11 13 Sep 07 nicklas 533     
11 13 Sep 07 nicklas 534     /** Reads the expression data from a non-XDA file.
11 13 Sep 07 nicklas 535      * @param fis The input file stream.
11 13 Sep 07 nicklas 536      * @return True if successful.
11 13 Sep 07 nicklas 537      */
11 13 Sep 07 nicklas 538     private boolean readExpressionNonXDA(FileInputStream fis)
11 13 Sep 07 nicklas 539     {
11 13 Sep 07 nicklas 540         // Read each probe set result.
11 13 Sep 07 nicklas 541         int ival;
11 13 Sep 07 nicklas 542         float fval;
11 13 Sep 07 nicklas 543         byte bval;
11 13 Sep 07 nicklas 544         int nsets = header.getNumProbeSets();
11 13 Sep 07 nicklas 545         probeSetResults = new Vector();
11 13 Sep 07 nicklas 546         probeSetResults.setSize(nsets);
11 13 Sep 07 nicklas 547         for (int iset=0; iset<nsets; iset++)
11 13 Sep 07 nicklas 548         {
11 13 Sep 07 nicklas 549             ExpressionProbeSetResults results = new ExpressionProbeSetResults();
11 13 Sep 07 nicklas 550
11 13 Sep 07 nicklas 551             results.setNumPairs((short)FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 552             results.setNumUsedPairs((short)FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 553             if (header.getVersion() <= 12) // unused
11 13 Sep 07 nicklas 554                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 555
11 13 Sep 07 nicklas 556             ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 557             if (header.getVersion() == 12)
11 13 Sep 07 nicklas 558             {
11 13 Sep 07 nicklas 559                 ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 560                 ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 561                 ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 562             }
11 13 Sep 07 nicklas 563
11 13 Sep 07 nicklas 564             results.setDetectionPValue(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 565
11 13 Sep 07 nicklas 566             if (header.getVersion() == 12)
11 13 Sep 07 nicklas 567             {
11 13 Sep 07 nicklas 568                 fval = FileIO.ReadFloat_I(fis); // unused
11 13 Sep 07 nicklas 569             }
11 13 Sep 07 nicklas 570
11 13 Sep 07 nicklas 571             results.setSignal(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 572             results.setDetection((byte)FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 573
11 13 Sep 07 nicklas 574             // unused
11 13 Sep 07 nicklas 575             int npairs = results.getNumPairs();
11 13 Sep 07 nicklas 576             for (int ip=0; ip<npairs; ++ip)
11 13 Sep 07 nicklas 577             {
11 13 Sep 07 nicklas 578                 fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 579                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 580                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 581                 {
11 13 Sep 07 nicklas 582                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 583                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 584                     fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 585                     fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 586                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 587                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 588                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 589                 }
11 13 Sep 07 nicklas 590                 else
11 13 Sep 07 nicklas 591                 {
11 13 Sep 07 nicklas 592                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 593                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 594                 }
11 13 Sep 07 nicklas 595                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 596                 {
11 13 Sep 07 nicklas 597                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 598                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 599                     fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 600                     fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 601                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 602                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 603                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 604                 }
11 13 Sep 07 nicklas 605                 else
11 13 Sep 07 nicklas 606                 {
11 13 Sep 07 nicklas 607                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 608                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 609                 }
11 13 Sep 07 nicklas 610             }
11 13 Sep 07 nicklas 611
11 13 Sep 07 nicklas 612             ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 613             results.setHasCompResults(ival == 1 ? true : false);
11 13 Sep 07 nicklas 614
11 13 Sep 07 nicklas 615             if (results.getHasCompResults() == true)
11 13 Sep 07 nicklas 616             {
11 13 Sep 07 nicklas 617                 results.setNumCommonPairs((short)FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 618
11 13 Sep 07 nicklas 619                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 620                 {
11 13 Sep 07 nicklas 621                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 622                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 623                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 624                 }
11 13 Sep 07 nicklas 625
11 13 Sep 07 nicklas 626                 results.setChange((byte)FileIO.ReadInt32_I(fis));
11 13 Sep 07 nicklas 627
11 13 Sep 07 nicklas 628                 bval = FileIO.ReadInt8(fis); // unused
11 13 Sep 07 nicklas 629                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 630                 {
11 13 Sep 07 nicklas 631                     bval = FileIO.ReadInt8(fis); // unused
11 13 Sep 07 nicklas 632                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 633                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 634                 }
11 13 Sep 07 nicklas 635
11 13 Sep 07 nicklas 636                 results.setSignalLogRatioHigh((float)FileIO.ReadInt32_I(fis) / ROUNDFLOAT);
11 13 Sep 07 nicklas 637
11 13 Sep 07 nicklas 638                 ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 639
11 13 Sep 07 nicklas 640                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 641                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 642
11 13 Sep 07 nicklas 643                 results.setSignalLogRatio((float)FileIO.ReadInt32_I(fis) / ROUNDFLOAT);
11 13 Sep 07 nicklas 644
11 13 Sep 07 nicklas 645                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 646                     ival = FileIO.ReadInt32_I(fis); // unused
11 13 Sep 07 nicklas 647
11 13 Sep 07 nicklas 648                 results.setSignalLogRatioLow((float)FileIO.ReadInt32_I(fis) / ROUNDFLOAT);
11 13 Sep 07 nicklas 649
11 13 Sep 07 nicklas 650                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 651                 {
11 13 Sep 07 nicklas 652                     results.setChangePValue((float)FileIO.ReadInt32_I(fis) / ROUNDFLOAT);
11 13 Sep 07 nicklas 653                 }
11 13 Sep 07 nicklas 654                 else
11 13 Sep 07 nicklas 655                 {
11 13 Sep 07 nicklas 656                     results.setChangePValue(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 657                 }
11 13 Sep 07 nicklas 658             }
11 13 Sep 07 nicklas 659             probeSetResults.set(iset, results);
11 13 Sep 07 nicklas 660         }
11 13 Sep 07 nicklas 661         return true;
11 13 Sep 07 nicklas 662     }
11 13 Sep 07 nicklas 663
11 13 Sep 07 nicklas 664     /** Reads the genotyping data from a non-XDA file.
11 13 Sep 07 nicklas 665      * @param fis The input file stream.
11 13 Sep 07 nicklas 666      * @return True if successful.
11 13 Sep 07 nicklas 667      */
11 13 Sep 07 nicklas 668     private boolean readGenotypingNonXDA(FileInputStream fis)
11 13 Sep 07 nicklas 669     {
11 13 Sep 07 nicklas 670         int nsets = header.getNumProbeSets();
11 13 Sep 07 nicklas 671         probeSetResults = new Vector();
11 13 Sep 07 nicklas 672         probeSetResults.setSize(nsets);
11 13 Sep 07 nicklas 673         int ival;
11 13 Sep 07 nicklas 674         float fval;
11 13 Sep 07 nicklas 675         byte bval;
11 13 Sep 07 nicklas 676         String sval;
11 13 Sep 07 nicklas 677         for (int iset=0; iset<nsets; iset++)
11 13 Sep 07 nicklas 678         {
11 13 Sep 07 nicklas 679             GenotypeProbeSetResults results = new GenotypeProbeSetResults();
11 13 Sep 07 nicklas 680
11 13 Sep 07 nicklas 681             // Unused data
11 13 Sep 07 nicklas 682             int ngroups=FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 683             for (int ig=0; ig<ngroups; ig++)
11 13 Sep 07 nicklas 684             {
11 13 Sep 07 nicklas 685                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 686                 sval = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 687                 bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 688                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 689                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 690                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 691             }
11 13 Sep 07 nicklas 692             bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 693             if (bval == 1)
11 13 Sep 07 nicklas 694             {
11 13 Sep 07 nicklas 695                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 696                 sval = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 697                 sval = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 698                 sval = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 699                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 700                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 701
11 13 Sep 07 nicklas 702                 // The call
11 13 Sep 07 nicklas 703                 results.setAlleleCall(FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 704
11 13 Sep 07 nicklas 705                 // The confidence
11 13 Sep 07 nicklas 706                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 707                 {
11 13 Sep 07 nicklas 708                     results.setConfidence((float)FileIO.ReadInt32_I(fis) / ROUNDFLOAT);
11 13 Sep 07 nicklas 709                 }
11 13 Sep 07 nicklas 710                 else
11 13 Sep 07 nicklas 711                 {
11 13 Sep 07 nicklas 712                     results.setConfidence(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 713                 }
11 13 Sep 07 nicklas 714
11 13 Sep 07 nicklas 715                 // unused
11 13 Sep 07 nicklas 716                 fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 717                 fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 718                 fval = FileIO.ReadFloat_I(fis);
11 13 Sep 07 nicklas 719
11 13 Sep 07 nicklas 720                 // RAS 1 and 2
11 13 Sep 07 nicklas 721                 results.setRAS1(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 722                 results.setRAS2(FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 723             }
11 13 Sep 07 nicklas 724             else
11 13 Sep 07 nicklas 725             {
11 13 Sep 07 nicklas 726                 results.setConfidence(0.0f);
11 13 Sep 07 nicklas 727                 results.setRAS1(0.0f);
11 13 Sep 07 nicklas 728                 results.setRAS2(0.0f);
11 13 Sep 07 nicklas 729                 results.setAlleleCall(GenotypeProbeSetResults.ALLELE_NO_CALL);
11 13 Sep 07 nicklas 730             }
11 13 Sep 07 nicklas 731
11 13 Sep 07 nicklas 732
11 13 Sep 07 nicklas 733             // 100K results are not stored in this version
11 13 Sep 07 nicklas 734             results.setPValue_AA(0.0f);
11 13 Sep 07 nicklas 735             results.setPValue_AB(0.0f);
11 13 Sep 07 nicklas 736             results.setPValue_BB(0.0f);
11 13 Sep 07 nicklas 737             results.setPValue_NoCall(0.0f);
11 13 Sep 07 nicklas 738
11 13 Sep 07 nicklas 739             // unused
11 13 Sep 07 nicklas 740             sval = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 741             sval = FileIO.ReadString_I(fis);
11 13 Sep 07 nicklas 742             int np = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 743             for (int ip=0; ip<np; ++ip)
11 13 Sep 07 nicklas 744             {
11 13 Sep 07 nicklas 745                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 746                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 747                 {
11 13 Sep 07 nicklas 748                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 749                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 750                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 751                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 752                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 753                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 754                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 755                 }
11 13 Sep 07 nicklas 756                 else
11 13 Sep 07 nicklas 757                 {
11 13 Sep 07 nicklas 758                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 759                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 760                 }
11 13 Sep 07 nicklas 761                 if (header.getVersion() == 12)
11 13 Sep 07 nicklas 762                 {
11 13 Sep 07 nicklas 763                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 764                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 765                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 766                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 767                     ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 768                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 769                     bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 770                 }
11 13 Sep 07 nicklas 771                 else
11 13 Sep 07 nicklas 772                 {
11 13 Sep 07 nicklas 773                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 774                     ival = FileIO.ReadUInt16_I(fis);
11 13 Sep 07 nicklas 775                 }
11 13 Sep 07 nicklas 776             }
11 13 Sep 07 nicklas 777             probeSetResults.set(iset, results);
11 13 Sep 07 nicklas 778         }
11 13 Sep 07 nicklas 779         return true;
11 13 Sep 07 nicklas 780     }
11 13 Sep 07 nicklas 781
11 13 Sep 07 nicklas 782     /** Reads the universal data from a non-XDA file.
11 13 Sep 07 nicklas 783      * @param fis The input file stream.
11 13 Sep 07 nicklas 784      * @param tagCells The number of cells per atom.
11 13 Sep 07 nicklas 785      * @return True if successful.
11 13 Sep 07 nicklas 786      */
11 13 Sep 07 nicklas 787     private boolean readUniversalNonXDA(FileInputStream fis, AffxIntVector tagCells)
11 13 Sep 07 nicklas 788     {
11 13 Sep 07 nicklas 789         int nsets = header.getNumProbeSets();
11 13 Sep 07 nicklas 790         probeSetResults = new Vector();
11 13 Sep 07 nicklas 791         probeSetResults.setSize(nsets);
11 13 Sep 07 nicklas 792         byte bval;
11 13 Sep 07 nicklas 793         int ival;
11 13 Sep 07 nicklas 794
11 13 Sep 07 nicklas 795         // Read each probe set result.
11 13 Sep 07 nicklas 796         for (int iset=0; iset<nsets; iset++)
11 13 Sep 07 nicklas 797         {
11 13 Sep 07 nicklas 798             UniversalProbeSetResults results = new UniversalProbeSetResults();
11 13 Sep 07 nicklas 799
11 13 Sep 07 nicklas 800             // unused (wildtype) length(int), string(len)
11 13 Sep 07 nicklas 801             ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 802             for (int ibase=0; ibase<ival; ibase++)
11 13 Sep 07 nicklas 803             {
11 13 Sep 07 nicklas 804                 bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 805             }
11 13 Sep 07 nicklas 806             // unused (called) length(int), string(len)
11 13 Sep 07 nicklas 807             ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 808             for (int ibase=0; ibase<ival; ibase++)
11 13 Sep 07 nicklas 809             {
11 13 Sep 07 nicklas 810                 bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 811             }
11 13 Sep 07 nicklas 812
11 13 Sep 07 nicklas 813             // unused (#atoms(int))
11 13 Sep 07 nicklas 814             int natoms = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 815             for (int iatom=0; iatom<natoms; iatom++)
11 13 Sep 07 nicklas 816             {
11 13 Sep 07 nicklas 817                 ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 818                 if (iatom == 0)
11 13 Sep 07 nicklas 819                 {
11 13 Sep 07 nicklas 820                     results.setBackground((float) ival / ROUNDFLOAT);
11 13 Sep 07 nicklas 821                 }
11 13 Sep 07 nicklas 822
11 13 Sep 07 nicklas 823                 // Ignore the probe level data.
11 13 Sep 07 nicklas 824                 int ncells = tagCells.getInt(iset);
11 13 Sep 07 nicklas 825                 for (int icell=0; icell<ncells; icell++)
11 13 Sep 07 nicklas 826                 {
11 13 Sep 07 nicklas 827                     if (header.getVersion() <= 12)
11 13 Sep 07 nicklas 828                     {
11 13 Sep 07 nicklas 829                         ival = FileIO.ReadInt32_I(fis); // unused X coordinate
11 13 Sep 07 nicklas 830                         ival = FileIO.ReadInt32_I(fis); // unused Y coordinate
11 13 Sep 07 nicklas 831                     }
11 13 Sep 07 nicklas 832                     else
11 13 Sep 07 nicklas 833                     {
11 13 Sep 07 nicklas 834                         ival = FileIO.ReadUInt16_I(fis); // unused X coordinate
11 13 Sep 07 nicklas 835                         ival = FileIO.ReadUInt16_I(fis); // unused Y coordinate
11 13 Sep 07 nicklas 836                     }
11 13 Sep 07 nicklas 837                     if (header.getVersion() <= 12)
11 13 Sep 07 nicklas 838                     {
11 13 Sep 07 nicklas 839                         ival = FileIO.ReadInt32_I(fis); // unused intensity
11 13 Sep 07 nicklas 840                         ival = FileIO.ReadInt32_I(fis); // unused stdv
11 13 Sep 07 nicklas 841                         ival = FileIO.ReadInt32_I(fis); // unused pixel count
11 13 Sep 07 nicklas 842                         if (header.getVersion() >= 8)
11 13 Sep 07 nicklas 843                         {
11 13 Sep 07 nicklas 844                             bval = FileIO.ReadInt8(fis); // unused mask
11 13 Sep 07 nicklas 845                             bval = FileIO.ReadInt8(fis); // unused outlier
11 13 Sep 07 nicklas 846                         }
11 13 Sep 07 nicklas 847                     }
11 13 Sep 07 nicklas 848                 }
11 13 Sep 07 nicklas 849             }
11 13 Sep 07 nicklas 850             probeSetResults.set(iset, results);
11 13 Sep 07 nicklas 851         }
11 13 Sep 07 nicklas 852         return true;
11 13 Sep 07 nicklas 853     }
11 13 Sep 07 nicklas 854
11 13 Sep 07 nicklas 855     /** Reads the resequencing data from a non-XDA file.
11 13 Sep 07 nicklas 856      * @param fis The input file stream.
11 13 Sep 07 nicklas 857      * @return True if successful.
11 13 Sep 07 nicklas 858      */
11 13 Sep 07 nicklas 859     private boolean readReseqNonXDA(FileInputStream fis)
11 13 Sep 07 nicklas 860     {
11 13 Sep 07 nicklas 861         byte bval;
11 13 Sep 07 nicklas 862         int ival;
11 13 Sep 07 nicklas 863         String sval;
11 13 Sep 07 nicklas 864         
11 13 Sep 07 nicklas 865         // Read the base calls.
11 13 Sep 07 nicklas 866         reseqResults = new ResequencingResults();
11 13 Sep 07 nicklas 867         int dataSize = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 868         reseqResults.resizeCalledBases(dataSize);
11 13 Sep 07 nicklas 869         reseqResults.resizeScores(dataSize);
11 13 Sep 07 nicklas 870         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 871         {
11 13 Sep 07 nicklas 872             reseqResults.setCalledBase(index, (char)FileIO.ReadInt8(fis));
11 13 Sep 07 nicklas 873         }
11 13 Sep 07 nicklas 874
11 13 Sep 07 nicklas 875         // Ignore the edit section - there were none with the non-XDA file.
11 13 Sep 07 nicklas 876         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 877         {
11 13 Sep 07 nicklas 878             bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 879         }
11 13 Sep 07 nicklas 880
11 13 Sep 07 nicklas 881         // Ignore the confidence section - there were none with the non-XDA file.
11 13 Sep 07 nicklas 882         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 883         {
11 13 Sep 07 nicklas 884             bval = FileIO.ReadInt8(fis);
11 13 Sep 07 nicklas 885         }
11 13 Sep 07 nicklas 886
11 13 Sep 07 nicklas 887         // Ignore the unit index section - there were none with the non-XDA file.
11 13 Sep 07 nicklas 888         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 889         {
11 13 Sep 07 nicklas 890             ival = FileIO.ReadInt16_I(fis);
11 13 Sep 07 nicklas 891         }
11 13 Sep 07 nicklas 892
11 13 Sep 07 nicklas 893         ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 894         if (ival>0)
11 13 Sep 07 nicklas 895         {
11 13 Sep 07 nicklas 896             sval = FileIO.ReadFixedString(fis, ival);
11 13 Sep 07 nicklas 897             ival = FileIO.ReadInt32_I(fis);
11 13 Sep 07 nicklas 898             if (ival>0)
11 13 Sep 07 nicklas 899                 sval = FileIO.ReadFixedString(fis, ival);
11 13 Sep 07 nicklas 900         }
11 13 Sep 07 nicklas 901
11 13 Sep 07 nicklas 902         for (int index=0; index<dataSize; index++)
11 13 Sep 07 nicklas 903         {
11 13 Sep 07 nicklas 904             reseqResults.setScore(index, FileIO.ReadFloat_I(fis));
11 13 Sep 07 nicklas 905         }
11 13 Sep 07 nicklas 906
11 13 Sep 07 nicklas 907         return true;
11 13 Sep 07 nicklas 908     }
11 13 Sep 07 nicklas 909             
11 13 Sep 07 nicklas 910     /** Read an non-XDA file.
11 13 Sep 07 nicklas 911      * @param bReadHeaderOnly Flag to indicate if the header is to be read only.
11 13 Sep 07 nicklas 912      * @return True if successful.
11 13 Sep 07 nicklas 913      */
11 13 Sep 07 nicklas 914     private boolean readNonXDAFile(boolean bReadHeaderOnly)
11 13 Sep 07 nicklas 915     {
11 13 Sep 07 nicklas 916         try
11 13 Sep 07 nicklas 917         {
11 13 Sep 07 nicklas 918             // Open the file.
11 13 Sep 07 nicklas 919             FileInputStream fis = new FileInputStream(fileName);
11 13 Sep 07 nicklas 920       
11 13 Sep 07 nicklas 921             // Read the header.
11 13 Sep 07 nicklas 922             AffxIntVector tagCells = new AffxIntVector();
11 13 Sep 07 nicklas 923             if (readHeaderNonXDA(fis, tagCells) == false)
11 13 Sep 07 nicklas 924                 return false;
11 13 Sep 07 nicklas 925             
11 13 Sep 07 nicklas 926             // Return if only reading the header.
11 13 Sep 07 nicklas 927             if (bReadHeaderOnly == true)
11 13 Sep 07 nicklas 928                 return true;
11 13 Sep 07 nicklas 929
11 13 Sep 07 nicklas 930             // Only continue if genotyping or expression
11 13 Sep 07 nicklas 931             int assayType = header.getAssayType();
11 13 Sep 07 nicklas 932             if (assayType != CHPFileHeader.EXPRESSION_ASSAY &&
11 13 Sep 07 nicklas 933                 assayType != CHPFileHeader.GENOTYPING_ASSAY &&
11 13 Sep 07 nicklas 934                 assayType != CHPFileHeader.UNIVERSAL_ASSAY &&
11 13 Sep 07 nicklas 935                 assayType != CHPFileHeader.RESEQUENCING_ASSAY)
11 13 Sep 07 nicklas 936             {
11 13 Sep 07 nicklas 937                 strError = "The software only supports reading expression, genotyping, tag or resequencing CHP files.";
11 13 Sep 07 nicklas 938                 return false;
11 13 Sep 07 nicklas 939             }
11 13 Sep 07 nicklas 940
11 13 Sep 07 nicklas 941             // Read the probe set data
11 13 Sep 07 nicklas 942             if (assayType == CHPFileHeader.EXPRESSION_ASSAY)
11 13 Sep 07 nicklas 943             {
11 13 Sep 07 nicklas 944                 return readExpressionNonXDA(fis);
11 13 Sep 07 nicklas 945                 
11 13 Sep 07 nicklas 946             }
11 13 Sep 07 nicklas 947             else if (assayType == CHPFileHeader.GENOTYPING_ASSAY)
11 13 Sep 07 nicklas 948             {
11 13 Sep 07 nicklas 949                 return readGenotypingNonXDA(fis);
11 13 Sep 07 nicklas 950             }
11 13 Sep 07 nicklas 951             else if (assayType == CHPFileHeader.UNIVERSAL_ASSAY)
11 13 Sep 07 nicklas 952             {
11 13 Sep 07 nicklas 953                 return readUniversalNonXDA(fis, tagCells);
11 13 Sep 07 nicklas 954             }
11 13 Sep 07 nicklas 955             else if (assayType == CHPFileHeader.RESEQUENCING_ASSAY)
11 13 Sep 07 nicklas 956             {
11 13 Sep 07 nicklas 957                 return readReseqNonXDA(fis);
11 13 Sep 07 nicklas 958             }
11 13 Sep 07 nicklas 959             else
11 13 Sep 07 nicklas 960             {
11 13 Sep 07 nicklas 961                 return false;
11 13 Sep 07 nicklas 962             }
11 13 Sep 07 nicklas 963         }
11 13 Sep 07 nicklas 964         catch (Throwable t)
11 13 Sep 07 nicklas 965         {
11 13 Sep 07 nicklas 966             strError = t.getMessage();
11 13 Sep 07 nicklas 967             return false;
11 13 Sep 07 nicklas 968         }
11 13 Sep 07 nicklas 969     }
11 13 Sep 07 nicklas 970
11 13 Sep 07 nicklas 971     /** Accessors to header.
11 13 Sep 07 nicklas 972      * @return The header data object
11 13 Sep 07 nicklas 973      */
11 13 Sep 07 nicklas 974     public CHPFileHeader getHeader() { return header; }
11 13 Sep 07 nicklas 975
11 13 Sep 07 nicklas 976     /** Returns the expression probe set result
11 13 Sep 07 nicklas 977      * @param index The index to the result object of interest.
11 13 Sep 07 nicklas 978      * @return The expression result.
11 13 Sep 07 nicklas 979      */ 
11 13 Sep 07 nicklas 980     public ExpressionProbeSetResults getExpressionResults(int index) {
11 13 Sep 07 nicklas 981         if (index < header.getNumProbeSets() && header.getAssayType() == CHPFileHeader.EXPRESSION_ASSAY)
11 13 Sep 07 nicklas 982             return (ExpressionProbeSetResults) probeSetResults.elementAt(index);
11 13 Sep 07 nicklas 983         return null;
11 13 Sep 07 nicklas 984     }
11 13 Sep 07 nicklas 985
11 13 Sep 07 nicklas 986     /** Returns the genotyping probe set result
11 13 Sep 07 nicklas 987      * @param index The index to the result object of interest.
11 13 Sep 07 nicklas 988      * @return The genotyping result.
11 13 Sep 07 nicklas 989      */
11 13 Sep 07 nicklas 990     public GenotypeProbeSetResults getGenotypingResults(int index) {
11 13 Sep 07 nicklas 991         if (index < header.getNumProbeSets() && header.getAssayType() == CHPFileHeader.GENOTYPING_ASSAY)
11 13 Sep 07 nicklas 992             return (GenotypeProbeSetResults) probeSetResults.elementAt(index);
11 13 Sep 07 nicklas 993         return null;
11 13 Sep 07 nicklas 994     }
11 13 Sep 07 nicklas 995
11 13 Sep 07 nicklas 996     /** Returns the universal (tag array) probe set result
11 13 Sep 07 nicklas 997      * @param index The index to the result object of interest.
11 13 Sep 07 nicklas 998      * @return The universal result.
11 13 Sep 07 nicklas 999      */
11 13 Sep 07 nicklas 1000     public UniversalProbeSetResults getUniversalResults(int index) {
11 13 Sep 07 nicklas 1001         if (index < header.getNumProbeSets() && header.getAssayType() == CHPFileHeader.UNIVERSAL_ASSAY)
11 13 Sep 07 nicklas 1002             return (UniversalProbeSetResults) probeSetResults.elementAt(index);
11 13 Sep 07 nicklas 1003         return null;
11 13 Sep 07 nicklas 1004     }
11 13 Sep 07 nicklas 1005
11 13 Sep 07 nicklas 1006     /** Returns the resequencing results.
11 13 Sep 07 nicklas 1007      * @return The resequencing results.
11 13 Sep 07 nicklas 1008      */
11 13 Sep 07 nicklas 1009     public ResequencingResults getResequencingResults() {
11 13 Sep 07 nicklas 1010         if (header.getAssayType() == CHPFileHeader.RESEQUENCING_ASSAY)
11 13 Sep 07 nicklas 1011             return (ResequencingResults) reseqResults;
11 13 Sep 07 nicklas 1012         return null;
11 13 Sep 07 nicklas 1013     }
11 13 Sep 07 nicklas 1014
11 13 Sep 07 nicklas 1015     /** Error string when the read functions fail.
11 13 Sep 07 nicklas 1016      * @return A string message describing a read error
11 13 Sep 07 nicklas 1017      */
11 13 Sep 07 nicklas 1018     public String getError() { return strError; }
11 13 Sep 07 nicklas 1019
11 13 Sep 07 nicklas 1020     /** Reads the entire file.
11 13 Sep 07 nicklas 1021      * @return True if successful.
11 13 Sep 07 nicklas 1022      */
11 13 Sep 07 nicklas 1023     public boolean read() {
11 13 Sep 07 nicklas 1024         // Read the header, close if failed.
11 13 Sep 07 nicklas 1025   if (open(false) == false)
11 13 Sep 07 nicklas 1026   {
11 13 Sep 07 nicklas 1027             clear();
11 13 Sep 07 nicklas 1028             return false;
11 13 Sep 07 nicklas 1029   }
11 13 Sep 07 nicklas 1030   return true;
11 13 Sep 07 nicklas 1031     }
11 13 Sep 07 nicklas 1032
11 13 Sep 07 nicklas 1033     /** Reads the header of the CHP file
11 13 Sep 07 nicklas 1034      * @return True if successful
11 13 Sep 07 nicklas 1035      */
11 13 Sep 07 nicklas 1036     public boolean readHeader() {
11 13 Sep 07 nicklas 1037         // Read the header, close if failed.
11 13 Sep 07 nicklas 1038   if (open(true) == false)
11 13 Sep 07 nicklas 1039   {
11 13 Sep 07 nicklas 1040             clear();
11 13 Sep 07 nicklas 1041             return false;
11 13 Sep 07 nicklas 1042   }
11 13 Sep 07 nicklas 1043   return true;
11 13 Sep 07 nicklas 1044     }
11 13 Sep 07 nicklas 1045
11 13 Sep 07 nicklas 1046     /** Determines if the file specified by the FileName property exists.
11 13 Sep 07 nicklas 1047      * @return True if the file exists.
11 13 Sep 07 nicklas 1048      */
11 13 Sep 07 nicklas 1049     public boolean exists() {
11 13 Sep 07 nicklas 1050         return new File(fileName).exists();
11 13 Sep 07 nicklas 1051     }
11 13 Sep 07 nicklas 1052
11 13 Sep 07 nicklas 1053     /** Determines if the CHP file specified by the FileName property is an XDA format file
11 13 Sep 07 nicklas 1054      * @return True if the file is an XDA file
11 13 Sep 07 nicklas 1055      */
11 13 Sep 07 nicklas 1056     public boolean isXDACompatibleFile() {
11 13 Sep 07 nicklas 1057         
11 13 Sep 07 nicklas 1058   // Open the file.
11 13 Sep 07 nicklas 1059         try
11 13 Sep 07 nicklas 1060         {
11 13 Sep 07 nicklas 1061             FileInputStream fis = new FileInputStream(fileName);
11 13 Sep 07 nicklas 1062             FileChannel fc = fis.getChannel();
11 13 Sep 07 nicklas 1063             MappedByteBuffer mbb = fc.map(MapMode.READ_ONLY,0,DataSizes.INT_SIZE);
11 13 Sep 07 nicklas 1064             mbb.order(ByteOrder.LITTLE_ENDIAN);
11 13 Sep 07 nicklas 1065             int magic = mbb.getInt();
11 13 Sep 07 nicklas 1066             mbb = null;
11 13 Sep 07 nicklas 1067             fc.close();
11 13 Sep 07 nicklas 1068             fis.close();
11 13 Sep 07 nicklas 1069             return (magic == CHPFileData.CHP_FILE_MAGIC_NUMBER);
11 13 Sep 07 nicklas 1070   }
11 13 Sep 07 nicklas 1071         catch (Throwable t)
11 13 Sep 07 nicklas 1072         {
11 13 Sep 07 nicklas 1073             return false;
11 13 Sep 07 nicklas 1074         }
11 13 Sep 07 nicklas 1075     }
11 13 Sep 07 nicklas 1076
11 13 Sep 07 nicklas 1077     /** Sets the file name.
11 13 Sep 07 nicklas 1078      * @param name The full path to the CHP file
11 13 Sep 07 nicklas 1079      */
11 13 Sep 07 nicklas 1080     public void setFileName(String name) { fileName = name; }
11 13 Sep 07 nicklas 1081
11 13 Sep 07 nicklas 1082     /** Gets the file name.
11 13 Sep 07 nicklas 1083      * @return The full path to the CHP file.
11 13 Sep 07 nicklas 1084      */
11 13 Sep 07 nicklas 1085     public String getFileName() { return fileName; }
11 13 Sep 07 nicklas 1086
11 13 Sep 07 nicklas 1087     /** Deallocates any memory used by the class object */
11 13 Sep 07 nicklas 1088     public void clear() {
11 13 Sep 07 nicklas 1089         header = null;
11 13 Sep 07 nicklas 1090         strError = "";
11 13 Sep 07 nicklas 1091         probeSetResults = null;
11 13 Sep 07 nicklas 1092         reseqResults = null;
11 13 Sep 07 nicklas 1093     }
11 13 Sep 07 nicklas 1094     
11 13 Sep 07 nicklas 1095     
11 13 Sep 07 nicklas 1096     /** Parses a string into tag/value parameters.
11 13 Sep 07 nicklas 1097      * @param sSource The parameter string
11 13 Sep 07 nicklas 1098      * @sDelimiter1 The delimiter between the tag and value
11 13 Sep 07 nicklas 1099      * @sDelimiter2 The delimiter between the parameters.
11 13 Sep 07 nicklas 1100      */
11 13 Sep 07 nicklas 1101     private Vector parseString(String sSource, String sDelimiter1, String sDelimiter2) {
11 13 Sep 07 nicklas 1102         
11 13 Sep 07 nicklas 1103         if (sSource == null)
11 13 Sep 07 nicklas 1104             return null;
11 13 Sep 07 nicklas 1105         
11 13 Sep 07 nicklas 1106         // Parameters are like one of the following (no value, spaces in values, simple tag/values)
11 13 Sep 07 nicklas 1107         // BF= NF=1
11 13 Sep 07 nicklas 1108         // BF=c:\p f\file.cel NF=1
11 13 Sep 07 nicklas 1109  
11 13 Sep 07 nicklas 1110         Vector tagValueParams = new Vector();
11 13 Sep 07 nicklas 1111         String[] params = sSource.split(sDelimiter1);
11 13 Sep 07 nicklas 1112         int nParams = 0;
11 13 Sep 07 nicklas 1113         int index;
11 13 Sep 07 nicklas 1114         int index2;
11 13 Sep 07 nicklas 1115         for (int i=0; i<params.length; i++)
11 13 Sep 07 nicklas 1116         {
11 13 Sep 07 nicklas 1117             index = params[i].indexOf(sDelimiter2);
11 13 Sep 07 nicklas 1118             
11 13 Sep 07 nicklas 1119             // No value, just the tag.
11 13 Sep 07 nicklas 1120             if (index == params[i].length()-1)
11 13 Sep 07 nicklas 1121                 continue;
11 13 Sep 07 nicklas 1122             
11 13 Sep 07 nicklas 1123             // Tag and value
11 13 Sep 07 nicklas 1124             else if (index >= 0)
11 13 Sep 07 nicklas 1125             {
11 13 Sep 07 nicklas 1126                 String[] tagvalue = params[i].split(sDelimiter2);
11 13 Sep 07 nicklas 1127                 TagValuePair param = new TagValuePair();
11 13 Sep 07 nicklas 1128                 param.setTag(tagvalue[0]);
11 13 Sep 07 nicklas 1129                 param.setValue(tagvalue[1]);
11 13 Sep 07 nicklas 1130                 tagValueParams.add(param);
11 13 Sep 07 nicklas 1131                 ++nParams;
11 13 Sep 07 nicklas 1132             }
11 13 Sep 07 nicklas 1133             
11 13 Sep 07 nicklas 1134             // No tag, just value.
11 13 Sep 07 nicklas 1135             else if (index == -1)
11 13 Sep 07 nicklas 1136             {
11 13 Sep 07 nicklas 1137                 TagValuePair param = (TagValuePair) tagValueParams.elementAt(nParams-1);
11 13 Sep 07 nicklas 1138                 param.setValue(param.getValue() + " " + params[i]);
11 13 Sep 07 nicklas 1139             }
11 13 Sep 07 nicklas 1140         }
11 13 Sep 07 nicklas 1141         return tagValueParams;
11 13 Sep 07 nicklas 1142     }
11 13 Sep 07 nicklas 1143     
11 13 Sep 07 nicklas 1144 }