Skip to content

Commit

Permalink
uses revised facet_grid with side panels
Browse files Browse the repository at this point in the history
  • Loading branch information
metamaden committed Jan 12, 2024
1 parent 069ab9c commit bbae031
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 128 deletions.
199 changes: 169 additions & 30 deletions cohort1/.Rhistory
Original file line number Diff line number Diff line change
@@ -1,43 +1,182 @@
plot()
library(hexSticker)
install.packages("hexSticker")
library(hexSticker)
sticker("./cellScaleFactorsIMAGE.png",
package="cellScaleFactors",
p_size=20, s_x=1, s_y=.75, s_width=.6,
filename="cellScaleFactors.png")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=20, s_x=1, s_y=.75, s_width=.6,
filename="cellScaleFactors.png")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=20, s_x=1, s_y=.75, s_width=.6,
filename="cellScaleFactors.png")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.75, s_width=.6,
filename="cellScaleFactors.png")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.75, s_width=.5,
filename="cellScaleFactors.png")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png")
?sticker
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png",)
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png", h_fill="#111111")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png", h_fill="#000000")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png", h_fill="#999999")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png", h_fill="#FCFCFC")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png", h_fill="#FCFCFC",
p_color = "#111111")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
p_size=15, s_x=1, s_y=.8, s_width=.5,
filename="cellScaleFactors.png",
h_fill="#FCFCFC", p_color = "#111111", h_color = "#FF8E60")
sticker("./cellScaleFactorsIMAGE.PNG",
package="cellScaleFactors",
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")
knitr::opts_chunk$set(fig.width=10, fig.height=10, echo = F)
libv <- c("ggplot2")
sapply(libv, library, character.only = TRUE)
knitr::opts_chunk$set(echo = TRUE)
sapply(libv, library, character.only = T)
# load env data
setwd("..")
setwd("..")
list.files()
load("./env/02_pseudobulk/02_k3.RData")
new.plot
# plot proportions multipanel -- scale vs with scale
new.plot <- ggplot(dfp.ct, aes(x = true.noscale, y = pred.noscale)) +
geom_point(size = 4, alpha = 0.5) +
geom_abline(slope = 1, intercept = 0) +
geom_hline(yintercept = 0.5) + geom_vline(xintercept = 0.5) + theme_bw() +
xlab("Known") + ylab("Predicted") +
xlim(0, 1) + ylim(0, 1) + facet_wrap(~celltype) +
load("./env/05_bulk/01_run_manual_script.RData")
# format plot data
dfp <- df.k2
# format variable states
dfp$experiment.type <- paste0("z_type : ", dfp$experiment.type)
dfp$assay.name.lutearg <- paste0("rescale_type : ", dfp$assay.name.lutearg)
dfp$s.set.label <- paste0("s_set : ", dfp$s.set.label)
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)
# filter na
dfp <- na.omit(dfp)
expt <- data.frame(z.reference.type = c("shared", "within", "shared", "within"),
y.expression.scale = c("counts", "counts", "RPKM", "RPKM"))
expt <- do.call(rbind, lapply(seq(length(list.s.pred)), function(ii){
expt.iter <- expt
expt.iter
}))
expt$cell.label.type <- "k2"
# table visualization
knitr::kable(expt)
data.dict <- list(z.reference.type = "Type of cell type reference for deconvolution",
y.expression.scale = "Scale of the bulk sample data passed to lute",
s.pred.set.name = "Label of the S factor set",
s.pred.set.values = "S factor set values.",
cell.label.type = "Cell type identifier")
data.dict <- do.call(rbind, lapply(seq(length(data.dict)), function(ii){c(names(data.dict)[ii], data.dict[[ii]])}))
knitr::kable(data.dict)
# 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))
new.plot
# plot proportions multipanel -- scale vs with scale
dfp.ct$celltype <- factor(dfp.ct$celltype, levels = c("Excit", "Inhib", "glial"))
new.plot <- ggplot(dfp.ct, aes(x = true.noscale, y = pred.noscale)) +
geom_point(size = 4, alpha = 0.5) +
geom_abline(slope = 1, intercept = 0) +
geom_hline(yintercept = 0.5) + geom_vline(xintercept = 0.5) + theme_bw() +
xlab("Known") + ylab("Predicted") +
xlim(0, 1) + ylim(0, 1) + facet_wrap(~celltype) +
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))
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))
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))
new.plot
new.plot.scatter
setwd("..")
setwd("..")
new.plot.name <- "fig2c_cohort1.jpg"
jpeg(file.path("./figures/02_pseudobulk/", new.plot.name),
width = 6, height = 3, units = "in", res = 400)
new.plot
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
dev.off()
setwd("..")
setwd("..")
new.plot.name <- "fig2c_cohort1.jpg"
jpeg(file.path("./figures/02_pseudobulk/", new.plot.name),
width = 6.5, height = 3, units = "in", res = 400)
new.plot
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)
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.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))
new.plot.scatter
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.scatter
dev.off()
Binary file modified cohort1/figures/05_bulk/figs2b_validate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cohort1/figures/05_bulk/figs3a_scatter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cohort1/figures/07_adjustment/fig3_bulk-results_nnls.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion cohort1/notebooks/02_summarize_mae/01_data_summaries.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ dev.off()
```
# Sample quality summaries

```{r}
sample.id.train
```

Bulk

```{r}
Expand All @@ -110,12 +114,35 @@ assays(bulk)[["counts"]] |> colSums() |> summary()
# count zeros
apply(assays(bulk)[["counts"]],2,function(ci){length(ci[ci==0])}) |> summary()
length(intersect(bulk$batch.id2, sample.id.train))
length(intersect(bulk$batch.id2, sample.id.validate))
bf <- bulk[bulk$library_prep=="Bulk",]
length(intersect(bf$batch.id2, sample.id.train))
length(intersect(bf$batch.id2, sample.id.validate))
bf <- bulk[bulk$library_prep=="Cyto",]
length(intersect(bf$batch.id2, sample.id.train))
length(intersect(bf$batch.id2, sample.id.validate))
bf <- bulk[bulk$library_prep=="Nuc",]
length(intersect(bf$batch.id2, sample.id.train))
length(intersect(bf$batch.id2, sample.id.validate))
bf <- bulk[bulk$library_type=="polyA",]
length(intersect(bf$batch.id2, sample.id.train))
length(intersect(bf$batch.id2, sample.id.validate))
bf <- bulk[bulk$library_type=="RiboZeroGold",]
length(intersect(bf$batch.id2, sample.id.train))
length(intersect(bf$batch.id2, sample.id.validate))
```

snRNA-seq

```{r}
sce <- combineCols(mae[["snrnaseq.k2.all"]], mae[["snrnaseq.k2.all"]])
sce <- rbind(mae[["snrnaseq.k2.all"]], mae[["snrnaseq.k2.all"]])
# counts summary
assays(sce)[["counts"]] |> colSums() |> summary()
Expand All @@ -128,6 +155,10 @@ apply(assays(bulk)[["counts"]],2,function(ci){length(ci[ci==0])}) |> summary()
RNAscope

```{r}
img <- mae[["sce.img"]]
length(unique(img$Sample))
length(intersect(img$Sample, sample.id.train))
length(intersect(img$Sample, sample.id.validate))
```

# Session info
Expand Down
4 changes: 2 additions & 2 deletions cohort1/notebooks/05_bulk/01_plot_manual_save.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Proportions scatterplots.
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
Expand All @@ -89,7 +89,7 @@ setwd("..")
setwd("..")
new.plot.path <- "./figures/05_bulk/figs3a_scatter.jpg"
jpeg(new.plot.path, width = 7, height = 7, res = 400, units = "in")
jpeg(new.plot.path, width = 8, height = 4.2, res = 400, units = "in")
new.plot.scatter
dev.off()
```
Expand Down
2 changes: 1 addition & 1 deletion cohort1/notebooks/05_bulk/02_crossvalidate_save.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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") +
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))
Expand Down
7 changes: 5 additions & 2 deletions cohort1/notebooks/07_adjustment/03_run_sopt_realbulk_all.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ plotsList <- function(dfp, outlier = TRUE){
newPlot <- ggplot(dfp, aes(x = true, y = value)) +
geom_point(size = 4, alpha = 0.5) +
geom_abline(slope = 1, intercept = 0) +
facet_wrap(~cell.type*scale, nrow = 2) + xlab("Known") +
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))
Expand Down Expand Up @@ -169,6 +169,8 @@ plotsListBISQUE <- plotsList(dfp.tall[dfp.tall$algorithm=="bisque",], outlier =
Save NNLS multipanel plot.

```{r}
setwd("..")
setwd("..")
jpeg("./figures/07_adjustment/fig3_bulk-results_nnls.jpg",
width = 6, height = 4, units = "in", res = 400)
Expand All @@ -183,7 +185,8 @@ dev.off()
Save Bisque and MuSiC multipanel plot.

```{r}
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(""),
Expand Down
Loading

0 comments on commit bbae031

Please sign in to comment.