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

List of tree sequence nodes in canonical (time) order #2470

Closed
hyanwong opened this issue Aug 23, 2022 · 3 comments
Closed

List of tree sequence nodes in canonical (time) order #2470

hyanwong opened this issue Aug 23, 2022 · 3 comments

Comments

@hyanwong
Copy link
Member

hyanwong commented Aug 23, 2022

I would find it useful to get a list of nodes in the same order as required by the edge table, that is, by time of node, then by node ID (I think of this as a "canonical" node order). Would this be a useful (if trivial) addition to tskit? At the moment we can only iterate over tree sequence nodes by node ID using ts.nodes(). In python, the required order is given by

np.lexsort((np.arange(ts.tables.nodes.num_rows), ts.tables.nodes.time))

One option would be to provide an order parameter to ts.nodes, like there is for tree.nodes. It would default to "id", but could be e.g. "time". It might be useful to have something like this because when hand coding it, it's easy to forget about what happens when there are ties (nodes at the same time).

@hyanwong
Copy link
Member Author

hyanwong commented Aug 23, 2022

Part of the rationale is to add features that help when thinking of the tree sequence as a large graph (aka ARG) rather than when wanting to deal with the trees one-by-one. See #2469

@hyanwong
Copy link
Member Author

hyanwong commented Aug 23, 2022

Gosh, I have a short memory. This is already an issue: #2370 , although we didn't note the requirement to sort secondarily by node ID, so as to break ties and match the edge table order.

@hyanwong
Copy link
Member Author

Closing as dup of #2370

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

1 participant