Skip to content

Obtain a list of trees based on edge ID or node ID #2507

Discussion options

You must be logged in to vote

Would something like this do the trick?

import numpy as np

# Total number of samples below each mutation on an edge
edge_mutation_samples = np.zeros(ts.num_edges)
# Total number of mutations that fall on each edge
edge_mutations = np.zeros(ts.num_edges)

for tree in ts.trees():
    for mut in tree.mutations():
        edge_mutations[mut.edge] += 1
        edge_mutation_samples[mut.edge] += tree.num_samples(mut.node)

print(edge_mutations)
print(edge_mutation_samples)

keep = edge_mutations > 0
print(edge_mutation_samples[keep] / edge_mutations[keep])

for a little example I made this gives:

[0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 3. 2. 0.]
[ 0.  0.  0.  1.  0.  0.  0.  0.  0.  0.  0…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@Proteios1998
Comment options

Comment options

You must be logged in to vote
3 replies
@Proteios1998
Comment options

@jeromekelleher
Comment options

@Proteios1998
Comment options

Answer selected by Proteios1998
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
Converted from issue

This discussion was converted from issue #2506 on September 15, 2022 08:11.