Skip to content

Commit

Permalink
rm graphQL related things
Browse files Browse the repository at this point in the history
  • Loading branch information
xuebingjie1990 committed Aug 31, 2023
1 parent d5922bc commit 196ca20
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
11 changes: 1 addition & 10 deletions bedhost/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
77 changes: 57 additions & 20 deletions bedhost/routers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"),
):
"""
Expand Down Expand Up @@ -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"],
)
)

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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
5 changes: 0 additions & 5 deletions requirements/requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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



1 change: 0 additions & 1 deletion requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
-e git+https://github.com/cooldudemcgeexl/graphene-sqlalchemy-filter@master#egg=graphene-sqlalchemy-filter

0 comments on commit 196ca20

Please sign in to comment.