Skip to content
Permalink
6340f8bf78
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
175 lines (155 sloc) 6.9 KB
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<String, Gene> _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<String, PathwayEdge> 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<String, Gene>();
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$src").asStrings();
String[] destinations = c.parseAndEval("ed$dest").asStrings();
String[] edgetype = c.parseAndEval("ed$type").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<String, PathwayEdge> getEdgeTypeMapping(){
Map<String, PathwayEdge> rv = new TreeMap<String, PathwayEdge>();
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<String, Gene> getGenes(){
return _genes;
}
private void startRServe(){
//TODO start RServe within this application
}
}