Author

Hu Zheng

Published

2024-12-01

Code
library(Seurat)
library(tidyverse)
library(aplot)
source('bin/Palettes.R')
Code
seu.harmony <- readRDS('../data/seu.harmony.rds')
seu.harmony.metadata <- readRDS('../data/seu.harmony.metadata.rds')
seu.harmony@meta.data <- seu.harmony.metadata

6.1 Figure_S1A

Code
seu <- seu.harmony
seu$SubType <- factor(seu$SubType, levels = names(col_SubType))
seu$orig.ident <- factor(seu$orig.ident, levels = c("P1","P4","P10","Adult"))
Figure_S1A <- 
  DimPlot(seu,
          reduction = 'umap', group.by = "SubType", label = F, split.by = 'orig.ident',
          ncol = 4, cols = col_SubType) +
  theme(axis.line = element_blank(), axis.ticks = element_blank(), 
        axis.text = element_blank(), plot.title = element_text(size = 30)) +
  labs(x='', y='', title = "") +
  coord_fixed()
Figure_S1A

Code
ggsave("../../Figure/FigureS1/Figure_S1A.pdf", plot = Figure_S1A,
       height = 6, width = 18, units = "in")

6.2 Figure_S1B

Code
# cell type
df_type <- data.frame(
  'SubType' = names(col_SubType),
  'Color' = as.character(col_SubType)
)
df_type$SubType <- factor(df_type$SubType, levels=names(col_SubType))
p1 <- ggplot(df_type, aes(x=SubType, y=1, fill=SubType)) + 
  geom_tile() +
  scale_fill_manual(values = col_SubType, name="Cell Type") +
  theme_void() +
  NoLegend()

# dot plot
seu <- seu.harmony
seu$SubType <- factor(seu$SubType, levels = names(col_SubType))
Idents(seu) <- 'SubType'
p2 <- DotPlot(
  seu,
  features = c('Sox11','Cd24a','Cux2','Calb1','Rorb','Deptor','Oprk1','Pou3f1',
               'Npr3','Tshz2','Syt6',
               'Lamp5','Pvalb','Sst','Vip',
               'Top2a','Gja1','Flt1','C1qc','Ptgds','Pdgfra'),
  group.by = 'SubType',
  col.min=0, col.max=2, dot.scale = 8) +
  coord_flip() +
  scale_x_discrete(limits=rev) +
  scale_color_gradientn(colours = c("lightblue3", "lightblue", "white", "red", "red4")) +
  theme_minimal() +
  theme(axis.text.x = element_blank(),
        axis.title.x = element_blank(), axis.title.y = element_blank())

# cell prob
df <- seu.harmony@meta.data[,c("orig.ident","SubType")]
df <- as.data.frame.array(table(df$orig.ident, df$SubType))
df_long <- as.data.frame(apply(df, 2, function(x){x/sum(x)}))
df_long$Time <- rownames(df_long)
df_long <- pivot_longer(df_long, !Time, names_to = "Subtype", values_to = "Prob")
df_long$Time <- factor(df_long$Time, levels = rev(c("P1","P4","P10","Adult")))

p3 <- 
  ggplot(df_long, aes(x = Subtype, y = Prob, fill = Time)) + 
  geom_bar(stat = "identity", width = 1) +
  scale_fill_manual(values = col_Time) +
  labs(x='', y='', title='') +
  theme_minimal(base_size = 15) +
  theme(panel.grid = element_blank(), plot.title = element_text(hjust = 0.5),
        legend.position = "none",
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 90, hjust = 1))

Figure_S1B <- 
  p2 %>%
  insert_top(p1, height = 0.02) %>%
  insert_bottom(p3, height = 0.3)

Figure_S1B

Code
ggsave("../../Figure/FigureS1/Figure_S1B.pdf", plot = Figure_S1B,
       height = 8, width = 14, units = "in")

6.3 Figure_S1C

Code
seu <- subset(
  seu.harmony, 
  cells = colnames(seu.harmony)[seu.harmony$SubType %in% names(col_SubType)[1:8]])
seu$SubType <- factor(seu$SubType, levels = names(col_SubType)[1:8])
gene_list <- c("Cd24a","Slc17a7","Cux2","Rorb","Etv1","Npy")

Figure_S1C <- 
  VlnPlot(seu, features = gene_list, group.by = "SubType", fill.by ="ident",
          cols = as.character(col_SubType[1:8]),
          stack = TRUE, flip = TRUE) +
  theme(legend.position = "none", axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  labs(x="")
Figure_S1C

Code
ggsave("../../Figure/FigureS1/Figure_S1C.pdf", plot = Figure_S1C,
       height = 6.5, width = 10, units = "in")

6.4 Figure_S1D

Code
knitr::include_graphics("./images/Figure_S1D.jpg", dpi = 300)

6.5 Figure_S1E

Code
column <- c("x_rotated","y_rotated","Im.L2.3.IT","Im.L4.5.IT","Im.L5.IT","Im.L6.IT","L2.3.IT","L4.5.IT","L5.IT","L6.IT","L5.PT","L5.NP","L6.CT","Lamp5","Pvalb","Sst","Vip","NPC","Astro","Endo","Microglia","Oligo","OPC")
P1_cell2loc <- read.csv("../data/Figure1/P1_cell2location.csv", row.names = 1)
P1_cell2loc <- P1_cell2loc[,column]
colnames(P1_cell2loc) <- c("x_rotated","y_rotated",names(col_SubType))
P1_cell2loc$SubType <- as.character(apply(P1_cell2loc[,names(col_SubType)], 1, function(x){
  names(which.max(x))
}))
data <- P1_cell2loc

plist <- list()
for (i in 1:length(col_SubType)){
  subtype_i <- names(col_SubType)[i]
  df_i <- data.frame(
    x = data$x_rotated,
    y = data$y_rotated,
    col = data[,subtype_i]
  )
  #df_i$col[!data$SubType==subtype_i] <- 0
  df_i$col[df_i$col>1] <- 1
  df_i$col[df_i$col<0.05] <- 0
  
  plist[[i]] <- 
    ggplot(df_i, aes(x=x, y=y, color=col)) +
    geom_point(size=2) +
    scale_color_gradient(low = "#f7f7f7", high=col_SubType[i],
                          na.value = "#f7f7f7",
                          limits = c(0,max(df_i$col)),
                         #limits = c(0,1),
                          breaks = c(0,max(df_i$col))) +
    coord_fixed() +
    theme_void() +
    theme(legend.position = "none")
  subtype_i <- gsub("/","",subtype_i)
  #ggsave(paste("../../Figure/Figure1/Figure_1H/",i,".P1_",subtype_i,".png",sep=""), 
  #       plot = plist[[i]], height = 5, width = 5, units = "in")
}

plist[[10]]

6.6 Figure_S1F

Code
column <- c("x_rotated","y_rotated","Im.L2.3.IT","Im.L4.5.IT","Im.L5.IT","Im.L6.IT","L2.3.IT","L4.5.IT","L5.IT","L6.IT","L5.PT","L5.NP","L6.CT","Lamp5","Pvalb","Sst","Vip","NPC","Astro","Endo","Microglia","Oligo","OPC")
P77_cell2loc <- read.csv("../data/Figure1/P77_cell2location.csv", row.names = 1)
P77_cell2loc <- P77_cell2loc[,column]
colnames(P77_cell2loc) <- c("x_rotated","y_rotated",names(col_SubType))
P77_cell2loc$SubType <- as.character(apply(P77_cell2loc[,names(col_SubType)], 1, function(x){
  names(which.max(x))
}))
data <- P77_cell2loc

plist <- list()
for (i in 1:length(col_SubType)){
  subtype_i <- names(col_SubType)[i]
  df_i <- data.frame(
    x = data$x_rotated,
    y = data$y_rotated,
    col = data[,subtype_i]
  )
  #df_i$col[!data$SubType==subtype_i] <- 0
  df_i$col[df_i$col>1] <- 1
  df_i$col[df_i$col<0.05] <- 0
  plist[[i]] <- 
    ggplot(df_i, aes(x=x, y=y, color=col)) +
    geom_point(size=0.8) +
    scale_color_gradient(low = "#f7f7f7", high=col_SubType[i],
                          na.value = "#f7f7f7",
                          limits = c(0,max(df_i$col)), 
                          breaks = c(0,max(df_i$col))) +
    coord_fixed() +
    theme_void() +
    theme(legend.position = "none")
  subtype_i <- gsub("/","",subtype_i)
  #ggsave(paste("../../Figure/Figure1/Figure_1J/",i,".P77_",subtype_i,".png",sep=""), 
  #       plot = plist[[i]], height = 5, width = 5, units = "in")
}
plist[[10]]