R/plotLioness.R

Defines functions plotLioness

Documented in plotLioness

#' Plot single-sample network
#' 
#' This function is able to plot sepecified amount of edges in a specified sample network.
#' This function should be used following the \code{\link{runLioness}}.
#' As LIONESS estimates the single-sample network of an aggregate network generated by PANDA (more )
#'
#' @param col Numerical Vector indicating the index (0-based)of specified sample in a population. Defaults to 0.
#' @param top Numeric Vector indicating the amount of edges selected to plot by decreasting order of egde weights. Defaults to 100.
#' @param file Character String indicating the name of output .png file. Defaults to 'lioness_top_100.png'.
#'
#' @return A message showing the path of output plot.
#' @examples

#' # refer to the input datasets files of control in inst/extdat as example
#' control_expression_file_path <- system.file("extdata", "expr10.txt", package = "netZoo", mustWork = TRUE)
#' motif_file_path <- system.file("extdata", "chip.txt", package = "netZoo", mustWork = TRUE)
#' ppi_file_path <- system.file("extdata", "ppi.txt", package = "netZoo", mustWork = TRUE)
#' 
#' # Run PANDA algorithm
#' control_lioness_result <- runLioness(e = control_expression_file_path, m = motif_file_path, ppi = ppi_file_path, rm_missing = TRUE )
#' 
#' # plot the top 100 egdes in first sample network.
#' plotLioness(col = 0, top = 100, file = "top100_sample1.png")
#' 
#' @import reticulate
#' @export
plotLioness <- function(col = 0, top = 100, file = 'lioness_top_100.png'){
  
  # source analyze_lioness.py in pypanda from GitHub
  reticulate::source_python("https://raw.githubusercontent.com/twangxxx/pypanda/master/pypanda/analyze_lioness.py",convert = TRUE)
  # run py code to create an instance named "plot" of AnalyzeLioness class.
  py_run_string(paste("plot = AnalyzeLioness(l)"))
  # invoke the method "top_network_plot" to plot the network. 
  py_run_string(paste("plot.top_network_plot(column=", col,",", "top=", top, ",", "file='", file,"\')",sep=""))
  # print out a message to indicate the path of output .png file.
  message(paste("The plot of top ", top, " edges in sample ", col+1, " is located in ", getwd(), "/", file, sep = ""))
}
twangxxx/netZoo documentation built on May 17, 2019, 1:02 p.m.