You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法保存plotBS()输出的树数据——基于phyDat序列构建进化树的问题

Saving Bootstrap Tree Data from plotBS() in phangorn

Got it, I've run into this exact issue before with phangorn's plotBS()! The key thing most people miss is that plotBS() actually returns a modified phylogenetic tree object (with bootstrap values attached as node labels) — you just need to capture that return value instead of only running the function to plot. Here's how to do it step-by-step with your data:

Step 1: Complete Tree Construction & Bootstrap Analysis (if you haven't already)

First, let's tie together your existing sequence data with tree building and bootstrap testing (adjust the tree-building method if you used something like maximum likelihood instead of NJ):

library(seqinr)
library(phangorn)
library(ape) # Needed for tree-saving functions

# Your original sequence setup
seqs <- DNAMultipleAlignment( 
  c(a1 = "------ATGTTCATTAACCGCTGACTATTCTCAACCA", 
    a2 = "------ATGTTCACCGACCGCTGACTATTCTCTACAA", 
    a3 = "---GTGACCTTCATCAACCGATGATTATTCTCAA---", 
    a4 = "---TCAGTCGTCACCAGGCGTTG-CAGGACCCGAC--", 
    a5 = "ATGGGGGTCTTCCTCA-TCGCCGTCGCCGCGT-----"))
phyDat_seqs <- as.phyDat(seqs)

# Build initial tree (example: Neighbor-Joining)
dm <- dist.ml(phyDat_seqs)
base_tree <- NJ(dm)

# Run bootstrap replicates (adjust `bs` to your desired number of replicates)
bs_replicates <- bootstrap.phyDat(phyDat_seqs, 
                                  FUN = function(x) NJ(dist.ml(x)), 
                                  bs = 100)

Step 2: Capture the Bootstrap Tree from plotBS()

Instead of just running plotBS() to visualize, assign its output to a variable — this variable will hold your tree with bootstrap values embedded:

# Plot the bootstrap tree AND capture the tree object
bootstrap_tree <- plotBS(base_tree, bs_replicates, 
                         type = "phylogram", # Adjust plot type as needed
                         bs.col = "blue",    # Customize bootstrap text color
                         bs.adj = 0.5)       # Adjust bootstrap text position

Step 3: Save the Bootstrap Tree to File

Now use ape package functions to write the tree to a standard phylogenetic file format (Newick or Nexus):

# Save as Newick format (most common for tree viewers)
write.tree(bootstrap_tree, file = "bootstrap_tree.nwk")

# OR save as Nexus format
write.nexus(bootstrap_tree, file = "bootstrap_tree.nex")

Key Notes:

  • The bootstrap_tree object is a standard phylo class object, so any tree-manipulation or saving function that works with phylo objects will work here.
  • Bootstrap values are stored in the node.label slot of the bootstrap_tree object — you can verify this with bootstrap_tree$node.label.

内容的提问来源于stack exchange,提问作者Mel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:18:54