mev-4.0.01/source/org/tigr/microarray/mev/cluster/algorithm/impl/tease/TEASE.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2  * TEASE.java
2 26 Feb 07 jari 3  * 
2 26 Feb 07 jari 4  * @version July 1, 2005
2 26 Feb 07 jari 5  * @author Annie Liu
2 26 Feb 07 jari 6  */
2 26 Feb 07 jari 7 package org.tigr.microarray.mev.cluster.algorithm.impl.tease;
2 26 Feb 07 jari 8
2 26 Feb 07 jari 9 import java.io.BufferedReader;
2 26 Feb 07 jari 10 import java.io.FileOutputStream;
2 26 Feb 07 jari 11 import java.io.FileReader;
2 26 Feb 07 jari 12 import java.io.IOException;
2 26 Feb 07 jari 13 import java.io.PrintWriter;
2 26 Feb 07 jari 14 import java.util.ArrayList;
2 26 Feb 07 jari 15 import java.util.HashMap;
2 26 Feb 07 jari 16
2 26 Feb 07 jari 17 import org.tigr.microarray.mev.cluster.algorithm.AbstractAlgorithm;
2 26 Feb 07 jari 18 import org.tigr.microarray.mev.cluster.algorithm.Algorithm;
2 26 Feb 07 jari 19 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData;
2 26 Feb 07 jari 20 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent;
2 26 Feb 07 jari 21 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException;
2 26 Feb 07 jari 22 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters;
2 26 Feb 07 jari 23 import org.tigr.util.FloatMatrix;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 /**
2 26 Feb 07 jari 26  * TEASE (Tree EASE) takes in the clustered tree data and 
2 26 Feb 07 jari 27  * conduct an EASE search at each node level. Each node is 
2 26 Feb 07 jari 28  * called in turn and all leaves under each node are put into
2 26 Feb 07 jari 29  * a list that will be used to find the most enriched category
2 26 Feb 07 jari 30  * in Genome Ontology (GO). This class determines which category 
2 26 Feb 07 jari 31  * is most enriched at each node level.
2 26 Feb 07 jari 32  */
2 26 Feb 07 jari 33 public class TEASE extends AbstractAlgorithm {
2 26 Feb 07 jari 34   
2 26 Feb 07 jari 35   private EASEAnalysis ease;    //an instance of EASEAnalysis
2 26 Feb 07 jari 36   private boolean stop;         //boolean that allows the user to terminate the task
2 26 Feb 07 jari 37                     //while in process
2 26 Feb 07 jari 38     private int[] child1;         //child-1-array
2 26 Feb 07 jari 39     private int[] child2;         //child-2-array
2 26 Feb 07 jari 40     private int[] node;           //node-order
2 26 Feb 07 jari 41     private String[] annotation;   //annotations correspond to the indices of genes
2 26 Feb 07 jari 42     private ArrayList rootList;     //a list of all the nodes
2 26 Feb 07 jari 43     private HashMap leafMap;         //key: root, value: array of the leaves
2 26 Feb 07 jari 44     private HashMap selectedLeafMap; //select root that fall within min and max limit from leafmap
2 26 Feb 07 jari 45     
2 26 Feb 07 jari 46     private AlgorithmEvent event;
2 26 Feb 07 jari 47     
2 26 Feb 07 jari 48     /**
2 26 Feb 07 jari 49      * Constructor, create an instance of TEASE
2 26 Feb 07 jari 50      * create and initialize
2 26 Feb 07 jari 51      */
2 26 Feb 07 jari 52     public TEASE() {
2 26 Feb 07 jari 53     this.stop = false;
2 26 Feb 07 jari 54     this.leafMap = new HashMap();
2 26 Feb 07 jari 55     this.selectedLeafMap = new HashMap();
2 26 Feb 07 jari 56     this.ease = new EASEAnalysis();       //create an instance of EASEAnalysis
2 26 Feb 07 jari 57         this.event = new AlgorithmEvent(this, AlgorithmEvent.MONITOR_VALUE, 0);
2 26 Feb 07 jari 58     }
2 26 Feb 07 jari 59     
2 26 Feb 07 jari 60     /**
2 26 Feb 07 jari 61    * Execute method is called by TEASEGUI. It takes AlgorithmData 
2 26 Feb 07 jari 62    * as parameter, calculate the result, and store it in 
2 26 Feb 07 jari 63    * AlgorithmData. This data is returned to the TEASEGUI
2 26 Feb 07 jari 64    * 
2 26 Feb 07 jari 65    * @param data clustering data and needs to be processed
2 26 Feb 07 jari 66    * @return result a FloatMatrix of the result
2 26 Feb 07 jari 67    */
2 26 Feb 07 jari 68   public AlgorithmData execute(AlgorithmData data) throws AlgorithmException {
2 26 Feb 07 jari 69     //initialize
2 26 Feb 07 jari 70       AlgorithmParameters params = data.getParams();
2 26 Feb 07 jari 71       AlgorithmData resultData = new AlgorithmData();    //result to be returned
2 26 Feb 07 jari 72       HCL hcl = new HCL();
2 26 Feb 07 jari 73       
2 26 Feb 07 jari 74       resultData = hcl.execute(data);
2 26 Feb 07 jari 75       resultData.addParam("hcl-only", String.valueOf(params.getBoolean("hcl-only")));
2 26 Feb 07 jari 76       
2 26 Feb 07 jari 77       if (params.getBoolean("hcl-only"))
2 26 Feb 07 jari 78         return resultData;
2 26 Feb 07 jari 79       
2 26 Feb 07 jari 80       setAndDisplayEvent("Complete HCL analysis. Assigning clusters...");
2 26 Feb 07 jari 81       //System.out.println("Complete HCL analysis. Assigning clusters...");
2 26 Feb 07 jari 82
2 26 Feb 07 jari 83       this.annotation = data.getStringArray("annotation-list");
2 26 Feb 07 jari 84     this.child1 = resultData.getIntArray("child-1-array");
2 26 Feb 07 jari 85     this.child2 = resultData.getIntArray("child-2-array");
2 26 Feb 07 jari 86     this.node = resultData.getIntArray("node-order");
2 26 Feb 07 jari 87     //print();
2 26 Feb 07 jari 88     int min = params.getInt("minimum-genes");    //get min
2 26 Feb 07 jari 89     int max = params.getInt("maximum-genes");
2 26 Feb 07 jari 90     
2 26 Feb 07 jari 91     getSelectedLeafMap(min, max);       //set selectedLeafMap
2 26 Feb 07 jari 92     setAndDisplayEvent("Complete leafmap. Setting up category map...");
2 26 Feb 07 jari 93     //System.out.println("Complete leafmap. Setting up category map...");
2 26 Feb 07 jari 94     
2 26 Feb 07 jari 95     this.ease.setCategories(data);   //read in annotation file(s)
2 26 Feb 07 jari 96
2 26 Feb 07 jari 97     setAndDisplayEvent("Waiting for EASE iteration...");
2 26 Feb 07 jari 98     //System.out.println("Waiting for EASE iteration...");
2 26 Feb 07 jari 99     int[] rootArray = listToArray(this.rootList);
2 26 Feb 07 jari 100
2 26 Feb 07 jari 101 //    int root;
2 26 Feb 07 jari 102 //    int total = 0;
2 26 Feb 07 jari 103 //    ArrayList list;
2 26 Feb 07 jari 104 //    for(int i = 0; i < rootArray.length; i++) {
2 26 Feb 07 jari 105 //      root = rootArray[i];
2 26 Feb 07 jari 106 //      list = (ArrayList)this.selectedLeafMap.get(new Integer(root));
2 26 Feb 07 jari 107 //      System.out.println("root = "+root+" " +list);
2 26 Feb 07 jari 108 //      total += list.size();
2 26 Feb 07 jari 109 //    }
2 26 Feb 07 jari 110 //    System.out.println("average sample list size = "+(total/rootArray.length));
2 26 Feb 07 jari 111     
2 26 Feb 07 jari 112     String[] sample;
2 26 Feb 07 jari 113     ArrayList indices;
2 26 Feb 07 jari 114     setAndDisplayEvent("number of EASE iteration: "+rootArray.length);
2 26 Feb 07 jari 115     //System.out.println("number of EASE iteration: "+rootArray.length);
2 26 Feb 07 jari 116
2 26 Feb 07 jari 117     for (int i = 0; i < rootArray.length; i++) {       //iterator through all the node:children set in selectedLeafMap
2 26 Feb 07 jari 118       if (this.stop == true)        //break the loop when user abort
2 26 Feb 07 jari 119         return null;
2 26 Feb 07 jari 120       indices = (ArrayList)this.selectedLeafMap.get(new Integer(rootArray[i]));
2 26 Feb 07 jari 121       sample = mapIndiceToGene(indices);    //acquire genes ID array
2 26 Feb 07 jari 122       AlgorithmData singleResult = new AlgorithmData();
2 26 Feb 07 jari 123       singleResult.addParam("upper-boundary", params.getString("upper-boundary"));
2 26 Feb 07 jari 124       singleResult.addParam("lower-boundary", params.getString("lower-boundary"));
2 26 Feb 07 jari 125       singleResult.addIntArray("sample-indices", listToArray(indices));
2 26 Feb 07 jari 126       singleResult.addStringArray("sample-list", sample);       //sample-list with selected gene list
2 26 Feb 07 jari 127       singleResult = this.ease.runEASEAnalysis(singleResult);     //acquire result for each gene list
2 26 Feb 07 jari 128       resultData.addResultAlgorithmData(new Integer(rootArray[i]), singleResult);    //store result in AlgorithmData
2 26 Feb 07 jari 129       
2 26 Feb 07 jari 130       setAndDisplayEvent("Complete analyzing node: "+ rootArray[i]);
2 26 Feb 07 jari 131       //System.out.println("Complete analyzing node: "+ rootArray[i]);
2 26 Feb 07 jari 132 //      System.out.println(root);
2 26 Feb 07 jari 133 //      AlgorithmData al = resultData.getResultAlgorithmData(root);
2 26 Feb 07 jari 134 //      System.out.println(al);
2 26 Feb 07 jari 135 //      String[][] re = (String[][])al.getObjectMatrix("result-matrix");
2 26 Feb 07 jari 136 //      for (int i = 0; i < 10; i ++) {
2 26 Feb 07 jari 137 //        for (int j = 0; j < re[i].length; j++)
2 26 Feb 07 jari 138 //          System.out.print(re[i][j]+ " ");
2 26 Feb 07 jari 139 //        System.out.println();
2 26 Feb 07 jari 140 //      }
2 26 Feb 07 jari 141     }
2 26 Feb 07 jari 142     setAndDisplayEvent("Complete execution. Exiting TEASE.");
2 26 Feb 07 jari 143       //System.out.println("Complete execution. Exiting TEASE.");
2 26 Feb 07 jari 144       
2 26 Feb 07 jari 145       resultData.addIntArray("node-list", rootArray);
2 26 Feb 07 jari 146     resultData.addStringArray("name-list", data.getStringArray("name-list"));
2 26 Feb 07 jari 147     //printDataResult(resultData);
2 26 Feb 07 jari 148     return resultData; 
2 26 Feb 07 jari 149   }
2 26 Feb 07 jari 150   
2 26 Feb 07 jari 151     /**
2 26 Feb 07 jari 152     * update set event message and fire event value changed to the viewer
2 26 Feb 07 jari 153     * @param eventMessage string to be displayed in viewer
2 26 Feb 07 jari 154     */
2 26 Feb 07 jari 155    private void setAndDisplayEvent(String eventMessage) {
2 26 Feb 07 jari 156      this.event.setDescription("\n" + eventMessage);
2 26 Feb 07 jari 157      this.fireValueChanged(this.event);
2 26 Feb 07 jari 158    }
2 26 Feb 07 jari 159   
2 26 Feb 07 jari 160   private void print() {
2 26 Feb 07 jari 161     
2 26 Feb 07 jari 162     System.out.println("annotation-array");
2 26 Feb 07 jari 163     for (int i = 0; i < this.annotation.length; i++) {
2 26 Feb 07 jari 164       System.out.print(this.annotation[i] + " ");
2 26 Feb 07 jari 165     }
2 26 Feb 07 jari 166     System.out.println("\nchild1-array");
2 26 Feb 07 jari 167     for (int i = 0; i < this.child1.length; i++) {
2 26 Feb 07 jari 168       System.out.print(this.child1[i] + " ");
2 26 Feb 07 jari 169     }
2 26 Feb 07 jari 170     
2 26 Feb 07 jari 171     System.out.println("\nchild2-array" );
2 26 Feb 07 jari 172     for (int i = 0; i < this.child2.length; i++) {
2 26 Feb 07 jari 173       System.out.print(this.child2[i] + " ");
2 26 Feb 07 jari 174     }
2 26 Feb 07 jari 175     
2 26 Feb 07 jari 176     System.out.println("\nnode-array");
2 26 Feb 07 jari 177     for (int i = 0; i < this.node.length; i++) {
2 26 Feb 07 jari 178       System.out.print(this.node[i] + " ");
2 26 Feb 07 jari 179     }
2 26 Feb 07 jari 180   }
2 26 Feb 07 jari 181   
2 26 Feb 07 jari 182   private String[] mapIndiceToGene(ArrayList arr) {
2 26 Feb 07 jari 183     String[] str = new String[arr.size()];
2 26 Feb 07 jari 184     for (int i = 0; i < arr.size(); i++)
2 26 Feb 07 jari 185       str[i] = this.annotation[((Integer)arr.get(i)).intValue()];
2 26 Feb 07 jari 186     return str;
2 26 Feb 07 jari 187   }
2 26 Feb 07 jari 188   /**
2 26 Feb 07 jari 189    * Change an Integer ArrayList to an int[]
2 26 Feb 07 jari 190    * @param rootList
2 26 Feb 07 jari 191    * @return
2 26 Feb 07 jari 192    */
2 26 Feb 07 jari 193   private int[] listToArray(ArrayList rootList) {
2 26 Feb 07 jari 194     int[] roots = new int[rootList.size()];        //change ArrayList rootList into an intArray
2 26 Feb 07 jari 195     for (int i = 0; i < rootList.size(); i++) 
2 26 Feb 07 jari 196       roots[i] = ((Integer)rootList.get(i)).intValue();
2 26 Feb 07 jari 197     return roots;
2 26 Feb 07 jari 198   }
2 26 Feb 07 jari 199   
2 26 Feb 07 jari 200   /**
2 26 Feb 07 jari 201    * Termminate the calculation, set parameter stop to true.
2 26 Feb 07 jari 202    */
2 26 Feb 07 jari 203   public void abort() {
2 26 Feb 07 jari 204     this.stop = true;   //stop the task
2 26 Feb 07 jari 205     this.ease.abort();
2 26 Feb 07 jari 206   }
2 26 Feb 07 jari 207   
2 26 Feb 07 jari 208 //  /**
2 26 Feb 07 jari 209 //   * recursively get all root nodes that can be reached at the required depth
2 26 Feb 07 jari 210 //   * Store the node numbers in rootList arraylist
2 26 Feb 07 jari 211 //   * @param depth current depth during the traversal
2 26 Feb 07 jari 212 //   * @param root the root node 
2 26 Feb 07 jari 213 //   */
2 26 Feb 07 jari 214 ////  private void setRootList(int depth, int root) {  
2 26 Feb 07 jari 215 ////    if (depth == 0)             //to the bottom of the indeicated depth
2 26 Feb 07 jari 216 ////      return;
2 26 Feb 07 jari 217 ////    if (root < node.length)     //if the root node is a leaf, stop trversal at this branch
2 26 Feb 07 jari 218 ////      return;
2 26 Feb 07 jari 219 ////    else {                     //update rootList
2 26 Feb 07 jari 220 ////      rootList.add(new Integer(root));   //add root node in the rootList
2 26 Feb 07 jari 221 ////      setRootList(depth-1, child1[root]);   //search the right branch
2 26 Feb 07 jari 222 ////      setRootList(depth-1, child2[root]);   //search the left branch
2 26 Feb 07 jari 223 ////    }
2 26 Feb 07 jari 224 ////  }
2 26 Feb 07 jari 225   /**
2 26 Feb 07 jari 226    * get selectedLeafMap that contains roots of within the min and max limit
2 26 Feb 07 jari 227    * 
2 26 Feb 07 jari 228    * @param min
2 26 Feb 07 jari 229    * @param max
2 26 Feb 07 jari 230    */
2 26 Feb 07 jari 231   private void getSelectedLeafMap(int min, int max) {  
2 26 Feb 07 jari 232     HashMap leafMap = getLeafMap();          //acquire map that holds all the nodes and its childs
2 26 Feb 07 jari 233     this.rootList = new ArrayList();
2 26 Feb 07 jari 234     ArrayList leaves;
2 26 Feb 07 jari 235     
2 26 Feb 07 jari 236     for (int i = 0; i < this.node.length -1 ; i++) {
2 26 Feb 07 jari 237       Integer root = new Integer(this.node[i]);
2 26 Feb 07 jari 238       leaves = (ArrayList)leafMap.get(root);
2 26 Feb 07 jari 239       if (leaves.size() >= min && leaves.size() <= max) {  //if number of genes is within the limit
2 26 Feb 07 jari 240         this.rootList.add(root);              //store the root in rootList
2 26 Feb 07 jari 241         this.selectedLeafMap.put(root, leaves);    //store in selectedLeafMap
2 26 Feb 07 jari 242       }
2 26 Feb 07 jari 243     }
2 26 Feb 07 jari 244   }
2 26 Feb 07 jari 245   
2 26 Feb 07 jari 246   /**
2 26 Feb 07 jari 247    * find all leaves under each node and push it into a hashmap -> leafMap
2 26 Feb 07 jari 248    * key: root node, value: array of the leaves under ths root
2 26 Feb 07 jari 249    * @return leafMap 
2 26 Feb 07 jari 250    */
2 26 Feb 07 jari 251   private HashMap getLeafMap() {
2 26 Feb 07 jari 252     HashMap leafMap = new HashMap();
2 26 Feb 07 jari 253     for (int i = 0; i < this.node.length -1 ; i++) {
2 26 Feb 07 jari 254       int root = this.node[i];
2 26 Feb 07 jari 255       ArrayList leafList = new ArrayList();
2 26 Feb 07 jari 256       Integer node1 = new Integer(this.child1[root]);
2 26 Feb 07 jari 257       Integer node2 = new Integer(this.child2[root]);
2 26 Feb 07 jari 258       
2 26 Feb 07 jari 259       if (leafMap.containsKey(node1))                        //if right child has been searched through
2 26 Feb 07 jari 260         stitch(leafList, (ArrayList)leafMap.get(node1));   //extract the leaves of the right child
2 26 Feb 07 jari 261       else                                                   //and stick onto the leafList of the root 
2 26 Feb 07 jari 262         leafList = findLeaves(leafList, node1.intValue()); //find all leaves of the right child      
2 26 Feb 07 jari 263       
2 26 Feb 07 jari 264       if (leafMap.containsKey(node2))                        //if the left child has been searched through 
2 26 Feb 07 jari 265         stitch(leafList, (ArrayList)leafMap.get(node2));
2 26 Feb 07 jari 266       else
2 26 Feb 07 jari 267         leafList = findLeaves(leafList, node2.intValue());
2 26 Feb 07 jari 268       
2 26 Feb 07 jari 269 //      System.out.println("root = "+root);      
2 26 Feb 07 jari 270 //      for(int k = 0; k < leafList.size(); k++) {
2 26 Feb 07 jari 271 //        System.out.print(leafList.get(k) + " ");
2 26 Feb 07 jari 272 //      }
2 26 Feb 07 jari 273 //      System.out.println();
2 26 Feb 07 jari 274       
2 26 Feb 07 jari 275       leafMap.put(new Integer(root), leafList);     //store the key, value set into the leafMap
2 26 Feb 07 jari 276     }        
2 26 Feb 07 jari 277     return leafMap;          //key: root, value: leafList leaves under the root
2 26 Feb 07 jari 278   }
2 26 Feb 07 jari 279   
2 26 Feb 07 jari 280   /**
2 26 Feb 07 jari 281    * stitch list2 to list1
2 26 Feb 07 jari 282    * @param list1 receptor 
2 26 Feb 07 jari 283    * @param list2 list to add
2 26 Feb 07 jari 284    * @return list1
2 26 Feb 07 jari 285    */
2 26 Feb 07 jari 286   private ArrayList stitch(ArrayList list1, ArrayList list2) {
2 26 Feb 07 jari 287     for (int i = 0; i < list2.size(); i++)
2 26 Feb 07 jari 288       list1.add(list2.get(i));
2 26 Feb 07 jari 289     return list1;
2 26 Feb 07 jari 290   }
2 26 Feb 07 jari 291   
2 26 Feb 07 jari 292   /**
2 26 Feb 07 jari 293    * recursive method that finds all leaves under the root node given
2 26 Feb 07 jari 294    * @param leafList
2 26 Feb 07 jari 295    * @return leafList
2 26 Feb 07 jari 296    */
2 26 Feb 07 jari 297   private ArrayList findLeaves(ArrayList leafList, int root) {
2 26 Feb 07 jari 298     if (root < this.node.length) {
2 26 Feb 07 jari 299       leafList.add(new Integer(root));
2 26 Feb 07 jari 300       return leafList;
2 26 Feb 07 jari 301     }
2 26 Feb 07 jari 302     findLeaves(leafList, this.child1[root]);        //search right branch
2 26 Feb 07 jari 303     findLeaves(leafList, this.child2[root]);         //search left branch
2 26 Feb 07 jari 304     return leafList; 
2 26 Feb 07 jari 305   }
2 26 Feb 07 jari 306   
2 26 Feb 07 jari 307   
2 26 Feb 07 jari 308   
2 26 Feb 07 jari 309   /*******************************************************************************/
2 26 Feb 07 jari 310   /**
2 26 Feb 07 jari 311    * main method for testing, using arbitrary data set.
2 26 Feb 07 jari 312    */
2 26 Feb 07 jari 313   final static int NUMBER = 1000;
2 26 Feb 07 jari 314   
2 26 Feb 07 jari 315   public static void main(String[] args) {
2 26 Feb 07 jari 316     Algorithm algorithm = new TEASE();
2 26 Feb 07 jari 317     AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 318     AlgorithmParameters params = new AlgorithmParameters();
2 26 Feb 07 jari 319     
2 26 Feb 07 jari 320     int max = 100;
2 26 Feb 07 jari 321     int min = 10;
2 26 Feb 07 jari 322     String inputFile = "C:/Documents and Settings/hwl2/Desktop/data/expdata.txt";
2 26 Feb 07 jari 323     String outputFile = "C:/Documents and Settings/hwl2/Desktop/output.txt";
2 26 Feb 07 jari 324     String dataFile = "C:/Documents and Settings/hwl2/Desktop/data/RV14-test("+NUMBER+").txt";
2 26 Feb 07 jari 325     
2 26 Feb 07 jari 326 //    int[] a = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,    //child1
2 26 Feb 07 jari 327 //          4,7,10,0,2,1,3,16,15,-1}; 
2 26 Feb 07 jari 328 //    int[] b = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,    //child2
2 26 Feb 07 jari 329 //          5,8,6,9,13,11,12,14,17,-1};      //node
2 26 Feb 07 jari 330 //    int[] c = {10,11,12,13,14,15,16,17,18,-1};
2 26 Feb 07 jari 331     
2 26 Feb 07 jari 332     try {
2 26 Feb 07 jari 333       BufferedReader buff = new BufferedReader(new FileReader(dataFile));
2 26 Feb 07 jari 334       data = readData(buff);
2 26 Feb 07 jari 335       System.out.println("Completed reading data. Waiting for HCL data...");
2 26 Feb 07 jari 336       buff.close();
2 26 Feb 07 jari 337       //FloatMatrix matrix = FloatMatrix.read(buff);
2 26 Feb 07 jari 338       //data.addMatrix("experiment", matrix);
2 26 Feb 07 jari 339       //System.out.println("matrix is null ? "+(matrix == null));
2 26 Feb 07 jari 340 //      System.out.println("TEASE 279");
2 26 Feb 07 jari 341 //      for (int x = 0; x < matrix.getRowDimension(); x ++) {  //************************************
2 26 Feb 07 jari 342 //        for(int y = 0; y < matrix.getColumnDimension(); y ++)
2 26 Feb 07 jari 343 //          System.out.print(matrix.get(x,y)+" ");
2 26 Feb 07 jari 344 //        System.out.println();
2 26 Feb 07 jari 345 //      }
2 26 Feb 07 jari 346     }catch (IOException e) {
2 26 Feb 07 jari 347       e.printStackTrace();
2 26 Feb 07 jari 348     }
2 26 Feb 07 jari 349
2 26 Feb 07 jari 350     String[] annotations = new String[1];
2 26 Feb 07 jari 351     //String[] indi = {"780", "5982", "3310", "7849", "2978", "7318", "7067", "11099", "6352", "1571"};
2 26 Feb 07 jari 352     annotations[0] = "C:/MeV3.1/data/ease/Data/Class/GO Biological Process.txt";
2 26 Feb 07 jari 353     
2 26 Feb 07 jari 354     data.addParam("minimum-genes", String.valueOf(min));
2 26 Feb 07 jari 355     data.addParam("maximum-genes", String.valueOf(max));
2 26 Feb 07 jari 356 //    data.addIntArray("child-1-array", a);
2 26 Feb 07 jari 357 //    data.addIntArray("child-2-array", b);
2 26 Feb 07 jari 358 //    data.addIntArray("node-order", c);
2 26 Feb 07 jari 359     
2 26 Feb 07 jari 360     data.addParam("perform-cluster-analysis", "false");
2 26 Feb 07 jari 361     data.addParam("trim-option", "NO_TRIM");
2 26 Feb 07 jari 362 //    data.addStringArray("indices-list", indi);
2 26 Feb 07 jari 363 //    data.addStringArray("population-list", indi);
2 26 Feb 07 jari 364     data.addStringArray("annotation-file-list", annotations);
2 26 Feb 07 jari 365     
2 26 Feb 07 jari 366         data.addParam("hcl-distance-function", "1");   //pearson correlation
2 26 Feb 07 jari 367         data.addParam("hcl-distance-absolute", "false"); //relative distance
2 26 Feb 07 jari 368         data.addParam("method-linkage", "0");  //average-link
2 26 Feb 07 jari 369         
2 26 Feb 07 jari 370     //execute and print result in indicated output file
2 26 Feb 07 jari 371         try {    
2 26 Feb 07 jari 372           AlgorithmData result = algorithm.execute(data);  //execute
2 26 Feb 07 jari 373       int[] roots = result.getIntArray("node-list");
2 26 Feb 07 jari 374       
2 26 Feb 07 jari 375           PrintWriter out = new PrintWriter(new FileOutputStream(outputFile));  //create output writer
2 26 Feb 07 jari 376           out.println("size of data set: " + NUMBER);
2 26 Feb 07 jari 377           out.println("number of iteration: " + roots.length);
2 26 Feb 07 jari 378           out.println("\n\n");
2 26 Feb 07 jari 379
2 26 Feb 07 jari 380       for (int i = 0; i < roots.length; i ++) {
2 26 Feb 07 jari 381         out.println("node = " +roots[i]);
2 26 Feb 07 jari 382         AlgorithmData indiData = result.getResultAlgorithmData(new Integer(roots[i]));
2 26 Feb 07 jari 383         String[] names = result.getStringArray("name-list");
2 26 Feb 07 jari 384         printResult(indiData, names, out);
2 26 Feb 07 jari 385       }
2 26 Feb 07 jari 386       out.close();
2 26 Feb 07 jari 387     }catch(Exception e){
2 26 Feb 07 jari 388       e.printStackTrace();
2 26 Feb 07 jari 389     }
2 26 Feb 07 jari 390   }
2 26 Feb 07 jari 391   private static void printDataResult(AlgorithmData data) {
2 26 Feb 07 jari 392     int[] nodes = data.getIntArray("node-list");
2 26 Feb 07 jari 393     String[] names = data.getStringArray("name-list");
2 26 Feb 07 jari 394     String outputFile = "C:/Documents and Settings/hwl2/Desktop/output.txt";
2 26 Feb 07 jari 395     AlgorithmData single;
2 26 Feb 07 jari 396     try {
2 26 Feb 07 jari 397       PrintWriter out = new PrintWriter(new FileOutputStream(outputFile));  //create output writer
2 26 Feb 07 jari 398           out.println("size of data set: ");
2 26 Feb 07 jari 399           out.println("number of iteration: " + nodes.length);
2 26 Feb 07 jari 400           out.println("\n\n");
2 26 Feb 07 jari 401       for (int i = 0; i < nodes.length; i++) {
2 26 Feb 07 jari 402         out.println("node = " +nodes[i]);
2 26 Feb 07 jari 403         single = data.getResultAlgorithmData(new Integer(nodes[i]));
2 26 Feb 07 jari 404         printResult(single, names, out);
2 26 Feb 07 jari 405       }
2 26 Feb 07 jari 406       out.close();
2 26 Feb 07 jari 407     }catch (IOException e) {
2 26 Feb 07 jari 408       e.printStackTrace();
2 26 Feb 07 jari 409     }
2 26 Feb 07 jari 410   }
2 26 Feb 07 jari 411   
2 26 Feb 07 jari 412   private static void printResult(AlgorithmData result, String[] names, PrintWriter out) throws IOException{
2 26 Feb 07 jari 413     String[][] re = (String[][])result.getObjectMatrix("result-matrix");
2 26 Feb 07 jari 414
2 26 Feb 07 jari 415     String[] sample = result.getStringArray("sample-list");  //print sample genes
2 26 Feb 07 jari 416     int[] indices = result.getIntArray("sample-indices");
2 26 Feb 07 jari 417 //    System.out.println(sample == null);
2 26 Feb 07 jari 418 //    System.out.println(indices == null);
2 26 Feb 07 jari 419 //    System.out.println(names == null);
2 26 Feb 07 jari 420     for (int j = 0; j < sample.length; j++) {
2 26 Feb 07 jari 421       out.print(sample[j]+ ": "/*+ names[indices[j]]+"\t"*/);
2 26 Feb 07 jari 422     }
2 26 Feb 07 jari 423     out.println();
2 26 Feb 07 jari 424     
2 26 Feb 07 jari 425     String[] header = result.getStringArray("header-names");  //print header
2 26 Feb 07 jari 426     for (int j = 0; j < header.length; j++) {
2 26 Feb 07 jari 427       out.print(header[j]+ "\t");
2 26 Feb 07 jari 428     }
2 26 Feb 07 jari 429     out.println();
2 26 Feb 07 jari 430     
2 26 Feb 07 jari 431     for (int x = 0;  x< 5; x ++) {   //print categories
2 26 Feb 07 jari 432       for (int y = 0; y < re[x].length; y++)
2 26 Feb 07 jari 433         out.print(re[x][y]+ "\t");
2 26 Feb 07 jari 434       out.println();
2 26 Feb 07 jari 435     }
2 26 Feb 07 jari 436     out.println();
2 26 Feb 07 jari 437     out.println();
2 26 Feb 07 jari 438   }
2 26 Feb 07 jari 439   
2 26 Feb 07 jari 440   private static AlgorithmData readData(BufferedReader buff) throws IOException{
2 26 Feb 07 jari 441     //System.out.println(buff == null);
2 26 Feb 07 jari 442     AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 443     FloatMatrix matrix = new FloatMatrix(NUMBER, 12);
2 26 Feb 07 jari 444     String line = buff.readLine();
2 26 Feb 07 jari 445     String[] genes = new String[NUMBER];
2 26 Feb 07 jari 446     String[] names = new String[NUMBER];
2 26 Feb 07 jari 447     int i = 0;
2 26 Feb 07 jari 448     int parse1 = 0;
2 26 Feb 07 jari 449     int parse2 = 0;
2 26 Feb 07 jari 450     
2 26 Feb 07 jari 451     while(i < NUMBER) {
2 26 Feb 07 jari 452       line = buff.readLine();
2 26 Feb 07 jari 453       //System.out.println(line);
2 26 Feb 07 jari 454       parse2 = line.indexOf("\t");
2 26 Feb 07 jari 455           genes[i] = line.substring(0, parse2);
2 26 Feb 07 jari 456           parse1 = parse2+1;
2 26 Feb 07 jari 457           parse2 = line.indexOf("\t", parse1+1);
2 26 Feb 07 jari 458           names[i] = line.substring(parse1, parse2);
2 26 Feb 07 jari 459       for (int j = 0; j < 11; j++) {
2 26 Feb 07 jari 460                 parse1 = parse2+1;
2 26 Feb 07 jari 461                 parse2 = line.indexOf( "\t", parse1+1);
2 26 Feb 07 jari 462                 //System.out.println("parse1 = "+parse1+"  parse2 = "+parse2);
2 26 Feb 07 jari 463         String exp = line.substring(parse1, parse2); 
2 26 Feb 07 jari 464         matrix.set(i, j, (Float.valueOf(exp)).floatValue());
2 26 Feb 07 jari 465             }
2 26 Feb 07 jari 466       String exp = line.substring(parse2+1, line.length()); 
2 26 Feb 07 jari 467       matrix.set(i, 11, (Float.valueOf(exp)).floatValue());
2 26 Feb 07 jari 468       i++;
2 26 Feb 07 jari 469     }
2 26 Feb 07 jari 470     
2 26 Feb 07 jari 471 //    for (int x = 0; x < matrix.getRowDimension(); x ++) {  //************************************
2 26 Feb 07 jari 472 //      for(int y = 0; y < matrix.getColumnDimension(); y ++)
2 26 Feb 07 jari 473 //        System.out.print(matrix.get(x,y)+" ");
2 26 Feb 07 jari 474 //      System.out.println();
2 26 Feb 07 jari 475 //    }
2 26 Feb 07 jari 476 //    for (int k = 0; k < genes.length; k ++) {
2 26 Feb 07 jari 477 //      System.out.print(genes[k]+"**");
2 26 Feb 07 jari 478 //    }
2 26 Feb 07 jari 479     data.addMatrix("experiment", matrix);
2 26 Feb 07 jari 480     data.addStringArray("population-list", genes);
2 26 Feb 07 jari 481     data.addStringArray("annotation-list", genes);
2 26 Feb 07 jari 482     data.addStringArray("name-list", names);
2 26 Feb 07 jari 483     return data;
2 26 Feb 07 jari 484   }
2 26 Feb 07 jari 485 }