Errors with pyslim.recapitate( )

102 views
Skip to first unread message

Kadee Lawrence

unread,
Jun 27, 2022, 1:42:23 PM6/27/22
to slim-discuss
Hey All, 

I have been trying to use pyslim recapitate and have been having some problems. I've now started to include the demography before trying to recapitate, but am still getting errors. I'm using this code to recapitate:

import msprime, pyslim
import tskit

ts = tskit.load("MS123sweep.trees")

demography = msprime.Demography.from_tree_sequence(ts, initial_size=20000)
demography.add_population_split(time =400 , derived = ["pop_3"], ancestral = "pop_2")
demography.add_population_split(time =4000 , derived = ["pop_2", "pop_1"], ancestral = "pop_0")
print(demography.debug())

rts = pyslim.recapitate(ts, demography=demography, recombination_rate= 1.14e-8, random_seed=1)

recap.dump("MS123sweepRecap.trees")

And I'm getting the demography.debug( ) and then this error:

/opt/miniconda3/lib/python3.8/site-packages/msprime/ancestry.py:831: TimeUnitsMismatchWarning: The initial_state has time_units=unknown but time is measured in generations in msprime. This may lead to significant discrepancies between the timescales. If you wish to suppress this warning, you can use, e.g., warnings.simplefilter('ignore', msprime.TimeUnitsMismatchWarning)
  warnings.warn(message, TimeUnitsMismatchWarning)
/opt/miniconda3/lib/python3.8/site-packages/msprime/demography.py:1142: IncompletePopulationMetadataWarning: The metadata schema does not have a 'name' property; population names will not be recorded in the output tree sequence
  warnings.warn(
/opt/miniconda3/lib/python3.8/site-packages/msprime/demography.py:1149: IncompletePopulationMetadataWarning: The metadata schema does not have a 'description' property; population descriptions will not be recorded in the output tree sequence
  warnings.warn(
Traceback (most recent call last):
  File "recapSLiMmsprime.txt", line 13, in <module>
    rts = pyslim.recapitate(ts, demography=demography, recombination_rate= 1.14e-8, random_seed=1)
  File "/opt/miniconda3/lib/python3.8/site-packages/pyslim/methods.py", line 78, in recapitate
    recap = msprime.sim_ancestry(
  File "/opt/miniconda3/lib/python3.8/site-packages/msprime/ancestry.py", line 1207, in sim_ancestry
    sim = _parse_sim_ancestry(
  File "/opt/miniconda3/lib/python3.8/site-packages/msprime/ancestry.py", line 1010, in _parse_sim_ancestry
    return Simulator(
  File "/opt/miniconda3/lib/python3.8/site-packages/msprime/ancestry.py", line 1318, in __init__
    super().__init__(
msprime._msprime.InputError: Input error in initialise: Attempt to sample a lineage from an inactive population

Thanks!
Kadee

Max Shpak

unread,
Jun 28, 2022, 1:44:21 PM6/28/22
to slim-discuss
It's quite strange that you're getting the "attempt to sample lineage from an inactive population" error, since your input is a single population tree generated by slim which, by definition, should be active at time 0.

Peter Ralph

unread,
Jun 29, 2022, 11:28:28 AM6/29/22
to Kadee Lawrence, slim-discuss
Hi, Kadee! Let's see: there's some kind of mismatch between where the
lineages are in the tree sequence and the demography. I can't be sure
without knowing some more things about the SLiM recipe, but my first
guess is that your SLiM simulation ran for 400 generations, and
everyone there is in population 3? This would create the error that
you're seeing because add_subpopulation_split(time=400, derived,
ancestral) implies that more recently than 400 time units ago, the
derived pops are "inactive" (ie didn't exist), so that all lineages
should shift from the derived populations to the ancestral one. This
means it's an error if there are any lineages in the derived pops
before time=400. The way that time intervals work in msprime, however,
it's an error if there are lineages in the derived pops with time >=
400; and if your SLiM simulation ran for 400 generations, then that
will be the time of the lineages you're trying to recapitate. The fix
is to change 400 to 401 (or any number larger than 400).

If that doesn't fix it, you can check where and when the lineages
needing recapitation are by something like:
```
for p, t in set([ts.node(r).population, ts.node(r).time for t in
ts.trees for r in t.roots]):
print(f"pop {p}, time {t}")
```
and then printing your demography to make sure things match up. If you
have further issues perhaps you should post it ias a discussion on
pyslim?

thanks,
Peter
> --
> SLiM forward genetic simulation: http://messerlab.org/slim/
> ---
> You received this message because you are subscribed to the Google Groups "slim-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to slim-discuss...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/slim-discuss/1f25e6f6-0f4d-4f87-9ecb-4504672a3b8cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages