Heatmap引擎
NMF包中的热图引擎是由aheatmap函数实现,其余的热图函数都是基于它的修改。而aheatmap函数本身又是pheatmap包pheatmap函数的修改版本。引擎具体的优点作者有在文档是写,我就不唠叨了。
数据和模型
为了演示热图函数的用法,我们这里创建一个随机的NMF输入矩阵,以及一些注释和协变量。
library(NMF)#> Loading required package: pkgmaker#> Loading required package: registry#> #> Attaching package: 'pkgmaker'#> The following object is masked from 'package:base':#> #> isFALSE#> Loading required package: rngtools#> Loading required package: cluster#> Warning: replacing previous import 'colorspace::plot' by 'graphics::plot'#> when loading 'NMF'#> Warning: replacing previous import 'dendextend::cutree' by 'stats::cutree'#> when loading 'NMF'#> NMF - BioConductor layer [OK] | Shared memory capabilities [NO: bigmemory] | Cores 9/10#> To enable shared memory capabilities, try: install.extras('#> NMF#> ')# random data that follow an 3-rank NMF model (with quite some noise: sd=2)X <- syntheticNMF(100, 3, 20, noise=2)# row annotations and covariatesn <- nrow(X)
d <- rnorm(n)
e <- unlist(mapply(rep, c('X', 'Y', 'Z'), 10))
e <- c(e, rep(NA, n-length(e)))
rdata <- data.frame(Var=d, Type=e)# column annotations and covariatesp <- ncol(X)
a <- sample(c('alpha', 'beta', 'gamma'), p, replace=TRUE)
c <- rnorm(p)# gather them in a data.framecovariates <- data.frame(a, X$pData, c)查看下生成的注释数据:
head(rdata)#> Var Type#> 1 0.0900 X#> 2 0.0418 X#> 3 -2.1354 X#> 4 -0.1632 X#> 5 -1.6008 X#> 6 -1.0027 Xhead(covariates)#> a Group c#> 1 beta 1 0.601#> 2 gamma 1 -0.486#> 3 beta 1 1.661#> 4 alpha 1 1.017#> 5 alpha 1 -1.177#> 6 alpha 1 1.553
这里X实际是一个矩阵,rdata是行注释,covariates是列注释。
下面画图:
par(mfrow = c(1, 2)) aheatmap(X, annCol = covariates, annRow = X$fData) aheatmap(X)
[图片上传失败...(image-840b81-1545294882772)]
接着,我们使用NMF模型来分解矩阵。
res = nmf(X, 3, nrun = 10)
混合系数矩阵:coefmap
NMF结果的混合系数矩阵可以使用coefmap()函数进行绘制。该函数默认添加2个注释通道用来展示从最佳拟合结果中获得的簇(聚类数)和一致性矩阵的层次聚类。在图例中,这两个通道分别以basis和consensus命名。对于一个简单的NMF模型结果,一致性数据是不能显示的,只能通过最佳拟合进行聚类。
opar = par(mfrow = c(1, 2))# coefmap from multiple run fit: includes a consensus trackcoefmap(res)# coefmap of a single run fit: no consensus trackcoefmap(minfit(res))
[图片上传失败...(image-18b1ac-1545294882772)]
par(opar)
默认情况下:
行没有排序
列使用
aheatmap的默认顺序,不过设置Colv="basis"就能让列根据由主导的basis组分定义的类进行排序。或者设置Colv="consensus"让列以consensus矩阵排序每一列和为1(刻度化过)
调色板使用RColorBrewer包提供的“Y10rRd”,有50个刻度
如果想让coefmap()显示aheatmap()函数的默认形式,设置Rowv=TRUE, Colv=TRUE, scale='none'。
自动注释的通道可以使用tracks=NA进行隐藏,或者设置一个(tracks=':basis'或tracks='basis:'可以分别设置行注释或列注释),图例名可以以tracks=c(Metagene=':basis', 'consensus')的形式进行修改。除此之外,利用annCol参数可以添加用户设定的手动注释。
opar = par(mfrow = c(1,2))# removing all automatic annotation trackscoefmap(res, tracks = NA)# customized plotcoefmap(res, Colv = 'euclidean',
main = "Metagene contributions in each sample", labCol = NULL,
annRow = list(Metagene = ":basis"), annCol = list(':basis', Class = a, Index = c),
annColors = list(Metagene = 'Set2'),
info = TRUE)[图片上传失败...(image-751117-1545294882772)] 默认情况下: 列没有排序 行根据默认的层次聚类得到的距离进行排序( 每一行和为1 调色板使用RColorBrewer包提供的“Y10rRd”,有50个刻度 当使用NMF进行矩阵的时候,一种评估基于指定rank评估聚类稳定性的方法是考虑由多个独立NMF运行结果计算得到的连接矩阵。有篇par(opar)
eculidean和complete)一致性矩阵:consensusmap
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章