suppressWarnings(suppressMessages(library(clusterProfiler))) # 4.6.0 suppressWarnings(suppressMessages(library(stringr))) # 1.5.1 suppressWarnings(suppressMessages(library(data.table))) # 1.14.8 suppressWarnings(suppressMessages(library(tidyr))) # 1.3.0 suppressWarnings(suppressMessages(library(dplyr))) argv <- commandArgs(TRUE) go_file <- argv[1] out_file <- argv[2] GO_df <- fread(go_file, sep = "\t", header = F) colnames(GO_df) <- c("Gene ID","GO") GO_df <- GO_df %>% separate_rows(GO, sep = ";") %>% dplyr::filter(GO != "-") GO_df <- as.data.frame(GO_df) term2gene <- buildGOmap(GO_df[, c(2, 1)]) colnames(term2gene)[1] <- "go_id" merged_df <- left_join(term2gene, go2term(term2gene$go_id), by = "go_id") term2gene <- left_join(merged_df, go2ont(term2gene$go_id), by = "go_id") colnames(term2gene) <- c("GO_ID", "Gene", "Term", "Category") save(term2gene, file =out_file)