R/calcyt_heat.R

#' Cytoscape heatmaps
#'
#' Plot heatmaps of up to 9 conditions and unlimited replicates for each node of the network
#'
#' @param x experimental data as a dataframe, compounds in rows, samples in columns
#' @param y number of experimental conditions
#' @param z number of replicates per condition
#'
#' @return Cytoscape network with heatmaps for each node
#' @export
#'
#' @examples
#' x <- data_to_plot
#' y <- 4
#' z <- 3
#' calcyt_binary(x,y,z)
calcyt_heat <- function (x,y,z)
{
  #remove previous plots
  for (i in 1:9)
  {
    removeNodeCustomGraphics(
    slot = i,
    style.name = "default")
  }

  #change heatmap y-axis offset for 9 different conditions (Cytoscape allows 9 slots for plots on each node)
  for (i in 1:9)
  {
    property_name <- paste("NODE_CUSTOMGRAPHICS_POSITION","_",as.character(i),sep="")
    setVisualPropertyDefault(list(visualProperty = property_name, value = paste("C,C,c,0.00,",as.character((i-1)*8),sep="")))
  }

  #move node label to the north of the node
  setVisualPropertyDefault(list(visualProperty = "NODE_LABEL_POSITION", value = "N,C,c,0.00,-5"))

  #modify other visual properties
  setNodeFontSizeDefault(10, style.name = "default")
  setNodeFontFaceDefault("Arial,plain,10", style.name = "default")
  setNodeColorDefault("#FFFFFF", style.name = "default")
  setNodeBorderColorDefault("#000000", style.name = "default")
  setNodeBorderWidthDefault(0, style.name = "default")
  setEdgeColorDefault("#000000", style.name = "default")
  setEdgeLineWidthDefault(1, style.name = "default")
  setEdgeSourceArrowShapeDefault('ARROW_SHORT', style.name = "default")
  setEdgeTargetArrowShapeDefault('ARROW_SHORT', style.name = "default")

  #hide nodes without data to plot
  setNodeWidthMapping(
    'detected',
    table.column.values = c("no","yes"),
    widths = c(1,25),
    mapping.type = "d",
    default.width = 1,
    style.name = "default",
    network = NULL)

  #hide nodes without data to plot
  setNodeHeightMapping(
    'detected',
    table.column.values = c("no","yes"),
    heights = c(1,10),
    mapping.type = "d",
    default.height = 1,
    style.name = "default",
    network = NULL)

  #range for plotting
  ax_range <- max(abs(floor(min(x))),abs(ceiling(max(x))))

  #plot heatmaps
  for (i in 1:y)
  {
    a = (i-1)*3 + 1
    b = a + z - 1
    setNodeCustomHeatMapChart(
      colnames(x[a:b]),
      colors = NULL,
      range = c(-ax_range,ax_range),
      orientation = "HORIZONTAL",
      #if (i==1){rangeAxis = TRUE} else{rangeAxis = FALSE},
      rangeAxis = FALSE,
      zeroLine = TRUE,
      axisWidth = 0.5,
      axisColor = "#000000",
      axisFontSize = 3,
      slot = i,
      style.name = "default")
  }
}
delfarahalireza/calcyt documentation built on April 28, 2022, 12:05 a.m.