嗨,我的目标是制作一个物种丰富度的热图,并同时显示系统发育树。系统发育树在MEGA中制作,并在转换为树状图对象之前作为Newick文件输入到R中。
然而,系统发育树在输出图形中的分支长度并不相同。我可以问一下,有什么方法可以使分支长度相似吗?
我附上了下面的代码和输出。提前谢谢你。
library(DECIPHER)
library(dendextend)
library(ape)
#Input the tree from newick file from Mega and convert into dendrogram
dend <- ReadDendrogram("VPstrainand3-major_ASV_5%_withlength.nwk")
#Make the plot using data from the excel stored in the directory
#load the data
library(openxlsx)
library(dplyr)
heatmap.dataframe <- read.xlsx("Complete.xlsx","Modified", rowNames =TRUE)
heatmap.mat <- as.matrix(heatmap.dataframe)
whitered <- colorRampPalette(c("white", "red"), space = "rgb")(100)
#plot
library(repr)
options (repr.plot.width=20, repr.plot.height=20)
heatmap <- heatmap(as.matrix(heatmap.mat), Rowv = dend, Colv = NA, col = whitered)
print(heatmap)发布于 2021-08-11 15:41:07
我们可以结合使用dendrapply()和一个简单的函数-本例中名为ForceUltrametric的函数。这个表单可以用于几个不同的任务,dendrapply的帮助文件中的示例是用于更改叶子的颜色,但您可以使用它在叶子下面添加点,或者也可以调整标签。
你的整个过程在R中的一个可重现的例子,因为我们不能访问你的newick文件:
library(DECIPHER)
# using one of DECIPHER's built in examples:
db <- system.file("extdata",
"Bacteria_175seqs.sqlite",
package="DECIPHER")
dna <- SearchDB(db,
remove="all")
alignedDNA <- AlignSeqs(dna)
Dist <- DistanceMatrix(myXStringSet = alignedDNA,
includeTerminalGaps = TRUE, # global identity
verbose = TRUE)
tree1 <- IdClusters(myDistMatrix = Dist,
method = "NJ", # a non-ultrametric tree
verbose = TRUE,
showPlot = FALSE, # you can return a plot as the function completes, or not
type = "dendrogram") # return a dendrogram
ForceUltrametric <- function(n) {
if (is.leaf(n)) {
# if object is a leaf, adjust height attribute
attr(n, "height") <- 0L
}
return(n)
}
tree2 <- dendrapply(X = tree1,
FUN = function(x) ForceUltrametric(x))使用一些newick文件,我们无法访问这些文件,也不能保证正常工作:
library(DECIPHER)
tree1 <- ReadDendrogram("<yourfilehere>")
ForceUltrametric <- function(n) {
if (is.leaf(n)) {
# if object is a leaf, adjust height attribute
attr(n, "height") <- 0L
}
return(n)
}
tree2 <- dendrapply(X = tree1,
FUN = function(x) ForceUltrametric(x))应该注意的是,虽然在您想要将数据绘制在树叶下的情况下,强制树形图是超测量的是令人愉快的,但如果树是用非超测量方法构建的,那么它并不能真正准确地表示数据。
tree1

tree2

https://stackoverflow.com/questions/68616611
复制相似问题