From 7f7186f75b216e0f756495f5baa883504e5d8938 Mon Sep 17 00:00:00 2001 From: Sean Hatton <41756439+seanhatton@users.noreply.github.com> Date: Mon, 3 Jun 2024 10:43:44 -0700 Subject: [PATCH] Updating queries --- queries/HippocampusVolumeAgeGender.sparql | 14 +--- queries/ID_sex_age.sparql | 37 +++++++++++ queries/Thickness.sparql | 81 +++++++++++++++++++++++ queries/Volumetrics.sparql | 60 +++++++++++++++++ queries/all_brain_measures.sparql | 29 ++++++++ queries/dwi_count.sparql | 8 +-- queries/female_subj_IDs.sparql | 43 ++++-------- queries/flowweighted_count.sparql | 18 ++--- queries/get_volumes.sparql | 4 +- queries/get_volumes_NoExpData.sparql | 23 +++---- queries/male_subj_IDs.sparql | 24 ++----- queries/metasearch_query_v2.sparql | 32 ++------- queries/simple2_query.sparql | 7 +- 13 files changed, 253 insertions(+), 127 deletions(-) create mode 100644 queries/ID_sex_age.sparql create mode 100644 queries/Thickness.sparql create mode 100644 queries/Volumetrics.sparql create mode 100644 queries/all_brain_measures.sparql diff --git a/queries/HippocampusVolumeAgeGender.sparql b/queries/HippocampusVolumeAgeGender.sparql index 5b0ac43..af9d320 100644 --- a/queries/HippocampusVolumeAgeGender.sparql +++ b/queries/HippocampusVolumeAgeGender.sparql @@ -3,16 +3,10 @@ prefix rdf: prefix prov: prefix ndar: -prefix fsl: prefix nidm: -prefix onli: -prefix freesurfer: -prefix dx: -prefix ants: prefix dct: prefix dctypes: prefix rdfs: -PREFIX ncicb: PREFIX xsd: PREFIX ilx: . @@ -32,9 +26,7 @@ where { OPTIONAL {?measure nidm:isAbout ?federatedLabel }. OPTIONAL {?measure nidm:hasLaterality ?laterality }. ?as_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . - - - + # find age data element uuid {?age_measure a nidm:PersonalDataElement ; nidm:isAbout ilx:ilx_0100400 ; @@ -42,12 +34,12 @@ where { } # find sex data element uuid {?sex_measure a nidm:PersonalDataElement ; - nidm:isAbout . + nidm:isAbout . #Biological sex } ?as_entity prov:wasGeneratedBy ?as_activity ; ?age_measure ?Age ; ?sex_measure ?GenderCoded . bind(IF((?GenderCoded ="1" || ?GenderCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Gender) . - FILTER (?federatedLabel = ) + FILTER (?federatedLabel = ) #Hippocampus } \ No newline at end of file diff --git a/queries/ID_sex_age.sparql b/queries/ID_sex_age.sparql new file mode 100644 index 0000000..2652d34 --- /dev/null +++ b/queries/ID_sex_age.sparql @@ -0,0 +1,37 @@ +prefix xsd: +prefix rdf: +prefix prov: +prefix ndar: +prefix nidm: +prefix fs: +prefix dct: +prefix dctypes: +prefix ilx: + +select distinct ?ID ?Sex ?Age +where { + + ?tool_act a prov:Activity ; + prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + ?as_activity prov:qualifiedAssociation [prov:agent ?agent] ; + dct:isPartOf/dct:isPartOf [dctypes:title ?study] . + ?agent ndar:src_subject_id ?ID . + + # find sex data element uuid + {?sex_measure a nidm:PersonalDataElement ; + nidm:isAbout . #Biological sex + #nidm:isAbout . #Genetic sex + } + + # find age data element uuid + {?age_measure a nidm:PersonalDataElement ; + nidm:isAbout ilx:ilx_0100400 . + } + + ?as_entity prov:wasGeneratedBy ?as_activity ; + ?sex_measure ?SexCoded ; + ?age_measure ?Age. + bind(IF((?SexCoded ="M" || ?SexCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Sex) . +#filter (?Sex = "Male"^^xsd:string) . +} +ORDER BY ?ID \ No newline at end of file diff --git a/queries/Thickness.sparql b/queries/Thickness.sparql new file mode 100644 index 0000000..366436f --- /dev/null +++ b/queries/Thickness.sparql @@ -0,0 +1,81 @@ +## The main issue was that the measures (for left, right, and mean) were coming from different stats collections +## (nidm:FSStatsCollection) associated with different activitities (prov:Acitivity). The previous code +## was assuming that the measurements were coming from the same collection and activity. I also fixed other +## minor issues for effeciency (e.g., removing unnecessary transitive subclass searches) and made the code +## simpler to follow. - Fahim + +prefix xsd: +prefix rdf: +prefix prov: +prefix ndar: +prefix nidm: +prefix fs: +prefix dct: +prefix dctypes: +prefix ilx: + +SELECT DISTINCT + ?ID ?Sex ?Age + ?measure_left_label ?measure_left_value + ?measure_right_label ?measure_right_value + ?measure_mean_label ?measure_mean_value + +WHERE +{ + # Gather the activity types for each type of measure associated with a given subject + ?measure_left_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + ?measure_right_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + ?measure_mean_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + + # Gather the stats collections (nidm:FSStatsCollection) generated by each acitivity type above, + # and allocate the variables for measurement types and values to be identified. + ?left_stats_collection a nidm:FSStatsCollection; + prov:wasGeneratedBy ?measure_left_activity; + ?measure_left ?measure_left_value. + + ?right_stats_collection a nidm:FSStatsCollection; + prov:wasGeneratedBy ?measure_right_activity; + ?measure_right ?measure_right_value. + + ?left_stats_collection a nidm:FSStatsCollection; + prov:wasGeneratedBy ?measure_mean_activity; + ?measure_mean ?measure_mean_value. + + # Set the mesurement type identified based on the specific values for each data element + ?measure_left a fs:DataElement; + rdfs:label ?measure_left_label; + fs:measure 'ThickAvg' ; + fs:structure 'superiortemporal' ; + nidm:hasLaterality 'Left'. + + ?measure_right a fs:DataElement; + rdfs:label ?measure_right_label; + fs:measure 'ThickAvg' ; + fs:structure 'superiortemporal' ; + nidm:hasLaterality 'Right'. + + ?measure_mean a fs:DataElement ; + rdfs:label ?measure_mean_label; + fs:measure 'MeanThickness' ; + fs:structure 'Cortex' . + + + ?as_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + + # find sex data element uuid + {?sex_measure a nidm:PersonalDataElement ; + nidm:isAbout . #Biological sex + #nidm:isAbout . #Genetic sex + } + + # find age data element uuid + {?age_measure a nidm:PersonalDataElement ; + nidm:isAbout ilx:ilx_0100400 . + } + + ?as_entity prov:wasGeneratedBy ?as_activity ; + ?sex_measure ?SexCoded ; + ?age_measure ?Age. + bind(IF((?SexCoded ="M" || ?SexCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Sex) . +} +ORDER BY ?ID diff --git a/queries/Volumetrics.sparql b/queries/Volumetrics.sparql new file mode 100644 index 0000000..6c612d5 --- /dev/null +++ b/queries/Volumetrics.sparql @@ -0,0 +1,60 @@ +prefix xsd: +prefix rdf: +prefix prov: +prefix ndar: +prefix nidm: +prefix fs: +prefix dct: +prefix dctypes: +prefix ilx: + +select distinct ?ID ?Sex ?Age ?left_hipp_vol_softwareLabel ?left_hipp_vol + ?right_hipp_vol_softwareLabel ?right_hipp_vol ?eICV_softwareLabel ?eICV +where { + # tool initialization + ?tool_act a prov:Activity ; + prov:qualifiedAssociation [prov:agent [nidm:NIDM_0000164 ?tool]] . + ?tool_act prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + + # Left Hippocampus Volume + ?tool_entity prov:wasGeneratedBy ?tool_act ; + ?measure_left_hipp_vol ?left_hipp_vol . + ?measure_left_hipp_vol a/rdfs:subClassOf* nidm:DataElement ; + rdfs:label ?left_hipp_vol_softwareLabel; + fs:measure 'Volume_mm3'; + fs:structure 'Left-Hippocampus'. + # Right Hippocampus Volume + ?tool_entity prov:wasGeneratedBy ?tool_act ; + ?measure_right_hipp_vol ?right_hipp_vol . + ?measure_right_hipp_vol a/rdfs:subClassOf* nidm:DataElement ; + rdfs:label ?right_hipp_vol_softwareLabel; + fs:measure 'Volume_mm3'; + fs:structure 'Right-Hippocampus'. + # estimated Intracarnial Volume + ?tool_entity prov:wasGeneratedBy ?tool_act ; + ?measure_eICV ?eICV . + ?measure_eICV a/rdfs:subClassOf* nidm:DataElement ; + rdfs:label ?eICV_softwareLabel; + fs:measure 'eTIV'; + fs:structure 'EstimatedTotalIntraCranialVol'. + ?as_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + + # find sex data element uuid + {?sex_measure a nidm:PersonalDataElement ; + nidm:isAbout . #Biological sex + #nidm:isAbout . #Genetic sex + } + + # find age data element uuid + {?age_measure a nidm:PersonalDataElement ; + nidm:isAbout ilx:ilx_0100400 . + } + + ?as_entity prov:wasGeneratedBy ?as_activity ; + ?sex_measure ?SexCoded ; + ?age_measure ?Age. + bind(IF((?SexCoded ="M" || ?SexCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Sex) . +#filter (?Sex = "Male"^^xsd:string) . +} + +ORDER BY ?ID \ No newline at end of file diff --git a/queries/all_brain_measures.sparql b/queries/all_brain_measures.sparql new file mode 100644 index 0000000..2f9d0e4 --- /dev/null +++ b/queries/all_brain_measures.sparql @@ -0,0 +1,29 @@ +# This query simply returns the brain measurements without dependencies on other +# demographics/assessment measures. + +prefix rdf: +prefix prov: +prefix ndar: +prefix nidm: +prefix dct: +prefix dctypes: +prefix rdfs: + +select distinct ?ID ?tool ?softwareLabel ?federatedLabel ?laterality ?volume +where { + ?tool_act a prov:Activity ; + prov:qualifiedAssociation [prov:agent [nidm:NIDM_0000164 ?tool]] . + ?tool_act prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + ?tool_entity prov:wasGeneratedBy ?tool_act ; + ?measure ?volume . + + ?measure a/rdfs:subClassOf* nidm:DataElement ; + rdfs:label ?softwareLabel; + nidm:measureOf ; #Volume + nidm:datumType . #Volume + #nidm:measureOf . #Thickness + #nidm:measureOf . #Surface Area + OPTIONAL {?measure nidm:isAbout ?federatedLabel }. + OPTIONAL {?measure nidm:hasLaterality ?laterality }. +} +ORDER BY ?ID ?softwareLabel diff --git a/queries/dwi_count.sparql b/queries/dwi_count.sparql index be3d9fa..9045e2e 100644 --- a/queries/dwi_count.sparql +++ b/queries/dwi_count.sparql @@ -14,11 +14,9 @@ prefix ncit: select distinct (count(?entity) as ?dwi_count) where { - - - + ?entity prov:wasGeneratedBy ?activity ; nidm:hadImageContrastType nidm:DiffusionWeighted . - - + + } \ No newline at end of file diff --git a/queries/female_subj_IDs.sparql b/queries/female_subj_IDs.sparql index 497e934..3e5c14c 100644 --- a/queries/female_subj_IDs.sparql +++ b/queries/female_subj_IDs.sparql @@ -2,42 +2,27 @@ prefix xsd: prefix rdf: prefix prov: prefix ndar: -prefix fsl: prefix nidm: -prefix onli: -prefix freesurfer: -prefix dx: -prefix ants: prefix dct: prefix dctypes: -prefix ncicb: -prefix ncit: select distinct ?ID ?Gender -where { - - - ?tool_act a prov:Activity ; - - prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . - - ?as_activity prov:qualifiedAssociation [prov:agent ?agent] ; - dct:isPartOf/dct:isPartOf [dctypes:title ?study] . - ?agent ndar:src_subject_id ?ID . - - - # find sex data element uuid - {?sex_measure a nidm:PersonalDataElement ; - nidm:isAbout . - } - - +where { + ?tool_act a prov:Activity ; + prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + ?as_activity prov:qualifiedAssociation [prov:agent ?agent] ; + dct:isPartOf/dct:isPartOf [dctypes:title ?study] . + ?agent ndar:src_subject_id ?ID . + +# find sex data element uuid + {?sex_measure a nidm:PersonalDataElement ; + nidm:isAbout . + } + ?as_entity prov:wasGeneratedBy ?as_activity ; - - ?sex_measure ?GenderCoded . + ?sex_measure ?GenderCoded . - - bind(IF((?GenderCoded ="1" || ?GenderCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Gender) . + bind(IF((?GenderCoded ="1" || ?GenderCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Gender) . filter (?Gender = "Female"^^xsd:string) . } \ No newline at end of file diff --git a/queries/flowweighted_count.sparql b/queries/flowweighted_count.sparql index 03df72b..46569e0 100644 --- a/queries/flowweighted_count.sparql +++ b/queries/flowweighted_count.sparql @@ -1,27 +1,17 @@ prefix rdf: prefix prov: prefix ndar: -prefix fsl: prefix nidm: -prefix onli: -prefix freesurfer: -prefix dx: -prefix ants: prefix dct: prefix dctypes: -prefix ncicb: -prefix ncit: select distinct (count(?as_entity) as ?flowweighted_count) -where { - - - ?as_activity prov:qualifiedAssociation [prov:agent ?agent] ; +where { + ?as_activity prov:qualifiedAssociation [prov:agent ?agent] ; dct:isPartOf/dct:isPartOf [dctypes:title ?study] . ?agent ndar:src_subject_id ?ID . - ?as_entity prov:wasGeneratedBy ?as_activity ; - nidm:hadImageContrastType nidm:FlowWeighted ; - nidm:Task ?task . + nidm:hadImageContrastType nidm:FlowWeighted ; + nidm:Task ?task . } \ No newline at end of file diff --git a/queries/get_volumes.sparql b/queries/get_volumes.sparql index 32c6932..3b9200f 100644 --- a/queries/get_volumes.sparql +++ b/queries/get_volumes.sparql @@ -74,10 +74,10 @@ WHERE ?measure a measurement_datum:; rdfs:label ?label; - isAbout: ?structure; #; + isAbout: ?structure; #; #caudate nucleus hasMeasurementType: ilx:0112559; hasUnit: "mm^3" ; hasDatumType: ?datum_uri . - #FILTER (?structure = ) . + #FILTER (?structure = ) . #caudate nucleus } diff --git a/queries/get_volumes_NoExpData.sparql b/queries/get_volumes_NoExpData.sparql index 9c72dc9..5873212 100644 --- a/queries/get_volumes_NoExpData.sparql +++ b/queries/get_volumes_NoExpData.sparql @@ -3,30 +3,23 @@ prefix rdf: prefix prov: prefix ndar: -prefix fsl: prefix nidm: -prefix onli: -prefix freesurfer: -prefix dx: -prefix ants: -prefix dct: -prefix dctypes: prefix rdfs: select distinct ?ID ?tool ?softwareLabel ?federatedLabel ?laterality ?volume where { ?tool_act a prov:Activity ; - prov:qualifiedAssociation [prov:agent [nidm:NIDM_0000164 ?tool]] ; - prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + prov:qualifiedAssociation [prov:agent [nidm:NIDM_0000164 ?tool]] ; + prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . ?tool_entity prov:wasGeneratedBy ?tool_act ; ?measure ?volume . - ?measure a/rdfs:subClassOf* nidm:DataElement ; - rdfs:label ?softwareLabel; - nidm:measureOf ; - nidm:datumType . - OPTIONAL {?measure nidm:isAbout ?federatedLabel }. - OPTIONAL {?measure nidm:hasLaterality ?laterality }. + ?measure a/rdfs:subClassOf* nidm:DataElement ; + rdfs:label ?softwareLabel; + nidm:measureOf ; #Volume + nidm:datumType . + OPTIONAL {?measure nidm:isAbout ?federatedLabel }. + OPTIONAL {?measure nidm:hasLaterality ?laterality }. } diff --git a/queries/male_subj_IDs.sparql b/queries/male_subj_IDs.sparql index c077d6b..f55dfa0 100644 --- a/queries/male_subj_IDs.sparql +++ b/queries/male_subj_IDs.sparql @@ -2,42 +2,28 @@ prefix xsd: prefix rdf: prefix prov: prefix ndar: -prefix fsl: prefix nidm: -prefix onli: -prefix freesurfer: -prefix dx: -prefix ants: prefix dct: prefix dctypes: -prefix ncicb: -prefix ncit: select distinct ?ID ?Gender -where { - - +where { ?tool_act a prov:Activity ; - - prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . ?as_activity prov:qualifiedAssociation [prov:agent ?agent] ; dct:isPartOf/dct:isPartOf [dctypes:title ?study] . ?agent ndar:src_subject_id ?ID . - # find sex data element uuid {?sex_measure a nidm:PersonalDataElement ; nidm:isAbout . } - - ?as_entity prov:wasGeneratedBy ?as_activity ; - - ?sex_measure ?GenderCoded . + ?as_entity prov:wasGeneratedBy ?as_activity ; + ?sex_measure ?GenderCoded . - bind(IF((?GenderCoded ="1" || ?GenderCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Gender) . + bind(IF((?GenderCoded ="1" || ?GenderCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?Gender) . filter (?Gender = "Male"^^xsd:string) . - } \ No newline at end of file diff --git a/queries/metasearch_query_v2.sparql b/queries/metasearch_query_v2.sparql index ffcbf2e..73e6f25 100644 --- a/queries/metasearch_query_v2.sparql +++ b/queries/metasearch_query_v2.sparql @@ -1,12 +1,8 @@ prefix rdf: prefix prov: prefix ndar: -prefix fsl: prefix nidm: -prefix onli: -prefix freesurfer: prefix dx: -prefix ants: prefix dct: prefix dctypes: prefix ncicb: @@ -20,12 +16,9 @@ prefix dicom: select distinct ?project_title ?ID ?age ?sex ?diagnosis ?field_strength2 ?manufacturer ?image_type ?contrast_type ?task ?location where { - ?scan_act a prov:Activity ; prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . - - ?scan_entity prov:wasGeneratedBy ?scan_act ; nidm:hadAcquisitionModality nidm:MagneticResonanceImaging ; nidm:hadImageUsageType ?image_type_long ; @@ -33,20 +26,14 @@ where { dicom:MagneticFieldStrength ?field_strength ; dicom:Manufacturer ?manufacturer . - OPTIONAL {?scan_entity nidm:Task ?task } . OPTIONAL {?scan_entity prov:Location ?location } . - ?scan_act dct:isPartOf/dct:isPartOf ?project . ?project dctypes:title ?project_title . - - - # ?as_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . - - - - + + # ?as_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . + # find age data element uuid {?age_measure a nidm:PersonalDataElement ; nidm:isAbout ilx:ilx_0100400 . @@ -65,10 +52,7 @@ where { ?age_measure ?age_string; ?sex_measure ?GenderCoded; ?DX_measure ?dx . - #OPTIONAL {?as_entity ?DX_measure ?dx } . - - - + #OPTIONAL {?as_entity ?DX_measure ?dx } . BIND(IF((?GenderCoded="1" || ?GenderCoded ="Male"^^xsd:string), "Male"^^xsd:string,"Female"^^xsd:string) as ?sex) . BIND(IF((?dx="1" && strStarts(?project_title,"ABIDE")), "Autism", ?dx) as ?dx2) . @@ -76,10 +60,6 @@ where { BIND(IF((?field_strength=3), "3T", ?field_strength) as ?field_strength2) . BIND(IF((?dx3="Typically Developing Children" && strStarts(?project_title,"ADHD")), "Control", ?dx3) as ?diagnosis) . - - - - BIND(IF((?image_type_long = nidm:Anatomical),"Structural"^^xsd:string, "Functional"^^xsd:string) as ?image_type) . BIND ( COALESCE ( @@ -90,10 +70,6 @@ where { ) as ?contrast_type ) bind(xsd:float(?age_string) as ?age) . - - - - } order by ?field_strength2 diff --git a/queries/simple2_query.sparql b/queries/simple2_query.sparql index 3f7e53a..1b71088 100644 --- a/queries/simple2_query.sparql +++ b/queries/simple2_query.sparql @@ -19,9 +19,9 @@ prefix ilx: select distinct ?study ?ID ?Age ?dx ?Gender ?FIQ ?PIQ ?VIQ ?tool ?softwareLabel ?federatedLabel ?laterality ?volume where { ?measure a/rdfs:subClassOf nidm:DataElement; - rdfs:label ?softwareLabel; - nidm:measureOf ; - nidm:datumType . + rdfs:label ?softwareLabel; + nidm:measureOf ; + nidm:datumType . OPTIONAL {?measure nidm:isAbout ?federatedLabel }. OPTIONAL {?measure nidm:hasLaterality ?laterality }. @@ -35,7 +35,6 @@ where { ?as_activity prov:qualifiedAssociation [prov:agent [ndar:src_subject_id ?ID]] . - # find age data element uuid {?age_measure a nidm:PersonalDataElement ; nidm:isAbout ilx:ilx_0100400 .