Seurat::DoHeatmap 的谜之报错

作者: 黄海菌 | 来源:发表于2019-08-08 01:23 被阅读0次

    Seurat::DoHeatmap 的谜之报错

    最近在学习Seurat教程(Seurat版本3.0.2),发现运行到倒数第二步做热图展示marker genes时总是报错

    主要问题:

    DoHeatmap(pbmc, features = top10$gene) + NoLegend()
    

    运行结果:

    Warning message:
    In DoHeatmap(pbmc, features = top10$gene) :
    The following features were omitted as they were not found in the scale.data slot for the RNA assay: NEAT1, SLC25A39, AC090498.1, CTSS, DNAJB1, HSP90AA1, PRF1, NKG7, KLRD1, CD8B, DUSP4, CD8A, CCL5, CD27, GZMK, CD69, TNFAIP3, ZFP36L2, IL7R

    图片倒是生成了,但是数了一下基因数,确实少了很多,尤其是Cluster 0 和1,都没几个剩下的了


    1565194413212.png

    尝试自己调,一晚上也就调到这个程度:


    1565194545049.png

    好丑,还是继续研究下包里的代码吧/(ㄒoㄒ)/~~

    DoHeatMap
    

    看了一下代码,里面有这样一句:

      if (any(!features %in% possible.features)) {
        bad.features <- features[!features %in% possible.features]
        features <- features[features %in% possible.features]
        if (length(x = features) == 0) {
          stop("No requested features found in the ", 
               slot, " slot for the ", assay, " assay.")
        }
        warning("The following features were omitted as they were not found in the ", 
                slot, " slot for the ", assay, " assay: ", 
                paste(bad.features, collapse = ", "))
    

    这个bad.features来自features和possible.feature的比对,之后判断若features内元素个数不为零则warning:"The following features were omitted as they were not found in the ······“

    function (object, features = NULL, cells = NULL, group.by = "ident", 
              group.bar = TRUE, disp.min = -2.5, disp.max = NULL, slot = "scale.data", 
              assay = NULL, label = TRUE, size = 5.5, hjust = 0, angle = 45, 
              raster = TRUE, draw.lines = TRUE, lines.width = NULL, group.bar.height = 0.02, 
              combine = TRUE) 
    

    往回找,原来DoHeatMap()有个默认参数slot = "scale.data",自动用scale.data的数据画图。
    看一下这个Seurat对象的结构:


    1565195235734.png

    哈哈,发现问题了,原来counts (应该是raw read count)和data 都是20647行,每行对应一个基因,但scale.data只有2000行。

    > pbmc <- ScaleData(
    +   object = pbmc,
    +   do.scale = TRUE,
    +   do.center = FALSE,
    +   vars.to.regress = c("percent.mt"))
    

    重新ScaleData()一下,发现数据没有任何改变····

    算了,试试用data作图:

    DoHeatmap(pbmc, features = top10$gene,slot = "data") 
    
    1565195494082.png

    还是很难看,间接证明Seurat包开发者的可视化功力非同一般。但是没有报warning,而且可以看到消失的基因都出现了。

    试试直接给scale.data赋值:

    pbmc@assays$RNA@scale.data <- scale(pbmc@assays$RNA@data, scale = TRUE)
    DoHeatmap(pbmc, features = top10$gene,size = 0.5,slot = "scale.data") + NoLegend()
    

    这次也没有报warning,配色还是有点难看,大概是scale参数设置的不同,想完全复现可能还得查ScaleData的代码了。不过基本上能用了。增加了height,避免文字挤在一起,其实最好是保存成ggplot的对象,拼图的时候再改。

    1565195816712.png

    总结:

    产生这个问题的主要原因是ScaleData()指令生成scale.data(封装在Seurat对象里)中基因数减少。

    因为Seurat对象封装了好几层,并且对S4对象的操作也不太熟悉,所以一开始不太容易发现原因。

    另外,操作多个Seurat对象时注意偶尔rm()+gc()清空内存,我24G内存都好几次99%内存占用(╯‵□′)╯︵┻━┻

    相关文章

      网友评论

        本文标题:Seurat::DoHeatmap 的谜之报错

        本文链接:https://www.haomeiwen.com/subject/rjozdctx.html