R/network_import_ppcor.R

Defines functions ppcor

Documented in ppcor

#' @title Output Parser for PPCOR
#' @description This function parses the standard output generated by the BEELINE tool PPCOR.
#' @param file_path a file path to the PPCOR output file generated by BEELINE.
#' @author Sergio Vasquez and Hajk-Georg Drost
#' @examples
#' # path to PPCOR output file
#' ppcor_output <- system.file('beeline_examples/PPCOR/outFile.txt', package = 'edgynode')
#' # import PPCOR specific output
#' ppcor_parsed <- ppcor(ppcor_output)
#' # look at output
#' head(ppcor_parsed)
#' @export

ppcor <- function(file_path) {

  if (!file.exists(file_path))
    stop("Please specify a valid file path to ", file_path, "...", .call = FALSE)

  PPCOR_output <- suppressMessages(suppressWarnings(readr::read_delim(file = file_path, col_names = TRUE, delim = "\t")))

  ngenes <- length(unique(PPCOR_output$Gene1))
  res <- matrix(NA_real_, ngenes, ngenes)
  gene_names <- unique(PPCOR_output$Gene1)

  colnames(res) <- gene_names
  res <- dplyr::bind_cols(X = gene_names, as.data.frame(res))

  res <- as.data.frame(res)


  for (k in 1:length(PPCOR_output$corVal)) {

    res[match(PPCOR_output[k, 1], gene_names),
        match(PPCOR_output[k, 2], gene_names) + 1] <- PPCOR_output[k, 3]

  }

  colnames(res)[1] <- "Gene"

  result <- data.matrix(res[,2:ncol(res)])

  row.names(result) <- res[,1]

  return(result)
}
drostlab/edgynode documentation built on March 29, 2024, 10:36 a.m.