单细胞分析实录(8): 展示marker基因的4种图形(一) 您所在的位置:网站首页 气泡图怎么画的 单细胞分析实录(8): 展示marker基因的4种图形(一)

单细胞分析实录(8): 展示marker基因的4种图形(一)

2024-07-15 15:31| 来源: 网络整理| 查看: 265

今天的内容讲讲单细胞文章中经常出现的展示细胞marker的图:tsne/umap图、热图、堆叠小提琴图、气泡图,每个图我都会用两种方法绘制。

使用的数据来自文献:Single-cell transcriptomics reveals regulators underlying immune cell diversity and immune subtypes associated with prognosis in nasopharyngeal carcinoma. 去年7月发表在Cell Research上的关于鼻咽癌的文章,数据下载:https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE150430

髓系细胞数量相对少一些,为了方便演示,选它作为例子。

library(Seurat) library(tidyverse) library(harmony) Myeloid=read.table("Myeloid_mat.txt",header = T,row.names = 1,sep = "\t",stringsAsFactors = F) Myeloid_anno=read.table("Myeloid_anno.txt",header = T,sep = "\t",stringsAsFactors = F)

导入数据的时候需要注意一个地方:从cell ranger得到的矩阵,每一列的列名会在CB后面加上"-1"这个字符串,在R里面导入数据时,会自动转化为".1",在做匹配的时候需要注意一下。我已经提前转换为"_1"

> summary(as.numeric(Myeloid["CD14",])) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.000 0.000 0.689 1.080 2.111 4.500 > summary(as.numeric(Myeloid["PTPRC",])) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.000 1.200 1.681 1.607 2.124 3.520

考虑到下载的表达矩阵,表达值都不是整数,且大于0,推测该矩阵已经经过了标准化,因此下面的流程会跳过这一步

0. Seurat流程

我们直接把注释结果赋值到[email protected]矩阵中,后面省去聚类这一步

mye.seu=CreateSeuratObject(Myeloid) [email protected]$CB=rownames([email protected]) [email protected]=merge([email protected],Myeloid_anno,by="CB") rownames([email protected])[email protected]$CB #替代LogNormalize这一步 mye.seu[["RNA"]]@data=mye.seu[["RNA"]]@counts mye.seu %arrange(celltype) rownames(colanno)=colanno$CB colanno$CB=NULL colanno$celltype=factor(colanno$celltype,levels = unique(colanno$celltype))

先对细胞进行排序,按照celltype的顺序,然后对基因排序

rowanno=markerdf1 rowanno=rowanno%>%arrange(celltype)

提取scale矩阵的行列时,按照上面的顺序

mat4=mye.seu[["RNA"]]@scale.data[rowanno$gene,rownames(colanno)] mat4[mat4>=2.5]=2.5 mat4[mat4 < (-1.5)]= -1.5 #小于负数时,加括号!

下面就是绘图代码了,我加了分界线,使其看上去更有区分度

pheatmap(mat4,cluster_rows = F,cluster_cols = F, show_colnames = F, annotation_col = colanno, gaps_row=as.numeric(cumsum(table(rowanno$celltype))[-6]), gaps_col=as.numeric(cumsum(table(colanno$celltype))[-6]), filename="heatmap.2.pdf",width=11,height = 7 )

先写到这儿吧(原本以为能写完的),剩下的气泡图、堆叠小提琴图改天再补上。

因水平有限,有错误的地方,欢迎批评指正!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有