Skip to content

Commit 3cc61cf

Browse files
Add possible paths to install-org-db execution function
1 parent fce6a73 commit 3cc61cf

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

GeneLab_Reference_Annotations/Workflow_Documentation/GL_RefAnnotTable-A/workflow_code/GL-DPPD-7110-A_build-genome-annots-tab.R

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,35 +145,48 @@ GTF <- data.frame(GTF)
145145

146146
# Define a function to load the specified org.db package for a given target organism
147147
install_and_load_org_db <- function(target_organism, target_org_db, ref_tab_path) {
148+
# Folder names for the script location: Parent directories or . for executing from parent dir or cd.
149+
## No functionality to pull in the path of an executing R script is available
150+
possible_folders <- c("workflow_code", "GL_RefAnnotTable-A_1.1.0", ".")
151+
152+
# Get the current working directory and attempt to locate the correct folder
153+
script_dir <- getwd()
154+
155+
install_script_path <- NULL
156+
157+
for (folder in possible_folders) {
158+
potential_path <- file.path(script_dir, folder, "install-org-db.R")
159+
if (file.exists(potential_path)) {
160+
install_script_path <- potential_path
161+
break
162+
}
163+
}
164+
165+
# If the install script path was not found, stop with an error
166+
if (is.null(install_script_path)) {
167+
stop("Cannot find 'install-org-db.R' in the expected folders: 'workflow_code' or 'GL_RefAnnotTable-A_1.1.0'")
168+
}
169+
170+
# If target_org_db is provided, try to install it from Bioconductor
148171
if (!is.na(target_org_db) && target_org_db != "") {
149-
# Attempt to install the package from Bioconductor
150172
BiocManager::install(target_org_db, ask = FALSE)
151173

152174
# Check if the package was successfully loaded
153175
if (!requireNamespace(target_org_db, quietly = TRUE)) {
154-
# If not, attempt to create it locally using a helper script
155-
source("install-org-db.R")
176+
# Source the install script to create the database locally
177+
source(install_script_path)
156178
target_org_db <- install_annotations(target_organism, ref_tab_path)
157179
}
158180
} else {
159181
# If target_org_db is NA or empty, create it locally using the helper script
160-
source("install-org-db.R")
182+
source(install_script_path)
161183
target_org_db <- install_annotations(target_organism, ref_tab_path)
162184
}
163185

164186
# Load the package into the R session
165187
library(target_org_db, character.only = TRUE)
166188
}
167189

168-
# Define list of supported organisms which do not use annotations from an org.db
169-
no_org_db <- c("Lactobacillus acidophilus", "Mycobacterium marinum", "Oryza sativa", "Pseudomonas aeruginosa",
170-
"Serratia liquefaciens", "Staphylococcus aureus", "Streptococcus mutans", "Vibrio fischeri")
171-
172-
# Run the function unless the target_organism is in no_org_db
173-
if (!(target_organism %in% no_org_db) && (target_organism %in% currently_accepted_orgs)) {
174-
install_and_load_org_db(target_organism, target_org_db, ref_tab_path)
175-
}
176-
177190

178191
############################################
179192
######## Build annotation table ############

0 commit comments

Comments
 (0)