diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..96e29a5
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..84c048a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/build/
diff --git a/.project b/.project
new file mode 100644
index 0000000..27a5884
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ TriPOINT
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.nature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..295926d
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 0000000..017b6f4
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src/edu/uconn/tripoint/export/CytoscapeEdge.java b/src/edu/uconn/tripoint/export/CytoscapeEdge.java
new file mode 100644
index 0000000..5559fe0
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/CytoscapeEdge.java
@@ -0,0 +1,29 @@
+package edu.uconn.tripoint.export;
+
+public abstract class CytoscapeEdge {
+
+ private int _id;
+ private CytoscapeNode _n1, _n2;
+
+ public CytoscapeEdge(int id, CytoscapeNode n1, CytoscapeNode n2){
+ _id = id;
+ _n1 = n1;
+ _n2 = n2;
+ }
+
+ public int getId(){
+ return _id;
+ }
+
+ public CytoscapeNode getN1(){
+ return _n1;
+ }
+
+ public CytoscapeNode getN2(){
+ return _n2;
+ }
+
+
+ public abstract String toJSON();
+
+}
diff --git a/src/edu/uconn/tripoint/export/CytoscapeExport.java b/src/edu/uconn/tripoint/export/CytoscapeExport.java
new file mode 100644
index 0000000..8d1d572
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/CytoscapeExport.java
@@ -0,0 +1,130 @@
+package edu.uconn.tripoint.export;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import quin.network.Location;
+import edu.uconn.tripoint.graph.Edge;
+import edu.uconn.tripoint.graph.Node;
+import edu.uconn.tripoint.pathway.Gene;
+import edu.uconn.tripoint.pathway.Pathway;
+import edu.uconn.tripoint.pathway.PathwayEdge;
+import edu.uconn.tripoint.triangulation.TriangulatedGene;
+
+/**
+ *
+ * Exports the pathways into a cytoscape format.
+ *
+ */
+public class CytoscapeExport {
+
+ /**
+ *
+ * @param p
+ * @param genes
+ * @param noncoding
+ * @param outdir
+ */
+ public void exportToCytoscapeJSON(Pathway p, Map genes, Map> noncoding, String outdir, String prefix){
+ Map geneids = new TreeMap();
+ int nindex = 0;
+ Map nl = new TreeMap();
+ for(Iterator> it = p.getNodes().iterator(); it.hasNext();){
+ Node next = it.next();
+ int curnindex = nindex++;
+ Gene curgene = next.getData();
+ geneids.put(curgene, curnindex);
+ int nccount = 0;
+ if(noncoding.get(curgene) != null){
+ nccount = noncoding.get(curgene).size();
+ }
+ nl.put(curnindex,new PathwayGeneCytoscapeNode(curnindex, p.getId(), genes.get(curgene), nccount));
+ }
+
+ int eindex = 0;
+ List el = new LinkedList();
+ for(Iterator> it = p.getEdges().iterator(); it.hasNext();){
+ Edge edge = it.next();
+ Gene src = edge.getSource().getData();
+ Gene dest = edge.getDestination().getData();
+ String type = getStringType(edge.getData().getType());
+ el.add(new PathwayCytoscapeEdge(eindex, nl.get(geneids.get(src)), nl.get(geneids.get(dest)), type));
+ }
+
+ for(Iterator git = geneids.keySet().iterator(); git.hasNext();){
+ Gene next = git.next();
+ List l = noncoding.get(next);
+ if(l != null){
+ for(Iterator lit = l.iterator(); lit.hasNext();){
+ int curnindex = nindex++;
+ CytoscapeNode n = new NonCodingCytoscapeNode(curnindex, lit.next());
+ nl.put(curnindex,n);
+ el.add(new PathwayCytoscapeEdge(eindex++, nl.get(geneids.get(next)), n, "NonCoding"));
+ }
+ }
+ }
+
+ String outdir2 = outdir;
+ if(!outdir.endsWith("/")){
+ outdir2 += "/";
+ }
+
+ String filename = p.getId();
+ filename = filename.substring(filename.indexOf(":")+1).replaceAll("[^A-Za-z0-9]", "");
+ filename = filename.substring(0, Math.min(filename.length(), 16));
+
+ try {
+ writeJSONFile(outdir2+prefix+"_"+filename+".json", p, nl, el);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private String getStringType(int type){
+ if(type == PathwayEdge.ACTIVATION){
+ return "Activation";
+ }
+ else if(type == PathwayEdge.INHIBITION){
+ return "Inhibition";
+ }
+ else{
+ return "Association";
+ }
+ }
+
+ private void writeJSONFile(String outfile, Pathway p, Map nodes, List edges) throws IOException{
+ BufferedWriter bw = new BufferedWriter(new FileWriter(outfile));
+ bw.write("{\n");
+ bw.write("\"data\": {\"name\": \""+p.getId()+"\"},\n");
+ bw.write("\"elements\" : {\n");
+ bw.write("\"nodes\" : [");
+ Iterator it = nodes.values().iterator();
+ if(it.hasNext()){
+ bw.write(it.next().toJSON()+"\n");
+ }
+ while(it.hasNext()){
+ bw.write(","+it.next().toJSON()+"\n");
+ }
+ bw.write("],\n");
+ bw.write("\"edges\" : [\n");
+ Iterator ite = edges.iterator();
+ if(ite.hasNext()){
+ bw.write(ite.next().toJSON()+"\n");
+ }
+ while(ite.hasNext()){
+ bw.write(","+ite.next().toJSON()+"\n");
+ }
+ bw.write("]\n");
+ bw.write("}\n");
+ bw.write("}\n");
+ bw.flush();
+ bw.close();
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/export/CytoscapeNode.java b/src/edu/uconn/tripoint/export/CytoscapeNode.java
new file mode 100644
index 0000000..15483ba
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/CytoscapeNode.java
@@ -0,0 +1,18 @@
+package edu.uconn.tripoint.export;
+
+public abstract class CytoscapeNode {
+
+ private int _id;
+
+ public CytoscapeNode(int id){
+ _id = id;
+ }
+
+ public int getId(){
+ return _id;
+ }
+
+
+ public abstract String toJSON();
+
+}
diff --git a/src/edu/uconn/tripoint/export/NonCodingCytoscapeNode.java b/src/edu/uconn/tripoint/export/NonCodingCytoscapeNode.java
new file mode 100644
index 0000000..5b64625
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/NonCodingCytoscapeNode.java
@@ -0,0 +1,25 @@
+package edu.uconn.tripoint.export;
+
+import quin.network.Location;
+
+public class NonCodingCytoscapeNode extends CytoscapeNode{
+
+ public Location _l;
+ public NonCodingCytoscapeNode(int id, Location l) {
+ super(id);
+ _l = l;
+ }
+
+ @Override
+ public String toJSON(){
+ StringBuilder sb = new StringBuilder();
+ sb.append("{\n");
+ sb.append("\"data\" : {\n");
+ sb.append("\"id\" : \""+getId()+"\",\n");
+ sb.append("\"type\" : \"NonCoding Target\",\n");
+ sb.append("\"name\" : \""+_l.getChr()+":"+_l.getStart()+"-"+_l.getEnd()+"\"\n");
+ sb.append("}\n");
+ sb.append("}\n");
+ return sb.toString();
+ }
+}
diff --git a/src/edu/uconn/tripoint/export/NonCodingTargetExport.java b/src/edu/uconn/tripoint/export/NonCodingTargetExport.java
new file mode 100644
index 0000000..7842cae
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/NonCodingTargetExport.java
@@ -0,0 +1,49 @@
+package edu.uconn.tripoint.export;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import quin.network.Location;
+import edu.uconn.tripoint.pathway.Gene;
+import edu.uconn.tripoint.pathway.Pathway;
+import edu.uconn.tripoint.triangulation.TriangulatedGene;
+
+public class NonCodingTargetExport {
+
+ public void ExportNonCodingTargets(Pathway globalpathway, Pathway[] pathways, Collection genes, Map> noncoding, String outdir, String prefix) throws IOException{
+ String outdir2 = outdir;
+ if(!outdir.endsWith("/")){
+ outdir2 += "/";
+ }
+
+ BufferedWriter bw = new BufferedWriter(new FileWriter(outdir2+prefix+"_noncoding.txt"));
+ bw.write("Gene ID"+"\t"+
+ "Chr"+"\t"+"Start"+"\t"+"End"+"\n");
+ for(Iterator it = genes.iterator(); it.hasNext();){
+ TriangulatedGene next = it.next();
+ writeLine(bw,next, noncoding);
+ }
+
+ bw.flush();
+ bw.close();
+ }
+
+ private void writeLine(BufferedWriter bw, TriangulatedGene g, Map> noncoding) throws IOException{
+ Gene gene = g.getGene();
+ List nc = noncoding.get(gene);
+ if(nc.size() > 0){
+ String id = gene.getId();
+ for(Iterator it = nc.iterator(); it.hasNext();){
+ Location next = it.next();
+ bw.write(id+"\t"+
+ next.getChr()+"\t"+next.getStart()+"\t"+next.getEnd()+"\n");
+ }
+
+ }
+ }
+}
diff --git a/src/edu/uconn/tripoint/export/PathwayCytoscapeEdge.java b/src/edu/uconn/tripoint/export/PathwayCytoscapeEdge.java
new file mode 100644
index 0000000..ad892f4
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/PathwayCytoscapeEdge.java
@@ -0,0 +1,25 @@
+package edu.uconn.tripoint.export;
+
+public class PathwayCytoscapeEdge extends CytoscapeEdge{
+
+ private String _type;
+
+ public PathwayCytoscapeEdge(int id, CytoscapeNode n1, CytoscapeNode n2, String type){
+ super(id, n1, n2);
+ _type = type;
+ }
+
+ public String toJSON(){
+ StringBuilder sb = new StringBuilder();
+ sb.append("{\n");
+ sb.append("\"data\" : {\n");
+ sb.append("\"id\" : \""+getId()+"\",\n");
+ sb.append("\"source\" : \""+getN1().getId()+"\",\n");
+ sb.append("\"target\" : \""+getN2().getId()+"\",\n");
+ sb.append("\"type\" : \""+_type+"\"\n");
+ sb.append("}\n");
+ sb.append("}\n");
+ return sb.toString();
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java b/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java
new file mode 100644
index 0000000..05ce374
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/PathwayGeneCytoscapeNode.java
@@ -0,0 +1,46 @@
+package edu.uconn.tripoint.export;
+
+import edu.uconn.tripoint.triangulation.TriangulatedGene;
+
+public class PathwayGeneCytoscapeNode extends CytoscapeNode {
+
+ private String _pathway;
+ private TriangulatedGene _tg;
+ private int _noncodingcount;
+
+ public PathwayGeneCytoscapeNode(int id, String pathway, TriangulatedGene tg, int nccount){
+ super(id);
+ _pathway = pathway;
+ _tg = tg;
+ _noncodingcount = nccount;
+ }
+
+ @Override
+ public String toJSON(){
+ StringBuilder sb = new StringBuilder();
+ sb.append("{\n");
+ sb.append("\"data\" : {\n");
+ sb.append("\"id\" : \""+getId()+"\",\n");
+ sb.append("\"type\" : \"Pathway Gene\",\n");
+ sb.append("\"name\" : \""+_tg.getGene().getId()+"\",\n");
+ sb.append("\"pathway\" : \""+_pathway+"\",\n");
+ sb.append("\"expression\" : "+_tg.getGene().getValue()+",\n");
+ sb.append("\"inconsistency\" : "+_tg.getInconsistencyScore(_pathway)+",\n");
+ sb.append("\"inconsistency_pval\" : "+_tg.getInconsistencyPValue(_pathway)+",\n");
+ sb.append("\"inconsistency_qval\" : "+_tg.getInconsistencyFDR(_pathway)+",\n");
+ sb.append("\"support\" : "+_tg.getSupportScore(_pathway)+",\n");
+ sb.append("\"support_pval\" : "+_tg.getSupportPValue(_pathway)+",\n");
+ sb.append("\"support_qval\" : "+_tg.getSupportFDR(_pathway)+",\n");
+ sb.append("\"consistency\" : "+_tg.getConsistencyScore(_pathway)+",\n");
+ sb.append("\"consistency_pval\" : "+_tg.getConsistencyPValue(_pathway)+",\n");
+ sb.append("\"consistency_qval\" : "+_tg.getConsistencyFDR(_pathway)+",\n");
+ sb.append("\"impact\" : "+_tg.getImpactScore(_pathway)+",\n");
+ sb.append("\"impact_pval\" : "+_tg.getImpactPValue(_pathway)+",\n");
+ sb.append("\"impact_qval\" : "+_tg.getImpactFDR(_pathway)+",\n");
+ sb.append("\"noncoding_count\" : "+_noncodingcount+"\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
new file mode 100644
index 0000000..8c05ea4
--- /dev/null
+++ b/src/edu/uconn/tripoint/export/TriangulationExport.java
@@ -0,0 +1,96 @@
+package edu.uconn.tripoint.export;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import quin.network.Location;
+import edu.uconn.tripoint.pathway.Gene;
+import edu.uconn.tripoint.pathway.Pathway;
+import edu.uconn.tripoint.triangulation.TriangulatedGene;
+
+
+/**
+ * Exports the Triangulation scores in a tab-delimited text format.
+ */
+public class TriangulationExport {
+
+
+ public void ExportTriangulation(Map> genepathways, Collection genes, Map> noncoding, Map ncpval, String outdir, String prefix) throws IOException{
+ String outdir2 = outdir;
+ if(!outdir.endsWith("/")){
+ outdir2 += "/";
+ }
+
+ BufferedWriter bw = new BufferedWriter(new FileWriter(outdir2+prefix+"_triangulation.txt"));
+ bw.write("Gene ID"+"\t"+"Pathway ID"+"\t"+"Expression Value"+"\t"+
+ "Inconsistency Score"+"\t"+"Inconsistency p-value"+"\t"+"Inconsistency q-value"+"\t"+
+ "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");
+ for(Iterator it = genes.iterator(); it.hasNext();){
+ TriangulatedGene next = it.next();
+ for(Iterator it2 = genepathways.get(next.getGene()).iterator(); it2.hasNext();){
+ Pathway p = it2.next();
+ writeLine(bw,p,next,noncoding, ncpval);
+ }
+ }
+
+ bw.flush();
+ bw.close();
+ }
+
+ private void writeLine(BufferedWriter bw, Pathway p, TriangulatedGene g, Map> noncoding, Map ncpval) throws IOException{
+ Gene gene = g.getGene();
+
+ String id = gene.getId();
+ String pid = p.getId();
+ double value = gene.getValue();
+
+ double is = g.getInconsistencyScore(pid);
+ double ip = g.getInconsistencyPValue(pid);
+ double ifdr = g.getInconsistencyFDR(pid);
+
+ double ss = g.getSupportScore(pid);
+ double sp = g.getSupportPValue(pid);
+ double sfdr = g.getSupportFDR(pid);
+
+ double cs = g.getConsistencyScore(pid);
+ double cp = g.getConsistencyPValue(pid);
+ double cfdr = g.getConsistencyFDR(pid);
+
+ double ims = g.getImpactScore(pid);
+ double imp = g.getImpactPValue(pid);
+ double imfdr = g.getImpactFDR(pid);
+
+ double stris = g.getSupportTriangulationScore(pid);
+ double strip = g.getSupportTriangulationPValue(pid);
+ double strifdr = g.getSupportingTriangulationFDR(pid);
+
+ double itris = g.getInconsistentTriangulationScore(pid);
+ double itrip = g.getInconsistentTriangulationPValue(pid);
+ double itrifdr = g.getInconsistentTriangulationFDR(pid);
+
+ List l = noncoding.get(gene);
+ int nccount = l != null ? l.size() : 0;
+ Double d = ncpval.get(gene);
+ double ncp = d != null ? d : 1;
+
+ bw.write(id+"\t"+pid+"\t"+value+"\t"+
+ is+"\t"+ip+"\t"+ifdr+"\t"+
+ ss+"\t"+sp+"\t"+sfdr+"\t"+
+ cs+"\t"+cp+"\t"+cfdr+"\t"+
+ ims+"\t"+imp+"\t"+imfdr+"\t"+
+ stris+"\t"+strip+"\t"+strifdr+"\t"+
+ itris+"\t"+itrip+"\t"+itrifdr+"\t"+
+ nccount+"\t"+ncp+"\n");
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/graph/Edge.java b/src/edu/uconn/tripoint/graph/Edge.java
new file mode 100644
index 0000000..db3c024
--- /dev/null
+++ b/src/edu/uconn/tripoint/graph/Edge.java
@@ -0,0 +1,87 @@
+package edu.uconn.tripoint.graph;
+
+/**
+ *
+ * The edge object associates two Node objects in a graph and stores data specific to the edge.
+ *
+ * @param The type of data associated with a node.
+ * @param The type of data associated with an edge.
+ */
+public class Edge {
+
+ private Node _n1, _n2;
+ private ED _data;
+ private boolean _directed;
+
+ /**
+ * Creates an instance of an Edge.
+ * @param n1 The first node to be associated. If directed, it is the source node.
+ * @param n2 The second node to be associated. If directed, it is the destination node.
+ * @param data The data stored in this edge object.
+ * @param directed Boolean value representing whether or not this is a directed edge.
+ */
+ public Edge(Node n1, Node n2, ED data, boolean directed){
+ _n1 = n1;
+ _n2 = n2;
+ _data = data;
+ _directed = directed;
+ }
+
+ /**
+ * Sets the data stored in this edge.
+ * @param data The data to be stored in this edge.
+ */
+ public void setData(ED data){
+ _data = data;
+ }
+
+ /**
+ * Gets the first (source) node in this edge.
+ * @return The first (source) node in this edge.
+ */
+ public Node getNode1(){
+ return _n1;
+ }
+
+ /**
+ * Gets the second (destination) node in this edge.
+ * @return The second (destination) node in this edge.
+ */
+ public Node getNode2(){
+ return _n2;
+ }
+
+ /**
+ * Gets the data stored in this edge.
+ * @return The data stored in this edge.
+ */
+ public ED getData(){
+ return _data;
+ }
+
+ /**
+ * Gets the source node in a directed edge.
+ * @return The source node in a directed edge.
+ */
+ public Node getSource(){
+ return getNode1();
+ }
+
+ /**
+ * Gets the destination node in a directed edge.
+ * @return The destination node in a directed edge.
+ */
+ public Node getDestination(){
+ return getNode2();
+ }
+
+
+ /**
+ * Returns whether or not this edge is directed.
+ * @return TRUE if directed, FALSE if undirected.
+ */
+ public boolean isDirected(){
+ return _directed;
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/graph/Node.java b/src/edu/uconn/tripoint/graph/Node.java
new file mode 100644
index 0000000..6a34e53
--- /dev/null
+++ b/src/edu/uconn/tripoint/graph/Node.java
@@ -0,0 +1,68 @@
+package edu.uconn.tripoint.graph;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * The node object is one element of a graph where a List of Nodes will represent the entirety
+ * of the graph. Nodes are just the building blocks and it is up to the implementation to
+ * decide how the overall graph is constructed/stored.
+ *
+ * @param The type of data associated with a node.
+ * @param The type of data associated with an edge.
+ */
+public class Node {
+
+ private ND _data;
+ private List> _edges;
+
+ /**
+ * Creates a Node object that encapsulates the data provided.
+ * @param data The data stored in this Node.
+ */
+ public Node(ND data){
+ _data = data;
+ _edges = new LinkedList>();
+ }
+
+ /**
+ * Get the data encapsulated in this node.
+ * @return The data encapsulated in this node.
+ */
+ public ND getData(){
+ return _data;
+ }
+
+ /**
+ * Sets new data for this node to encapsulate.
+ * @param data The new data object for this node to encapsulate.
+ */
+ public void setData(ND data){
+ _data = data;
+ }
+
+ /**
+ * Add an edge to the list of edges connected to this node.
+ * @param edge The edge instance to add to this node's list of edges.
+ */
+ public void addEdge(Edge edge){
+ _edges.add(edge);
+ }
+
+ /**
+ * Get the list of edges connected to this node.
+ * @return The list of edges connected to this node.
+ */
+ public List> getEdges(){
+ return _edges;
+ }
+
+ /**
+ * Removes an edge from this node.
+ * @param e The edge instance to remove from this node's list of edges.
+ */
+ public void removeEdge(Edge e){
+ _edges.remove(e);
+ }
+}
diff --git a/src/edu/uconn/tripoint/integration/ChromatinInteractionNetwork.java b/src/edu/uconn/tripoint/integration/ChromatinInteractionNetwork.java
new file mode 100644
index 0000000..3eb82b2
--- /dev/null
+++ b/src/edu/uconn/tripoint/integration/ChromatinInteractionNetwork.java
@@ -0,0 +1,97 @@
+package edu.uconn.tripoint.integration;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import edu.uconn.tripoint.pathway.Gene;
+import quin.network.ChIAPETNetwork;
+import quin.network.Edge;
+import quin.network.Location;
+import quin.network.NetworkBuilder;
+import quin.network.Node;
+
+public class ChromatinInteractionNetwork implements NonCodingTargets {
+
+ private ChIAPETNetwork _network;
+
+ /**
+ * Uses QuIN to generate the Chromatin Interaction Network from 7 column tab delimited file.
+ * The last column of the interaction file is an integer score.
+ * @param interactionfile Seven column tab delimited chromatin interaction file.
+ * @param ext How much to extend the locations provided to intersect with interaction anchors.
+ */
+ public ChromatinInteractionNetwork(String interactionfile, int ext){
+ try {
+ NetworkBuilder nb = new NetworkBuilder(interactionfile);
+ _network = nb.buildNetwork(ext, 0, 1, 1000000, Integer.MAX_VALUE, 0, 2, Integer.MAX_VALUE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Uses QuIN to generate the Chromatin Interaction Network from 7 column tab delimited file.
+ * The last column of the interaction file is an integer score.
+ * @param interactionfile Seven column tab delimited chromatin interaction file.
+ * @param bedfile Bedfile containing regions to build the interaction network.
+ * @param ext How much to extend the locations provided to intersect with interaction anchors.
+ */
+ public ChromatinInteractionNetwork(String interactionfile, String bedfile, int ext){
+ try {
+ Util u = new Util();
+ Location[] l = u.readLocations(bedfile);
+ NetworkBuilder nb = new NetworkBuilder(interactionfile);
+ _network = nb.buildNetwork(l, 1, 1000000, Integer.MAX_VALUE, 0, 2, Integer.MAX_VALUE, 0, false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ @Override
+ public Map> getNoncodingTargets(Collection genes, Map> genecoords){
+ Util u = new Util();
+ quin.network.Util u2 = new quin.network.Util();
+ TreeMap sortednodes = u2.getChrStartSorted(_network.getNodes());
+
+ Location[] allgenelocations = u.getAllLocations(genecoords);
+ TreeMap sortedgeneloci = u2.getChrStartSorted(allgenelocations);
+
+ Map> rv = new TreeMap>();
+
+ for(Iterator it = genes.iterator(); it.hasNext();){
+ Gene next = it.next();
+ Map mappedlocations = new TreeMap();
+ if(genecoords.containsKey(next)){
+ for(Iterator it2 = genecoords.get(next).iterator(); it2.hasNext();){
+ Location nextlocation = it2.next();
+ Location[] chrnodes = sortednodes.get(nextlocation.getChr());
+ Location[] onodes = new Location[0];
+ if(chrnodes != null){
+ onodes = u.getOverlappingLoci(chrnodes, nextlocation);
+ }
+ for(int i = 0; i < onodes.length; i++){
+ Node curnode = (Node)onodes[i];
+ Edge[] edges = curnode.getEdges();
+ for(int j = 0; j < edges.length; j++){
+ Edge curedge = edges[j];
+ Node target = curedge.getAdjacentNode(curnode);
+ if(sortedgeneloci.containsKey(target.getChr()) && u.getOverlappingLoci(sortedgeneloci.get(target.getChr()), target).length == 0){
+ mappedlocations.put(target.getChr()+":"+target.getStart()+"-"+target.getEnd(), target);
+ }
+ }
+ }
+ }
+ }
+ rv.put(next, new LinkedList(mappedlocations.values()));
+ }
+
+ return rv;
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/integration/NonCodingTargets.java b/src/edu/uconn/tripoint/integration/NonCodingTargets.java
new file mode 100644
index 0000000..c5c36b9
--- /dev/null
+++ b/src/edu/uconn/tripoint/integration/NonCodingTargets.java
@@ -0,0 +1,20 @@
+package edu.uconn.tripoint.integration;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import quin.network.Location;
+import edu.uconn.tripoint.pathway.Gene;
+
+public interface NonCodingTargets {
+
+ /**
+ * Gets a list of non-coding targets which are targeting the gene.
+ * @param genes The collection of genes to get the targets from.
+ * @param genecoords The gene coordinates.
+ * @return A mapping from gene to non-coding targets.
+ */
+ public Map> getNoncodingTargets(Collection genes, Map> genecoords);
+
+}
diff --git a/src/edu/uconn/tripoint/integration/PoissonNonCoding.java b/src/edu/uconn/tripoint/integration/PoissonNonCoding.java
new file mode 100644
index 0000000..6af11b0
--- /dev/null
+++ b/src/edu/uconn/tripoint/integration/PoissonNonCoding.java
@@ -0,0 +1,67 @@
+package edu.uconn.tripoint.integration;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import quin.network.Location;
+import edu.uconn.tripoint.pathway.Gene;
+
+public class PoissonNonCoding {
+
+ public Map getPoissonPValues(Map> m){
+ double average = 0;
+ int max = 0;
+ for(Iterator> it = m.values().iterator(); it.hasNext();){
+ int size = it.next().size();
+ 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));
+ }
+ return rv;
+ }
+
+ public double getPoissonPValue(BigDecimal[] distr, int k, double l){
+ if(k <= l){
+ return distr[k].doubleValue();
+ }
+ else{
+ return 1-(distr[k]).doubleValue();
+ }
+ }
+
+ public BigDecimal[] getCumulativePoisson(int maxk, double l){
+ BigDecimal bdel = new BigDecimal(Math.exp(l));
+ BigDecimal bdl = new BigDecimal(l);
+
+ BigDecimal[] numerator = new BigDecimal[maxk+1];
+ numerator[0] = new BigDecimal(1);
+
+ BigDecimal[] denominator = new BigDecimal[maxk+1];
+ denominator[0] = new BigDecimal(1);
+
+
+ BigDecimal[] rv = new BigDecimal[maxk+1];
+ rv[0] = numerator[0].divide(bdel,10,RoundingMode.FLOOR);
+ for(int k = 1; k <= maxk; k++){
+ numerator[k] = numerator[k-1].multiply(bdl);
+ denominator[k] = denominator[k-1].multiply(new BigDecimal(k));
+ rv[k] = rv[k-1].add(numerator[k].divide(denominator[k].multiply(bdel),10,RoundingMode.FLOOR));
+ }
+ return rv;
+ }
+
+
+}
diff --git a/src/edu/uconn/tripoint/integration/Proximal.java b/src/edu/uconn/tripoint/integration/Proximal.java
new file mode 100644
index 0000000..c3f56c5
--- /dev/null
+++ b/src/edu/uconn/tripoint/integration/Proximal.java
@@ -0,0 +1,68 @@
+package edu.uconn.tripoint.integration;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import quin.network.Location;
+import edu.uconn.tripoint.pathway.Gene;
+
+public class Proximal implements NonCodingTargets {
+
+ private Map _locations;
+ private int _distance;
+
+ public Proximal(String locations, int distance){
+ try {
+ _locations = readLocations(locations);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ _distance = distance;
+ }
+
+ private Map readLocations(String file) throws IOException{
+ Util u = new Util();
+ Location[] l = u.readLocations(file);
+ quin.network.Util u2 = new quin.network.Util();
+ return u2.getChrStartSorted(l);
+ }
+
+ public void setDistance(int distance){
+ _distance = distance;
+ }
+
+ @Override
+ public Map> getNoncodingTargets(Collection genes, Map> genecoords){
+ Util u = new Util();
+ quin.network.Util u2 = new quin.network.Util();
+ Location[] allgenelocations = u.getAllLocations(genecoords);
+ TreeMap sortedgeneloci = u2.getChrStartSorted(allgenelocations);
+
+ Map> rv = new TreeMap>();
+
+ for(Iterator it = genes.iterator(); it.hasNext();){
+ Gene next = it.next();
+ Map mappedlocations = new TreeMap();
+ for(Iterator it2 = genecoords.get(next).iterator(); it2.hasNext();){
+ Location nextlocation = it2.next();
+ Location paddedlocation = new Location(nextlocation.getIntegerId(), nextlocation.getChr(), nextlocation.getStart()-_distance, nextlocation.getEnd()+_distance);
+ Location[] chrloci = _locations.get(nextlocation.getChr());
+ Location[] oloci = u.getOverlappingLoci(chrloci, paddedlocation);
+ for(int i = 0; i < oloci.length; i++){
+ Location curloci = oloci[i];
+ if(u.getOverlappingLoci(sortedgeneloci.get(curloci.getChr()), curloci).length == 0){
+ mappedlocations.put(curloci.getChr()+":"+curloci.getStart()+"-"+curloci.getEnd(), curloci);
+ }
+ }
+ }
+ rv.put(next, new LinkedList(mappedlocations.values()));
+ }
+
+ return rv;
+ }
+}
diff --git a/src/edu/uconn/tripoint/integration/Util.java b/src/edu/uconn/tripoint/integration/Util.java
new file mode 100644
index 0000000..029909d
--- /dev/null
+++ b/src/edu/uconn/tripoint/integration/Util.java
@@ -0,0 +1,161 @@
+package edu.uconn.tripoint.integration;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import edu.uconn.tripoint.pathway.Gene;
+import quin.network.Location;
+
+public class Util {
+
+ public Location[] readLocations(String file) throws IOException{
+ LinkedList l = new LinkedList();
+ BufferedReader br = new BufferedReader(new FileReader(file));
+ int id = 0;
+ while(br.ready()){
+ String line = br.readLine();
+ String[] split = line.split("\t");
+ if(split.length >= 3){
+ try {
+ l.add(new Location(id++, split[0], Integer.parseInt(split[1]), Integer.parseInt(split[2])));
+ }
+ catch(NumberFormatException e){ }
+ }
+ }
+ br.close();
+ return l.toArray(new Location[0]);
+ }
+
+ /**
+ * Reads gene coordinates from a refflat file which can be obtained from
+ * UCSC.
+ * @param refflat The path to the refflat file
+ * @return A mapping from Gene to Location.
+ * @throws IOException
+ */
+ public Map> readRefflatGeneCoords(String refflat, int up, int down) throws IOException{
+ Map> rv = new TreeMap>();
+
+ BufferedReader br = new BufferedReader(new FileReader(refflat));
+ int id = 0;
+ while(br.ready()){
+ try{
+ String line = br.readLine();
+ String[] split = line.split("\t");
+ String gene = split[0];
+ String chr = split[2];
+ String strand = split[3];
+ int start = Integer.parseInt(split[4]);
+ int end = Integer.parseInt(split[5]);
+ Gene g = new Gene(gene);
+ if(!rv.containsKey(g)){
+ rv.put(g, new LinkedList());
+ }
+ if(strand.equals("-")){
+ rv.get(g).add(new Location(id++, chr, end-down, end+up));
+ }
+ else{
+ rv.get(g).add(new Location(id++, chr, start-up, start+down));
+ }
+ }
+ catch(NumberFormatException e){
+
+ }
+
+ }
+ br.close();
+ return rv;
+ }
+
+ public Location[] getAllLocations(Map> m){
+ Map all = new TreeMap();
+ for(Iterator> it = m.values().iterator(); it.hasNext();){
+ for(Iterator it2 = it.next().iterator(); it2.hasNext();){
+ Location next = it2.next();
+ all.put(next.getChr()+":"+next.getStart()+"-"+next.getEnd(), next);
+ }
+ }
+ return all.values().toArray(new Location[0]);
+ }
+
+ /**
+ *
+ * @param loci A start sorted array of loci.
+ * @param l
+ * @return
+ */
+ public Location[] getOverlappingLoci(Location[] loci, Location l){
+ int fi = findFirstIndex(loci, l);
+ int s = l.getStart();
+ int e = l.getEnd();
+ if(fi != -1){
+ LinkedList rv = new LinkedList();
+ for(int i = fi; i < loci.length; i++){
+ if(isIn(loci[i], s, e)){
+ rv.add(loci[i]);
+ }
+ }
+ return rv.toArray(new Location[0]);
+ }
+ else{
+ return new Location[0];
+ }
+ }
+
+ private boolean isIn(Location l, int start, int end){
+ return l.getEnd() >= start && end >= l.getStart();
+ }
+
+ private int findFirstIndex(Location[] loci, Location l){
+ int start = l.getStart();
+ int end = l.getEnd();
+
+ //Binary search to get an approximate index
+ int s = 0;
+ int e = loci.length-1;
+ while((e-s) > 1){
+ int mi = s+((e-s)/2);
+ Location ml = loci[mi];
+ int mstart = ml.getStart();
+ if(mstart < start){
+ s = mi;
+ }
+ else if(mstart > start){
+ e = mi;
+ }
+ else{
+ s = mi;
+ e = mi;
+ break;
+ }
+ }
+
+ //Loop to make sure we have the location just before the start position goes beyond
+ for(int i = s+1; i < loci.length; i++){
+ if(loci[i].getStart() > start){
+ s = i-1;
+ break;
+ }
+ }
+
+ //Choose position just before or just after depending on the overlap.
+ //If neither of them do return -1
+ int n = s+1;
+ if(s < loci.length && loci[s].getEnd() > start){ //0base
+ return s;
+ }
+ else if(n < loci.length && loci[n].getStart() <= end && loci[n].getEnd() > start){ //0base
+ return n;
+ }
+ else {
+ return -1;
+ }
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/pathway/Gene.java b/src/edu/uconn/tripoint/pathway/Gene.java
new file mode 100644
index 0000000..a82af67
--- /dev/null
+++ b/src/edu/uconn/tripoint/pathway/Gene.java
@@ -0,0 +1,86 @@
+package edu.uconn.tripoint.pathway;
+
+import java.util.Comparator;
+
+/**
+ *
+ * Gene/protein related data to store in the nodes of graph/network representations of pathways.
+ *
+ */
+public class Gene implements Comparator, Comparable{
+
+ private String _id;
+ private double _value;
+ /**
+ * Creates a new Gene instance.
+ * @param id The Gene identifier (i.e. Gene Symbol).
+ */
+ public Gene(String id){
+ _id = id;
+ _value = 0;
+ }
+
+ /**
+ * Creates a new Gene instance with a given value/score.
+ * @param id The Gene identifier (i.e. Gene Symbol).
+ * @param value The numeric value/score (i.e. Expression/Log2 Fold change) of this gene.
+ */
+ public Gene(String id, double value){
+ _id = id;
+ _value = value;
+ }
+
+ /**
+ * Gets the identifier for this gene.
+ * @return The string identifier for this gene.
+ */
+ public String getId(){
+ return _id;
+ }
+
+ /**
+ * Gets the value/score of this gene.
+ * @return The value/score for this gene.
+ */
+ public double getValue(){
+ return _value;
+ }
+
+ /**
+ * Sets the value/score of this gene.
+ * @param v The numeric value/score (i.e. Expression/Differential Expression) of this gene.
+ */
+ public void setValue(double v){
+ _value = v;
+ }
+
+ @Override
+ public int compare(Gene g1, Gene g2) {
+ int compareto = g1.compareTo(g2);
+ if(compareto < 0){
+ return -1;
+ }
+ else if(compareto > 0){
+ return 1;
+ }
+ else{
+ return 0;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o){
+ if(o instanceof Gene){
+ return getId().equals(((Gene) o).getId());
+ }
+ else{
+ return false;
+ }
+ }
+
+ @Override
+ public int compareTo(Gene o) {
+ return getId().compareTo(o.getId());
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/pathway/Pathway.java b/src/edu/uconn/tripoint/pathway/Pathway.java
new file mode 100644
index 0000000..89b9d23
--- /dev/null
+++ b/src/edu/uconn/tripoint/pathway/Pathway.java
@@ -0,0 +1,205 @@
+package edu.uconn.tripoint.pathway;
+
+import edu.uconn.tripoint.graph.Edge;
+import edu.uconn.tripoint.graph.Node;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ *
+ * This Pathway object facilitates the construction of a graph/network for a pathway to perform
+ * pathway enrichment based on topology.
+ *
+ */
+public class Pathway {
+
+ private String _id;
+ private Map> _nodes;
+ private TreeMap _edgetypekey;
+ private TreeMap> _edgekey;
+
+ /**
+ * Creates a new pathway object with an associated identifier (i.e. The pathway name.
+ * @param id The identifier associated with this pathway.
+ */
+ public Pathway(String id){
+ _id = id;
+ _nodes = new TreeMap>();
+ _edgekey = new TreeMap>();
+ _edgetypekey = new TreeMap();
+ }
+
+ /**
+ * Gets the identifier for this pathway.
+ * @return The identifier for this pathway.
+ */
+ public String getId(){
+ return _id;
+ }
+
+ /**
+ * Adds a gene to this pathway, creating a node in the underlying graph/network.
+ * If a gene object with the same identifier as one previously added is provided,
+ * the gene is NOT added to avoid duplicate entries. A gene list should be kept
+ * by the caller of this method so that expression values can be changed easily
+ * WITHOUT recreating the graph/network.
+ * @param g The Gene to add to the pathway.
+ */
+ public void addGene(Gene g) {
+ if(!_nodes.containsKey(g)){
+ Node newnode = new Node(g);
+ _nodes.put(g, newnode);
+ }
+ }
+
+ /**
+ * Gets the collection of nodes associated with this pathway.
+ * @return The collection of nodes associated with this pathway.
+ */
+ public Collection> getEdges(){
+ return _edgekey.values();
+ }
+
+ /**
+ * Gets the collection of nodes associated with this pathway.
+ * @return The collection of nodes associated with this pathway.
+ */
+ public Collection> getNodes(){
+ return _nodes.values();
+ }
+
+ /**
+ * Gets the node associated with the provided gene.
+ * @param g The gene object to identify the node to return.
+ * @return The node associated with the gene. NULL if no node is found.
+ */
+ public Node getNode(Gene g){
+ return _nodes.get(g);
+ }
+
+
+ /**
+ * Adds an edge in the pathway graph.
+ * @param g1 The first (source) gene to be associated.
+ * @param g2 The second (destination) gene to be associated.
+ * @param pe The type of edge. (activation, inhibition, association)
+ * @throws Exception An exception is thrown if the gene is not found in the pathway.
+ */
+ public void addEdge(Gene g1, Gene g2, PathwayEdge pe) throws Exception{
+ //TODO Should check if pathway is built where both directions for associations (undirected) are included
+ //Both genes must be in the pathway to add an edge.
+ if(_nodes.containsKey(g1) && _nodes.containsKey(g2)){
+ //Get the corresponding nodes.
+ Node n1 = _nodes.get(g1);
+ Node n2 = _nodes.get(g2);
+
+ EdgeKey edgeid = new EdgeKey(g1,g2);
+ EdgeKey cedgeid = new EdgeKey(g2,g1);
+ int curtype = pe.getType();
+ if(_edgetypekey.containsKey(edgeid)){
+ int prevtype = _edgetypekey.get(edgeid);
+ //Check for conflict cases
+ if((prevtype == PathwayEdge.ACTIVATION && curtype == PathwayEdge.INHIBITION)
+ || (curtype == PathwayEdge.ACTIVATION && prevtype == PathwayEdge.INHIBITION)){
+
+ System.out.println("Inconsistency in pathway. Removing:"+edgeid);
+ Edge e = _edgekey.get(edgeid);
+ e.getNode1().removeEdge(e);
+ e.getNode2().removeEdge(e);
+ _edgetypekey.put(edgeid, -2); //Set to -2 to prevent this type of edge from being added in the future
+ _edgekey.remove(edgeid);
+ }
+ else if(prevtype == PathwayEdge.ASSOCIATION && curtype != PathwayEdge.ASSOCIATION){ //update association edges to more informative activation/inhibition
+ System.out.println("Updating association in pathway:"+edgeid);
+ Edge e = _edgekey.get(edgeid);
+ e.getNode1().removeEdge(e);
+ e.getNode2().removeEdge(e);
+ _edgetypekey.put(edgeid, curtype);
+ _edgekey.remove(edgeid);
+ Edge newedge = new Edge(n1,n2,pe, true);
+ _edgekey.put(edgeid, newedge);
+ }
+ }
+ else if(_edgetypekey.containsKey(cedgeid)){
+ int prevtype = _edgetypekey.get(cedgeid);
+ if(prevtype == PathwayEdge.ASSOCIATION && curtype != PathwayEdge.ASSOCIATION){
+ System.out.println("Updating association in pathway:"+cedgeid);
+ Edge e = _edgekey.get(cedgeid);
+ e.getNode1().removeEdge(e);
+ e.getNode2().removeEdge(e);
+ _edgetypekey.remove(cedgeid);
+ _edgekey.remove(cedgeid);
+ Edge newedge = new Edge(n1,n2,pe, true);
+ _edgetypekey.put(edgeid, curtype);
+ _edgekey.put(edgeid, newedge);
+ }
+ }
+ else{
+ Edge newedge = new Edge(n1,n2,pe, curtype != PathwayEdge.ASSOCIATION);
+ n1.addEdge(newedge);
+ n2.addEdge(newedge);
+ _edgetypekey.put(edgeid, curtype);
+ _edgekey.put(edgeid, newedge);
+ }
+ }
+ else{
+ throw new Exception("Missing gene in pathway.");
+ }
+ }
+
+ private class EdgeKey implements Comparator, Comparable{
+
+ private Gene _src;
+ private Gene _dest;
+
+ public EdgeKey(Gene src, Gene dest){
+ _src = src;
+ _dest = dest;
+ }
+
+ @Override
+ public int compareTo(EdgeKey e) {
+ int srccompare = _src.compareTo(e._src);
+ if(srccompare == 0){
+ return _dest.compareTo(e._dest);
+ }
+ else{
+ return srccompare;
+ }
+ }
+
+ @Override
+ public int compare(EdgeKey o1, EdgeKey o2) {
+ int compareto = o1.compareTo(o2);
+ if(compareto < 0){
+ return -1;
+ }
+ else if(compareto > 0){
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o){
+ if(o instanceof EdgeKey){
+ EdgeKey ek = (EdgeKey)o;
+ return _src.equals(ek._src) && _dest.equals(ek._dest);
+ }
+ else{
+ return false;
+ }
+ }
+
+ @Override
+ public String toString(){
+ return _src.getId()+":"+_dest.getId();
+ }
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/pathway/PathwayEdge.java b/src/edu/uconn/tripoint/pathway/PathwayEdge.java
new file mode 100644
index 0000000..d382213
--- /dev/null
+++ b/src/edu/uconn/tripoint/pathway/PathwayEdge.java
@@ -0,0 +1,91 @@
+package edu.uconn.tripoint.pathway;
+
+/**
+ *
+ * The PathwayEdge type for use with generics used in the graph Edge class.
+ *
+ */
+public class PathwayEdge {
+
+ /**
+ * Activation type. A directed edge.
+ */
+ public static int ACTIVATION = 1;
+ /**
+ * Association type. An undirected edge.
+ */
+ public static int ASSOCIATION = 0;
+ /**
+ * Inhibition type. A directed edge.
+ */
+ public static int INHIBITION = -1;
+
+ private static PathwayEdge ACTIVATIONEDGE = new PathwayEdge(ACTIVATION);
+ private static PathwayEdge ASSOCIATIONEDGE = new PathwayEdge(ASSOCIATION);
+ private static PathwayEdge INHIBITIONEDGE = new PathwayEdge(INHIBITION);
+
+ private int _type;
+
+ /**
+ * Use the static methods for creating the edge.
+ * @param type The type of edge.
+ */
+ private PathwayEdge(int type){
+ _type = type;
+ }
+
+
+ /**
+ * Gets the type of the pathway edge.
+ * @return The type of the pathway edge.
+ */
+ public int getType(){
+ return _type;
+ }
+
+
+ /**
+ * Get the activation pathway edge.
+ * @return The instance of the activation pathway edge.
+ */
+ public static PathwayEdge ACTIVATION(){
+ return ACTIVATIONEDGE;
+ }
+
+ /**
+ * Get the inhibition pathway edge.
+ * @return The instance of the inhibition pathway edge.
+ */
+ public static PathwayEdge INHIBITION(){
+ return INHIBITIONEDGE;
+ }
+
+ /**
+ * Get the association pathway edge.
+ * @return The instance of the association pathway edge.
+ */
+ public static PathwayEdge ASSOCIATION(){
+ return ASSOCIATIONEDGE;
+ }
+
+ /**
+ * Helper method for obtaining the pathway edge for a provided type.
+ * @param type The type of PathwayEdge to return.
+ * @return The instance of the PathwayEdge with the input type.
+ * If the integer does not match any of the types provided in this class NULL is returned.
+ */
+ public static PathwayEdge getPathwayEdge(int type){
+ if(type == ACTIVATION){
+ return ACTIVATION();
+ }
+ else if(type == INHIBITION){
+ return INHIBITION();
+ }
+ else if(type == ASSOCIATION){
+ return ASSOCIATION();
+ }
+ else{
+ return null;
+ }
+ }
+}
diff --git a/src/edu/uconn/tripoint/pathway/PathwayHelper.java b/src/edu/uconn/tripoint/pathway/PathwayHelper.java
new file mode 100644
index 0000000..bb825bd
--- /dev/null
+++ b/src/edu/uconn/tripoint/pathway/PathwayHelper.java
@@ -0,0 +1,78 @@
+package edu.uconn.tripoint.pathway;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import edu.uconn.tripoint.graph.Edge;
+import edu.uconn.tripoint.graph.Node;
+
+public class PathwayHelper {
+
+
+ public List> getInconsistentInconsistencies(Node n, Set seen, double downthresh, double upthresh){
+ List> rv = new LinkedList>();
+ List> edges = getDownstreamEdges(n);
+ Set seen2 = new TreeSet();
+ for(Iterator> it = edges.iterator(); it.hasNext();){
+ Edge next = it.next();
+ Node dest = getDestination(n, next);
+ if(!isConsistent(next,n,dest,downthresh,upthresh) && !seen.contains(dest.getData()) && !seen2.contains(dest.getData())){
+ seen2.add(dest.getData());
+ rv.add(dest);
+ }
+ }
+ return rv;
+ }
+
+ public boolean isConsistent(Edge edge, Node src, Node dest, double downthresh, double upthresh){
+ int type = edge.getData().getType();
+ double sv = src.getData().getValue();
+ double dv = dest.getData().getValue();
+ if(type == PathwayEdge.ACTIVATION){
+ if(sv > upthresh && dv > upthresh){
+ return true;
+ }
+ else if(sv < downthresh && dv < downthresh){
+ return true;
+ }
+ }
+ else if(type == PathwayEdge.INHIBITION){
+ if(sv > upthresh && dv < downthresh){
+ return true;
+ }
+ else if(sv < downthresh && dv > upthresh){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public Node getDestination(Node n, Edge e){
+ if(e.isDirected()){
+ return e.getDestination();
+ }
+ else{
+ if(e.getNode1().equals(n)){
+ return e.getNode2();
+ }
+ else{
+ return e.getNode1();
+ }
+ }
+ }
+
+ public List> getDownstreamEdges(Node node){
+ List> rv = new LinkedList>();
+ for(Iterator> it = node.getEdges().iterator(); it.hasNext();){
+ Edge next = it.next();
+ if(!next.isDirected() || next.getSource().equals(node)){
+ rv.add(next);
+ }
+ }
+ return rv;
+ }
+}
diff --git a/src/edu/uconn/tripoint/pathwayimport/GraphiteImport.java b/src/edu/uconn/tripoint/pathwayimport/GraphiteImport.java
new file mode 100644
index 0000000..45cb44a
--- /dev/null
+++ b/src/edu/uconn/tripoint/pathwayimport/GraphiteImport.java
@@ -0,0 +1,174 @@
+package edu.uconn.tripoint.pathwayimport;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.rosuda.REngine.REXPMismatchException;
+import org.rosuda.REngine.REngineException;
+import org.rosuda.REngine.Rserve.RConnection;
+import org.rosuda.REngine.Rserve.RserveException;
+
+import edu.uconn.tripoint.pathway.Gene;
+import edu.uconn.tripoint.pathway.Pathway;
+import edu.uconn.tripoint.pathway.PathwayEdge;
+
+/**
+ * Imports pathways from the Graphite R package using RServe.
+ *
+ */
+public class GraphiteImport {
+
+ //All pathways merged into one.
+ private Pathway _globalpathway;
+ //Each individual pathway for each pathway in the library
+ private Pathway[] _pathways;
+ //All genes in the pathways. Used to update values after import.
+ private Map _genes;
+
+ /**
+ * Imports a set of pathways from the Graphite R package.
+ * Requires RServe to be running in R.
+ * @param pathwaylibrary
+ * The name of the graphite pathway library
+ * to use ("kegg", "reactome", "biocarta", "humancyc", "nci", "panther")
+ */
+ public GraphiteImport(String pathwaylibrary, String gid){
+ Map edgetypemapping = getEdgeTypeMapping();
+ startRServe();
+ RConnection c;
+ System.out.println("Starting import.");
+ try {
+ //Creates an R Connection and loads the pathways in R.
+ c = new RConnection();
+ c.parseAndEval("library(graphite)");
+ c.parseAndEval("plib <- pathways(\"hsapiens\", \""+pathwaylibrary+"\")");
+ c.parseAndEval("cpathwaylist <- convertIdentifiers(plib, \""+gid+"\")");
+ int numpathways = c.parseAndEval("length(cpathwaylist)").asInteger();
+
+ //Set the global variables
+ _pathways = new Pathway[numpathways];
+ _globalpathway = new Pathway("All "+pathwaylibrary);
+ _genes = new TreeMap();
+
+ System.out.println("Creating graphs.");
+ //Import each pathway
+ for(int i = 0; i < numpathways; i++){
+ int rindex = (i+1);
+ String pathwayname = c.parseAndEval("names(cpathwaylist)["+rindex+"]").asString();
+ c.parseAndEval("curpath = cpathwaylist[["+rindex+"]]");
+ c.parseAndEval("ed <- edges(curpath)");
+ String[] sources = c.parseAndEval("ed[,2]").asStrings();
+ String[] destinations = c.parseAndEval("ed[,4]").asStrings();
+ String[] edgetype = c.parseAndEval("ed[,6]").asStrings();
+
+ System.out.println("Loading "+pathwayname);
+ Pathway p = new Pathway(pathwaylibrary+":"+pathwayname);
+ _pathways[i] = p;
+
+ //Add genes/nodes to the graph/network
+ for(int j = 0; j < sources.length; j++){
+ if(!_genes.containsKey(sources[j])){
+ _genes.put(sources[j], new Gene(sources[j]));
+ }
+ Gene g = _genes.get(sources[j]);
+ p.addGene(g);
+ _globalpathway.addGene(g);
+ }
+ for(int j = 0; j < destinations.length; j++){
+ if(!_genes.containsKey(destinations[j])){
+ _genes.put(destinations[j], new Gene(destinations[j]));
+ }
+ Gene g = _genes.get(destinations[j]);
+ p.addGene(g);
+ _globalpathway.addGene(g);
+ }
+
+ //Add the edges
+ for(int j = 0; j < edgetype.length; j++){
+ PathwayEdge pe = edgetypemapping.get(edgetype[j]);
+ if(pe != null){
+ Gene g1 = _genes.get(sources[j]);
+ Gene g2 = _genes.get(destinations[j]);
+ try {
+ p.addEdge(g1, g2, pe);
+ _globalpathway.addEdge(g1,g2,pe);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ c.close();
+
+ } catch (RserveException e) {
+ e.printStackTrace();
+ } catch (REXPMismatchException e) {
+ e.printStackTrace();
+ } catch (REngineException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ //Contains the mapping of edge types from Graphite to Activation, Inhibition, and Association
+ private Map getEdgeTypeMapping(){
+ Map rv = new TreeMap();
+ rv.put("Binding", PathwayEdge.ASSOCIATION());
+ rv.put("Control(In: ACTIVATION of BiochemicalReaction)", PathwayEdge.ACTIVATION());
+ rv.put("Control(In: ACTIVATION of ComplexAssembly)", PathwayEdge.ACTIVATION());
+ rv.put("Control(In: ACTIVATION of Degradation)", PathwayEdge.ACTIVATION());
+ rv.put("Control(In: ACTIVATION of Transport)", PathwayEdge.ACTIVATION());
+ rv.put("Control(indirect)", null);
+ rv.put("Control(In: INHIBITION-COMPETITIVE of BiochemicalReaction)", PathwayEdge.INHIBITION());
+ rv.put("Control(In: INHIBITION of BiochemicalReaction)", PathwayEdge.INHIBITION());
+ rv.put("Control(In: INHIBITION of ComplexAssembly)", PathwayEdge.INHIBITION());
+ rv.put("Control(In: INHIBITION of Transport)", PathwayEdge.INHIBITION());
+ rv.put("Control(Out: ACTIVATION of ACTIVATION)", PathwayEdge.ACTIVATION());
+ rv.put("Control(Out: ACTIVATION of BiochemicalReaction)", PathwayEdge.ACTIVATION());
+ rv.put("Control(Out: ACTIVATION of ComplexAssembly)", PathwayEdge.ACTIVATION());
+ rv.put("Control(Out: ACTIVATION of TemplateReaction)", PathwayEdge.ACTIVATION());
+ rv.put("Control(Out: ACTIVATION of Transport)", PathwayEdge.ACTIVATION());
+ rv.put("Control(Out: INHIBITION-COMPETITIVE of BiochemicalReaction)", PathwayEdge.INHIBITION());
+ rv.put("Control(Out: INHIBITION of ACTIVATION)", PathwayEdge.INHIBITION());
+ rv.put("Control(Out: INHIBITION of BiochemicalReaction)", PathwayEdge.INHIBITION());
+ rv.put("Control(Out: INHIBITION of ComplexAssembly)", PathwayEdge.INHIBITION());
+ rv.put("Control(Out: INHIBITION of TemplateReaction)", PathwayEdge.INHIBITION());
+ rv.put("Control(Out: INHIBITION of Transport)", PathwayEdge.INHIBITION());
+ rv.put("Process", PathwayEdge.ACTIVATION());
+ rv.put("Process(activation)", PathwayEdge.ACTIVATION());
+ rv.put("Process(binding/association)", PathwayEdge.ASSOCIATION());
+ rv.put("Process(BiochemicalReaction)", PathwayEdge.ACTIVATION());
+ rv.put("Process(demethylation)", PathwayEdge.ASSOCIATION());
+ rv.put("Process(dephosphorylation)", PathwayEdge.ASSOCIATION());
+ rv.put("Process(dissociation)", null);
+ rv.put("Process(expression)", PathwayEdge.ACTIVATION()); //Setting this to activation
+ rv.put("Process(glycosylation)", PathwayEdge.ASSOCIATION());
+ rv.put("Process(indirect)", null);
+ rv.put("Process(indirect effect)", null);
+ rv.put("Process(inhibition)", PathwayEdge.INHIBITION());
+ rv.put("Process(methylation)", PathwayEdge.ASSOCIATION());
+ rv.put("Process(missing)", null);
+ rv.put("Process(missing interaction)", null);
+ rv.put("Process(phosphorylation)", PathwayEdge.ASSOCIATION());
+ rv.put("Process(repression)", PathwayEdge.INHIBITION());
+ rv.put("Process(state change)", PathwayEdge.ASSOCIATION());
+ return rv;
+ }
+
+ public Pathway getGlobalPathway(){
+ return _globalpathway;
+ }
+
+ public Pathway[] getPathways(){
+ return _pathways;
+ }
+
+ public Map getGenes(){
+ return _genes;
+ }
+
+ private void startRServe(){
+ //TODO start RServe within this application
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/triangulation/FDRCorrection.java b/src/edu/uconn/tripoint/triangulation/FDRCorrection.java
new file mode 100644
index 0000000..c6caae6
--- /dev/null
+++ b/src/edu/uconn/tripoint/triangulation/FDRCorrection.java
@@ -0,0 +1,17 @@
+package edu.uconn.tripoint.triangulation;
+
+import org.rosuda.REngine.REXPMismatchException;
+import org.rosuda.REngine.REngineException;
+import org.rosuda.REngine.Rserve.RConnection;
+
+public class FDRCorrection {
+
+ public double[] getCorrectedPValues(double[] pvals) throws REngineException, REXPMismatchException{
+ RConnection con = new RConnection();
+ con.assign("pvals", pvals);
+ double[] rv = con.parseAndEval("p.adjust(pvals, \"fdr\")").asDoubles();
+ con.close();
+ return rv;
+ }
+
+}
diff --git a/src/edu/uconn/tripoint/triangulation/ProgramParameters.java b/src/edu/uconn/tripoint/triangulation/ProgramParameters.java
new file mode 100644
index 0000000..6f3bb2a
--- /dev/null
+++ b/src/edu/uconn/tripoint/triangulation/ProgramParameters.java
@@ -0,0 +1,234 @@
+package edu.uconn.tripoint.triangulation;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class ProgramParameters {
+
+ public final double VERSION = 1.0;
+ //required
+ private String _expfile;
+ private String _db;
+ private String _outdir;
+
+ //defaults
+ private double _down;
+ private double _up;
+ private double _w;
+ private double _p1;
+ private double _p2;
+ private double _r;
+ private String _gid;
+ private int _perm;
+ private long _rstate;
+
+ //optional
+ private String _refflat;
+ private String _chrinter;
+ private String _nct;
+ private int _prox = 50000;
+
+
+ public ProgramParameters(String[] args){
+ //set default values;
+ _down = -0.05;
+ _up = 0.05;
+ _w = 0.2;
+ _p1 = 0.25;
+ _p2 = 0.000001;
+ _r = 0.25;
+ _gid = "SYMBOL";
+ _perm = 1000;
+ _rstate = System.currentTimeMillis();
+
+ if(args.length > 0){
+ _expfile = args[0]; //First argument will always be the expression file
+ }
+
+ //TODO Probably better to just use a map and only set values
+ //if the key already exists
+ for(int i = 1; i < args.length-1; i += 2){
+ String cur = args[i];
+ String next = args[i+1];
+ if(cur.equals("-down")){
+ _down = Double.parseDouble(next);
+ }
+ else if(cur.equals("-up")){
+ _up = Double.parseDouble(next);
+ }
+ else if(cur.equals("-w")){
+ _w = Double.parseDouble(next);
+ }
+ else if(cur.equals("-p1")){
+ _p1 = Double.parseDouble(next);
+ }
+ else if(cur.equals("-p2")){
+ _p2 = Double.parseDouble(next);
+ }
+ else if(cur.equals("-r")){
+ _r = Double.parseDouble(next);
+ }
+ else if(cur.equals("-gid")){
+ _gid = next;
+ }
+ else if(cur.equals("-perm")){
+ _perm = Integer.parseInt(next);
+ }
+ else if(cur.equals("-rstate")){
+ _rstate = Long.parseLong(next);
+ }
+ else if(cur.equals("-db")){
+ _db = next;
+ }
+ else if(cur.equals("-o")){
+ _outdir = next;
+ if(!_outdir.endsWith("/")){
+ _outdir = _outdir+"/";
+ }
+ }
+ else if(cur.equals("-ci")){
+ _chrinter = next;
+ }
+ else if(cur.equals("-nct")){
+ _nct = next;
+ }
+ else if(cur.equals("-refflat")){
+ _refflat = next;
+ }
+ else if(cur.equals("-prox")){
+ _prox = Integer.parseInt(next);
+ }
+
+ }
+
+ }
+
+ public String getExpressionFile(){
+ return _expfile;
+ }
+
+ public String getPathwayDB(){
+ return _db;
+ }
+
+ public String getOutputDirectory(){
+ return _outdir;
+ }
+
+ public double getDownThresh(){
+ return _down;
+ }
+
+ public double getUpThresh(){
+ return _up;
+ }
+
+ public double getW(){
+ return _w;
+ }
+
+ public double getP1(){
+ return _p1;
+ }
+
+ public double getP2(){
+ return _p2;
+ }
+
+ public double getR(){
+ return _r;
+ }
+
+
+ public String getGID(){
+ return _gid;
+ }
+
+ public String getRefflat(){
+ return _refflat;
+ }
+
+ public String getChrInter(){
+ return _chrinter;
+ }
+
+ public String getNonCodingTargets(){
+ return _nct;
+ }
+
+ public int getProximityDistance(){
+ return _prox;
+ }
+
+ public int getNumPermutations(){
+ return _perm;
+ }
+
+ public long getRandomState(){
+ return _rstate;
+ }
+
+ public boolean hasRequired(){
+ return _db != null && _outdir != null && (new File(_expfile)).exists() && (new File(_outdir)).isDirectory();
+ }
+
+ public boolean hasNonCoding(){
+ return _refflat != null && (_chrinter != null || _nct != null);
+ }
+
+ public String getConsoleManual(){
+ StringBuilder sb = new StringBuilder();
+ sb.append("Version: "+VERSION+"\n");
+ sb.append("Usage\t\t\tjava -jar tripoint.jar -db -o