Skip to content

Commit 12b0587

Browse files
committed
[GL_RefAnnotTable] Fix interactive install-org-db
1 parent 99daa55 commit 12b0587

File tree

1 file changed

+26
-2
lines changed
  • GeneLab_Reference_Annotations/Workflow_Documentation/GL_RefAnnotTable-A/workflow_code

1 file changed

+26
-2
lines changed

GeneLab_Reference_Annotations/Workflow_Documentation/GL_RefAnnotTable-A/workflow_code/install-org-db.R

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# install-org-db.R
22

3+
# Set R library path to current working directory
4+
lib_path <- file.path(getwd())
5+
.libPaths(lib_path)
6+
7+
# Load required libraries
8+
library(tidyverse)
9+
library(AnnotationForge)
10+
library(BiocManager)
11+
312
# Function: Get annotations db from ref table. If no annotations db is defined, create the package name from genus, species, (and strain for microbes),
413
# Try to Bioconductor install annotations db. If fail then build the package using AnnotationForge, install it into the current directory.
514
# Requires ~80GB for NCBIFilesDir file caching
@@ -11,8 +20,8 @@ install_annotations <- function(target_organism, refTablePath = NULL) {
1120
csv_source <- ifelse(is.null(refTablePath), default_url, refTablePath)
1221

1322
# Attempt to read the CSV file
14-
tryCatch({
15-
ref_table <- read.csv(csv_source)
23+
ref_table <- tryCatch({
24+
read.csv(csv_source)
1625
}, error = function(e) {
1726
stop("Failed to read the reference table: ", e$message)
1827
})
@@ -60,6 +69,7 @@ install_annotations <- function(target_organism, refTablePath = NULL) {
6069
} else {
6170
cat(paste0("\nAttempting to install '", target_org_db, "' from Bioconductor...\n"))
6271
BiocManager::install(target_org_db, ask = FALSE)
72+
6373
if (requireNamespace(target_org_db, quietly = TRUE)) {
6474
cat(paste0("'", target_org_db, "' has been successfully installed from Bioconductor.\n"))
6575
} else {
@@ -93,3 +103,17 @@ install_annotations <- function(target_organism, refTablePath = NULL) {
93103
cat(paste0("Using Annotation Database '", target_org_db, "'.\n"))
94104
return(target_org_db)
95105
}
106+
107+
if (!interactive()) {
108+
# Parse command line arguments
109+
args <- commandArgs(trailingOnly = TRUE)
110+
111+
if (length(args) < 1) {
112+
stop("Usage: Rscript install-org-db.R <target_organism> [refTablePath]")
113+
}
114+
115+
target_organism <- args[1]
116+
refTablePath <- if (length(args) > 1) args[2] else NULL
117+
118+
install_annotations(target_organism, refTablePath)
119+
}

0 commit comments

Comments
 (0)