cssFile <- system.file("extdata", "style.css", package="ccPaper")
options(markdown.HTML.stylesheet = cssFile)

RCy Pie Nodes

If we want to create pie nodes in RCy using custom graphics, what do we need to do, and how hard will it be?

library(RCytoscape)
g <- new ('graphNEL', edgemode='directed')
g <- graph::addNode ('A', g)
g <- graph::addNode ('B', g)
g <- graph::addNode ('C', g)
cw <- new.CytoscapeWindow ('vignette', graph=g)
displayGraph(cw)
layoutNetwork(cw, layout.name="grid")
redraw(cw)

OK, so we have now a little example graph to play with. How about we create some pie graphs and save them as png objects?

pieData <- list(
  A = list(
    area = c(0.5, 0.5),
    color = c("blue", "green")),
  B = list(
    area = c(0.2, 0.8),
    color = c("red", "yellow")),
  C = list(
    area = c(0.6, 0.4),
    color = c("green", "purple"))
  )

plotPie <- function(inData){
  names(inData$area) <- ""
  pie(inData$area, col=inData$color, clockwise=TRUE)
}

plotPie(pieData[["A"]])
plotPie(pieData[["B"]])
plotPie(pieData[["C"]])

Sweet, little pie graphs. Next up, saving the graphics and letting Cytoscape know about them.

saveDir <- file.path(getwd(), "vignettes/")

outFiles <- sapply(names(pieData), function(pieName){
  pieFile <- paste("pieFile_", pieName, ".png", sep="")
  outFile <- file.path(saveDir, pieFile)
  png(outFile, bg="transparent")
  plotPie(pieData[[pieName]])
  dev.off()
  return(outFile)
})
names(outFiles) <- NULL
outFiles2 <- paste("file://localhost/", outFiles, sep="")

Now to try and associate them with the nodes in Cytoscape

setNodeImageDirect(cw, names(pieData), outFiles2)
setDefaultNodeColor(cw, 'transparent')
setNodeOpacityDirect(cw, names(pieData), 0)
redraw(cw)

Finally, to use it in categoryCompare, I think we would always want the same number of slices for each node image, but use the saturated vs desaturated color to indicate significant vs not-significant, so the eye does not get fooled, and individuals can quickly scan to see which ones are which.

library(colorspace)
desaturatePercentage <- function(col, percentage=0.5){
  # this code is taken from the desaturate function in colorspace
  if (is.character(col) && (all(substr(col, 1L, 1L) == "#") & 
    all(nchar(col) %in% c(7L, 9L)))) {
    alpha <- substr(col, 8L, 9L)
    col <- substr(col, 1L, 7L)
    col <- hex2RGB(col)
    }
  else {
    col <- col2rgb(col, alpha = TRUE)
    alpha <- format(as.hexmode(col[4L, ]), width = 2L, upper.case = TRUE)
    alpha[alpha == "FF"] <- ""
    col <- RGB(t(col[1L:3L, ])/255)
  }
  col <- as(col, "polarLUV")
  col@coords[, 2L] <- col@coords[, 2L] * percentage
  col <- hex(col)
  return(col)
}

twoColors <- c("red", desaturatePercentage("red", 0.25))
pie(c(0.5, 0.5), col=twoColors)
library(categoryComparePaper)

ccOpts <- new("ccOptions", listNames=c("T10_UP", "T10_DN", "T48_UP", "T48_DN", "T1_X", "T1_Y"), colorType="pie")

nTerm <- 1000

pieMatrix <- do.call(cbind, lapply(listNames(ccOpts), function(inName){
    baseCol <- rep(ccOpts@unsaturatedColor[inName], nTerm)
    baseCol[sample(nTerm, 500)] <- compareColors(ccOpts)[inName]
    baseCol
  }))

pieArea <- rep(1 / length(listNames(ccOpts)), length(listNames(ccOpts)))
names(pieArea) <- ""


rmflight/ccPaper documentation built on May 27, 2019, 9:31 a.m.