这里是引用

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阳性 和阴性在空转上的映射
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 #字体容易出错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  26758All.merge.SCT = SCTransform(All.merge.SCT, verbose = FALSE) %>% RunPCA(verbose = FALSE)  #默认3000个HVGAll.merge.SCT$cell.type = labeltable(All.merge.SCT$cell.type)dim(All.merge.SCT@assays$SCT@scale.data)cell.type = All.merge.SCT$cell.typelibrary(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_sctDefaultAssay(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_typepdf("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_sctDefaultAssay(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_typepdf("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_56load("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_sctDefaultAssay(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_typepdf("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_sctDefaultAssay(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_typepdf("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()
}

gpnmb+ gpnmb-AT2 cell空转映射 上皮细胞的空转映射相关推荐

  1. 【STM32】端口复用和重映射,完全重映射,部分重映射

    文章目录 端口复用 端口复用函数总结 端口重映射 完全重映射 完全重映射函数总结 部分重映射 端口复用 当 PA9,PA10 引脚作为串口 1 的 TX,RX 引脚使用的时候,那就是端口复用(相较于作 ...

  2. 【SSH系列】Hibernate映射 -- 一对多关联映射

         映射原理        一对多关联映射和多对一关联映射的映射原理是一样一样的,所以说嘛,知识都是相通的,一通百通,为什么说一对多关联映射和多对一关联映射是一样的呢?因为她们都是在多的一端加入 ...

  3. ARM的存储器映射与存储器重映射【转载】2009-12-14 10:29最近在用LPC2148,看到了一篇文章,感觉很有帮助,就转了过来。

    ARM的存储器映射与存储器重映射[转载]2009-12-14 10:29最近在用LPC2148,看到了一篇文章,感觉很有帮助,就转了过来. arm处理器本身所产生的地址为虚拟地址,每一个arm芯片内都 ...

  4. 【SSH进阶之路】Hibernate映射——一对一单向关联映射(五)

    [SSH进阶之路]Hibernate基本原理(一) ,小编介绍了Hibernate的基本原理以及它的核心,采用对象化的思维操作关系型数据库. [SSH进阶之路]Hibernate搭建开发环境+简单实例 ...

  5. 映射技术之储存器映射

    映射技术之储存器映射 一般情况下,我们希望当数据流过FPGA时,FPGA尽可能多地处理数据,并且减少FPGA和外部设备之间的数据传输,采用流水处理架构则可以很好地减少对存储器的频繁读写. 很少会把帧缓 ...

  6. Linux内核访问外设I/O--动态映射(ioremap)和静态映射(map_desc)

    本篇文章主要介绍了"Linux内核访问外设I/O--动态映射(ioremap)和静态映射(map_desc)",主要涉及到Linux内核访问外设I/O--动态映射(ioremap) ...

  7. mysql映射超_Hibernate的映射类型 hibernate mysql映射类型

    (转)http://blog.csdn.net/zxy_snow/article/details/7214222 Hibernate的映射类型 hibernate mysql映射类型 1.Hibern ...

  8. 字符设备驱动高级篇5——静态映射表、动态映射结构体方式操作寄存器

    以下内容源于朱有鹏<物联网大讲堂>课程的学习整理,如有侵权,请告知删除. 一.静态映射表建立过程分析 1.建立映射表的三个关键部分 (1)映射表描述 具体物理地址和虚拟地址的值相关的宏定义 ...

  9. 分布式映射与集中式映射_K映射上的表达式映射和组包围

    分布式映射与集中式映射 In the previous article (Karnaugh Map 2, 3 and 4- variable) we have already discussed th ...

最新文章

  1. php curl ob start,curl - php中开启缓冲压缩 ob_start('ob_gzhandler') 之后是在什么时候开始的压缩?...
  2. 把字符串每隔四个字符使用“-”中横线分隔的方法
  3. NOIP 2016【蚯蚓】
  4. C++,Java编程中 标识符 常见命名约定
  5. oracle的todate函数 不用英文,关于在mybaties 和 oracle的to_date函数的问题?
  6. java把map值放入vector_Thinking in java基础之集合框架
  7. 1049. 最后一块石头的重量 II(JavaScript)
  8. Android开发文档
  9. java spark读写hdfs文件,Spark1.4从HDFS读取文件运行Java语言WordCounts
  10. 手机、桌面和浏览器应用程序开发的差异
  11. 移动终端如何远程接入企业的核心系统?
  12. 高效测试必学 | 用pytest生成测试报告
  13. 夏至与北回归线的故事
  14. 地球上20张最惊人照片!不看将后悔一辈子
  15. 全纯函数导数的几何意义
  16. nginx+php-fpm docker镜像合二为一
  17. mysql gh ost 对比_GitHub开源MySQL Online DDL工具gh-ost参数解析
  18. 纯前端导出export,复杂表格表头合并,表头数据部分动态,
  19. C语言 计算cosx的近似值
  20. QQ机器人-nonebot

热门文章

  1. KGAT 2019(KDD)Knowledge Graph Attention Network for Recommendation
  2. 《TP5.0学习笔记---百度地图封装》
  3. 钉钉老版本下载3.31_钉钉2016旧版本下载-钉钉2016历史版本v5.1.31 安卓手机版 - 极光下载站...
  4. java求偶数位之和,Java实战开发今日头条资讯网站
  5. 谈谈你对Spring的理解
  6. 实现ImageView的双指缩放
  7. linux系统建立ftp用户名和密码,linux系统搭建ftp服务器及创建用户使用
  8. openJDK源码下载及阅读
  9. 轻量级神经网络算法系列文章-MobileNet v3
  10. 在英文版的excel中把数字转换成中文金额大写