customCnet2Cytoscape <- function(kgg, category=NULL, nPath=NULL, byDE=FALSE){
if(! "ggraph" %in% .packages()) require("ggraph")
if(! "igraph" %in% .packages()) require("igraph")
if(! "RCy3" %in% .packages()) require("RCy3")
if(! "dplyr" %in% .packages()) require("dplyr")
if(! "tidyr" %in% .packages()) require("tidyr")
## check if cytoscape is running
a <- tryCatch( expr= { cytoscapePing() },
error = function(e){print("Error!! Cytoscape must be running")}
)
## define palette
color_palette <- function(colors) colorRampPalette(colors)(n = 299)
if(byDE){
kgg <- kgg %>% arrange(-DE)
}
## check parameters
if(!is.null(category)){
if(is.numeric(category)){
tmp <- kgg[category, c(1,6)]
} else{
tmp <- kgg[kgg$Pathway %in% category, c(1,6)]
}
} else{
tmp <- kgg[,c(1,6)]
}
if(!is.null(nPath)){
if(is.numeric(nPath)){
tmp <- tmp[1:nPath, ]
} else{ stop("nPath must be numeric or NULL")}
}
# prepare data
tmp2 <- tmp %>% separate_rows( genes, convert=TRUE)
g <- igraph::graph.data.frame(tmp2, directed=FALSE)
size <- tmp2 %>% dplyr::select(Pathway) %>% group_by(Pathway) %>% summarise(n=n())
size <- left_join(tmp, size, by=c("Pathway"))
size <- size$n
V(g)$size <- min(size)/2
n <- dim(tmp)[1]
V(g)$size[1:n] <- size
V(g)$pval <- NA
V(g)$pval[1:n] <- kgg$P.DE[1:n]
edge_layer <- geom_edge_link(alpha=.8, colour='darkgrey')
fc <- V(g)$pval
V(g)$color <- fc
createNetworkFromIgraph(g, "customIgraph")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.