term2gene.R 891 B

123456789101112131415161718192021222324
  1. suppressWarnings(suppressMessages(library(clusterProfiler))) # 4.6.0
  2. suppressWarnings(suppressMessages(library(stringr))) # 1.5.1
  3. suppressWarnings(suppressMessages(library(data.table))) # 1.14.8
  4. suppressWarnings(suppressMessages(library(tidyr))) # 1.3.0
  5. suppressWarnings(suppressMessages(library(dplyr)))
  6. argv <- commandArgs(TRUE)
  7. go_file <- argv[1]
  8. out_file <- argv[2]
  9. GO_df <- fread(go_file, sep = "\t", header = F)
  10. colnames(GO_df) <- c("Gene ID","GO")
  11. GO_df <- GO_df %>%
  12. separate_rows(GO, sep = ";") %>%
  13. dplyr::filter(GO != "-")
  14. GO_df <- as.data.frame(GO_df)
  15. term2gene <- buildGOmap(GO_df[, c(2, 1)])
  16. colnames(term2gene)[1] <- "go_id"
  17. merged_df <- left_join(term2gene, go2term(term2gene$go_id), by = "go_id")
  18. term2gene <- left_join(merged_df, go2ont(term2gene$go_id), by = "go_id")
  19. colnames(term2gene) <- c("GO_ID", "Gene", "Term", "Category")
  20. save(term2gene, file =out_file)