-
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
How can I rename the leaf nodes of a ::RootedTree? #70
Comments
|
You can e.g. read the tree from a Newick file and want to change the names from eg common to scientific names? This seems like a common use case to me. |
Yup @mkborregaard that is exactly my case (well, species ID -weird format- to scientific species name). I didn't create the tree myself, and was expecting to be able to do everything I wanted to do with it in Julia (since it's the only language I know to a good level). What about editing the plotting pane instead of the original tree? How can the recipe in plot.jl be changed so that there is an extra kwarg ( @recipe function f(tree::Phylo.AbstractTree; treetype = :dendrogram, marker_group = nothing, line_group = nothing, showtips = true, tipfont = (7,))
linecolor --> :black
grid --> false
framestyle --> :none
legend --> false
colorbar --> true
size --> (1000, 1000)
d, h, n = _findxy(tree)
adj = 0.03maximum(values(d))
tipannotations = map(x->(d[x] + adj, h[x], x), getleafnames(tree))
....#continues |
You could just add a |
Thanks for your help. I had never played with the source code of a package before, so it took me some time to realise what I was doing. I am quite behind schedule with other things right now so won't be submitting a PR (again, I've never done it before and can't really spare the time to learn that at the minute). However, the following edit of /src/plot.jl worked for me: using RecipesBase
using AxisArrays # need to ensure this package is loaded in the environment
@recipe function f(tree::Phylo.AbstractTree; tipnames = getleafnames(tree), treetype = :dendrogram, marker_group = nothing, line_group = nothing, showtips = true, tipfont = (7,)) # add extra kwarg 'tipnames'
linecolor --> :black
grid --> false
framestyle --> :none
legend --> false
colorbar --> true
size --> (1000, 1000)
d, h, n = _findxy(tree)
adj = 0.03maximum(values(d))
#################
if length(tipnames) == length(getleafnames(tree))
dict = Dict(getleafnames(tree) .=> string.(tipnames))
tipannotations = map(x->(d[x] + adj, h[x], dict[x]), getleafnames(tree))
else
@warn "tipnames attribute must have $(length(getleafnames(tree))) elements. Using original tipnames instead."
tipannotations = map(x->(d[x] + adj, h[x], x), getleafnames(tree))
end
################
lz = get(plotattributes, :line_z, nothing)
#.... continues Note: the part of the code wrapped in '###' is the only thing that is changed from the original file |
Thanks @casasgomezuribarri / @mkborregaard - this seems like a useful thing to be able to do. I'm less certain about interactively changing the actually names of nodes (or branches) in the tree as that would disrupt a few things. In any event, maybe we should add this plotting functionality for now. |
Okay, |
I would like to rename all the leaves of my tree, of type
::RootedTree
.setleafinfo!(mytree, vector)
throws the errorI couldn't find any information on the
::Phylo.AbstractBranchTree
type in the docs, but the docstring of the function suggests that the tree to be edited must be of type::AbstractTree
. I triedAbstractTree(mytree)
, but got the errorReally, all I want to do is to plot my tree with a nicer format for the leaf names. How can I do it? (either editing the tree itself or specifying the names in the
plot
call)The text was updated successfully, but these errors were encountered: