当前位置:网站首页>gpnmb+ gpnmb-AT2 cell idling mapping Epithelial cell idling mapping
gpnmb+ gpnmb-AT2 cell idling mapping Epithelial cell idling mapping
2022-08-03 08:34:00 【youngleeyoung】
这里是引用
library(Seurat)
library(dplyr)
library(cowplot)
library(ggplot2)
library(harmony)
library(patchwork)
library(openxlsx)
file = "G:/silicosis/sicosis/YSQ/2022-8-2_EPITHELIAL"## 改成想存放文件的路径
dir.create(file)
setwd(file)
getwd()
path=getwd()
load("G:\\silicosis\\sicosis\\YSQ\\3-23_EPITHELIAL\\silicosi_AT2.rds")
DotPlot(subset_data,features = "Gpnmb")
DotPlot(subset_data,features = "Gpnmb",group.by = "stim")
label = as.character(Idents(subset_data))
label
levels(label)
table(label)
label[which(label %in% c("AT2 cell-1", "AT2 cell-2", "Igha+ AT2 cell"))] = "AT2 cell"
label[which(label %in% "AT2 cell" & subset_data$RNA@counts["Gpnmb", ] > 0)] = "Gpnmb+ AT2 cell"
label[which(label %in% "AT2 cell" & subset_data$RNA@counts["Gpnmb", ] == 0)] = "Gpnmb- AT2 cell"
#label = factor(label, levels = c(levels(Idents(subset_data))[1:17], "Gpnmb+ AT2 cell", "Gpnmb- AT2 cell"))
table(label)
#label = factor(label, levels = c("Gpnmb+ AT2 cell", "Gpnmb- AT2 cell"))
subset_data$my_group=label
Idents(subset_data)=subset_data$my_group
Idents(subset_data)
markers_for_gpnmb_postive_and_gpnmb_negtive=FindMarkers(subset_data,ident.1 ="Gpnmb+ AT2 cell",
ident.2 = "Gpnmb- AT2 cell")
head(markers_for_gpnmb_postive_and_gpnmb_negtive)
getwd()
write.xlsx(markers_for_gpnmb_postive_and_gpnmb_negtive,file = "differential_markers_for_gpnmb_postive_and_gpnmb_negtive.xlsx",
col.names=T, row.names=T)
#save(subset_data,file = "subsetdata_for_gpnmb+_.rds")
load("G:\\silicosis\\sicosis\\YSQ\\2022-8-2_EPITHELIAL\\spatialMapping\\Gpnmb\\subsetdata_for_gpnmb+_.rds")
Idents(subset_data)=subset_data$stim
#2
##gpnmb阳性 And negative in idling on map
load("G:/silicosis/sicosis/silicosis-1122-merge/silicosis_cluster_merge.rds")## 17226 25002
#阳性的AT2细胞在四个组别空转上的分布;
{
getwd()
dir.create(paste(path, "spatialMapping", "Gpnmb", sep = "/"),recursive = TRUE)
setwd(paste(path, "spatialMapping", "Gpnmb", sep = "/"))
getwd()
label = as.character(Idents(All.merge))
label
#Igha+ AT2 cell
#Font error prone
label[which(label %in% c("AT2 cell-1", "AT2 cell-2", "Igha+ AT2 cell"))] = "AT2 cell"
label[which(label %in% "AT2 cell" & All.merge$RNA@counts["Gpnmb", ] > 0)] = "Gpnmb+ AT2 cell"
label[which(label %in% "AT2 cell" & All.merge$RNA@counts["Gpnmb", ] == 0)] = "Gpnmb- AT2 cell"
levels(label)
table(label)
label = factor(label, levels = c(levels(Idents(All.merge))[1:17], "Gpnmb+ AT2 cell", "Gpnmb- AT2 cell"))
levels(label)
levels(Idents(All.merge))
table(label)
All.merge.SCT <- CreateSeuratObject(counts = All.merge@assays$RNA@counts, project = "silicosis") #17226 26758
All.merge.SCT = SCTransform(All.merge.SCT, verbose = FALSE) %>% RunPCA(verbose = FALSE) #默认3000个HVG
All.merge.SCT$cell.type = label
table(All.merge.SCT$cell.type)
dim(All.merge.SCT@assays$SCT@scale.data)
cell.type = All.merge.SCT$cell.type
library(Seurat)
library(dplyr)
library(cowplot)
library(ggplot2)
library(RColorBrewer)
library(patchwork)
SpatialColors <- colorRampPalette(colors = rev(x = brewer.pal(n = 11, name = "Spectral")))
#################sio2_56
#load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/sio2_56_sct.rds")
getwd()
load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/sio2_56_sct.rds")
anterset.sio2_56_sct <- FindTransferAnchors(reference = All.merge.SCT,query = sio2_56_sct,normalization.method="SCT")
predictions.assay.sio2_56_sct <- TransferData(anchorset = anterset.sio2_56_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
sio2_56_sct[["predictions"]] <- predictions.assay.sio2_56_sct
DefaultAssay(sio2_56_sct) <- "predictions"
save(sio2_56_sct,file="sio2_56_sct.prediction.rds")
rowSums(sio2_56_sct$predictions@data)
dim(sio2_56_sct$predictions@data)
sio2_56_sct$predictions@data = sio2_56_sct$predictions@data[c(levels(cell.type), "max"), ]
rowSums(sio2_56_sct$predictions@data)
pre.mat = sio2_56_sct$predictions@data[-dim(sio2_56_sct$predictions@data)[1],]
pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
pdf("SiO2_56_spot_cell_type_prediction_split.pdf")
for(i in levels(cell.type)){
p <- SpatialPlot(sio2_56_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "SiO2_56")
print(p)
}
dev.off()
num = nrow(sio2_56_sct$predictions@data)
max_index = apply(sio2_56_sct$predictions@data[-num,],2,which.max)
max_cell_type = rownames(sio2_56_sct$predictions@data)[max_index]
max_cell_type = factor(max_cell_type, levels=levels(cell.type))
table(max_cell_type)
spot.mat = data.frame(table(max_cell_type))
colnames(spot.mat) = c("cell.type", "spot.num")
spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
write.xlsx(spot.num.score, "SiO2_56_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
sio2_56_sct$spot.cell.type = max_cell_type
pdf("SiO2_56_spot_cell_type_prediction_all.pdf", width = 10)
SpatialPlot(sio2_56_sct, group.by="spot.cell.type")+labs(title = "SiO2_56")+guides(fill = guide_legend(override.aes = list(size = 5)))
dev.off()
pdf("SiO2_56_max_spot_cellType.pdf")
for (i in levels(cell.type)){
idx = which(max_cell_type == i)
cell = colnames(sio2_56_sct)[idx]
if(length(idx)!=0){
p = SpatialPlot(sio2_56_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
print(p)
}
}
dev.off()
#################sio2_7
#load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/sio2_7_sct.rds")
load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/sio2_7_sct.rds")
anterset.sio2_7_sct <- FindTransferAnchors(reference = All.merge.SCT,query = sio2_7_sct,normalization.method="SCT")
predictions.assay.sio2_7_sct <- TransferData(anchorset = anterset.sio2_7_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
sio2_7_sct[["predictions"]] <- predictions.assay.sio2_7_sct
DefaultAssay(sio2_7_sct) <- "predictions"
# save(sio2_7_sct,file="sio2_7_sct.prediction.rds")
#load("G:\\silicosis\\sicosis\\YSQ\\2022-8-2_EPITHELIAL\\spatialMapping\\Gpnmb\\sio2_7_sct.prediction.rds")
rowSums(sio2_7_sct$predictions@data)
dim(sio2_7_sct$predictions@data)
sio2_7_sct$predictions@data = sio2_7_sct$predictions@data[c(levels(cell.type), "max"), ]
rowSums(sio2_7_sct$predictions@data)
pre.mat = sio2_7_sct$predictions@data[-dim(sio2_7_sct$predictions@data)[1],]
pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
pdf("SiO2_7_spot_cell_type_prediction_split.pdf")
for(i in levels(cell.type)){
p <- SpatialPlot(sio2_7_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "SiO2_7")
print(p)
}
dev.off()
num = nrow(sio2_7_sct$predictions@data)
max_index = apply(sio2_7_sct$predictions@data[-num,],2,which.max)
max_cell_type = rownames(sio2_7_sct$predictions@data)[max_index]
max_cell_type = factor(max_cell_type, levels=levels(cell.type))
table(max_cell_type)
spot.mat = data.frame(table(max_cell_type))
colnames(spot.mat) = c("cell.type", "spot.num")
spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
library(openxlsx)
write.xlsx(spot.num.score, "SiO2_7_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
sio2_7_sct$spot.cell.type = max_cell_type
pdf("SiO2_7_spot_cell_type_prediction_all.pdf")
SpatialPlot(sio2_7_sct, group.by="spot.cell.type")+labs(title = "SiO2_7")+guides(fill = guide_legend(override.aes = list(size = 5)))
dev.off()
pdf("SiO2_7_max_spot_cellType.pdf")
for (i in levels(cell.type)){
idx = which(max_cell_type == i)
cell = colnames(sio2_7_sct)[idx]
if(length(idx)!=0){
p = SpatialPlot(sio2_7_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
print(p)
}
}
dev.off()
#################NS_56
#load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/NS_56_sct.rds")
#################NS_56
load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/NS_56_sct.rds")
anterset.NS_56_sct <- FindTransferAnchors(reference = All.merge.SCT,query = NS_56_sct,normalization.method="SCT")
predictions.assay.NS_56_sct <- TransferData(anchorset = anterset.NS_56_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
NS_56_sct[["predictions"]] <- predictions.assay.NS_56_sct
DefaultAssay(NS_56_sct) <- "predictions"
save(NS_56_sct,file="NS_56_sct.prediction.rds")
rowSums(NS_56_sct$predictions@data)
dim(NS_56_sct$predictions@data)
NS_56_sct$predictions@data = NS_56_sct$predictions@data[c(levels(cell.type), "max"), ]
rowSums(NS_56_sct$predictions@data)
pre.mat = NS_56_sct$predictions@data[-dim(NS_56_sct$predictions@data)[1],]
pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
pdf("NS_56_spot_cell_type_prediction_split.pdf")
for(i in levels(cell.type)){
p <- SpatialPlot(NS_56_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "NS_56")
print(p)
}
dev.off()
num = nrow(NS_56_sct$predictions@data)
max_index = apply(NS_56_sct$predictions@data[-num,],2,which.max)
max_cell_type = rownames(NS_56_sct$predictions@data)[max_index]
max_cell_type = factor(max_cell_type, levels=levels(cell.type))
table(max_cell_type)
spot.mat = data.frame(table(max_cell_type))
colnames(spot.mat) = c("cell.type", "spot.num")
spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
write.xlsx(spot.num.score, "NS_56_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
NS_56_sct$spot.cell.type = max_cell_type
pdf("NS_56_spot_cell_type_prediction_all.pdf")
SpatialPlot(NS_56_sct, group.by="spot.cell.type")+labs(title = "NS_56")+guides(fill = guide_legend(override.aes = list(size = 5)))
dev.off()
pdf("NS_56_max_spot_cellType.pdf")
for (i in levels(cell.type)){
idx = which(max_cell_type == i)
cell = colnames(NS_56_sct)[idx]
if(length(idx)!=0){
p = SpatialPlot(NS_56_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
print(p)
}
}
dev.off()
#################NS_7
#load("/data/home/longmin/code_test/silicosis_scRNAseq/unknown/ST_mapping_1012/NS_7_sct.rds")
load("G:/silicosis/需求/矽肺-数据分析结果-0119-yll/矽肺-数据分析结果-0119/NS_7_sct.rds")
anterset.NS_7_sct <- FindTransferAnchors(reference = All.merge.SCT,query = NS_7_sct,normalization.method="SCT")
predictions.assay.NS_7_sct <- TransferData(anchorset = anterset.NS_7_sct, refdata = All.merge.SCT$cell.type, prediction.assay = TRUE, dims = 1:30)
NS_7_sct[["predictions"]] <- predictions.assay.NS_7_sct
DefaultAssay(NS_7_sct) <- "predictions"
save(NS_7_sct,file="NS_7_sct.prediction.rds")
rowSums(NS_7_sct$predictions@data)
dim(NS_7_sct$predictions@data)
NS_7_sct$predictions@data = NS_7_sct$predictions@data[c(levels(cell.type), "max"), ]
rowSums(NS_7_sct$predictions@data)
pre.mat = NS_7_sct$predictions@data[-dim(NS_7_sct$predictions@data)[1],]
pre.mat.sum = data.frame(cell.type = rownames(pre.mat),score = rowSums(pre.mat))
pdf("NS_7_spot_cell_type_prediction_split.pdf")
for(i in levels(cell.type)){
p <- SpatialPlot(NS_7_sct, features=i, pt.size.factor=1.6)+scale_fill_gradientn(limits=c(0,1),colours=SpatialColors(n=100))+labs(title = "NS_7")
print(p)
}
dev.off()
num = nrow(NS_7_sct$predictions@data)
max_index = apply(NS_7_sct$predictions@data[-num,],2,which.max)
max_cell_type = rownames(NS_7_sct$predictions@data)[max_index]
max_cell_type = factor(max_cell_type, levels=levels(cell.type))
table(max_cell_type)
spot.mat = data.frame(table(max_cell_type))
colnames(spot.mat) = c("cell.type", "spot.num")
spot.num.score = merge(spot.mat, pre.mat.sum, by.x="cell.type", sort=F)
write.xlsx(spot.num.score, "NS_7_cellType_spotNum_score.xlsx", col.names=T, row.names=F)
NS_7_sct$spot.cell.type = max_cell_type
pdf("NS_7_spot_cell_type_prediction_all.pdf")
SpatialPlot(NS_7_sct, group.by="spot.cell.type")+labs(title = "NS_7")+guides(fill = guide_legend(override.aes = list(size = 5)))
dev.off()
pdf("NS_7_max_spot_cellType.pdf")
for (i in levels(cell.type)){
idx = which(max_cell_type == i)
cell = colnames(NS_7_sct)[idx]
if(length(idx)!=0){
p = SpatialPlot(NS_7_sct, cells.highlight=cell)+theme(legend.position="None")+labs(title=i)
print(p)
}
}
dev.off()
}
边栏推荐
猜你喜欢
随机推荐
行业洞察 | 如何更好的实现与虚拟人的互动体验?
内存模型之有序性
dflow入门1——HelloWorld!
第十二天&接口和协议
frp: open source intranet penetration tool
NFT到底有哪些实际用途?
Mysql的in和exists用法区别
mysql的innodb存储引擎和myisam存储引擎的区别
QT中线程调用GUI主线程控件的问题
用diskpart的offline命令弹出顽固硬盘
FusionAccess软件架构、FusionAccess必须配置的四个组件、桌面发放流程、虚拟机组类型、桌面组类型
WPS EXCEL 筛选指定长度的文本 内容 字符串
LeetCode 每日一题——622. 设计循环队列
qt使用mysql数据库(自学笔记)
MySQL2
Eject stubborn hard drives with diskpart's offline command
The Transformer, BERT, GPT paper intensive reading notes
Redis的基础与django使用redis
ArcEngine(八)用IWorkspaceFactory加载矢量数据
mysql 8.0.12 安装配置方法并--设置修改密码









