Skip to content

Commit

Permalink
informative error message when chrom length > gc length (closes #1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrelharp committed Jan 20, 2025
1 parent 0ab99e0 commit 8531b99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions stdpopsim/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,14 @@ def species_contig(
ploidy=ploidy,
)

if contig.gene_conversion_length is not None:
if contig.length <= contig.gene_conversion_length:
raise ValueError(
"Cannot simulate a contig whose length is shorter "
"than the gene conversion length "
f"({contig.gene_conversion_length}bp)."
)

return contig

@property
Expand Down
5 changes: 5 additions & 0 deletions tests/test_genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def test_gc_errors(self):
gene_conversion_length=bad_len,
)

def test_gc_length_error(self):
sp = stdpopsim.get_species("StrAga")
with pytest.raises(ValueError, match="shorter than the gene conv"):
_ = sp.get_contig(length=100000)

def test_default_dfe(self):
contig = stdpopsim.Contig.basic_contig(length=100)
assert len(contig.dfe_list) == 1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_default_ploidy(self):
for chrom in self.species.genome.chromosomes:
contig = self.species.get_contig(chrom.id)
assert contig.ploidy is not None
contig = self.species.get_contig(length=1000)
contig = self.species.get_contig(length=200000)
assert contig.ploidy == self.species.ploidy


Expand Down

0 comments on commit 8531b99

Please sign in to comment.