-
Notifications
You must be signed in to change notification settings - Fork 79
Closed
Labels
Python APIIssue is about the Python APIIssue is about the Python APIenhancementNew feature or requestNew feature or requestfutureIssues that are closed as they are not planned in the medium-term, but which are still desirable.Issues that are closed as they are not planned in the medium-term, but which are still desirable.
Milestone
Description
Getting the state that a mutation inherited is fiddly right now, and has been annoying me quite bit recently. We should add a method to the Python object at least to get it, but it would also be nice to have access to it in numpy for reasoning efficiently about reversions and so on.
Does inherited_state feel like the right term here?
The numpy stuff would depend on us making some decisions about vectorised access to the string columns which I guess I should open a seperate issue on.
tables = ts.tables
assert np.all(tables.mutations.derived_state_offset == np.arange(ts.num_mutations + 1))
derived_state = tables.mutations.derived_state.view("S1")
assert np.all(tables.sites.ancestral_state_offset == np.arange(ts.num_sites + 1))
ancestral_state = tables.sites.ancestral_state.view("S1")
# Compute the "inherited state" for each mutation
inherited_state = ancestral_state[ts.mutations_site]
mutations_with_parent = ts.mutations_parent != -1
parent = ts.mutations_parent[mutations_with_parent]
assert np.all(parent >= 0)
inherited_state[mutations_with_parent] = derived_state[parent]
# Check
for mut in ts.mutations():
state0 = ts.site(mut.site).ancestral_state
if mut.parent != -1:
state0 = ts.mutation(mut.parent).derived_state
assert state0 == inherited_state[mut.id].decode()Metadata
Metadata
Assignees
Labels
Python APIIssue is about the Python APIIssue is about the Python APIenhancementNew feature or requestNew feature or requestfutureIssues that are closed as they are not planned in the medium-term, but which are still desirable.Issues that are closed as they are not planned in the medium-term, but which are still desirable.
Type
Projects
Status
Bigger things