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

Mkb/rev sort #51

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,28 @@ function _extend(tmp, x)
end

"""
sort!(::AbstractTree)
sort!(::AbstractTree; rev = false)

Sorts the branches descending from each node by total number of
descendants. This creates a clearer tree for plotting. The
process is also called "ladderizing" the tree
"""
function Base.sort!(tree::AbstractTree)
function Base.sort!(tree::AbstractTree; rev = false)
function loc!(clade::String)
if isleaf(tree, clade)
return 1
end

sizes = map(loc!, getchildren(tree, clade))
node = getnode(tree, clade)
node.other .= node.other[sortperm(sizes)]
node.other .= node.other[sortperm(sizes, rev = rev)]
sum(sizes) + 1
end

loc!(first(nodenamefilter(isroot, tree)))
tree
end

Base.sort(tree::AbstractTree; rev = false) = sort!(copy(tree))


function _findxy(tree::Phylo.AbstractTree)
Expand Down