Skip to content

Commit

Permalink
1. Fixed #153
Browse files Browse the repository at this point in the history
2. Set limit for Trackhub
  • Loading branch information
khoroshevskyi committed Nov 13, 2024
1 parent 1358cb8 commit b76fc2a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
44 changes: 42 additions & 2 deletions bedhost/routers/bed_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
BEDFileNotFoundError,
TokenizeFileNotExistError,
)
from bbconf.models.bed_models import BedClassification # BedPEPHub,
from bbconf.models.bed_models import (
BedClassification, # BedPEPHub,
BedEmbeddingResult,
BedFiles,
BedListResult,
Expand Down Expand Up @@ -193,6 +193,27 @@ async def get_bed_pephub(
)


@router.get(
"/{bed_id}/neighbours",
summary="Get nearest neighbours for a single BED record",
response_model=BedListSearchResult,
response_model_by_alias=False,
description=f"Returns most similar BED files in the database. "
f"Example\n bed_id: {EXAMPLE_BED}",
)
async def get_bed_neighbours(
bed_id: str = BedDigest,
limit: int = 10,
offset: int = 0,
):
try:
return bbagent.bed.get_neighbours(bed_id, limit=limit, offset=offset)
except BEDFileNotFoundError as _:
raise HTTPException(
status_code=404,
)


@router.get(
"/{bed_id}/embedding",
summary="Get embeddings for a single BED record",
Expand Down Expand Up @@ -335,7 +356,26 @@ async def text_to_bed_search(query, limit: int = 10, offset: int = 0):
Example: query="cancer"
"""
_LOGGER.info(f"Searching for: {query}")
results = bbagent.bed.text_to_bed_search(query, limit=limit, offset=offset)

results_sql = bbagent.bed.sql_search(
query, limit=round(limit / 2, 0), offset=round(offset / 2, 0)
)

if results_sql.count > results_sql.offset:
qdrant_offset = offset - results_sql.offset
else:
qdrant_offset = offset - results_sql.count

results_qdr = bbagent.bed.text_to_bed_search(
query, limit=limit, offset=qdrant_offset - 1 if qdrant_offset > 0 else 0
)

results = BedListSearchResult(
count=results_qdr.count,
limit=limit,
offset=offset,
results=(results_sql.results + results_qdr.results)[0:limit],
)

if results:
return results
Expand Down
11 changes: 8 additions & 3 deletions bedhost/routers/bedset_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from bbconf.exceptions import BedSetNotFoundError
from bbconf.exceptions import BedSetNotFoundError, BedSetTrackHubLimitError
from bbconf.models.bedset_models import (
BedSetBedFiles,
BedSetListResult,
Expand Down Expand Up @@ -174,7 +174,12 @@ async def get_trackDb_file_bedset(bedset_id: str):
# f"longLabel\t {metadata.description}\n"
# "visibility\t full\n\n"
# )

trackDb_txt = bbagent.bedset.get_track_hub_file(bedset_id)
try:
trackDb_txt = bbagent.bedset.get_track_hub_file(bedset_id)
except BedSetTrackHubLimitError as _:
raise HTTPException(
status_code=400,
detail="Track hub limit reached. Please try smaller BEDset.",
)

return Response(trackDb_txt, media_type="text/plain")

0 comments on commit b76fc2a

Please sign in to comment.