-
Notifications
You must be signed in to change notification settings - Fork 90
Description
Hi,
I'm having issues converting my Demes graphs to msprime Demography objects; both population sizes and migration rates are missing unexpectedly. My Demes graphs match what I think I'm trying to specify, so it looks to me like a bug in msprime.Demography.from_demes() rather than in Demes.
I first encountered this problem with msprime 1.2.0, and upgraded to 1.3.0 in a fresh environment, with the exact same behaviour. The versions of key packages for this example are:
demes 0.2.3 pyhd8ed1ab_0 conda-forge
demesdraw 0.4.0 pyhd8ed1ab_0 conda-forge
msprime 1.3.0 py312h0767fef_0 conda-forge
python 3.12.1 hdf0ec26_1_cpython conda-forge
tskit 0.5.6 py312hf635c46_0 conda-forge
Missing population sizes
I've specified a Demes graph with three current demes (a, b, c) and their ancestors (ab_anc and abc_anc):
b = demes.Builder(time_units="generations")
b.add_deme("abc_anc", epochs=[{"start_size":1e6, "end_time":1e5}])
b.add_deme("ab_anc", ancestors=["abc_anc"], epochs=[{"start_size":1e6, "end_time":1e4}])
b.add_deme("a", ancestors=["ab_anc"], epochs=[{"start_size":1e6}])
b.add_deme("b", ancestors=["ab_anc"], epochs=[{"start_size":1e6}])
b.add_deme("c", ancestors=["abc_anc"], epochs=[{"start_size":1e6}])
graph = b.resolve()The graph looks like what I was trying to create:

And indeed population sizes are what we specified:
[(pop_idx, pop.epochs[0].start_size) for pop_idx, pop in enumerate(graph.demes)][(0, 1000000.0),
(1, 1000000.0),
(2, 1000000.0),
(3, 1000000.0),
(4, 1000000.0)]But when converting to an msprime Demography, population sizes are not preserved for the ancestral populations:
msprime.Demography.from_demes(graph)This is not just a table formatting error either:
[Population(initial_size=0, growth_rate=0, name='abc_anc', description='', extra_metadata={}, default_sampling_time=100000.0, initially_active=False, id=0),
Population(initial_size=0, growth_rate=0, name='ab_anc', description='', extra_metadata={}, default_sampling_time=10000.0, initially_active=False, id=1),
Population(initial_size=1000000.0, growth_rate=0, name='a', description='', extra_metadata={}, default_sampling_time=0.0, initially_active=True, id=2),
Population(initial_size=1000000.0, growth_rate=0, name='b', description='', extra_metadata={}, default_sampling_time=0.0, initially_active=True, id=3),
Population(initial_size=1000000.0, growth_rate=0, name='c', description='', extra_metadata={}, default_sampling_time=0.0, initially_active=True, id=4)]
I tried also specifying "end_size"...
b = demes.Builder(time_units="generations")
b.add_deme("abc_anc", epochs=[{"start_size":1e6, "end_time":1e5}])
b.add_deme("ab_anc", ancestors=["abc_anc"], epochs=[{"start_size":1e6, "end_time":1e4}])
b.add_deme("a", ancestors=["ab_anc"], epochs=[{"start_size":1e6, "end_size":1e6}])
b.add_deme("b", ancestors=["ab_anc"], epochs=[{"start_size":1e6, "end_size":1e6}])
b.add_deme("c", ancestors=["abc_anc"], epochs=[{"start_size":1e6, "end_size":1e6}])
graph2 = b.resolve()...but that made no difference.
Missing migration rates
Adding some migration to the demes specification:
b = demes.Builder(time_units="generations")
b.add_deme("abc_anc", epochs=[{"start_size":1e6, "end_time":1e5}])
b.add_deme("ab_anc", ancestors=["abc_anc"], epochs=[{"start_size":1e6, "end_time":1e4}])
b.add_deme("a", ancestors=["ab_anc"], epochs=[{"start_size":1e6}])
b.add_deme("b", ancestors=["ab_anc"], epochs=[{"start_size":1e6}])
b.add_deme("c", ancestors=["abc_anc"], epochs=[{"start_size":1e6}])
b.add_migration(rate=1e-5, source="a", dest="b")
b.add_migration(rate=1e-5, source="b", dest="a")
b.add_migration(rate=1e-5, source="c", dest="ab_anc")
graph3 = b.resolve()
demesdraw.tubes(graph3)

