From 196ca204b9a02f48220b81e269a079fe07474eaf Mon Sep 17 00:00:00 2001 From: Bingjie Xue Date: Thu, 31 Aug 2023 14:50:26 -0400 Subject: [PATCH] rm graphQL related things --- bedhost/main.py | 11 +---- bedhost/routers/api.py | 77 +++++++++++++++++++++++-------- requirements/requirements-all.txt | 5 -- requirements/requirements-dev.txt | 1 - 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/bedhost/main.py b/bedhost/main.py index b6af20b5..f5a531f2 100644 --- a/bedhost/main.py +++ b/bedhost/main.py @@ -7,8 +7,6 @@ import uvicorn from bbconf import BedBaseConf from fastapi import FastAPI, HTTPException, Path, Query -from pipestat_reader import PipestatReader -from starlette_graphene3 import GraphQLApp, make_graphiql_handler from starlette.middleware.cors import CORSMiddleware from starlette.responses import FileResponse, RedirectResponse from starlette.staticfiles import StaticFiles @@ -98,14 +96,7 @@ def main(): else: raise FileNotFoundError(f"React UI path to mount not found: {UI_PATH}") - app.mount("/ui", StaticFiles(directory=UI_PATH)) - - psr = PipestatReader(pipestat_managers=[bbc.bed, bbc.bedset, bbc.dist]) - _LOGGER.info("Generating GraphQL schema") - graphql_schema = psr.generate_graphql_schema() - app.mount( - "/graphql", GraphQLApp(graphql_schema, on_get=make_graphiql_handler()) - ) + app.mount("/", StaticFiles(directory=UI_PATH)) _LOGGER.info(f"running {PKG_NAME} app") uvicorn.run( diff --git a/bedhost/routers/api.py b/bedhost/routers/api.py index 2f7e2276..d4506ffb 100644 --- a/bedhost/routers/api.py +++ b/bedhost/routers/api.py @@ -34,7 +34,9 @@ FileColumnBed = enum.Enum("FileColumnBed", get_enum_map(bbc, BED_TABLE, "file")) -ImgColumnBedset = enum.Enum("ImgColumnBedset", get_enum_map(bbc, BEDSET_TABLE, "image")) +ImgColumnBedset = enum.Enum( + "ImgColumnBedset", get_enum_map(bbc, BEDSET_TABLE, "image") +) ImgColumnBed = enum.Enum("ImgColumnBed", get_enum_map(bbc, BED_TABLE, "image")) @@ -118,8 +120,12 @@ async def get_bedfile_count(): @router.get("/bed/all/metadata") async def get_all_bed_metadata( - ids: Optional[List[str]] = Query(None, description="Bedfiles table column name"), - limit: int = Query(None, description="number of rows returned by the query"), + ids: Optional[List[str]] = Query( + None, description="Bedfiles table column name" + ), + limit: int = Query( + None, description="number of rows returned by the query" + ), ): """ Get bedfiles metadata for selected columns @@ -165,7 +171,9 @@ async def get_bedfile_metadata( Returns metadata from selected columns for selected bedfile """ - res = bbc.bed.select(columns=ids, filter_conditions=[("md5sum", "eq", md5sum)]) + res = bbc.bed.select( + columns=ids, filter_conditions=[("md5sum", "eq", md5sum)] + ) if res: if ids: @@ -227,7 +235,8 @@ async def get_file_path_for_bedfile( remote = True if CFG_REMOTE_KEY in bbc.config else False path = ( os.path.join( - bbc.config[CFG_REMOTE_KEY][remoteClass.value]["prefix"], file["path"] + bbc.config[CFG_REMOTE_KEY][remoteClass.value]["prefix"], + file["path"], ) if remote else os.path.join( @@ -307,7 +316,9 @@ async def get_image_path_for_bedfile( def get_regions_for_bedfile( md5sum: str = bd, chr_num: str = c, - start: Optional[str] = Query(None, description="query range: start coordinate"), + start: Optional[str] = Query( + None, description="query range: start coordinate" + ), end: Optional[str] = Query(None, description="query range: end coordinate"), ): """ @@ -393,10 +404,13 @@ async def get_regions_for_bedfile( md5sum = bed[1] remote = True if CFG_REMOTE_KEY in bbc.config else False path = ( - os.path.join(bbc.config[CFG_REMOTE_KEY]["http"]["prefix"], bed[2]["path"]) + os.path.join( + bbc.config[CFG_REMOTE_KEY]["http"]["prefix"], bed[2]["path"] + ) if remote else os.path.join( - bbc.config[CFG_PATH_KEY][CFG_PIPELINE_OUT_PTH_KEY], bed[2]["path"] + bbc.config[CFG_PATH_KEY][CFG_PIPELINE_OUT_PTH_KEY], + bed[2]["path"], ) ) @@ -424,7 +438,11 @@ async def get_regions_for_bedfile( ) if int(ct_process.communicate()[0].rstrip("\n")) != 0: values.append( - [name, md5sum, int(ct_process.communicate()[0].rstrip("\n"))] + [ + name, + md5sum, + int(ct_process.communicate()[0].rstrip("\n")), + ] ) except FileNotFoundError: @@ -443,7 +461,9 @@ async def get_bedset_genome_assemblies(): Returns available genome assemblies in the database """ - return bbc.bedset.select_distinct(table_name=BEDSET_TABLE, columns=["genome"]) + return bbc.bedset.select_distinct( + table_name=BEDSET_TABLE, columns=["genome"] + ) @router.get("/bedset/count", response_model=int) @@ -456,14 +476,20 @@ async def get_bedset_count(): @router.get("/bedset/all/metadata") async def get_all_bedset_metadata( - ids: Optional[List[str]] = Query(None, description="Bedsets table column name"), - limit: int = Query(None, description="number of rows returned by the query"), + ids: Optional[List[str]] = Query( + None, description="Bedsets table column name" + ), + limit: int = Query( + None, description="number of rows returned by the query" + ), ): """ Get bedsets metadata for selected columns """ if ids: - assert_table_columns_match(bbc=bbc, table_name=BEDSET_TABLE, columns=ids) + assert_table_columns_match( + bbc=bbc, table_name=BEDSET_TABLE, columns=ids + ) res = bbc.bedset.select(columns=ids, limit=limit) @@ -495,7 +521,9 @@ async def get_bedset_schema(): @router.get("/bedset/{md5sum}/bedfiles", response_model=DBResponse) async def get_bedfiles_in_bedset( md5sum: str = bsd, - ids: Optional[List[str]] = Query(None, description="Bedfiles table column name"), + ids: Optional[List[str]] = Query( + None, description="Bedfiles table column name" + ), ): if ids: assert_table_columns_match(bbc=bbc, table_name=BED_TABLE, columns=ids) @@ -533,7 +561,9 @@ async def get_bedset_metadata( """ Returns metadata from selected columns for selected bedset """ - res = bbc.bedset.select(columns=ids, filter_conditions=[("md5sum", "eq", md5sum)]) + res = bbc.bedset.select( + columns=ids, filter_conditions=[("md5sum", "eq", md5sum)] + ) if res: if ids: @@ -594,7 +624,8 @@ async def get_file_path_for_bedset( remote = True if CFG_REMOTE_KEY in bbc.config else False path = ( os.path.join( - bbc.config[CFG_REMOTE_KEY][remoteClass.value]["prefix"], file["path"] + bbc.config[CFG_REMOTE_KEY][remoteClass.value]["prefix"], + file["path"], ) if remote else os.path.join( @@ -721,7 +752,8 @@ async def get_trackDb_file_bedset(request: Request, md5sum: str = bsd): """ hit = bbc.select_bedfiles_for_bedset( - bedfile_cols=["name", "other"], filter_conditions=[("md5sum", "eq", md5sum)] + bedfile_cols=["name", "other"], + filter_conditions=[("md5sum", "eq", md5sum)], ) values = [list(x) for x in hit] @@ -743,7 +775,9 @@ async def get_trackDb_file_bedset(request: Request, md5sum: str = bsd): @router.post("/bedset/create/{name}/{bedfiles}", include_in_schema=False) async def create_new_bedset( name: str = Path(..., description="BED set name"), - bedfiles: str = Path(..., description="BED file ID list (comma sep string)"), + bedfiles: str = Path( + ..., description="BED file ID list (comma sep string)" + ), ): """ add new BED set to database, @@ -813,7 +847,8 @@ async def get_mybedset_file_path( path = ( os.path.join( - bbc.config[CFG_REMOTE_KEY][remoteClass.value]["prefix"], file["path"] + bbc.config[CFG_REMOTE_KEY][remoteClass.value]["prefix"], + file["path"], ) if remote else os.path.join( @@ -829,6 +864,8 @@ async def get_mybedset_file_path( stream, media_type="text/csv", ) - response.headers["Content-Disposition"] = f"attachment; filename={filename}" + response.headers[ + "Content-Disposition" + ] = f"attachment; filename={filename}" return response diff --git a/requirements/requirements-all.txt b/requirements/requirements-all.txt index 234f0450..54328e44 100644 --- a/requirements/requirements-all.txt +++ b/requirements/requirements-all.txt @@ -12,11 +12,6 @@ starlette==0.22.0 uvicorn yacman>=0.7.1 setuptools -graphene==3.1 -graphene-sqlalchemy==3.0.0b1 -graphql-core==3.2.1 -graphql-relay==3.2.0 -starlette-graphene3==0.6.0 diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index b3a1054b..e69de29b 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -1 +0,0 @@ --e git+https://github.com/cooldudemcgeexl/graphene-sqlalchemy-filter@master#egg=graphene-sqlalchemy-filter