【问题标题】:How to adjust the branch length of dendrogram converted from Newick file?如何调整从 Newick 文件转换的树状图的分​​支长度?
【发布时间】:2021-08-02 05:10:08
【问题描述】:

您好,我的目标是制作物种丰度的热图,并同时显示系统发育树。系统发育树在 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)

Output heat map with phylogeny tree

【问题讨论】:

  • 这和git有什么关系? (我认为您可能已经接受了基于“分支”一词的机器建议,但 Git 的分支与系统发育分支无关。请检查并更正您的标签。)

标签: r


【解决方案1】:

我们可以结合使用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

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 2011-11-18
    • 2013-10-05
    相关资源
    最近更新 更多