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