Running into a new error due to mismatch between Expected root time and Observed root times #341
-
Hello! Per usual, I have been running simulations incorporating alternation of generations, which stores the haploid and diploid individuals in separate populations. For post-sim analysis these individuals need to end up back in the same population. I used to use the following code to move all the individuals into one population ("p0") then I would use #copy the tables
tables = tree_sequence.dump_tables()
#change the population to p0 for everyone
nnodes = tables.nodes.time.size
tables.nodes.population = np.zeros(nnodes, dtype=np.int32)
# drop nodes that are not connected to anything.
nodes_in_edge_table = list(set(tables.edges.parent).union(tables.edges.child))
# remove the empty population nodes by using simplify
tables.simplify(
samples=nodes_in_edge_table,
keep_input_roots=True,
filter_individuals=True,
filter_populations=True,
filter_sites=False
)
# turn it back into a treesequence
new_ts = tables.tree_sequence() Recently this functionality has broken, I suspect due to a pyslim update. I've tried changing various setting in the simplify() function, as well as a different method for selecting the samples (I tried keeping them all), to no avail. It seems like some of the pertinent nodes are being removed because some of the root times are no longer the ancestral root time (see error). Error, for reference:
If I don't run the simplify() function then the recapitation works just fine. My impression is that using The empty population may not seem like a big deal, but it ends up being a nuisance for more complex situations where demography is involved. A workaround may be editing the tables manually to remove the empty population, but alas I couldn't figure out how to do that. model as .txt - script_ex.txt Thank you for maintaining and updating pyslim! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello! Thanks for the easy-to-run code.
That works (for me). Why are you getting that error? Something weird is happening with your simplify-but-mark-everyone-as-samples-first call. I haven't dug into why exactly this happens, but I think you probably don't want to do it, anyhow? I have confirmed that if you don't do that then it also works:
This also works (for me). If you do want to simplify something else away, explain what it is you're wanting to do? FYI, the only thing (I think) that has changed recently in pyslim is the consistency check that you're hitting - so, it might well be saving you from something nonsensical happening. |
Beta Was this translation helpful? Give feedback.
-
Programming rule of thumb: The more consistency checks the better. :-> |
Beta Was this translation helpful? Give feedback.
Hello! Thanks for the easy-to-run code.
Let's see - if you really just want to only remove that entry in the population table, you can just do like this:
That works (for me).
Why are you getting that error? Something weird is happening with your simplify-but-mark-everyone-as-samples-first call. I haven't dug into why exactly this ha…