diff --git a/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java b/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java index a20294f..be936b1 100644 --- a/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java +++ b/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java @@ -39,7 +39,11 @@ public String toJSON(){ sb.append("\"impact_pval\" : "+_tg.getImpactPValue(_pathway)+",\n"); sb.append("\"impact_qval\" : "+_tg.getImpactFDR(_pathway)+",\n"); sb.append("\"noncoding_count\" : "+_noncodingcount+",\n"); - sb.append("\"noncoding_count_pval\" : "+_ncp+"\n"); + sb.append("\"noncoding_count_pval\" : "+_ncp+",\n"); + sb.append("\"triangulation\" : "+_tg.getTriangulationScore(_pathway)+",\n"); + sb.append("\"triangulation_pval\" : "+_tg.getTriangulationPValue(_pathway)+",\n"); + sb.append("\"triangulation_qval\" : "+_tg.getTriangulationFDR(_pathway)+"\n"); + sb.append("}\n"); sb.append("}\n"); return sb.toString(); diff --git a/src/edu/uconn/tripoint/export/TriangulationExport.java b/src/edu/uconn/tripoint/export/TriangulationExport.java index d60bf01..6c56809 100644 --- a/src/edu/uconn/tripoint/export/TriangulationExport.java +++ b/src/edu/uconn/tripoint/export/TriangulationExport.java @@ -32,9 +32,9 @@ public void ExportTriangulation(Map> genepathways, Collectio "Support Score"+"\t"+"Support p-value"+"\t"+"Support q-value"+"\t"+ "Consistency Score"+"\t"+"Consistency p-value"+"\t"+"Consistency q-value"+"\t"+ "Impact Score"+"\t"+"Impact p-value"+"\t"+"Impact q-value"+"\t"+ - //"Supporting Triangulation Score"+"\t"+"Supporting Triangulation p-value"+"\t"+"Supporting Triangulation q-value"+"\t"+ - //"Inconsistent Triangulation Score"+"\t"+"Inconsistent Triangulation p-value"+"\t"+"Inconsistent Triangulation q-value"+"\t"+ - "Number of NonCoding Targets"+"\t"+"NonCoding Poisson p-value"+"\n"); + "Number of NonCoding Targets"+"\t"+"NonCoding Poisson p-value"+"\t"+ + "Triangulation Score"+"\t"+"Triangulation p-value"+"\t"+"Triangulation q-value"+"\t"+"\n"); + for(Iterator it = genes.iterator(); it.hasNext();){ TriangulatedGene next = it.next(); for(Iterator it2 = genepathways.get(next.getGene()).iterator(); it2.hasNext();){ @@ -70,13 +70,9 @@ private void writeLine(BufferedWriter bw, Pathway p, TriangulatedGene g, Map l = noncoding.get(gene); int nccount = l != null ? l.size() : 0; @@ -88,9 +84,8 @@ private void writeLine(BufferedWriter bw, Pathway p, TriangulatedGene g, Map getPoissonPValues(Map> m){ average += size; max = Math.max(max, size); } - average /= m.size(); - BigDecimal[] distr = getCumulativePoisson(max,average); - - Map rv = new TreeMap(); - for(Iterator>> it = m.entrySet().iterator(); it.hasNext();){ - Entry> e = it.next(); - rv.put(e.getKey(), getPoissonPValue(distr, e.getValue().size(), average)); + if(max == 0){ + Map rv = new TreeMap(); + for(Iterator>> it = m.entrySet().iterator(); it.hasNext();){ + Entry> e = it.next(); + rv.put(e.getKey(), 1d); + } + return rv; + } + else{ + average /= m.size(); + BigDecimal[] distr = getCumulativePoisson(max,average); + Map rv = new TreeMap(); + for(Iterator>> it = m.entrySet().iterator(); it.hasNext();){ + Entry> e = it.next(); + rv.put(e.getKey(), getPoissonPValue(distr, e.getValue().size(), average)); + } + return rv; } - return rv; } /** diff --git a/src/edu/uconn/tripoint/triangulation/ProgramParameters.java b/src/edu/uconn/tripoint/triangulation/ProgramParameters.java index a55603e..27aab75 100644 --- a/src/edu/uconn/tripoint/triangulation/ProgramParameters.java +++ b/src/edu/uconn/tripoint/triangulation/ProgramParameters.java @@ -7,7 +7,7 @@ public class ProgramParameters { - public final double VERSION = 1.0; + public final double VERSION = 1.1; //required private String _expfile; private String _db; @@ -28,7 +28,50 @@ public class ProgramParameters { private String _chrinter; private String _nct; private int _prox = 50000; + + public ProgramParameters(String expfile, String db, String outdir, + String nct, String ci, String refflat, Integer prox, + double down, double up, double w, double p, double r, int perm, long rstate){ + _down = -0.05; + _up = 0.05; + _w = 0.2; + _p = 0.25; + _r = 0.25; + _gid = "SYMBOL"; + _perm = 10000; + _rstate = System.currentTimeMillis(); + + + _expfile = expfile; + _db = db; + _outdir = outdir; + + if(nct != null && !nct.equals("")){ + _nct = nct; + } + + if(ci != null && !ci.equals("")){ + _chrinter = ci; + } + + if(refflat != null && !refflat.equals("")){ + _refflat = refflat; + } + + if(prox != null){ + _prox = prox; + } + + _down = down; + _up = up; + _w = w; + _p = p; + _r = r; + _perm = perm; + _rstate = rstate; + } + public ProgramParameters(String[] args){ //set default values; @@ -172,13 +215,13 @@ public boolean hasNonCoding(){ public String getConsoleManual(){ StringBuilder sb = new StringBuilder(); sb.append("Version: "+VERSION+"\n"); - sb.append("Usage:\t\t\tjava -jar tripoint.jar -db -o \n\n"); + sb.append("Usage:\t\t\tjava -jar tripoint.jar -db -o \n\n"); sb.append("-db\t\t\tSets pathway database to import pathways from GRAPHITE. Values available: \"kegg\", \"reactome\", \"biocarta\", \"humancyc\", \"nci\", \"panther\" \n\n"); sb.append("-o\t\t\tSets output directory for saving result files. REQUIRED\n\n"); sb.append("-gid\t\t\tSets the conversion method for gene identifiers. Refer to 'convertIdentifiers' in GRAPHITE. Default: \"SYMBOL\" (Currently other identifiers are not recommended)\n\n"); sb.append("-up\t\t\tSets the up-regulated gene threshold. Default: 0.05\n\n"); sb.append("-down\t\t\tSets the down-regulated gene threshold. Default: -0.05\n\n"); - sb.append("-w\t\t\tSets the weak activation/inhibition factor. Default: 0.5\n\n"); + sb.append("-w\t\t\tSets the weak activation/inhibition factor. Default: 0.2\n\n"); sb.append("-p\t\t\tControls the impact of gene expression when calculating measures. Default: 0.25\n\n"); sb.append("-r\t\t\tControls the rate of exponential decay to control edge distance in impact score calculation. Default: 0.25\n\n"); sb.append("-perm\t\t\tSets the number of permutations for p-value calculations. Default: 10000\n\n"); diff --git a/src/edu/uconn/tripoint/triangulation/Run.java b/src/edu/uconn/tripoint/triangulation/Run.java index 381877e..7b4e1dd 100644 --- a/src/edu/uconn/tripoint/triangulation/Run.java +++ b/src/edu/uconn/tripoint/triangulation/Run.java @@ -28,6 +28,7 @@ public static void main(String[] args){ } public void run(String[] args){ + long timestart = System.currentTimeMillis(); ProgramParameters params = new ProgramParameters(args); if(params.hasRequired()){ //Step 1: Import the pathways from Graphite (needs Rserve started to work) @@ -53,18 +54,13 @@ public void run(String[] args){ e.printStackTrace(); } - //Step 3: Run Triangulation. - Triangulation t = new Triangulation(); - t.runTriangulation(globalpathway, pathways, g.values(), params.getDownThresh(), params.getUpThresh(), params.getW(), params.getP(), params.getR()); - - System.out.println("Running permutations:"); - //Step 4: Run Permutations - t.runPermutations(g.values(), params.getNumPermutations(), params.getRandomState(), globalpathway, pathways, params.getDownThresh(), params.getUpThresh(), params.getW(), params.getP(), params.getR()); - //Optional & Output Steps: Map> m = new TreeMap>(); + Map ncp = new TreeMap(); + PoissonNonCoding pnc = new PoissonNonCoding(); if(params.hasNonCoding()){ + Util u = new Util(); Map> refflat = null; try { @@ -89,20 +85,28 @@ public void run(String[] args){ Proximal p = new Proximal(params.getNonCodingTargets(), params.getProximityDistance()); m = p.getNoncodingTargets(g.values(), refflat); } - //Export Noncoding Targets + } + + + //Step 3: Run Triangulation. + Triangulation t = new Triangulation(); + t.runTriangulation(globalpathway, pathways, g.values(), params.getDownThresh(), params.getUpThresh(), params.getW(), params.getP(), params.getR(), m); + + System.out.println("Running permutations:"); + //Step 4: Run Permutations + t.runPermutations(g.values(), params.getNumPermutations(), params.getRandomState(), globalpathway, pathways, params.getDownThresh(), params.getUpThresh(), params.getW(), params.getP(), params.getR(), m); + + if(params.hasNonCoding()){ NonCodingRegulatorExport ncte = new NonCodingRegulatorExport(); try { ncte.ExportNonCodingTargets(globalpathway, pathways, t.getTriangulatedGenes(), m, params.getOutputDirectory(), params.getPathwayDB()); } catch (IOException e) { e.printStackTrace(); } + ncp = pnc.getPoissonPValues(m); } - - - Map ncp = new TreeMap(); - PoissonNonCoding pnc = new PoissonNonCoding(); - ncp = pnc.getPoissonPValues(m); - + + //Export Triangulation TriangulationExport te = new TriangulationExport(); try { @@ -128,6 +132,7 @@ public void run(String[] args){ else{ System.out.println(params.getConsoleManual()); } + System.out.println(System.currentTimeMillis()-timestart+" milliseconds."); } diff --git a/src/edu/uconn/tripoint/triangulation/TriangulatedGene.java b/src/edu/uconn/tripoint/triangulation/TriangulatedGene.java index fb6b74f..e7f33b9 100644 --- a/src/edu/uconn/tripoint/triangulation/TriangulatedGene.java +++ b/src/edu/uconn/tripoint/triangulation/TriangulatedGene.java @@ -17,8 +17,7 @@ public class TriangulatedGene { private Map _inconsistencyscores; private Map _consistencyscores; private Map _impactscores; - private Map _striscores; - private Map _itriscores; + private Map _triscores; //The following variables relate to memory efficient P-Value calculations for each score @@ -31,16 +30,14 @@ public class TriangulatedGene { private Map _inconsistencynullcount; private Map _consistencynullcount; private Map _impactnullcount; - private Map _strinullcount; - private Map _itrinullcount; + private Map _trinullcount; private Map _supportfdr; private Map _inconsistencyfdr; private Map _consistencyfdr; private Map _impactfdr; - private Map _strifdr; - private Map _itrifdr; + private Map _trifdr; /** @@ -54,8 +51,7 @@ public TriangulatedGene(Gene g){ _inconsistencyscores = new TreeMap(); _consistencyscores = new TreeMap(); _impactscores = new TreeMap(); - _striscores = new TreeMap(); - _itriscores = new TreeMap(); + _triscores = new TreeMap(); resetPermutations(); } @@ -141,37 +137,20 @@ public double getImpactScore(String pathway){ /** - * Sets the Supporting Triangulation score for a given pathway. - * @param pathway The pathway for which the score is set. - * @param score The Supporting Triangulation score for the specified pathway. - */ - public void setSupportTriangulationScore(String pathway, double score){ - _striscores.put(pathway, score); - } - - /** - * Gets the Supporting Triangulation score from the specified pathway. - * @param score The Supporting Triangulation score for the specific pathway. - */ - public double getSupportTriangulationScore(String pathway){ - return _striscores.get(pathway); - } - - /** - * Sets the Inconsistent Triangulation score for a given pathway. + * Sets the Triangulation score for a given pathway. * @param pathway The pathway for which the score is set. * @param score The Inconsistent Triangulation score for the specified pathway. */ - public void setInconsistentTriangulationScore(String pathway, double score){ - _itriscores.put(pathway, score); + public void setTriangulationScore(String pathway, double score){ + _triscores.put(pathway, score); } /** - * Gets the Inconsistent Triangulation score from the specified pathway. + * Gets the Triangulation score from the specified pathway. * @param score The Inconsistent Triangulation score for the specific pathway. */ - public double getInconsistentTriangulationScore(String pathway){ - return _itriscores.get(pathway); + public double getTriangulationScore(String pathway){ + return _triscores.get(pathway); } /** @@ -183,8 +162,7 @@ public void resetPermutations(){ _inconsistencynullcount = new TreeMap(); _consistencynullcount = new TreeMap(); _impactnullcount = new TreeMap(); - _itrinullcount = new TreeMap(); - _strinullcount = new TreeMap(); + _trinullcount = new TreeMap(); _permutationsupportscores = new TreeMap(); @@ -196,8 +174,7 @@ public void resetPermutations(){ _inconsistencyfdr = new TreeMap(); _consistencyfdr = new TreeMap(); _impactfdr = new TreeMap(); - _itrifdr = new TreeMap(); - _strifdr = new TreeMap(); + _trifdr = new TreeMap(); } /** @@ -290,22 +267,14 @@ public double getImpactPermutation(String pathway){ /** - * Updates the permutation counts (P-Value calculation) for the supporting triangulation score specified by the pathway. + * Updates the permutation counts (P-Value calculation) for the triangulation score specified by the pathway. * @param pathway The pathway for which the score is set. * @param score The permuted supporting triangulation score for the specified pathway. */ - public void updateSupportTriangulationPermutation(String pathway, double score) { - updatePermutationScore(_striscores, _strinullcount, pathway, score); + public void updateTriangulationPermutation(String pathway, double score) { + updatePermutationScore(_triscores, _trinullcount, pathway, score); } - /** - * Updates the permutation counts (P-Value calculation) for the inconsistent triangulation score specified by the pathway. - * @param pathway The pathway for which the score is set. - * @param score The permuted impact score for the specified pathway. - */ - public void updateInconsistentTriangulationPermutation(String pathway, double score) { - updatePermutationScore(_itriscores, _itrinullcount, pathway, score); - } private void updatePermutationScore(Map obsmap, Map nullcount, String pathway, double score){ double observed = obsmap.get(pathway); @@ -365,24 +334,15 @@ public double getImpactPValue(String pathway){ } /** - * Gets the current P-Value for the support triangulation Score of this gene for the pathway selected. + * Gets the current P-Value for the triangulation Score of this gene for the pathway selected. * @param pathway The pathway selected. * @return The support triangulation Score P-Value for the specified Pathway. */ - public double getSupportTriangulationPValue(String pathway){ - return getPValue(_strinullcount.get(pathway)); + public double getTriangulationPValue(String pathway){ + return getPValue(_trinullcount.get(pathway)); } - /** - * Gets the current P-Value for the inconsistent triangulation Score of this gene for the pathway selected. - * @param pathway The pathway selected. - * @return The inconsistent triangulation Score P-Value for the specified Pathway. - */ - public double getInconsistentTriangulationPValue(String pathway){ - return getPValue(_itrinullcount.get(pathway)); - } - /** @@ -422,22 +382,14 @@ public void setImpactFDR(String pathway, double fdr){ } /** - * Sets the support triangulation FDR value for the pathway specified. + * Sets the triangulation FDR value for the pathway specified. * @param pathway The pathway specified to set the FDR value. * @param fdr The support triangulation FDR value; */ - public void setSupportTriangulationFDR(String pathway, double fdr){ - _strifdr.put(pathway, fdr); + public void setTriangulationFDR(String pathway, double fdr){ + _trifdr.put(pathway, fdr); } - /** - * Sets the inconsistent triangulation FDR value for the pathway specified. - * @param pathway The pathway specified to set the FDR value. - * @param fdr The inconsistent triangulation FDR value; - */ - public void setInconsistentTriangulationFDR(String pathway, double fdr){ - _itrifdr.put(pathway, fdr); - } /** * Gets the inconsistency adjusted p-FDR value for the specified pathway. @@ -476,21 +428,12 @@ public double getImpactFDR(String pathway){ } /** - * Gets the Supporting Triangulation FDR adjusted p-value for the specified pathway. - * @param pathway The pathway specified. - * @return The FDR value for this gene in the specified pathway. - */ - public double getSupportingTriangulationFDR(String pathway){ - return _strifdr.get(pathway); - } - - /** - * Gets the Inconsistent Triangulation FDR adjusted p-value for the specified pathway. + * Gets the Triangulation FDR adjusted p-value for the specified pathway. * @param pathway The pathway specified. * @return The FDR value for this gene in the specified pathway. */ - public double getInconsistentTriangulationFDR(String pathway){ - return _itrifdr.get(pathway); + public double getTriangulationFDR(String pathway){ + return _trifdr.get(pathway); } private double getPValue(Integer nullcount){ diff --git a/src/edu/uconn/tripoint/triangulation/Triangulation.java b/src/edu/uconn/tripoint/triangulation/Triangulation.java index 980a337..9892b7d 100644 --- a/src/edu/uconn/tripoint/triangulation/Triangulation.java +++ b/src/edu/uconn/tripoint/triangulation/Triangulation.java @@ -21,12 +21,15 @@ import org.rosuda.REngine.REXPMismatchException; import org.rosuda.REngine.REngineException; +import quin.network.Location; + public class Triangulation { private Map _alltgenes; private TriangulatedGene[] _tgenearray; private Map> _genepathways; - public void runTriangulation(Pathway globalpathway, Pathway[] pathways, Collection genes, double downthresh, double upthresh, double w, double p, double r){ + public void runTriangulation(Pathway globalpathway, Pathway[] pathways, Collection genes, double downthresh, + double upthresh, double w, double p, double r, Map> noncoding){ _alltgenes = new TreeMap(); //Set a map of genes for log(n) access @@ -46,6 +49,158 @@ public void runTriangulation(Pathway globalpathway, Pathway[] pathways, Collecti setConsistencyScores(triangulatedgenes, pathways); setImpactScores(triangulatedgenes, pathways, downthresh, upthresh, p, r); + NormParameters connparams = getConsistencyNormParams(triangulatedgenes, pathways); + NormParameters impnparams = getImpactNormParams(triangulatedgenes, pathways); + setTriangulationScores(triangulatedgenes, pathways, connparams, impnparams, noncoding); + } + + + private NormParameters getPermutedConsistencyNormParams(TriangulatedGene[] genes, Pathway[] pathways){ + double nmin = Double.POSITIVE_INFINITY; + double nmax = Double.NEGATIVE_INFINITY; + double pmin = Double.POSITIVE_INFINITY; + double pmax = Double.NEGATIVE_INFINITY; + for(int i = 0; i < genes.length; i++){ + for(Iterator it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){ + Pathway curpath = it.next(); + double score = genes[i].getConsistencyPermutation(curpath.getId()); + + if(score > 0){ + pmin = Math.min(pmin, score); + pmax = Math.max(pmax, score); + } + else if (score < 0){ + nmin = Math.min(nmin, score); + pmax = Math.max(pmax, score); + } + } + } + + if(nmin == Double.POSITIVE_INFINITY){ + nmin = 0; + } + if(pmin == Double.POSITIVE_INFINITY){ + pmin = 0; + } + if(nmax == Double.NEGATIVE_INFINITY){ + nmax = 1; + } + if(pmax == Double.NEGATIVE_INFINITY){ + pmax = 1; + } + + return new NormParameters(nmin,nmax,pmin,pmax); + } + + private NormParameters getConsistencyNormParams(TriangulatedGene[] genes, Pathway[] pathways){ + double nmin = Double.POSITIVE_INFINITY; + double nmax = Double.NEGATIVE_INFINITY; + double pmin = Double.POSITIVE_INFINITY; + double pmax = Double.NEGATIVE_INFINITY; + for(int i = 0; i < genes.length; i++){ + for(Iterator it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){ + Pathway curpath = it.next(); + double score = genes[i].getConsistencyScore(curpath.getId()); + + if(score > 0){ + pmin = Math.min(pmin, score); + pmax = Math.max(pmax, score); + } + else if (score < 0){ + nmin = Math.min(nmin, score); + pmax = Math.max(pmax, score); + } + } + } + + if(nmin == Double.POSITIVE_INFINITY){ + nmin = 0; + } + if(pmin == Double.POSITIVE_INFINITY){ + pmin = 0; + } + if(nmax == Double.NEGATIVE_INFINITY){ + nmax = 1; + } + if(pmax == Double.NEGATIVE_INFINITY){ + pmax = 1; + } + + return new NormParameters(nmin,nmax,pmin,pmax); + } + + private NormParameters getImpactNormParams(TriangulatedGene[] genes, Pathway[] pathways){ + double nmin = Double.POSITIVE_INFINITY; + double nmax = Double.NEGATIVE_INFINITY; + double pmin = Double.POSITIVE_INFINITY; + double pmax = Double.NEGATIVE_INFINITY; + for(int i = 0; i < genes.length; i++){ + for(Iterator it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){ + Pathway curpath = it.next(); + double score = genes[i].getImpactScore(curpath.getId()); + + if(score > 0){ + pmin = Math.min(pmin, score); + pmax = Math.max(pmax, score); + } + else if (score < 0){ + nmin = Math.min(nmin, score); + pmax = Math.max(pmax, score); + } + } + } + + if(nmin == Double.POSITIVE_INFINITY){ + nmin = 0; + } + if(pmin == Double.POSITIVE_INFINITY){ + pmin = 0; + } + if(nmax == Double.NEGATIVE_INFINITY){ + nmax = 1; + } + if(pmax == Double.NEGATIVE_INFINITY){ + pmax = 1; + } + + return new NormParameters(nmin,nmax,pmin,pmax); + } + + private NormParameters getPermutedImpactNormParams(TriangulatedGene[] genes, Pathway[] pathways){ + double nmin = Double.POSITIVE_INFINITY; + double nmax = Double.NEGATIVE_INFINITY; + double pmin = Double.POSITIVE_INFINITY; + double pmax = Double.NEGATIVE_INFINITY; + for(int i = 0; i < genes.length; i++){ + for(Iterator it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){ + Pathway curpath = it.next(); + double score = genes[i].getImpactPermutation(curpath.getId()); + + if(score > 0){ + pmin = Math.min(pmin, score); + pmax = Math.max(pmax, score); + } + else if (score < 0){ + nmin = Math.min(nmin, score); + pmax = Math.max(pmax, score); + } + } + } + + if(nmin == Double.POSITIVE_INFINITY){ + nmin = 0; + } + if(pmin == Double.POSITIVE_INFINITY){ + pmin = 0; + } + if(nmax == Double.NEGATIVE_INFINITY){ + nmax = 1; + } + if(pmax == Double.NEGATIVE_INFINITY){ + pmax = 1; + } + + return new NormParameters(nmin,nmax,pmin,pmax); } private Map> getGenePathways(Pathway[] pathways){ @@ -66,7 +221,7 @@ public Map> getGenePathways(){ return _genepathways; } - public void runPermutations(Collection genes, int numpermutatons, long seedstart, Pathway globalpathway, Pathway[] pathways, double downthresh, double upthresh, double w, double p, double r){ + public void runPermutations(Collection genes, int numpermutatons, long seedstart, Pathway globalpathway, Pathway[] pathways, double downthresh, double upthresh, double w, double p, double r, Map> noncoding){ //Store the original gene values in order List values = new LinkedList(); for(Iterator it = genes.iterator(); it.hasNext();){ @@ -85,7 +240,7 @@ public void runPermutations(Collection genes, int numpermutatons, long see while(it1.hasNext()){ it2.next().setValue(it1.next()); } - setPermutationScores(globalpathway, pathways, downthresh, upthresh, w, p, r); + setPermutationScores(globalpathway, pathways, downthresh, upthresh, w, p, r, noncoding); //System.out.println(i); if((i+1)%500 == 0){ System.out.println("Finished "+(i+1)+" permutations."); @@ -118,8 +273,7 @@ private void setFDRAdjustedValues(TriangulatedGene[] genes, Pathway[] pathways) List spvals = new LinkedList(); List cpvals = new LinkedList(); List impvals = new LinkedList(); - List strivals = new LinkedList(); - List itrivals = new LinkedList(); + List trivals = new LinkedList(); for(int i = 0; i < genes.length; i++){ @@ -132,8 +286,7 @@ private void setFDRAdjustedValues(TriangulatedGene[] genes, Pathway[] pathways) spvals.add(tg.getSupportPValue(curpath.getId())); cpvals.add(tg.getConsistencyPValue(curpath.getId())); impvals.add(tg.getImpactPValue(curpath.getId())); - strivals.add(tg.getSupportTriangulationPValue(curpath.getId())); - itrivals.add(tg.getInconsistentTriangulationPValue(curpath.getId())); + trivals.add(tg.getTriangulationPValue(curpath.getId())); } } @@ -145,8 +298,7 @@ private void setFDRAdjustedValues(TriangulatedGene[] genes, Pathway[] pathways) double[] sqvals = fdrc.getCorrectedPValues(getArray(spvals)); double[] cqvals = fdrc.getCorrectedPValues(getArray(cpvals)); double[] imqvals = fdrc.getCorrectedPValues(getArray(impvals)); - double[] striqvals = fdrc.getCorrectedPValues(getArray(strivals)); - double[] itriqvals = fdrc.getCorrectedPValues(getArray(itrivals)); + double[] triqvals = fdrc.getCorrectedPValues(getArray(trivals)); Iterator it1 = gl.iterator(); @@ -160,8 +312,7 @@ private void setFDRAdjustedValues(TriangulatedGene[] genes, Pathway[] pathways) tg.setSupportFDR(p.getId(), sqvals[index]); tg.setConsistencyFDR(p.getId(), cqvals[index]); tg.setImpactFDR(p.getId(), imqvals[index]); - tg.setSupportTriangulationFDR(p.getId(), striqvals[index]); - tg.setInconsistentTriangulationFDR(p.getId(), itriqvals[index]); + tg.setTriangulationFDR(p.getId(), triqvals[index]); index++; } @@ -197,7 +348,7 @@ public Map getTrianguatedGeneMapping(){ return _alltgenes; } - private void setPermutationScores(Pathway globalpathway, Pathway[] pathways, double downthresh, double upthresh, double w, double p, double r){ + private void setPermutationScores(Pathway globalpathway, Pathway[] pathways, double downthresh, double upthresh, double w, double p, double r, Map> noncoding){ for(int i = 0; i < _tgenearray.length; i++){ _tgenearray[i].newPermutationRound(); } @@ -207,7 +358,9 @@ private void setPermutationScores(Pathway globalpathway, Pathway[] pathways, dou setPermutationConsistencyScores(_tgenearray, pathways); setPermutationImpactScores(_tgenearray, pathways, downthresh, upthresh, p, r); - setTriangulationScores(_tgenearray, pathways); + NormParameters connparams = getPermutedConsistencyNormParams(_tgenearray, pathways); + NormParameters impnparams = getPermutedImpactNormParams(_tgenearray, pathways); + setPermutationTriangulationScores(_tgenearray, pathways, connparams, impnparams, noncoding); } @@ -257,6 +410,49 @@ private void setPermutationImpactScores(TriangulatedGene[] genes, Pathway[] path } + + private void setPermutationTriangulationScores(TriangulatedGene[] genes, Pathway[] pathways, NormParameters connparam, NormParameters impnparam, Map> noncoding){ + double max = 0; + for(Iterator> it = noncoding.values().iterator(); it.hasNext();){ + max = Math.max(max, it.next().size()); + } + + for(int i = 0; i < genes.length; i++){ + int numnoncoding = noncoding.get(genes[i].getGene()).size(); + for(Iterator it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){ + Pathway curpath = it.next(); + String pathwayid = curpath.getId(); + double consistencyscore = genes[i].getConsistencyScore(pathwayid); + double impactscore = genes[i].getImpactScore(pathwayid); + + double tri = 0; + + double factor = 1; + if(consistencyscore < 0){ + factor = -1; + } + + if(consistencyscore != 0 && impactscore != 0){ + tri = getNormScore(consistencyscore, connparam)+getNormScore(impactscore, impnparam); + } + if(noncoding != null && noncoding.size() > 0){ + if(numnoncoding == 0){ + tri = 0; + } + else{ + tri += (numnoncoding/max); + } + genes[i].updateTriangulationPermutation(pathwayid, factor*tri/3); + + } + else{ + genes[i].updateTriangulationPermutation(pathwayid, factor*tri/2); + } + } + } + + } + private void setInconsistencyScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double w, double p){ for(int i = 0; i < genes.length; i++){ //genes[i].setInconsistencyScore(globalpathway.getId(), getInconsistencyScore(globalpathway, genes[i], downthresh, upthresh, w, p)); @@ -302,19 +498,43 @@ private void setImpactScores(TriangulatedGene[] genes, Pathway[] pathways, doubl } } - private void setTriangulationScores(TriangulatedGene[] genes, Pathway[] pathways){ + private void setTriangulationScores(TriangulatedGene[] genes, Pathway[] pathways, NormParameters connparam, NormParameters impnparam, Map> noncoding){ + double max = 0; + for(Iterator> it = noncoding.values().iterator(); it.hasNext();){ + max = Math.max(max, it.next().size()); + } + for(int i = 0; i < genes.length; i++){ + int numnoncoding = noncoding.get(genes[i].getGene()).size(); for(Iterator it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){ Pathway curpath = it.next(); String pathwayid = curpath.getId(); double consistencyscore = genes[i].getConsistencyScore(pathwayid); - double consistency = genes[i].getConsistencyPValue(pathwayid); - double impact = genes[i].getImpactPValue(pathwayid); + double impactscore = genes[i].getImpactScore(pathwayid); + + double tri = 0; + + double factor = 1; + if(consistencyscore < 0){ + factor = -1; + } + + if(consistencyscore != 0 && impactscore != 0){ + tri = getNormScore(consistencyscore, connparam)+getNormScore(impactscore, impnparam); + } + if(noncoding != null && noncoding.size() > 0){ + if(numnoncoding == 0){ + tri = 0; + } + else{ + tri += (numnoncoding/max); + } + genes[i].setTriangulationScore(pathwayid, factor*tri/3); - double stri = consistencyscore <= 0 ? 1 : consistency*0.5+impact*0.5; - double itri = consistencyscore >= 0 ? 1 :consistency*0.5+impact*0.5; - genes[i].setSupportTriangulationScore(pathwayid, stri); - genes[i].setInconsistentTriangulationScore(pathwayid, itri); + } + else{ + genes[i].setTriangulationScore(pathwayid, factor*tri/2); + } } } } @@ -459,6 +679,36 @@ private double getImpactScore(TriangulatedGene g, Pathway pathway, double downth return score; } + private double getNormScore(double score, NormParameters np){ + if(score < 0){ + return (score - np.nmin)/np.ndiv; + } + else if(score > 0){ + return (score - np.pmin)/np.pdiv; + } + return 0; + } + + private class NormParameters{ + + public double nmin; + public double nmax; + public double ndiv; + public double pmin; + public double pmax; + public double pdiv; + + public NormParameters(double nminp, double nmaxp, double pminp, double pmaxp){ + nmin = nminp; + nmax = nmaxp; + ndiv = nmax-nmin; + pmin = pminp; + pmax = pmaxp; + pdiv = pmax-pmin; + } + + } + // private double getImpactScoreNormalizer(TriangulatedGene g, Pathway pathway, double downthresh, double upthresh, double p, double e, double rate){ // double score = 0; // diff --git a/src/edu/uconn/tripoint/ui/InputValidator.java b/src/edu/uconn/tripoint/ui/InputValidator.java new file mode 100644 index 0000000..505610a --- /dev/null +++ b/src/edu/uconn/tripoint/ui/InputValidator.java @@ -0,0 +1,210 @@ +package edu.uconn.tripoint.ui; + +import java.io.File; + + +public class InputValidator { + + private boolean _haserror; + private String _errormessages; + + private String _expfile; + private String _outdir; + private String _pathwaydb; + private int _randomstate; + private String _cifile; + private String _ncrfile; + private String _refflatfile; + private Integer _proxdist; + private double _up; + private double _down; + private double _weak; + private double _ed; + private double _geneinf; + + + + public InputValidator(String expfile, String outdir, String pwdb, String randomstate, + String ci, String ncr, String refflat, String proxdist, + String up, String down, String weak, String ed, String geneinf){ + _haserror = false; + StringBuilder errorbuilder = new StringBuilder(); + + _expfile = expfile.trim(); + if(!(new File(_expfile).exists())){ + _haserror = true; + errorbuilder.append("Gene expression/score file does not exist.\n"); + } + + _outdir = outdir.trim(); + if(!(new File(_outdir).exists())){ + _haserror = true; + errorbuilder.append("Output directory does not exist.\n"); + } + if(!(new File(_outdir).isDirectory())){ + _haserror = true; + errorbuilder.append("Output directory is not a directory.\n"); + } + + + _pathwaydb = pwdb.trim(); + if(_pathwaydb.equals("")){ + _haserror = true; + errorbuilder.append("Missing pathway database.\n"); + } + + try{ + _randomstate = Integer.parseInt(randomstate.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Random state must be an integer.\n"); + } + + ///// + _cifile = ci.trim(); + if(!_cifile.equals("") && !(new File(_cifile).exists())){ + _haserror = true; + errorbuilder.append("Chromatin interaction file does not exist.\n"); + } + + _ncrfile = ncr.trim(); + if(!_ncrfile.equals("") && !(new File(_ncrfile).exists())){ + _haserror = true; + errorbuilder.append("Noncoding regulatory file does not exist.\n"); + } + + _refflatfile = refflat.trim(); + if(!_refflatfile.equals("") && !(new File(_refflatfile).exists())){ + _haserror = true; + errorbuilder.append("Refflat file does not exist.\n"); + } + + if(!proxdist.trim().equals("")){ + try{ + _proxdist = Integer.parseInt(proxdist.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Proximity distance must be an integer.\n"); + } + } + if(!_ncrfile.equals("")){ + if(_refflatfile.equals("")){ + _haserror = true; + errorbuilder.append("Must provide a refflat file for TSS definitions for linking non-coding regulators.\n"); + } + if(_cifile.equals("") || _proxdist == null){ + _haserror = true; + errorbuilder.append("Must provide either chromatin interactions or a distance for proximity based identification of TSS targets.\n"); + } + } + ///// + + try{ + _up = Double.parseDouble(up.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Active gene/upregulation threshold must be numeric.\n"); + } + + try{ + _down = Double.parseDouble(down.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Inctive gene/downregulation threshold must be numeric.\n"); + } + + try{ + _weak = Double.parseDouble(weak.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Weak association factor must be numeric.\n"); + } + + try{ + _ed = Double.parseDouble(weak.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Exponential decay must be numeric.\n"); + } + + try{ + _geneinf = Double.parseDouble(weak.trim()); + } + catch(NumberFormatException e){ + _haserror = true; + errorbuilder.append("Gene score influence factor must be numeric.\n"); + } + + _errormessages = errorbuilder.toString(); + } + + public String getExpFile(){ + return _expfile; + } + + public String getOutputDirectory(){ + return _outdir; + } + + public String getPathwayDB(){ + return _pathwaydb; + } + + public int getRandomState(){ + return _randomstate; + } + + + public String getNoncodingRegulatorsFile(){ + return _ncrfile; + } + + public String getRefflatFile(){ + return _refflatfile; + } + + + public String getInteractionFile(){ + return _cifile; + } + + public Integer getProxDist(){ + return _proxdist; + } + + public double getUpThresh(){ + return _up; + } + + public double getDownThresh(){ + return _down; + } + + public double getWeakFactor(){ + return _weak; + } + + public double getExponentialDecayRate(){ + return _ed; + } + + public double getGeneScoreInfluence(){ + return _geneinf; + } + + + public boolean hasError(){ + return _haserror; + } + + public String getErrorMessages(){ + return _errormessages; + } + +} diff --git a/src/edu/uconn/tripoint/ui/NonCodingPanel.java b/src/edu/uconn/tripoint/ui/NonCodingPanel.java new file mode 100644 index 0000000..95320d1 --- /dev/null +++ b/src/edu/uconn/tripoint/ui/NonCodingPanel.java @@ -0,0 +1,65 @@ +package edu.uconn.tripoint.ui; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + + +@SuppressWarnings("serial") +public class NonCodingPanel extends JPanel{ + + private JTextField _ci; + private JTextField _nct; + private JTextField _refflat; + private JTextField _prox; + + public NonCodingPanel(JFileChooser fc){ + UIUtil util = new UIUtil(); + setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + + JLabel nctl = new JLabel("Noncoding Regulators:"); + _nct = new JTextField(); + util.setFieldPanel(this, fc, nctl, _nct, new JButton("..."), null, false); + + JLabel refflatl = new JLabel("UCSC Refflat TSS Definitions:"); + _refflat = new JTextField(); + util.setFieldPanel(this, fc, refflatl, _refflat, new JButton("..."), null, false); + + JLabel cil = new JLabel("Target TSS via Chromatin Interactions:"); + _ci = new JTextField(); + util.setFieldPanel(this, fc, cil, _ci, new JButton("..."), null, false); + + JLabel proxl = new JLabel("or Target TSS via Proximity(bp):"); + _prox = new JTextField(""); + add(util.getHorizontalField(proxl, _prox)); + + + + + + + } + + public String getInteractions(){ + return _ci.getText(); + } + + + public String getNoncodingRegulators(){ + return _nct.getText(); + } + + public String getRefflat(){ + return _refflat.getText(); + } + + + public String getProximityDistance(){ + return _prox.getText(); + } + + +} diff --git a/src/edu/uconn/tripoint/ui/ScoreConfigPanel.java b/src/edu/uconn/tripoint/ui/ScoreConfigPanel.java new file mode 100644 index 0000000..d1fc103 --- /dev/null +++ b/src/edu/uconn/tripoint/ui/ScoreConfigPanel.java @@ -0,0 +1,72 @@ +package edu.uconn.tripoint.ui; + +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + + +@SuppressWarnings("serial") +public class ScoreConfigPanel extends JPanel{ + + private JTextField _act; + private JTextField _inact; + private JTextField _weakfactor; + private JTextField _expdecay; + private JTextField _gsimp; + + + public ScoreConfigPanel(){ + UIUtil util = new UIUtil(); + setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + JLabel actl = new JLabel("Active (i.e., Upregulated) Gene Theshold:"); + _act = new JTextField("0.5"); + _act.setColumns(5); + add(util.getHorizontalField(actl, _act)); + + JLabel inactl = new JLabel("Inactive (i.e., Downregulated) Gene Threshold:"); + _inact = new JTextField("-0.5"); + _inact.setColumns(5); + add(util.getHorizontalField(inactl, _inact)); + + + JLabel wl = new JLabel("Weak Pathway Association Factor (w):"); + _weakfactor = new JTextField("0.2"); + _weakfactor.setColumns(5); + add(util.getHorizontalField(wl, _weakfactor)); + + JLabel edl = new JLabel("Expnonential Decay Rate (r):"); + _expdecay = new JTextField("0.25"); + _expdecay.setColumns(5); + add(util.getHorizontalField(edl, _expdecay)); + + JLabel gsil = new JLabel("Gene Score Influence (p):"); + _gsimp = new JTextField("0.25"); + _gsimp.setColumns(5); + add(util.getHorizontalField(gsil, _gsimp)); + + } + + public String getActiveThreshold(){ + return _act.getText(); + } + + public String getInActiveThreshold(){ + return _inact.getText(); + } + + public String getWeakFactor(){ + return _weakfactor.getText(); + } + + + public String getExponentialDecayRate(){ + return _expdecay.getText(); + } + + public String getGeneScoreImpact(){ + return _gsimp.getText(); + } + + +} diff --git a/src/edu/uconn/tripoint/ui/TriPOINT.java b/src/edu/uconn/tripoint/ui/TriPOINT.java new file mode 100644 index 0000000..e772e73 --- /dev/null +++ b/src/edu/uconn/tripoint/ui/TriPOINT.java @@ -0,0 +1,156 @@ +package edu.uconn.tripoint.ui; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JSeparator; +import javax.swing.JTextField; +import javax.swing.JPanel; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.border.EmptyBorder; + + +public class TriPOINT { + private final JFileChooser _fc = new JFileChooser(); + + private String _path = "./"; + private JFrame _frame; + private UIUtil _util = new UIUtil(); + + private JTextField _dg; + private JTextField _out; + private JComboBox _pdb; + private JTextField _rs; + private ScoreConfigPanel _scp; + private NonCodingPanel _ncp; + + + + public static void main(String[] args) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (UnsupportedLookAndFeelException e) { } + catch (ClassNotFoundException e) { } + catch (InstantiationException e) { } + catch (IllegalAccessException e) { } + new TriPOINT(); + + } + + public TriPOINT(){ + _path = System.getProperty("user.dir"); + if(!_path.endsWith("/")){ + _path += "/"; + } + + _fc.setCurrentDirectory(new File(_path)); + + _frame = new JFrame(); + _frame.add(getMainPanel()); + + _frame.setSize(450,550); + _frame.setResizable(false); + _frame.setVisible(true); + _frame.setTitle("TriPOINT"); + _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + } + + private JPanel getMainPanel(){ + + JPanel rv = new JPanel(); + rv.setLayout(new BoxLayout(rv, BoxLayout.Y_AXIS)); + + + JLabel dgl = new JLabel("Gene Expression/Score File:"); + _dg = new JTextField(); + _util.setFieldPanel(rv, _fc, dgl, _dg, new JButton("..."), null, false); + + JLabel outl = new JLabel("Output Directory:"); + _out = new JTextField(); + _util.setFieldPanel(rv, _fc, outl, _out, new JButton("..."), null, true); + + JLabel pdbl = new JLabel("Pathway DB:"); + _pdb = new JComboBox(); + _pdb.addItem("kegg"); + _pdb.addItem("reactome"); + _pdb.addItem("biocarta"); + _pdb.addItem("humancyc"); + _pdb.addItem("nci"); + _pdb.addItem("panther"); + + rv.add(_util.getHorizontalField(pdbl, _pdb)); + + JLabel rsl = new JLabel("Random State:"); + _rs = new JTextField("929"); + rv.add(_util.getHorizontalField(rsl, _rs)); + + rv.add(new JSeparator(JSeparator.HORIZONTAL)); + JPanel ncropanel = new JPanel(); + ncropanel.setLayout(new BorderLayout()); + JLabel ncro = new JLabel("Non-Coding Regulator Options:"); + ncro.setFont(new Font("Arial", Font.BOLD, 14)); + ncropanel.add(ncro, BorderLayout.WEST); + rv.add(ncropanel); + _ncp = new NonCodingPanel(_fc); + rv.add(_ncp); + + + rv.add(new JSeparator(JSeparator.HORIZONTAL)); + JPanel scpanel = new JPanel(); + scpanel.setLayout(new BorderLayout()); + JLabel sc = new JLabel("Score Configurations:"); + sc.setFont(new Font("Arial", Font.BOLD, 14)); + scpanel.add(sc, BorderLayout.WEST); + rv.add(scpanel); + _scp = new ScoreConfigPanel(); + rv.add(_scp); + + JPanel runpanel = new JPanel(); + runpanel.setLayout(new BorderLayout()); + JButton run = new JButton("Run TriPOINT"); + runpanel.add(run, BorderLayout.EAST); + rv.add(runpanel); + + run.addActionListener(new ActionListener(){ + + @Override + public void actionPerformed(ActionEvent e) { + InputValidator iv = new InputValidator(_dg.getText(), _out.getText(), _pdb.getSelectedItem().toString(), _rs.getText(), + _ncp.getInteractions(), _ncp.getNoncodingRegulators(), _ncp.getRefflat(), _ncp.getProximityDistance(), + _scp.getActiveThreshold(), _scp.getInActiveThreshold(), _scp.getWeakFactor(), _scp.getExponentialDecayRate(), _scp.getGeneScoreImpact()); + + if(iv.hasError()){ + JOptionPane.showMessageDialog(_frame, iv.getErrorMessages().toString(),"Input Error",JOptionPane.ERROR_MESSAGE); + + } + else{ + + } + } + + }); + + rv.setBorder(new EmptyBorder(10, 10, 10, 10)); + + + + return rv; + } + + + +} diff --git a/src/edu/uconn/tripoint/ui/UIUtil.java b/src/edu/uconn/tripoint/ui/UIUtil.java new file mode 100644 index 0000000..841fcb5 --- /dev/null +++ b/src/edu/uconn/tripoint/ui/UIUtil.java @@ -0,0 +1,63 @@ +package edu.uconn.tripoint.ui; + + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.GroupLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.GroupLayout.ParallelGroup; +import javax.swing.GroupLayout.SequentialGroup; +import javax.swing.filechooser.FileFilter; + +public class UIUtil { + public JPanel getHorizontalField(JComponent ...c ){ + JPanel rvpanel = new JPanel(); + GroupLayout rvlayout = new GroupLayout(rvpanel); + rvpanel.setLayout(rvlayout); + SequentialGroup seqgroup = rvlayout.createSequentialGroup(); + ParallelGroup pgroup = rvlayout.createParallelGroup(GroupLayout.Alignment.BASELINE); + for(int i = 0; i < c.length; i++){ + seqgroup.addComponent(c[i]); + pgroup.addComponent(c[i]); + } + rvlayout.setHorizontalGroup(seqgroup); + rvlayout.setVerticalGroup(rvlayout.createSequentialGroup().addGroup(pgroup)); + return rvpanel; + } + + public void setFileAction(final JFileChooser fc, final JPanel comp, final JTextField filetext, final JButton filebutton, final FileFilter filter, final boolean directory){ + final ActionListener bamaction = new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + fc.resetChoosableFileFilters(); + fc.setFileFilter(filter); + fc.setMultiSelectionEnabled(false); + if(directory){ + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + else{ + fc.setFileSelectionMode(JFileChooser.FILES_ONLY); + } + int result = fc.showOpenDialog(comp); + if(result == JFileChooser.APPROVE_OPTION){ + filetext.setText(fc.getSelectedFile().getAbsolutePath()); + } + } + }; + filebutton.addActionListener(bamaction); + } + + public void setFieldPanel(JPanel panel, JFileChooser fc, JLabel label, JTextField textfield, JButton button, FileFilter filter, boolean directory){ + textfield.setColumns(12); + setFileAction(fc, panel, textfield, button, filter, directory); + panel.add(getHorizontalField(label, textfield, button)); + } + + +}