Upload 5 files
Browse files- 0.IntegrateData.R +82 -0
- 1.Maintype2.R +86 -0
- 2.Dimplot.R +19 -0
- 3.MetaNeighbor.R +82 -0
- 4.Percentage of infected.R +121 -0
0.IntegrateData.R
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#20230909尝试整合mPFC rAAV与V1 RV数据
|
| 2 |
+
|
| 3 |
+
RV_Infected<-RV_infected_mock_intergreted[,RV_infected_mock_intergreted$sample%in%"RV_infected"]
|
| 4 |
+
RV_MOCK<-RV_infected_mock_intergreted[,RV_infected_mock_intergreted$sample%in%"MOCK"]
|
| 5 |
+
|
| 6 |
+
rAAV_Infected<-all.Adult[,all.Adult$BC_label%in%"Barcoded"]
|
| 7 |
+
rAAV_MOCK<-all.Adult[,all.Adult$BC_label%in%"Unbarcoded"]
|
| 8 |
+
|
| 9 |
+
VIRUS_LIST<-list(RV_Infected,RV_MOCK,rAAV_Infected,rAAV_MOCK)
|
| 10 |
+
virus_sample_name<- c('RV_infected', 'RV_MOCK',"rAAV_infected","rAAV_MOCK")
|
| 11 |
+
|
| 12 |
+
for (i in 1:length(VIRUS_LIST)){
|
| 13 |
+
VIRUS_LIST[[i]]@meta.data$sample <- virus_sample_name[[i]]}
|
| 14 |
+
|
| 15 |
+
p <- list()
|
| 16 |
+
for (i in 1:4){
|
| 17 |
+
p[[i]] <- DimPlot(VIRUS_LIST[[i]], reduction = 'tsne') +
|
| 18 |
+
labs(title = virus_sample_name[i]) +
|
| 19 |
+
guides(colour=guide_legend(ncol=2, override.aes = list(size=2)))
|
| 20 |
+
}
|
| 21 |
+
plot_grid(plotlist = p, ncol =2)
|
| 22 |
+
|
| 23 |
+
#整合
|
| 24 |
+
features <- SelectIntegrationFeatures(object.list = VIRUS_LIST)
|
| 25 |
+
adult.anchors <- FindIntegrationAnchors(object.list = VIRUS_LIST,
|
| 26 |
+
anchor.features = features)
|
| 27 |
+
adult.inte <- IntegrateData(anchorset = adult.anchors)
|
| 28 |
+
adult.inte <- ScaleData(adult.inte, verbose = FALSE)
|
| 29 |
+
adult.inte <- RunPCA(adult.inte, npcs = 10, verbose = FALSE)
|
| 30 |
+
adult.inte <- FindNeighbors(adult.inte, reduction = "pca", dims = 1:10)
|
| 31 |
+
adult.inte <- FindClusters(adult.inte, resolution = 1)
|
| 32 |
+
adult.inte <- RunUMAP(adult.inte, reduction = "pca", dims = 1:10)
|
| 33 |
+
adult.inte <- RunTSNE(adult.inte, reduction = "pca", dims = 1:10)
|
| 34 |
+
adult.inte <-rAAV_RV.inte
|
| 35 |
+
adult.inte$seurat_clusters
|
| 36 |
+
VlnPlot(adult.inte,
|
| 37 |
+
features = c("Snap25",'Gad1',"Sox6","Col23a1","Pvalb","Sst","Prox1","Vip","Lamp5","Slc17a7",
|
| 38 |
+
"Rorb","Foxp2","Bcl6","Ctss","Slc1a3","Mog","Cux2","Rorb","Deptor","Etv1","Pou3f1",'Oprk1','Foxp2',"Syt6","Tshz2"),stack = TRUE, flip = TRUE, assay = 'RNA') +
|
| 39 |
+
NoLegend()
|
| 40 |
+
VlnPlot(adult.inte,
|
| 41 |
+
features = c("Snap25",'Gad1','Gad2',"Bcl11b","Sox6",
|
| 42 |
+
"Col23a1","Pvalb","Sst","Prox1","Vip","Lamp5","Slc17a7",
|
| 43 |
+
"Rorb","Foxp2","Bcl6","Ctss","Slc1a3","Mog","Cux2",
|
| 44 |
+
"Rorb","Deptor","Etv1","Pou3f1",'Oprk1','Foxp2',"Syt6","Tshz2"),
|
| 45 |
+
stack = TRUE, flip = TRUE, assay = 'RNA') + NoLegend()
|
| 46 |
+
|
| 47 |
+
VlnPlot(adult.inte,
|
| 48 |
+
features = c("Snap25",'Gad1','Gad2',"Sox6",
|
| 49 |
+
"Pvalb","Sst","Prox1","Vip","Lamp5","Aldoc", "Slc1a3", "Aqp4","Slc17a6","Slc17a7",
|
| 50 |
+
'Calb1','Otof','Hap1','Cux2','Rorb','Tnnc1','Rspo1','Bdnf',
|
| 51 |
+
'Ptn','Sema3d','Cpne7','Fstl5','Slc24a2','Oprk1','Penk',"Col23a1",
|
| 52 |
+
'Syt6','Pcp4','Pou3f1','S100b','Etv1','Scn4b','Adamts2','Dlk1','Npr3',
|
| 53 |
+
'Tshz2','Cbln2','Grp',"Pdgfra", "C1ql1", "Olig2", "Olig1","Fcrls", "Trem2"),
|
| 54 |
+
stack = TRUE, flip = TRUE, assay = 'RNA') + NoLegend()
|
| 55 |
+
level_maintype<-c( "Pvalb","Sst","Vip/Lamp5","Astro","Oligo","Microglia","L2/3IT","L4/5IT","L6IT","L5NP","L6CT","L5ET")
|
| 56 |
+
Idents(adult.inte) <- factor(Idents(adult.inte),levels=level_maintype)
|
| 57 |
+
levels(Idents(adult.inte))
|
| 58 |
+
adult.inte$Maintype <- as.character(adult.inte$seurat_clusters)
|
| 59 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(9))] <- "Pvalb"
|
| 60 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(11))] <- "Sst"
|
| 61 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(13))] <- "Vip/Lamp5"
|
| 62 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(0,1,6,9))] <- "L2/3IT"#cux2
|
| 63 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(5,21,22))] <- "L4/5IT"
|
| 64 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(3,18))] <- "L6IT"
|
| 65 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(2,22))] <- "L6CT"
|
| 66 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(12,17))] <- "L5ET"
|
| 67 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(8,15))] <- "L5NP"
|
| 68 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(10,14,19))] <- "Microglia"
|
| 69 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(4,16,17))] <- "Astro"
|
| 70 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(7,20))] <- "Oligo"
|
| 71 |
+
Idents(adult.inte) <- 'Maintype'
|
| 72 |
+
VlnPlot(adult.inte,
|
| 73 |
+
features = c('Gad1',"Sox6","Pvalb","Sst","Prox1","Vip","Lamp5","Slc17a7","Col23a1",
|
| 74 |
+
"Rorb","Foxp2","Bcl6","Ctss","Slc1a3","Mog"),group.by = "Maintype",stack = TRUE, flip = TRUE, fill.by="ident", assay = 'RNA') +
|
| 75 |
+
NoLegend()
|
| 76 |
+
|
| 77 |
+
DimPlot(adult.inte, split.by = 'sample', reduction = 'tsne', label = T, ncol = 2) +
|
| 78 |
+
theme(axis.line = element_blank(), axis.ticks = element_blank(),
|
| 79 |
+
axis.text = element_blank(), plot.title = element_text(size = 30)) +
|
| 80 |
+
labs(x='', y='')
|
| 81 |
+
saveRDS(adult.inte,"H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/rAAV_RV.inte2.RDS")
|
| 82 |
+
|
1.Maintype2.R
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#20230909尝试整合mPFC rAAV与V1 RV数据
|
| 2 |
+
install.packages("ape")
|
| 3 |
+
RV_Infected<-RV_infected_mock_intergreted[,RV_infected_mock_intergreted$sample%in%"RV_infected"]
|
| 4 |
+
RV_MOCK<-RV_infected_mock_intergreted[,RV_infected_mock_intergreted$sample%in%"MOCK"]
|
| 5 |
+
|
| 6 |
+
rAAV_Infected<-all.Adult[,all.Adult$BC_label%in%"Barcoded"]
|
| 7 |
+
rAAV_MOCK<-all.Adult[,all.Adult$BC_label%in%"Unbarcoded"]
|
| 8 |
+
|
| 9 |
+
VIRUS_LIST<-list(RV_Infected,RV_MOCK,rAAV_Infected,rAAV_MOCK)
|
| 10 |
+
virus_sample_name<- c('RV_infected', 'RV_MOCK',"rAAV_infected","rAAV_MOCK")
|
| 11 |
+
|
| 12 |
+
for (i in 1:length(VIRUS_LIST)){
|
| 13 |
+
VIRUS_LIST[[i]]@meta.data$sample <- virus_sample_name[[i]]}
|
| 14 |
+
|
| 15 |
+
p <- list()
|
| 16 |
+
for (i in 1:4){
|
| 17 |
+
p[[i]] <- DimPlot(VIRUS_LIST[[i]], reduction = 'tsne') +
|
| 18 |
+
labs(title = virus_sample_name[i]) +
|
| 19 |
+
guides(colour=guide_legend(ncol=2, override.aes = list(size=2)))
|
| 20 |
+
}
|
| 21 |
+
plot_grid(plotlist = p, ncol =2)
|
| 22 |
+
|
| 23 |
+
#整合
|
| 24 |
+
features <- SelectIntegrationFeatures(object.list = VIRUS_LIST)
|
| 25 |
+
adult.anchors <- FindIntegrationAnchors(object.list = VIRUS_LIST,
|
| 26 |
+
anchor.features = features)
|
| 27 |
+
adult.inte <- IntegrateData(anchorset = adult.anchors)
|
| 28 |
+
adult.inte <- ScaleData(adult.inte, verbose = FALSE)
|
| 29 |
+
adult.inte <- RunPCA(adult.inte, npcs = 10, verbose = FALSE)
|
| 30 |
+
adult.inte <- FindNeighbors(adult.inte, reduction = "pca", dims = 1:20)
|
| 31 |
+
adult.inte <- FindClusters(adult.inte, resolution = 1)
|
| 32 |
+
adult.inte <- RunUMAP(adult.inte, reduction = "pca", dims = 1:10)
|
| 33 |
+
adult.inte <- RunTSNE(adult.inte, reduction = "pca", dims = 1:10)
|
| 34 |
+
|
| 35 |
+
adult.inte$seurat_clusters
|
| 36 |
+
|
| 37 |
+
VlnPlot(adult.inte,
|
| 38 |
+
features = c("Snap25",'Gad1','Gad2',"Sox6",
|
| 39 |
+
"Pvalb","Sst","Prox1","Vip",
|
| 40 |
+
"Aldoc", "Slc1a3", "Aqp4", "Olig2", "Olig1","Pdgfra", "C1ql1","Fcrls", "Trem2",
|
| 41 |
+
"Slc17a7",'Calb1','Cux2','Rorb','Bdnf',
|
| 42 |
+
'Ptn',"Col23a1",
|
| 43 |
+
'Tshz2','Cbln2','Grp',"Syt6",
|
| 44 |
+
'Pou3f1','Etv1','Adamts2','Dlk1','Npr3'),
|
| 45 |
+
stack = TRUE, flip = TRUE, assay = 'RNA') + NoLegend()
|
| 46 |
+
level_maintype<-c( "Pvalb","Sst","Vip/Lamp5","Astro","Oligo","Microglia","L2/3IT","L4/5IT","L6IT","L5NP","L6CT","L5ET")
|
| 47 |
+
Idents(adult.inte) <- factor(Idents(adult.inte),levels=level_maintype)
|
| 48 |
+
levels(Idents(adult.inte))
|
| 49 |
+
|
| 50 |
+
Idents(adult.inte) <- 'seurat_clusters'
|
| 51 |
+
Idents(adult.inte) <- 'Maintype'
|
| 52 |
+
adult.inte<- BuildClusterTree(object = adult.inte, dims=1:10)
|
| 53 |
+
phy <- Tool(object = adult.inte, slot = 'BuildClusterTree')
|
| 54 |
+
plot(phy)
|
| 55 |
+
|
| 56 |
+
adult.inte$Maintype <- as.character(adult.inte$seurat_clusters)
|
| 57 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(8))] <- "Pvalb"
|
| 58 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(9))] <- "Sst"
|
| 59 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(13,27))] <- "Vip/Lamp5"
|
| 60 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(2,14))] <- "L2/3IT"#cux2
|
| 61 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(0,6))] <- "L4/5IT"
|
| 62 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(3,4,23,25,19))] <- "L6IT"
|
| 63 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(1))] <- "L6CT"
|
| 64 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(11))] <- "L5ET"
|
| 65 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(16))] <- "L5NP"
|
| 66 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(10,15,21))] <- "Microglia"
|
| 67 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(5,17,24,7))] <- "Astro"
|
| 68 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(12,18,20,22,26))] <- "Oligo"
|
| 69 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(7))] <- "7"
|
| 70 |
+
adult.inte$Maintype[which(adult.inte$Maintype %in% c(19))] <- "19"
|
| 71 |
+
Idents(adult.inte) <- 'Maintype'
|
| 72 |
+
VlnPlot(adult.inte,
|
| 73 |
+
features = c('Gad1',"Sox6","Pvalb","Sst","Prox1","Vip","Lamp5","Slc17a7","Col23a1",
|
| 74 |
+
"Rorb","Foxp2","Bcl6","Ctss","Slc1a3","Mog"),group.by = "Maintype",stack = TRUE, flip = TRUE, fill.by="ident", assay = 'RNA') +
|
| 75 |
+
NoLegend()
|
| 76 |
+
DimPlot(adult.inte, reduction = 'umap', label = T, ncol = 2)
|
| 77 |
+
DimPlot(adult.inte, split.by = 'sample', reduction = 'tsne', label = T, ncol = 2) +
|
| 78 |
+
theme(axis.line = element_blank(), axis.ticks = element_blank(),
|
| 79 |
+
axis.text = element_blank(), plot.title = element_text(size = 30)) +
|
| 80 |
+
labs(x='', y='')
|
| 81 |
+
saveRDS(adult.inte,"H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/rAAV_RV.inte2.RDS")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
table(SLQ_IPC$predicted.id)
|
| 85 |
+
SLQ_IPC$`ACB-I`
|
| 86 |
+
SLQ_IPC$`BLA-I`
|
2.Dimplot.R
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(Seurat)
|
| 2 |
+
DimPlot(rAAV_RV.inte,)
|
| 3 |
+
table(rAAV_RV.inte$sample)
|
| 4 |
+
FeaturePlot(rAAV_RV.inte,
|
| 5 |
+
reduction = 'tsne',
|
| 6 |
+
c('rAAV_infected','RV_infected','Syt6','Tshz2'),
|
| 7 |
+
ncol = 2,
|
| 8 |
+
cols=c("lightgrey", "red"),
|
| 9 |
+
min.cutoff='q1')
|
| 10 |
+
Idents(rAAV_RV.inte) <- rAAV_RV.inte$sample # 设定细胞身份
|
| 11 |
+
|
| 12 |
+
DimPlot(rAAV_RV.inte, reduction = "tsne", group.by = "sample",
|
| 13 |
+
cols = c("#00bfc4", "lightgrey","red", "grey"), pt.size = 0.5) +
|
| 14 |
+
ggtitle("t-SNE Visualization of Infected Cells")
|
| 15 |
+
|
| 16 |
+
Idents(rAAV_RV.inte) <- rAAV_RV.inte$Maintype # 设定细胞身份
|
| 17 |
+
DimPlot(rAAV_RV.inte, reduction = "umap", pt.size = 0.5) +
|
| 18 |
+
ggtitle("t-SNE Visualization of Infected Cells")
|
| 19 |
+
table(rAAV_RV.inte$Maintype,rAAV_RV.inte$sample)
|
3.MetaNeighbor.R
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
adult.inte$maintype_sample <- paste(adult.inte$Maintype, adult.inte$sample, sep = "|")
|
| 2 |
+
library(dplyr)
|
| 3 |
+
table(adult.inte$sample)
|
| 4 |
+
adult.inte$sample <- recode(adult.inte$sample,
|
| 5 |
+
"rAAV_MOCK" = "control_PFC",
|
| 6 |
+
"RV_MOCK" = "Control_V1")
|
| 7 |
+
Idents(adult.inte) <- 'maintype_sample'
|
| 8 |
+
|
| 9 |
+
#build the tree
|
| 10 |
+
adult.inte<- BuildClusterTree(object = adult.inte, dims=1:10)
|
| 11 |
+
phy <- Tool(object = adult.inte, slot = 'BuildClusterTree')
|
| 12 |
+
p5<-plot(phy)
|
| 13 |
+
p5
|
| 14 |
+
unique(adult.inte$maintype_sample)
|
| 15 |
+
|
| 16 |
+
#MetaNeighbor
|
| 17 |
+
library(SingleCellExperiment)
|
| 18 |
+
library(MetaNeighbor)
|
| 19 |
+
|
| 20 |
+
# 创建 colData
|
| 21 |
+
new_colData <- data.frame(
|
| 22 |
+
study_id = adult.inte$sample,
|
| 23 |
+
cell_type = adult.inte$Maintype # 确保 row.names 对齐
|
| 24 |
+
)
|
| 25 |
+
new_colData$study_id <- as.character(new_colData$study_id)
|
| 26 |
+
new_colData$study_id[which(new_colData$study_id %in% c("Control_V1","RV_infected"))] <- "VISp"
|
| 27 |
+
new_colData$study_id[which(new_colData$study_id %in% c("control_PFC","rAAV_infected"))] <- "PFC"
|
| 28 |
+
|
| 29 |
+
dat <- SingleCellExperiment(adult.inte@assays$integrated@data,
|
| 30 |
+
colData = new_colData
|
| 31 |
+
)
|
| 32 |
+
var_genes <- VariableFeatures(adult.inte) # 替换为实际的高变基因获取方式
|
| 33 |
+
# 运行 MetaNeighbor
|
| 34 |
+
celltype_NV = MetaNeighborUS(
|
| 35 |
+
var_genes = var_genes,
|
| 36 |
+
dat = dat, # 确保 dat 是矩阵
|
| 37 |
+
study_id = dat$study_id,
|
| 38 |
+
cell_type = dat$cell_type,
|
| 39 |
+
fast_version = TRUE
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
library(pheatmap)
|
| 43 |
+
pheatmap(celltype_NV, cluster_rows=T, cluster_cols=F, display_numbers=T)
|
| 44 |
+
|
| 45 |
+
cor_inter<-celltype_NV[grep('VISp|PFC',rownames(celltype_NV),value = T),
|
| 46 |
+
grep('VISp|PFC',rownames(celltype_NV),value = T)]
|
| 47 |
+
p<-pheatmap(cor_inter, cluster_rows=T, cluster_cols=T, display_numbers=T,fontsize_number = 5,silent = T)
|
| 48 |
+
cluster_order <- rownames(cor_inter)[p$tree_row$order]
|
| 49 |
+
|
| 50 |
+
pheatmap(cor_inter, cluster_rows=T, cluster_cols=T, display_numbers=T,
|
| 51 |
+
fontsize_number=5, fontsize_row=8, fontsize_col=8)
|
| 52 |
+
p5<-pheatmap(cor_inter[cluster_order, cluster_order],
|
| 53 |
+
cluster_rows=F, cluster_cols=F, display_numbers=T, fontsize_number=5)
|
| 54 |
+
|
| 55 |
+
cluster_order<-c("PFC|Pvalb" ,"VISp|Pvalb","PFC|Vip/Lamp5","VISp|Vip/Lamp5","PFC|Sst" ,"VISp|Sst",
|
| 56 |
+
"PFC|Microglia","VISp|Microglia","PFC|Oligo" ,"VISp|Oligo","PFC|Astro","VISp|Astro",
|
| 57 |
+
"VISp|L2/3IT" ,"PFC|L2/3IT","VISp|L4/5IT", "PFC|L4/5IT","PFC|L6IT","VISp|L6IT" , "VISp|L5ET","PFC|L5ET","PFC|L6CT", "VISp|L6CT","PFC|L5NP","VISp|L5NP")
|
| 58 |
+
ggsave("H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/p5_MetaNeighbor.pdf",
|
| 59 |
+
plot = p5, width =8, height = 8, dpi = 300)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# 提取所有共有细胞类型(PFC和VISp共有的类型)
|
| 65 |
+
common_types <- sub("PFC\\|", "", grep("PFC\\|", rownames(cor_inter), value = TRUE))
|
| 66 |
+
common_types <- common_types[common_types %in% sub("VISp\\|", "", grep("VISp\\|", rownames(cor_inter), value = TRUE))]
|
| 67 |
+
|
| 68 |
+
# 提取PFC与VISp同类型细胞的相似性得分(单向即可,因矩阵对称)
|
| 69 |
+
scores <- sapply(common_types, function(type) {
|
| 70 |
+
cor_inter[paste0("PFC|", type), paste0("VISp|", type)]
|
| 71 |
+
})
|
| 72 |
+
|
| 73 |
+
# 输出所有配对得分
|
| 74 |
+
print(data.frame(CellType = common_types, AUROC = scores))
|
| 75 |
+
|
| 76 |
+
# 计算平均相似性得分(假设理想情况下应接近1)
|
| 77 |
+
mean_score <- mean(scores)
|
| 78 |
+
cat(sprintf("\nMean AUROC between matched cell types: %.2f\n", mean_score))
|
| 79 |
+
|
| 80 |
+
# 显著性检验:判断得分是否显著高于随机预期(假设随机预期为0.5)
|
| 81 |
+
t_test_result <- t.test(scores, mu = 0.5, alternative = "greater")
|
| 82 |
+
cat(sprintf("t-test p-value vs. random expectation (0.5): %.1e\n", t_test_result$p.value))
|
4.Percentage of infected.R
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(dplyr)
|
| 2 |
+
library(ggplot2)
|
| 3 |
+
RAAV_RV.INTE<-readRDS("H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/adult.inte.RDS")
|
| 4 |
+
Idents(RAAV_RV.INTE) <- 'sample'
|
| 5 |
+
Idents(RAAV_RV.INTE) <- factor(Idents(RAAV_RV.INTE),
|
| 6 |
+
levels = c("RV_infected", "rAAV_infected", "rAAV_MOCK", "RV_MOCK"))
|
| 7 |
+
nMaintype <- RAAV_RV.INTE@meta.data$Maintype
|
| 8 |
+
nsample <- RAAV_RV.INTE@meta.data$sample
|
| 9 |
+
nMaintype
|
| 10 |
+
|
| 11 |
+
custom_order <- c('Pvalb','Sst','Vip/Lamp5',"Astro","Microglia",'Oligo','L2/3IT','L4/5IT','L6IT','L5NP','L6CT','L5ET')
|
| 12 |
+
nMaintype <- factor(nMaintype, levels = custom_order)
|
| 13 |
+
# 转换为data.frame对象
|
| 14 |
+
data <- data.frame(nMaintype, nsample)
|
| 15 |
+
|
| 16 |
+
levels(data)
|
| 17 |
+
|
| 18 |
+
# 计算每个nMaintype中nsample1和nsample2的数量
|
| 19 |
+
summary_data <- data %>%
|
| 20 |
+
group_by(nMaintype, nsample) %>%
|
| 21 |
+
summarise(count = n()) %>%
|
| 22 |
+
ungroup()
|
| 23 |
+
summary_data_3 <- summary_data %>%
|
| 24 |
+
filter(nsample %in% c("rAAV_infected", "RV_infected"))
|
| 25 |
+
# 计算百分比
|
| 26 |
+
percent_data <- summary_data %>%
|
| 27 |
+
group_by(nMaintype) %>%
|
| 28 |
+
mutate(percentage = count / sum(count))
|
| 29 |
+
|
| 30 |
+
percent_data$nMaintype
|
| 31 |
+
library(dplyr)
|
| 32 |
+
|
| 33 |
+
percent_data_3 <- summary_data_3 %>%
|
| 34 |
+
group_by(nMaintype) %>%
|
| 35 |
+
mutate(percentage = count / sum(count))
|
| 36 |
+
|
| 37 |
+
#不同亚群占比
|
| 38 |
+
p1<- ggplot(percent_data, aes(x = nMaintype, y = percentage, fill = nsample)) +
|
| 39 |
+
geom_bar(stat = "identity") +
|
| 40 |
+
scale_fill_manual(values = c("#f8766d","#f8766d","#00bfc4", '#eade5e')) +
|
| 41 |
+
ylab("Percentage") +
|
| 42 |
+
theme_bw() +
|
| 43 |
+
labs(
|
| 44 |
+
title = "Percentage of RV rAAV infected cells", # 设置标题
|
| 45 |
+
x = "Cluster Type", # 设置x轴标签
|
| 46 |
+
y = "Percentage of virus infected cells"
|
| 47 |
+
) +
|
| 48 |
+
theme(
|
| 49 |
+
plot.title = element_text(size = 20, hjust = 0.5), # 设置标题大小为20,居中对齐
|
| 50 |
+
axis.title.x = element_text(size = 14), # 设置x轴标签大小为14
|
| 51 |
+
axis.title.y = element_text(size = 14), # 设置y轴标签大小为14
|
| 52 |
+
axis.text.x = element_text(angle = 45, hjust = 1,size = 14,color ='black'), # 横坐标倾斜45度
|
| 53 |
+
legend.text = element_text(size = 14))
|
| 54 |
+
|
| 55 |
+
# 过滤掉 "rAAV_MOCK" 和 "RV_MOCK"
|
| 56 |
+
filtered_data <- data %>%
|
| 57 |
+
filter(nsample %in% c("RV_infected", "rAAV_infected")) %>% # 只保留 RV_infected 和 rAAV_infected
|
| 58 |
+
filter(!nMaintype %in% c("Pvalb", "Sst", "Vip/Lamp5")) # 去掉这几类细胞
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# 重新绘制柱状图
|
| 62 |
+
p2<- ggplot(filtered_data, aes(x = nMaintype, fill = nsample)) +
|
| 63 |
+
geom_bar() +
|
| 64 |
+
scale_fill_manual(values = c("#00bfc4", '#eade5e')) + # 仅保留 RV_infected 和 rAAV_infected 的颜色
|
| 65 |
+
theme_bw() +
|
| 66 |
+
labs(
|
| 67 |
+
title = "Number of Virus infected cells",
|
| 68 |
+
x = " ",
|
| 69 |
+
y = "Cell Numbers"
|
| 70 |
+
) +
|
| 71 |
+
theme(
|
| 72 |
+
plot.title = element_text(size = 20, hjust = 0.5),
|
| 73 |
+
axis.title.x = element_text(size = 14),
|
| 74 |
+
axis.title.y = element_text(size = 14),
|
| 75 |
+
axis.text.x = element_text(angle = 45, hjust = 1, size = 14, color ='black'),
|
| 76 |
+
legend.text = element_text(size = 14)
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
print(p2)
|
| 80 |
+
#Virus Percentage===RV/rAAV
|
| 81 |
+
# 计算每个nMaintype中nsample1和nsample2的数量
|
| 82 |
+
summary_data <- filtered_data%>%
|
| 83 |
+
group_by(nMaintype, nsample) %>%
|
| 84 |
+
summarise(count = n()) %>%
|
| 85 |
+
ungroup()
|
| 86 |
+
summary_data_3 <- summary_data %>%
|
| 87 |
+
filter(nsample %in% c("rAAV_infected", "RV_infected"))
|
| 88 |
+
|
| 89 |
+
percent_data_3 <- summary_data_3 %>%
|
| 90 |
+
group_by(nMaintype) %>%
|
| 91 |
+
mutate(percentage = count / sum(count))
|
| 92 |
+
|
| 93 |
+
p3 <- ggplot(percent_data_3, aes(x = nMaintype, y = percentage, fill = nsample)) +
|
| 94 |
+
geom_bar(stat = "identity") +
|
| 95 |
+
scale_fill_manual(values = c("#00bfc4", '#eade5e')) +
|
| 96 |
+
ylab("Percentage") +
|
| 97 |
+
theme_bw() +
|
| 98 |
+
labs(
|
| 99 |
+
title = "Percentage of RV rAAV infected cells", # 设置标题
|
| 100 |
+
x = "Cluster Type", # 设置x轴标签
|
| 101 |
+
y = "Percentage of virus infected cells"
|
| 102 |
+
) +
|
| 103 |
+
theme(
|
| 104 |
+
plot.title = element_text(size = 20, hjust = 0.5), # 设置标题大小为20,居中对齐
|
| 105 |
+
axis.title.x = element_text(size = 14), # 设置x轴标签大小为14
|
| 106 |
+
axis.title.y = element_text(size = 14), # 设置y轴标签大小为14
|
| 107 |
+
axis.text.x = element_text(angle = 45, hjust = 1,size = 14,color ='black') # 横坐标倾斜45度
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
p3
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
p1
|
| 114 |
+
p2
|
| 115 |
+
p3
|
| 116 |
+
ggsave("H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/p6.Percentage of virus infected cells.pdf",
|
| 117 |
+
plot = p1, width =7, height = 8, dpi = 300)
|
| 118 |
+
ggsave("H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/p7.Percentage of virus infected cells.pdf",
|
| 119 |
+
plot = p2, width =6, height = 8, dpi = 300)
|
| 120 |
+
ggsave("H:/Project1_RV Receptor Projection/FIG1.皮层单细胞RV rAAV感染数据分析/p8.Percentage of virus infected cells.pdf",
|
| 121 |
+
plot = p3, width =6, height = 8, dpi = 300)
|