Skip to content

Commit

Permalink
raise error when recording migrants
Browse files Browse the repository at this point in the history
  • Loading branch information
GertjanBisschop committed Aug 23, 2023
1 parent f9dd5bd commit 83a2b9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
12 changes: 8 additions & 4 deletions msprime/ancestry.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,18 +866,22 @@ def _parse_sim_ancestry(
" additional_nodes."
)

if is_dtwf:
if additional_nodes.value & NodeType.MIGRANT.value:
if additional_nodes.value & NodeType.MIGRANT.value:
if is_dtwf:
raise ValueError(
"Recording MIGRANT nodes is currently not supported in"
" DTWF simulation."
)
if is_pedigree:
if additional_nodes.value & NodeType.MIGRANT.value:
if is_pedigree:
raise ValueError(
"Recording MIGRANT nodes is not supported in "
"FixedPedigree simulation."
)
if any(isinstance(model, SweepGenicSelection) for model in models):
raise ValueError(
"Recording MIGRANT nodes is not supported in "
"SweepGenicSelection simulation."
)

record_migrations = core._parse_flag(record_migrations, default=False)

Expand Down
27 changes: 27 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,3 +962,30 @@ def test_lots_of_sweeps(self):
random_seed=2,
)
assert all(tree.num_roots == 1 for tree in ts.trees())

def test_sweep_migration_event(self):
models = [
msprime.StandardCoalescent(duration=0.01),
msprime.SweepGenicSelection(
position=5,
start_frequency=0.69,
end_frequency=0.7,
s=0.1,
dt=1e-6,
),
]
with pytest.raises(
ValueError,
match="Recording MIGRANT nodes is not supported in "
"SweepGenicSelection simulation.",
):
msprime.sim_ancestry(
3,
population_size=1000,
sequence_length=10,
recombination_rate=0.2,
model=models,
random_seed=2,
coalescing_segments_only=False,
additional_nodes=msprime.NodeType.MIGRANT,
)

0 comments on commit 83a2b9c

Please sign in to comment.