Skip to content

Mutation's "inherited" state #2631

Open
@jeromekelleher

Description

@jeromekelleher

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

No one assigned

    Labels

    Python APIIssue is about the Python APIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions