Skip to content

Commit

Permalink
feat: add IGV.js search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed May 23, 2024
1 parent 8f76d18 commit 1d00f4e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bento_reference_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class GenomeFeature(BaseModel):
parents: tuple[str, ...]


class GenomeFeatureIGV(BaseModel):
chromosome: str
start: int
end: int


TaskStatus = Literal["queued", "running", "success", "error"]


Expand Down
14 changes: 14 additions & 0 deletions bento_reference_service/routers/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ async def genomes_detail_features_detail(db: DatabaseDependency, genome_id: str,
return await db.get_genome_feature_by_id(genome_id, feature_id)


@genome_router.get("/{genome_id}/igv-js-features", dependencies=[authz_middleware.dep_public_endpoint()])
async def genomes_detail_igv_js_features(
db: DatabaseDependency, genome_id: str, q: str | None = None
) -> list[m.GenomeFeatureIGV]:
results, _ = await db.query_genome_features(
genome_id, name=q, name_fzy=True, feature_types=["mRNA", "gene", "transcript", "exon"], limit=1
)
return [
m.GenomeFeatureIGV(chromosome=r.contig_name, start=r.entries[0].start_pos, end=r.entries[-1].end_pos)
for r in results
if len(r.entries) > 0
]


@genome_router.get("/{genome_id}/features.gff3.gz", dependencies=[authz_middleware.dep_public_endpoint()])
async def genomes_detail_features_gff3(
config: ConfigDependency, db: DatabaseDependency, logger: LoggerDependency, request: Request, genome_id: str
Expand Down
10 changes: 10 additions & 0 deletions tests/test_genome_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ async def test_genome_feature_endpoints(test_client: TestClient, aioresponse: ai
assert srd["pagination"]["total"] == 1
assert isinstance(srd.get("time"), float)
assert srd["time"] < 0.2 # this is a very basic operation on a small dataset and should be fast.
q_feature = srd["results"][0]

# - fuzzy search
sr = test_client.get(f"/genomes/{genome.id}/features", params={"q": "ENSSASP00005000003", "q_fzy": "true"})
Expand All @@ -339,3 +340,12 @@ async def test_genome_feature_endpoints(test_client: TestClient, aioresponse: ai
sr = test_client.get(f"/genomes/{genome.id}/features/CDS:ENSSASP00005000003")
assert sr.status_code == 200
assert sr.json()["feature_id"] == "CDS:ENSSASP00005000003"

# Test we can do an IGV.js search
sr = test_client.get(f"/genomes/{genome.id}/igv-js-features", params={"q": "ENSSASP00005000003"})
assert sr.status_code == 200
srd = sr.json()
assert len(srd) == 1
assert srd[0]["chromosome"] == q_feature["contig_name"]
assert srd[0]["start"] == q_feature["entries"][0]["start_pos"]
assert srd[0]["end"] == q_feature["entries"][0]["end_pos"]

0 comments on commit 1d00f4e

Please sign in to comment.