Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparql query for flip, TE, TR values #5

Open
wdduncan opened this issue Aug 29, 2021 · 0 comments
Open

sparql query for flip, TE, TR values #5

wdduncan opened this issue Aug 29, 2021 · 0 comments

Comments

@wdduncan
Copy link
Member

@addiehl @mtsmith6 @adbartni Below is the query (with results) you requested. There are a lot of things going on this query that are difficult to explain in a post. You need to know how to query equivalent classes and traverse lists in RDF. Figuring out how the min/max values worked was a bit of a pain. I only figured it by looking the Turtle version of the ontology and adjusting accordingly (with much trial and error).
In the query, you see many lines where I used (xsd:minInclusive|xsd:minExclusive)/(xsd:maxInclusive|xsd:maxExclusive). This is b/c I noticed that sometimes the ranges were exclusive (e.g. >) and sometimes they were inclusive (e.g., >=). The query could be simplified a little if you can standardize on just using an inclusive or exclusive operator.

Hopefully, this query will give you enough of what you need :)

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX root: <http://purl.obolibrary.org/obo/mrio.owl/MRIO_0000623>
PREFIX TR: <http://purl.obolibrary.org/obo/MRIO_0000376>
PREFIX TE: <http://purl.obolibrary.org/obo/MRIO_0000377>
PREFIX flip: <http://purl.obolibrary.org/obo/MRIO_0000384>
SELECT DISTINCT 
?subject ?subject_label ?flip ?flip_min ?flip_max ?te_min ?te_max ?tr_min ?tr_max 
WHERE {
    ?subject rdfs:subClassOf* root: .
    ?subject rdfs:label ?subject_label .
    # find equiv class with flip angle value
    optional {
        ?subject owl:equivalentClass 
                [ a owl:Class;
                  owl:intersectionOf/rdf:rest*/rdf:first 
                [ a owl:Restriction;
                  owl:onProperty flip:;
                  owl:hasValue ?flip]].
    }
    # find eqiv class with flip min/max value
    optional {
        ?subject owl:equivalentClass 
                [ a owl:Class;
                  owl:intersectionOf/rdf:rest*/rdf:first 
                [ a owl:Restriction;
                  owl:onProperty flip:;
                  owl:someValuesFrom* 
                [ a rdfs:Datatype ;
                  owl:withRestrictions ?flip_range ]]] .
        optional {
            ?flip_range 
                rdf:rest*/rdf:first/(xsd:minInclusive|xsd:minExclusive) ?flip_min 
        }
        optional {
            ?flip_range 
                rdf:rest*/rdf:first/(xsd:maxInclusive|xsd:maxExclusive) ?flip_max 
        }
    }
    # find eqiv class with TE min/max values
    optional {
        ?subject owl:equivalentClass 
                [ a owl:Class;
                  owl:intersectionOf/rdf:rest*/rdf:first 
                [ a owl:Restriction;
                  owl:onProperty TE:;
                  owl:someValuesFrom*
                [ a rdfs:Datatype ;
                  owl:withRestrictions ?te_range ]]] .
        optional {
            ?te_range 
                rdf:rest*/rdf:first/(xsd:minInclusive|xsd:minExclusive) ?te_min .
        }
        optional {
            ?te_range 
                rdf:rest*/rdf:first/(xsd:maxInclusive|xsd:maxExclusive) ?te_max .
        }
    }
    # find eqiv class with TR min/max value
    optional {
        ?subject owl:equivalentClass 
                [ a owl:Class;
                  owl:intersectionOf/rdf:rest*/rdf:first 
                [ a owl:Restriction;
                  owl:onProperty TR:;
                  owl:someValuesFrom*
                [ a rdfs:Datatype ;
                  owl:withRestrictions ?tr_range ]]] .
        optional {
            ?tr_range 
                rdf:rest*/rdf:first/(xsd:minInclusive|xsd:minExclusive) ?tr_min .
        }
        optional {
            ?tr_range 
                rdf:rest*/rdf:first/(xsd:maxInclusive|xsd:maxExclusive) ?tr_max .
        }
    }
}

Results

subject subject_label flip flip_min flip_max te_min te_max tr_min tr_max
obo:mrio.owl/MRIO_0000623 MRI acquisition sequence
obo:MRIO_0000385 T1 weighted MRI acquisition sequence 90 0.0 30.0 0.0 800.0
obo:MRIO_0000386 T2 weighted MRI acquisition sequence 90 30.0 2000.0
obo:MRIO_0000387 Proton density sequence 90 30.0 1000.0
obo:MRIO_0000388 T2 FSE sequence 90 60.0 2000.0
obo:MRIO_0000389 T1 GRE sequence 70.0 110.0 30.0 0.0
obo:MRIO_0000390 T2* GRE sequence 5.0 20.0 30.0 0.0
obo:MRIO_0000391 STIR sequence 180 60.0 2000.0
obo:MRIO_0000392 T2 FLAIR sequence 70.0 110.0 80.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant