Commit 4a3031c5 authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

final namechange update

parent f4893fb3
......@@ -29,11 +29,11 @@ create_Pathway <- function(name, version = date(), organism = "Homo sapiens") {
}
### Create a GPML::DataNode object, with given label, id, type position and size
create_DataNode <- function(label, id, type, x, y, w, h,
create_DataNode <- function(label, id, type, x, y, w, h, color,
zorder = "32768", fontsize="12", valign="Middle") {
return(read_xml(paste0("<DataNode TextLabel='", label, "' GraphId='", id, "' Type='", type, "'>",
"<Graphics CenterX='", x, "' CenterY='", y, "' Width='", w,
"' Height='", h,"' ZOrder='", zorder,"' FontSize='", fontsize,"' Valign='", valign,"' />",
"' Height='", h,"' ZOrder='", zorder,"' FontSize='", fontsize,"' Valign='", valign,"' FillColor = '", color,"'/>",
"<Xref Database='' ID='' />",
"</DataNode>")))
}
......@@ -54,7 +54,7 @@ add_DataNode_to_Pathway <- function(gpml_pathway, gpml_node) {
}
### Add a GPML::Interaction to a GPML::Pathway, based on the ids of two GPML::DataNodes
add_Interaction_to_Pathway <- function(gpml_pathway, id_source, id_target) {
add_Interaction_to_Pathway <- function(gpml_pathway, id_source, id_target, color = "ffffff", thickness = "1.0") {
dn_src <- xml_find_first(gpml_pathway, paste0("//DataNode[@GraphId='", id_source, "']"))
dn_trg <- xml_find_first(gpml_pathway, paste0("//DataNode[@GraphId='", id_target, "']"))
### Identify anchor points
......@@ -65,7 +65,7 @@ add_Interaction_to_Pathway <- function(gpml_pathway, id_source, id_target) {
"' Y='", xml_attr(xml_child(dn_trg),"CenterY"),
"' GraphRef='", xml_attr(dn_trg,"GraphId"), "' RelX='-1.0' RelY='0.0' ArrowHead='Arrow'/>"))
gpml_gr <- read_xml("<Graphics ZOrder='12288' LineThickness='1.0'/>")
gpml_gr <- read_xml(paste0("<Graphics ZOrder='12288' LineThickness='", thickness,"' Color='", color,"'/>"))
xml_add_child(gpml_gr, gpml_ps)
xml_add_child(gpml_gr, gpml_pt)
......@@ -91,15 +91,17 @@ cys_nodedata <- function(cys_node_xgmml) {
nd_attrs <- xml_attrs(cys_node_xgmml)
gr_attrs <- xml_attrs(xml_find_first(cys_node_xgmml, "./xgmml:graphics", ns = ns_xgmml))
return(data.frame(id = nd_attrs["id"], label = nd_attrs["label"],
x = as.numeric(gr_attrs["x"]), y = as.numeric(gr_attrs["y"]),
w = as.numeric(gr_attrs["w"]), h = as.numeric(gr_attrs["h"]), fill = gr_attrs["fill"]))
type = xml_attrs(xml_find_first(cys_node_xgmml, "./xgmml:att[@name='mol_type']", ns = ns_xgmml))["value"],
x = as.numeric(gr_attrs["x"]), y = as.numeric(gr_attrs["y"]),
w = as.numeric(gr_attrs["w"]), h = as.numeric(gr_attrs["h"]), fill = gr_attrs["fill"]))
}
### Read edge information from the CytoScape XGMML file
cys_edgedata <- function(cys_edge_xgmml) {
eg_attrs <- xml_attrs(cys_edge_xgmml)
gr_attrs <- xml_attrs(xml_find_first(cys_edge_xgmml, "./xgmml:graphics", ns = ns_xgmml))
return(data.frame(id = eg_attrs["id"], label = eg_attrs["label"],
source = eg_attrs["source"], target = eg_attrs["target"]))
source = eg_attrs["source"], target = eg_attrs["target"], color = gr_attrs["fill"], thickness = gr_attrs["width"]))
}
### The main function to call, optionally generating an image of the created diagram
......@@ -117,9 +119,6 @@ xgmml_gpml <- function(xgmml_file, output,
### Correct for x,y negative values, add 100 margin
nodedata$x <- nodedata$x + abs(min(nodedata$x)) + 100
nodedata$y <- nodedata$y + abs(min(nodedata$y)) + 100
nodedata <- cbind(nodedata, type = "Pathway")
nodedata$type[grep("^[A-Z0-9]{3,}$",nodedata$label)] <- "Protein"
nodedata$type[grep("_[1-9]",nodedata$label)] <- "Metabolite"
edgedata <- do.call("rbind", lapply(xml_find_all(xgmml, "//xgmml:edge", ns = ns_xgmml), cys_edgedata))
### Purely numeric ids are a problem, adding a letter
......@@ -132,10 +131,12 @@ xgmml_gpml <- function(xgmml_file, output,
apply(nodedata, 1, function(x)
add_DataNode_to_Pathway(xgmml_P,
create_DataNode(label = x["label"], id = x["id"], type = x["type"],
x = x["x"], y = x["y"], w = x["w"], h = x["h"])))
x = x["x"], y = x["y"], w = x["w"], h = x["h"],
color = tolower(substr(x["fill"], 2, 7)))))
apply(edgedata, 1, function(x)
add_Interaction_to_Pathway(xgmml_P, x["source"], x["target"]))
add_Interaction_to_Pathway(xgmml_P, x["source"], x["target"],
color = tolower(substr(x["color"], 2, 7)), thickness = x["thickness"]))
write_Pathway(xgmml_P, filename = output)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment