当前位置: 首页 > news >正文

细胞打分 addmodule addmodule对所有细胞进行循环评分

细胞打分 addmodule addmodule对所有细胞进行循环评分

在这里插入图片描述


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-cluster013-mixed"
dir.create(path)
setwd(path)


从这里开始!!!!!!!!!!!!!!!!!!!!!!!1
getwd()
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")
**marker=read.xlsx("G:/silicosis/sicosis/yll/macrophage/no cluster2/0.3/pure_cluster01345_dotplot/cluster01345.xlsx")
head(marker)
library(dplyr)**

#判断

cellnames=colnames(marker)  #取出细胞的名字,即列名              ##number=length(marker[,cellname])

for (each in cellnames) {
  cellname=each
  
  mymarker=marker[,cellname]   %>% na.exclude() %>% unique() %>%
    capitalize()    %>% list()
  number=length(mymarker[[1]])
  unlist(mymarker)
  
  #对给定的基因集合进行打分  并画图
  if(1==1){d.all=AddModuleScore(d.all,
                                features = mymarker,
                                name = "mymarker")
  #结果保存在这里
  colnames(d.all@meta.data)
  
  ###
  
  p1=SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data",images = "image")+ ggtitle(paste(unlist(mymarker), collapse = "|"))
  p2=SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data",images = "image.1")
  p3=SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data",images = "image.2")+ ggtitle(paste(cellname))
  p4=SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data",images = "image.3")
  
  jpeg(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(p1,p2,p3,p4,ncol = 2,nrow =2)
  print(p)
  dev.off()}
}


#下面的代码是为了测试
if(1==1){#
  names(d.all)
  
  SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data")+ 
    ggtitle(paste(unlist(mymarker), collapse = "|"))
  
  #https://ggplot2-book.org/polishing.html?q=title#themes
  SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data")+ 
    theme(plot.title =element_text(paste(unlist(mymarker), collapse = "|")) )
  
  
  ####
  SpatialFeaturePlot(d.all, features = "mymarker1", slot = "scale.data")+ 
    labs(title = paste(unlist(mymarker), collapse = "|"),
         colour="Cylinders")
  
}

#再画一个所有细胞的dotplot气泡图 批量气泡图
在这里插入图片描述

##再画一个所有细胞的dotplot气泡图  批量气泡图
head(marker)
load(file = 'G:/silicosis/sicosis/silicosis-1122-merge/silicosis_cluster_merge.rds')
table(All.merge$new.cluster.idents)
table(All.merge$cell.type,All.merge$orig.ident)
Idents(All.merge)=All.merge$new.cluster.idents

#把datafram形式的marker基因制作成基因列表形式
cluster_marker=list()
for (eachcolum in colnames(marker)) {
  cluster_marker[[paste(eachcolum)]]= marker[,eachcolum] %>%unique() %>% capitalize()
}
unlist(cluster_marker)
unlist(lapply(cluster_marker, length))
head(cluster_marker)

在这里插入图片描述

#开始画图


getwd()
#批量做气泡图 Dotplot  all.merge
for (j in names(cluster_marker)) {#一定要记得是向量 而不是一个数 for j in(1:11) 一定记得加括号!!!1:length(cluster_marker!!!!!!!!!
  #j=5
  times=(length(cluster_marker[[j]])+10)/10
  times
  
  if (floor(times)>=2 ){
    for (i in seq(1,330,10)) { #使用循环出图 画图
      #i=1 
      if ((i+9)>(10*floor(times))) {next}   
      print(cluster_marker[[j]][i:(i+9)])
      jpeg(paste0("cluster_",j,"_",paste0(unlist(strsplit(cluster_marker[[j]][i:(i+2)], " "))[seq(1,3,1)],seq='_',collapse = "") , ".jpeg"),height = 9, width = 18, units = 'in', res=300)
      p=DotPlot(All.merge,
                features = cluster_marker[[j]][i:(i+9)])
      print(p)
      dev.off()
      print(paste0("cluster_",j));print(cluster_marker[[j]][i:(i+9)])
    } 
    print(j)
    
  } else{ #条件一定记得加括号! !!!!!!!!!!!!!!!11!!!!!!!!!!!
    print(j); print(cluster_marker[[j]][1:(1+9)])
    jpeg(paste0("cluster_",j,"_",paste0(unlist(strsplit(cluster_marker[[j]][1:(1+2)], " "))[seq(1,3,1)],seq='_',collapse = "") , ".jpeg"),height = 9, width = 18, units = 'in', res=300)
    p=DotPlot(All.merge,features = cluster_marker[[j]][1:(1+9)])
    print(p)
    dev.off()
  } 
}

getwd()
##批量做气泡图 Dotplot 画在同一张图上
#制作基因向量

all.gene=vector()
for (eachcellname in names(cluster_marker)) {
  all.gene=union(all.gene,cluster_marker[[eachcellname]]) %>% unique()
}
head(all.gene)

#画图
jpeg(paste0("allmerge" ,".jpeg"),height = 9, width = 18, units = 'in', res=300)
p=DotPlot(All.merge,features = all.gene)
print(p)
dev.off()


相关文章:

  • 6.4 序列及range函数
  • 5_addmodule空转spatial空转打分模块inflammatory炎症评分空转炎症评分 addmodule seurat
  • 6.5 python while 循环
  • 6.6 Python for 循环
  • 批量读取文件夹下所有excel文件里的内容,放入列表 把所有不管行列名如何excel合并成一个大的excel 批量读取excel,批量合并excel
  • 6.7 continue 和 break 语句
  • 批量多个excel合并成一个大的excel
  • 7.1 python 自定义函数的创建及调用
  • 7.2 Python return 语句
  • 6_ggplot可视化addmodule得到的炎症评分自己选择颜色 自定义更改显示的颜色 seurat得到的单细胞数据
  • 8.1 Python 类 对象 属性 方法
  • 8.2 类的实例化 调用属性 调用方法
  • 8.3 python __init__()方法
  • 多个h5文件整理到一个文件夹下面,不改变名字
  • 9.1 Python 绝对路径与相对路径
  • 自己简单写的 事件订阅机制
  • 【Redis学习笔记】2018-06-28 redis命令源码学习1
  • 【刷算法】从上往下打印二叉树
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • el-input获取焦点 input输入框为空时高亮 el-input值非法时
  • Fabric架构演变之路
  • idea + plantuml 画流程图
  • JDK9: 集成 Jshell 和 Maven 项目.
  • JS字符串转数字方法总结
  • Meteor的表单提交:Form
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • 分享一个自己写的基于canvas的原生js图片爆炸插件
  • 简单实现一个textarea自适应高度
  • 将回调地狱按在地上摩擦的Promise
  • 看完九篇字体系列的文章,你还觉得我是在说字体?
  • 利用DataURL技术在网页上显示图片
  • 扫描识别控件Dynamic Web TWAIN v12.2发布,改进SSL证书
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 小而合理的前端理论:rscss和rsjs
  • 优秀架构师必须掌握的架构思维
  • 职业生涯 一个六年开发经验的女程序员的心声。
  • Java性能优化之JVM GC(垃圾回收机制)
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • 函数计算新功能-----支持C#函数
  • 说说我为什么看好Spring Cloud Alibaba
  • ​软考-高级-系统架构设计师教程(清华第2版)【第12章 信息系统架构设计理论与实践(P420~465)-思维导图】​
  • ​无人机石油管道巡检方案新亮点:灵活准确又高效
  • ​油烟净化器电源安全,保障健康餐饮生活
  • ###51单片机学习(1)-----单片机烧录软件的使用,以及如何建立一个工程项目
  • #mysql 8.0 踩坑日记
  • #鸿蒙生态创新中心#揭幕仪式在深圳湾科技生态园举行
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (07)Hive——窗口函数详解
  • (1)(1.13) SiK无线电高级配置(五)
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (AngularJS)Angular 控制器之间通信初探
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (c语言版)滑动窗口 给定一个字符串,只包含字母和数字,按要求找出字符串中的最长(连续)子串的长度
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (二)springcloud实战之config配置中心