From e45fe67069edc340a536826dc606433ffe9a8c24 Mon Sep 17 00:00:00 2001 From: Sean Maden Date: Tue, 16 Jan 2024 06:32:13 -0800 Subject: [PATCH] saves Tran et al 2021 k nuclei summaries --- cohort1/.Rhistory | 100 ++- .../02_summaries/cohort2_nuclei_summaries.csv | 10 +- cohort2/scripts/02_summaries/03_nuclei.R | 16 +- software/.Rhistory | 642 +++++++++--------- 4 files changed, 374 insertions(+), 394 deletions(-) diff --git a/cohort1/.Rhistory b/cohort1/.Rhistory index d667902..30486cf 100644 --- a/cohort1/.Rhistory +++ b/cohort1/.Rhistory @@ -63,6 +63,20 @@ p_size=15, s_x=1, s_y=.8, s_width=.5, filename="cellScaleFactors.png", h_fill="#FCFCFC", p_color = "#111111", h_color = "#FF674F") setwd("C:/Users/User/Documents/GitHub/deconvo_method-paper/cohort1") +setwd("..") +setwd("..") +load("./env/05_bulk/02_crossvalidate_script.RData") +# Filter results to within-reference condition only +dfp <- df.k2[df.k2$experiment.type=="shared.reference",] +dfp$preparation.type <- gsub(".*_", "", dfp$bulk.sample.condition) +dfp <- na.omit(dfp) +# new plot +new.plot.scatter <- +ggplot(dfp, aes(x = true.neuron, y = neuron, color = bulk.scale.type)) + +theme_bw() + geom_point(alpha = 0.5) + geom_abline(slope = 1, intercept = 0) + +facet_grid(experiment.type~assay.name.lutearg+s.set.label) + +xlab("Known") + ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + +theme(axis.text.x = element_text(angle = 45, hjust = 1)) knitr::opts_chunk$set(fig.width=10, fig.height=10, echo = F) libv <- c("ggplot2") sapply(libv, library, character.only = T) @@ -104,79 +118,55 @@ knitr::kable(data.dict) new.plot.scatter <- ggplot(dfp, aes(x = true.neuron, y = neuron, color = bulk.scale.type)) + theme_bw() + geom_point(alpha = 0.5) + geom_abline(slope = 1, intercept = 0) + -facet_wrap(experiment.type*assay.name.lutearg~s.set.label) + +facet_grid(experiment.type~assay.name.lutearg+s.set.label) + xlab("Known") + ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) new.plot.scatter -# new plot -new.plot.scatter <- -ggplot(dfp, aes(x = true.neuron, y = neuron, color = bulk.scale.type)) + -theme_bw() + geom_point(alpha = 0.5) + geom_abline(slope = 1, intercept = 0) + -facet_wrap(experiment.type+assay.name.lutearg~s.set.label) + -xlab("Known") + ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + -theme(axis.text.x = element_text(angle = 45, hjust = 1)) +setwd("..") +setwd("..") +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 7.5, height = 7, res = 400, units = "in") new.plot.scatter -# new plot -new.plot.scatter <- -ggplot(dfp, aes(x = true.neuron, y = neuron, color = bulk.scale.type)) + -theme_bw() + geom_point(alpha = 0.5) + geom_abline(slope = 1, intercept = 0) + -facet_grid(experiment.type+assay.name.lutearg~s.set.label) + -xlab("Known") + ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + -theme(axis.text.x = element_text(angle = 45, hjust = 1)) +dev.off() +setwd("..") +setwd("..") +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 6, height = 6, res = 400, units = "in") new.plot.scatter -# new plot -new.plot.scatter <- -ggplot(dfp, aes(x = true.neuron, y = neuron, color = bulk.scale.type)) + -theme_bw() + geom_point(alpha = 0.5) + geom_abline(slope = 1, intercept = 0) + -facet_grid(experiment.type~assay.name.lutearg+s.set.label) + -xlab("Known") + ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + -theme(axis.text.x = element_text(angle = 45, hjust = 1)) +dev.off() +setwd("..") +setwd("..") +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 7, height = 5.5, res = 400, units = "in") new.plot.scatter +dev.off() setwd("..") setwd("..") new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" -jpeg(new.plot.path, width = 7.5, height = 7, res = 400, units = "in") +jpeg(new.plot.path, width = 8, height = 5.5, res = 400, units = "in") new.plot.scatter dev.off() setwd("..") setwd("..") -load("./env/05_bulk/02_crossvalidate_script.RData") -knitr::opts_chunk$set(fig.width=10, fig.height=10, echo = F) -libv <- c("ggplot2") -sapply(libv, library, character.only = T) +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 8, height = 5, res = 400, units = "in") +new.plot.scatter +dev.off() setwd("..") setwd("..") -load("./env/05_bulk/02_crossvalidate_script.RData") -dfp <- df.k2 -# format plot data -dfp <- dfp[dfp$crossvalidation=="validation",] -dfp[dfp$s.set.label=="s.null",]$s.set.label <- "unscaled" -dfp[dfp$s.set.label=="s.manual",]$s.set.label <- "scaled" -dfp$experiment.type <- paste0("z_type : ", dfp$experiment.type) -dfp$bulk.sample.id <- gsub("c1", "c", dfp$bulk.sample.id) -dfp$bulk.sample.id <- gsub("k1", "k", dfp$bulk.sample.id) -dfp$bulk.sample.id <- gsub("o1", "o", dfp$bulk.sample.id) -# experiment conditions -dfp$bulk.sample.condition <- cd[dfp$bulk.sample.id,]$expt_condition -table(dfp$bulk.sample.condition) -dfp <- na.omit(dfp) -new.plot.scatter <- ggplot(dfp, aes(x = true.neuron, y = neuron)) + -theme_bw() + geom_point(alpha = 0.5) + -geom_abline(slope = 1, intercept = 0) + -facet_wrap(~s.set.label*experiment.type) + xlab("Known") + -ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + -theme(axis.text.x = element_text(angle = 45, hjust = 1)) +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 8, height = 4.5, res = 400, units = "in") new.plot.scatter -new.plot.scatter <- ggplot(dfp, aes(x = true.neuron, y = neuron)) + -theme_bw() + geom_point(alpha = 0.5) + -geom_abline(slope = 1, intercept = 0) + -facet_grid(s.set.label~experiment.type) + xlab("Known") + -ylab("Predicted") + xlim(0, 1) + ylim(0, 1) + -theme(axis.text.x = element_text(angle = 45, hjust = 1)) +dev.off() +setwd("..") +setwd("..") +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 8, height = 4, res = 400, units = "in") new.plot.scatter +dev.off() setwd("..") setwd("..") -new.plot.path <- "./figures/05_bulk/figs2b_validate.jpg" -jpeg(new.plot.path, width = 4.5, height = 5, units = "in", res = 400) +new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg" +jpeg(new.plot.path, width = 8, height = 4.2, res = 400, units = "in") new.plot.scatter dev.off() diff --git a/cohort2/outputs/02_summaries/cohort2_nuclei_summaries.csv b/cohort2/outputs/02_summaries/cohort2_nuclei_summaries.csv index 27ec3a6..9a43ab4 100644 --- a/cohort2/outputs/02_summaries/cohort2_nuclei_summaries.csv +++ b/cohort2/outputs/02_summaries/cohort2_nuclei_summaries.csv @@ -1,6 +1,6 @@ k,cellType,median_nuclei_per_sample,mean_nuclei_per_sample,sd_nuclei_per_sample,median_proportion_nuclei_per_sample,mean_proportion_nuclei_per_sample,sd_proportion_nuclei_per_sample,median_marker_library_size,mean_marker_library_size,sd_marker_library_size -k2,neuron,2176.5,2078.75,922.920180238199,0.665874128565984,0.627831690999206,0.164627022800621,186.275005011024,129,192.069766282185 -k2,glial,1067.5,1128.66666666667,419.576048656332,0.334125871434016,0.372168309000794,0.164627022800621,107.204075605434,77,101.892617186566 -k3,Inhib,558,554.090909090909,451.741176902317,0.125752364574377,0.168093277786039,0.146388486906233,308.952255947498,261,217.308741475141 -k3,Excit,1819,1659.72727272727,791.794176653136,0.494908350305499,0.493756240943012,0.158568135189935,232.023114421866,195,193.732105594974 -k3,glial,977,1072.63636363636,390.139019511577,0.305217119650109,0.338150481270949,0.120569714000566,141.515043647767,104,128.84792068759 +k2,neuron,849,1322.667,920.012,0.452,0.377,0.177,324.413,296,164.115 +k2,glial,2887,2399,1384.1,0.548,0.623,0.177,269.877,263,151.807 +k3,Inhib,332,526.667,360.808,0.179,0.149,0.067,336.114,313,168.653 +k3,Excit,517,796,559.376,0.273,0.227,0.11,316.671,286,160.61 +k3,glial,2887,2399,1384.1,0.548,0.623,0.177,269.877,263,151.807 diff --git a/cohort2/scripts/02_summaries/03_nuclei.R b/cohort2/scripts/02_summaries/03_nuclei.R index 64f9f37..1a936f1 100644 --- a/cohort2/scripts/02_summaries/03_nuclei.R +++ b/cohort2/scripts/02_summaries/03_nuclei.R @@ -14,9 +14,7 @@ #------ # load marker data load("env/01_pseudobulk/01_k2_mrb_script.RData") - -sceK2 <- list.sce.markers[["k2"]] -sceK3 <- list.sce.markers[["k3"]] +load("env/01_pseudobulk/01_k3_mrb_script.RData") dfSummary <- function(sce, sampleIdVariable = "donor", @@ -78,18 +76,10 @@ dfSummary <- function(sce, return(dfSummaries) } -summaryK2 <- dfSummary(sceK2, "Sample", "k2", c("neuron", "glial")) -summaryK3 <- dfSummary(sceK3, "Sample", "k3", c("Inhib", "Excit", "glial")) +summaryK2 <- dfSummary(sce.k2, "donor", "k2", c("neuron", "glial")) +summaryK3 <- dfSummary(sce.k3, "donor", "k3", c("Inhib", "Excit", "glial")) summaryTable <- rbind(summaryK2, summaryK3) -sce.mrb$Sample <- sce.mrb$donor -summaryK2 <- dfSummary(sce.mrb, "Sample", "k2", c("neuron", "glial")) -summaryK3 <- dfSummary(sce.mrb, "Sample", "k3", c("Inhib", "Excit", "glial")) - -summaryK3 <- dfSummary(sceK3, "Sample", "k3", c("Inhib", "Excit", "glial")) -summaryTable <- rbind(summaryK2, summaryK3) - - #----- # save #----- diff --git a/software/.Rhistory b/software/.Rhistory index 149cd55..363856f 100644 --- a/software/.Rhistory +++ b/software/.Rhistory @@ -1,92 +1,288 @@ -plotK2.c2box.glial, -layout_matrix = layoutMatrix) -jpeg("./figures/01_multipanel/pseudobulk-k2-2cohort_multi.jpg", width = 10, height = 4, units = "in", res = 400) -jpeg("./figures/01_multipanel/pseudobulk-k2-2cohort_multi.jpg", width = 10, height = 4, units = "in", res = 400) -grid.arrange(plotK2.c1Scatter.neuron, -plotK2.c1box.neuron, -plotK2.c2Scatter.neuron, -plotK2.c2box.neuron, -plotK2.c1Scatter.glial, -plotK2.c1box.glial, -plotK2.c2Scatter.glial, -plotK2.c2box.glial, -layout_matrix = layoutMatrix) +geom_text(data = dfLabelNeuron, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) + +geom_text(data = dfLabelGlial, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) +} +jitterbox <- ggplot(dfp[dfp$cell.type == "neuron",], aes(x = scale, y = error)) + +geom_jitter(alpha = 0.5, width = 0.5, height = 0) + theme_bw() + +geom_boxplot(alpha = 0, color = "cyan") + +xlab("Scale") + ylab("Error") + ylim(0, 0.5) + +theme(axis.text.x = element_text(angle = 45, hjust = 1), +axis.title.x = element_blank()) +return(list( +newPlot, jitterbox +)) +} +plotsListNNLS <- plotsList(dfp.tall[dfp.tall$algorithm=="nnls",]) +plotsListMUSIC <- plotsList(dfp.tall[dfp.tall$algorithm=="music",]) +plotsListBISQUE <- plotsList(dfp.tall[dfp.tall$algorithm=="bisque",], outlier = FALSE) +setwd("..") +setwd("..") +jpeg("./figures/07_adjustment/fig3_bulk-results_nnls.jpg", +width = 6, height = 4, units = "in", res = 400) +grid.arrange(plotsListNNLS[[1]], plotsListNNLS[[2]], +layout_matrix = matrix(c(1,1,2), byrow=TRUE, nrow = 1)) dev.off() -head(dfp.tall.c1.k2) -dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k2$glial.true, -pred = dfp.tall.c1.k2$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c1.k2))), -data.frame(true = dfp.tall.c1.k2$neuron.true, -pred = dfp.tall.c1.k2$neuron.pred, -cell.type = rep("neuron", nrow(dfp.tall.c1.k2)))) |> -as.data.frame() -ggplot(dfp.c1, aes(x = glial.true, y = glial.pred)) + -geom_point() + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1)) + -facet_wrap(~type) + geom_abline(slope = 1) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(cell.type) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1)) + -facet_wrap(~type) + geom_abline(slope = 1) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(cell.type) -head(dfp.c1) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -facet_wrap(~type) + geom_abline(slope = 1) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(cell.type) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -facet_wrap(~type) + geom_abline(slope = 1) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -facet_wrap(~type) + geom_abline(slope = 1) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type) -head(dfp.c1) -head(dfp.tall.c1.k2) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -geom_abline(slope = 1) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k2$glial.true, -pred = dfp.tall.c1.k2$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c1.k2)), -type = dfp.tall.c1.k2$type), -data.frame(true = dfp.tall.c1.k2$neuron.true, -pred = dfp.tall.c1.k2$neuron.pred, -cell.type = rep("neuron", nrow(dfp.tall.c1.k2)), -type = dfp.tall.c1.k2$type)) |> -as.data.frame() -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) +setwd("..") +setwd("..") +jpeg("./figures/07_adjustment/fig3_bulk-results_music-bisque.jpg", +width = 5.5, height = 8, units = "in", res = 400) +grid.arrange(plotsListMUSIC[[1]] + ggtitle("MuSiC"), plotsListMUSIC[[2]] + ggtitle(""), +plotsListBISQUE[[1]] + ggtitle("Bisque"), plotsListBISQUE[[2]] + ggtitle(""), +layout_matrix = matrix(c(1,1,2,3,3,4), byrow = TRUE, nrow = 2)) +dev.off() +# append glial +dfp.tall2 <- dfp.tall +dfp.tall2$cell.type <- "glial" +dfp.tall2$value <- 1-dfp.tall2$value +dfp.tall2$true <- 1-dfp.tall2$true +dfp.tall <- rbind(dfp.tall, dfp.tall2) |> as.data.frame() +plotsList <- function(dfp, outlier = TRUE){ +# plotsList +# +# scatterplot and jitterbox plot of results data, with outlier label. +# +# dfp.tall results data.frame +# +# +# +# +dfp$scale <- ifelse(dfp$scale, "withscale", "noscale") +newPlot <- ggplot(dfp, aes(x = true, y = value)) + +geom_point(size = 4, alpha = 0.5) + +geom_abline(slope = 1, intercept = 0) + +facet_grid(cell.type~scale, nrow = 2) + xlab("Known") + +ylab("Predicted") + theme_bw() + xlim(0, 1) + ylim(0, 1) + +theme(axis.text.x = element_text(angle = 45, hjust = 1)) +if(outlier){ +dfLabelGlial <- dfp[dfp$value > 0.75 & dfp$cell.type == "glial",] +dfLabelNeuron <- dfp[dfp$value < 0.25 & +dfp$true < 0.75 & dfp$cell.type == "neuron",] +newPlot <- newPlot + +geom_text(data = dfLabelNeuron, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) + +geom_text(data = dfLabelGlial, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) +} +jitterbox <- ggplot(dfp[dfp$cell.type == "neuron",], aes(x = scale, y = error)) + +geom_jitter(alpha = 0.5, width = 0.5, height = 0) + theme_bw() + +geom_boxplot(alpha = 0, color = "cyan") + +xlab("Scale") + ylab("Error") + ylim(0, 0.5) + +theme(axis.text.x = element_text(angle = 45, hjust = 1), +axis.title.x = element_blank()) +return(list( +newPlot, jitterbox +)) +} +plotsListNNLS <- plotsList(dfp.tall[dfp.tall$algorithm=="nnls",]) +setwd("..") +setwd("..") +jpeg("./figures/07_adjustment/fig3_bulk-results_nnls.jpg", +width = 6, height = 4, units = "in", res = 400) +grid.arrange(plotsListNNLS[[1]], plotsListNNLS[[2]], +layout_matrix = matrix(c(1,1,2), byrow=TRUE, nrow = 1)) +dev.off() +setwd("..") +setwd("..") +jpeg("./figures/07_adjustment/fig3_bulk-results_music-bisque.jpg", +width = 5.5, height = 8, units = "in", res = 400) +grid.arrange(plotsListMUSIC[[1]] + ggtitle("MuSiC"), plotsListMUSIC[[2]] + ggtitle(""), +plotsListBISQUE[[1]] + ggtitle("Bisque"), plotsListBISQUE[[2]] + ggtitle(""), +layout_matrix = matrix(c(1,1,2,3,3,4), byrow = TRUE, nrow = 2)) +dev.off() +plotsListNNLS[[1]] +plotsListNNLS <- plotsList(dfp.tall[dfp.tall$algorithm=="nnls",]) +plotsList <- function(dfp, outlier = TRUE){ +# plotsList +# +# scatterplot and jitterbox plot of results data, with outlier label. +# +# dfp.tall results data.frame +# +# +# +# +dfp$scale <- ifelse(dfp$scale, "withscale", "noscale") +newPlot <- ggplot(dfp, aes(x = true, y = value)) + +geom_point(size = 4, alpha = 0.5) + +geom_abline(slope = 1, intercept = 0) + +facet_grid(cell.type~scale) + xlab("Known") + +ylab("Predicted") + theme_bw() + xlim(0, 1) + ylim(0, 1) + +theme(axis.text.x = element_text(angle = 45, hjust = 1)) +if(outlier){ +dfLabelGlial <- dfp[dfp$value > 0.75 & dfp$cell.type == "glial",] +dfLabelNeuron <- dfp[dfp$value < 0.25 & +dfp$true < 0.75 & dfp$cell.type == "neuron",] +newPlot <- newPlot + +geom_text(data = dfLabelNeuron, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) + +geom_text(data = dfLabelGlial, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) +} +jitterbox <- ggplot(dfp[dfp$cell.type == "neuron",], aes(x = scale, y = error)) + +geom_jitter(alpha = 0.5, width = 0.5, height = 0) + theme_bw() + +geom_boxplot(alpha = 0, color = "cyan") + +xlab("Scale") + ylab("Error") + ylim(0, 0.5) + +theme(axis.text.x = element_text(angle = 45, hjust = 1), +axis.title.x = element_blank()) +return(list( +newPlot, jitterbox +)) +} +plotsListNNLS <- plotsList(dfp.tall[dfp.tall$algorithm=="nnls",]) +plotsListMUSIC <- plotsList(dfp.tall[dfp.tall$algorithm=="music",]) +plotsListBISQUE <- plotsList(dfp.tall[dfp.tall$algorithm=="bisque",], outlier = FALSE) +grid.arrange(plotsListNNLS[[1]], plotsListNNLS[[2]], +layout_matrix = matrix(c(1,1,2), byrow=TRUE, nrow = 1)) +gc() +gc() +knitr::opts_chunk$set(echo = TRUE) +libv <- c("dplyr", "ggplot2", "GGally", "gridExtra") +sapply(libv, library, character.only = TRUE) +setwd("..") +setwd("..") +load("./env/07_adjustment/03_run_adjustment_realbulk_all_script.RData") +list.df.true <- metadata(sce)[["list.df.true.k2"]] +plotsList <- function(dfp){ +# plotsList +# +# scatterplot and jitterbox plot of results data, with outlier label. +# +# dfp.tall results data.frame +# +# +dfp$scale <- ifelse(dfp$scale, "withscale", "noscale") +dfLabel <- dfp[dfp$true < 0.75 & dfp$value < 0.25,] +new.plot.tall <- ggplot(dfp, aes(x = true, y = value)) + +geom_point(size = 4, alpha = 0.5) + geom_abline(slope = 1, intercept = 0) + facet_wrap(~scale) + +xlab("Known") + ylab("Predicted") + xlim(0.1,0.9) + ylim(0.1,0.9) + theme_bw() + +theme(axis.text.x = element_text(angle = 45, hjust = 1)) + +geom_text(data = dfLabel, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) +new.plot.tall +new.plot.tall.jitterbox <- ggplot(dfp, aes(x = scale, y = error)) + +geom_jitter(alpha = 0.5, width = 0.5, height = 0) + theme_bw() + +geom_boxplot(alpha = 0, color = "cyan") + +xlab("Scale") + ylab("Error (neuron)") + ylim(0, 0.5) + +theme(axis.text.x = element_text(angle = 45, hjust = 1), +axis.title.x = element_blank()) +new.plot.tall.jitterbox +return(list( +new.plot.tall, new.plot.tall.jitterbox +)) +} +list.df.true <- metadata(sce)[["list.df.true.k2"]] +for(sample.id in unique(dfp.tall$sample.id)){ +message(sample.id) +message(identical(dfp.tall[dfp.tall$sample.id==sample.id,]$true[1], +as.numeric(list.df.true[[sample.id]]["neuron"]))) +} +for(sample.id in unique(dfp.tall$sample.id)){ +filter.dfp.tall <- dfp.tall$sample.id==sample.id +filter.dfp.wide <- rownames(dfp.wide)==sample.id +true.neuron.value <- as.numeric(df.true.list[[sample.id]]["neuron"]) +dfp.tall[filter.dfp.tall,]$true <- true.neuron.value +dfp.wide[filter.dfp.wide,]$neuron.true <- true.neuron.value +} +dfp.tall$error <- abs(dfp.tall$true-dfp.tall$value) +new.plot.tall.jitterbox <- ggplot(dfp.tall, +aes(x = scale, y = error)) + +geom_jitter(alpha = 0.5, width = 0.5, height = 0) + geom_boxplot(alpha = 0, color = "cyan") + +facet_wrap(~algorithm) + xlab("Scale") + +ylab("Error (neuron)") + ylim(0, 0.5) + +theme(axis.text.x = element_text(angle = 45, hjust = 1)) +new.plot.tall.jitterbox +# append glial +dfp.tall2 <- dfp.tall +dfp.tall2$cell.type <- "glial" +dfp.tall2$value <- 1-dfp.tall2$value +dfp.tall2$true <- 1-dfp.tall2$true +dfp.tall <- rbind(dfp.tall, dfp.tall2) |> as.data.frame() +plotsList <- function(dfp, outlier = TRUE){ +# plotsList +# +# scatterplot and jitterbox plot of results data, with outlier label. +# +# dfp.tall results data.frame +# +# +# +# +dfp$scale <- ifelse(dfp$scale, "withscale", "noscale") +newPlot <- ggplot(dfp, aes(x = true, y = value)) + +geom_point(size = 4, alpha = 0.5) + +geom_abline(slope = 1, intercept = 0) + +facet_grid(cell.type~scale) + xlab("Known") + +ylab("Predicted") + theme_bw() + xlim(0, 1) + ylim(0, 1) + +theme(axis.text.x = element_text(angle = 45, hjust = 1)) +if(outlier){ +dfLabelGlial <- dfp[dfp$value > 0.75 & dfp$cell.type == "glial",] +dfLabelNeuron <- dfp[dfp$value < 0.25 & +dfp$true < 0.75 & dfp$cell.type == "neuron",] +newPlot <- newPlot + +geom_text(data = dfLabelNeuron, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) + +geom_text(data = dfLabelGlial, aes(x = true, y = value), +label = sample.id, nudge_x = 0.1, nudge_y = 0.1) +} +jitterbox <- ggplot(dfp[dfp$cell.type == "neuron",], aes(x = scale, y = error)) + +geom_jitter(alpha = 0.5, width = 0.5, height = 0) + theme_bw() + +geom_boxplot(alpha = 0, color = "cyan") + +xlab("Scale") + ylab("Error") + ylim(0, 0.5) + +theme(axis.text.x = element_text(angle = 45, hjust = 1), +axis.title.x = element_blank()) +return(list( +newPlot, jitterbox +)) +} +plotsListNNLS <- plotsList(dfp.tall[dfp.tall$algorithm=="nnls",]) +plotsListMUSIC <- plotsList(dfp.tall[dfp.tall$algorithm=="music",]) +plotsListBISQUE <- plotsList(dfp.tall[dfp.tall$algorithm=="bisque",], outlier = FALSE) +setwd("..") +setwd("..") +jpeg("./figures/07_adjustment/fig3_bulk-results_nnls.jpg", +width = 6, height = 4, units = "in", res = 400) +grid.arrange(plotsListNNLS[[1]], plotsListNNLS[[2]], +layout_matrix = matrix(c(1,1,2), byrow=TRUE, nrow = 1)) +dev.off() +setwd("..") +setwd("..") +jpeg("./figures/07_adjustment/fig3_bulk-results_music-bisque.jpg", +width = 5.5, height = 8, units = "in", res = 400) +grid.arrange(plotsListMUSIC[[1]] + ggtitle("MuSiC"), plotsListMUSIC[[2]] + ggtitle(""), +plotsListBISQUE[[1]] + ggtitle("Bisque"), plotsListBISQUE[[2]] + ggtitle(""), +layout_matrix = matrix(c(1,1,2,3,3,4), byrow = TRUE, nrow = 2)) +dev.off() +setwd("C:/Users/User/Documents/GitHub/deconvo_method-paper/software") +libv <- c("here", "nlme", "lute", "ggplot2", "gridExtra", +"dplyr", "ggforce", "MultiAssayExperiment", "SingleCellExperiment") +sapply(libv, library, character.only = TRUE) +knitr::opts_chunk$set(echo = TRUE) +setwd("..") +setwd("..") +list.files() +load("env/01_multipanel/01_pseudobulk_script.RData") +# cohort 1 +# scatter with facet dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k2$glial.true, pred = dfp.tall.c1.k2$glial.pred, cell.type = rep("glial", nrow(dfp.tall.c1.k2)), type = dfp.tall.c1.k2$type, -error = dpf.tall.c1.k2$glial.abs.error), +error = dfp.tall.c1.k2$glial.abs.error), data.frame(true = dfp.tall.c1.k2$neuron.true, pred = dfp.tall.c1.k2$neuron.pred, cell.type = rep("neuron", nrow(dfp.tall.c1.k2)), type = dfp.tall.c1.k2$type, error = dfp.tall.c1.k2$neuron.abs.error)) |> as.data.frame() +plotK2.scatter.c1 <- ggplot(dfp.c1, aes(x = true, y = pred)) + +geom_point() + theme_bw() + geom_abline(slope = 1) + +theme(axis.text.x = element_text(angle = 45, hjust=1)) + +xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + +xlim(0,1) + ylim(0,1) + +facet_grid(type+cell.type) +# cohort 1 +# scatter with facet dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k2$glial.true, pred = dfp.tall.c1.k2$glial.pred, cell.type = rep("glial", nrow(dfp.tall.c1.k2)), @@ -98,82 +294,18 @@ cell.type = rep("neuron", nrow(dfp.tall.c1.k2)), type = dfp.tall.c1.k2$type, error = dfp.tall.c1.k2$neuron.abs.error)) |> as.data.frame() -ggplot(dfp.c1, aes(x = type, y = neuron.abs.error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) -ggplot(dfp.c1, aes(x = type, y = neuron.abs.error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + -theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) -ggplot(dfp.c1, aes(x = type, y = error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + -theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) -ggplot(dfp.c1, aes(x = type, y = error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + -theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type) -ggplot(dfp.c1, aes(x = type, y = error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + -theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 2) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -dfp.c2 <- rbind(data.frame(true = dfp.tall.c2.k2$glial.true, -pred = dfp.tall.c2.k2$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c2.k2)), -type = dfp.tall.c2.k2$type, -error = dfp.tall.c2.k2$glial.abs.error), -data.frame(true = dfp.tall.c2.k2$neuron.true, -pred = dfp.tall.c2.k2$neuron.pred, -cell.type = rep("neuron", nrow(dfp.tall.c2.k2)), -type = dfp.tall.c2.k2$type, -error = dfp.tall.c2.k2$neuron.abs.error)) |> -as.data.frame() -dfp.c2 <- ggplot(dfp.c2, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Tran et. al. 2021") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -plotK2.box.c2 <- ggplot(dfp.c2, aes(x = type, y = error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + -theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 2) -dfp.c2 <- rbind(data.frame(true = dfp.tall.c2.k2$glial.true, -pred = dfp.tall.c2.k2$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c2.k2)), -type = dfp.tall.c2.k2$type, -error = dfp.tall.c2.k2$glial.abs.error), -data.frame(true = dfp.tall.c2.k2$neuron.true, -pred = dfp.tall.c2.k2$neuron.pred, -cell.type = rep("neuron", nrow(dfp.tall.c2.k2)), -type = dfp.tall.c2.k2$type, -error = dfp.tall.c2.k2$neuron.abs.error)) |> -as.data.frame() -dfp.c2 -dfp.c2 <- ggplot(dfp.c2, aes(x = true, y = pred)) + +plotK2.scatter.c1 <- ggplot(dfp.c1, aes(x = true, y = pred)) + geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Tran et. al. 2021") + +xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -dfp.c2 -plotK2.box.c2 <- ggplot(dfp.c2, aes(x = type, y = error)) + +facet_grid(type~cell.type) +plotK2.box.c1 <- ggplot(dfp.c1, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 2) -head(dfp.c2) -class(dfp.c2) -plotK2.scatter.c2 <- ggplot(dfp.c2, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Tran et. al. 2021") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) +# cohort 2 +# scatter with facet dfp.c2 <- rbind(data.frame(true = dfp.tall.c2.k2$glial.true, pred = dfp.tall.c2.k2$glial.pred, cell.type = rep("glial", nrow(dfp.tall.c2.k2)), @@ -190,51 +322,11 @@ geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + xlab("Known") + ylab("Predicted") + ggtitle("Tran et. al. 2021") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) +facet_grid(type~cell.type) plotK2.box.c2 <- ggplot(dfp.c2, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 2) -matrix(c(rep(seq(4), each = 2)), nrow = 2, byrow=T) -matrix(rep(c(1,1,2,3,3,4), 2), nrow=2) -matrix(rep(c(1,1,2,3,3,4), 2), byrow=T, nrow=2) -layoutMatrix <- matrix(rep(c(1,1,2,3,3,4), 2), byrow=T, nrow=2) -grid.arrange(plotK2.scatter.c1, -plotK2.box.c1, -plotK2.scatter.c2, -plotK2.box.c2) -grid.arrange(plotK2.scatter.c1, -plotK2.box.c1, -plotK2.scatter.c2, -plotK2.box.c2, -layout_matrix = layoutMatrix) -dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k2$glial.true, -pred = dfp.tall.c1.k2$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c1.k2)), -type = dfp.tall.c1.k2$type, -error = dfp.tall.c1.k2$glial.abs.error), -data.frame(true = dfp.tall.c1.k2$neuron.true, -pred = dfp.tall.c1.k2$neuron.pred, -cell.type = rep("neuron", nrow(dfp.tall.c1.k2)), -type = dfp.tall.c1.k2$type, -error = dfp.tall.c1.k2$neuron.abs.error)) |> -as.data.frame() -plotK2.scatter.c1 <- ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -plotK2.box.c1 <- ggplot(dfp.c1, aes(x = type, y = error)) + -geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + -theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + -ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 2) -layoutMatrix <- matrix(rep(c(1,1,2,3,3,4), 2), byrow=T, nrow=2) -grid.arrange(plotK2.scatter.c1, -plotK2.box.c1, -plotK2.scatter.c2, -plotK2.box.c2, -layout_matrix = layoutMatrix) setwd("..") setwd("..") jpeg("./figures/01_multipanel/pseudobulk-k2-2cohort_multi.jpg", width = 10, height = 4, units = "in", res = 400) @@ -245,9 +337,6 @@ plotK2.scatter.c2, plotK2.box.c2, layout_matrix = layoutMatrix) dev.off() -gc() -gc() -gc() libv <- c("here", "nlme", "lute", "ggplot2", "gridExtra", "dplyr", "ggforce", "MultiAssayExperiment", "SingleCellExperiment") sapply(libv, library, character.only = TRUE) @@ -256,57 +345,6 @@ setwd("..") setwd("..") list.files() load("env/01_multipanel/01_pseudobulk_script.RData") -head(dfp.tall.c1.k3) -dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k3$glial.true, -pred = dfp.tall.c1.k3$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.32$glial.abs.error), -data.frame(true = dfp.tall.c1.k3$Excit.true, -pred = dfp.tall.c1.k3$Excit.pred, -cell.type = rep("Excit", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.k3$Excit.abs.error), -data.frame(true = dfp.tall.c1.k3$Inhib.true, -pred = dfp.tall.c1.k3$Inhib.pred, -cell.type = rep("Inhib", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.k3$Inhib.abs.error)) |> -as.data.frame() -dfp.tall.c1.k3$# cohort 1 -dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k3$glial.true, -pred = dfp.tall.c1.k3$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.3$glial.abs.error), -data.frame(true = dfp.tall.c1.k3$Excit.true, -pred = dfp.tall.c1.k3$Excit.pred, -cell.type = rep("Excit", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.k3$Excit.abs.error), -data.frame(true = dfp.tall.c1.k3$Inhib.true, -pred = dfp.tall.c1.k3$Inhib.pred, -cell.type = rep("Inhib", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.k3$Inhib.abs.error)) |> -as.data.frame() -# cohort 1 -dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k3$glial.true, -pred = dfp.tall.c1.k3$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.3$glial.abs.error), -data.frame(true = dfp.tall.c1.k3$Excit.true, -pred = dfp.tall.c1.k3$Excit.pred, -cell.type = rep("Excit", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.k3$Excit.abs.error), -data.frame(true = dfp.tall.c1.k3$Inhib.true, -pred = dfp.tall.c1.k3$Inhib.pred, -cell.type = rep("Inhib", nrow(dfp.tall.c1.k3)), -type = dfp.tall.c1.k3$type, -error = dfp.tall.c1.k3$Inhib.abs.error)) |> -as.data.frame() # cohort 1 dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k3$glial.true, pred = dfp.tall.c1.k3$glial.pred, @@ -324,56 +362,14 @@ cell.type = rep("Inhib", nrow(dfp.tall.c1.k3)), type = dfp.tall.c1.k3$type, error = dfp.tall.c1.k3$Inhib.abs.error)) |> as.data.frame() -dfp.c2 <- rbind(data.frame(true = dfp.tall.c2.k3$glial.true, -pred = dfp.tall.c2.k3$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c2.k3)), -type = dfp.tall.c2.k3$type, -error = dfp.tall.c2.k3$glial.abs.error), -data.frame(true = dfp.tall.c2.k3$Excit.true, -pred = dfp.tall.c2.k3$Excit.pred, -cell.type = rep("Excit", nrow(dfp.tall.c2.k3)), -type = dfp.tall.c2.k3$type, -error = dfp.tall.c2.k3$Excit.abs.error), -data.frame(true = dfp.tall.c2.k3$Inhib.true, -pred = dfp.tall.c2.k3$Inhib.pred, -cell.type = rep("Inhib", nrow(dfp.tall.c2.k3)), -type = dfp.tall.c2.k3$type, -error = dfp.tall.c2.k3$Inhib.abs.error)) |> -as.data.frame() -plotK3.scatter.c1 <- ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type) -plotK3.scatter.c1 -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~type*cell.type) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~type*cell.type, ncol = 2) -ggplot(dfp.c1, aes(x = true, y = pred)) + -geom_point() + theme_bw() + geom_abline(slope = 1) + -theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type, ncol = 2) -dfp.c1$cell.type <- factor(dfp.c1$cell.type, levels = c("glial", "Excit", "Inhib")) +dfp.c1$cell.type <- factor(dfp.c1$cell.type, levels = c("Excit", "Inhib", "glial")) plotK3.scatter.c1 <- ggplot(dfp.c1, aes(x = true, y = pred)) + geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type, ncol = 2) -plotK3.scatter.c1 -ggplot(dfp.c1, aes(x = type, y = error)) + +facet_wrap(type~cell.type) +plotK3.box.c1 <- ggplot(dfp.c1, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 3) @@ -394,24 +390,26 @@ cell.type = rep("Inhib", nrow(dfp.tall.c2.k3)), type = dfp.tall.c2.k3$type, error = dfp.tall.c2.k3$Inhib.abs.error)) |> as.data.frame() -dfp.c2$cell.type <- factor(dfp.c2$cell.type, levels = c("glial", "Excit", "Inhib")) +dfp.c2$cell.type <- factor(dfp.c2$cell.type, levels = c("Excit", "Inhib", "glial")) plotK3.scatter.c2 <- ggplot(dfp.c2, aes(x = true, y = pred)) + geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + -xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + facet_wrap(~cell.type*type, ncol = 2) +xlab("Known") + ylab("Predicted") + ggtitle("Tran et. al. 2021") + +xlim(0,1) + ylim(0,1) + facet_wrap(type~cell.type) plotK3.box.c2 <- ggplot(dfp.c2, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 3) -plotK3.scatter.c2 -plotK3.box.c2 +setwd("..") +setwd("..") +jpeg("./figures/01_multipanel/pseudobulk-k3-2cohort_multi.jpg", width = 10, height = 4, units = "in", res = 400) layoutMatrix <- matrix(rep(c(1,1,2,3,3,4), 2), byrow=T, nrow=2) grid.arrange(plotK3.scatter.c1, plotK3.box.c1, plotK3.scatter.c2, plotK3.box.c2, layout_matrix = layoutMatrix) +dev.off() # cohort 1 dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k3$glial.true, pred = dfp.tall.c1.k3$glial.pred, @@ -435,44 +433,46 @@ geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + xlim(0,1) + ylim(0,1) + -facet_wrap(~cell.type*type, ncol = 2) +facet_grid(type~cell.type) plotK3.box.c1 <- ggplot(dfp.c1, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 3) -# cohort 2 -dfp.c2 <- rbind(data.frame(true = dfp.tall.c2.k3$glial.true, -pred = dfp.tall.c2.k3$glial.pred, -cell.type = rep("glial", nrow(dfp.tall.c2.k3)), -type = dfp.tall.c2.k3$type, -error = dfp.tall.c2.k3$glial.abs.error), -data.frame(true = dfp.tall.c2.k3$Excit.true, -pred = dfp.tall.c2.k3$Excit.pred, -cell.type = rep("Excit", nrow(dfp.tall.c2.k3)), -type = dfp.tall.c2.k3$type, -error = dfp.tall.c2.k3$Excit.abs.error), -data.frame(true = dfp.tall.c2.k3$Inhib.true, -pred = dfp.tall.c2.k3$Inhib.pred, -cell.type = rep("Inhib", nrow(dfp.tall.c2.k3)), -type = dfp.tall.c2.k3$type, -error = dfp.tall.c2.k3$Inhib.abs.error)) |> +plotK3.scatter.c1 +ggplot(dfp.c1, aes(x = true, y = pred)) + +geom_point() + theme_bw() + geom_abline(slope = 1) + +theme(axis.text.x = element_text(angle = 45, hjust=1)) + +xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + +xlim(0,1) + ylim(0,1) + +facet_grid(cell.type~type) +# cohort 1 +dfp.c1 <- rbind(data.frame(true = dfp.tall.c1.k3$glial.true, +pred = dfp.tall.c1.k3$glial.pred, +cell.type = rep("glial", nrow(dfp.tall.c1.k3)), +type = dfp.tall.c1.k3$type, +error = dfp.tall.c1.k3$glial.abs.error), +data.frame(true = dfp.tall.c1.k3$Excit.true, +pred = dfp.tall.c1.k3$Excit.pred, +cell.type = rep("Excit", nrow(dfp.tall.c1.k3)), +type = dfp.tall.c1.k3$type, +error = dfp.tall.c1.k3$Excit.abs.error), +data.frame(true = dfp.tall.c1.k3$Inhib.true, +pred = dfp.tall.c1.k3$Inhib.pred, +cell.type = rep("Inhib", nrow(dfp.tall.c1.k3)), +type = dfp.tall.c1.k3$type, +error = dfp.tall.c1.k3$Inhib.abs.error)) |> as.data.frame() -dfp.c2$cell.type <- factor(dfp.c2$cell.type, levels = c("Excit", "Inhib", "glial")) -plotK3.scatter.c2 <- ggplot(dfp.c2, aes(x = true, y = pred)) + +dfp.c1$cell.type <- factor(dfp.c1$cell.type, levels = c("Excit", "Inhib", "glial")) +plotK3.scatter.c1 <- ggplot(dfp.c1, aes(x = true, y = pred)) + geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + xlab("Known") + ylab("Predicted") + ggtitle("Huuki-Meyers et. al. 2023") + -xlim(0,1) + ylim(0,1) + facet_wrap(~cell.type*type, ncol = 2) -plotK3.box.c2 <- ggplot(dfp.c2, aes(x = type, y = error)) + +xlim(0,1) + ylim(0,1) + +facet_grid(cell.type~type) +plotK3.box.c1 <- ggplot(dfp.c1, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) + ylab("Error") + ggtitle("\n") + ylim(0, 0.3) + facet_wrap(~cell.type, nrow = 3) -layoutMatrix <- matrix(rep(c(1,1,2,3,3,4), 2), byrow=T, nrow=2) -grid.arrange(plotK3.scatter.c1, -plotK3.box.c1, -plotK3.scatter.c2, -plotK3.box.c2, -layout_matrix = layoutMatrix) # cohort 2 dfp.c2 <- rbind(data.frame(true = dfp.tall.c2.k3$glial.true, pred = dfp.tall.c2.k3$glial.pred, @@ -495,7 +495,7 @@ plotK3.scatter.c2 <- ggplot(dfp.c2, aes(x = true, y = pred)) + geom_point() + theme_bw() + geom_abline(slope = 1) + theme(axis.text.x = element_text(angle = 45, hjust=1)) + xlab("Known") + ylab("Predicted") + ggtitle("Tran et. al. 2021") + -xlim(0,1) + ylim(0,1) + facet_wrap(~cell.type*type, ncol = 2) +xlim(0,1) + ylim(0,1) + facet_grid(cell.type~type) plotK3.box.c2 <- ggplot(dfp.c2, aes(x = type, y = error)) + geom_boxplot(color="cyan") + geom_jitter(alpha = 0.5) + theme_bw() + theme(axis.text.x = element_text(angle = 45,hjust=1), axis.title.x = element_blank()) +