Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Changes in each published version, newest first. These notes start at 2.27.2;
earlier versions are available as [Git tags](https://github.com/openvax/pyensembl/tags).

## 2.34.5

Define `Locus.__bool__` returning `True` so truthiness checks (`bool(transcript)`
or `if transcript:`) evaluate in constant time instead of falling back to
`Transcript.__len__()` and querying the `exon` SQLite table on cold or unindexed
genomes (#534). `len(locus)` and `len(transcript)` are unchanged.

## 2.34.4

Exit with argparse status 2 when a selection resolves to no genomes (#505),
Expand Down
3 changes: 3 additions & 0 deletions pyensembl/locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __str__(self):
def __len__(self):
return self.end - self.start + 1

def __bool__(self) -> bool:
return True

def __eq__(self, other):
if not isinstance(other, Locus):
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion pyensembl/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.34.4"
__version__ = "2.34.5"

def print_version():
print(f"v{__version__}")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_lazy_locus_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_unavailable_reference_allows_identity_roundtrip_but_not_annotation(tmp_
locus = cls(contig="1", start=10, end=20, strand="+", biotype="protein_coding",
genome=genome, **identity)
restored = from_json(to_json(locus))
assert bool(locus) is True
assert bool(restored) is True
assert restored == locus
assert (restored.contig, restored.start, restored.end, restored.strand) == ("1", 10, 20, "+")
assert restored.gene_id == "gene"
Expand All @@ -30,6 +32,23 @@ def test_unavailable_reference_allows_identity_roundtrip_but_not_annotation(tmp_
restored.exons if isinstance(restored, Transcript) else restored.transcripts


def test_transcript_bool_does_not_query_exons(tmp_path, monkeypatch):
genome = Genome(reference_name="GRCm38", annotation_name="test", annotation_version=81,
gtf_path_or_url=data_path("mouse.ensembl.81.partial.ENSMUSG00000017167.gtf"),
cache_directory_path=str(tmp_path))
genome.index()
transcript = genome.transcripts()[0]
expected_len = len(transcript)
with monkeypatch.context() as no_exons:
no_exons.setattr(
Transcript,
"exons",
property(lambda _self: (_ for _ in ()).throw(AssertionError("exons queried"))),
)
assert bool(transcript) is True
assert len(transcript) == expected_len


def test_available_reference_resolves_real_database_after_metadata_roundtrip(tmp_path):
genome = Genome(reference_name="GRCm38", annotation_name="test", annotation_version=81,
gtf_path_or_url=data_path("mouse.ensembl.81.partial.ENSMUSG00000017167.gtf"),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def test_normalize_chromosome():

def test_locus_overlaps():
locus = Locus("1", 10, 20, "+")
assert bool(locus) is True
assert bool(Exon("E1", "1", 10, 10, "+", "G", "GID")) is True
assert locus.overlaps("1", 10, 20, "+")
assert locus.overlaps("1", 10, 20)
assert locus.overlaps("1", 5, 30)
Expand Down
Loading