Pipseq chemistry kit comparison Sample NPID control female NA05-055

Libraries & paths

library(dplyr)
library(Seurat)
library(patchwork)
library(knitr)
library(dittoSeq)
library(reshape2)
Sys.setenv(RSTUDIO_PANDOC="/usr/local/biotools/pandoc/3.1.2/bin")

sampleID <- c("v4_Miltenyi")
sample_color.panel <- c("gold")
color.panel <- dittoColors()

Read in object

# read object
dataObject <- readRDS(file = paste0("../../../rObjects/", sampleID, ".filtered.rds"))
markers.strict <- readRDS(file = paste0("../../../rObjects/", 
                          sampleID, "_FindAllMarkers_strict_logFC1_FDR0.05.rds"))

Unannotated

UMAP

ditto_umap <- dittoDimPlot(object = dataObject,
             var = "seurat_clusters",
             reduction.use = "umap",
             do.label = TRUE,
             labels.highlight = TRUE)
ditto_umap

Nuclei count per cluster

count_per_cluster <- FetchData(dataObject,
                               vars = c("ident", "orig.ident")) %>%
  dplyr::count(ident, orig.ident) %>%
  tidyr::spread(ident, n)
count_per_cluster
##   orig.ident    0    1    2    3    4    5   6   7   8   9  10  11  12  13  14
## 1 v4Miltenyi 2057 1953 1775 1334 1277 1205 872 827 522 464 432 378 354 223 193
##    15  16  17
## 1 168 129 123
count_melt <- reshape2::melt(count_per_cluster)
colnames(count_melt) <- c("ident", "cluster", "number of nuclei")
count_max <- count_melt[which.max(count_melt$`number of nuclei`), ]
count_max_value <- count_max$`number of nuclei`
cellmax <- count_max_value + 200 # so that the figure doesn't cut off the text
count_bar <- ggplot(count_melt, aes(x = factor(cluster), y = `number of nuclei`, fill = `ident`)) +
  geom_bar(
    stat = "identity",
    colour = "black",
    width = 1,
    position = position_dodge(width = 0.8)
  ) +
  geom_text(
    aes(label = `number of nuclei`),
    position = position_dodge(width = 0.9),
    vjust = -0.25,
    angle = 45,
    hjust = -.01
  ) +
  theme_classic() + scale_fill_manual(values = sample_color.panel) +
  ggtitle("Number of nuclei per cluster") +  xlab("cluster") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_y_continuous(limits = c(0, cellmax))
count_bar

Cluster tree

dataObject <- BuildClusterTree(
  object = dataObject,
  dims = 1:30,
  reorder = FALSE,
  reorder.numeric = FALSE
)

tree <- dataObject@tools$BuildClusterTree
tree$tip.label <- paste0("Cluster ", tree$tip.label)
nClusters <- length(tree$tip.label)

tree_graph <- ggtree::ggtree(tree, aes(x, y)) +
  scale_y_reverse() +
  ggtree::geom_tree() +
  ggtree::theme_tree() +
  ggtree::geom_tiplab(offset = 1) +
  ggtree::geom_tippoint(color = color.panel[1:nClusters],
                        shape = 16,
                        size = 5) +
  coord_cartesian(clip = 'off') +
  theme(plot.margin = unit(c(0, 2.5, 0, 0), 'cm'))
tree_graph

Violins - Canonical cell-type markers

Markers obtained from dropviz

# Astrocytes
VlnPlot(dataObject,
        features = c("AQP4", "GJA1", "CLU", "GFAP"))

# Endothelial
VlnPlot(dataObject,
        features = c("CLDN5", "ADGRF5", "FLT1"))

# Fibroblast-Like_Dcn
VlnPlot(dataObject,
        features = c("COL1A1", "COL1A2", "DCN"))

# Microglia / Marchophage 
VlnPlot(dataObject,
        features = c("C1QA", "C1QC", "C1QB"))

# Microglia / Marchophage 
VlnPlot(dataObject,
        features = c( "HEXB", "TMEM119", "ITGAM", "TYROBP","P2RY12", "AIF1"))

# Neurons
VlnPlot(dataObject,
        features = c("RBFOX3", "SNAP25","SYT1", "GAD1", "GAD2"))

# Oligodendrocyte
VlnPlot(dataObject,
        features = c("PLP1","MBP", "MOG"))

# OPC
VlnPlot(dataObject,
        features = c("OLIG1","PDGFRA", "VCAN", "TNR"))

# Smooth muscle 
VlnPlot(dataObject,
        features = c("ACTA2","RGS5", "VTN", "MYL5"))

Percent cell type - Canonical cell-type markers

# astrocyte
dataObject[["percent.astrocyte"]] <- PercentageFeatureSet(dataObject, 
                                     features = c("CLU", "GFAP", "AQP4", "GJA1"))
# endothelial
dataObject[["percent.endothelial"]] <- PercentageFeatureSet(dataObject, 
                                       features = c("CLDN5", "ADGRF5", "FLT1"))
# fibroblast 
dataObject[["percent.fibroblast"]] <- PercentageFeatureSet(dataObject, 
                                      features = c("COL1A1", "COL1A2", "DCN"))
# microglia
dataObject[["percent.microglia"]] <- PercentageFeatureSet(dataObject, 
                                     features = c("HEXB", "C1QA", "C1QC", "C1QB", 
                                     "TMEM119", "ITGAM", "TYROBP","P2RY12", "AIF1")) 
# neuron 
dataObject[["percent.neurons"]] <- PercentageFeatureSet(dataObject, 
                                   features = c("RBFOX3", "SNAP25","SYT1", "GAD1", "GAD2"))
# oligodendrocyte
dataObject[["percent.oligodendrocyte"]] <- PercentageFeatureSet(dataObject, 
                                           features = c("PLP1","MBP", "MOG"))
# oligodendrocyte precursor cells
dataObject[["percent.opc"]] <- PercentageFeatureSet(dataObject, 
                               features = c("OLIG1","PDGFRA", "VCAN", "TNR"))
# smooth muscle 
dataObject[["percent.smooth"]] <- PercentageFeatureSet(dataObject, 
                                  features = c("ACTA2","RGS5", "VTN", "MYL5"))

Feature plot percent cell type - Canonical cell-type markers

# astrocyte
FeaturePlot(dataObject, features = "percent.astrocyte", label = TRUE)  

# endothelial
FeaturePlot(dataObject, features = "percent.endothelial", label = TRUE) 

# fibroblast
FeaturePlot(dataObject, features = "percent.fibroblast", label = TRUE) 

# microglia
FeaturePlot(dataObject, features = "percent.microglia", label = TRUE)  

# neuron 
FeaturePlot(dataObject, features = "percent.neurons", label = TRUE) 

# oligodendrocyte
FeaturePlot(dataObject, features = "percent.oligodendrocyte", label = TRUE) 

# oligodendrocyte precursor cells
FeaturePlot(dataObject, features = "percent.opc", label = TRUE)  

# smooth
FeaturePlot(dataObject, features = "percent.smooth", label = TRUE) 

Markers per cluster

Get markers for each cluster

# unique clusters variable
unique_clusters <- unique(markers.strict$cluster)

# empty list to store individual cluster data frames
cluster_list <- list()

# loop through each cluster and create a data frame
for (i in unique_clusters) {
  cluster_name <- paste0("cluster", i)
  cluster_data <- markers.strict[markers.strict$cluster == i, ]
  assign(cluster_name, cluster_data)
  cluster_list[[cluster_name]] <- cluster_data
}

Feature plot

# UMAP showing the expression of select features
umap_feature <-
  FeaturePlot(dataObject,
              features = c("TYROBP", "MOG", "AQP4", "RBFOX3"))
umap_feature

Cluster Annotation

Cluster 0 - oligodendrocyte

# Number of cells per condition
count_per_cluster[,c(1,2)]
##   orig.ident    0
## 1 v4Miltenyi 2057
# UMAP with only cluster 0
DimPlot(object = subset(dataObject, seurat_clusters == "0"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[1])

VlnPlot(dataObject,
        features = cluster0$gene[1:10],
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster0$gene[1:10]
##  [1] "CNP"       "LINC00844" "APOD"      "LINC01608" "SUN2"      "AMER2"    
##  [7] "FTH1"      "VWA1"      "MBP"       "PLP1"

Cluster 1 - noise

count_per_cluster[,c(1,3)]
##   orig.ident    1
## 1 v4Miltenyi 1953
DimPlot(object = subset(dataObject, seurat_clusters == "1"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[2])

VlnPlot(dataObject,
        features = cluster1$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster1$gene[1:10]
##  [1] "LINC01608"    "DYSF"         "LAMA2"        "LINC01170"    "KIF19"       
##  [6] "SVEP1"        "CR1"          "RP4-537K23.4" "LINC02073"    "RP11-50D16.4"

Cluster 2 - oligodendrocyte

count_per_cluster[,c(1,4)]
##   orig.ident    2
## 1 v4Miltenyi 1775
DimPlot(object = subset(dataObject, seurat_clusters == "2"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[3])

VlnPlot(dataObject,
        features = cluster2$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster2$gene[1:10]
##  [1] "SLC5A11"      "ANKRD18A"     "LRRC63"       "SAMD12"       "LINC00609"   
##  [6] "RASGRF1"      "RP11-141F7.1" "RP1-223B1.1"  "SEC14L5"      "LDB3"

Cluster 3 - noise

count_per_cluster[,c(1,4)]
##   orig.ident    2
## 1 v4Miltenyi 1775
DimPlot(object = subset(dataObject, seurat_clusters == "3"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols =  color.panel[4])

VlnPlot(dataObject,
        features = cluster3$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster3$gene[1:10]
##  [1] "FGFR1"    "SH3RF1"   "GADD45B"  "ITPKB"    "UHRF2"    "FNIP2"   
##  [7] "SH3PXD2B" "GTF2H2B"  "PLA2G4C"  "CAMK2D"

Cluster 4 - noise

count_per_cluster[,c(1,5)]
##   orig.ident    3
## 1 v4Miltenyi 1334
DimPlot(object = subset(dataObject, seurat_clusters == "4"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[5])

VlnPlot(dataObject,
        features = cluster4$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster4$gene[1:10]
##  [1] "SLC5A11"  "MARCKSL1" "SPP1"     "TUBA1A"   "S100B"    "CNP"     
##  [7] "STMN1"    "RASGRF1"  "TF"       "PLP1"

Cluster 5 - noise

count_per_cluster[,c(1,6)]
##   orig.ident    4
## 1 v4Miltenyi 1277
DimPlot(object = subset(dataObject, seurat_clusters == "5"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[6])

VlnPlot(dataObject,
        features = cluster5$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster5$gene[1:10]
##  [1] "CCDC200"   "LINC00685" "CERS4"     "SLCO5A1"   "SAMHD1"    "ATAD3C"   
##  [7] "LINC00463" "PRDM1"     "MMP17"     "COL19A1"

Cluster 6 - oligodendrocyte

count_per_cluster[,c(1,7)]
##   orig.ident    5
## 1 v4Miltenyi 1205
DimPlot(object = subset(dataObject, seurat_clusters == "6"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = "#CC79A7")

VlnPlot(dataObject,
        features = cluster6$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster6$gene[1:10]
##  [1] "QDPR"         "CD9"          "AMD1"         "TMTC4"        "SUN2"        
##  [6] "H3-3B"        "SFRP1"        "SYT11"        "RP4-613B23.1" "PSAP"

Cluster 7 - noise

count_per_cluster[,c(1,8)]
##   orig.ident   6
## 1 v4Miltenyi 872
DimPlot(object = subset(dataObject, seurat_clusters == "7"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[7])

VlnPlot(dataObject,
        features = cluster7$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster7$gene[1:10]
##  [1] "CNDP1"       "PLA2G4C"     "MIDN"        "IL6R"        "IRAK2"      
##  [6] "ARRB1"       "AC005609.16" "LINC02197"   "MAP2K3"      "SPRED3"

Cluster 8 - astrocyte

count_per_cluster[,c(1,9)]
##   orig.ident   7
## 1 v4Miltenyi 827
DimPlot(object = subset(dataObject, seurat_clusters == "8"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[8])

VlnPlot(dataObject,
        features = cluster8$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster8$gene[1:10]
##  [1] "GLIS3"       "CD44"        "FAM189A2"    "GFAP"        "ADCY2"      
##  [6] "RFX4"        "RP11-6L16.1" "WWC1"        "ABLIM1"      "AQP4"

Cluster 9 - microglia

count_per_cluster[,c(1,10)]
##   orig.ident   8
## 1 v4Miltenyi 522
DimPlot(object = subset(dataObject, seurat_clusters == "9"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[9])

VlnPlot(dataObject,
        features = cluster9$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster9$gene[1:10]
##  [1] "ADAM28"   "SLC11A1"  "DOCK8"    "LRMDA"    "ARHGAP24" "DENND3"  
##  [7] "APBB1IP"  "PTPRC"    "MEF2C"    "ST6GAL1"

Cluster 10 - neuron

count_per_cluster[,c(1,11)]
##   orig.ident   9
## 1 v4Miltenyi 464
DimPlot(object = subset(dataObject, seurat_clusters == "10"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[10])

VlnPlot(dataObject,
        features = cluster10$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster10$gene[1:10]
##  [1] "DDIT3"          "FOS"            "EGR1"           "GADD45B"       
##  [5] "HSP90B1"        "RP11-181L23.10" "NAMPT"          "FGFR1"         
##  [9] "ATF3"           "CREB5"

Cluster 11 - polydendrocyte

count_per_cluster[,c(1,12)]
##   orig.ident  10
## 1 v4Miltenyi 432
DimPlot(object = subset(dataObject, seurat_clusters == "11"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[11])

VlnPlot(dataObject,
        features = cluster11$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster11$gene[1:10]
##  [1] "TNR"    "VCAN"   "MMP16"  "PTPRZ1" "CA10"   "LHFPL3" "MEGF11" "FGF14" 
##  [9] "DSCAM"  "LUZP2"

Cluster 12 - astrocyte

count_per_cluster[,c(1,13)]
##   orig.ident  11
## 1 v4Miltenyi 378
DimPlot(object = subset(dataObject, seurat_clusters == "12"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[12])

VlnPlot(dataObject,
        features = cluster12$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster12$gene[1:10]
##  [1] "IRAG1"    "SLC1A2"   "BMPR1B"   "FAM189A2" "AQP4"     "RFX4"    
##  [7] "ADGRV1"   "RYR3"     "SLC14A1"  "ADCY2"

Cluster 13 - neuron

count_per_cluster[,c(1,14)]
##   orig.ident  12
## 1 v4Miltenyi 354
DimPlot(object = subset(dataObject, seurat_clusters == "13"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[13])

VlnPlot(dataObject,
        features = cluster13$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster13$gene[1:10]
##  [1] "RP11-909M7.3" "PAK3"         "MEG3"         "MYT1L"        "CELF4"       
##  [6] "GRIP1"        "GRIN2B"       "KCNC2"        "GRIA1"        "CACNA1B"

Cluster 14 - neuron

count_per_cluster[,c(1,15)]
##   orig.ident  13
## 1 v4Miltenyi 223
DimPlot(object = subset(dataObject, seurat_clusters == "14"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[14])

VlnPlot(dataObject,
        features = cluster14$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster14$gene[1:10]
##  [1] "RALYL"        "RP11-909M7.3" "NELL2"        "MEG3"         "SNAP25"      
##  [6] "LRFN5"        "SCN2A"        "UNC80"        "GRM5"         "SLC4A10"

Cluster 15 - neuron

count_per_cluster[,c(1,16)]
##   orig.ident  14
## 1 v4Miltenyi 193
DimPlot(object = subset(dataObject, seurat_clusters == "15"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[15])

VlnPlot(dataObject,
        features = cluster15$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster15$gene[1:10]
##  [1] "HS3ST4"       "CELF4"        "CTD-2337L2.1" "GABRB2"       "MYT1L"       
##  [6] "GABRG3"       "SCN2A"        "PAK3"         "MIR137HG"     "MIAT"

Cluster 16 - fibroblast-like

count_per_cluster[,c(1,17)]
##   orig.ident  15
## 1 v4Miltenyi 168
DimPlot(object = subset(dataObject, seurat_clusters == "16"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[16])

VlnPlot(dataObject,
        features = cluster16$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster16$gene[1:10]
##  [1] "EBF1"   "NID1"   "CFH"    "LEF1"   "DCN"    "COL1A2" "IFITM1" "NR2F2" 
##  [9] "PDLIM1" "FMO2"

Cluster 17 - noise

count_per_cluster[,c(1,18)]
##   orig.ident  16
## 1 v4Miltenyi 129
DimPlot(object = subset(dataObject, seurat_clusters == "17"),
        reduction = "umap", 
        label = TRUE,
        label.box = TRUE,
        label.size = 3,
        repel = TRUE,
        cols = color.panel[17])

VlnPlot(dataObject,
        features = cluster17$gene[1:10],
        cols = color.panel,
        stack = TRUE,
        flip = TRUE,
        split.by = "seurat_clusters")

cluster17$gene[1:10]
##  [1] "ZSCAN31"      "SLC5A11"      "RP11-141F7.1" "LRRC63"       "SAMD12"      
##  [6] "LINC00609"    "RP1-223B1.1"  "PLEKHG1"      "LINC01877"    "GPX6"

Assign identities

Individual

dataObject.annotated <- RenameIdents(object = dataObject, 
                               "0" = "oligodendrocyte 1",
                               "1" = "noise 1",
                               "2" = "oligodendrocyte 2",
                               "3" = "noise 2",
                               "4" = "noise 3",
                               "5" = "noise 4",
                               "6" = "oligodendrocyte/polydendrocyte",
                               "7" = "noise 5",
                               "8" = "astrocyte 1",
                               "9" = "microglia",
                               "10" = "neuron 1",
                               "11" = "polydendrocyte",
                               "12" = "astrocyte 2",
                               "13" = "neuron 2",
                               "14" = "neuron 3",
                               "15" = "neuron 4",
                               "16" = "fibroblast-like",
                               "17" = "noise 6")
dataObject.annotated$individual_clusters <- factor(Idents(dataObject.annotated))

UMAP_ind <- dittoDimPlot(object = dataObject.annotated,
             var = "individual_clusters",
             reduction.use = "umap",
             do.label = TRUE,
             labels.highlight = TRUE)
UMAP_ind

## png 
##   2

Nuclei count per cluster

count_per_cluster <- FetchData(dataObject.annotated,
                               vars = c("ident", "orig.ident")) %>%
  dplyr::count(ident, orig.ident) %>%
  tidyr::spread(ident, n)
count_per_cluster
##   orig.ident oligodendrocyte 1 noise 1 oligodendrocyte 2 noise 2 noise 3
## 1 v4Miltenyi              2057    1953              1775    1334    1277
##   noise 4 oligodendrocyte/polydendrocyte noise 5 astrocyte 1 microglia neuron 1
## 1    1205                            872     827         522       464      432
##   polydendrocyte astrocyte 2 neuron 2 neuron 3 neuron 4 fibroblast-like noise 6
## 1            378         354      223      193      168             129     123
count_melt <- reshape2::melt(count_per_cluster)
colnames(count_melt) <- c("ident", "cluster", "number of nuclei")
count_max <- count_melt[which.max(count_melt$`number of nuclei`), ]
count_max_value <- count_max$`number of nuclei`
cellmax <- count_max_value + 500 # so that the figure doesn't cut off the text
count_bar <- ggplot(count_melt, aes(x = factor(cluster), y = `number of nuclei`, fill = `cluster`)) +
  geom_bar(
    stat = "identity",
    colour = "black",
    width = 1,
    position = position_dodge(width = 0.8)
  ) +
  geom_text(
    aes(label = `number of nuclei`),
    position = position_dodge(width = 0.9),
    vjust = -0.25,
    angle = 45,
    hjust = -.01
  ) +
  theme_classic() + scale_fill_manual(values = color.panel) +
  ggtitle("Number of nuclei per cluster") +  xlab("cluster") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_y_continuous(limits = c(0, cellmax))
count_bar

## png 
##   2

DotPlot

markers.to.plot <-
  c(
"CLU", 
"GFAP", 
"AQP4", 
"GJA1",
"CLDN5", 
"ADGRF5", 
"FLT1",
"COL1A1", 
"COL1A2", 
"DCN",
"HEXB", 
"C1QA", 
"C1QC", 
"C1QB", 
"TMEM119", 
"ITGAM", 
"TYROBP",
"P2RY12", 
"AIF1",
"RBFOX3", 
"SNAP25",
"SYT1", 
"GAD1", 
"GAD2",
"PLP1",
"MBP", 
"MOG",
"OLIG1",
"PDGFRA", 
"VCAN", 
"TNR",
"ACTA2",
"RGS5", 
"VTN", 
"MYL5"
  )

dot_ind <- DotPlot(dataObject, 
                   features = markers.to.plot, 
                   cluster.idents = TRUE,
                   dot.scale = 8) + RotatedAxis()
dot_ind

## png 
##   2

Merged

dataObject.annotated <- RenameIdents(object = dataObject, 
                               "0" = "oligodendrocyte",
                               "1" = "noise",
                               "2" = "oligodendrocyte",
                               "3" = "noise",
                               "4" = "noise",
                               "5" = "noise",
                               "6" = "oligodendrocyte",
                               "7" = "noise",
                               "8" = "astrocyte",
                               "9" = "microglia",
                               "10" = "neuron",
                               "11" = "polydendrocyte",
                               "12" = "astrocyte",
                               "13" = "neuron",
                               "14" = "neuron",
                               "15" = "neuron",
                               "16" = "fibroblast-like",
                               "17" = "noise")
dataObject.annotated$annotated_clusters <- factor(Idents(dataObject.annotated))
Idents(dataObject.annotated) <- "annotated_clusters"

UMAP_merge <- dittoDimPlot(object = dataObject.annotated,
             var = "annotated_clusters",
             reduction.use = "umap",
             do.label = TRUE,
             labels.highlight = TRUE)
UMAP_merge

## png 
##   2

Nuclei count per cluster

count_per_cluster <- FetchData(dataObject.annotated,
                               vars = c("ident", "orig.ident")) %>%
  dplyr::count(ident, orig.ident) %>%
  tidyr::spread(ident, n)
count_per_cluster
##   orig.ident oligodendrocyte noise astrocyte microglia neuron polydendrocyte
## 1 v4Miltenyi            4704  6719       876       464   1016            378
##   fibroblast-like
## 1             129
count_melt <- reshape2::melt(count_per_cluster)
colnames(count_melt) <- c("ident", "cluster", "number of nuclei")
count_max <- count_melt[which.max(count_melt$`number of nuclei`), ]
count_max_value <- count_max$`number of nuclei`
cellmax <- count_max_value + 500 # so that the figure doesn't cut off the text
count_bar <- ggplot(count_melt, aes(x = factor(cluster), y = `number of nuclei`, fill = `cluster`)) +
  geom_bar(
    stat = "identity",
    colour = "black",
    width = 1,
    position = position_dodge(width = 0.8)
  ) +
  geom_text(
    aes(label = `number of nuclei`),
    position = position_dodge(width = 0.9),
    vjust = -0.25,
    angle = 45,
    hjust = -.01
  ) +
  theme_classic() + scale_fill_manual(values = color.panel) +
  ggtitle("Number of nuclei per cluster") +  xlab("cluster") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_y_continuous(limits = c(0, cellmax))
count_bar

## png 
##   2

Relative abundance

relative_abundance <- dataObject.annotated@meta.data %>%
  group_by(annotated_clusters, orig.ident) %>%
  dplyr::count() %>%
  group_by(orig.ident) %>%
  dplyr::mutate(percent = 100 * n / sum(n)) %>%
  ungroup()


rel_abun <- ggplot(relative_abundance, aes(x = orig.ident, y = percent, fill = annotated_clusters)) +
  geom_col() +
  geom_text(aes(label = paste0(round(percent), "%")), 
            position = position_stack(vjust = 0.5), size = 3, color = "white") +
  scale_fill_manual(values = color.panel) +
  ggtitle("Percentage of cell type") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
rel_abun

DotPlot

markers.to.plot <-
  c(
"CLU", 
"GFAP", 
"AQP4", 
"GJA1",
"CLDN5", 
"ADGRF5", 
"FLT1",
"COL1A1", 
"COL1A2", 
"DCN",
"HEXB", 
"C1QA", 
"C1QC", 
"C1QB", 
"TMEM119", 
"ITGAM", 
"TYROBP",
"P2RY12", 
"AIF1",
"RBFOX3", 
"SNAP25",
"SYT1", 
"GAD1", 
"GAD2",
"PLP1",
"MBP", 
"MOG",
"OLIG1",
"PDGFRA", 
"VCAN", 
"TNR",
"ACTA2",
"RGS5", 
"VTN", 
"MYL5"
  )
dot_merge <- DotPlot(dataObject.annotated, 
               features = markers.to.plot, 
               cluster.idents = TRUE,
               dot.scale = 8) + RotatedAxis()
dot_merge

## png 
##   2

Save RDS

saveRDS(dataObject.annotated, paste0("../../../rObjects/", sampleID, ".annotated.rds"))