[英]Trying to root a phylogenetic tree using phangorn package in R
我正在嘗試使用 R 中的 phangorn package 來根植一個 phylog.netic 樹(我之前使用 DECIPHER 和 phagorn 為微生物組研究創建了 16S 數據)。但是,我遇到了一個問題,指出節點數量需要要大於類群的數量。 該樹有 2151 個節點。 使用 Dada2 管道將相關序列分為 2153 個分類群。 樹中的序列和 phyloseq object (ps) 中的 refseq 中的序列完全相同。 我對此很陌生。 如果您需要任何其他信息,請告訴我。 先感謝您!
直到發生錯誤的部分的所有相關代碼:
#從dada2 output object中提取序列:
sequences <- getSequences(seqtab.nochim)
names(sequences) <- sequences
#使用 DECIPHER 運行序列 alignment (MSA):
alignment <- AlignSeqs(DNAStringSet(sequences), anchor=NA)
#將序列alignment output改成phyDat結構
phang.align <- phyDat(as(alignment, "matrix"), type="DNA")
#創建距離矩陣
dm <- dist.ml(phang.align)
#執行鄰居加入
treeNJ <- NJ(dm)
#注意,提示順序不是序列順序
#內部最大似然
fit <- pml(treeNJ, data=phang.align)
#negative edges length 更改為 0!
#Fit the tree #注意:這一步可能需要相當長的時間......
optim.pml()
fitGTR <- update(fit, k=4, inv=0.2)`
fitGTR <- optim.pml(fitGTR, model="GTR", optInv=TRUE, optGamma=TRUE,
rearrangement = "stochastic", control = pml.control(trace = 0))
#導入現有的phyloseq object“ps”:
ps@phy_tree <- fitGTR$tree
ps@phy_tree
#Phylog.netic 樹有 2153 個提示和 2151 個內部節點 - 好!
#Need root 它用於基於系統發育的多樣性指標(Unifrac)
phy_tree(ps) <- root(phy_tree(ps), taxa_names(ps), 1, resolve.root = TRUE)
Error in root.phylo(phy_tree(ps), taxa_names(ps), 1, resolve.root = TRUE) : incorrect node#: should be greater than the number of taxa
ape::root
需要新根節點的 id。 第一個節點是葉子。 將樹根植於葉子上是沒有意義的,因此是錯誤的。 葉子沒有孩子,根必須有孩子,否則它就是一棵空樹。
使用 tidytree as_tibble
中的tidytree
as_tibble 獲取節點元數據表以提取所需的節點 ID:
library(ape)
library(tidytree)
# create example tree
tree <- read.tree(text='((A, B), ((C, D), (E, F)));')
tree <- makeNodeLabel(tree)
as_tibble(tree)
#> # A tibble: 11 x 3
#> parent node label
#> <int> <int> <chr>
#> 1 8 1 A
#> 2 8 2 B
#> 3 10 3 C
#> 4 10 4 D
#> 5 11 5 E
#> 6 11 6 F
#> 7 7 7 Node1
#> 8 7 8 Node2
#> 9 7 9 Node3
#> 10 9 10 Node4
#> 11 9 11 Node5
plot(tree, show.node.label = TRUE)
# Root tree on leaf E (5th node)
# Does not make sense
tree2 <- root(phy = tree, node = 5)
#> Error in root.phylo(phy = tree, node = 5): incorrect node#: should be greater than the number of taxa
# Root tree on internal Node2 (8th node)
tree3 <- root(phy = tree, node = 8)
plot(tree3, show.node.label = TRUE)
由reprex package (v2.0.0) 創建於 2022-02-10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.