CompileGTF.R 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env Rscript
  2. # Load the openxlsx package
  3. library(openxlsx)
  4. args <- commandArgs(TRUE)
  5. outDir <- args[1]
  6. # Function to combine CSV and TXT files into a workbook with named sheets
  7. combineFilesToWorkbook <- function(file_list, output_file) {
  8. # Create a new workbook
  9. wb <- createWorkbook()
  10. # Loop through the file list
  11. for (i in seq_along(file_list)) {
  12. file <- file_list[i]
  13. # Extract the sheet name from the file name based on the extension
  14. ext <- tools::file_ext(file)
  15. sheet_name <- tools::file_path_sans_ext(basename(file))
  16. # Read the data based on the file extension
  17. if (ext %in% c("csv", "txt")) {
  18. if (ext == "csv") {
  19. data <- read.csv(file)
  20. } else if (ext == "txt") {
  21. data <- readLines(file)
  22. }
  23. # Create a new sheet in the workbook with the extracted sheet name
  24. addWorksheet(wb, sheetName = sheet_name)
  25. # Write the data to the sheet
  26. writeData(wb, sheet = sheet_name, x = data)
  27. }
  28. }
  29. # Save the workbook as an Excel file
  30. saveWorkbook(wb, output_file)
  31. }
  32. Component <- file.path(outDir, "Component", "ComponentResults.txt")
  33. Function <- file.path(outDir, "Function", "FunctionResults.txt")
  34. Process <- file.path(outDir, "Process", "ProcessResults.txt")
  35. # Specify the list of input files (both CSV and TXT)
  36. file_list <- c(Component, Process, Function)
  37. # Specify the output file name
  38. output_file <- file.path(outDir, "GTFCombined.xlsx")
  39. # Call the function to combine the files into a workbook with named sheets
  40. combineFilesToWorkbook(file_list, output_file)