Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create RootedTree objects from their components? #76

Open
RiboRings opened this issue Oct 31, 2022 · 1 comment
Open

How to create RootedTree objects from their components? #76

RiboRings opened this issue Oct 31, 2022 · 1 comment

Comments

@RiboRings
Copy link

RiboRings commented Oct 31, 2022

Hello!

I am trying to disassemble a RootedTree object into its components and then reassemble it. However, I get a method error as follows:

# generate random tree
nu = Nonultrametric(20)
tree = rand(nu)

# reassemble tree components into a RootedTree
RootedTree(getfield(tree, :name),
           getfield(tree, :nodedict),
           getfield(tree, :roots),
           getfield(tree, :nodes),
           getfield(tree, :branches),
           getfield(tree, :data),
           getfield(tree, :tipdata),
           getfield(tree, :rootheight),
           getfield(tree, :isvalid),
           getfield(tree, :cache))

ERROR: MethodError: no method matching RootedTree(::Missing, ::Dict{String, Int64}, ::Vector{LinkNode{OneRoot, String,
 Dict{String, Any}, LinkBranch{OneRoot, String, Dict{String, Any}, Float64}}}, ::Vector{Union{Missing, LinkNode{OneRoot,
 String, Dict{String, Any}, LinkBranch{OneRoot, String, Dict{String, Any}, Float64}}}}, ::Vector{Union{Missing, 
LinkBranch{OneRoot, String, Dict{String, Any}, Float64}}}, ::Dict{String, Any}, ::Dict{String, Any}, ::Missing, ::Missing, 
::Dict{TraversalOrder, Vector{LinkNode{OneRoot, String, Dict{String, Any}, LinkBranch{OneRoot, String, Dict{String, Any},
 Float64}}}})
Closest candidates are:
  LinkTree{RT, NL, N, B, TD}(::TD) where {RT, NL, N, B, TD} at ~/.julia/packages/Phylo/0WXtf/src/LinkTree.jl:61

It would be great if you could provide a tutorial on how to build trees from scratch starting from their components.

Thank you in advance!

@richardreeve
Copy link
Member

@RiboRings - apologies for the delay in getting back to you - this is peak teaching for me at the moment. We've explicitly disabled the ability to make create a tree from its components as there are so many parts that need to align correctly - essentially every single component needs to match the elements in every other component, so the only way to easily construct a tree is to read one in or to generate a random one at the moment. Can I ask what you are trying to do?

If you want to construct a tree from scratch the way to manage that is to create an empty tree with the correct number of tips and then to use createnode!() and createbranch!() to create all of the internal nodes in sequence. An example of this in action is the code for rand() here, though there is some potentially superfluous code at the end of that function for adjusting all of the branch lengths retrospectively to fit a standard length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants