mev-4.0.01/source/org/tigr/microarray/mev/cluster/algorithm/impl/ease/JEASEStatistics.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4  */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: JEASEStatistics.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.7 $
2 26 Feb 07 jari 8  * $Date: 2006/05/02 20:52:48 $
2 26 Feb 07 jari 9  * $Author: eleanorahowe $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 /* 
2 26 Feb 07 jari 13  * Developed by NIAID LTB Lab.
2 26 Feb 07 jari 14  */
2 26 Feb 07 jari 15 /*
2 26 Feb 07 jari 16  * Modified at TIGR for use within MeV v. 2.2 and later.
2 26 Feb 07 jari 17  */
2 26 Feb 07 jari 18 package org.tigr.microarray.mev.cluster.algorithm.impl.ease;
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20 import java.io.BufferedReader;
2 26 Feb 07 jari 21 import java.io.File;
2 26 Feb 07 jari 22 import java.io.FileReader;
2 26 Feb 07 jari 23 import java.io.FileWriter;
2 26 Feb 07 jari 24 import java.math.BigDecimal;
2 26 Feb 07 jari 25 import java.util.Date;
2 26 Feb 07 jari 26 import java.util.Enumeration;
2 26 Feb 07 jari 27 import java.util.Hashtable;
2 26 Feb 07 jari 28 import java.util.Vector;
2 26 Feb 07 jari 29
2 26 Feb 07 jari 30 public class JEASEStatistics {
2 26 Feb 07 jari 31     
2 26 Feb 07 jari 32     /** the name of the population file */
2 26 Feb 07 jari 33     public String population_file_name = "";
2 26 Feb 07 jari 34     
2 26 Feb 07 jari 35     /** the name of the input file that contains a list of gene identifiers. */
2 26 Feb 07 jari 36     public String list_file_name = "";
2 26 Feb 07 jari 37     
2 26 Feb 07 jari 38     /** the name of the file which the result will be written to. */
2 26 Feb 07 jari 39     public String output_file_name;
2 26 Feb 07 jari 40     
2 26 Feb 07 jari 41     /** a vector that contains names of the annotation files. */
2 26 Feb 07 jari 42     public Vector annotation_file_names = new Vector();
2 26 Feb 07 jari 43     
2 26 Feb 07 jari 44     /** the total number of genes that are imported from a file and belong to categories in the annotation files */
2 26 Feb 07 jari 45     public int population_total;
2 26 Feb 07 jari 46     
2 26 Feb 07 jari 47     /** the total number of genes from the sample list that belong to categories in the annotation files. */
2 26 Feb 07 jari 48     public int list_total;
2 26 Feb 07 jari 49     
2 26 Feb 07 jari 50     /** the categories from the annotation files*/
2 26 Feb 07 jari 51     public Hashtable categories = new Hashtable();
2 26 Feb 07 jari 52     
2 26 Feb 07 jari 53     /** categories and hits in each of the categories for the population  */
2 26 Feb 07 jari 54     public Hashtable categories_population = new Hashtable();
2 26 Feb 07 jari 55     
2 26 Feb 07 jari 56     /** categories and hits in each of the categories for the sample  */
2 26 Feb 07 jari 57     public Hashtable categories_list = new Hashtable();
2 26 Feb 07 jari 58     
2 26 Feb 07 jari 59     /** stores category names and associated locus id hits as java.lang.String in java.util.Vector */
2 26 Feb 07 jari 60     public Hashtable hitAccumulator = new Hashtable(); //jcb
2 26 Feb 07 jari 61     
2 26 Feb 07 jari 62     /** An instance of HypergeometricProbability class. */
2 26 Feb 07 jari 63     public HypergeometricProbability hgp_computation = new HypergeometricProbability();
2 26 Feb 07 jari 64     
2 26 Feb 07 jari 65     /** A BufferedReader object used to read an external file. */
2 26 Feb 07 jari 66     public BufferedReader read_in_stream;
2 26 Feb 07 jari 67     
2 26 Feb 07 jari 68     /** a two dimension array to store the result */
2 26 Feb 07 jari 69     public String[][] records;
2 26 Feb 07 jari 70     
2 26 Feb 07 jari 71     /** Category names */  //jcb
2 26 Feb 07 jari 72     public String [] categoryNames;
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74     /** Category list hits */
2 26 Feb 07 jari 75     public String [][] listHitMatrix;  //jcb
2 26 Feb 07 jari 76     
2 26 Feb 07 jari 77     /** the order in which the results should be listed. */
2 26 Feb 07 jari 78     public String[] orders;
2 26 Feb 07 jari 79     
2 26 Feb 07 jari 80     /** indicates statistic to report */
2 26 Feb 07 jari 81     public boolean reportEaseScore = true; //jcb
2 26 Feb 07 jari 82     
2 26 Feb 07 jari 83     /** accumulates totals for various systems  **/
2 26 Feb 07 jari 84     private Hashtable pop_totals = new Hashtable();
2 26 Feb 07 jari 85         
2 26 Feb 07 jari 86     /** accumulates totals for various systems  **/
2 26 Feb 07 jari 87     private Hashtable sample_totals = new Hashtable();
2 26 Feb 07 jari 88     
2 26 Feb 07 jari 89     /** OS file separator **/
2 26 Feb 07 jari 90     private String sep;
2 26 Feb 07 jari 91     
2 26 Feb 07 jari 92     /**  Constructor */
2 26 Feb 07 jari 93     public JEASEStatistics() {
2 26 Feb 07 jari 94         population_total = 0;
2 26 Feb 07 jari 95         list_total =0;
2 26 Feb 07 jari 96         sep = System.getProperty("file.separator");
2 26 Feb 07 jari 97     }
2 26 Feb 07 jari 98     
2 26 Feb 07 jari 99     /**  Constructor */ //jcb
2 26 Feb 07 jari 100     public JEASEStatistics(boolean reportEaseScore) {
2 26 Feb 07 jari 101         this.reportEaseScore = reportEaseScore;
2 26 Feb 07 jari 102         population_total = 0;
2 26 Feb 07 jari 103         list_total =0;
2 26 Feb 07 jari 104         sep = System.getProperty("file.separator");
2 26 Feb 07 jari 105     }
2 26 Feb 07 jari 106     
2 26 Feb 07 jari 107     /** Choose a new population file
2 26 Feb 07 jari 108      * @param file_name file name
2 26 Feb 07 jari 109      */
2 26 Feb 07 jari 110     public void UseNewPopulationFileName(String file_name) {
2 26 Feb 07 jari 111         population_file_name =  file_name;
2 26 Feb 07 jari 112     }
2 26 Feb 07 jari 113     
2 26 Feb 07 jari 114     /** Remove all of the annotation files from the list currently being used. */
2 26 Feb 07 jari 115     public void RemoveCurrentAnnotationFileNames() {
2 26 Feb 07 jari 116         annotation_file_names.removeAllElements();
2 26 Feb 07 jari 117     }
2 26 Feb 07 jari 118     
2 26 Feb 07 jari 119     /** Add a new annotation file name into the annotation file name list. */
2 26 Feb 07 jari 120     public void AddAnnotationFileName(String file_name) {
2 26 Feb 07 jari 121         annotation_file_names.addElement(file_name);
2 26 Feb 07 jari 122     }
2 26 Feb 07 jari 123     
2 26 Feb 07 jari 124     /** Use a new list file name. */
2 26 Feb 07 jari 125     public void UseNewListFileName(String file_name) {
2 26 Feb 07 jari 126         list_file_name = file_name;
2 26 Feb 07 jari 127     }
2 26 Feb 07 jari 128     
2 26 Feb 07 jari 129     /** set the name of the file that stores the results.*/
2 26 Feb 07 jari 130     public void SetOutputFileName(String file_name){
2 26 Feb 07 jari 131         output_file_name = file_name;
2 26 Feb 07 jari 132     }
2 26 Feb 07 jari 133     
2 26 Feb 07 jari 134     /**  Obtain the categories from the annotation files and create a hashtable using these categories as keys.*/
2 26 Feb 07 jari 135     public void GetCategories() {
2 26 Feb 07 jari 136         BufferedReader in = null;
2 26 Feb 07 jari 137         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 138         Hashtable implied_associations = new Hashtable();
2 26 Feb 07 jari 139         String term;
2 26 Feb 07 jari 140         String line="", category="", file_name="";
2 26 Feb 07 jari 141         int idx, c =0, idx2;        
2 26 Feb 07 jari 142         
2 26 Feb 07 jari 143         try{
2 26 Feb 07 jari 144             for(Enumeration e = annotation_file_names.elements(); e.hasMoreElements();){
2 26 Feb 07 jari 145                 file_name = e.nextElement().toString();
2 26 Feb 07 jari 146                 in = new BufferedReader(new FileReader(file_name));
2 26 Feb 07 jari 147                 
2 26 Feb 07 jari 148                 //use last index of . in case a user has a . in the path.
2 26 Feb 07 jari 149                 term = file_name.substring(file_name.lastIndexOf(sep)+1, file_name.lastIndexOf("."));
2 26 Feb 07 jari 150                 
2 26 Feb 07 jari 151                 //store terms in total hits accumulators
2 26 Feb 07 jari 152                 this.sample_totals.put(term, new Hashtable());
2 26 Feb 07 jari 153                 this.pop_totals.put(term, new Hashtable());
2 26 Feb 07 jari 154                 
2 26 Feb 07 jari 155                 while((line = in.readLine()) != null){
2 26 Feb 07 jari 156                     
2 26 Feb 07 jari 157                     idx = line.indexOf("\t");
2 26 Feb 07 jari 158                     
2 26 Feb 07 jari 159                     if( idx >= line.length() || idx < 1){
2 26 Feb 07 jari 160                         continue;
2 26 Feb 07 jari 161                     }
2 26 Feb 07 jari 162                     
2 26 Feb 07 jari 163                     //put this in to guard against no trailing tab (jcb)
2 26 Feb 07 jari 164                     idx2 = line.indexOf("\t", idx+1);
2 26 Feb 07 jari 165                     if(idx2 >= line.length() || idx2 < 1)
2 26 Feb 07 jari 166                         idx2 = line.length();
2 26 Feb 07 jari 167                     
2 26 Feb 07 jari 168                     category = term + "\t" + line.substring(idx+1, idx2).trim();
2 26 Feb 07 jari 169                     
2 26 Feb 07 jari 170                     if(!categories.containsKey(category)){
2 26 Feb 07 jari 171                         categories.put(category, new Hashtable());
2 26 Feb 07 jari 172                         ((Hashtable) categories.get(category)).put(line.substring(0,idx).trim(), "");
2 26 Feb 07 jari 173                     }else{
2 26 Feb 07 jari 174                         ((Hashtable) categories.get(category)).put(line.substring(0,idx).trim(), "");
2 26 Feb 07 jari 175                     }
2 26 Feb 07 jari 176                 }
2 26 Feb 07 jari 177             }
2 26 Feb 07 jari 178
2 26 Feb 07 jari 179             //System.out.println("categories size = "+categories.size());
2 26 Feb 07 jari 180             
2 26 Feb 07 jari 181             //(jcb)
2 26 Feb 07 jari 182             //create hash table for implies using (implies_associator)
2 26 Feb 07 jari 183             //This will then be used to add implied categories
2 26 Feb 07 jari 184             String fileName, impliesFile;
2 26 Feb 07 jari 185             int stringIndex;
2 26 Feb 07 jari 186             for(int i = 0; i < annotation_file_names.size(); i++){
2 26 Feb 07 jari 187                 fileName = (String)annotation_file_names.elementAt(i);
2 26 Feb 07 jari 188                 stringIndex = fileName.lastIndexOf(sep);
2 26 Feb 07 jari 189                 impliesFile = fileName.substring(0, stringIndex) + sep+"Implies"+sep;
2 26 Feb 07 jari 190                 impliesFile += fileName.substring(stringIndex+1, fileName.length());
2 26 Feb 07 jari 191                 
2 26 Feb 07 jari 192                 //System.out.println("implies file = "+impliesFile);
2 26 Feb 07 jari 193                 
2 26 Feb 07 jari 194                 File file = new File(impliesFile);
2 26 Feb 07 jari 195                 if(!file.exists() || !file.isFile())  //if implies file is missing move on
2 26 Feb 07 jari 196                     continue;
2 26 Feb 07 jari 197                 
2 26 Feb 07 jari 198                 in = new BufferedReader(new FileReader(impliesFile));
2 26 Feb 07 jari 199                 //term = fileName.substring(file_name.lastIndexOf("/")+1, file_name.indexOf("."));
2 26 Feb 07 jari 200                 term = fileName.substring(fileName.lastIndexOf(sep)+1, fileName.lastIndexOf("."));
2 26 Feb 07 jari 201                 
2 26 Feb 07 jari 202                 
2 26 Feb 07 jari 203                 while((line = in.readLine()) != null){
2 26 Feb 07 jari 204                     idx = line.indexOf('\t');
2 26 Feb 07 jari 205                     
2 26 Feb 07 jari 206                     if(idx >= line.length() || idx < 1)  //must include a tab
2 26 Feb 07 jari 207                         continue;
2 26 Feb 07 jari 208                     
2 26 Feb 07 jari 209                     if(!implied_associations.containsKey(term + "\t" +line.substring(0,idx).trim())){
2 26 Feb 07 jari 210                         implied_associations.put(term + "\t" +line.substring(0,idx).trim(), new Vector());
2 26 Feb 07 jari 211                         ((Vector)(implied_associations.get(term + "\t" +line.substring(0,idx).trim()))).addElement(term + "\t" + line.substring(idx, line.length()).trim());
2 26 Feb 07 jari 212                     } else {
2 26 Feb 07 jari 213                         ((Vector)(implied_associations.get(term + "\t" +line.substring(0,idx).trim()))).addElement(term + "\t" + line.substring(idx, line.length()).trim());
2 26 Feb 07 jari 214                     }
2 26 Feb 07 jari 215                 }
2 26 Feb 07 jari 216             }
2 26 Feb 07 jari 217             
2 26 Feb 07 jari 218             boolean end = false;
2 26 Feb 07 jari 219             //(jcb) append associated categories to the list
2 26 Feb 07 jari 220             for(int k = 0; k < 10 && !end; k++){  // !end will short circuit if stable
2 26 Feb 07 jari 221                 String cat="";
2 26 Feb 07 jari 222                 Hashtable catHash;
2 26 Feb 07 jari 223                 Vector impVector;
2 26 Feb 07 jari 224                 String impCat;
2 26 Feb 07 jari 225
2 26 Feb 07 jari 226                 end = true;  //start at true until no new indices are inserted
2 26 Feb 07 jari 227                 
2 26 Feb 07 jari 228                 for( Enumeration _enum = implied_associations.keys(); _enum.hasMoreElements(); ){
2 26 Feb 07 jari 229                     
2 26 Feb 07 jari 230                     cat = (String) _enum.nextElement();
2 26 Feb 07 jari 231                     
2 26 Feb 07 jari 232                     //if the category is represented, add the implied associations if they don't exist
2 26 Feb 07 jari 233                     if(categories.containsKey(cat)){
2 26 Feb 07 jari 234                         catHash = (Hashtable)categories.get(cat);
2 26 Feb 07 jari 235                         
2 26 Feb 07 jari 236                         //associated categories
2 26 Feb 07 jari 237                         impVector = ((Vector)implied_associations.get(cat));
2 26 Feb 07 jari 238                         
2 26 Feb 07 jari 239                         for(int i = 0; i < impVector.size(); i++){
2 26 Feb 07 jari 240                             
2 26 Feb 07 jari 241                             impCat = ((String)impVector.elementAt(i));
2 26 Feb 07 jari 242                             
2 26 Feb 07 jari 243                             if(!categories.containsKey(impCat)){
2 26 Feb 07 jari 244                                 end = false;
2 26 Feb 07 jari 245                                 categories.put(impCat, new Hashtable());
2 26 Feb 07 jari 246                                 for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){
2 26 Feb 07 jari 247                                     ((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), "");
2 26 Feb 07 jari 248                                 }
2 26 Feb 07 jari 249                             } else {  //category exists, need to append locus link numbers
2 26 Feb 07 jari 250                                 for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){
2 26 Feb 07 jari 251                                     String indexString = (String)categoryEnum.nextElement();
2 26 Feb 07 jari 252                                     if(!((Hashtable)categories.get(impCat)).containsKey(indexString) ){
2 26 Feb 07 jari 253                                         // ((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), "");
2 26 Feb 07 jari 254                                         ((Hashtable)categories.get(impCat)).put(indexString, "");
2 26 Feb 07 jari 255                                         
2 26 Feb 07 jari 256                                         end = false;
2 26 Feb 07 jari 257                                     }
2 26 Feb 07 jari 258                                 }
2 26 Feb 07 jari 259                             }
2 26 Feb 07 jari 260                         }
2 26 Feb 07 jari 261                     }
2 26 Feb 07 jari 262                 }
2 26 Feb 07 jari 263             }
2 26 Feb 07 jari 264             
2 26 Feb 07 jari 265         }catch(Exception error){
2 26 Feb 07 jari 266             System.out.println("Error occured collecting categories");
2 26 Feb 07 jari 267             System.out.println(error.getMessage());
2 26 Feb 07 jari 268             error.printStackTrace();
2 26 Feb 07 jari 269         }
2 26 Feb 07 jari 270     }
2 26 Feb 07 jari 271
2 26 Feb 07 jari 272     
2 26 Feb 07 jari 273     /**  Obtain the categories from the annotation files and create a hashtable using these categories as keys.*/
2 26 Feb 07 jari 274     public void GetCategories(Vector popVector) {
2 26 Feb 07 jari 275         BufferedReader in = null;
2 26 Feb 07 jari 276         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 277         Hashtable implied_associations = new Hashtable();
2 26 Feb 07 jari 278         String term;
2 26 Feb 07 jari 279         String line="", category="", file_name="";
2 26 Feb 07 jari 280         int idx, c =0, idx2;        
2 26 Feb 07 jari 281         
2 26 Feb 07 jari 282         try{
2 26 Feb 07 jari 283             for(Enumeration e = annotation_file_names.elements(); e.hasMoreElements();){
2 26 Feb 07 jari 284                 file_name = e.nextElement().toString();
2 26 Feb 07 jari 285                 in = new BufferedReader(new FileReader(file_name));
2 26 Feb 07 jari 286                 
2 26 Feb 07 jari 287                 //use last index of . in case a user has a . in the path.
2 26 Feb 07 jari 288                 term = file_name.substring(file_name.lastIndexOf(sep)+1, file_name.lastIndexOf("."));
2 26 Feb 07 jari 289                 
2 26 Feb 07 jari 290                 //store terms in total hits accumulators
2 26 Feb 07 jari 291                 this.sample_totals.put(term, new Hashtable());
2 26 Feb 07 jari 292                 this.pop_totals.put(term, new Hashtable());
2 26 Feb 07 jari 293                 
2 26 Feb 07 jari 294                 while((line = in.readLine()) != null){
2 26 Feb 07 jari 295                     
2 26 Feb 07 jari 296                     idx = line.indexOf("\t");
2 26 Feb 07 jari 297                     
2 26 Feb 07 jari 298                     if( idx >= line.length() || idx < 1){
2 26 Feb 07 jari 299                         continue;
2 26 Feb 07 jari 300                     }
2 26 Feb 07 jari 301                     
2 26 Feb 07 jari 302                     //put this in to guard against no trailing tab (jcb)
2 26 Feb 07 jari 303                     idx2 = line.indexOf("\t", idx+1);
2 26 Feb 07 jari 304                     if(idx2 >= line.length() || idx2 < 1)
2 26 Feb 07 jari 305                         idx2 = line.length();
2 26 Feb 07 jari 306                     
2 26 Feb 07 jari 307                     category = term + "\t" + line.substring(idx+1, idx2).trim();
2 26 Feb 07 jari 308                     if(popVector.contains(line.substring(0,idx).trim())) {
2 26 Feb 07 jari 309                         if(!categories.containsKey(category)){
2 26 Feb 07 jari 310                             categories.put(category, new Hashtable());
2 26 Feb 07 jari 311                             ((Hashtable) categories.get(category)).put(line.substring(0,idx).trim(), "");
2 26 Feb 07 jari 312                         }else{
2 26 Feb 07 jari 313                             ((Hashtable) categories.get(category)).put(line.substring(0,idx).trim(), "");
2 26 Feb 07 jari 314                         }
2 26 Feb 07 jari 315                     }
2 26 Feb 07 jari 316                 }
2 26 Feb 07 jari 317             }
2 26 Feb 07 jari 318                         
2 26 Feb 07 jari 319             //(jcb)
2 26 Feb 07 jari 320             //create hash table for implies using (implies_associator)
2 26 Feb 07 jari 321             //This will then be used to add implied categories
2 26 Feb 07 jari 322             String fileName, impliesFile;
2 26 Feb 07 jari 323             int stringIndex;
2 26 Feb 07 jari 324             for(int i = 0; i < annotation_file_names.size(); i++){
2 26 Feb 07 jari 325                 fileName = (String)annotation_file_names.elementAt(i);
2 26 Feb 07 jari 326                 stringIndex = fileName.lastIndexOf(sep);
2 26 Feb 07 jari 327                 impliesFile = fileName.substring(0, stringIndex) + sep+"Implies"+sep;
2 26 Feb 07 jari 328                 impliesFile += fileName.substring(stringIndex+1, fileName.length());
2 26 Feb 07 jari 329                  
2 26 Feb 07 jari 330                 File file = new File(impliesFile);
2 26 Feb 07 jari 331                 if(!file.exists() || !file.isFile())  //if implies file is missing move on
2 26 Feb 07 jari 332                     continue;
2 26 Feb 07 jari 333                 
2 26 Feb 07 jari 334                 in = new BufferedReader(new FileReader(impliesFile));
2 26 Feb 07 jari 335                 //term = fileName.substring(file_name.lastIndexOf("/")+1, file_name.indexOf("."));
2 26 Feb 07 jari 336                 term = fileName.substring(fileName.lastIndexOf(sep)+1, fileName.lastIndexOf("."));
2 26 Feb 07 jari 337                 
2 26 Feb 07 jari 338                 
2 26 Feb 07 jari 339                 while((line = in.readLine()) != null){
2 26 Feb 07 jari 340                     idx = line.indexOf('\t');
2 26 Feb 07 jari 341                     
2 26 Feb 07 jari 342                     if(idx >= line.length() || idx < 1)  //must include a tab
2 26 Feb 07 jari 343                         continue;
2 26 Feb 07 jari 344                     
2 26 Feb 07 jari 345                     if(!implied_associations.containsKey(term + "\t" +line.substring(0,idx).trim())){
2 26 Feb 07 jari 346                         implied_associations.put(term + "\t" +line.substring(0,idx).trim(), new Vector());
2 26 Feb 07 jari 347                         ((Vector)(implied_associations.get(term + "\t" +line.substring(0,idx).trim()))).addElement(term + "\t" + line.substring(idx, line.length()).trim());
2 26 Feb 07 jari 348                     } else {
2 26 Feb 07 jari 349                         ((Vector)(implied_associations.get(term + "\t" +line.substring(0,idx).trim()))).addElement(term + "\t" + line.substring(idx, line.length()).trim());
2 26 Feb 07 jari 350                     }
2 26 Feb 07 jari 351                 }
2 26 Feb 07 jari 352             }
2 26 Feb 07 jari 353             
2 26 Feb 07 jari 354             boolean end = false;
2 26 Feb 07 jari 355             //(jcb) append associated categories to the list
2 26 Feb 07 jari 356             for(int k = 0; k < 10 && !end; k++){  // !end will short circuit if stable
2 26 Feb 07 jari 357                 String cat="";
2 26 Feb 07 jari 358                 Hashtable catHash;
2 26 Feb 07 jari 359                 Vector impVector;
2 26 Feb 07 jari 360                 String impCat;
2 26 Feb 07 jari 361
2 26 Feb 07 jari 362                 end = true;  //start at true until no new indices are inserted
2 26 Feb 07 jari 363                 
2 26 Feb 07 jari 364                 for( Enumeration _enum = implied_associations.keys(); _enum.hasMoreElements(); ){
2 26 Feb 07 jari 365                     
2 26 Feb 07 jari 366                     cat = (String) _enum.nextElement();
2 26 Feb 07 jari 367                     
2 26 Feb 07 jari 368                     //if the category is represented, add the implied associations if they don't exist
2 26 Feb 07 jari 369                     if(categories.containsKey(cat)){
2 26 Feb 07 jari 370                         catHash = (Hashtable)categories.get(cat);
2 26 Feb 07 jari 371                         
2 26 Feb 07 jari 372                         //associated categories
2 26 Feb 07 jari 373                         impVector = ((Vector)implied_associations.get(cat));
2 26 Feb 07 jari 374                         
2 26 Feb 07 jari 375                         for(int i = 0; i < impVector.size(); i++){
2 26 Feb 07 jari 376                             
2 26 Feb 07 jari 377                             impCat = ((String)impVector.elementAt(i));
2 26 Feb 07 jari 378                             
2 26 Feb 07 jari 379                             if(!categories.containsKey(impCat)){
2 26 Feb 07 jari 380                                 end = false;
2 26 Feb 07 jari 381                                 categories.put(impCat, new Hashtable());
2 26 Feb 07 jari 382                                 for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){
2 26 Feb 07 jari 383                                     ((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), "");
2 26 Feb 07 jari 384                                 }
2 26 Feb 07 jari 385                             } else {  //category exists, need to append locus link numbers
2 26 Feb 07 jari 386                                 for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){
2 26 Feb 07 jari 387                                     String indexString = (String)categoryEnum.nextElement();
2 26 Feb 07 jari 388                                     if(!((Hashtable)categories.get(impCat)).containsKey(indexString) ){
2 26 Feb 07 jari 389                                         // ((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), "");
2 26 Feb 07 jari 390                                         ((Hashtable)categories.get(impCat)).put(indexString, "");
2 26 Feb 07 jari 391                                         
2 26 Feb 07 jari 392                                         end = false;
2 26 Feb 07 jari 393                                     }
2 26 Feb 07 jari 394                                 }
2 26 Feb 07 jari 395                             }
2 26 Feb 07 jari 396                         }
2 26 Feb 07 jari 397                     }
2 26 Feb 07 jari 398                 }
2 26 Feb 07 jari 399             }
2 26 Feb 07 jari 400             
2 26 Feb 07 jari 401         }catch(Exception error){
2 26 Feb 07 jari 402             System.out.println("Error occured collecting categories");
2 26 Feb 07 jari 403             System.out.println(error.getMessage());
2 26 Feb 07 jari 404             error.printStackTrace();
2 26 Feb 07 jari 405         }
2 26 Feb 07 jari 406     }
2 26 Feb 07 jari 407     
2 26 Feb 07 jari 408     /** Get the number of the genes in the population for each category that exists in the annotation files. */
2 26 Feb 07 jari 409     public void GetPopulationHitsByCategory() {
2 26 Feb 07 jari 410         BufferedReader in = null;
2 26 Feb 07 jari 411         String line="", category="", hits="", key="", locus_id;
2 26 Feb 07 jari 412         Hashtable locus_ids = new Hashtable();
2 26 Feb 07 jari 413         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 414         Hashtable count_ids = new Hashtable();
2 26 Feb 07 jari 415         
2 26 Feb 07 jari 416         int c = 0;
2 26 Feb 07 jari 417         
2 26 Feb 07 jari 418         try{
2 26 Feb 07 jari 419             in = new BufferedReader(new FileReader(population_file_name));
2 26 Feb 07 jari 420             
2 26 Feb 07 jari 421             while((line = in.readLine()) != null){
2 26 Feb 07 jari 422                 locus_ids.put(line.trim(), "");
2 26 Feb 07 jari 423             }
2 26 Feb 07 jari 424             
2 26 Feb 07 jari 425             for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){
2 26 Feb 07 jari 426                 locus_id = (String)(enum1.nextElement());
2 26 Feb 07 jari 427                 
2 26 Feb 07 jari 428                 for(Enumeration _enum = categories.keys(); _enum.hasMoreElements();){
2 26 Feb 07 jari 429                     key = (String)(_enum.nextElement());
2 26 Feb 07 jari 430                     hash_table = (Hashtable) (categories.get(key));
2 26 Feb 07 jari 431                     
2 26 Feb 07 jari 432                     if(hash_table.containsKey(locus_id)){
2 26 Feb 07 jari 433                         if(!categories_population.containsKey(key)){
2 26 Feb 07 jari 434                             categories_population.put(key, "1");
2 26 Feb 07 jari 435                         }else{
2 26 Feb 07 jari 436                             hits = String.valueOf(Integer.parseInt((String) categories_population.get(key)) + 1);
2 26 Feb 07 jari 437                             categories_population.put(key, hits);
2 26 Feb 07 jari 438                         }
2 26 Feb 07 jari 439                         
2 26 Feb 07 jari 440                         count_ids.put(locus_id, "");
2 26 Feb 07 jari 441                     }
2 26 Feb 07 jari 442                 }
2 26 Feb 07 jari 443             }
2 26 Feb 07 jari 444             
2 26 Feb 07 jari 445             population_total = count_ids.size();
2 26 Feb 07 jari 446             
2 26 Feb 07 jari 447         }catch(Exception e){
2 26 Feb 07 jari 448             System.out.println(e.getMessage());
2 26 Feb 07 jari 449         }
2 26 Feb 07 jari 450     }
2 26 Feb 07 jari 451     
2 26 Feb 07 jari 452     /** Get the number of the genes in the sample for each category that exists in the annotation files. */
2 26 Feb 07 jari 453     public void GetListHitsByCategory() {
2 26 Feb 07 jari 454         BufferedReader in = null;
2 26 Feb 07 jari 455         String line="", category="", hits="", key="", locus_id;
2 26 Feb 07 jari 456         Hashtable locus_ids = new Hashtable();
2 26 Feb 07 jari 457         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 458         Hashtable count_ids = new Hashtable();
2 26 Feb 07 jari 459         
2 26 Feb 07 jari 460         int c = 0;
2 26 Feb 07 jari 461         
2 26 Feb 07 jari 462         try{
2 26 Feb 07 jari 463             in = new BufferedReader(new FileReader(list_file_name));
2 26 Feb 07 jari 464             
2 26 Feb 07 jari 465             while((line = in.readLine()) != null){
2 26 Feb 07 jari 466                 locus_ids.put(line.trim(), "");
2 26 Feb 07 jari 467             }
2 26 Feb 07 jari 468             
2 26 Feb 07 jari 469             for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){
2 26 Feb 07 jari 470                 locus_id = (String)(enum1.nextElement());
2 26 Feb 07 jari 471                 for(Enumeration _enum = categories.keys(); _enum.hasMoreElements();){
2 26 Feb 07 jari 472                     key = (String)(_enum.nextElement());
2 26 Feb 07 jari 473                     hash_table = (Hashtable) (categories.get(key));
2 26 Feb 07 jari 474                     
2 26 Feb 07 jari 475                     if(hash_table.containsKey(locus_id)){
2 26 Feb 07 jari 476                         if(!categories_list.containsKey(key)){
2 26 Feb 07 jari 477                             categories_list.put(key, "1");
2 26 Feb 07 jari 478                         }else{
2 26 Feb 07 jari 479                             hits = String.valueOf(Integer.parseInt((String) (categories_list.get(key))) + 1);
2 26 Feb 07 jari 480                             categories_list.put(key, hits);
2 26 Feb 07 jari 481                         }
2 26 Feb 07 jari 482                         count_ids.put(locus_id, "");
2 26 Feb 07 jari 483                     }
2 26 Feb 07 jari 484                 }
2 26 Feb 07 jari 485             }
2 26 Feb 07 jari 486             
2 26 Feb 07 jari 487             list_total = count_ids.size();
2 26 Feb 07 jari 488             
2 26 Feb 07 jari 489         }catch(Exception e){
2 26 Feb 07 jari 490             System.out.println(e.getMessage());
2 26 Feb 07 jari 491         }
2 26 Feb 07 jari 492     }
2 26 Feb 07 jari 493     
2 26 Feb 07 jari 494     
2 26 Feb 07 jari 495     /** Creates the tab-delimited results containing information on system, category, population hits, population total, sample hits
2 26 Feb 07 jari 496      *  and sample totoal, and the one-tailed hypergeometric probability score of over-representation.
2 26 Feb 07 jari 497      */
2 26 Feb 07 jari 498     public void ConstructResults() {
2 26 Feb 07 jari 499         
2 26 Feb 07 jari 500         String key="", list_hit="", population_hit="", temp="";
2 26 Feb 07 jari 501         records = new String[categories_list.size()][7];
2 26 Feb 07 jari 502         orders = new String[categories_list.size()];
2 26 Feb 07 jari 503         
2 26 Feb 07 jari 504         int c=0;
2 26 Feb 07 jari 505         
2 26 Feb 07 jari 506         for(Enumeration e = categories_list.keys(); e.hasMoreElements();){
2 26 Feb 07 jari 507             key = (String)(e.nextElement());
2 26 Feb 07 jari 508             list_hit="";
2 26 Feb 07 jari 509             population_hit="";
2 26 Feb 07 jari 510             
2 26 Feb 07 jari 511             temp = key.substring(0, key.indexOf('\t')).trim();
2 26 Feb 07 jari 512             records[c][0] = temp.substring(temp.lastIndexOf(sep)+1).trim();
2 26 Feb 07 jari 513             records[c][1] = key.substring(key.indexOf('\t')).trim();
2 26 Feb 07 jari 514             
2 26 Feb 07 jari 515             list_hit = (String)(categories_list.get(key));
2 26 Feb 07 jari 516             
2 26 Feb 07 jari 517             records[c][2] = list_hit;
2 26 Feb 07 jari 518             
2 26 Feb 07 jari 519             list_total = ((Hashtable)(sample_totals.get(temp))).size();
2 26 Feb 07 jari 520             
2 26 Feb 07 jari 521             records[c][3] = String.valueOf(list_total);
2 26 Feb 07 jari 522             
2 26 Feb 07 jari 523             if(categories_population.containsKey(key)){
2 26 Feb 07 jari 524                 population_hit = (String)(categories_population.get(key));
2 26 Feb 07 jari 525                 records[c][4] = population_hit;
2 26 Feb 07 jari 526             }else{
2 26 Feb 07 jari 527                 records[c][4] = "";
2 26 Feb 07 jari 528             }
2 26 Feb 07 jari 529             
2 26 Feb 07 jari 530             population_total = ((Hashtable)(pop_totals.get(temp))).size();
2 26 Feb 07 jari 531             
2 26 Feb 07 jari 532             records[c][5] = String.valueOf(population_total);
2 26 Feb 07 jari 533             
2 26 Feb 07 jari 534             if(!list_hit.equals("") && !population_hit.equals("")){
2 26 Feb 07 jari 535                 double p;
2 26 Feb 07 jari 536                 if(reportEaseScore){  //report ease score (jcb) added option of EASEScore
2 26 Feb 07 jari 537                     if(Integer.parseInt(list_hit) > 1){
2 26 Feb 07 jari 538                         p = hgp_computation.SumHGP(population_total, Integer.parseInt(population_hit), list_total-1, Integer.parseInt(list_hit)-1);
2 26 Feb 07 jari 539                     } else{
2 26 Feb 07 jari 540                         p = 1.0;
2 26 Feb 07 jari 541                     }
2 26 Feb 07 jari 542                 } else {  //else report Fisher Exact Prob.
2 26 Feb 07 jari 543                     p = hgp_computation.SumHGP(population_total, Integer.parseInt(population_hit), list_total, Integer.parseInt(list_hit));
2 26 Feb 07 jari 544                 }
2 26 Feb 07 jari 545                 records[c][6] = String.valueOf(p);
2 26 Feb 07 jari 546             }else{
2 26 Feb 07 jari 547                 records[c][6] = "1.0";
2 26 Feb 07 jari 548             }
2 26 Feb 07 jari 549             c++;
2 26 Feb 07 jari 550         }
2 26 Feb 07 jari 551         
2 26 Feb 07 jari 552         //jcb
2 26 Feb 07 jari 553         //accumulates hits for the result matrix and the category names
2 26 Feb 07 jari 554         categoryNames = new String[hitAccumulator.size()];
2 26 Feb 07 jari 555         listHitMatrix = new String[categoryNames.length][];
2 26 Feb 07 jari 556         
2 26 Feb 07 jari 557         int cnt = 0;
2 26 Feb 07 jari 558         Vector locusVector;
2 26 Feb 07 jari 559         
2 26 Feb 07 jari 560         for(Enumeration e = hitAccumulator.keys(); e.hasMoreElements();){
2 26 Feb 07 jari 561             String cat = (String)(e.nextElement());
2 26 Feb 07 jari 562             categoryNames[cnt] = cat;
2 26 Feb 07 jari 563             locusVector = ((Vector)hitAccumulator.get(cat));
2 26 Feb 07 jari 564             listHitMatrix[cnt] = new String[locusVector.size()];
2 26 Feb 07 jari 565             for(int i = 0; i < listHitMatrix[cnt].length; i++){
2 26 Feb 07 jari 566                 listHitMatrix[cnt][i] = ((String)locusVector.elementAt(i));
2 26 Feb 07 jari 567             }
2 26 Feb 07 jari 568             cnt++;
2 26 Feb 07 jari 569         }
2 26 Feb 07 jari 570     }
2 26 Feb 07 jari 571     
2 26 Feb 07 jari 572     
2 26 Feb 07 jari 573     
2 26 Feb 07 jari 574     /** Sort the results in the ascending order of p-score and write the tab-delimited result to a file and standard IO output*/
2 26 Feb 07 jari 575     public void SortRecords() {
2 26 Feb 07 jari 576         
2 26 Feb 07 jari 577         BigDecimal big1, big2;
2 26 Feb 07 jari 578         String holder;
2 26 Feb 07 jari 579         
2 26 Feb 07 jari 580         int len = records.length;
2 26 Feb 07 jari 581         
2 26 Feb 07 jari 582         for(int i0=0; i0 < len; i0++){
2 26 Feb 07 jari 583             for(int i=0; i < len-1 - i0; i++){
2 26 Feb 07 jari 584                 big1 = new BigDecimal(records[i][6]);
2 26 Feb 07 jari 585                 big2 = new BigDecimal(records[i+1][6]);
2 26 Feb 07 jari 586                 
2 26 Feb 07 jari 587                 if(big1.compareTo(big2) > 0){
2 26 Feb 07 jari 588                     holder = records[i][0];
2 26 Feb 07 jari 589                     records[i][0] = records[i+1][0];
2 26 Feb 07 jari 590                     records[i+1][0] = holder;
2 26 Feb 07 jari 591                     
2 26 Feb 07 jari 592                     holder = records[i][1];
2 26 Feb 07 jari 593                     records[i][1] = records[i+1][1];
2 26 Feb 07 jari 594                     records[i+1][1] = holder;
2 26 Feb 07 jari 595                     
2 26 Feb 07 jari 596                     holder = records[i][2];
2 26 Feb 07 jari 597                     records[i][2] = records[i+1][2];
2 26 Feb 07 jari 598                     records[i+1][2] = holder;
2 26 Feb 07 jari 599                     
2 26 Feb 07 jari 600                     holder = records[i][3];
2 26 Feb 07 jari 601                     records[i][3] = records[i+1][3];
2 26 Feb 07 jari 602                     records[i+1][3] = holder;
2 26 Feb 07 jari 603                     
2 26 Feb 07 jari 604                     holder = records[i][4];
2 26 Feb 07 jari 605                     records[i][4] = records[i+1][4];
2 26 Feb 07 jari 606                     records[i+1][4] = holder;
2 26 Feb 07 jari 607                     
2 26 Feb 07 jari 608                     holder = records[i][5];
2 26 Feb 07 jari 609                     records[i][5] = records[i+1][5];
2 26 Feb 07 jari 610                     records[i+1][5] = holder;
2 26 Feb 07 jari 611                     
2 26 Feb 07 jari 612                     holder = records[i][6];
2 26 Feb 07 jari 613                     records[i][6] = records[i+1][6];
2 26 Feb 07 jari 614                     records[i+1][6] = holder;
2 26 Feb 07 jari 615                 }
2 26 Feb 07 jari 616             }
2 26 Feb 07 jari 617         }
2 26 Feb 07 jari 618         //jcb, elected not to output file by default here.
2 26 Feb 07 jari 619         //DisplayResults();
2 26 Feb 07 jari 620     }
2 26 Feb 07 jari 621     
2 26 Feb 07 jari 622     /** Writes the tab-delimited results to the specified output file and to the standout IO output as well */
2 26 Feb 07 jari 623     public void DisplayResults() {
2 26 Feb 07 jari 624         try{
2 26 Feb 07 jari 625             File output_file = new File(output_file_name);
2 26 Feb 07 jari 626             FileWriter output_writer = new FileWriter(output_file); //, false);
2 26 Feb 07 jari 627             
2 26 Feb 07 jari 628             for(int i=0; i < records.length; i++){
2 26 Feb 07 jari 629                 System.out.print(records[i][0] + "\t");
2 26 Feb 07 jari 630                 output_writer.write(records[i][0] + "\t");
2 26 Feb 07 jari 631                 
2 26 Feb 07 jari 632                 System.out.print(records[i][1] + "\t");
2 26 Feb 07 jari 633                 output_writer.write(records[i][1] + "\t");
2 26 Feb 07 jari 634                 
2 26 Feb 07 jari 635                 System.out.print(records[i][2] + "\t");
2 26 Feb 07 jari 636                 output_writer.write(records[i][2] + "\t");
2 26 Feb 07 jari 637                 
2 26 Feb 07 jari 638                 System.out.print(records[i][3] + "\t");
2 26 Feb 07 jari 639                 output_writer.write(records[i][3] + "\t");
2 26 Feb 07 jari 640                 
2 26 Feb 07 jari 641                 System.out.print(records[i][4] + "\t");
2 26 Feb 07 jari 642                 output_writer.write(records[i][4] + "\t");
2 26 Feb 07 jari 643                 
2 26 Feb 07 jari 644                 System.out.println(records[i][5] + "\t");
2 26 Feb 07 jari 645                 output_writer.write(records[i][5] + "\t");
2 26 Feb 07 jari 646                 
2 26 Feb 07 jari 647                 output_writer.write("\n");
2 26 Feb 07 jari 648             }
2 26 Feb 07 jari 649             output_writer.close();
2 26 Feb 07 jari 650         }catch(Exception e){
2 26 Feb 07 jari 651             System.out.println(e.getMessage());
2 26 Feb 07 jari 652         }
2 26 Feb 07 jari 653     }
2 26 Feb 07 jari 654     
2 26 Feb 07 jari 655     public static void main(String[] args) {
2 26 Feb 07 jari 656         
2 26 Feb 07 jari 657         JEASEStatistics jstatistics = new JEASEStatistics();
2 26 Feb 07 jari 658         System.out.println(new Date(System.currentTimeMillis()));
2 26 Feb 07 jari 659         
2 26 Feb 07 jari 660         jstatistics.UseNewPopulationFileName("C:/01_Work_Test_4/Files/JStatistics/All Homo sapiens.txt");
2 26 Feb 07 jari 661         jstatistics.RemoveCurrentAnnotationFileNames();
2 26 Feb 07 jari 662         jstatistics.AddAnnotationFileName("C:/01_Work_Test_4/Files/JStatistics/GO Biological Process.txt");
2 26 Feb 07 jari 663         jstatistics.UseNewListFileName("C:/01_Work_Test_4/Files/JStatistics/Bigger_HepC_chimp.txt");
2 26 Feb 07 jari 664         jstatistics.SetOutputFileName("C:/del.txt");
2 26 Feb 07 jari 665         
2 26 Feb 07 jari 666         jstatistics.GetCategories();
2 26 Feb 07 jari 667         jstatistics.GetListHitsByCategory();
2 26 Feb 07 jari 668         jstatistics.GetPopulationHitsByCategory();
2 26 Feb 07 jari 669         jstatistics.ConstructResults();
2 26 Feb 07 jari 670         jstatistics.SortRecords();
2 26 Feb 07 jari 671         
2 26 Feb 07 jari 672         System.out.println(new Date(System.currentTimeMillis()));
2 26 Feb 07 jari 673         System.out.println("\nCompleted.");
2 26 Feb 07 jari 674     }
2 26 Feb 07 jari 675     
2 26 Feb 07 jari 676     
2 26 Feb 07 jari 677     /***
2 26 Feb 07 jari 678      * (jcb)Modified Hit collection methods to accept a vector argument of annotation keys
2 26 Feb 07 jari 679      * Modification of code to enable integration into MeV Ease module.
2 26 Feb 07 jari 680      */
2 26 Feb 07 jari 681     
2 26 Feb 07 jari 682     /** Get the number of the genes in the population for each category that exists in the annotation files.
2 26 Feb 07 jari 683      * @param list population list.
2 26 Feb 07 jari 684      */
2 26 Feb 07 jari 685     public void GetPopulationHitsByCategory(Vector list) {
2 26 Feb 07 jari 686         BufferedReader in = null;
2 26 Feb 07 jari 687         String category="", hits="", key="", locus_id;
2 26 Feb 07 jari 688         Hashtable locus_ids = new Hashtable();
2 26 Feb 07 jari 689         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 690         Hashtable count_ids = new Hashtable();
2 26 Feb 07 jari 691         
2 26 Feb 07 jari 692         try{
2 26 Feb 07 jari 693             int size = list.size();
2 26 Feb 07 jari 694             for(int i = 0; i < size; i++)
2 26 Feb 07 jari 695                 locus_ids.put((String)list.elementAt(i), "");
2 26 Feb 07 jari 696             
2 26 Feb 07 jari 697             for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){
2 26 Feb 07 jari 698                 locus_id = (String)(enum1.nextElement());
2 26 Feb 07 jari 699                 
2 26 Feb 07 jari 700                 for(Enumeration _enum = categories.keys(); _enum.hasMoreElements();){
2 26 Feb 07 jari 701                     key = (String)(_enum.nextElement());
2 26 Feb 07 jari 702                     hash_table = (Hashtable) (categories.get(key));
2 26 Feb 07 jari 703                     
2 26 Feb 07 jari 704                     if(hash_table.containsKey(locus_id)){
2 26 Feb 07 jari 705                         if(!categories_population.containsKey(key)){
2 26 Feb 07 jari 706                             categories_population.put(key, "1");
2 26 Feb 07 jari 707                         }else{
2 26 Feb 07 jari 708                             hits = String.valueOf(Integer.parseInt((String) categories_population.get(key)) + 1);
2 26 Feb 07 jari 709                             categories_population.put(key, hits);
2 26 Feb 07 jari 710                         }
2 26 Feb 07 jari 711                         count_ids.put(locus_id, "");
2 26 Feb 07 jari 712                         
2 26 Feb 07 jari 713                         //accumulate the pop total hits
2 26 Feb 07 jari 714                         key = key.substring(0, key.indexOf("\t")).trim();
2 26 Feb 07 jari 715                         ((Hashtable)pop_totals.get(key)).put(locus_id,"");
2 26 Feb 07 jari 716                     }
2 26 Feb 07 jari 717                 }
2 26 Feb 07 jari 718             }
2 26 Feb 07 jari 719             population_total = count_ids.size();
2 26 Feb 07 jari 720         }catch(Exception e){
2 26 Feb 07 jari 721             System.out.println(e.getMessage());
2 26 Feb 07 jari 722         }
2 26 Feb 07 jari 723     }
2 26 Feb 07 jari 724     
2 26 Feb 07 jari 725     /** Get the number of the genes in the sample for each category that exists in the annotation files.
2 26 Feb 07 jari 726      * @param list List indices.
2 26 Feb 07 jari 727      */
2 26 Feb 07 jari 728     public void GetListHitsByCategory(Vector list) {
2 26 Feb 07 jari 729         BufferedReader in = null;
2 26 Feb 07 jari 730         String category="", hits="", key="", locus_id;
2 26 Feb 07 jari 731         Hashtable locus_ids = new Hashtable();
2 26 Feb 07 jari 732         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 733         Hashtable count_ids = new Hashtable();
2 26 Feb 07 jari 734         
2 26 Feb 07 jari 735         int c = 0;
2 26 Feb 07 jari 736         try{
2 26 Feb 07 jari 737             int size = list.size();
2 26 Feb 07 jari 738             for(int i = 0; i < size; i++)
2 26 Feb 07 jari 739                 locus_ids.put((String)list.elementAt(i), "");
2 26 Feb 07 jari 740             
2 26 Feb 07 jari 741             for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){
2 26 Feb 07 jari 742                 locus_id = (String)(enum1.nextElement());
2 26 Feb 07 jari 743                 
2 26 Feb 07 jari 744                 for(Enumeration _enum = categories.keys(); _enum.hasMoreElements();){
2 26 Feb 07 jari 745                     key = (String)(_enum.nextElement());
2 26 Feb 07 jari 746                     hash_table = (Hashtable) (categories.get(key));
2 26 Feb 07 jari 747                     
2 26 Feb 07 jari 748                     if(hash_table.containsKey(locus_id)){
2 26 Feb 07 jari 749                         if(!categories_list.containsKey(key)){
2 26 Feb 07 jari 750                             categories_list.put(key, "1");
2 26 Feb 07 jari 751                             //jcb
2 26 Feb 07 jari 752                             hitAccumulator.put(key, new Vector());
2 26 Feb 07 jari 753                             ((Vector)hitAccumulator.get(key)).add(locus_id);
2 26 Feb 07 jari 754                             //end mod
2 26 Feb 07 jari 755                         }else {
2 26 Feb 07 jari 756                             hits = String.valueOf(Integer.parseInt((String) (categories_list.get(key))) + 1);
2 26 Feb 07 jari 757                             categories_list.put(key, hits);
2 26 Feb 07 jari 758                             //jcb
2 26 Feb 07 jari 759                             ((Vector)hitAccumulator.get(key)).add(locus_id);
2 26 Feb 07 jari 760                             //end mod
2 26 Feb 07 jari 761                         }
2 26 Feb 07 jari 762                         count_ids.put(locus_id, "");
2 26 Feb 07 jari 763                         
2 26 Feb 07 jari 764                         //accumulate the sample total hits
2 26 Feb 07 jari 765                         key = key.substring(0, key.indexOf("\t")).trim();
2 26 Feb 07 jari 766                         ((Hashtable)sample_totals.get(key)).put(locus_id,"");
2 26 Feb 07 jari 767                     }
2 26 Feb 07 jari 768                 }
2 26 Feb 07 jari 769             }
2 26 Feb 07 jari 770             list_total = count_ids.size();
2 26 Feb 07 jari 771         }catch(Exception e){
2 26 Feb 07 jari 772             System.out.println(e.getMessage());
2 26 Feb 07 jari 773         }
2 26 Feb 07 jari 774     }
2 26 Feb 07 jari 775     
2 26 Feb 07 jari 776     String [][] getResults(){
2 26 Feb 07 jari 777         return this.records;
2 26 Feb 07 jari 778     }
2 26 Feb 07 jari 779     
2 26 Feb 07 jari 780     String [][] getSurveyResults(){
2 26 Feb 07 jari 781         return this.records;
2 26 Feb 07 jari 782     }
2 26 Feb 07 jari 783     
2 26 Feb 07 jari 784     String [][] getListHitMatrix(){
2 26 Feb 07 jari 785         return this.listHitMatrix;
2 26 Feb 07 jari 786     }
2 26 Feb 07 jari 787     
2 26 Feb 07 jari 788     String [] getCategoryNames(){
2 26 Feb 07 jari 789         return this.categoryNames;
2 26 Feb 07 jari 790     }
2 26 Feb 07 jari 791     
2 26 Feb 07 jari 792     /** Resets the list total and list hit accumulators.
2 26 Feb 07 jari 793      */    
2 26 Feb 07 jari 794     public void resetForNewList(){
2 26 Feb 07 jari 795         this.categories_list = new Hashtable();
2 26 Feb 07 jari 796         this.sample_totals = new Hashtable();
2 26 Feb 07 jari 797         String file_name, term;
2 26 Feb 07 jari 798    
2 26 Feb 07 jari 799         for(Enumeration e = annotation_file_names.elements(); e.hasMoreElements();){
2 26 Feb 07 jari 800             file_name = e.nextElement().toString();
2 26 Feb 07 jari 801             term = file_name.substring(file_name.lastIndexOf(sep)+1, file_name.lastIndexOf("."));
2 26 Feb 07 jari 802             
2 26 Feb 07 jari 803             //store terms in total hits accumulators
2 26 Feb 07 jari 804             this.sample_totals.put(term, new Hashtable());
2 26 Feb 07 jari 805         }
2 26 Feb 07 jari 806     }
2 26 Feb 07 jari 807     
2 26 Feb 07 jari 808     
2 26 Feb 07 jari 809     /***
2 26 Feb 07 jari 810      * Modified Hit collection methods to accept a vector argument of annotation keys
2 26 Feb 07 jari 811      * Modification of code to enable integration into TIGR MeV EASE module.
2 26 Feb 07 jari 812      */
2 26 Feb 07 jari 813     
2 26 Feb 07 jari 814     /** Get the number of the genes in the population for each category that exists in the annotation files.
2 26 Feb 07 jari 815      * @param list Input population list.
2 26 Feb 07 jari 816      */
2 26 Feb 07 jari 817     public void GetPopulationHitsByCategoryForSurvey(Vector list) {
2 26 Feb 07 jari 818         BufferedReader in = null;
2 26 Feb 07 jari 819         String category="", hits="", key="", locus_id;
2 26 Feb 07 jari 820         Hashtable locus_ids = new Hashtable();
2 26 Feb 07 jari 821         Hashtable hash_table = new Hashtable();
2 26 Feb 07 jari 822         Hashtable count_ids = new Hashtable();
2 26 Feb 07 jari 823         //jcb
2 26 Feb 07 jari 824         String impliedCategory="";
2 26 Feb 07 jari 825         Vector impliedVector;
2 26 Feb 07 jari 826         
2 26 Feb 07 jari 827         int c = 0;
2 26 Feb 07 jari 828         
2 26 Feb 07 jari 829         try{
2 26 Feb 07 jari 830             int size = list.size();
2 26 Feb 07 jari 831             for(int i = 0; i < size; i++)
2 26 Feb 07 jari 832                 locus_ids.put((String)list.elementAt(i), "");
2 26 Feb 07 jari 833             
2 26 Feb 07 jari 834             for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){
2 26 Feb 07 jari 835                 locus_id = (String)(enum1.nextElement());
2 26 Feb 07 jari 836                 
2 26 Feb 07 jari 837                 for(Enumeration _enum = categories.keys(); _enum.hasMoreElements();){
2 26 Feb 07 jari 838                     key = (String)(_enum.nextElement());
2 26 Feb 07 jari 839                     hash_table = (Hashtable) (categories.get(key));
2 26 Feb 07 jari 840                     
2 26 Feb 07 jari 841                     if(hash_table.containsKey(locus_id)){
2 26 Feb 07 jari 842                         if(!categories_population.containsKey(key)){
2 26 Feb 07 jari 843                             categories_population.put(key, "1");
2 26 Feb 07 jari 844                             
2 26 Feb 07 jari 845                             hitAccumulator.put(key, new Vector());
2 26 Feb 07 jari 846                             ((Vector)hitAccumulator.get(key)).add(locus_id);
2 26 Feb 07 jari 847                         }else{
2 26 Feb 07 jari 848                             hits = String.valueOf(Integer.parseInt((String) categories_population.get(key)) + 1);
2 26 Feb 07 jari 849                             categories_population.put(key, hits);
2 26 Feb 07 jari 850                             
2 26 Feb 07 jari 851                             ((Vector)hitAccumulator.get(key)).add(locus_id);
2 26 Feb 07 jari 852                         }
2 26 Feb 07 jari 853                         count_ids.put(locus_id, "");
2 26 Feb 07 jari 854                         
2 26 Feb 07 jari 855                         //accumulate the pop total hits
2 26 Feb 07 jari 856                         key = key.substring(0, key.indexOf("\t")).trim();
2 26 Feb 07 jari 857                         ((Hashtable)pop_totals.get(key)).put(locus_id,"");
2 26 Feb 07 jari 858                     }
2 26 Feb 07 jari 859                 }
2 26 Feb 07 jari 860             }
2 26 Feb 07 jari 861             
2 26 Feb 07 jari 862             population_total = count_ids.size();
2 26 Feb 07 jari 863             
2 26 Feb 07 jari 864         }catch(Exception e){
2 26 Feb 07 jari 865             System.out.println(e.getMessage());
2 26 Feb 07 jari 866         }
2 26 Feb 07 jari 867     }
2 26 Feb 07 jari 868     
2 26 Feb 07 jari 869     
2 26 Feb 07 jari 870     /** Creates the tab-delimited results containing information on system, category, population hits, population total, sample hits
2 26 Feb 07 jari 871      *  and sample totoal, and the one-tailed hypergeometric probability score of over-representation.
2 26 Feb 07 jari 872      */
2 26 Feb 07 jari 873     public void ConstructSurveyResults() {
2 26 Feb 07 jari 874         
2 26 Feb 07 jari 875         String key="", list_hit="", population_hit="", temp="";        
2 26 Feb 07 jari 876         
2 26 Feb 07 jari 877         records = new String[categories_population.size()][4];
2 26 Feb 07 jari 878         orders = new String[categories_population.size()];
2 26 Feb 07 jari 879         
2 26 Feb 07 jari 880         int c=0;
2 26 Feb 07 jari 881         
2 26 Feb 07 jari 882         for(Enumeration e = categories_population.keys(); e.hasMoreElements();){
2 26 Feb 07 jari 883             key = (String)(e.nextElement());
2 26 Feb 07 jari 884             list_hit="";
2 26 Feb 07 jari 885             population_hit="";
2 26 Feb 07 jari 886             
2 26 Feb 07 jari 887             temp = key.substring(0, key.indexOf('\t')).trim();
2 26 Feb 07 jari 888             records[c][0] = temp.substring(temp.lastIndexOf(sep)+1).trim();
2 26 Feb 07 jari 889             records[c][1] = key.substring(key.indexOf('\t')).trim();
2 26 Feb 07 jari 890             
2 26 Feb 07 jari 891             list_hit = (String)(categories_population.get(key));
2 26 Feb 07 jari 892             
2 26 Feb 07 jari 893             records[c][2] = list_hit;
2 26 Feb 07 jari 894             
2 26 Feb 07 jari 895             population_total = ((Hashtable)(pop_totals.get(temp))).size();
2 26 Feb 07 jari 896             
2 26 Feb 07 jari 897             records[c][3] = String.valueOf(population_total);
2 26 Feb 07 jari 898             
2 26 Feb 07 jari 899             c++;
2 26 Feb 07 jari 900         }
2 26 Feb 07 jari 901         
2 26 Feb 07 jari 902         //jcb
2 26 Feb 07 jari 903         //accumulates hits for the result matrix.
2 26 Feb 07 jari 904         categoryNames = new String[hitAccumulator.size()];
2 26 Feb 07 jari 905         listHitMatrix = new String[categoryNames.length][];
2 26 Feb 07 jari 906         
2 26 Feb 07 jari 907         int cnt = 0;
2 26 Feb 07 jari 908         Vector locusVector;
2 26 Feb 07 jari 909         
2 26 Feb 07 jari 910         for(Enumeration e = hitAccumulator.keys(); e.hasMoreElements();){
2 26 Feb 07 jari 911             String cat = (String)(e.nextElement());
2 26 Feb 07 jari 912             categoryNames[cnt] = cat;
2 26 Feb 07 jari 913             locusVector = ((Vector)hitAccumulator.get(cat));
2 26 Feb 07 jari 914             listHitMatrix[cnt] = new String[locusVector.size()];
2 26 Feb 07 jari 915             for(int i = 0; i < listHitMatrix[cnt].length; i++){
2 26 Feb 07 jari 916                 listHitMatrix[cnt][i] = ((String)locusVector.elementAt(i));
2 26 Feb 07 jari 917             }
2 26 Feb 07 jari 918             cnt++;
2 26 Feb 07 jari 919         }
2 26 Feb 07 jari 920     }
2 26 Feb 07 jari 921     
2 26 Feb 07 jari 922 }
2 26 Feb 07 jari 923