mev-4.0.01/source/org/tigr/microarray/mev/file/agilent/AgilentFile.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2  * Created on Jan 21, 2004
2 26 Feb 07 jari 3  */
2 26 Feb 07 jari 4 package org.tigr.microarray.mev.file.agilent;
2 26 Feb 07 jari 5
2 26 Feb 07 jari 6 import java.io.File;
2 26 Feb 07 jari 7 import java.util.StringTokenizer;
2 26 Feb 07 jari 8 import java.util.Vector;
2 26 Feb 07 jari 9
2 26 Feb 07 jari 10 /**
2 26 Feb 07 jari 11  * Object representing an Agilent Pattern File.
2 26 Feb 07 jari 12  * 
2 26 Feb 07 jari 13  * @author vu
2 26 Feb 07 jari 14  */
2 26 Feb 07 jari 15 public class AgilentFile {
2 26 Feb 07 jari 16   static final int EIGHT_COL = 8;
2 26 Feb 07 jari 17   static final int NINE_COL = 9;
2 26 Feb 07 jari 18   
2 26 Feb 07 jari 19   private int patternType;
2 26 Feb 07 jari 20   //private Vector vLine;
2 26 Feb 07 jari 21   private Vector vAgilentFeature;
2 26 Feb 07 jari 22   private File file;
2 26 Feb 07 jari 23   
2 26 Feb 07 jari 24   
2 26 Feb 07 jari 25   /**
2 26 Feb 07 jari 26    * Default Constructer
2 26 Feb 07 jari 27    * 
2 26 Feb 07 jari 28    * @param vLine  Vector of Strings where each String is a line in the file.
2 26 Feb 07 jari 29    */  
2 26 Feb 07 jari 30   public AgilentFile(Vector vLine) throws UnrecognizedPatternException {
2 26 Feb 07 jari 31     //see if this pattern contains a TopHit column
2 26 Feb 07 jari 32     String header = (String) vLine.elementAt(0);
2 26 Feb 07 jari 33     this.patternType = this.characterizePattern(header);
2 26 Feb 07 jari 34     
2 26 Feb 07 jari 35     //create the Feature objects and add them to vFeature vector
2 26 Feb 07 jari 36     setVAgilentFeature(new Vector());
2 26 Feb 07 jari 37     
2 26 Feb 07 jari 38     //for(int i = 1; i < 50; i ++) {
2 26 Feb 07 jari 39     for(int i = 1; i < vLine.size(); i ++) {
2 26 Feb 07 jari 40       String line = (String) vLine.elementAt(i);
2 26 Feb 07 jari 41       if(this.patternType == AgilentFile.EIGHT_COL) {
2 26 Feb 07 jari 42         EightFeature ef = new EightFeature(line);
2 26 Feb 07 jari 43         this.getVAgilentFeature().add(ef);
2 26 Feb 07 jari 44       } else if(this.patternType == AgilentFile.NINE_COL) {
2 26 Feb 07 jari 45         TopFeature tf = new TopFeature(line);
2 26 Feb 07 jari 46         this.getVAgilentFeature().add(tf);
2 26 Feb 07 jari 47       }
2 26 Feb 07 jari 48     }//end i
2 26 Feb 07 jari 49   }//end constructor
2 26 Feb 07 jari 50   
2 26 Feb 07 jari 51   
2 26 Feb 07 jari 52   /**
2 26 Feb 07 jari 53    * By reading the header line of the pattern, we should be able to determine what kind of
2 26 Feb 07 jari 54    * Feature subclass to use to represent the features of this pattern.
2 26 Feb 07 jari 55    * 
2 26 Feb 07 jari 56    * For the sake of saving time, I am going to dangerously assume that all patterns with a
2 26 Feb 07 jari 57    * given number of columns will be consistent with all others containing that given number
2 26 Feb 07 jari 58    * of columns.  In other words, all patterns with 8 columns will contain exactly the same 
2 26 Feb 07 jari 59    * columns in exactly the same order.  Moreover, all patterns with 9 columns will contain 
2 26 Feb 07 jari 60    * the same 9 columns in the same order.
2 26 Feb 07 jari 61    * 
2 26 Feb 07 jari 62    * @param header The first line in the pattern containing column headings
2 26 Feb 07 jari 63    */
2 26 Feb 07 jari 64   public int characterizePattern(String header) throws UnrecognizedPatternException {
2 26 Feb 07 jari 65     StringTokenizer st = new StringTokenizer(header, "\t");
2 26 Feb 07 jari 66     int kount = st.countTokens();
2 26 Feb 07 jari 67     if(kount == 8) {
2 26 Feb 07 jari 68       return AgilentFile.EIGHT_COL;
2 26 Feb 07 jari 69     } else if(kount == 9) {
2 26 Feb 07 jari 70       return AgilentFile.NINE_COL;
2 26 Feb 07 jari 71     } else {
2 26 Feb 07 jari 72       //some new kind, throw error
2 26 Feb 07 jari 73       throw new UnrecognizedPatternException(header + " unrecognized");
2 26 Feb 07 jari 74     }
2 26 Feb 07 jari 75   }
2 26 Feb 07 jari 76
2 26 Feb 07 jari 77   public void setPatternType(int patternType) {
2 26 Feb 07 jari 78     this.patternType = patternType;
2 26 Feb 07 jari 79   }
2 26 Feb 07 jari 80   public int getPatternType() {
2 26 Feb 07 jari 81     return patternType;
2 26 Feb 07 jari 82   }
2 26 Feb 07 jari 83   public String getPatternName() {
2 26 Feb 07 jari 84     return this.file.getName();
2 26 Feb 07 jari 85   }
2 26 Feb 07 jari 86
2 26 Feb 07 jari 87   public void setVAgilentFeature(Vector vFeature) {
2 26 Feb 07 jari 88     this.vAgilentFeature = vFeature;
2 26 Feb 07 jari 89   }
2 26 Feb 07 jari 90
2 26 Feb 07 jari 91   public Vector getVAgilentFeature() {
2 26 Feb 07 jari 92     return vAgilentFeature;
2 26 Feb 07 jari 93   }
2 26 Feb 07 jari 94 }//end class