affyfusion-109/src/affymetrix/gcos/psi/PSIFileData.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.psi;
11 13 Sep 07 nicklas 23 import java.io.*;
11 13 Sep 07 nicklas 24 import java.util.*;
11 13 Sep 07 nicklas 25
11 13 Sep 07 nicklas 26 /** This class is used to read and access data stored in a PSI file. */
11 13 Sep 07 nicklas 27 public class PSIFileData {
11 13 Sep 07 nicklas 28     
11 13 Sep 07 nicklas 29     /** The name of the PSI file. */
11 13 Sep 07 nicklas 30     private String fileName;
11 13 Sep 07 nicklas 31     
11 13 Sep 07 nicklas 32     /** Gets the name of the PSI file.
11 13 Sep 07 nicklas 33      * @return The file name.
11 13 Sep 07 nicklas 34      */
11 13 Sep 07 nicklas 35     public String getFileName() { return fileName; }
11 13 Sep 07 nicklas 36     
11 13 Sep 07 nicklas 37     /** Sets the name of the PSI file.
11 13 Sep 07 nicklas 38      * @param name The name of the file.
11 13 Sep 07 nicklas 39      */
11 13 Sep 07 nicklas 40     public void setFileName(String name) { fileName = name; }
11 13 Sep 07 nicklas 41     
11 13 Sep 07 nicklas 42     /** The array of probe set names. */
11 13 Sep 07 nicklas 43     private Vector probeSets;
11 13 Sep 07 nicklas 44     
11 13 Sep 07 nicklas 45     /** The number of probe sets in the file.
11 13 Sep 07 nicklas 46      * @return The number of probe sets.
11 13 Sep 07 nicklas 47      */
11 13 Sep 07 nicklas 48     public int getProbeSetCount() {
11 13 Sep 07 nicklas 49         if (probeSets == null)
11 13 Sep 07 nicklas 50             return 0;
11 13 Sep 07 nicklas 51         else
11 13 Sep 07 nicklas 52             return probeSets.size();
11 13 Sep 07 nicklas 53     }
11 13 Sep 07 nicklas 54     
11 13 Sep 07 nicklas 55     /** Gets the probe set name.
11 13 Sep 07 nicklas 56      * @param index The 0 based index to the probe set array.
11 13 Sep 07 nicklas 57      * @return The probe set name.
11 13 Sep 07 nicklas 58      */
11 13 Sep 07 nicklas 59     public String getProbeSetName(int index)
11 13 Sep 07 nicklas 60     {
11 13 Sep 07 nicklas 61         ProbeSetInfo ps = (ProbeSetInfo) probeSets.elementAt(index);
11 13 Sep 07 nicklas 62         return ps.getProbeSetName();
11 13 Sep 07 nicklas 63     }
11 13 Sep 07 nicklas 64     
11 13 Sep 07 nicklas 65     /** Gets the number of probe pairs in a set.
11 13 Sep 07 nicklas 66      * @param index The 0 based index to the probe set array.
11 13 Sep 07 nicklas 67      * @return The number of pairs.
11 13 Sep 07 nicklas 68      */
11 13 Sep 07 nicklas 69     public int getProbePairs(int index)
11 13 Sep 07 nicklas 70     {
11 13 Sep 07 nicklas 71         ProbeSetInfo ps = (ProbeSetInfo) probeSets.elementAt(index);
11 13 Sep 07 nicklas 72         return ps.getNumberPairs();
11 13 Sep 07 nicklas 73     }
11 13 Sep 07 nicklas 74     
11 13 Sep 07 nicklas 75     /** Reads the contents of the PSI file.
11 13 Sep 07 nicklas 76      * @return True if successful.
11 13 Sep 07 nicklas 77      */
11 13 Sep 07 nicklas 78     public boolean read()
11 13 Sep 07 nicklas 79     {
11 13 Sep 07 nicklas 80         clear();
11 13 Sep 07 nicklas 81         try
11 13 Sep 07 nicklas 82         {
11 13 Sep 07 nicklas 83             FileReader f = new FileReader(fileName);
11 13 Sep 07 nicklas 84             BufferedReader b = new BufferedReader(f);
11 13 Sep 07 nicklas 85             
11 13 Sep 07 nicklas 86             // Check that the first line is what we expect.
11 13 Sep 07 nicklas 87             String line;
11 13 Sep 07 nicklas 88             line = b.readLine();
11 13 Sep 07 nicklas 89             String header = "#Probe Sets: ";
11 13 Sep 07 nicklas 90             if (line.startsWith(header) == false)
11 13 Sep 07 nicklas 91                 return false;
11 13 Sep 07 nicklas 92             
11 13 Sep 07 nicklas 93             // Get the number of probe sets
11 13 Sep 07 nicklas 94             int nsets = Integer.parseInt(line.substring(header.length()).trim());
11 13 Sep 07 nicklas 95             probeSets = new Vector();
11 13 Sep 07 nicklas 96             probeSets.setSize(nsets);
11 13 Sep 07 nicklas 97             
11 13 Sep 07 nicklas 98             // Get the probe set names and #pairs
11 13 Sep 07 nicklas 99             int index=0;
11 13 Sep 07 nicklas 100             while ((line = b.readLine()) != null)
11 13 Sep 07 nicklas 101             {
11 13 Sep 07 nicklas 102                 String[] s = line.split("\t", 3);
11 13 Sep 07 nicklas 103                 ProbeSetInfo info = new ProbeSetInfo();
11 13 Sep 07 nicklas 104                 info.setProbeSetName(s[1]);
11 13 Sep 07 nicklas 105                 info.setNumberPairs(Integer.parseInt(s[2].trim()));
11 13 Sep 07 nicklas 106                 probeSets.set(index, info);
11 13 Sep 07 nicklas 107                 ++index;
11 13 Sep 07 nicklas 108             }
11 13 Sep 07 nicklas 109         }
11 13 Sep 07 nicklas 110         catch (Throwable t)
11 13 Sep 07 nicklas 111         {
11 13 Sep 07 nicklas 112             clear();
11 13 Sep 07 nicklas 113             return false;
11 13 Sep 07 nicklas 114         }
11 13 Sep 07 nicklas 115         return true;
11 13 Sep 07 nicklas 116     }
11 13 Sep 07 nicklas 117     
11 13 Sep 07 nicklas 118     /** Checks for the existance of a file.
11 13 Sep 07 nicklas 119      * @return True if exists.
11 13 Sep 07 nicklas 120      */
11 13 Sep 07 nicklas 121     public boolean exists()
11 13 Sep 07 nicklas 122     {
11 13 Sep 07 nicklas 123         return new File(fileName).exists();
11 13 Sep 07 nicklas 124     }
11 13 Sep 07 nicklas 125     
11 13 Sep 07 nicklas 126     /** Clears the members. */
11 13 Sep 07 nicklas 127     public void clear()
11 13 Sep 07 nicklas 128     {
11 13 Sep 07 nicklas 129         probeSets = null;
11 13 Sep 07 nicklas 130     }
11 13 Sep 07 nicklas 131     
11 13 Sep 07 nicklas 132     /** Creates a new instance of PSIFileData */
11 13 Sep 07 nicklas 133     public PSIFileData() {
11 13 Sep 07 nicklas 134         fileName = "";
11 13 Sep 07 nicklas 135         clear();
11 13 Sep 07 nicklas 136     }
11 13 Sep 07 nicklas 137     
11 13 Sep 07 nicklas 138 }