From 8a9f216d2bd387b56f78aa06f5a4c0c0f6568753 Mon Sep 17 00:00:00 2001 From: Ameen Eetemadi Date: Fri, 9 Jul 2021 13:35:58 -0700 Subject: [PATCH] source from script's directory --- R/convert_to_friendlyname_OMMs.R | 10 ++++++++-- R/generate_OMMs.R | 9 ++++++++- R/select_OMMs.R | 12 ++++++++++-- R/visualize_OMMs.R | 12 ++++++++++-- 4 files changed, 36 insertions(+), 7 deletions(-) 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