Skip to content

Commit

Permalink
Merge pull request #4 from IBPA/master
Browse files Browse the repository at this point in the history
bug fixes and gurobi setup script
  • Loading branch information
ameenetemady authored Jul 10, 2021
2 parents ad43a6e + e8e96dc commit 02d28a0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/common_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ load_MMs <- function(filename) {
MMs <- matrix(0, nrow = num_meals, ncol = length(uids), dimnames = list(1:num_meals, uids))
for (i in 1:num_meals){
line_cur <- all_lines[[i]]
df_cur <- data.frame(str_split(line_cur, ":"))
df_cur <- data.frame(str_split(line_cur, ":"), stringsAsFactors = FALSE)
fids_cur <- unlist(unname(df_cur[1,]))
proportions_cur <- unname(df_cur[2,])
MMs[i,fids_cur] <- as.numeric(unlist(proportions_cur))
Expand Down
1 change: 1 addition & 0 deletions R/convert_to_friendlyname_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
suppressPackageStartupMessages(library("argparse"))
library(stringr)

# Parse and return command line arguments of this script
get_args <- function() {
parser <- ArgumentParser(description = "Use friendly food names instead of uids for the OMMs.")
parser$add_argument("--glycanDB", required=TRUE,
Expand Down
17 changes: 17 additions & 0 deletions R/setup_OMMs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env Rscript
#' One-time setup script

suppressPackageStartupMessages(library("argparse"))
library(stringr)

# Parse and return command line arguments of this script
get_args <- function() {
parser <- ArgumentParser(description = "One-time setup for OMMs package.")
parser$add_argument("--gurobi-R-package", required=TRUE,
help="The path to the gurobi R package.")
args <- parser$parse_args()
return(args)
}

args <- get_args()
install.packages(args$gurobi_R_package, repos=NULL)
23 changes: 11 additions & 12 deletions R/visualize_OMMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ source_from_here <- function(filename) {
source_from_here("common_OMMs.R")
source_from_here("theme_util_OMMs.R")


args <- get_args()

# 1) Load data
Expand All @@ -68,8 +67,8 @@ gPlot_bars <- ggplot(df_MM_melt, aes(x=id, y=Quantity, fill=Glycan))+
my_base_theme

print(gPlot_bars)
ggsave("./results/Fig1_A.pdf", gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave("./results/Fig1_A.png", gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig1_A.pdf"), gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig1_A.png"), gPlot_bars, dpi = 400, width=8 , height = 4)

# 3.B) Plot stacked bar-charts of mixed meals (proportions)
df_MM <- data.frame(MM_vectors)
Expand All @@ -81,8 +80,8 @@ gPlot_bars <- ggplot(df_MM_melt, aes(x=id, y=Quantity, fill=Glycan))+
scale_y_continuous("Glycan %weight per mg of wet sample", labels = scales::percent)+
my_base_theme
print(gPlot_bars)
ggsave("./results/Fig1_B.pdf", gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave("./results/Fig1_B.png", gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig1_B.pdf"), gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig1_B.png"), gPlot_bars, dpi = 400, width=8 , height = 4)

# 3.C) Plot stacked bar-charts of foods (proportions)
df_food_vectors_vis <- data.frame(df_food_vectors)
Expand All @@ -96,8 +95,8 @@ gPlot_bars <- ggplot(df_food_vectors_melt, aes(x=id, y=Quantity, fill=Glycan))+
scale_y_continuous("Glycan %weight per mg of wet sample", labels = scales::percent)+
my_base_theme
print(gPlot_bars)
ggsave("./results/Fig1_C.pdf", gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave("./results/Fig1_C.png", gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig1_C.pdf"), gPlot_bars, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig1_C.png"), gPlot_bars, dpi = 400, width=8 , height = 4)

# 4) Calculate information content iteratively
df_vectors_all <- data.frame(MM_vectors)
Expand All @@ -120,8 +119,8 @@ gPlot <- ggplot(df_infos, aes(x=iter, y=infos))+
scale_y_continuous("Glycan information content (entropy)", breaks = 0:round(max(df_infos$info)))+
my_base_theme
print(gPlot)
ggsave("./results/Fig2.pdf", gPlot, dpi = 400, width=8 , height = 4)
ggsave("./results/Fig2.png", gPlot, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig2.pdf"), gPlot, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig2.png"), gPlot, dpi = 400, width=8 , height = 4)

# 6) Histogram for number of foods used in the mixed-meals
df_hist <- data.frame(id=1:nrow(MMs), count = rowSums(MMs!=0))
Expand All @@ -132,6 +131,6 @@ gPlot_hist <- ggplot(df_hist, aes(count))+
my_base_theme
sprintf("Mixed meals use an average %.2f foods.", mean(df_hist$count))
print(gPlot_hist)
ggsave("./results/Fig3.pdf", gPlot_hist, dpi = 400, width=8 , height = 4)
ggsave("./results/Fig3.png", gPlot_hist, dpi = 400, width=8 , height = 4)
print("Completed Successfully!")
ggsave(file.path(args$output_dir,"Fig3.pdf"), gPlot_hist, dpi = 400, width=8 , height = 4)
ggsave(file.path(args$output_dir,"Fig3.png"), gPlot_hist, dpi = 400, width=8 , height = 4)
print("Completed Successfully!")

0 comments on commit 02d28a0

Please sign in to comment.