当前位置:网站首页>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()
}
边栏推荐
- Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
- FusionAccess软件架构、FusionAccess必须配置的四个组件、桌面发放流程、虚拟机组类型、桌面组类型
- “==”和equals的区别
- 获取JDcookie的方法
- 用diskpart的offline命令弹出顽固硬盘
- window的供选数据流
- ArcEngine(一)加载矢量数据
- 二进制日志过期时间设置expire_logs_days
- mysql 8.0.12 安装配置方法并--设置修改密码
- ArcEngine (5) use the ICommand interface to achieve zoom in and zoom out
猜你喜欢
随机推荐
【论文笔记】一种基于启发式奖赏函数的分层强化学习方法
unity的game界面里有canvas的线框?如何隐藏掉?
BOM系列之localStorage
WPF 学习笔记《WPF样式基础》
flutter 应用 抓包
IDEA2021.2安装与配置(持续更新)
Unity关于编辑器扩展自定义标签,方便扩展Inspector
批量将PNG格式转化为JPG格式
基于SSM开发的的小区物业管理系统小程序源码
国内IT市场还有发展吗?有哪些创新好用的IT运维工具可以推荐?
LINGO 18.0软件安装包下载及安装教程
流行和声基础大笔记
多线程下的单例模式
Path Prefixes (倍增!树上の二分)
ArcEngine (5) use the ICommand interface to achieve zoom in and zoom out
C# 一周入门高级编程之《C#-继承》Day One
ArcEngine (1) Loading vector data
Evaluate:huggingface评价指标模块入门详细介绍
Add Modulo 10 (规律循环节,代码实现细节)
内存模型之可见性