Skip to content

Relabel leaf nodes in "canonical" order #1290

Answered by hyanwong
hyanwong asked this question in Q&A
Discussion options

You must be logged in to vote

I think I can do this by using the order of labels returned by standard traversal though a RankTree. But there's no function that does this. Here's one of my own that I rolled (name updated to leaves as an equivalent to Tree.leaves() after discussion with @daniel-goldstein ) (edit: this method now PRed in #1292)

def leaves(self):
    if self.is_leaf():
        return self.label,
    return [l for c in self.children for l in c.ordered_labels()]
tskit.combinatorics.RankTree.leaves = leaves

Used as follows (note that the internal node numbers are not the same between tree 1 and tree 3, which is to be expected)

tree = msprime.simulate(6, random_seed=13).first()
orig_ranktree = tskit.combinat…

Replies: 1 comment 1 reply

Comment options

hyanwong
Apr 1, 2021
Maintainer Author

You must be logged in to vote
1 reply
@daniel-goldstein
Comment options

Answer selected by benjeffery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants