mosaic_2020/boxplots_stat_ob_paper.R

266 lines
8.2 KiB
R
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/Rscript
getwd()
setwd("~/git/mosaic_2020/")
getwd()
###############################################################
# TASK: boxplots with stats for NPA, SAM and SERUM
# for each mediator, at each timepoint by group
# TODO: check boxplot_stat_function.R
# output plots even if stats fail due to data containing only LLODs
# however for a given mediator, if there is error for ANY timepoint
# stats will not be added for the entire plot! To be handled in
# next iteration!
###############################################################
#=============
# Input
#=============
source("boxplot_stat_function.R")
source("plot_data_ob_paper.R")
# numbers
table(vl_lf_plot_df$mosaic)
length(unique(vl_lf_plot_df$mosaic))
table(vl_lf_plot_df$obesity, vl_lf_plot_df$timepoint)
table(vl_lf_plot_df$obesity, vl_lf_plot_df$timepoint, vl_lf_plot_df$mediator)
length(unique(npa_lf_plot_df$mosaic))
table(npa_lf_plot_df$obesity, npa_lf_plot_df$timepoint, npa_lf_plot_df$mediator)
table(npa_lf_plot_df$mediator, npa_lf_plot_df$obesity, npa_lf_plot_df$timepoint)
ob_grp_npa = npa_wf[npa_wf$obesity==1,]
nob_grp_npa = npa_wf[npa_wf$obesity==0,]
wilcox.test(ob_grp_npa$il1_npa1,
nob_grp_npa$il1_npa1, paired = F)
wilcox.test(ob_grp_npa$il1_npa2,
nob_grp_npa$il1_npa2, paired = F)
wilcox.test(ob_grp_npa$il6_npa1,
nob_grp_npa$il6_npa1, paired = F)
wilcox.test(ob_grp_npa$il6_npa2,
nob_grp_npa$il6_npa2, paired = F)
wilcox.test(ob_grp_npa$il8_npa1,
nob_grp_npa$il8_npa1, paired = F)
wilcox.test(ob_grp_npa$il8_npa2,
nob_grp_npa$il8_npa2, paired = F)
wilcox.test(ob_grp_npa$ip10_npa1,
nob_grp_npa$ip10_npa1, paired = F)
wilcox.test(ob_grp_npa$ip10_npa2,
nob_grp_npa$ip10_npa2, paired = F)
length(unique(serum_lf_plot_df$mosaic))
table(serum_lf_plot_df$obesity, serum_lf_plot_df$timepoint, serum_lf_plot_df$mediator)
table(serum_lf_plot_df$mediator, serum_lf_plot_df$obesity, serum_lf_plot_df$timepoint)
#=============
# Output
#=============
outdir_plots_paper = "/home/tanu/git/mosaic_2020/output/plots_paper/"
#outfile_bp = paste0("boxplots_stats_paper-%03d.png")
#output_boxplot_stats = paste0(outdir_plots_paper, outfile_bp); output_boxplot_stats
#svg(output_boxplot_stats, width=22, height=16)
#png(output_boxplot_stats, width = 11, height = 8, units = "in", res = 300)
###############################################################
#===============================
# data assignment for plots
#===============================
#-------------
# NPA: VL
#-------------
#linear
cat("plotting for FP adult patients:",
length(unique(vl_lf_plot_df$mosaic)))
# linear : but data is not visible
plots_npa_vl = doMyPlotsStats(vl_lf_plot_df)
npa_plot_vl = ggpubr::ggarrange(plotlist = plots_npa_vl
, align = "hv"
#, legend = c(0.8,1)
#, legend = "bottom"
, common.legend = T)
npa_plot_vl
# log
plots_npa_vl_log = doMyPlotsStats(vl_lf_plot_df_log)
npa_plot_vl_log = ggpubr::ggarrange(plotlist = plots_npa_vl_log
, align = "hv"
, common.legend = T
)
npa_plot_vl_log
############################################################
mediator_order = c("IFN-α2a","IFN-β", "IFN-γ", "IL-1", "IL-6", "CXCL8", "CXCL10", "TNF-α")
#-----------------------------
# NPA: selected mediators
#-----------------------------
# linear
plots_npa = doMyPlotsStats(npa_lf_plot_df, custom_order = mediator_order)
npa_plot_1 = ggpubr::ggarrange(plotlist = plots_npa
, align = "hv"
, ncol = 8
, nrow = 1
, common.legend = T)
npa_plot = annotate_figure(npa_plot_1,
top = text_grob("NPA"
, color = "black"
#, face = "bold"
, size = 14))
# log
plots_npa_log = doMyPlotsStats(npa_lf_plot_df_log, custom_order = mediator_order)
npa_plot_log_1 = ggpubr::ggarrange(plotlist = plots_npa_log
, align = "hv"
, ncol = 8
, nrow = 1
, common.legend = T)
npa_plot_log = annotate_figure(npa_plot_log_1,
top = text_grob("NPA"
, color = "black"
#, face = "bold"
, size = 14))
npa_plot_log
#-------------------------------
# SERUM: selected mediators
#--------------------------------
# linear
plots_serum = doMyPlotsStats(serum_lf_plot_df, custom_order = mediator_order)
serum_plot_1 = ggpubr::ggarrange(plotlist = plots_serum
, align = "hv"
, ncol = 8
, nrow = 1
, common.legend = F
)
serum_plot = annotate_figure(serum_plot_1,
top = text_grob("Serum"
, color = "black"
#, face = "bold"
, size = 14))
serum_plot
# log
plots_serum_log = doMyPlotsStats(serum_lf_plot_log, custom_order = mediator_order)
serum_plot_log_1 = ggpubr::ggarrange(plotlist = plots_serum_log
, align = "hv"
, ncol = 8
, nrow = 1
, common.legend = F)
serum_plot_log = annotate_figure(serum_plot_log_1,
top = text_grob("Serum"
, color = "black"
#, face = "bold"
, size = 14))
serum_plot_log
##############################################################
##############################################################
cat ("Outplots will be in:", outdir_plots_paper)
#======================
# Output: Linear graphs
#======================
# viral load: linear
viral_load_annot = annotate_figure(
npa_plot_vl
, left = text_grob("pg/ml"
, color = "black"
, rot = 90
, size = 18)
)
png(paste0(outdir_plots_paper, "viral_load_linear"),
width = 5,
height = 5,
units = "in",
res = 300)
viral_load_annot
dev.off()
# npa and serum mediators: linear
outplot_linear = cowplot::plot_grid(
npa_plot,
serum_plot,
nrow = 2,
rel_heights = c(1.15,1)
)
outplot_linear_annot = annotate_figure(
outplot_linear
, left = text_grob("pg/ml"
, color = "black"
, rot = 90
, size = 16)
)
png(paste0(outdir_plots_paper, "npa_serum_linear"),
width = 18,
height = 6,
units = "in",
res = 300)
outplot_linear_annot
dev.off()
#======================
# Output: Log graphs
#======================
# viral load: log
viral_load_log_annot = annotate_figure(
npa_plot_vl_log
, left = text_grob("Log10 (pg/ml)"
, color = "black"
, rot = 90
, size = 18)
)
png(paste0(outdir_plots_paper, "viral_load_log" ),
width = 5,
height = 5,
units = "in",
res = 300)
viral_load_log_annot
dev.off()
# npa and serum mediators: log
outplot_log = cowplot::plot_grid(
npa_plot_log,
serum_plot_log,
nrow = 2,
rel_heights = c(1.15,1)
)
outplot_log_annot = annotate_figure(
outplot_log
, left = text_grob("Log10 (pg/ml)"
, color = "black"
, rot = 90
, size = 16)
)
png(paste0(outdir_plots_paper, "npa_serum_log"),
width = 18,
height = 6,
units = "in",
res = 300)
outplot_log_annot
dev.off()
###############################################################
# END OF SCRIPT #
###############################################################