Skip to content

Extracting branch lengths from mutations #2895

Answered by nspope
Schraiber asked this question in Q&A
Discussion options

You must be logged in to vote

Here's one approach:

import msprime
import numpy as np
import tskit
ts = msprime.sim_ancestry(samples=100, sequence_length=1e6, population_size=1e4, recombination_rate=1e-8)
ts = msprime.sim_mutations(ts, rate=1.25e-8)
branch_lengths = np.full(ts.num_mutations, np.nan)
for m in ts.mutations():
    if m.edge != tskit.NULL: # skip unmapped mutations; these'll be nan in "branch_lengths"
        p, c = ts.edges_parent[m.edge], ts.edges_child[m.edge]
        branch_lengths[m.id] = ts.nodes_time[p] - ts.nodes_time[c]

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Schraiber
Comment options

@nspope
Comment options

nspope Jan 26, 2024
Collaborator

@Schraiber
Comment options

@nspope
Comment options

nspope Jan 26, 2024
Collaborator

@Schraiber
Comment options

Answer selected by hyanwong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants