当前位置:网站首页>addmodule_allmerge_ams_im
addmodule_allmerge_ams_im
2022-06-30 15:48:00 【youngleeyoung】
library(patchwork)
library(ggplot2)
library(ggalluvial)
library(svglite)
library(Seurat)
library(openxlsx)
library(Hmisc)
#https://www.jianshu.com/p/cef5663888ff
getwd()
path="G:/silicosis/sicosis/silicosis_ST/overlapped_map/addmodule_allmarkers_from_findallmarkers_allmerge_ams_im"
dir.create(path)
setwd(path)
getwd()
load("G:/silicosis/sicosis/yll/macrophage/no cluster2/0.3/pure_cluster3_in_allmerge-IM/silicosis_cluster_merge.rds")
table(All.merge$new.cluster.idents)
#比例图
markers=FindAllMarkers(All.merge,min.pct = 0.75,logfc.threshold = 0.8,only.pos = T)
head(markers)
unique(markers$cluster)
library(stringr)
Myselectedmarekrs=markers %>% filter(str_detect(markers$cluster,"AM"))
DotPlot(All.merge,features=Myselectedmarekrs$gene[1:30])+RotatedAxis()
#openxlsx::write.xlsx(markers,file = "G:/silicosis/sicosis/silicosis_ST/overlapped_map/addmodule/markers_forallmerge_ams_im.xlsx")
library(openxlsx)
load("G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster/d_all/silicosis_ST_harmony_SCT_r0.6.rds")
load("G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster/d_all/silicosis_ST_harmony_SCT_r0.6.rds")
#marker = read.xlsx("G:/silicosis/sicosis/silicosis_ST/overlapped_map/Rigional and cell markers.xlsx",
# sheet = "SingleCell_markers")
#markers=read.xlsx('G:/silicosis/sicosis/yll/macrophage/no cluster2/0.3/findmarkers_1and2/30cluster_markers.xlsx')
#markers=read.xlsx("G:/silicosis/sicosis/silicosis-1122-merge/silicosis_cluster_merge_markers.xlsx")
markers=read.xlsx("G:/silicosis/sicosis/silicosis_ST/overlapped_map/addmodule/markers_forallmerge_ams_im.xlsx")
head(markers)
library(dplyr)
markers=markers %>% group_by(cluster) %>% slice_head(n=20) %>%select(cluster,gene)
head(markers)
library(reshape2)
markers2=dcast(markers,gene~cluster)
head(markers2)
markers2[is.na(markers2)]<-0
head(markers2)
markers2=markers2[,-1]
marker=markers2
head(marker)
cellnames=colnames(marker) ##number=length(marker[,cellname])
library(Hmisc)
getwd()
#path="G:/silicosis/sicosis/silicosis_ST/overlapped_map/addmodule_allmarkers_from_findallmarkers"
path="G:/silicosis/sicosis/silicosis_ST/overlapped_map/addmodule_allmarkers_from_findallmarkers_allmerge_ams_im"
dir.create(path)
setwd(path)
getwd()
for (each in cellnames) {
#each='Myofibroblast/vascular smooth muscle cell'
cellname=each
mymarker=marker[,paste0(cellname)] %>% na.exclude() %>% unique() %>%
list() #capitalize() %>%
number=length(mymarker[[1]])
unlist(mymarker)
#对给定的基因集合进行打分 并画图
if(1==1){
d.all=AddModuleScore(d.all,
features = mymarker,
name = paste0(cellname))
#结果保存在这里
colnames(d.all@meta.data)
head(d.all@meta.data)
colnames(d.all@meta.data)[[9]]=paste0(cellname)
###
p1=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image")+ ggtitle(paste0("SiO2_7d")) #sio27d
p2=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.1")+ggtitle(paste0("NS_7d"))
p3=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.2")+ ggtitle(paste0("SiO2_56d"))
p4=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.3")+ggtitle(paste0(("NS_56d")))
jpeg(paste0(ifelse(grep(paste0(cellname),pattern = "/"),"Myofibroblast-vascular smooth muscle cell",paste0(cellname))
,paste0(cellname),"_","total_",length(unlist(mymarker)),"_",paste0(min(number),"-",max(number)),
paste(unlist(mymarker)[1:15],collapse = "_"),"_.jpeg"), #只取前15个
height = 12, width = 12, units = 'in', res=600)
p=ggpubr::ggarrange(p2,p1,p4,p3,ncol = 2,nrow =2)
print(p)
dev.off()
d.all@meta.data=d.all@meta.data[,1:8] }
}
for (each in c("Neutrophil","NK cell","T cell")) {
#each='Myofibroblast/vascular smooth muscle cell'
cellname=each
mymarker=marker[,paste0(cellname)] %>% na.exclude() %>% unique() %>%
list() #capitalize() %>%
number=length(mymarker[[1]])
unlist(mymarker)
#对给定的基因集合进行打分 并画图
if(1==1){
d.all=AddModuleScore(d.all,
features = mymarker,
name = paste0(cellname))
#结果保存在这里
colnames(d.all@meta.data)
head(d.all@meta.data)
colnames(d.all@meta.data)[[9]]=paste0(cellname)
###
p1=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image")+ ggtitle(paste0("SiO2_7d")) #sio27d
p2=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.1")+ggtitle(paste0("NS_7d"))
p3=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.2")+ ggtitle(paste0("SiO2_56d"))
p4=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.3")+ggtitle(paste0(("NS_56d")))
jpeg(paste0(ifelse(grep(paste0(cellname),pattern = "/"),"Myofibroblast-vascular smooth muscle cell",paste0(cellname))
,paste0(cellname),"_","total_",length(unlist(mymarker)),"_",paste0(min(number),"-",max(number)),
paste(unlist(mymarker)[1:15],collapse = "_"),"_.jpeg"), #只取前15个
height = 12, width = 12, units = 'in', res=600)
p=ggpubr::ggarrange(p2,p1,p4,p3,ncol = 2,nrow =2)
print(p)
dev.off()
d.all@meta.data=d.all@meta.data[,1:8] }
}
#只要ns56 和sio2_56d
for (each in cellnames) {
#each='Myofibroblast/vascular smooth muscle cell'
cellname=each
mymarker=marker[,paste0(cellname)] %>% na.exclude() %>% unique() %>%
list() #capitalize() %>%
number=length(mymarker[[1]])
unlist(mymarker)
#对给定的基因集合进行打分 并画图
if(1==1){
d.all=AddModuleScore(d.all,
features = mymarker,
name = paste0(cellname))
#结果保存在这里
colnames(d.all@meta.data)
colnames(d.all@meta.data)[[9]]=paste0(cellname)
###
# p1=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image")+ ggtitle(paste0("SiO2_7d")) #sio27d
# p2=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.1")+ggtitle(paste0("NS_7d"))
p3=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.2")+ ggtitle(paste0("SiO2_56d"))
p4=SpatialFeaturePlot(d.all, features = paste0(cellname), slot = "scale.data",images = "image.3")+ggtitle(paste0(("NS_56d")))
jpeg(paste0(paste0(cellname),"_","total_",length(unlist(mymarker)),"_",paste0(min(number),"-",max(number)),
paste(unlist(mymarker)[1:15],collapse = "_"),"_.jpeg"), #只取前15个
height = 12, width = 12, units = 'in', res=600)
p=ggpubr::ggarrange(p4,p3,ncol = 1,nrow =2)
print(p)
dev.off()}
}
边栏推荐
- Exception class_ Log frame
- Undistorted resize using pil
- jspreadsheet/CE JExcel数据字段比给的字段(columns)多会导致空白列的问题解决方案
- 【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
- halcon知识:区域专题【07】
- 备战数学建模35-时间序列预测模型
- restartProcessIfVisible的流程
- register_ Chrdev and CDEV_ init cdev_ Add usage differences
- Php7.3 centos7.9 installing sqlserver extensions
- [machine learning] K-means clustering analysis
猜你喜欢

The new tea drinks are "dead and alive", but the suppliers are "full of pots and bowls"?

List announced - outstanding intellectual property service team in China in 2021

Multi terminal collaboration of Huawei accounts to create a better internet life
![删除有序数组中的重复项 II[双指针--多情况统一]](/img/e2/cadfdbe476a86cb2d72c1ae0160a4a.png)
删除有序数组中的重复项 II[双指针--多情况统一]

备战数学建模35-时间序列预测模型

Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API

【微信小程序】小程序的宿主环境

Data mining knowledge points sorting (final review version)

数据挖掘知识点整理(期末复习版)

数据安全合规之后,给风控团队带来了新的问题
随机推荐
Eight basic sorting (detailed explanation)
搬运两个负载均衡的笔记,日后省的找
idea必用插件
ArcMap operation series: 80 plane to latitude and longitude 84
[demo] write file circularly
Headhunter 50, 000, I'll go to VC
go-micro教程 — 第一章 快速入门
More dragon lizard self-developed features! Production available Anolis OS 8.6 officially released
Mathematical modeling for war preparation 36 time series model 2
TCP socket and TCP connection
Data mining knowledge points sorting (final review version)
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
The new tea drinks are "dead and alive", but the suppliers are "full of pots and bowls"?
nichenet实战silicosis
异常类_日志框架
RT thread heap size Setting
2022蓝桥杯国赛B组-费用报销-(线性dp|状态dp)
2020 Blue Bridge Cup group B - move bricks - (greedy sorting +01 backpack)
STL tutorial 7-set, pair pair pair group and functor
Installing jupyter notebook under Anaconda