前言
cellphoneDB是一个单细胞测序下游分析中,分析细胞受体-配体交互的很方便的数据库和软件,也有完备的可视化结果展示,但是在热图中,并没有给到设置热图legend的范围的参数,因此,它所生成的多个数据集的热图的颜色范围是不一致的,假如想要比对多个数据集之间的差异,那么设置colorbar的一致性就显得尤为重要
方法
先看一下官方的参数设置:
--pvalues-path: The pvalues output file [./out/pvalues.txt]--output-path: Output folder [./out]--count-name: Filename of the output plot [heatmap_count.pdf]--log-name: Filename of the output plot using log-count of interactions [heatmap_log_count.pdf]--count-network-name: Filename of the output network file [count_network.txt]--interaction-count-name: Filename of the output interactions-count file [interactions_count.txt]--pvalue: pvalue threshold to consider when plotting [0.05]--verbose / --quiet: Print or hide cellphonedb logs [verbose]
的确没有设置的参数,那么既然官方说采用了pheatmap画热图,那么我们也用
首先,处理数据
在首次运行heatmap_plot后,会生成这样的一个文件XX_count_net.txt,
这个数据就是用来画热图的数据,接下来直接转换成矩阵
library(readr)library(dplyr)library(pheatmap)test<-read_delim("./test/test_count_net.txt",delim = "\t")##我们给数据作log(x+1)处理test_log<-test%>%mutate(count=log1p(count))%>%tidyr::pivot_wider(names_from = "TARGET",values_from="count")%>%tibble::column_to_rownames(var="SOURCE")%>%as.matrix()
然后,画图就可以了
col.heatmap<-colorRampPalette(c("dodgerblue4","peachpuff","deeppink4"))(1000)pheatmap(test_log,show_rownames = T,show_colnames = T,scale = "none",cluster_rows = T,cluster_cols = T,border_color = "white",fontsize_row = 11,fontsize_col = 11,treeheight_row = 0,treeheight_col = 0,family='Arial',color = col.heatmap,breaks = seq(0.5,4,length=1000),#这里设置你想要的区间,length必须和颜色数目相同legend_breaks = c(1,1.5,2,2.5,3,3.5))#这里设置legend上显示的数值
