Skip to content

Commit

Permalink
test regions simulated; closes #1577
Browse files Browse the repository at this point in the history
  • Loading branch information
petrelharp committed Jul 7, 2024
1 parent 94aa81c commit e628ad0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ def test_chromosome_segment(self):
assert contig.origin == f"{chromosome}:{left}-{right}"
assert contig.length == length

def test_not_simulated_outside_region(self):
# test that when left, right are specified
# we legit don't simulate anything outside that region
species = stdpopsim.get_species("AraTha")
model = stdpopsim.PiecewiseConstantSize(100)
samples = {"pop_0": 50}

left, right = 100000, 900000
contig = species.get_contig("1", left=left, right=right)

engine = stdpopsim.get_engine("msprime")
ts = engine.simulate(
model,
contig,
samples,
seed=236,
)

assert ts.sequence_length > right
assert ts.num_sites > 0
assert left in ts.breakpoints()
assert right in ts.breakpoints()
assert left <= min(ts.sites_position)
assert max(ts.sites_position) < right
assert ts.num_trees > 2
for t in ts.trees(root_threshold=2):
tl, tr = t.interval
if tl > right or tr < left:
assert t.num_roots == 0

def test_chromosome_segment_with_genetic_map(self):
chr_id = "chr2"
left = 1000001
Expand Down
35 changes: 35 additions & 0 deletions tests/test_slim_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,41 @@ def test_off_by_one(self):
self.verify_recombination_map(contig, ts)
assert list(ts.breakpoints()) == [0.0, midpoint, contig.length]

def test_not_simulated_outside_region(self):
# test that when left, right are specified
# we legit don't simulate anything outside that region
species = stdpopsim.get_species("AraTha")
model = stdpopsim.PiecewiseConstantSize(100)
samples = {"pop_0": 50}

left, right = 100000, 900000
contig = species.get_contig("1", left=left, right=right)
dfe = species.get_dfe("Gamma_H18")
exons = species.get_annotations("araport_11_exons")
exon_intervals = exons.get_chromosome_annotations("1")
contig.add_dfe(intervals=exon_intervals, DFE=dfe)

engine = stdpopsim.get_engine("slim")
ts = engine.simulate(
model,
contig,
samples,
seed=236,
slim_burn_in=100,
)

assert ts.sequence_length > right
assert ts.num_sites > 0
assert left in ts.breakpoints()
assert right in ts.breakpoints()
assert left <= min(ts.sites_position)
assert max(ts.sites_position) < right
assert ts.num_trees > 2
for t in ts.trees(root_threshold=2):
tl, tr = t.interval
if tl > right or tr < left:
assert t.num_roots == 0


@pytest.mark.skipif(IS_WINDOWS, reason="SLiM not available on windows")
class TestGenomicElementTypes(PiecewiseConstantSizeMixin):
Expand Down

0 comments on commit e628ad0

Please sign in to comment.