[英]Pheatmap: Make hierarchical clustering on full matrix but only display subset of rows
我有一个基因表达数据集,想显示一些基因的热图。 首先,我想基于所有基因进行层次聚类,创建树状图,然后在这些基因的子集上创建热图。 明确地说,热图的列与已创建的树状图相同,但显示的行较少。 我尝试使用下面的代码,但似乎Pheatmap根据简化后的矩阵对群集进行了重新排序。
# Random data
full_mat <- matrix(rgamma(1000, shape = 1) * 5, ncol = 50)
reduced_mat <- full_mat[1:5,]
# Function to calculate distances on full-matrix and make dendrogram
cl_cb <- function(hcl, mat){
# Recalculate manhattan distances for reorder method
dists <- dist(full_mat, method = "manhattan")
# Perform reordering according to OLO or GW method
hclust_olo <- reorder(hcl, dists, method="GW")
return(hclust_olo)
}
# Only display the reduced matrix (same columns but fewer rows)
p <- pheatmap(reduced_mat,
show_rownames=TRUE,
show_colnames = TRUE,
cluster_cols=T,
cluster_rows=F,
scale = "none",
clustering_callback = cl_cb
)
我尝试设置cluster_cols = F
但是根本没有进行树状图或重新排序。
尝试改用heatmap.2
函数。 如果尚未安装,请安装。
之后,运行以下命令:
heatmap.2(reduced_mat, dendrogram = "both", labRow=row.names(reduced_mat),
labCol=colnames(reduced_mat), Colv = FALSE, Rowv = FALSE)
#If you want to only show row or col dendrogram, change dendrogram = "both" to dendrogram = "column" (or "row")
它仍然会基于子集数据集生成树状图,但是,它不应更改所使用矩阵的顺序。 如果我理解正确,这就是您想要的。
如果您使用dput()
提供了可复制的示例,我可以自己尝试一下。
如果设置了此功能,也许您可以做的就是创建热图,保持行和列的顺序,不创建第二个树状图,而是将热图另存为图像,可以使用以下:
dev.copy(jpeg,filename="plot.jpg")
dev.off ()
对原始热图执行相同的操作,裁剪出所需树状图的一部分,然后将其粘贴在photoshop中或绘制到创建的第二个热图图像上。
但是,正如我在评论中提到的那样,这不是子集数据集的“真实”树状图,而是原始热图的“摘要”。
让我知道它是否有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.