Skip to content

Commit

Permalink
[REF] Make session count names clearer in query response (#282)
Browse files Browse the repository at this point in the history
* update session count variable names in response

* update default SPARQL query file

* better highlight default query file in README

* Update README.md

Co-authored-by: Sebastian Urchs <[email protected]>

---------

Co-authored-by: Sebastian Urchs <[email protected]>
  • Loading branch information
alyssadai and surchs authored Feb 28, 2024
1 parent cf10db0 commit 2b1377b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Please refer to our [**official documentation**](https://neurobagel.org/api/) fo
- [Docker (recommended)](#docker)
- [Python](#python)
- [Testing](#testing)
- [The default Neurobagel SPARQL query](#the-default-neurobagel-sparql-query)
- [License](#license)


Expand Down Expand Up @@ -180,7 +181,7 @@ pytest tests
## The default Neurobagel SPARQL query
`docs/default_neurobagel_query.rq` contains a sample default SPARQL query sent by the Neurobagel API to a graph database to retrieve all available phenotypic and imaging data.
[`docs/default_neurobagel_query.rq`](docs/default_neurobagel_query.rq) contains a sample default SPARQL query sent by the Neurobagel API to a graph database to retrieve all available phenotypic and imaging data.
This file is mainly intended for reference because in normal operations,
the API will always talk to the graph on behalf of the user.
Expand Down
4 changes: 2 additions & 2 deletions app/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ async def get(
{
"sub_id": "first",
"session_id": "first",
"num_phenotypic_sessions": "first",
"num_imaging_sessions": "first",
"num_matching_phenotypic_sessions": "first",
"num_matching_imaging_sessions": "first",
"session_type": "first",
"age": "first",
"sex": "first",
Expand Down
4 changes: 2 additions & 2 deletions app/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class SessionResponse(BaseModel):

sub_id: str
session_id: str
num_phenotypic_sessions: int
num_imaging_sessions: int
num_matching_phenotypic_sessions: int
num_matching_imaging_sessions: int
session_type: str
age: Optional[float]
sex: Optional[str]
Expand Down
10 changes: 5 additions & 5 deletions app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def create_query(
if min_num_phenotypic_sessions is not None:
subject_level_filters += (
"\n"
+ f"FILTER (?num_phenotypic_sessions >= {min_num_phenotypic_sessions})."
+ f"FILTER (?num_matching_phenotypic_sessions >= {min_num_phenotypic_sessions})."
)
if min_num_imaging_sessions is not None:
subject_level_filters += (
"\n"
+ f"FILTER (?num_imaging_sessions >= {min_num_imaging_sessions})."
+ f"FILTER (?num_matching_imaging_sessions >= {min_num_imaging_sessions})."
)

phenotypic_session_level_filters = ""
Expand Down Expand Up @@ -194,7 +194,7 @@ def create_query(
query_string = textwrap.dedent(
f"""
SELECT DISTINCT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?age ?sex
?diagnosis ?subject_group ?num_phenotypic_sessions ?num_imaging_sessions ?session_id ?session_type ?assessment ?image_modal ?session_file_path
?diagnosis ?subject_group ?num_matching_phenotypic_sessions ?num_matching_imaging_sessions ?session_id ?session_type ?assessment ?image_modal ?session_file_path
WHERE {{
?dataset_uuid a nb:Dataset;
nb:hasLabel ?dataset_name;
Expand Down Expand Up @@ -229,7 +229,7 @@ def create_query(
?session nb:hasAssessment ?assessment.
}}
{{
SELECT ?subject (count(distinct ?phenotypic_session) as ?num_phenotypic_sessions)
SELECT ?subject (count(distinct ?phenotypic_session) as ?num_matching_phenotypic_sessions)
WHERE {{
?subject a nb:Subject.
OPTIONAL {{
Expand All @@ -255,7 +255,7 @@ def create_query(
}} GROUP BY ?subject
}}
{{
SELECT ?subject (count(distinct ?imaging_session) as ?num_imaging_sessions)
SELECT ?subject (count(distinct ?imaging_session) as ?num_matching_imaging_sessions)
WHERE {{
?subject a nb:Subject.
OPTIONAL {{
Expand Down
10 changes: 5 additions & 5 deletions docs/default_neurobagel_query.rq
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PREFIX nidm: <http://purl.org/nidash/nidm#>
PREFIX snomed: <http://purl.bioontology.org/ontology/SNOMEDCT/>

SELECT DISTINCT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?age ?sex
?diagnosis ?subject_group ?num_phenotypic_sessions ?num_imaging_sessions ?session_id ?session_type ?assessment ?image_modal ?session_file_path
?diagnosis ?subject_group ?num_matching_phenotypic_sessions ?num_matching_imaging_sessions ?session_id ?session_type ?assessment ?image_modal ?session_file_path
WHERE {
?dataset_uuid a nb:Dataset;
nb:hasLabel ?dataset_name;
Expand All @@ -15,7 +15,7 @@ WHERE {
nb:hasLabel ?sub_id;
nb:hasSession ?session.
?session a ?session_type;
nb:hasLabel ?session_id.
nb:hasLabel ?session_id.
OPTIONAL {
?session nb:hasAcquisition/nb:hasContrastType ?image_modal.
OPTIONAL {
Expand All @@ -41,7 +41,7 @@ WHERE {
?session nb:hasAssessment ?assessment.
}
{
SELECT ?subject (count(distinct ?phenotypic_session) as ?num_phenotypic_sessions)
SELECT ?subject (count(distinct ?phenotypic_session) as ?num_matching_phenotypic_sessions)
WHERE {
?subject a nb:Subject.
OPTIONAL {
Expand All @@ -67,7 +67,7 @@ WHERE {
} GROUP BY ?subject
}
{
SELECT ?subject (count(distinct ?imaging_session) as ?num_imaging_sessions)
SELECT ?subject (count(distinct ?imaging_session) as ?num_matching_imaging_sessions)
WHERE {
?subject a nb:Subject.
OPTIONAL {
Expand All @@ -78,4 +78,4 @@ WHERE {
} GROUP BY ?subject
}

}
}

0 comments on commit 2b1377b

Please sign in to comment.