From 9bf799c9913b9501e6cb2ce6bf6b20f05fe795df Mon Sep 17 00:00:00 2001 From: rmanaem Date: Thu, 9 Feb 2023 16:07:31 -0500 Subject: [PATCH 1/6] Added `subject_group` to `query_template` in utility.py --- app/api/utility.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/api/utility.py b/app/api/utility.py index 15eb481..49b7eba 100644 --- a/app/api/utility.py +++ b/app/api/utility.py @@ -120,7 +120,7 @@ def create_query( SELECT ?dataset ?dataset_name ?sub_id ?file_path ?image_modal WHERE {{ SELECT DISTINCT ?dataset ?dataset_name ?subject ?sub_id ?age ?sex - ?diagnosis ?num_sessions ?assessment ?image_modal ?file_path + ?diagnosis ?subject_group ?num_sessions ?assessment ?image_modal ?file_path WHERE {{ ?dataset a bg:Dataset; bg:label ?dataset_name; @@ -131,6 +131,7 @@ def create_query( bg:age ?age; bg:sex ?sex; bg:diagnosis ?diagnosis; + bg:isSubjectGroup ?subject_group; bg:hasSession ?session; bg:assessment ?assessment; bg:hasSession/bg:hasAcquisition/bg:hasContrastType ?image_modal. From 288c58a7ee09c0285fdab1c94618726500c3911c Mon Sep 17 00:00:00 2001 From: rmanaem Date: Fri, 10 Feb 2023 12:01:31 -0500 Subject: [PATCH 2/6] Modified `query_template` in utility.py Wrapped age, sex, diagnosis, subject group, and assessment with sparql optional pattern --- app/api/utility.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/api/utility.py b/app/api/utility.py index 49b7eba..62dfd32 100644 --- a/app/api/utility.py +++ b/app/api/utility.py @@ -128,16 +128,27 @@ def create_query( ?subject a bg:Subject; bg:label ?sub_id; - bg:age ?age; - bg:sex ?sex; - bg:diagnosis ?diagnosis; - bg:isSubjectGroup ?subject_group; bg:hasSession ?session; - bg:assessment ?assessment; bg:hasSession/bg:hasAcquisition/bg:hasContrastType ?image_modal. ?session bg:filePath ?file_path. + OPTIONAL {{ + ?subject bg:age ?age. + }} + OPTIONAL {{ + ?subject bg:sex ?sex. + }} + OPTIONAL {{ + ?subject bg:diagnosis ?diagnosis. + }} + OPTIONAL {{ + ?subject bg:isSubjectGroup ?subject_group. + }} + OPTIONAL {{ + ?subject bg:assessment ?assessment. + }} + {{ SELECT ?subject (count(distinct ?session) as ?num_sessions) WHERE {{ From d1a1d9bb58e1e985419318cd6d13b2da6ee61205 Mon Sep 17 00:00:00 2001 From: rmanaem Date: Tue, 14 Feb 2023 14:16:07 -0500 Subject: [PATCH 3/6] Modified `query_template` in utility.py Wrapped file path with sparql optional pattern --- app/api/utility.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/api/utility.py b/app/api/utility.py index 62dfd32..2c9f6fd 100644 --- a/app/api/utility.py +++ b/app/api/utility.py @@ -131,8 +131,9 @@ def create_query( bg:hasSession ?session; bg:hasSession/bg:hasAcquisition/bg:hasContrastType ?image_modal. - ?session bg:filePath ?file_path. - + OPTIONAL {{ + ?session bg:filePath ?file_path. + }} OPTIONAL {{ ?subject bg:age ?age. }} From 241bf5746933f41c826ba49c8e1f3ab973905f4c Mon Sep 17 00:00:00 2001 From: rmanaem Date: Tue, 14 Feb 2023 14:18:52 -0500 Subject: [PATCH 4/6] Set the default response class of the app to ORJSONResponse The starlette.response.JSONResponse class which is the default response class in fastapi doesn't allow nan values and throws `ValueError: Out of range float values are not JSON compliant` error --- app/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 81af747..1499fe2 100644 --- a/app/main.py +++ b/app/main.py @@ -4,10 +4,11 @@ import uvicorn from fastapi import FastAPI +from fastapi.responses import ORJSONResponse from .api.routers import query -app = FastAPI() +app = FastAPI(default_response_class=ORJSONResponse) @app.on_event("startup") From d49589ba3196c53d4798b32398aeb0d9af2af036 Mon Sep 17 00:00:00 2001 From: rmanaem Date: Tue, 14 Feb 2023 14:38:24 -0500 Subject: [PATCH 5/6] Added orjson library to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 357c0a7..c8c8cd0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ identify==2.5.9 idna==3.4 iniconfig==1.1.1 nodeenv==1.7.0 +orjson==3.8.6 packaging==21.3 pandas==1.5.2 platformdirs==2.5.4 From 46cfb986b2a63bd590290841bc1ee9af9cb96976 Mon Sep 17 00:00:00 2001 From: Alyssa Dai Date: Tue, 14 Feb 2023 23:59:58 -0500 Subject: [PATCH 6/6] drop NaN file paths from aggregate query response --- app/api/crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/crud.py b/app/api/crud.py index 6c78412..643ad90 100644 --- a/app/api/crud.py +++ b/app/api/crud.py @@ -94,7 +94,7 @@ async def get( dataset=dataset, dataset_name=dataset_name, num_matching_subjects=group["sub_id"].nunique(), - subject_file_paths=list(group["file_path"]), + subject_file_paths=list(group["file_path"].dropna()), image_modals=list(group["image_modal"].unique()), ) )