Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 39 additions & 65 deletions RINCreator/src/cytargetlinker/conversion/Microcosm.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void main(String argv[]) throws Exception {
private int countGenes = 0;
private int countMiRNAs = 0;

private Map<String, MiRNANode> miRNAs;
private Map<String, Node> miRNAs;
private Map<String, GeneNode> genes;
private Map<String, MTI> interactions;

Expand All @@ -93,7 +93,7 @@ public Microcosm() throws Exception {
foundConnections = new ArrayList<String>();
genesNotFound = new ArrayList<String>();

miRNAs = new HashMap<String, MiRNANode>();
miRNAs = new HashMap<String, Node>();
genes = new HashMap<String, GeneNode>();
interactions = new HashMap<String, MTI>();
nodesNotFound = new ArrayList<String>();
Expand Down Expand Up @@ -199,9 +199,28 @@ private void parseMicrocosm(File in) {
}

private void addEdge(String gene, String mirna, String score, String pValue) {
if(edges.containsKey(gene)) {
if(!edges.get(gene).contains(mirna)) {
Edge e = graph.addEdge("" + countEdge, graph.getNode(mirna),graph.getNode(gene));
if(miRNAs.containsKey(mirna)) {
if(edges.containsKey(gene)) {
if(!edges.get(gene).contains(mirna)) {
Edge e = graph.addEdge("" + countEdge, miRNAs.get(mirna),graph.getNode(gene));
e.setAttribute("datasource", "Microcosm Targets version 5");
e.setAttribute("interactionType", "predicted MTI");
try {
Double d = Double.parseDouble(score);
e.setAttribute("score", d.toString());
Double pvalue = Double.parseDouble(pValue);
e.setAttribute("pvalue", pvalue.toString());
} catch(NumberFormatException ex) {
e.setAttribute("score", "");
e.setAttribute("pvalue", "");
}

edges.get(gene).add(mirna);
foundConnections.add(gene + "\t" + mirna);
countEdge++;
}
} else {
Edge e = graph.addEdge("" + countEdge, miRNAs.get(mirna),graph.getNode(gene));
e.setAttribute("datasource", "Microcosm Targets version 5");
e.setAttribute("interactionType", "predicted MTI");
try {
Expand All @@ -211,31 +230,16 @@ private void addEdge(String gene, String mirna, String score, String pValue) {
e.setAttribute("pvalue", pvalue.toString());
} catch(NumberFormatException ex) {
e.setAttribute("score", "");
e.setAttribute("pvalue", "");
e.setAttribute("pvalue", "");
}

edges.get(gene).add(mirna);
List<String> list = new ArrayList<String>();
list.add(mirna);
foundConnections.add(gene + "\t" + mirna);
edges.put(gene, list);
countEdge++;
}
} else {
Edge e = graph.addEdge("" + countEdge, graph.getNode(mirna),graph.getNode(gene));
e.setAttribute("datasource", "Microcosm Targets version 5");
e.setAttribute("interactionType", "predicted MTI");
try {
Double d = Double.parseDouble(score);
e.setAttribute("score", d.toString());
Double pvalue = Double.parseDouble(pValue);
e.setAttribute("pvalue", pvalue.toString());
} catch(NumberFormatException ex) {
e.setAttribute("score", "");
e.setAttribute("pvalue", "");
}
List<String> list = new ArrayList<String>();
list.add(mirna);
foundConnections.add(gene + "\t" + mirna);
edges.put(gene, list);
countEdge++;
log.warning("Edge " + gene + " -- " + mirna + " excluded, because miRNA couldn't be mapped.");
}
}

Expand Down Expand Up @@ -326,49 +330,19 @@ private void createGeneNode(String geneId, String geneName) {
}

private void createMiRNANode(String miRNA) {
String type = "microRNA";
String organism = pargs.getOrganism();

if(graph.getNode(miRNA) == null) {
String mimat = "";
String identifiers = "[" + miRNA;
Xref xrefIn = new Xref(miRNA, DataSource.getBySystemCode("Mb"));

if(mapping) {
try {
Set<Xref> result = gdb.mapID(xrefIn, DataSource.getBySystemCode("Mb"));
Set<Xref> result2 = gdb.mapID(xrefIn, DataSource.getBySystemCode("Mbm"));

List<String> list = new ArrayList<String>();
list.add(miRNA);
for(Xref x : result) {
if(!list.contains(x.getId())) {
list.add(x.getId());
identifiers = identifiers + "," + x.getId();
}
}
for(Xref x : result2) {
if(!list.contains(x.getId())) {
list.add(x.getId());
if(x.getId().startsWith("MIMAT")) {
mimat = x.getId();
}
identifiers = identifiers + "," + x.getId();
}
}
} catch (IDMapperException e) {
// could not be mapped
}
if(!miRNAs.containsKey(miRNA)) {
MiRNANode mirnaNode = MiRNANode.createMiRNANode(miRNA, gdb, DataSource.getBySystemCode("Mb"));
if(mirnaNode != null) {
Node node = mirnaNode.getNode(graph);
node.appendAttribute("miRBaseAccession", mirnaNode.getId());
node.appendAttribute("organism", organism);
countMiRNAs++;
miRNAs.put(miRNA, node);
} else {
log.warning("miRNA node for " + miRNA + " not found! Skipping this miRNA.");
}
identifiers = identifiers + "]";

Node node = graph.addNode(miRNA);
node.appendAttribute("identifiers", identifiers);
node.appendAttribute("label", miRNA);
node.appendAttribute("miRBaseAccession", mimat);
node.appendAttribute("biologicalType", type);
node.appendAttribute("organism", organism);
countMiRNAs++;
}
}

Expand Down
59 changes: 14 additions & 45 deletions RINCreator/src/cytargetlinker/conversion/MirTarBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import org.bridgedb.IDMapperStack;
import org.bridgedb.Xref;

import cytargetlinker.conversion.data.MiRNANode;
import cytargetlinker.conversion.graph.Graph;
import cytargetlinker.conversion.graph.Graph.Edge;
import cytargetlinker.conversion.graph.Graph.Node;
import cytargetlinker.conversion.utils.ArgsParser;
import cytargetlinker.conversion.utils.CommonAttributes;
import cytargetlinker.conversion.utils.Utils;
import cytargetlinker.conversion.utils.ArgsParser.AFilesAttributes;
import cytargetlinker.conversion.utils.ArgsParser.AFilesIn;
import cytargetlinker.conversion.utils.ArgsParser.AFilesOut;
import cytargetlinker.conversion.utils.ArgsParser.AHelp;
import cytargetlinker.conversion.utils.ArgsParser.GraphBuilder;
import cytargetlinker.conversion.utils.CommonAttributes;
import cytargetlinker.conversion.utils.Utils;

/**
* Converts miRNA target text files from MiRTarBase to a XGMML or GML network.
Expand Down Expand Up @@ -134,7 +135,7 @@ public Graph createNetwork(File input) throws IOException {
for (String[] r : rows) {
String geneNode = createGeneNode(r);
String miRNANode = createMiRNANode(r);
addEdge(geneNode, miRNANode, r);
if(geneNode != null && miRNANode != null) addEdge(geneNode, miRNANode, r);
}

log.info(foundConnections.size() + " interactions have been found.\n" + countGenes + " gene nodes.\n" + countMiRNAs + " miRNA nodes.\n");
Expand Down Expand Up @@ -184,52 +185,20 @@ private String createGeneNode(String[] r) {

private String createMiRNANode(String[] r) {
String miRNA = r[index.get("miRNA")];
String type = "microRNA";
String organism = r[index.get("Species (miRNA)")];

if(graph.getNode(miRNA) == null) {
String mimat = "";
String identifiers = "[" + miRNA;
Xref xrefIn = new Xref(miRNA, DataSource.getBySystemCode("Mb"));

if(mapping) {
try {
Set<Xref> result = gdb.mapID(xrefIn, DataSource.getBySystemCode("Mb"));
Set<Xref> result2 = gdb.mapID(xrefIn, DataSource.getBySystemCode("Mbm"));

List<String> list = new ArrayList<String>();
list.add(miRNA);
for(Xref x : result) {
if(!list.contains(x.getId())) {
list.add(x.getId());
identifiers = identifiers + "," + x.getId();
}
}
for(Xref x : result2) {
if(!list.contains(x.getId())) {
list.add(x.getId());
if(x.getId().startsWith("MIMAT")) {
mimat = x.getId();
}
identifiers = identifiers + "," + x.getId();
}
}
} catch (IDMapperException e) {
// could not be mapped
}
}
identifiers = identifiers + "]";

Node node = graph.addNode(miRNA);
node.appendAttribute("identifiers", identifiers);
node.appendAttribute("label", miRNA);
node.appendAttribute("miRBaseAccession", mimat);
node.appendAttribute("biologicalType", type);

MiRNANode mirnaNode = MiRNANode.createMiRNANode(miRNA, gdb, DataSource.getBySystemCode("Mb"));
if(mirnaNode != null) {
Node node = mirnaNode.getNode(graph);
node.appendAttribute("miRBaseAccession", mirnaNode.getId());
node.appendAttribute("organism", organism);
countMiRNAs++;
countMiRNAs++;
return mirnaNode.getId();
} else {
log.warning("miRNA node for " + miRNA + " not found! Skipping this miRNA.");
return null;
}

return miRNA;
}

private void addEdge(String gene, String mirna, String[] r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Node getNode(Graph graph) {
node.appendAttribute("label", getLabel());
node.appendAttribute("name", getLabel());
node.appendAttribute("biologicalType", getBiologicalType());
if(entrez.size() > 0) node.appendAttribute("entrezGeneID", entrez.get(0));
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void write(Graph graph, PrintWriter out) {
int indent = 0;

iout.println("graph [");
iout.println("directed\t" + (graph.isDirected() ? 1 : 0));
iout.setIndent(++indent);

//Print nodes and attributes
Expand Down
9 changes: 9 additions & 0 deletions RINCreator/src/cytargetlinker/conversion/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
public class Graph extends AttributeHolder {
String title = "";
boolean directed = false;

Map<String, Node> nodes = new HashMap<String, Node>();
Map<String, Edge> edges = new HashMap<String, Edge>();
Expand All @@ -23,6 +24,14 @@ public String getTitle() {
return title;
}

public boolean isDirected() {
return directed;
}

public void setDirected(boolean directed) {
this.directed = directed;
}

public Node addNode(String id) {
Node n = nodes.get(id);
if(n == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public static void convertAndWrite(AFilesIn fi, AFilesOut fo, GraphBuilder gb) t
log.info("Converting " + input + " to " + output + "\n");

Graph g = gb.buildGraph(input);
g.setDirected(true);

GraphWriter writer = new XGMML();
if(output.getName().endsWith(".gml")) {
Expand Down