# Load the library
library(Seurat)
library(ggplot2)
library(ggprism)
library(ggfun)
library(aplot)
#set the color
celltype_colors <- c(
"Astrocytes" = "#ED9F9B",
"Excitatory neurons" = "#8AB1D2",
"Inhibitory neurons" = "#80BA8A",
"Microglia" = "#9CD1C8",
"MSN" = "#EEC79F",
"Oligodendrocyte" = "#F1DFA4",
"OPC" = "#CC88B0" ,
"Vascular" = "#D9BDDB"
)
platform_colors <- c(
"Brain1-5 NV" = "#E58579",
"Brain1-5 SF" = "#6BB7CA"
)
# Define parameters
base_theme <- theme_prism(base_size = 10) +
theme(
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
plot.margin = margin(5, 5, 5, 5)
)
legend_guide <- guide_legend(
override.aes = list(size = 5),
title.theme = element_text(size = 15, face = "bold"),
label.theme = element_text(size = 12, face = "bold")
)
# Load the data and plot figure
load("10b_2l.RData")
p1 <- DimPlot(merged_10Brain, reduction = "umap", group.by = "cell_type",label = FALSE, label.size = 4) +
scale_color_manual(values = celltype_colors) +
base_theme +
NoLegend() +
ggtitle(NULL)
merged_10Brain$platform_group <- ifelse(grepl("NV", merged_10Brain$orig.ident), "Brain1-5 NV", "Brain1-5 SF")
p2 <- DimPlot(merged_10Brain, reduction = "umap", group.by = "platform_group",label = FALSE) +
scale_color_manual(values = platform_colors) +
base_theme +
guides(color = legend_guide) +
ggtitle(NULL)
p <- plot_list(p1, p2, ncol = 2)
p
# Define parameters
base_theme <- theme_minimal() +
theme_prism(base_size = 20) +
theme(
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
plot.title = element_text(size = 18, face = "bold", hjust = 0.5)
)
legend_guide <- guide_legend(
override.aes = list(size = 6),
title.theme = element_text(size = 17, face = "bold"),
label.theme = element_text(size = 17, face = "bold"),
ncol = 2
)
# Load the data and plot figure
cell_data <- merged_10Brain@meta.data
coords <- function(df) {
data.frame(
x = df[["x"]],
y = df[["y"]],
cell_type = df[["cell_type"]]
)
}
plot_data_nv <- coords(cell_data[cell_data[["orig.ident"]] == "Brain1 NV", ])
plot_data_sf <- coords(cell_data[cell_data[["orig.ident"]] == "Brain1 SF", ])
p1 <- ggplot(plot_data_nv, aes(x = x, y = y, color = cell_type)) +
geom_point(size = 0.5, show.legend = TRUE) +
labs(title = "Brain1 NV", color = "Cell Type") +
coord_fixed(ratio = 1) +
base_theme +
scale_color_manual(values = celltype_colors) +
guides(color = legend_guide)
p2 <- ggplot(plot_data_sf, aes(x = x, y = y, color = cell_type)) +
geom_point(size = 0.5, show.legend = TRUE) +
labs(title = "Brain1 SF", color = "Cell Type") +
coord_fixed(ratio = 1) +
base_theme +
scale_color_manual(values = celltype_colors) +
guides(color = legend_guide)
p <- plot_list(p1, p2, ncol = 1)
p
# Load the library
library(MetaNeighbor)
library(dplyr)
library(tidyr)
# Load the data
sce <- as.SingleCellExperiment(merged_10Brain, assay = "SCT")
hvgs <- head(merged_10Brain@assays[["SCT"]]@var.features, 3000)
study_id <- sce@colData[["orig.ident"]]
cell_type <- sce@colData[["cell_type"]]
Aurocs_matrix <- MetaNeighborUS(
var_genes = hvgs,
dat = sce,
study_id = study_id,
cell_type = cell_type,
fast_version = TRUE
)
auroc_df <- as.data.frame(as.table(Aurocs_matrix)) %>%
separate(Var1, into = c("Sample", "CellType"), sep = "\\|") %>%
separate(Var2, into = c("Sample_2", "CellType_2"), sep = "\\|") %>%
rename(AUROC = Freq) %>%
mutate(
Sample = factor(gsub(".*\\s(NV|SF)$", "\\1", Sample), levels = c("NV", "SF")),
Sample_2 = factor(gsub(".*\\s(NV|SF)$", "\\1", Sample_2), levels = c("NV", "SF")),
CellType = factor(CellType, levels = names(celltype_colors))
)
# Show the figure
p <- ggplot(auroc_df, aes(x = Sample, y = AUROC, fill = CellType)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_manual(values = celltype_colors) +
theme_minimal() +
theme_prism(base_size = 22) +
theme(
plot.margin = margin(25, 25, 25, 25),
axis.title.x = element_blank()
) +
labs(y = "AUROC") +
NoLegend()
p
# Load the data
Idents(merged_10Brain) <- merged_10Brain@meta.data$cell_type
selected_genes <- c("Ptprb", "Ctss", "Slc1a3", "Lhfpl3", "Mbp", "Pde10a", "Gad2", "Slc17a7")
plot_data <- DotPlot(merged_10Brain, features = selected_genes)$data
celltype_order <- c(
"Excitatory neurons",
"Inhibitory neurons",
"MSN",
"Oligodendrocyte",
"OPC",
"Astrocytes",
"Microglia",
"Vascular"
)
plot_data$id <- factor(plot_data$id, levels = celltype_order)
plot_data$combined_score <- plot_data$avg.exp.scaled * (plot_data$pct.exp/100)
# Show the figure
ggplot(plot_data, aes(x = features.plot, y = id,
size = combined_score,
color = avg.exp.scaled)) +
geom_point() +
scale_size_continuous(range = c(2, 15)) +
scale_color_gradient(low = "#FFFFFF",
high = "#AD1C42",
breaks = c(0, max(plot_data$avg.exp.scaled)/2, max(plot_data$avg.exp.scaled)),
labels = function(x) sprintf("%.1f", x)) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 30,
hjust = 1,
size = 26,
face = "bold",
color = "#333333"),
axis.text.y = element_text(size = 26,
face = "bold",
color = "#333333"),
legend.text = element_text(size = 22,
face = "bold",
color = "#333333"),
legend.title = element_text(size = 24,
face = "bold",
color = "#333333"),
axis.title = element_blank(),
legend.position = "bottom",
plot.margin = unit(c(0.8, 2, 1.2, 2), "cm"),
panel.grid.major = element_line(color = "grey90"),
panel.grid.minor = element_blank(),
legend.spacing.x = unit(1, 'cm'),
legend.box.margin = margin(-10, -300, 0, -300)
) +
coord_flip() +
guides(
size = guide_legend(title = "Expression Score",
title.position = "top",
title.hjust = 0.5,
nrow = 1),
color = guide_colorbar(title = "Scaled Expression",
title.position = "top",
title.hjust = 0.5,
barwidth = 15,
barheight = 1,
nrow = 1,
ticks.linewidth = 1,
label.theme = element_text(size = 20,
face = "bold",
color = "#333333"))
)
# package version
library(sessioninfo)
pi <- package_info(pkgs = "attached")
pi_df <- as.data.frame(pi)[, c("package", "loadedversion", "source")]
pi_df
## package loadedversion source
## aplot aplot 0.2.8 CRAN (R 4.3.3)
## dplyr dplyr 1.1.4 CRAN (R 4.3.3)
## ggfun ggfun 0.1.8 CRAN (R 4.3.3)
## ggplot2 ggplot2 3.5.2 CRAN (R 4.3.3)
## ggprism ggprism 1.0.6 CRAN (R 4.3.3)
## MetaNeighbor MetaNeighbor 1.22.0 Bioconductor
## sessioninfo sessioninfo 1.2.3 CRAN (R 4.3.3)
## Seurat Seurat 5.1.0 CRAN (R 4.3.3)
## SeuratObject SeuratObject 5.1.0 CRAN (R 4.3.3)
## sp sp 2.2-0 CRAN (R 4.3.3)
## tidyr tidyr 1.3.1 CRAN (R 4.3.1)