Skip to content

Commit

Permalink
source from script's directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Ameen Eetemadi committed Jul 9, 2021
1 parent 5d0d461 commit 8a9f216
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
10 changes: 8 additions & 2 deletions R/convert_to_friendlyname_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion R/generate_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions R/select_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions R/visualize_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand Down

0 comments on commit 8a9f216

Please sign in to comment.