diff --git a/R/convert_to_friendlyname_OMMs.R b/R/convert_to_friendlyname_OMMs.R index 7f162db..ac6880c 100755 --- a/R/convert_to_friendlyname_OMMs.R +++ b/R/convert_to_friendlyname_OMMs.R @@ -4,8 +4,6 @@ suppressPackageStartupMessages(library("argparse")) library(stringr) -source("common_OMMs.R") - get_args <- function() { parser <- ArgumentParser(description = "Use friendly food names instead of uids for the OMMs.") parser$add_argument("--glycanDB", required=TRUE, @@ -20,6 +18,14 @@ get_args <- function() { return(args) } +# source the filename from this script's directory +source_from_here <- function(filename) { + initial.options <- commandArgs(trailingOnly = FALSE) + script.name <- sub("--file=", "", initial.options[grep("--file=", initial.options)]) + source(file.path(dirname(script.name), filename)) +} +source_from_here("common_OMMs.R") + args <- get_args() # 1) Load mixed-meals diff --git a/R/generate_OMMs.R b/R/generate_OMMs.R index 123d6fc..1447896 100755 --- a/R/generate_OMMs.R +++ b/R/generate_OMMs.R @@ -7,7 +7,6 @@ library(readxl) library(stringr) library(gurobi) -source("common_OMMs.R") DEV_MODE <- FALSE # Parse and return command line arguments of this script (return defaults if DEV_MODE is TRUE). @@ -76,6 +75,14 @@ get_proportions <- function(df_food_glycans, target_glycans){ return(result$x[1:n]) } +# source the filename from this script's directory +source_from_here <- function(filename) { + initial.options <- commandArgs(trailingOnly = FALSE) + script.name <- sub("--file=", "", initial.options[grep("--file=", initial.options)]) + source(file.path(dirname(script.name), filename)) +} +source_from_here("common_OMMs.R") + args <- get_args() # 1) Load food data diff --git a/R/select_OMMs.R b/R/select_OMMs.R index a16f0d0..b27a5f4 100755 --- a/R/select_OMMs.R +++ b/R/select_OMMs.R @@ -9,8 +9,6 @@ library(ggplot2) library(reshape2) library(scales) -source("common_OMMs.R") -source("theme_util_OMMs.R") DEV_MODE <- FALSE # Parse and return command line arguments of this script (return defaults if DEV_MODE is TRUE). @@ -45,6 +43,16 @@ get_args <- function() { return(parser$parse_args()) } +# source the filename from this script's directory +source_from_here <- function(filename) { + initial.options <- commandArgs(trailingOnly = FALSE) + script.name <- sub("--file=", "", initial.options[grep("--file=", initial.options)]) + source(file.path(dirname(script.name), filename)) +} +source_from_here("common_OMMs.R") +source_from_here("theme_util_OMMs.R") + + args <- get_args() # 1) Load data diff --git a/R/visualize_OMMs.R b/R/visualize_OMMs.R index e70b6ab..1becbc6 100755 --- a/R/visualize_OMMs.R +++ b/R/visualize_OMMs.R @@ -9,8 +9,6 @@ library(ggplot2) library(reshape2) library(scales) -source("common.R") -source("theme_util.R") DEV_MODE <- FALSE # Parse and return command line arguments of this script (return defaults if DEV_MODE is TRUE). @@ -35,6 +33,16 @@ get_args <- function() { return(parser$parse_args()) } +# source the filename from this script's directory +source_from_here <- function(filename) { + initial.options <- commandArgs(trailingOnly = FALSE) + script.name <- sub("--file=", "", initial.options[grep("--file=", initial.options)]) + source(file.path(dirname(script.name), filename)) +} +source_from_here("common_OMMs.R") +source_from_here("theme_util_OMMs.R") + + args <- get_args() # 1) Load data