2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* Created on Jul 12, 2005 |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
package org.tigr.microarray.mev.cluster.algorithm.impl.tease; |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
import java.io.BufferedReader; |
2 |
26 Feb 07 |
jari |
8 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
9 |
import java.io.FileReader; |
2 |
26 Feb 07 |
jari |
10 |
import java.io.FileWriter; |
2 |
26 Feb 07 |
jari |
11 |
import java.math.BigDecimal; |
2 |
26 Feb 07 |
jari |
12 |
import java.util.Enumeration; |
2 |
26 Feb 07 |
jari |
13 |
import java.util.Hashtable; |
2 |
26 Feb 07 |
jari |
14 |
import java.util.Iterator; |
2 |
26 Feb 07 |
jari |
15 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
16 |
|
2 |
26 Feb 07 |
jari |
17 |
import org.tigr.microarray.mev.cluster.algorithm.impl.ease.HypergeometricProbability; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
/** |
2 |
26 Feb 07 |
jari |
* TEASEBench contains all the methods required for GO term matching. |
2 |
26 Feb 07 |
jari |
* This class works like JEASEStatistics and is used by TEASE |
2 |
26 Feb 07 |
jari |
22 |
* |
2 |
26 Feb 07 |
jari |
* @author Annie Liu |
2 |
26 Feb 07 |
jari |
* @version Jul 12, 2005 |
2 |
26 Feb 07 |
jari |
25 |
*/ |
2 |
26 Feb 07 |
jari |
26 |
public class TEASEBench { |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
// private HashMap categoryMap; |
2 |
26 Feb 07 |
jari |
// private HashMap categoryHitsMap; |
2 |
26 Feb 07 |
jari |
// private HashMap impliedCategory; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
public String population_file_name = ""; //name of the population file |
2 |
26 Feb 07 |
jari |
33 |
public String list_file_name = ""; //the name of the input file that contains a list of gene identifiers |
2 |
26 Feb 07 |
jari |
34 |
public String output_file_name; //the name of the file which the result will be written to |
2 |
26 Feb 07 |
jari |
35 |
public Vector annotation_file_names; //a vector that contains names of the annotation files. |
2 |
26 Feb 07 |
jari |
36 |
public int population_total; //the total number of genes that are imported from a file and |
2 |
26 Feb 07 |
jari |
//belong to categories in the annotation files |
2 |
26 Feb 07 |
jari |
38 |
public int list_total; //the total number of genes from the sample list that belong |
2 |
26 Feb 07 |
jari |
//to categories in the annotation files |
2 |
26 Feb 07 |
jari |
40 |
public Hashtable categories; //the categories from the annotation files |
2 |
26 Feb 07 |
jari |
41 |
public Hashtable categories_population; //categories and hits in each of the |
2 |
26 Feb 07 |
jari |
//categories for the population |
2 |
26 Feb 07 |
jari |
43 |
public Hashtable categories_list; //categories and hits in each of the categories for the sample |
2 |
26 Feb 07 |
jari |
44 |
public Hashtable hitAccumulator; //stores category names and associated locus id hits |
2 |
26 Feb 07 |
jari |
//as java.lang.String in java.util.Vector |
2 |
26 Feb 07 |
jari |
46 |
public HypergeometricProbability hgp_computation; //An instance of HypergeometricProbability class |
2 |
26 Feb 07 |
jari |
47 |
public BufferedReader read_in_stream; //A BufferedReader object used to read an external file |
2 |
26 Feb 07 |
jari |
48 |
public String[][] records; // two dimension array to store the result |
2 |
26 Feb 07 |
jari |
49 |
public String [] categoryNames; //ategory names |
2 |
26 Feb 07 |
jari |
50 |
public String [][] listHitMatrix; //Category list hits |
2 |
26 Feb 07 |
jari |
51 |
public String[] orders; //the order in which the results should be listed |
2 |
26 Feb 07 |
jari |
52 |
public boolean reportEaseScore; //indicates statistic to report |
2 |
26 Feb 07 |
jari |
53 |
private Hashtable pop_totals; //accumulates totals for various systems |
2 |
26 Feb 07 |
jari |
54 |
private Hashtable sample_totals; //accumulates totals for various systems |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
private String sep = //"/"; //os file separator |
2 |
26 Feb 07 |
jari |
57 |
System.getProperty("file.separator"); |
2 |
26 Feb 07 |
jari |
58 |
/** |
2 |
26 Feb 07 |
jari |
* Create an instance of TEASEBench |
2 |
26 Feb 07 |
jari |
* create all global variables |
2 |
26 Feb 07 |
jari |
61 |
*/ |
2 |
26 Feb 07 |
jari |
62 |
public TEASEBench() { |
2 |
26 Feb 07 |
jari |
// this.categoryMap = new HashMap(); //create the hashmap categoryMap |
2 |
26 Feb 07 |
jari |
// this.impliedCategory = new HashMap(); |
2 |
26 Feb 07 |
jari |
// this.categoryHitsMap = new HashMap(); |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
initiation(); |
2 |
26 Feb 07 |
jari |
68 |
this.pop_totals = new Hashtable(); |
2 |
26 Feb 07 |
jari |
69 |
this.categories = new Hashtable(); |
2 |
26 Feb 07 |
jari |
70 |
this.sample_totals = new Hashtable(); |
2 |
26 Feb 07 |
jari |
71 |
this.annotation_file_names = new Vector(); |
2 |
26 Feb 07 |
jari |
72 |
this.categories_population = new Hashtable(); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
this.reportEaseScore = true; |
2 |
26 Feb 07 |
jari |
75 |
} |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
public void initiation() { |
2 |
26 Feb 07 |
jari |
78 |
this.hitAccumulator = new Hashtable(); |
2 |
26 Feb 07 |
jari |
79 |
this.hgp_computation = new HypergeometricProbability(); |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
this.population_total = 0; |
2 |
26 Feb 07 |
jari |
82 |
this.list_total =0; |
2 |
26 Feb 07 |
jari |
83 |
} |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
85 |
/** |
2 |
26 Feb 07 |
jari |
* alternative constructor that sets reportEaseScore |
2 |
26 Feb 07 |
jari |
* @param reportEaseScore |
2 |
26 Feb 07 |
jari |
88 |
*/ |
2 |
26 Feb 07 |
jari |
89 |
public TEASEBench(boolean reportEaseScore) { |
2 |
26 Feb 07 |
jari |
90 |
this(); |
2 |
26 Feb 07 |
jari |
91 |
this.reportEaseScore = reportEaseScore; |
2 |
26 Feb 07 |
jari |
92 |
} |
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
94 |
// /** |
2 |
26 Feb 07 |
jari |
// * Reads in the file containing annotation information and create |
2 |
26 Feb 07 |
jari |
// * a hashmap that maps categories to locus IDs |
2 |
26 Feb 07 |
jari |
// * key: category, value: ArrayList of locus IDs |
2 |
26 Feb 07 |
jari |
// * @param filePath |
2 |
26 Feb 07 |
jari |
99 |
// */ |
2 |
26 Feb 07 |
jari |
// private HashMap getCategories(String fileName) { |
2 |
26 Feb 07 |
jari |
// String term = fileName.substring(fileName.lastIndexOf(sep)+1, fileName.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
// String line = ""; |
2 |
26 Feb 07 |
jari |
// String id = ""; |
2 |
26 Feb 07 |
jari |
// String cat = ""; |
2 |
26 Feb 07 |
jari |
// int ind; |
2 |
26 Feb 07 |
jari |
// int in2; |
2 |
26 Feb 07 |
jari |
// try { |
2 |
26 Feb 07 |
jari |
// BufferedReader buff = new BufferedReader(new FileReader(fileName)); |
2 |
26 Feb 07 |
jari |
109 |
// |
2 |
26 Feb 07 |
jari |
// while ((line = buff.readLine()) != null) { |
2 |
26 Feb 07 |
jari |
// //System.out.println(line); |
2 |
26 Feb 07 |
jari |
// ind = line.indexOf("\t"); |
2 |
26 Feb 07 |
jari |
// if (ind == -1) |
2 |
26 Feb 07 |
jari |
// break; |
2 |
26 Feb 07 |
jari |
// id = line.substring(0, ind); |
2 |
26 Feb 07 |
jari |
// cat = line.substring(ind+1); |
2 |
26 Feb 07 |
jari |
// in2 = cat.indexOf("\t"); |
2 |
26 Feb 07 |
jari |
// if (in2 == -1) |
2 |
26 Feb 07 |
jari |
// in2 = cat.length(); |
2 |
26 Feb 07 |
jari |
// if (this.categoryMap.containsKey(id) == true) { //if gene id already existed |
2 |
26 Feb 07 |
jari |
// ((ArrayList)this.categoryMap.get(id)).add(term + "\t" + cat.substring(0,in2).trim()); //add the new category to the arraylist |
2 |
26 Feb 07 |
jari |
122 |
// } |
2 |
26 Feb 07 |
jari |
// else { //if gene first appear |
2 |
26 Feb 07 |
jari |
// ArrayList catList = new ArrayList(); //create a new arraylist for it |
2 |
26 Feb 07 |
jari |
// catList.add(term + "\t" + cat.substring(0,in2).trim()); //add category in the arraylist |
2 |
26 Feb 07 |
jari |
// this.categoryMap.put(id, catList); //put the <id, categories> set in the categoryMap |
2 |
26 Feb 07 |
jari |
127 |
// } |
2 |
26 Feb 07 |
jari |
128 |
// } |
2 |
26 Feb 07 |
jari |
// }catch (IOException e) { |
2 |
26 Feb 07 |
jari |
// e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
131 |
// } |
2 |
26 Feb 07 |
jari |
// return this.categoryMap; |
2 |
26 Feb 07 |
jari |
133 |
// } |
2 |
26 Feb 07 |
jari |
134 |
// |
2 |
26 Feb 07 |
jari |
135 |
// /** |
2 |
26 Feb 07 |
jari |
// * store implies category in a map using category (column 1) as key |
2 |
26 Feb 07 |
jari |
// * implied categories (column 0) as value |
2 |
26 Feb 07 |
jari |
// * <key, value> = <string, arraylist> |
2 |
26 Feb 07 |
jari |
// * @param filePath file path to the implies category |
2 |
26 Feb 07 |
jari |
// * @return impliedCategory hashmap |
2 |
26 Feb 07 |
jari |
141 |
// */ |
2 |
26 Feb 07 |
jari |
// private HashMap getImpliedCategory (String fileName) { |
2 |
26 Feb 07 |
jari |
// String term = fileName.substring(fileName.lastIndexOf(sep)+1, fileName.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
// int stringIndex = fileName.lastIndexOf(sep); |
2 |
26 Feb 07 |
jari |
// String impliesFile = fileName.substring(0, stringIndex) + sep + "Implies" + sep; |
2 |
26 Feb 07 |
jari |
// impliesFile += fileName.substring(stringIndex+1, fileName.length()); |
2 |
26 Feb 07 |
jari |
// String line = ""; |
2 |
26 Feb 07 |
jari |
// String imp = ""; |
2 |
26 Feb 07 |
jari |
// String cat = ""; |
2 |
26 Feb 07 |
jari |
// int ind; |
2 |
26 Feb 07 |
jari |
// try { |
2 |
26 Feb 07 |
jari |
// BufferedReader buff = new BufferedReader(new FileReader(impliesFile)); |
2 |
26 Feb 07 |
jari |
// while ((line = buff.readLine()) != null) { |
2 |
26 Feb 07 |
jari |
// ind = line.indexOf("\t"); //in case incomplete entry |
2 |
26 Feb 07 |
jari |
// if (ind == -1) |
2 |
26 Feb 07 |
jari |
// break; |
2 |
26 Feb 07 |
jari |
// imp = term + "\t" + line.substring(0, ind); |
2 |
26 Feb 07 |
jari |
// cat = term + "\t" + line.substring(ind+1).trim(); |
2 |
26 Feb 07 |
jari |
159 |
// |
2 |
26 Feb 07 |
jari |
// if (this.impliedCategory.containsKey(cat) == true) { //if category already exists |
2 |
26 Feb 07 |
jari |
// ((ArrayList)this.impliedCategory.get(cat)).add(imp); //add the new implied category to the arraylist |
2 |
26 Feb 07 |
jari |
162 |
// } |
2 |
26 Feb 07 |
jari |
// else { //if category first appear |
2 |
26 Feb 07 |
jari |
// ArrayList impList = new ArrayList(); //create a new arraylist for it |
2 |
26 Feb 07 |
jari |
// impList.add(imp); //add implied category in the arraylist |
2 |
26 Feb 07 |
jari |
// this.impliedCategory.put(cat, impList); //put the <category, implied categories> set in the categoryMap |
2 |
26 Feb 07 |
jari |
167 |
// } |
2 |
26 Feb 07 |
jari |
168 |
// } |
2 |
26 Feb 07 |
jari |
// }catch (IOException e) { |
2 |
26 Feb 07 |
jari |
// e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
171 |
// } |
2 |
26 Feb 07 |
jari |
// return this.impliedCategory; |
2 |
26 Feb 07 |
jari |
173 |
// } |
2 |
26 Feb 07 |
jari |
174 |
// |
2 |
26 Feb 07 |
jari |
175 |
// |
2 |
26 Feb 07 |
jari |
176 |
// /** |
2 |
26 Feb 07 |
jari |
// * Search both the list of genes and find matching categories. |
2 |
26 Feb 07 |
jari |
// * Store all categories that has been hit at least once in categoryHitsMap. |
2 |
26 Feb 07 |
jari |
// * value is an arraylist of genes |
2 |
26 Feb 07 |
jari |
180 |
// * |
2 |
26 Feb 07 |
jari |
// * @param geneList |
2 |
26 Feb 07 |
jari |
// * @return categoryHitsMap |
2 |
26 Feb 07 |
jari |
183 |
// */ |
2 |
26 Feb 07 |
jari |
// private HashMap getCategoryHitsMap(ArrayList geneList) { |
2 |
26 Feb 07 |
jari |
// String id; |
2 |
26 Feb 07 |
jari |
// String category; |
2 |
26 Feb 07 |
jari |
// String impcat; |
2 |
26 Feb 07 |
jari |
// ArrayList categoryList; |
2 |
26 Feb 07 |
jari |
// ArrayList impliedList; |
2 |
26 Feb 07 |
jari |
// for (int i = 0; i < geneList.size(); i++) { //iterate through geneList |
2 |
26 Feb 07 |
jari |
// id = (String)geneList.get(i); |
2 |
26 Feb 07 |
jari |
// if (this.categoryMap.containsKey(id)) { //if gene is listed in categoryMap |
2 |
26 Feb 07 |
jari |
// categoryList = (ArrayList)this.categoryMap.get(id); //pull out all the categories it belongs to |
2 |
26 Feb 07 |
jari |
194 |
// |
2 |
26 Feb 07 |
jari |
// for (int j = 0; j < categoryList.size(); j++) { |
2 |
26 Feb 07 |
jari |
// category = (String)categoryList.get(j); |
2 |
26 Feb 07 |
jari |
// checkAndAddCategory(category, id); //check if category already exist in hitMap |
2 |
26 Feb 07 |
jari |
// if (this.impliedCategory.containsKey(category)) { |
2 |
26 Feb 07 |
jari |
// impliedList = (ArrayList)this.impliedCategory.get(category); |
2 |
26 Feb 07 |
jari |
// for(int k = 0; k < impliedList.size(); k++) { |
2 |
26 Feb 07 |
jari |
// impcat = (String)impliedList.get(k); |
2 |
26 Feb 07 |
jari |
// checkAndAddCategory(impcat, id); |
2 |
26 Feb 07 |
jari |
203 |
// } |
2 |
26 Feb 07 |
jari |
204 |
// } |
2 |
26 Feb 07 |
jari |
205 |
// } |
2 |
26 Feb 07 |
jari |
206 |
// } |
2 |
26 Feb 07 |
jari |
207 |
// } |
2 |
26 Feb 07 |
jari |
// return this.categoryHitsMap; |
2 |
26 Feb 07 |
jari |
209 |
// } |
2 |
26 Feb 07 |
jari |
210 |
// |
2 |
26 Feb 07 |
jari |
211 |
// /** |
2 |
26 Feb 07 |
jari |
// * Check if category already exist. If yes, extrack the arraylist of |
2 |
26 Feb 07 |
jari |
// * genes and add in a new id. If not, create a new arraylist and push |
2 |
26 Feb 07 |
jari |
// * <category, list> in categoryHitsMap |
2 |
26 Feb 07 |
jari |
// * @param category |
2 |
26 Feb 07 |
jari |
// * @param id |
2 |
26 Feb 07 |
jari |
217 |
// */ |
2 |
26 Feb 07 |
jari |
// private void checkAndAddCategory(String category, String id) { |
2 |
26 Feb 07 |
jari |
// ArrayList hitList; |
2 |
26 Feb 07 |
jari |
// if(this.categoryHitsMap.containsKey(category)) { |
2 |
26 Feb 07 |
jari |
// hitList = (ArrayList)this.categoryHitsMap.get(category); |
2 |
26 Feb 07 |
jari |
// hitList.add(id); |
2 |
26 Feb 07 |
jari |
223 |
// } |
2 |
26 Feb 07 |
jari |
// else { |
2 |
26 Feb 07 |
jari |
// hitList = new ArrayList(); |
2 |
26 Feb 07 |
jari |
// hitList.add(id); |
2 |
26 Feb 07 |
jari |
// this.categoryHitsMap.put(category, hitList); |
2 |
26 Feb 07 |
jari |
228 |
// } |
2 |
26 Feb 07 |
jari |
229 |
// } |
2 |
26 Feb 07 |
jari |
230 |
// |
2 |
26 Feb 07 |
jari |
231 |
// /** |
2 |
26 Feb 07 |
jari |
// * returen a reference of categoryMap |
2 |
26 Feb 07 |
jari |
// * @return categoryMap |
2 |
26 Feb 07 |
jari |
234 |
// */ |
2 |
26 Feb 07 |
jari |
// private HashMap getCategoryMap() { |
2 |
26 Feb 07 |
jari |
// return this.categoryMap; |
2 |
26 Feb 07 |
jari |
237 |
// } |
2 |
26 Feb 07 |
jari |
238 |
// |
2 |
26 Feb 07 |
jari |
// public static void main(String[] args) { |
2 |
26 Feb 07 |
jari |
// TEASEBench bench = new TEASEBench(); |
2 |
26 Feb 07 |
jari |
// ArrayList geneList = new ArrayList(); |
2 |
26 Feb 07 |
jari |
// geneList.add("6352"); |
2 |
26 Feb 07 |
jari |
// geneList.add("7849"); |
2 |
26 Feb 07 |
jari |
// String fileName = "C:/MeV3.1/data/ease/Data/Class/GO Biological Process.txt"; |
2 |
26 Feb 07 |
jari |
// HashMap map = bench.getCategories(fileName); |
2 |
26 Feb 07 |
jari |
// HashMap map1 = bench.getImpliedCategory(fileName); |
2 |
26 Feb 07 |
jari |
// HashMap hits = bench.getCategoryHitsMap(geneList); |
2 |
26 Feb 07 |
jari |
248 |
// |
2 |
26 Feb 07 |
jari |
249 |
// |
2 |
26 Feb 07 |
jari |
// Set keys = hits.keySet(); |
2 |
26 Feb 07 |
jari |
// Iterator it = keys.iterator(); |
2 |
26 Feb 07 |
jari |
252 |
// |
2 |
26 Feb 07 |
jari |
// while (it.hasNext()) { |
2 |
26 Feb 07 |
jari |
// String id = (String)it.next(); |
2 |
26 Feb 07 |
jari |
// System.out.println(id + ": " + hits.get(id)); |
2 |
26 Feb 07 |
jari |
256 |
// } |
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 |
* Add a new annotation file name into the annotation |
2 |
26 Feb 07 |
jari |
* file name list. |
2 |
26 Feb 07 |
jari |
263 |
*/ |
2 |
26 Feb 07 |
jari |
264 |
public void AddAnnotationFileName(String file_name) { |
2 |
26 Feb 07 |
jari |
265 |
annotation_file_names.addElement(file_name); |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
/** |
2 |
26 Feb 07 |
jari |
* Obtain the categories from the annotation files and create a hashtable |
2 |
26 Feb 07 |
jari |
* using these categories as keys. |
2 |
26 Feb 07 |
jari |
* <key, value>, key = unrepeated categories, value = hashtable using |
2 |
26 Feb 07 |
jari |
* locus ID (integers) as keys, value = "" |
2 |
26 Feb 07 |
jari |
* store all categories found in the annotation file(s) |
2 |
26 Feb 07 |
jari |
* called by performSlideAnnotationAnalysis() in EASEAnalysis |
2 |
26 Feb 07 |
jari |
275 |
*/ |
2 |
26 Feb 07 |
jari |
276 |
public void GetCategories() { |
2 |
26 Feb 07 |
jari |
277 |
BufferedReader in = null; |
2 |
26 Feb 07 |
jari |
278 |
Hashtable hash_table = new Hashtable(); |
2 |
26 Feb 07 |
jari |
279 |
Hashtable implied_associations = new Hashtable(); |
2 |
26 Feb 07 |
jari |
280 |
String term; |
2 |
26 Feb 07 |
jari |
281 |
String line="", category="", file_name=""; |
2 |
26 Feb 07 |
jari |
282 |
int idx; |
2 |
26 Feb 07 |
jari |
283 |
int c =0; |
2 |
26 Feb 07 |
jari |
284 |
int idx2; |
2 |
26 Feb 07 |
jari |
285 |
|
2 |
26 Feb 07 |
jari |
286 |
try{ |
2 |
26 Feb 07 |
jari |
287 |
for(Enumeration e = annotation_file_names.elements(); e.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
288 |
file_name = e.nextElement().toString(); |
2 |
26 Feb 07 |
jari |
289 |
in = new BufferedReader(new FileReader(file_name)); |
2 |
26 Feb 07 |
jari |
290 |
|
2 |
26 Feb 07 |
jari |
//use last index of . in case a user has a . in the path. |
2 |
26 Feb 07 |
jari |
292 |
term = file_name.substring(file_name.lastIndexOf(sep)+1, file_name.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
293 |
|
2 |
26 Feb 07 |
jari |
//store terms in total hits accumulators |
2 |
26 Feb 07 |
jari |
295 |
this.sample_totals.put(term, new Hashtable()); |
2 |
26 Feb 07 |
jari |
296 |
this.pop_totals.put(term, new Hashtable()); |
2 |
26 Feb 07 |
jari |
297 |
|
2 |
26 Feb 07 |
jari |
298 |
while((line = in.readLine()) != null){ |
2 |
26 Feb 07 |
jari |
299 |
idx = line.indexOf("\t"); |
2 |
26 Feb 07 |
jari |
300 |
|
2 |
26 Feb 07 |
jari |
301 |
if( idx >= line.length() || idx < 1){ |
2 |
26 Feb 07 |
jari |
302 |
continue; |
2 |
26 Feb 07 |
jari |
303 |
} |
2 |
26 Feb 07 |
jari |
304 |
|
2 |
26 Feb 07 |
jari |
//put this in to guard against no trailing tab (jcb) |
2 |
26 Feb 07 |
jari |
306 |
idx2 = line.indexOf("\t", idx+1); |
2 |
26 Feb 07 |
jari |
307 |
if(idx2 >= line.length() || idx2 < 1) |
2 |
26 Feb 07 |
jari |
308 |
idx2 = line.length(); |
2 |
26 Feb 07 |
jari |
309 |
|
2 |
26 Feb 07 |
jari |
310 |
category = term + "\t" + line.substring(idx+1, idx2).trim(); |
2 |
26 Feb 07 |
jari |
311 |
|
2 |
26 Feb 07 |
jari |
312 |
if(!categories.containsKey(category)){ |
2 |
26 Feb 07 |
jari |
313 |
categories.put(category, new Hashtable()); //key = locus ID, value = "" |
2 |
26 Feb 07 |
jari |
314 |
((Hashtable) categories.get(category)).put(line.substring(0,idx).trim(), ""); |
2 |
26 Feb 07 |
jari |
315 |
}else{ |
2 |
26 Feb 07 |
jari |
316 |
((Hashtable) categories.get(category)).put(line.substring(0,idx).trim(), ""); |
2 |
26 Feb 07 |
jari |
317 |
} |
2 |
26 Feb 07 |
jari |
318 |
} |
2 |
26 Feb 07 |
jari |
319 |
} |
2 |
26 Feb 07 |
jari |
320 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("categories size = "+categories.size()); |
2 |
26 Feb 07 |
jari |
322 |
|
2 |
26 Feb 07 |
jari |
//(jcb) |
2 |
26 Feb 07 |
jari |
//create hash table for implies using (implies_associator) |
2 |
26 Feb 07 |
jari |
//This will then be used to add implied categories |
2 |
26 Feb 07 |
jari |
326 |
String fileName, impliesFile; |
2 |
26 Feb 07 |
jari |
327 |
int stringIndex; |
2 |
26 Feb 07 |
jari |
328 |
for(int i = 0; i < annotation_file_names.size(); i++){ |
2 |
26 Feb 07 |
jari |
329 |
fileName = (String)annotation_file_names.elementAt(i); |
2 |
26 Feb 07 |
jari |
330 |
stringIndex = fileName.lastIndexOf(sep); |
2 |
26 Feb 07 |
jari |
331 |
impliesFile = fileName.substring(0, stringIndex) + sep+"Implies"+sep; |
2 |
26 Feb 07 |
jari |
332 |
impliesFile += fileName.substring(stringIndex+1, fileName.length()); |
2 |
26 Feb 07 |
jari |
333 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("implies file = "+impliesFile); |
2 |
26 Feb 07 |
jari |
335 |
|
2 |
26 Feb 07 |
jari |
336 |
File file = new File(impliesFile); |
2 |
26 Feb 07 |
jari |
337 |
if(!file.exists() || !file.isFile()) //if implies file is missing move on |
2 |
26 Feb 07 |
jari |
338 |
continue; |
2 |
26 Feb 07 |
jari |
339 |
|
2 |
26 Feb 07 |
jari |
340 |
in = new BufferedReader(new FileReader(impliesFile)); |
2 |
26 Feb 07 |
jari |
//term = fileName.substring(file_name.lastIndexOf("/")+1, file_name.indexOf(".")); |
2 |
26 Feb 07 |
jari |
342 |
term = fileName.substring(fileName.lastIndexOf(sep)+1, fileName.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
343 |
|
2 |
26 Feb 07 |
jari |
344 |
|
2 |
26 Feb 07 |
jari |
345 |
while((line = in.readLine()) != null){ |
2 |
26 Feb 07 |
jari |
346 |
idx = line.indexOf('\t'); |
2 |
26 Feb 07 |
jari |
347 |
|
2 |
26 Feb 07 |
jari |
348 |
if(idx >= line.length() || idx < 1) //must include a tab |
2 |
26 Feb 07 |
jari |
349 |
continue; |
2 |
26 Feb 07 |
jari |
350 |
|
2 |
26 Feb 07 |
jari |
351 |
if(!implied_associations.containsKey(term + "\t" +line.substring(0,idx).trim())){ |
2 |
26 Feb 07 |
jari |
352 |
implied_associations.put(term + "\t" +line.substring(0,idx).trim(), new Vector()); |
2 |
26 Feb 07 |
jari |
353 |
((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 |
354 |
} else { |
2 |
26 Feb 07 |
jari |
355 |
((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 |
356 |
} |
2 |
26 Feb 07 |
jari |
357 |
} |
2 |
26 Feb 07 |
jari |
358 |
} |
2 |
26 Feb 07 |
jari |
359 |
boolean end = false; |
2 |
26 Feb 07 |
jari |
//(jcb) append associated categories to the list |
2 |
26 Feb 07 |
jari |
361 |
for(int k = 0; k < 10 && !end; k++){ // !end will short circuit if stable |
2 |
26 Feb 07 |
jari |
362 |
String cat=""; |
2 |
26 Feb 07 |
jari |
363 |
Hashtable catHash; |
2 |
26 Feb 07 |
jari |
364 |
Vector impVector; |
2 |
26 Feb 07 |
jari |
365 |
String impCat; |
2 |
26 Feb 07 |
jari |
366 |
|
2 |
26 Feb 07 |
jari |
367 |
end = true; //start at true until no new indices are inserted |
2 |
26 Feb 07 |
jari |
368 |
|
2 |
26 Feb 07 |
jari |
369 |
for( Enumeration enum = implied_associations.keys(); enum.hasMoreElements(); ){ |
2 |
26 Feb 07 |
jari |
370 |
|
2 |
26 Feb 07 |
jari |
371 |
cat = (String) enum.nextElement(); |
2 |
26 Feb 07 |
jari |
372 |
|
2 |
26 Feb 07 |
jari |
//if the category is represented, add the implied associations if they don't exist |
2 |
26 Feb 07 |
jari |
374 |
if(categories.containsKey(cat)){ |
2 |
26 Feb 07 |
jari |
375 |
catHash = (Hashtable)categories.get(cat); |
2 |
26 Feb 07 |
jari |
376 |
|
2 |
26 Feb 07 |
jari |
//associated categories |
2 |
26 Feb 07 |
jari |
378 |
impVector = ((Vector)implied_associations.get(cat)); |
2 |
26 Feb 07 |
jari |
379 |
|
2 |
26 Feb 07 |
jari |
380 |
for(int i = 0; i < impVector.size(); i++){ |
2 |
26 Feb 07 |
jari |
381 |
|
2 |
26 Feb 07 |
jari |
382 |
impCat = ((String)impVector.elementAt(i)); |
2 |
26 Feb 07 |
jari |
383 |
|
2 |
26 Feb 07 |
jari |
384 |
if(!categories.containsKey(impCat)){ |
2 |
26 Feb 07 |
jari |
385 |
end = false; |
2 |
26 Feb 07 |
jari |
386 |
categories.put(impCat, new Hashtable()); |
2 |
26 Feb 07 |
jari |
387 |
for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
388 |
((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), ""); |
2 |
26 Feb 07 |
jari |
389 |
} |
2 |
26 Feb 07 |
jari |
390 |
} else { //category exists, need to append locus link numbers |
2 |
26 Feb 07 |
jari |
391 |
for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
392 |
String indexString = (String)categoryEnum.nextElement(); |
2 |
26 Feb 07 |
jari |
393 |
if(!((Hashtable)categories.get(impCat)).containsKey(indexString) ){ |
2 |
26 Feb 07 |
jari |
// ((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), ""); |
2 |
26 Feb 07 |
jari |
395 |
((Hashtable)categories.get(impCat)).put(indexString, ""); |
2 |
26 Feb 07 |
jari |
396 |
|
2 |
26 Feb 07 |
jari |
397 |
end = false; |
2 |
26 Feb 07 |
jari |
398 |
} |
2 |
26 Feb 07 |
jari |
399 |
} |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
} |
2 |
26 Feb 07 |
jari |
402 |
} |
2 |
26 Feb 07 |
jari |
403 |
} |
2 |
26 Feb 07 |
jari |
404 |
} |
2 |
26 Feb 07 |
jari |
// System.out.println(categories.size()); |
2 |
26 Feb 07 |
jari |
// Set arr = (Set)categories.keySet(); //*************************************************** |
2 |
26 Feb 07 |
jari |
// Iterator it = arr.iterator(); |
2 |
26 Feb 07 |
jari |
// while (it.hasNext()) { |
2 |
26 Feb 07 |
jari |
// Object ob = it.next(); |
2 |
26 Feb 07 |
jari |
// System.out.println(ob+" -----> "+categories.get(ob)); |
2 |
26 Feb 07 |
jari |
411 |
// } |
2 |
26 Feb 07 |
jari |
412 |
|
2 |
26 Feb 07 |
jari |
}catch(Exception error){ |
2 |
26 Feb 07 |
jari |
System.out.println("Error occured collecting categories"); |
2 |
26 Feb 07 |
jari |
System.out.println(error.getMessage()); |
2 |
26 Feb 07 |
jari |
error.printStackTrace(); |
2 |
26 Feb 07 |
jari |
417 |
} |
2 |
26 Feb 07 |
jari |
// System.out.println("JEASESTatistics"); //******************************************* |
2 |
26 Feb 07 |
jari |
// Set keySet = categories.keySet(); |
2 |
26 Feb 07 |
jari |
// Iterator it = keySet.iterator(); |
2 |
26 Feb 07 |
jari |
// while(it.hasNext()) { |
2 |
26 Feb 07 |
jari |
// Hashtable hash = (Hashtable)categories.get(it.next()); |
2 |
26 Feb 07 |
jari |
// Set id = hash.keySet(); |
2 |
26 Feb 07 |
jari |
// Iterator i = id.iterator(); |
2 |
26 Feb 07 |
jari |
// while(i.hasNext()) |
2 |
26 Feb 07 |
jari |
// System.out.println(i.next()); |
2 |
26 Feb 07 |
jari |
427 |
// } |
2 |
26 Feb 07 |
jari |
428 |
} |
2 |
26 Feb 07 |
jari |
429 |
|
2 |
26 Feb 07 |
jari |
430 |
|
2 |
26 Feb 07 |
jari |
431 |
/** |
2 |
26 Feb 07 |
jari |
* Obtain the categories from the annotation files and create a hashtable |
2 |
26 Feb 07 |
jari |
* using these categories as keys. |
2 |
26 Feb 07 |
jari |
* only store categories that are present in the population list |
2 |
26 Feb 07 |
jari |
* called by performClusterAnnotationAnalysis() in EASEAnalysis |
2 |
26 Feb 07 |
jari |
436 |
* |
2 |
26 Feb 07 |
jari |
* @param popVector population gene list |
2 |
26 Feb 07 |
jari |
438 |
* */ |
2 |
26 Feb 07 |
jari |
439 |
public void GetCategories(Vector popVector) { |
2 |
26 Feb 07 |
jari |
440 |
BufferedReader in = null; |
2 |
26 Feb 07 |
jari |
441 |
Hashtable hash_table = new Hashtable(); |
2 |
26 Feb 07 |
jari |
442 |
Hashtable implied_associations = new Hashtable(); |
2 |
26 Feb 07 |
jari |
443 |
String term; |
2 |
26 Feb 07 |
jari |
444 |
String line="", category="", file_name=""; |
2 |
26 Feb 07 |
jari |
445 |
int idx; |
2 |
26 Feb 07 |
jari |
446 |
int c = 0; |
2 |
26 Feb 07 |
jari |
447 |
int idx2; |
2 |
26 Feb 07 |
jari |
448 |
|
2 |
26 Feb 07 |
jari |
449 |
try{ |
2 |
26 Feb 07 |
jari |
450 |
for(Enumeration e = this.annotation_file_names.elements(); e.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
451 |
file_name = e.nextElement().toString(); |
2 |
26 Feb 07 |
jari |
452 |
in = new BufferedReader(new FileReader(file_name)); |
2 |
26 Feb 07 |
jari |
453 |
|
2 |
26 Feb 07 |
jari |
//use last index of . in case a user has a . in the path. |
2 |
26 Feb 07 |
jari |
455 |
term = file_name.substring(file_name.lastIndexOf(this.sep)+1, file_name.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
456 |
|
2 |
26 Feb 07 |
jari |
//store terms in total hits accumulators |
2 |
26 Feb 07 |
jari |
458 |
this.sample_totals.put(term, new Hashtable()); |
2 |
26 Feb 07 |
jari |
459 |
this.pop_totals.put(term, new Hashtable()); |
2 |
26 Feb 07 |
jari |
460 |
|
2 |
26 Feb 07 |
jari |
461 |
while((line = in.readLine()) != null){ |
2 |
26 Feb 07 |
jari |
462 |
idx = line.indexOf("\t"); |
2 |
26 Feb 07 |
jari |
463 |
|
2 |
26 Feb 07 |
jari |
464 |
if( idx >= line.length() || idx < 1){ |
2 |
26 Feb 07 |
jari |
465 |
continue; |
2 |
26 Feb 07 |
jari |
466 |
} |
2 |
26 Feb 07 |
jari |
467 |
|
2 |
26 Feb 07 |
jari |
//put this in to guard against no trailing tab (jcb) |
2 |
26 Feb 07 |
jari |
469 |
idx2 = line.indexOf("\t", idx+1); |
2 |
26 Feb 07 |
jari |
470 |
if(idx2 >= line.length() || idx2 < 1) |
2 |
26 Feb 07 |
jari |
471 |
idx2 = line.length(); |
2 |
26 Feb 07 |
jari |
472 |
|
2 |
26 Feb 07 |
jari |
473 |
category = term + "\t" + line.substring(idx+1, idx2).trim(); |
2 |
26 Feb 07 |
jari |
474 |
if(popVector.contains(line.substring(0,idx).trim())) { |
2 |
26 Feb 07 |
jari |
475 |
if(!this.categories.containsKey(category)){ |
2 |
26 Feb 07 |
jari |
476 |
this.categories.put(category, new Hashtable()); |
2 |
26 Feb 07 |
jari |
477 |
((Hashtable) this.categories.get(category)).put(line.substring(0,idx).trim(), ""); |
2 |
26 Feb 07 |
jari |
478 |
}else{ |
2 |
26 Feb 07 |
jari |
479 |
((Hashtable) this.categories.get(category)).put(line.substring(0,idx).trim(), ""); |
2 |
26 Feb 07 |
jari |
480 |
} |
2 |
26 Feb 07 |
jari |
481 |
} |
2 |
26 Feb 07 |
jari |
482 |
} |
2 |
26 Feb 07 |
jari |
483 |
} |
2 |
26 Feb 07 |
jari |
484 |
|
2 |
26 Feb 07 |
jari |
//create hash table for implies using (implies_associator) |
2 |
26 Feb 07 |
jari |
//This will then be used to add implied categories |
2 |
26 Feb 07 |
jari |
487 |
String fileName, impliesFile; |
2 |
26 Feb 07 |
jari |
488 |
int stringIndex; |
2 |
26 Feb 07 |
jari |
489 |
for(int i = 0; i < annotation_file_names.size(); i++){ |
2 |
26 Feb 07 |
jari |
490 |
fileName = (String)annotation_file_names.elementAt(i); |
2 |
26 Feb 07 |
jari |
491 |
stringIndex = fileName.lastIndexOf(sep); |
2 |
26 Feb 07 |
jari |
492 |
impliesFile = fileName.substring(0, stringIndex) + sep+"Implies"+sep; |
2 |
26 Feb 07 |
jari |
493 |
impliesFile += fileName.substring(stringIndex+1, fileName.length()); |
2 |
26 Feb 07 |
jari |
494 |
|
2 |
26 Feb 07 |
jari |
495 |
File file = new File(impliesFile); |
2 |
26 Feb 07 |
jari |
496 |
if(!file.exists() || !file.isFile()) //if implies file is missing move on |
2 |
26 Feb 07 |
jari |
497 |
continue; |
2 |
26 Feb 07 |
jari |
498 |
|
2 |
26 Feb 07 |
jari |
499 |
in = new BufferedReader(new FileReader(impliesFile)); |
2 |
26 Feb 07 |
jari |
//term = fileName.substring(file_name.lastIndexOf("/")+1, file_name.indexOf(".")); |
2 |
26 Feb 07 |
jari |
501 |
term = fileName.substring(fileName.lastIndexOf(sep)+1, fileName.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
502 |
|
2 |
26 Feb 07 |
jari |
503 |
|
2 |
26 Feb 07 |
jari |
504 |
while((line = in.readLine()) != null){ |
2 |
26 Feb 07 |
jari |
505 |
idx = line.indexOf('\t'); |
2 |
26 Feb 07 |
jari |
506 |
|
2 |
26 Feb 07 |
jari |
507 |
if(idx >= line.length() || idx < 1) //must include a tab |
2 |
26 Feb 07 |
jari |
508 |
continue; |
2 |
26 Feb 07 |
jari |
509 |
|
2 |
26 Feb 07 |
jari |
510 |
if(!implied_associations.containsKey(term + "\t" +line.substring(0,idx).trim())){ |
2 |
26 Feb 07 |
jari |
511 |
implied_associations.put(term + "\t" +line.substring(0,idx).trim(), new Vector()); |
2 |
26 Feb 07 |
jari |
512 |
((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 |
513 |
} else { |
2 |
26 Feb 07 |
jari |
514 |
((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 |
515 |
} |
2 |
26 Feb 07 |
jari |
516 |
} |
2 |
26 Feb 07 |
jari |
517 |
} |
2 |
26 Feb 07 |
jari |
518 |
|
2 |
26 Feb 07 |
jari |
519 |
boolean end = false; |
2 |
26 Feb 07 |
jari |
520 |
|
2 |
26 Feb 07 |
jari |
//(jcb) append associated categories to the list |
2 |
26 Feb 07 |
jari |
522 |
for(int k = 0; k < 10 && !end; k++){ // !end will short circuit if stable |
2 |
26 Feb 07 |
jari |
523 |
String cat=""; |
2 |
26 Feb 07 |
jari |
524 |
Hashtable catHash; |
2 |
26 Feb 07 |
jari |
525 |
Vector impVector; |
2 |
26 Feb 07 |
jari |
526 |
String impCat; |
2 |
26 Feb 07 |
jari |
527 |
|
2 |
26 Feb 07 |
jari |
528 |
end = true; //start at true until no new indices are inserted |
2 |
26 Feb 07 |
jari |
529 |
|
2 |
26 Feb 07 |
jari |
530 |
for( Enumeration enum = implied_associations.keys(); enum.hasMoreElements(); ){ |
2 |
26 Feb 07 |
jari |
531 |
|
2 |
26 Feb 07 |
jari |
532 |
cat = (String) enum.nextElement(); |
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
//if the category is represented, add the implied associations if they don't exist |
2 |
26 Feb 07 |
jari |
535 |
if(categories.containsKey(cat)){ |
2 |
26 Feb 07 |
jari |
536 |
catHash = (Hashtable)categories.get(cat); |
2 |
26 Feb 07 |
jari |
537 |
|
2 |
26 Feb 07 |
jari |
//associated categories |
2 |
26 Feb 07 |
jari |
539 |
impVector = ((Vector)implied_associations.get(cat)); |
2 |
26 Feb 07 |
jari |
540 |
|
2 |
26 Feb 07 |
jari |
541 |
for(int i = 0; i < impVector.size(); i++){ |
2 |
26 Feb 07 |
jari |
542 |
|
2 |
26 Feb 07 |
jari |
543 |
impCat = ((String)impVector.elementAt(i)); |
2 |
26 Feb 07 |
jari |
544 |
|
2 |
26 Feb 07 |
jari |
545 |
if(!categories.containsKey(impCat)){ |
2 |
26 Feb 07 |
jari |
546 |
end = false; |
2 |
26 Feb 07 |
jari |
547 |
categories.put(impCat, new Hashtable()); |
2 |
26 Feb 07 |
jari |
548 |
for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
549 |
((Hashtable)categories.get(impCat)).put((String)categoryEnum.nextElement(), ""); |
2 |
26 Feb 07 |
jari |
550 |
} |
2 |
26 Feb 07 |
jari |
551 |
} else { //category exists, need to append locus link numbers |
2 |
26 Feb 07 |
jari |
552 |
for(Enumeration categoryEnum = catHash.keys(); categoryEnum.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
553 |
String indexString = (String)categoryEnum.nextElement(); |
2 |
26 Feb 07 |
jari |
554 |
if(!((Hashtable)categories.get(impCat)).containsKey(indexString) ){ |
2 |
26 Feb 07 |
jari |
555 |
((Hashtable)categories.get(impCat)).put(indexString, ""); |
2 |
26 Feb 07 |
jari |
556 |
|
2 |
26 Feb 07 |
jari |
557 |
end = false; |
2 |
26 Feb 07 |
jari |
558 |
} |
2 |
26 Feb 07 |
jari |
559 |
} |
2 |
26 Feb 07 |
jari |
560 |
} |
2 |
26 Feb 07 |
jari |
561 |
} |
2 |
26 Feb 07 |
jari |
562 |
} |
2 |
26 Feb 07 |
jari |
563 |
} |
2 |
26 Feb 07 |
jari |
564 |
} |
2 |
26 Feb 07 |
jari |
565 |
|
2 |
26 Feb 07 |
jari |
566 |
|
2 |
26 Feb 07 |
jari |
567 |
}catch(Exception error){ |
2 |
26 Feb 07 |
jari |
568 |
System.out.println("Error occured collecting categories"); |
2 |
26 Feb 07 |
jari |
569 |
System.out.println(error.getMessage()); |
2 |
26 Feb 07 |
jari |
570 |
error.printStackTrace(); |
2 |
26 Feb 07 |
jari |
571 |
} |
2 |
26 Feb 07 |
jari |
572 |
} |
2 |
26 Feb 07 |
jari |
573 |
|
2 |
26 Feb 07 |
jari |
574 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the tab-delimited results containing information on system, |
2 |
26 Feb 07 |
jari |
* category, population hits, population total, sample hits |
2 |
26 Feb 07 |
jari |
* and sample totoal, and the one-tailed hypergeometric probability |
2 |
26 Feb 07 |
jari |
* score of over-representation. |
2 |
26 Feb 07 |
jari |
* categories_list stores all categories hits in the sample |
2 |
26 Feb 07 |
jari |
* categories_population contains categories hits in the population file |
2 |
26 Feb 07 |
jari |
581 |
*/ |
2 |
26 Feb 07 |
jari |
582 |
public void ConstructResults() { |
2 |
26 Feb 07 |
jari |
583 |
|
2 |
26 Feb 07 |
jari |
584 |
String key="", list_hit="", population_hit="", temp=""; |
2 |
26 Feb 07 |
jari |
585 |
this.records = new String[categories_list.size()][7]; |
2 |
26 Feb 07 |
jari |
586 |
this.orders = new String[categories_list.size()]; |
2 |
26 Feb 07 |
jari |
587 |
|
2 |
26 Feb 07 |
jari |
588 |
int c=0; |
2 |
26 Feb 07 |
jari |
//System.out.println(categories_list.isEmpty()); |
2 |
26 Feb 07 |
jari |
590 |
for(Enumeration e = categories_list.keys(); e.hasMoreElements();){ //iterate through categories_list |
2 |
26 Feb 07 |
jari |
591 |
key = (String)(e.nextElement()); //hashtable |
2 |
26 Feb 07 |
jari |
592 |
list_hit=""; |
2 |
26 Feb 07 |
jari |
593 |
population_hit=""; |
2 |
26 Feb 07 |
jari |
594 |
|
2 |
26 Feb 07 |
jari |
595 |
temp = key.substring(0, key.indexOf('\t')).trim(); |
2 |
26 Feb 07 |
jari |
596 |
records[c][0] = temp.substring(temp.lastIndexOf(sep)+1).trim(); |
2 |
26 Feb 07 |
jari |
597 |
records[c][1] = key.substring(key.indexOf('\t')).trim(); |
2 |
26 Feb 07 |
jari |
598 |
|
2 |
26 Feb 07 |
jari |
599 |
list_hit = (String)(categories_list.get(key)); |
2 |
26 Feb 07 |
jari |
600 |
|
2 |
26 Feb 07 |
jari |
601 |
records[c][2] = list_hit; |
2 |
26 Feb 07 |
jari |
602 |
|
2 |
26 Feb 07 |
jari |
603 |
list_total = ((Hashtable)(sample_totals.get(temp))).size(); |
2 |
26 Feb 07 |
jari |
604 |
|
2 |
26 Feb 07 |
jari |
605 |
records[c][3] = String.valueOf(list_total); |
2 |
26 Feb 07 |
jari |
606 |
|
2 |
26 Feb 07 |
jari |
607 |
if(categories_population.containsKey(key)){ |
2 |
26 Feb 07 |
jari |
608 |
population_hit = (String)(categories_population.get(key)); |
2 |
26 Feb 07 |
jari |
609 |
records[c][4] = population_hit; |
2 |
26 Feb 07 |
jari |
610 |
}else{ |
2 |
26 Feb 07 |
jari |
611 |
records[c][4] = ""; |
2 |
26 Feb 07 |
jari |
612 |
} |
2 |
26 Feb 07 |
jari |
613 |
|
2 |
26 Feb 07 |
jari |
614 |
population_total = ((Hashtable)(pop_totals.get(temp))).size(); |
2 |
26 Feb 07 |
jari |
615 |
|
2 |
26 Feb 07 |
jari |
616 |
records[c][5] = String.valueOf(population_total); |
2 |
26 Feb 07 |
jari |
617 |
|
2 |
26 Feb 07 |
jari |
618 |
if(!list_hit.equals("") && !population_hit.equals("")){ |
2 |
26 Feb 07 |
jari |
619 |
double p; |
2 |
26 Feb 07 |
jari |
//System.out.println("population_total = "+ population_total+" list_total = "+list_total); |
2 |
26 Feb 07 |
jari |
621 |
if(reportEaseScore){ //report ease score (jcb) added option of EASEScore |
2 |
26 Feb 07 |
jari |
622 |
if(Integer.parseInt(list_hit) > 1){ |
2 |
26 Feb 07 |
jari |
623 |
p = hgp_computation.SumHGP(population_total, Integer.parseInt(population_hit), list_total-1, Integer.parseInt(list_hit)-1); |
2 |
26 Feb 07 |
jari |
624 |
} else{ |
2 |
26 Feb 07 |
jari |
625 |
p = 1.0; |
2 |
26 Feb 07 |
jari |
626 |
} |
2 |
26 Feb 07 |
jari |
627 |
} else { //else report Fisher Exact Prob. |
2 |
26 Feb 07 |
jari |
628 |
p = hgp_computation.SumHGP(population_total, Integer.parseInt(population_hit), list_total, Integer.parseInt(list_hit)); |
2 |
26 Feb 07 |
jari |
629 |
} |
2 |
26 Feb 07 |
jari |
630 |
records[c][6] = String.valueOf(p); |
2 |
26 Feb 07 |
jari |
631 |
}else{ |
2 |
26 Feb 07 |
jari |
632 |
|
2 |
26 Feb 07 |
jari |
633 |
records[c][6] = "1.0"; |
2 |
26 Feb 07 |
jari |
634 |
} |
2 |
26 Feb 07 |
jari |
635 |
c++; |
2 |
26 Feb 07 |
jari |
636 |
} |
2 |
26 Feb 07 |
jari |
637 |
|
2 |
26 Feb 07 |
jari |
//jcb |
2 |
26 Feb 07 |
jari |
//accumulates hits for the result matrix and the category names |
2 |
26 Feb 07 |
jari |
640 |
categoryNames = new String[hitAccumulator.size()]; |
2 |
26 Feb 07 |
jari |
641 |
listHitMatrix = new String[categoryNames.length][]; |
2 |
26 Feb 07 |
jari |
642 |
|
2 |
26 Feb 07 |
jari |
643 |
int cnt = 0; |
2 |
26 Feb 07 |
jari |
644 |
Vector locusVector; |
2 |
26 Feb 07 |
jari |
//System.out.println("JEASEStatistics 585"); |
2 |
26 Feb 07 |
jari |
646 |
for(Enumeration e = hitAccumulator.keys(); e.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
647 |
String cat = (String)(e.nextElement()); |
2 |
26 Feb 07 |
jari |
648 |
categoryNames[cnt] = cat; |
2 |
26 Feb 07 |
jari |
//System.out.print(cat + ": "); |
2 |
26 Feb 07 |
jari |
650 |
locusVector = ((Vector)hitAccumulator.get(cat)); |
2 |
26 Feb 07 |
jari |
651 |
listHitMatrix[cnt] = new String[locusVector.size()]; |
2 |
26 Feb 07 |
jari |
652 |
for(int i = 0; i < listHitMatrix[cnt].length; i++){ |
2 |
26 Feb 07 |
jari |
653 |
listHitMatrix[cnt][i] = ((String)locusVector.elementAt(i)); |
2 |
26 Feb 07 |
jari |
654 |
|
2 |
26 Feb 07 |
jari |
//System.out.print(listHitMatrix[cnt][i] + " "); //***************************** |
2 |
26 Feb 07 |
jari |
656 |
} |
2 |
26 Feb 07 |
jari |
cnt++; |
2 |
26 Feb 07 |
jari |
//System.out.println(); |
2 |
26 Feb 07 |
jari |
659 |
} |
2 |
26 Feb 07 |
jari |
660 |
} |
2 |
26 Feb 07 |
jari |
661 |
|
2 |
26 Feb 07 |
jari |
662 |
|
2 |
26 Feb 07 |
jari |
663 |
|
2 |
26 Feb 07 |
jari |
/** Sort the results in the ascending order of p-score and write the tab-delimited |
2 |
26 Feb 07 |
jari |
* result to a file and standard IO output |
2 |
26 Feb 07 |
jari |
666 |
*/ |
2 |
26 Feb 07 |
jari |
667 |
public void SortRecords() { |
2 |
26 Feb 07 |
jari |
668 |
BigDecimal big1, big2; |
2 |
26 Feb 07 |
jari |
669 |
String holder; |
2 |
26 Feb 07 |
jari |
670 |
|
2 |
26 Feb 07 |
jari |
671 |
for(int i0=0; i0 < records.length; i0++){ |
2 |
26 Feb 07 |
jari |
672 |
for(int i=0; i < records.length-1 - i0; i++){ |
2 |
26 Feb 07 |
jari |
673 |
big1 = new BigDecimal(records[i][6]); |
2 |
26 Feb 07 |
jari |
674 |
big2 = new BigDecimal(records[i+1][6]); |
2 |
26 Feb 07 |
jari |
675 |
|
2 |
26 Feb 07 |
jari |
676 |
if(big1.compareTo(big2) > 0){ |
2 |
26 Feb 07 |
jari |
677 |
for (int j = 0; j < 7; j++) { |
2 |
26 Feb 07 |
jari |
678 |
holder = records[i][j]; |
2 |
26 Feb 07 |
jari |
679 |
records[i][j] = records[i+1][j]; |
2 |
26 Feb 07 |
jari |
680 |
records[i+1][j] = holder; |
2 |
26 Feb 07 |
jari |
681 |
} |
2 |
26 Feb 07 |
jari |
682 |
} |
2 |
26 Feb 07 |
jari |
683 |
} |
2 |
26 Feb 07 |
jari |
684 |
} |
2 |
26 Feb 07 |
jari |
685 |
} |
2 |
26 Feb 07 |
jari |
686 |
|
2 |
26 Feb 07 |
jari |
687 |
/** |
2 |
26 Feb 07 |
jari |
* Writes the tab-delimited results to the specified output file and to |
2 |
26 Feb 07 |
jari |
* the standout IO output as well |
2 |
26 Feb 07 |
jari |
690 |
*/ |
2 |
26 Feb 07 |
jari |
691 |
public void DisplayResults() { |
2 |
26 Feb 07 |
jari |
692 |
try{ |
2 |
26 Feb 07 |
jari |
693 |
File output_file = new File(output_file_name); |
2 |
26 Feb 07 |
jari |
694 |
FileWriter output_writer = new FileWriter(output_file); //, false); |
2 |
26 Feb 07 |
jari |
695 |
|
2 |
26 Feb 07 |
jari |
696 |
for(int i=0; i < records.length; i++){ |
2 |
26 Feb 07 |
jari |
697 |
for (int j = 0; j < 6; j++) { |
2 |
26 Feb 07 |
jari |
698 |
System.out.print(records[i][j] + "\t"); |
2 |
26 Feb 07 |
jari |
699 |
output_writer.write(records[i][j] + "\t"); |
2 |
26 Feb 07 |
jari |
700 |
output_writer.write("\n"); |
2 |
26 Feb 07 |
jari |
701 |
} |
2 |
26 Feb 07 |
jari |
702 |
} |
2 |
26 Feb 07 |
jari |
703 |
output_writer.close(); |
2 |
26 Feb 07 |
jari |
704 |
}catch(Exception e){ |
2 |
26 Feb 07 |
jari |
705 |
System.out.println(e.getMessage()); |
2 |
26 Feb 07 |
jari |
706 |
} |
2 |
26 Feb 07 |
jari |
707 |
} |
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
709 |
|
2 |
26 Feb 07 |
jari |
710 |
/** |
2 |
26 Feb 07 |
jari |
* (jcb)Modified Hit collection methods to accept a vector argument of annotation keys |
2 |
26 Feb 07 |
jari |
* Modification of code to enable integration into MeV Ease module. |
2 |
26 Feb 07 |
jari |
713 |
*/ |
2 |
26 Feb 07 |
jari |
714 |
|
2 |
26 Feb 07 |
jari |
715 |
/** |
2 |
26 Feb 07 |
jari |
* Get the number of the genes in the population for each category |
2 |
26 Feb 07 |
jari |
* that exists in the annotation files. |
2 |
26 Feb 07 |
jari |
* @param list population list. |
2 |
26 Feb 07 |
jari |
719 |
*/ |
2 |
26 Feb 07 |
jari |
720 |
public void GetPopulationHitsByCategory(Vector list) { |
2 |
26 Feb 07 |
jari |
721 |
BufferedReader in = null; |
2 |
26 Feb 07 |
jari |
722 |
String category="", hits="", key="", locus_id; |
2 |
26 Feb 07 |
jari |
723 |
Hashtable locus_ids = new Hashtable(); |
2 |
26 Feb 07 |
jari |
724 |
Hashtable hash_table = new Hashtable(); |
2 |
26 Feb 07 |
jari |
725 |
Hashtable count_ids = new Hashtable(); |
2 |
26 Feb 07 |
jari |
726 |
this.pop_totals = clear(this.pop_totals); |
2 |
26 Feb 07 |
jari |
727 |
|
2 |
26 Feb 07 |
jari |
728 |
try{ |
2 |
26 Feb 07 |
jari |
729 |
int size = list.size(); |
2 |
26 Feb 07 |
jari |
730 |
for(int i = 0; i < size; i++) //used locus_ids hashtable to store all elements in population list |
2 |
26 Feb 07 |
jari |
731 |
locus_ids.put((String)list.elementAt(i), ""); |
2 |
26 Feb 07 |
jari |
732 |
|
2 |
26 Feb 07 |
jari |
733 |
for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){ //iterate through population list |
2 |
26 Feb 07 |
jari |
734 |
locus_id = (String)(enum1.nextElement()); |
2 |
26 Feb 07 |
jari |
735 |
|
2 |
26 Feb 07 |
jari |
736 |
for(Enumeration enum = categories.keys(); enum.hasMoreElements();){ //iterate through categories |
2 |
26 Feb 07 |
jari |
737 |
key = (String)(enum.nextElement()); |
2 |
26 Feb 07 |
jari |
738 |
hash_table = (Hashtable) (categories.get(key)); |
2 |
26 Feb 07 |
jari |
739 |
|
2 |
26 Feb 07 |
jari |
740 |
if(hash_table.containsKey(locus_id)){ |
2 |
26 Feb 07 |
jari |
741 |
if(!categories_population.containsKey(key)){ |
2 |
26 Feb 07 |
jari |
742 |
categories_population.put(key, "1"); |
2 |
26 Feb 07 |
jari |
743 |
}else{ |
2 |
26 Feb 07 |
jari |
744 |
hits = String.valueOf(Integer.parseInt((String) categories_population.get(key)) + 1); |
2 |
26 Feb 07 |
jari |
745 |
categories_population.put(key, hits); |
2 |
26 Feb 07 |
jari |
746 |
} |
2 |
26 Feb 07 |
jari |
747 |
count_ids.put(locus_id, ""); |
2 |
26 Feb 07 |
jari |
748 |
|
2 |
26 Feb 07 |
jari |
//accumulate the pop total hits |
2 |
26 Feb 07 |
jari |
750 |
key = key.substring(0, key.indexOf("\t")).trim(); |
2 |
26 Feb 07 |
jari |
751 |
((Hashtable)pop_totals.get(key)).put(locus_id,""); |
2 |
26 Feb 07 |
jari |
752 |
} |
2 |
26 Feb 07 |
jari |
753 |
} |
2 |
26 Feb 07 |
jari |
754 |
} |
2 |
26 Feb 07 |
jari |
755 |
population_total = count_ids.size(); |
2 |
26 Feb 07 |
jari |
756 |
}catch(Exception e){ |
2 |
26 Feb 07 |
jari |
757 |
System.out.println(e.getMessage()); |
2 |
26 Feb 07 |
jari |
758 |
} |
2 |
26 Feb 07 |
jari |
// Iterator it = (categories_population.keySet()).iterator(); |
2 |
26 Feb 07 |
jari |
// while (it.hasNext()) |
2 |
26 Feb 07 |
jari |
// System.out.print(it.next()+ " "); |
2 |
26 Feb 07 |
jari |
762 |
|
2 |
26 Feb 07 |
jari |
763 |
} |
2 |
26 Feb 07 |
jari |
764 |
|
2 |
26 Feb 07 |
jari |
765 |
/** |
2 |
26 Feb 07 |
jari |
* Keep the key set but reset all value to blank |
2 |
26 Feb 07 |
jari |
* @param hash |
2 |
26 Feb 07 |
jari |
* @return hash |
2 |
26 Feb 07 |
jari |
769 |
*/ |
2 |
26 Feb 07 |
jari |
770 |
public Hashtable clear(Hashtable hash) { |
2 |
26 Feb 07 |
jari |
771 |
Iterator it = (hash.keySet()).iterator(); |
2 |
26 Feb 07 |
jari |
772 |
while(it.hasNext()) { |
2 |
26 Feb 07 |
jari |
773 |
hash.put(it.next(), new Hashtable()); |
2 |
26 Feb 07 |
jari |
774 |
} |
2 |
26 Feb 07 |
jari |
775 |
return hash; |
2 |
26 Feb 07 |
jari |
776 |
} |
2 |
26 Feb 07 |
jari |
777 |
/** |
2 |
26 Feb 07 |
jari |
* Get the number of the genes in the sample for each category |
2 |
26 Feb 07 |
jari |
* that exists in the annotation files. |
2 |
26 Feb 07 |
jari |
* sample list |
2 |
26 Feb 07 |
jari |
* @param list List indices. |
2 |
26 Feb 07 |
jari |
782 |
*/ |
2 |
26 Feb 07 |
jari |
783 |
public void GetListHitsByCategory(Vector list) { |
2 |
26 Feb 07 |
jari |
784 |
initiation(); |
2 |
26 Feb 07 |
jari |
785 |
this.categories_list = new Hashtable(); |
2 |
26 Feb 07 |
jari |
786 |
BufferedReader in = null; |
2 |
26 Feb 07 |
jari |
787 |
String category="", hits="", key="", locus_id; |
2 |
26 Feb 07 |
jari |
788 |
Hashtable locus_ids = new Hashtable(); |
2 |
26 Feb 07 |
jari |
789 |
Hashtable hash_table = new Hashtable(); |
2 |
26 Feb 07 |
jari |
790 |
Hashtable count_ids = new Hashtable(); |
2 |
26 Feb 07 |
jari |
791 |
this.sample_totals = clear(this.sample_totals); |
2 |
26 Feb 07 |
jari |
792 |
|
2 |
26 Feb 07 |
jari |
793 |
int c = 0; |
2 |
26 Feb 07 |
jari |
794 |
try{ |
2 |
26 Feb 07 |
jari |
795 |
int size = list.size(); |
2 |
26 Feb 07 |
jari |
796 |
for(int i = 0; i < size; i++) //use a hashtable to store all elements in the sample list |
2 |
26 Feb 07 |
jari |
797 |
locus_ids.put((String)list.elementAt(i), ""); |
2 |
26 Feb 07 |
jari |
798 |
|
2 |
26 Feb 07 |
jari |
799 |
for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){ //iterate through samples ids. |
2 |
26 Feb 07 |
jari |
800 |
locus_id = (String)(enum1.nextElement()); //locus_id is hashtable |
2 |
26 Feb 07 |
jari |
801 |
|
2 |
26 Feb 07 |
jari |
802 |
for(Enumeration enum = this.categories.keys(); enum.hasMoreElements();){ //iterate through categories |
2 |
26 Feb 07 |
jari |
803 |
key = (String)(enum.nextElement()); //hashtable |
2 |
26 Feb 07 |
jari |
804 |
hash_table = (Hashtable) (this.categories.get(key)); |
2 |
26 Feb 07 |
jari |
805 |
|
2 |
26 Feb 07 |
jari |
806 |
if(hash_table.containsKey(locus_id)){ //if sample id is present in the list of genes |
2 |
26 Feb 07 |
jari |
807 |
if(!this.categories_list.containsKey(key)){ |
2 |
26 Feb 07 |
jari |
808 |
this.categories_list.put(key, "1"); |
2 |
26 Feb 07 |
jari |
//jcb |
2 |
26 Feb 07 |
jari |
810 |
this.hitAccumulator.put(key, new Vector()); |
2 |
26 Feb 07 |
jari |
811 |
((Vector)this.hitAccumulator.get(key)).add(locus_id); |
2 |
26 Feb 07 |
jari |
//end mod |
2 |
26 Feb 07 |
jari |
813 |
}else { |
2 |
26 Feb 07 |
jari |
814 |
hits = String.valueOf(Integer.parseInt((String) (this.categories_list.get(key))) + 1); |
2 |
26 Feb 07 |
jari |
815 |
this.categories_list.put(key, hits); |
2 |
26 Feb 07 |
jari |
//jcb |
2 |
26 Feb 07 |
jari |
817 |
((Vector)this.hitAccumulator.get(key)).add(locus_id); |
2 |
26 Feb 07 |
jari |
//end mod |
2 |
26 Feb 07 |
jari |
819 |
} |
2 |
26 Feb 07 |
jari |
820 |
count_ids.put(locus_id, ""); |
2 |
26 Feb 07 |
jari |
821 |
|
2 |
26 Feb 07 |
jari |
//accumulate the sample total hits |
2 |
26 Feb 07 |
jari |
823 |
key = key.substring(0, key.indexOf("\t")).trim(); |
2 |
26 Feb 07 |
jari |
824 |
((Hashtable)this.sample_totals.get(key)).put(locus_id,""); |
2 |
26 Feb 07 |
jari |
825 |
} |
2 |
26 Feb 07 |
jari |
826 |
} |
2 |
26 Feb 07 |
jari |
827 |
} |
2 |
26 Feb 07 |
jari |
828 |
this.list_total = count_ids.size(); |
2 |
26 Feb 07 |
jari |
//System.out.println("list_total = " + list_total); |
2 |
26 Feb 07 |
jari |
830 |
}catch(Exception e){ |
2 |
26 Feb 07 |
jari |
831 |
System.out.println(e.getMessage()); |
2 |
26 Feb 07 |
jari |
832 |
} |
2 |
26 Feb 07 |
jari |
// System.out.println("categories_list is empty" + categories_list.isEmpty()); |
2 |
26 Feb 07 |
jari |
// Iterator it = (categories_list.keySet()).iterator(); |
2 |
26 Feb 07 |
jari |
// while (it.hasNext()) |
2 |
26 Feb 07 |
jari |
// System.out.println(it.next()+ " "); |
2 |
26 Feb 07 |
jari |
837 |
} |
2 |
26 Feb 07 |
jari |
838 |
|
2 |
26 Feb 07 |
jari |
839 |
String [][] getResults(){ |
2 |
26 Feb 07 |
jari |
840 |
return this.records; |
2 |
26 Feb 07 |
jari |
841 |
} |
2 |
26 Feb 07 |
jari |
842 |
|
2 |
26 Feb 07 |
jari |
843 |
String [][] getSurveyResults(){ |
2 |
26 Feb 07 |
jari |
844 |
return this.records; |
2 |
26 Feb 07 |
jari |
845 |
} |
2 |
26 Feb 07 |
jari |
846 |
|
2 |
26 Feb 07 |
jari |
847 |
String [][] getListHitMatrix(){ |
2 |
26 Feb 07 |
jari |
848 |
return this.listHitMatrix; |
2 |
26 Feb 07 |
jari |
849 |
} |
2 |
26 Feb 07 |
jari |
850 |
|
2 |
26 Feb 07 |
jari |
851 |
String [] getCategoryNames(){ |
2 |
26 Feb 07 |
jari |
852 |
return this.categoryNames; |
2 |
26 Feb 07 |
jari |
853 |
} |
2 |
26 Feb 07 |
jari |
854 |
|
2 |
26 Feb 07 |
jari |
/** Resets the list total and list hit accumulators. |
2 |
26 Feb 07 |
jari |
856 |
*/ |
2 |
26 Feb 07 |
jari |
857 |
public void resetForNewList(){ |
2 |
26 Feb 07 |
jari |
858 |
this.categories_list = new Hashtable(); |
2 |
26 Feb 07 |
jari |
859 |
this.sample_totals = new Hashtable(); |
2 |
26 Feb 07 |
jari |
860 |
String file_name, term; |
2 |
26 Feb 07 |
jari |
861 |
|
2 |
26 Feb 07 |
jari |
862 |
for(Enumeration e = annotation_file_names.elements(); e.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
863 |
file_name = e.nextElement().toString(); |
2 |
26 Feb 07 |
jari |
864 |
term = file_name.substring(file_name.lastIndexOf(sep)+1, file_name.lastIndexOf(".")); |
2 |
26 Feb 07 |
jari |
865 |
|
2 |
26 Feb 07 |
jari |
//store terms in total hits accumulators |
2 |
26 Feb 07 |
jari |
867 |
this.sample_totals.put(term, new Hashtable()); |
2 |
26 Feb 07 |
jari |
868 |
} |
2 |
26 Feb 07 |
jari |
869 |
} |
2 |
26 Feb 07 |
jari |
870 |
|
2 |
26 Feb 07 |
jari |
871 |
|
2 |
26 Feb 07 |
jari |
872 |
/** |
2 |
26 Feb 07 |
jari |
* Modified Hit collection methods to accept a vector argument of annotation keys |
2 |
26 Feb 07 |
jari |
* Modification of code to enable integration into TIGR MeV EASE module. |
2 |
26 Feb 07 |
jari |
875 |
*/ |
2 |
26 Feb 07 |
jari |
876 |
|
2 |
26 Feb 07 |
jari |
877 |
/** |
2 |
26 Feb 07 |
jari |
* Get the number of the genes in the population for each category that exists in the annotation files. |
2 |
26 Feb 07 |
jari |
* for slide annotation survey |
2 |
26 Feb 07 |
jari |
* @param list Input population list. |
2 |
26 Feb 07 |
jari |
881 |
*/ |
2 |
26 Feb 07 |
jari |
882 |
public void GetPopulationHitsByCategoryForSurvey(Vector list) { |
2 |
26 Feb 07 |
jari |
883 |
initiation(); |
2 |
26 Feb 07 |
jari |
884 |
this.categories_population = new Hashtable(); |
2 |
26 Feb 07 |
jari |
885 |
String category=""; |
2 |
26 Feb 07 |
jari |
886 |
String hits=""; |
2 |
26 Feb 07 |
jari |
887 |
String key=""; |
2 |
26 Feb 07 |
jari |
888 |
String locus_id; |
2 |
26 Feb 07 |
jari |
889 |
Hashtable locus_ids = new Hashtable(); //hashtable uses locus IDs in the list as key, "" as values |
2 |
26 Feb 07 |
jari |
890 |
Hashtable hash_table = new Hashtable(); |
2 |
26 Feb 07 |
jari |
891 |
Hashtable count_ids = new Hashtable(); //no duplicate locus id in the key set |
2 |
26 Feb 07 |
jari |
//jcb |
2 |
26 Feb 07 |
jari |
893 |
String impliedCategory=""; |
2 |
26 Feb 07 |
jari |
894 |
Vector impliedVector; |
2 |
26 Feb 07 |
jari |
895 |
this.pop_totals = clear(this.pop_totals); |
2 |
26 Feb 07 |
jari |
896 |
|
2 |
26 Feb 07 |
jari |
897 |
|
2 |
26 Feb 07 |
jari |
898 |
int c = 0; |
2 |
26 Feb 07 |
jari |
899 |
|
2 |
26 Feb 07 |
jari |
900 |
try{ |
2 |
26 Feb 07 |
jari |
901 |
// //************************************************************************ |
2 |
26 Feb 07 |
jari |
// Hashtable hash = (Hashtable)categories.get("biochemical function RNA polymerase subunit"); |
2 |
26 Feb 07 |
jari |
// Iterator it = hash.keySet().iterator(); |
2 |
26 Feb 07 |
jari |
// while (it.hasNext()){ |
2 |
26 Feb 07 |
jari |
// Object thing = it.next(); |
2 |
26 Feb 07 |
jari |
// System.out.println(thing); |
2 |
26 Feb 07 |
jari |
907 |
// } |
2 |
26 Feb 07 |
jari |
908 |
|
2 |
26 Feb 07 |
jari |
int size = list.size(); |
2 |
26 Feb 07 |
jari |
for(int i = 0; i < size; i++) |
2 |
26 Feb 07 |
jari |
locus_ids.put((String)list.elementAt(i), ""); |
2 |
26 Feb 07 |
jari |
912 |
|
2 |
26 Feb 07 |
jari |
for(Enumeration enum1 = locus_ids.keys(); enum1.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
locus_id = (String)(enum1.nextElement()); |
2 |
26 Feb 07 |
jari |
915 |
|
2 |
26 Feb 07 |
jari |
for(Enumeration enum = categories.keys(); enum.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
key = (String)(enum.nextElement()); |
2 |
26 Feb 07 |
jari |
hash_table = (Hashtable) (categories.get(key)); |
2 |
26 Feb 07 |
jari |
919 |
|
2 |
26 Feb 07 |
jari |
//if locus ID in the list can be found in the categories list |
2 |
26 Feb 07 |
jari |
if(hash_table.containsKey(locus_id)){ |
2 |
26 Feb 07 |
jari |
if(!categories_population.containsKey(key)){ |
2 |
26 Feb 07 |
jari |
categories_population.put(key, "1"); //if first locus id in this category |
2 |
26 Feb 07 |
jari |
//System.out.println("TEASEBench 1042, hitAccumulator add"); |
2 |
26 Feb 07 |
jari |
hitAccumulator.put(key, new Vector()); |
2 |
26 Feb 07 |
jari |
((Vector)hitAccumulator.get(key)).add(locus_id); //put in a list of locus id |
2 |
26 Feb 07 |
jari |
}else{ |
2 |
26 Feb 07 |
jari |
hits = String.valueOf(Integer.parseInt((String)categories_population.get(key)) + 1); |
2 |
26 Feb 07 |
jari |
categories_population.put(key, hits); |
2 |
26 Feb 07 |
jari |
// System.out.println("hitAccumulator is null? "+(hitAccumulator == null)); |
2 |
26 Feb 07 |
jari |
// System.out.println("key is null? "+(key == null)); |
2 |
26 Feb 07 |
jari |
// System.out.println("locus_id is null? "+(locus_id == null)); |
2 |
26 Feb 07 |
jari |
// System.out.println("list is null? "+(hitAccumulator.get(key) == null)); |
2 |
26 Feb 07 |
jari |
((Vector)hitAccumulator.get(key)).add(locus_id); |
2 |
26 Feb 07 |
jari |
935 |
} |
2 |
26 Feb 07 |
jari |
count_ids.put(locus_id, ""); |
2 |
26 Feb 07 |
jari |
//accumulate the pop total hits |
2 |
26 Feb 07 |
jari |
key = key.substring(0, key.indexOf("\t")).trim(); |
2 |
26 Feb 07 |
jari |
((Hashtable)pop_totals.get(key)).put(locus_id,""); |
2 |
26 Feb 07 |
jari |
940 |
} |
2 |
26 Feb 07 |
jari |
941 |
} |
2 |
26 Feb 07 |
jari |
942 |
} |
2 |
26 Feb 07 |
jari |
// System.out.println("cout_ids is empty? " +count_ids.isEmpty()); |
2 |
26 Feb 07 |
jari |
// Set keys = count_ids.keySet(); |
2 |
26 Feb 07 |
jari |
// Iterator it = keys.iterator(); |
2 |
26 Feb 07 |
jari |
// while (it.hasNext()) { |
2 |
26 Feb 07 |
jari |
// Object o = it.next(); |
2 |
26 Feb 07 |
jari |
// System.out.println("key: "+o + " value: "+ count_ids.get(o)); |
2 |
26 Feb 07 |
jari |
949 |
// } |
2 |
26 Feb 07 |
jari |
population_total = count_ids.size(); |
2 |
26 Feb 07 |
jari |
//System.out.println("population total: " + population_total); //******************************* |
2 |
26 Feb 07 |
jari |
952 |
|
2 |
26 Feb 07 |
jari |
}catch(Exception e){ |
2 |
26 Feb 07 |
jari |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
955 |
} |
2 |
26 Feb 07 |
jari |
956 |
} |
2 |
26 Feb 07 |
jari |
957 |
|
2 |
26 Feb 07 |
jari |
958 |
|
2 |
26 Feb 07 |
jari |
959 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the tab-delimited results containing information on system, category, |
2 |
26 Feb 07 |
jari |
* population hits, population total, sample hits and sample totoal, and the |
2 |
26 Feb 07 |
jari |
* one-tailed hypergeometric probability score of over-representation. |
2 |
26 Feb 07 |
jari |
* for slide annotation survey |
2 |
26 Feb 07 |
jari |
964 |
*/ |
2 |
26 Feb 07 |
jari |
965 |
public void ConstructSurveyResults() { |
2 |
26 Feb 07 |
jari |
966 |
|
2 |
26 Feb 07 |
jari |
967 |
String key="", list_hit="", population_hit="", temp=""; |
2 |
26 Feb 07 |
jari |
968 |
|
2 |
26 Feb 07 |
jari |
969 |
records = new String[categories_population.size()][4]; //records is String[][] |
2 |
26 Feb 07 |
jari |
970 |
orders = new String[categories_population.size()]; //orders is String[] |
2 |
26 Feb 07 |
jari |
971 |
|
2 |
26 Feb 07 |
jari |
972 |
int c=0; |
2 |
26 Feb 07 |
jari |
// System.out.println("TEASEBench 1101 "+categories_population.size()); |
2 |
26 Feb 07 |
jari |
974 |
for(Enumeration e = categories_population.keys(); e.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
975 |
key = (String)(e.nextElement()); |
2 |
26 Feb 07 |
jari |
976 |
list_hit=""; |
2 |
26 Feb 07 |
jari |
977 |
population_hit=""; |
2 |
26 Feb 07 |
jari |
978 |
|
2 |
26 Feb 07 |
jari |
979 |
temp = key.substring(0, key.indexOf('\t')).trim(); |
2 |
26 Feb 07 |
jari |
980 |
records[c][0] = temp.substring(temp.lastIndexOf(sep)+1).trim(); |
2 |
26 Feb 07 |
jari |
981 |
records[c][1] = key.substring(key.indexOf('\t')).trim(); |
2 |
26 Feb 07 |
jari |
982 |
|
2 |
26 Feb 07 |
jari |
983 |
list_hit = (String)(categories_population.get(key)); |
2 |
26 Feb 07 |
jari |
984 |
|
2 |
26 Feb 07 |
jari |
985 |
records[c][2] = list_hit; |
2 |
26 Feb 07 |
jari |
986 |
|
2 |
26 Feb 07 |
jari |
987 |
population_total = ((Hashtable)(pop_totals.get(temp))).size(); |
2 |
26 Feb 07 |
jari |
988 |
|
2 |
26 Feb 07 |
jari |
989 |
records[c][3] = String.valueOf(population_total); |
2 |
26 Feb 07 |
jari |
//System.out.println(records[c][3]); |
2 |
26 Feb 07 |
jari |
991 |
c++; |
2 |
26 Feb 07 |
jari |
992 |
} |
2 |
26 Feb 07 |
jari |
993 |
|
2 |
26 Feb 07 |
jari |
//jcb |
2 |
26 Feb 07 |
jari |
//accumulates hits for the result matrix. |
2 |
26 Feb 07 |
jari |
996 |
categoryNames = new String[hitAccumulator.size()]; //keys -> category names |
2 |
26 Feb 07 |
jari |
997 |
listHitMatrix = new String[categoryNames.length][]; //values -> list of hits |
2 |
26 Feb 07 |
jari |
998 |
|
2 |
26 Feb 07 |
jari |
999 |
int cnt = 0; |
2 |
26 Feb 07 |
jari |
1000 |
Vector locusVector; |
2 |
26 Feb 07 |
jari |
1001 |
|
2 |
26 Feb 07 |
jari |
1002 |
for(Enumeration e = hitAccumulator.keys(); e.hasMoreElements();){ |
2 |
26 Feb 07 |
jari |
1003 |
String cat = (String)(e.nextElement()); |
2 |
26 Feb 07 |
jari |
1004 |
categoryNames[cnt] = cat; //categoryNames[0] = name of a category |
2 |
26 Feb 07 |
jari |
1005 |
locusVector = ((Vector)hitAccumulator.get(cat)); |
2 |
26 Feb 07 |
jari |
1006 |
listHitMatrix[cnt] = new String[locusVector.size()]; //listHitMatrix[0][] = list of hits of |
2 |
26 Feb 07 |
jari |
1007 |
for(int i = 0; i < listHitMatrix[cnt].length; i++){ //corresponding category |
2 |
26 Feb 07 |
jari |
1008 |
listHitMatrix[cnt][i] = ((String)locusVector.elementAt(i)); |
2 |
26 Feb 07 |
jari |
1009 |
} |
2 |
26 Feb 07 |
jari |
1010 |
cnt++; |
2 |
26 Feb 07 |
jari |
1011 |
} |
2 |
26 Feb 07 |
jari |
1012 |
|
2 |
26 Feb 07 |
jari |
// for (int i = 0; i < categoryNames.length; i++) { //***************************************** |
2 |
26 Feb 07 |
jari |
// System.out.print(categoryNames[i]+" "); |
2 |
26 Feb 07 |
jari |
// for (int j = 0; j < listHitMatrix[i].length; j++) |
2 |
26 Feb 07 |
jari |
// System.out.print(listHitMatrix[i][j]+" "); |
2 |
26 Feb 07 |
jari |
// System.out.println(); |
2 |
26 Feb 07 |
jari |
1018 |
// } |
2 |
26 Feb 07 |
jari |
1019 |
} |
2 |
26 Feb 07 |
jari |
1020 |
} |