From 1903d759d7a82604fb241d8e06a2f4ba08981309 Mon Sep 17 00:00:00 2001 From: Bingjie Xue Date: Thu, 19 May 2022 18:42:37 -0400 Subject: [PATCH] fix distance endpoint --- bedhost/routers/api.py | 2 +- bedhost/routers/private_api.py | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/bedhost/routers/api.py b/bedhost/routers/api.py index 6d621c5a..d67a3823 100644 --- a/bedhost/routers/api.py +++ b/bedhost/routers/api.py @@ -159,7 +159,7 @@ async def get_bedfile_metadata( """ res = bbc.bed.select(columns=ids, filter_conditions=[("md5sum", "eq", md5sum)]) - + print(res[0]) if res: if ids: colnames = ids diff --git a/bedhost/routers/private_api.py b/bedhost/routers/private_api.py index 9f35777c..6d84205c 100644 --- a/bedhost/routers/private_api.py +++ b/bedhost/routers/private_api.py @@ -22,20 +22,38 @@ async def get_bedfiles_in_distance( limit: int = Query(None, description="number of rows returned by the query"), ): term = term.replace(" ", ",").split(",") + print(genome) if ids: assert_table_columns_match(bbc=bbc, table_name=BED_TABLE, columns=ids) + res = bbc.select_bedfiles_for_distance( - genome=genome, condition_val=term, bedfile_col=ids, limit=limit + bedfile_cols=ids, + filter_conditions=[ + ("search_term", "eq", term[0]), + ], ) - if res: - colnames = list(res[0].keys()) - values = [list(x.values()) for x in res] + + for x in res: + values = [] + if genome in str(x): + values.append(list(x)) + + if values: + if ids: + colnames = ids + else: + colnames = list( + serve_schema_for_table(bbc=bbc, table_name=BED_TABLE).keys() + ) + colnames.extend(["bed_label", "search_term", "score"]) + _LOGGER.info(f"Serving data for columns: {colnames}") else: _LOGGER.warning("No records matched the query") colnames = [] values = [[]] + return {"columns": colnames, "data": values}