Skip to content

Commit

Permalink
[FIX] Ensure subjects without imaging sessions are considered in main…
Browse files Browse the repository at this point in the history
… query (#333)

* use left join approach for imaging session subquery

* update default non-aggregated query
  • Loading branch information
alyssadai authored Aug 13, 2024
1 parent 6d14e39 commit 7f0ca21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def create_query(
{{
SELECT ?subject (count(distinct ?imaging_session) as ?num_matching_imaging_sessions)
WHERE {{
?subject a nb:Subject.
OPTIONAL {{
?subject nb:hasSession ?imaging_session.
?imaging_session a nb:ImagingSession;
Expand Down
28 changes: 13 additions & 15 deletions docs/default_neurobagel_query.rq
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ SELECT DISTINCT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?age ?se
?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;
nb:hasSamples ?subject.
nb:hasLabel ?dataset_name;
nb:hasSamples ?subject.
?subject a nb:Subject;
nb:hasLabel ?sub_id;
nb:hasSession ?session.
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 {?session nb:hasFilePath ?session_file_path.}
Expand All @@ -29,17 +29,15 @@ WHERE {
{
SELECT ?subject (count(distinct ?phenotypic_session) as ?num_matching_phenotypic_sessions)
WHERE {
?subject a nb:Subject.
OPTIONAL {
?subject nb:hasSession ?phenotypic_session.
?phenotypic_session a nb:PhenotypicSession.
?subject nb:hasSession ?phenotypic_session.
?phenotypic_session a nb:PhenotypicSession.

OPTIONAL {?phenotypic_session nb:hasAge ?age.}
OPTIONAL {?phenotypic_session nb:hasSex ?sex.}
OPTIONAL {?phenotypic_session nb:hasDiagnosis ?diagnosis.}
OPTIONAL {?phenotypic_session nb:isSubjectGroup ?subject_group.}
OPTIONAL {?phenotypic_session nb:hasAssessment ?assessment.}

OPTIONAL {?phenotypic_session nb:hasAge ?age.}
OPTIONAL {?phenotypic_session nb:hasSex ?sex.}
OPTIONAL {?phenotypic_session nb:hasDiagnosis ?diagnosis.}
OPTIONAL {?phenotypic_session nb:isSubjectGroup ?subject_group.}
OPTIONAL {?phenotypic_session nb:hasAssessment ?assessment.}
}

} GROUP BY ?subject
}
Expand Down

0 comments on commit 7f0ca21

Please sign in to comment.