/**
 * Data structure to represent a gene-set library.
 * 
 * @author		Edward Y. Chen
 * @since		5/14/2013 
 */

package edu.mssm.pharm.maayanlab.Enrichr;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;

public class GeneSetLibrary {

	private final HashMap<String, Term> terms = new HashMap<String, Term>();
	private final HashSet<String> backgroundGenes = new HashSet<String>();	
	private int numOfBackgroundGenes;
	private boolean isRanked = false;
	
	public GeneSetLibrary(Collection<String> libraryLines) {
		constructTerms(libraryLines);
		numOfBackgroundGenes = backgroundGenes.size();
	}
	
	public GeneSetLibrary(Collection<String> libraryLines, Collection<String> rankLines) {
		this(libraryLines);
		constructRanks(rankLines);
		isRanked = true;
	}
	
	private void constructTerms(Collection<String> libraryLines) {
		for (String line : libraryLines) {
			// In gmt file, 1st column is key, 2nd column is irrelevant, and the rest are the values
			String[] splitLine = line.split("\\t");
			String termName = splitLine[0];
			HashSet<String> targets = new HashSet<String>();
			
			for (int i = 2; i < splitLine.length; i++) {
				String gene = splitLine[i].toUpperCase();
				backgroundGenes.add(gene);
				targets.add(gene);
			}
			
			Term term = new Term(termName, targets);
			terms.put(termName, term);
		}
	}
	
	private void constructRanks(Collection<String> rankLines) {
		for (String line : rankLines) {
			String[] splitLine = line.split("\\t");	// Splits into 3 columns: name, average, std
			terms.get(splitLine[0]).setRankStats(Double.parseDouble(splitLine[1]), Double.parseDouble(splitLine[2]));
		}
	}

	public int getNumOfBackgroundGenes() {
		return numOfBackgroundGenes;
	}
	
	public boolean contains(String gene) {
		return backgroundGenes.contains(gene);
	}

	public boolean isRanked() {
		return isRanked;
	}
}

@@ -794,16 +794,21 @@
 es);%0D%0A%09%09
+this.
 isRanked
@@ -1594,24 +1594,36 @@
 ge, std%0D%0A%09%09%09
+Term term = 
 terms.get(sp
@@ -1637,21 +1637,26 @@
 %5B0%5D)
-.setRankStats
+;%0D%0A%09%09%09term.setMean
 (Dou
@@ -1684,18 +1684,49 @@
 Line%5B1%5D)
-, 
+);%0D%0A%09%09%09term.setStandardDeviation(
 Double.p

Use mean and std setter. Use this explicitly.