|
15 | 15 | BEDFileNotFoundError,
|
16 | 16 | TokenizeFileNotExistError,
|
17 | 17 | )
|
| 18 | +from bbconf.models.bed_models import BedClassification # BedPEPHub, |
18 | 19 | from bbconf.models.bed_models import (
|
19 |
| - BedClassification, # BedPEPHub, |
20 | 20 | BedEmbeddingResult,
|
21 | 21 | BedFiles,
|
22 | 22 | BedListResult,
|
|
27 | 27 | BedStatsModel,
|
28 | 28 | TokenizedBedResponse,
|
29 | 29 | TokenizedPathResponse,
|
| 30 | + QdrantSearchResult, |
| 31 | + RefGenValidReturnModel, |
30 | 32 | )
|
31 | 33 | from fastapi import APIRouter, File, HTTPException, Query, UploadFile
|
32 | 34 | from fastapi.responses import PlainTextResponse
|
@@ -193,6 +195,27 @@ async def get_bed_pephub(
|
193 | 195 | )
|
194 | 196 |
|
195 | 197 |
|
| 198 | +@router.get( |
| 199 | + "/{bed_id}/neighbours", |
| 200 | + summary="Get nearest neighbours for a single BED record", |
| 201 | + response_model=BedListSearchResult, |
| 202 | + response_model_by_alias=False, |
| 203 | + description=f"Returns most similar BED files in the database. " |
| 204 | + f"Example\n bed_id: {EXAMPLE_BED}", |
| 205 | +) |
| 206 | +async def get_bed_neighbours( |
| 207 | + bed_id: str = BedDigest, |
| 208 | + limit: int = 10, |
| 209 | + offset: int = 0, |
| 210 | +): |
| 211 | + try: |
| 212 | + return bbagent.bed.get_neighbours(bed_id, limit=limit, offset=offset) |
| 213 | + except BEDFileNotFoundError as _: |
| 214 | + raise HTTPException( |
| 215 | + status_code=404, |
| 216 | + ) |
| 217 | + |
| 218 | + |
196 | 219 | @router.get(
|
197 | 220 | "/{bed_id}/embedding",
|
198 | 221 | summary="Get embeddings for a single BED record",
|
@@ -335,7 +358,52 @@ async def text_to_bed_search(query, limit: int = 10, offset: int = 0):
|
335 | 358 | Example: query="cancer"
|
336 | 359 | """
|
337 | 360 | _LOGGER.info(f"Searching for: {query}")
|
338 |
| - results = bbagent.bed.text_to_bed_search(query, limit=limit, offset=offset) |
| 361 | + |
| 362 | + # results_sql = bbagent.bed.sql_search( |
| 363 | + # query, limit=round(limit / 2, 0), offset=round(offset / 2, 0) |
| 364 | + # ) |
| 365 | + # |
| 366 | + # if results_sql.count > results_sql.offset: |
| 367 | + # qdrant_offset = offset - results_sql.offset |
| 368 | + # else: |
| 369 | + # qdrant_offset = offset - results_sql.count |
| 370 | + # |
| 371 | + # results_qdr = bbagent.bed.text_to_bed_search( |
| 372 | + # query, limit=limit, offset=qdrant_offset - 1 if qdrant_offset > 0 else 0 |
| 373 | + # ) |
| 374 | + # |
| 375 | + # results = BedListSearchResult( |
| 376 | + # count=results_qdr.count, |
| 377 | + # limit=limit, |
| 378 | + # offset=offset, |
| 379 | + # results=(results_sql.results + results_qdr.results)[0:limit], |
| 380 | + # ) |
| 381 | + spaceless_query = query.replace(" ", "") |
| 382 | + if len(spaceless_query) == 32 and spaceless_query == query: |
| 383 | + try: |
| 384 | + similar_results = bbagent.bed.get_neighbours( |
| 385 | + query, limit=limit, offset=offset |
| 386 | + ) |
| 387 | + |
| 388 | + if similar_results.results and offset == 0: |
| 389 | + |
| 390 | + result = QdrantSearchResult( |
| 391 | + id=query, |
| 392 | + payload={}, |
| 393 | + score=1.0, |
| 394 | + metadata=bbagent.bed.get(query), |
| 395 | + ) |
| 396 | + |
| 397 | + similar_results.results.insert(0, result) |
| 398 | + return similar_results |
| 399 | + except Exception as _: |
| 400 | + pass |
| 401 | + |
| 402 | + results = bbagent.bed.text_to_bed_search( |
| 403 | + query, |
| 404 | + limit=limit, |
| 405 | + offset=offset, |
| 406 | + ) |
339 | 407 |
|
340 | 408 | if results:
|
341 | 409 | return results
|
@@ -414,3 +482,24 @@ async def get_tokens(
|
414 | 482 | status_code=404,
|
415 | 483 | detail="Tokenized file not found",
|
416 | 484 | )
|
| 485 | + |
| 486 | + |
| 487 | +@router.get( |
| 488 | + "/{bed_id}/genome-stats", |
| 489 | + summary="Get reference genome validation results", |
| 490 | + response_model=RefGenValidReturnModel, |
| 491 | +) |
| 492 | +async def get_ref_gen_results( |
| 493 | + bed_id: str, |
| 494 | +): |
| 495 | + """ |
| 496 | + Return reference genome validation results for a bed file |
| 497 | + Example: bed: 0dcdf8986a72a3d85805bbc9493a1302 |
| 498 | + """ |
| 499 | + try: |
| 500 | + return bbagent.bed.get_reference_validation(bed_id) |
| 501 | + except BEDFileNotFoundError as _: |
| 502 | + raise HTTPException( |
| 503 | + status_code=404, |
| 504 | + detail=f"Bed file {bed_id} not found", |
| 505 | + ) |
0 commit comments