R/pandaToAlpaca.R

Defines functions pandaToAlpaca

Documented in pandaToAlpaca

#' Use two PANDA network to generate an ALPACA result
#'
#' \strong{ALPACA}(ALtered Partitions Across Community Architectures) is a method for comparing two genome-scale networks derived from different phenotypic states to identify condition-specific modules.
#' \href{https://www.nature.com/articles/s41540-018-0052-5}{[(Padi and Quackenbush 2018)])}
#' This function compares two networks generate by \code{\link{pandaPy}} in this package and finds the sets of nodes that best characterize the change in modular structure.
#'
#' @param panda.net1 data.frame indicating an complete network of one condition generated by \code{\link{pandaPy}}
#' @param panda.net2 data.frame indicating an complete network of another condition generated by \code{\link{pandaPy}}
#' @param file.stem String indicating the folder path and prefix of result files, where all results will be stored.
#' @param verbose Boolean vector indicating whether the full differential modularity matrix should also be written to a file. The default values is 'FALSE'.
#'
#' @return A string message showing the location of output file if file.stem is given, 
#' and a List where the first element is the membership vector and second element is the contribution score of each node to its module's total differential modularity
#' @import Matrix
#'
#' @examples
#' # refer to four input datasets files in inst/extdat
#' treated_expression_file_path <- system.file("extdata", "expr4_matched.txt", 
#' package = "netZooR", mustWork = TRUE)
#' control_expression_file_path <- system.file("extdata", "expr10_matched.txt", 
#' package = "netZooR", mustWork = TRUE)
#' motif_file_path <- system.file("extdata", "chip_matched.txt", package = "netZooR", mustWork = TRUE)
#' ppi_file_path <- system.file("extdata", "ppi_matched.txt", package = "netZooR", mustWork = TRUE)
#' 
#' 
#' # Run PANDA for treated and control network
#' \donttest{
#' treated_panda_net <- pandaPy(expr_file = treated_expression_file_path, 
#' motif_file = motif_file_path, ppi_file = ppi_file_path, 
#' modeProcess="legacy", remove_missing = TRUE )$panda
#' control_panda_net <- pandaPy(expr_file = control_expression_file_path, 
#' motif_file = motif_file_path, ppi_file = ppi_file_path, 
#' modeProcess="legacy", remove_missing = TRUE )$panda
#'  
#' # Run ALPACA
#' alpaca<- pandaToAlpaca(treated_panda_net, control_panda_net, "./TB", verbose=TRUE)
#' }
#' 
#' @export
pandaToAlpaca <- function(panda.net1, panda.net2, file.stem = "./alpaca", verbose = FALSE){
  # remove "Motif" column
  panda.net1 <- panda.net1[,c("TF","Gene","Score")]
  panda.net2 <- panda.net2[,c("TF","Gene","Score")]

  # merge two PANDA networks by "TF","Gene" column to generate a four-columns data.frame.
  net <- merge(panda.net1, panda.net2, by=c("TF","Gene"))
  
  # run ALPACA.
  alp <- alpaca(net, file.stem, verbose)
  # full differential modularity matrix has been written to a file, print out the location.
  if(!is.null(file.stem)){message("the ALPACA output located in", file.stem)}
  return(alp)
  }
  
netZoo/netZooR documentation built on June 8, 2024, 6:20 a.m.