How to remove low frequency mutations? #1690
-
Hi, I'm currently trying to subset the mutations in a simulated tree sequence based on allele frequency. When trying to run very similar code as the one provided in the tutorial (copied below), I'm getting the error "AttributeError: 'TreeSequence' object has no attribute 'set_mutations'". It seems the set_mutations function was removed at some point (if I install an older version i.e. 3.6.2 set_mutations exists). In the latest versions of msprime, is there an alternative to subset mutations? Apologies if I'm missing an obvious alternative function.
Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Gee, thanks for the report! It's true, that method isn't around any more (it was never documented, so wasn't supposed to be something that we supported long-term). How did you find that tutorial, btw? I found it in this old version of the docs by googling, but I'm hoping others won't come upon this old version very easily. If you want to do that now, here's what I'd do:
Note that this will still have invariant sites; if you'd like to remove these then you could run If there's a bug here, it's that you found this old documentation for something that was never supposed to be released. But, it's a good question that probably belongs in Discussions - I'm going to transfer it over there (and let me know if you don't agree!). Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hi @kliao12! (seems @petrelharp and I were typing at the same time!)
The tutorial example was removed in 2018: 5b25db2 which would have been released in Where were you viewing the tutorial? It would be good to know so we can update it! The tables = tree_sequence.tables
tables.mutations.clear()
for tree in tree_sequence.trees():
for mutation in tree.mutations():
p = tree.get_num_leaves(mutation.node) / tree.get_sample_size()
if p >= 0.5:
tables.mutations.append(mutation)
tables.compute_mutation_parents()
ts = tables.tree_sequence() (@petrelharp used |
Beta Was this translation helpful? Give feedback.
-
Great thanks to both of you for the prompt responses and suggestions on working with the now immutable TreeSequence class! And yeah I was working off the apparent old docs (https://msprime.readthedocs.io/en/multi-requirements/tutorial.html), which was the first link that popped up for me when googling "msprime tutorial". |
Beta Was this translation helpful? Give feedback.
Hi @kliao12!
(seems @petrelharp and I were typing at the same time!)
set_mutations
was removed way back in 2017 in beforetskit
was split frommsprime
805d745The tutorial example was removed in 2018: 5b25db2 which would have been released in
0.5.0
in Feb '18Where were you viewing the tutorial? It would be good to know so we can update it!
The
TreeSequence
class is now immutable, if you want to modify the mutations table you create a new one via thetskit.TableCollection
which provides ways to mutate the underlying data of a tree sequence: