@@ -145,35 +145,48 @@ GTF <- data.frame(GTF)
145
145
146
146
# Define a function to load the specified org.db package for a given target organism
147
147
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
148
171
if (! is.na(target_org_db ) && target_org_db != " " ) {
149
- # Attempt to install the package from Bioconductor
150
172
BiocManager :: install(target_org_db , ask = FALSE )
151
173
152
174
# Check if the package was successfully loaded
153
175
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 )
156
178
target_org_db <- install_annotations(target_organism , ref_tab_path )
157
179
}
158
180
} else {
159
181
# 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 )
161
183
target_org_db <- install_annotations(target_organism , ref_tab_path )
162
184
}
163
185
164
186
# Load the package into the R session
165
187
library(target_org_db , character.only = TRUE )
166
188
}
167
189
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
-
177
190
178
191
# ###########################################
179
192
# ####### Build annotation table ############
0 commit comments