-
Notifications
You must be signed in to change notification settings - Fork 13
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
editing leaf names #54
Comments
Hmm. No, not at the moment. Can I ask why you want to do that? |
of course! |
Fair enough. I'll have a think about whether there's an easy way of doing it... |
thank you!! |
Sorry it has taken so long to get around to this, @shaul-pollak. I think I have a workaround on the off chance you're still interested. As of v0.5.1, we can export trees and so we can export and reimport through a newick tree to solve your problem, because for various nexus-format-related reasons the exported tree can have different node names than the tree in memory. So: julia> using Random, Phylo
julia> tree = rand(Nonultrametric(10));
julia> nn = getnodenames(tree);
julia> d = Dict(nn .=> nn);
julia> d["tip 1"] = "first tip"
"first tip"
julia> new_tree = parsenewick(Phylo.outputtree(t, Newick(d)));
julia> getleafnames(new_tree)
10-element Vector{String}:
"tip 8"
"tip 3"
"tip 5"
"tip 7"
"tip 9"
"first tip"
"tip 6"
"tip 4"
"tip 2"
"tip 10" You can also skip some nodes and they'll be given default names as they are read in: julia> ln = getleafnames(tree);
julia> d2 = Dict(ln .=> string.(Ref("newer "), ln))
Dict{String, String} with 10 entries:
"tip 7" => "newer tip 7"
"tip 4" => "newer tip 4"
"tip 8" => "newer tip 8"
"tip 1" => "newer tip 1"
"tip 9" => "newer tip 9"
"tip 2" => "newer tip 2"
"tip 10" => "newer tip 10"
"tip 6" => "newer tip 6"
"tip 5" => "newer tip 5"
"tip 3" => "newer tip 3"
julia> newer_tree = parsenewick(Phylo.outputtree(t, Newick(d2)));
julia> getnodenames(newer_tree)
19-element Vector{String}:
"Node 19"
"Node 18"
"Node 16"
"newer tip 4"
"newer tip 2"
"newer tip 10"
"Node 13"
"Node 12"
"newer tip 1"
"newer tip 6"
"Node 9"
"Node 8"
"newer tip 9"
"newer tip 7"
"Node 5"
"newer tip 8"
"Node 4"
"newer tip 3"
"newer tip 5" Anyway, that's about as good as it gets at the moment. I don't know if it's still any use to you, but I thought I'd mention it just in case. |
Okay, |
Hi!
Thanks for this awesome package!
Is it possible to change the leaf names of the tree after it was created? I couldn't find this functionality currently
Thanks!
The text was updated successfully, but these errors were encountered: