R/print_c_results.R

Defines functions print_c_results

print_c_results <- function(correlations, annotation, outputName, ontology) {
  # Generates a .tsv file with the results of the analysis.
  #
  # Args:
  #   correlations: (vector) value of the correlations between ontology's term
  #                          and variable.
  #   annotation: (list) translation of the ontology's terms.
  #   outputName: (char) name of the output file.
  #   ontology: (char) which ontology was used for correlation.
  # Returns:
  #   none.

  #   output <- Map("c", names(correlations), correlations,
  #                      annotation)

  outputName  <- gsub("//", "/", outputName, fixed = TRUE)


  output <- annotation[names(correlations)]
  #  colnames(output)
  for (term in names(correlations)) {
    #    term <- names(correlations)[i]
    output[[term]] <- c(term, correlations[[term]], annotation[[term]])
  }


  df.output <- data.frame(matrix(unlist(output), nrow = length(output),
                                 byrow = T, dimnames = list(names(output))))

  id <- switch(tolower(ontology),
               "go" = "GO",
               "gene ontology" = "GO",
               "kegg" = "KO",
               "other" = "ID")

  output.columns <- c(id, "CC", "annotation")

  write.table(df.output, file = outputName, quote = FALSE,
              row.names = FALSE, col.names = output.columns, sep = "\t")
  cat(".")

  return(NULL)

}
fcampelo/KOMODO2-CRAN documentation built on March 7, 2020, 6:35 a.m.