Skip to content

Commit

Permalink
Merge pull request #81 from neurobagel/maint-44-72
Browse files Browse the repository at this point in the history
Modified `query_template` in utility.py
  - Added bg:isSubjectGroup to query_template
  - Wrapped age, sex, diagnosis, subject group, assessment, and file path with sparql optional pattern
  • Loading branch information
rmanaem authored Feb 15, 2023
2 parents 2f5e0f3 + 46cfb98 commit 9e1db3c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
)
)
Expand Down
25 changes: 19 additions & 6 deletions app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,35 @@ 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;
bg:hasSamples ?subject.
?subject a bg:Subject;
bg:label ?sub_id;
bg:age ?age;
bg:sex ?sex;
bg:diagnosis ?diagnosis;
bg:hasSession ?session;
bg:assessment ?assessment;
bg:hasSession/bg:hasAcquisition/bg:hasContrastType ?image_modal.
?session bg:filePath ?file_path.
OPTIONAL {{
?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)
Expand Down
3 changes: 2 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e1db3c

Please sign in to comment.