You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is occasionally useful, given a Tree object, to iterate over all the edges in that tree. Would it be easy to add an edges() iterator to the Tree class? For consistency with the Tree.nodes() iterator, I guess this should return the integer ID of the edge, rather than an edge object.
Hm, I could see this being useful. Since we never refer to edges by ID elsewhere, I vote for not starting to do that here, though? It could be, very simply:
def edges(t):
for n in t.nodes():
if n not in t.roots:
pn = t.parent(n)
yield (n, pn, t.time(pn) - t.time(n))
... but is that what's useful? or is the times of the two nodes more useful? Or what? Or, maybe this is easy enough to get out that we don't need it?
No, I meant the actual edge ID, not the contents of the edge. For example, when displaying multiple trees, we might want to highlight one edge. The edge might appear in multiple trees, so we need to identify it by ID.
Similarly, when considering 2 different trees, we might want to check if they share an edge. We could do this by comparing the whole edge object, including left & right positions (as presumably we can have edges with the same parent & child that are not the same, because they are in different positions), but easier just to compare edge IDs, no?
Since we never refer to edges by ID elsewhere, I vote for not starting to do that here, though?
The edge might appear in multiple trees, so we need to identify it by ID.
Oh, that makes sense. Hm, is ID the right way to identify them? For instance, what if you've got a -> b on [0, 1] and then a -> c -> b on [1, 2] and then a -> b again on [2,3]. Arguably the "edge" a->b should extend over [0,3], but if not, it still seems like you'd want it to identify the edge on [0,1] and the edge on [2,3]? For this the (parent, child) pair is the right labeling?
If we want to see the structure of the tree sequence itself, I think Yan's right and the simplest/most useful thing to do is return the edge IDs/objects. I can see how we might want to highlight how a particular edge spans across multiple trees as a useful viz tool.
Unfortunately I don't think it's something we have easy access to. We'd need to change the tree update algorithm to have an edge array that is updated at the same time as the parent array. We could make this an option to the Tree() class so that we don't incur this cost every time.
However, this is sufficiently involved that someone would need to be quite motivated to do it. I'm not sure a "nice to have" is enough here.
I agree, and see this as a "punt down the line" issue, but thought it was worth raising. Not sure if we want a "nice to have, but not v important" flag for tskit issues?
I'm putting this into the "Random access for trees" project as it's the type of functionality we should be able to support with a point query interface for the edge table.
Activity
petrelharp commentedon Apr 25, 2020
Hm, I could see this being useful. Since we never refer to edges by ID elsewhere, I vote for not starting to do that here, though? It could be, very simply:
... but is that what's useful? or is the times of the two nodes more useful? Or what? Or, maybe this is easy enough to get out that we don't need it?
hyanwong commentedon Apr 25, 2020
No, I meant the actual edge ID, not the contents of the edge. For example, when displaying multiple trees, we might want to highlight one edge. The edge might appear in multiple trees, so we need to identify it by ID.
Similarly, when considering 2 different trees, we might want to check if they share an edge. We could do this by comparing the whole edge object, including left & right positions (as presumably we can have edges with the same parent & child that are not the same, because they are in different positions), but easier just to compare edge IDs, no?
petrelharp commentedon Apr 25, 2020
Oh, that makes sense. Hm, is ID the right way to identify them? For instance, what if you've got
a -> bon [0, 1] and thena -> c -> bon [1, 2] and thena -> bagain on [2,3]. Arguably the "edge"a->bshould extend over[0,3], but if not, it still seems like you'd want it to identify the edge on [0,1] and the edge on [2,3]? For this the (parent, child) pair is the right labeling?jeromekelleher commentedon Apr 27, 2020
If we want to see the structure of the tree sequence itself, I think Yan's right and the simplest/most useful thing to do is return the edge IDs/objects. I can see how we might want to highlight how a particular edge spans across multiple trees as a useful viz tool.
Unfortunately I don't think it's something we have easy access to. We'd need to change the tree update algorithm to have an
edgearray that is updated at the same time as theparentarray. We could make this an option to the Tree() class so that we don't incur this cost every time.However, this is sufficiently involved that someone would need to be quite motivated to do it. I'm not sure a "nice to have" is enough here.
hyanwong commentedon Apr 27, 2020
I agree, and see this as a "punt down the line" issue, but thought it was worth raising. Not sure if we want a "nice to have, but not v important" flag for tskit issues?
jeromekelleher commentedon Apr 27, 2020
Maybe the "enhancement" tag?
jeromekelleher commentedon Sep 29, 2020
I'm putting this into the "Random access for trees" project as it's the type of functionality we should be able to support with a point query interface for the edge table.
jeromekelleher commentedon Dec 11, 2022
Closing this we can now easily access edge information on trees.
hyanwong commentedon Dec 12, 2022
In particular, we can now do