R NMF包:如何提取样本分类?

时间:2016-11-20 12:58:10

标签: r cluster-analysis consensus nmf

在NMF R-package中,可以使用consensusmap()来显示输出。这些图显示哪些样本属于“共识”轨道中的哪些聚类。

我想提取这个样本分类,以便得到这样的数据框:

Sample    Cluster
S1        1
S2        1
S3        2
S4        1
.         .
.         .
S100      2

在ConsensusClusterPlus包中,这很容易。你只需抽出结果$ consensusClass。我找不到NMF包的类似解决方案。我试图查看原始绘图数据,但是从提取任何含义过于复杂。

这里是问题的一个例子:我需要找出“共识”中的“状态”。

enter image description here

1 个答案:

答案 0 :(得分:0)

走遍整棵树并数数?

> v <- syntheticNMF(20, 3, 10)

> xx<-consensusmap(x) 

> str(xx)
List of 4
$ Rowv  :  ..--[dendrogram w/ 2 branches and 10 members at h = 1,  midpoint = 5.97, value = 3.4]
  ..  |--[dendrogram w/ 2 branches and 7 members at h = 1, midpoint = 3.69, value = 2.5]
  ..  |  |--[dendrogram w/ 2 branches and 4 members at h = 0, midpoint = 2.12, value = 1.6]
  ..  |  |  |--[dendrogram w/ 2 branches and 3 members at h = 0, midpoint = 1.25, value = 1.2]
  ..  |  |  |  |--[dendrogram w/ 2 branches and 2 members at h = 0, midpoint = 0.5, value = 0.8]
  ..  |  |  |  |  |--leaf "2" ( value.2 = 0.4 )
  ..  |  |  |  |  `--leaf "1" ( value.1 = 0.4 )
  ..  |  |  |  `--leaf "3" ( value.3 = 0.4 )
  ..  |  |  `--leaf "4" ( value.4 = 0.4 )
  ..  |  `--[dendrogram w/ 2 branches and 3 members at h = 0, midpoint = 1.25, value = 0.9]
  ..  |     |--[dendrogram w/ 2 branches and 2 members at h = 0, midpoint = 0.5, value = 0.6]
  ..  |     |  |--leaf "6" ( value.6 = 0.3 )
  ..  |     |  `--leaf "5" ( value.5 = 0.3 )
  ..  |     `--leaf "7" ( value.7 = 0.3 )
  ..  `--[dendrogram w/ 2 branches and 3 members at h = 0, midpoint = 1.25, value = 0.9]
  ..     |--[dendrogram w/ 2 branches and 2 members at h = 0, midpoint = 0.5, value = 0.6]
  ..     |  |--leaf "9" ( value.9 = 0.3 )
  ..     |  `--leaf "8" ( value.8 = 0.3 )
  ..     `--leaf "10" ( value.10 = 0.3 )
  $ rowInd: int [1:10] 2 1 3 4 6 5 7 9 8 10
  $ Colv  :  ..--[dendrogram w/ 2 branches and 10 members at h = 1, midpoint = 3.03, value = 3.4]
  ..  |--[dendrogram w/ 2 branches and 3 members at h = 0, midpoint = 0.75, value = 0.9]
  ..  |  |--leaf "10" ( value.10 = 0.3 )
  ..  |  `--[dendrogram w/ 2 branches and 2 members at h = 0, midpoint = 0.5, value = 0.6]
  ..  |     |--leaf "8" ( value.8 = 0.3 )
  ..  |     `--leaf "9" ( value.9 = 0.3 )
  ..  `--[dendrogram w/ 2 branches and 7 members at h = 1, midpoint = 2.31, value = 2.5]
  ..     |--[dendrogram w/ 2 branches and 3 members at h = 0, midpoint = 0.75, value = 0.9]
  ..     |  |--leaf "7" ( value.7 = 0.3 )
  ..     |  `--[dendrogram w/ 2 branches and 2 members at h = 0, midpoint = 0.5, value = 0.6]
  ..     |     |--leaf "5" ( value.5 = 0.3 )
  ..     |     `--leaf "6" ( value.6 = 0.3 )
  ..     `--[dendrogram w/ 2 branches and 4 members at h = 0, midpoint = 0.875, value = 1.6]
  ..        |--leaf "4" ( value.4 = 0.4 )
  ..        `--[dendrogram w/ 2 branches and 3 members at h = 0, midpoint = 0.75, value = 1.2]
  ..           |--leaf "3" ( value.3 = 0.4 )
  ..           `--[dendrogram w/ 2 branches and 2 members at h = 0, midpoint = 0.5, value = 0.8]
  ..              |--leaf "1" ( value.1 = 0.4 )
  ..              `--leaf "2" ( value.2 = 0.4 )
 $ colInd: int [1:10] 10 8 9 7 5 6 4 3 1 2


> lapply(cut(xx$Rowv,0.5)$lower, function(l) rapply(l, function(i) i))
[[1]]
[1] 2 1 3 4

[[2]]
[1] 6 5 7

[[3]]
[1]  9  8 10