Finding nodes with multiple parents #2770
hyanwong
started this conversation in
Show and tell
Replies: 1 comment 4 replies
-
This is a slightly more efficient/simpler way to do [EDIT] something slightly different it (as it avoids a sort): node_is_child_count = np.bincount(ts.edges_child, minlength=ts.num_nodes)
multiple_parents = np.where(node_is_child_count > 1)[0]
print(multiple_parents) In general np.bincount is very useful for working with these arrays. E.g., counting the number of mutations per node or site is easy: sites_num_mutations = np.bincount(ts.mutations_site, minlength=ts.num_sites)
nodes_num_mutations = np.bincount(ts.mutations_node, minlength=ts.num_nodes) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A quick 3-liner for finding those nodes in a tree sequence with multiple parents (see #2765 (comment))
Change the
>1
to e.g.>2
to find nodes with 3 or more parents, etc. Note that in therecord_full_arg
option of msprime, the recombination nodes are the nodes immediately above any node with>1
parent. See tskit-dev/msprime#1942 (comment) for an explanation of this, which is only required because it allows calculation of likelihoods under the strict Hudson CwR (with max 1 breakpoint per chromosome)Beta Was this translation helpful? Give feedback.
All reactions