Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site

Use Cases from JBI submission

"vSPARQL: A View Definition Language for the Semantic Web"

 

This page is intended as suplemental material for the JBI submission "vSPARQL: A View Definition Language for the Semantic Web". Included are the URL of a vSPARQL demo interface, for query testing, a brief descriptions of each use case in the paper, and a runable query demonstrating each case. You may cut and paste queries found here into the vSPARQL interface below.

vSPARQL demo interface: http://axon.biostr.washington.edu:8080/VSparQL_Service/

Use Cases:

  1. Mitotic cell cycle. From Reactome, extract the mitotic cell cycle, all of its component processes, and their accompanying labels. This extraction will be used by an application for exploring processes and their subprocesses. Although the data leverages an OWL specification, only process data should be included in the view.

    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX reactome:<http://purl.org/science/ontology/reactome/>
    
    CONSTRUCT
    {
    	?a ?b ?c.
    	?a rdfs:label ?a_label.
    	?c rdfs:label ?c_label.
    
    }
    FROM <http://purl.org/science/ontology/reactome>
    FROM NAMED <mitotic_cell_cycle>
    [
    	CONSTRUCT {?b reactome:componentOf ?a}
    	FROM <http://purl.org/science/ontology/reactome>
    	WHERE
    	{
    		?a rdfs:label "mitotic cell cycle".
    		?b reactome:componentOf ?a .
    	}
    	UNION
    	CONSTRUCT {?c reactome:componentOf ?b}
    	FROM <http://purl.org/science/ontology/reactome>
    	FROM NAMED <mitotic_cell_cycle>
    	WHERE
    	{
    		GRAPH <mitotic_cell_cycle> {?b reactome:componentOf ?a}.
    		?c reactome:componentOf ?b .
    	}
    	
    ]
    WHERE
    {
    	GRAPH <mitotic_cell_cycle> {?a ?b ?c}.
    	?a rdfs:label ?a_label.
    	?c rdfs:label ?c_label.
    }
    

  2. Organ spatial location. From the FMA, extract the spatial information that can be used by image recognition software to automatically identify objects in medical images of the gastrointestinal tract. The result should only include the organs found in the gastrointestinal tract and their associated orientation and location properties.

    # Get all of the spatial relationships associated with the organs in
    # the gastrointestinal tract.
    
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX temp:<http://sig.biostr.washington.edu/temp#>
    PREFIX fma:<http://sig.biostr.washington.edu/fma3.0#>
    
    CONSTRUCT 
    { 
        ?organ_part ?spatial_rel ?spatial_value .
        ?fmlive ?fmlive_p ?fmlive_o .
        ?fmlive2 ?fmlive_p2 ?fmlive_o2
    }
    FROM NAMED <gi_parts> [
        CONSTRUCT { temp:set temp:member ?parts }
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { 
          ?parts gleen:OnPath ("([fma:regional_part_of]|[fma:constitutional_part_of]|[fma:systemic_part_of])*" fma:Gastrointestinal_tract) .
        }
    ]
    FROM NAMED <organ_parts> [
        CONSTRUCT { temp:set temp:member ?gi_part }
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { 
              ?gi_part gleen:OnPath ("([rdfs:subClassOf])*" fma:Organ) .
        }
    ]
    FROM <http://sig.biostr.washington.edu/fma3.0>
    WHERE {
        GRAPH <gi_parts> { ?a ?b ?organ_part } .
        GRAPH <organ_parts> { ?c ?d ?organ_part } .
        ?organ_part ?spatial_rel ?spatial_value .
        FILTER ( (?spatial_rel = fma:orientation) ||
        	     (?spatial_rel = fma:continuous_with) ||
    	     (?spatial_rel = fma:continuous_with_distally) ||
    	     (?spatial_rel = fma:continuous_with_proximally) ||
    	     (?spatial_rel = fma:attributed_continuous_with) ||
    	     (?spatial_rel = fma:contained_in) ) .
        OPTIONAL { ?organ_part fma:orientation ?fmlive .
                   ?fmlive ?fmlive_p ?fmlive_o . }		
        OPTIONAL { ?organ_part fma:attributed_continuous_with ?fmlive2 .
                   ?fmlive2 ?fmlive_p2 ?fmlive_o2 . }	
    }

  3. NeuroFMA ontology. From the FMA, generate a subset ontology that contains all of the information regarding neuro-anatomy. It should contain all of the neural structures from the FMA, their attributes, and the properties connecting them.

    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX temp:<http://sig.biostr.washington.edu/temp#>
    PREFIX fma:<http://sig.biostr.washington.edu/fma3.0#>
    
    ####################################################################################
    # Generate the NeuroFMA
    ####################################################################################
    CONSTRUCT {  ?x ?y ?z }
    FROM <http://sig.biostr.washington.edu/fma3.0>
    
    # all parts recursively of neuraxis
    FROM NAMEDV <top_pre_neuraxis_parts> [
        CONSTRUCT {temp:set temp:member ?part}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE {fma:Neuraxis gleen:OnPath ("([fma:regional_part]|[fma:constitutional_part])*" ?part)}
    ]
    FROM NAMEDV <pre_neuraxis_parts> [
         CONSTRUCT {temp:set temp:member ?part . temp:set temp:member ?c. }
         FROM NAMEDV <top_pre_neuraxis_parts>
         FROM <http://sig.biostr.washington.edu/fma3.0>
         WHERE { GRAPH <top_pre_neuraxis_parts> { ?a ?b ?part } . 
    	     OPTIONAL { ?part rdf:type ?c } }
    ]
    
    # get all inter-part attributed relationship instances (and rels)
    FROM NAMEDV <neuraxis_attr_rels_in> [
       CONSTRUCT {?p ?rel ?q}
       FROM <http://sig.biostr.washington.edu/fma3.0>
       WHERE { GRAPH <pre_neuraxis_parts> {temp:set temp:member ?p.}.
               ?p ?rel ?q.
               OPTIONAL {?q rdfs:subClassOf ?super}. FILTER(!bound(?super)).
               FILTER((?rel = fma:attributed_part) || (?rel = fma:related_part)). }
    ]
    
    # get all inter-part attributed relationship instances (and rels)
    FROM NAMEDV <neuraxis_attr_rels_out> [
       CONSTRUCT {?q ?rel2 ?p2.}
       FROM <http://sig.biostr.washington.edu/fma3.0>
       WHERE { GRAPH <pre_neuraxis_parts> {temp:set temp:member ?p2.}.
               ?q ?rel2 ?p2.
               OPTIONAL {?q rdfs:subClassOf ?super}. FILTER(!bound(?super)).
               FILTER((?rel2 = fma:attributed_part) || (?rel2 = fma:related_part)). }
    ]
    
    # get all inter-part attributed relationship instances (and rels)
    FROM NAMEDV <neuraxis_attr_rels> [
       CONSTRUCT {temp:set temp:member ?q. 
    	      temp:rel_set temp:member ?rel. 
    	      temp:rel_set temp:member ?rel2.}
       FROM <http://sig.biostr.washington.edu/fma3.0>
       WHERE { GRAPH <neuraxis_attr_rels_in> {?p ?rel ?q.}.
               GRAPH <neuraxis_attr_rels_out> {?q ?rel2 ?p2.}. }
    ]
    
    # get all inter-part attributed instances types 
    FROM NAMEDV <neuraxis_parts> [
    	CONSTRUCT {temp:set temp:member ?p. 
    		  temp:set temp:member fma:Concept_name.
    		  temp:set temp:member fma:Query_Atlas_term.
    		  temp:set temp:member fma:Neurolex_term.
    		  temp:set temp:member fma:AAL_term. }
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { { GRAPH <pre_neuraxis_parts> {temp:set temp:member ?p}
        	    } UNION {
    	      GRAPH <neuraxis_attr_rels> {temp:set temp:member ?q.}
       	      ?q rdf:type ?p.
       	    } }
    ]
    
    # build graph containing all properties of all classes identified so far
    FROM NAMEDV <neuraxis_parts_graph> [
        CONSTRUCT {?p ?rel ?obj}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE {GRAPH <neuraxis_parts> {temp:set temp:member ?p}. ?p ?rel ?obj .}
    ]
    
    # get all properties which either connect two of the parts above or connects a part to a literal
    FROM NAMEDV <neuraxis_parts_props> [
    	CONSTRUCT { temp:set temp:member ?b. 
    		    temp:set temp:member ?e. 
    		    temp:set temp:member ?rel.
    		    temp:set temp:member fma:Preferred_name.
    		    temp:set temp:member fma:Synonym.
    		    temp:set temp:member fma:Non-English_equivalent.
    		    temp:set temp:member fma:Query_Atlas.
    		    temp:set temp:member fma:Neurolex.
    		    temp:set temp:member fma:AAL. }
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { { GRAPH <neuraxis_parts_graph> {?a ?b ?c}. FILTER isLiteral(?c) 
    	    } UNION {
    	      GRAPH <neuraxis_parts_graph> {?d ?e ?f}.
    	      GRAPH <neuraxis_parts> {temp:set temp:member ?f}.
    	    } UNION {
    	      GRAPH <neuraxis_attr_rels> {temp:rel_set temp:member ?rel.}
    	    } }
    ]
    
    # Our view only includes a small number of Non-physical_anatomical_entity_template
    # (and subClass) instances. Build up a list of things to exclude.
    FROM NAMEDV <stoppingPoint> [
         CONSTRUCT { temp:set temp:member ?a .}
         FROM <http://sig.biostr.washington.edu/fma3.0>     
         WHERE { ?a gleen:OnPath ("[rdfs:subClassOf]*" fma:Non-physical_anatomical_entity_template) . }
    ]
    FROM NAMEDV <exclusionTypes> [
         CONSTRUCT { temp:set temp:member ?b }
         FROM <http://sig.biostr.washington.edu/fma3.0>     
         WHERE { GRAPH <stoppingPoint> { ?ts ?tm ?a . }
    	     ?b rdf:type ?a .
    	     FILTER ( ?b != fma:AAL_term && 
    		    ?b != fma:Concept_name &&
    		    ?b != fma:Neuro_term &&
    		    ?b != fma:Neurolex_term &&
    		    ?b != fma:Non-physical_anatomical_entity_template &&
    		    ?b != fma:Organ_part_of_relationship_value &&
    		    ?b != fma:Organ_subdivision_part_of_relationship_value &&
    		    ?b != fma:Part_of_relationship_value &&
    		    ?b != fma:Query_Atlas_term &&
    		    ?b != fma:Structural_relationship_value ) . }
    ]
    
    # determine superclasses, superproperties, and types
    # add nodes connected to blank nodes and recurse on these
    FROM NAMEDV <pre_neuraxis_parts_ext> [
        CONSTRUCT {temp:set temp:member ?c.}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        FROM NAMEDV <exclusionTypes>
        WHERE { { GRAPH <neuraxis_parts> {temp:set temp:member ?c}. 
    	      OPTIONAL {GRAPH <exclusionTypes> {?ts temp:member ?c}.}. FILTER (!bound(?ts)) .
    	    } UNION {
    		GRAPH <neuraxis_parts_props> {temp:set temp:member ?c}.
    		OPTIONAL {GRAPH <exclusionTypes> {?ts temp:member ?c}.}. FILTER (!bound(?ts)) .
    	    } }
        UNION
        CONSTRUCT {temp:set temp:member ?v.}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        FROM NAMEDV <exclusionTypes>
        FROM NAMEDV <pre_neuraxis_parts_ext>
        WHERE { GRAPH <pre_neuraxis_parts_ext> {temp:set temp:member ?c.}
                {?c rdf:type ?v.} UNION {?c rdfs:subClassOf ?v} UNION {?c rdfs:subPropertyOf ?v} UNION
                {?c ?rel ?v. FILTER (isBlank(?c) && !isLiteral(?v)).}.
                OPTIONAL {GRAPH <exclusionTypes> {?ts temp:member ?v}.} . FILTER (!bound(?ts)) . }
    ]
    
    # add in attributed instances
    FROM NAMEDV <neuraxis_parts_ext> [
        CONSTRUCT {temp:set temp:member ?p. temp:set temp:member ?q. temp:set temp:member ?cn.}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { { GRAPH <pre_neuraxis_parts_ext> {temp:set temp:member ?p}. 
                  OPTIONAL { {?p fma:Preferred_name ?cn.}UNION
                             {?p fma:Synonym ?cn.}UNION
                             {?p fma:Non-English_equivalent ?cn.}UNION
    		         {?p fma:Query_Atlas ?cn.}UNION
    		         {?p fma:Neurolex ?cn.}UNION
    		         {?p fma:AAL ?cn.} }
        	    } UNION {
        	      GRAPH <neuraxis_attr_rels> {temp:set temp:member ?q}.
        	    } }
    ]
    
    # build graph containing all properties of all classes identified so far
    FROM NAMEDV <neuraxis_parts_ext_graph> [
        CONSTRUCT {?p ?rel ?obj}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE {GRAPH <neuraxis_parts_ext> {temp:set temp:member ?p}. ?p ?rel ?obj .}
    ]
    
    # build graph containing only properties connecting two classes in ext or a class in ext to a literal
    FROM NAMEDV <neuraxis_view_wo_props> [
        CONSTRUCT {?a ?b ?c. ?d ?e ?f.}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { { GRAPH <neuraxis_parts_ext_graph> {?a ?b ?c}. FILTER isLiteral(?c) 
                } UNION {
    	      GRAPH <neuraxis_parts_ext_graph> {?d ?e ?f}.
    	      GRAPH <neuraxis_parts_ext> {temp:set temp:member ?f}.
    	    } }
    ]
    
    
    # determine superclasses, superproperties, and types
    # add nodes connected to blank nodes and recurse on these
    FROM NAMEDV <pre_neuraxis_parts_props_ext> [
        CONSTRUCT {temp:set temp:member ?c.}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE  { { # we need to define all of the properties that are going to be held in the result graph
    		GRAPH <neuraxis_view_wo_props> { ?uns ?c ?uno }
    	     } UNION { # see if we had any restrictions on properties; if we did, we need to define those properties fully 
    		GRAPH <pre_neuraxis_parts_ext> {temp:set temp:member ?c}. 
    		?r rdf:type owl:Restriction . ?r owl:onProperty ?c .
    	     } UNION {
    		GRAPH <neuraxis_parts_props> {temp:set temp:member ?c}.
    	     } }
        UNION
        CONSTRUCT {temp:set temp:member ?v.}
        FROM <http://sig.biostr.washington.edu/fma3.0>
        FROM NAMEDV <pre_neuraxis_parts_props_ext>
        WHERE { GRAPH <pre_neuraxis_parts_props_ext> {temp:set temp:member ?c.}
                {?c rdf:type ?v.} UNION {?c rdfs:subClassOf ?v} UNION {?c rdfs:subPropertyOf ?v} UNION
                {?c ?rel ?v. FILTER (isBlank(?c) && !isLiteral(?v)).}. }
    ]
    
    FROM NAMEDV <rec_pre_neuraxis_parts_props_ext> [
         CONSTRUCT { ?c ?d ?e }
         FROM <http://sig.biostr.washington.edu/fma3.0>
         WHERE { GRAPH <pre_neuraxis_parts_props_ext> { temp:set temp:member ?c } .
    	     ?c ?d ?e . 
    	     OPTIONAL {GRAPH <neuraxis_parts_ext> { ?ts temp:member ?e } } .
    	     FILTER (isBlank(?e) || isLiteral(?e) || bound(?ts) ||
    		    (!bound(?ts) && !regex(str(?e),"http://sig.biostr.washington.edu/fma3.0")) ). }
         UNION
         CONSTRUCT { ?e ?f ?g }
         FROM <http://sig.biostr.washington.edu/fma3.0>
         FROM NAMEDV <rec_pre_neuraxis_parts_props_ext> 
         WHERE { GRAPH <rec_pre_neuraxis_parts_props_ext> { ?c ?d ?e } .FILTER isBlank(?e) .
    	     ?e ?f ?g . 
    	     OPTIONAL {GRAPH <neuraxis_parts_ext> { ?ts temp:member ?g } .} .
    	     FILTER (isBlank(?g) || isLiteral(?g) || bound(?ts) ||
    		    (!bound(?ts) && !regex(str(?g),"http://sig.biostr.washington.edu/fma3.0")) ). }
    ]
    
    FROM NAMEDV <neuraxis_view> [
        CONSTRUCT {?a ?b ?c. ?d ?e ?f.
    	?ontS ?ontP owl:Ontology . ?ontS ?anyOntP ?anyOntO .
        }
        FROM <http://sig.biostr.washington.edu/fma3.0>
        WHERE { { GRAPH <neuraxis_view_wo_props> {?a ?b ?c}.
    	    } UNION {
    	      GRAPH <rec_pre_neuraxis_parts_props_ext> {?d ?e ?f}.
    	    } UNION {
    	      ?ontS ?ontP owl:Ontology .
    	      OPTIONAL { ?ontS ?anyOntP ?anyOntO . }
                } }
    ]
    
    ####################################################################################
    # Fixup the generated NeuroFMA
    ####################################################################################
    
    
    # Find all of the RDF list nodes that do not have an element; 
    # recursively follow the list until it either hits a node with
    # an element or it hits rdf:nil. Track the node that points
    # to this errant list and the entire set of reachable nodes
    # before the errant list has an element.
    FROM NAMEDV <identify_rdfListEmptyNodes> [
        CONSTRUCT { ?a rdf:rest ?b .	# to be changed
    	        ?b temp:rest ?c . 	# to be deleted
    	        ?a temp:starts ?b .	# first node in rest list
    	        ?a temp:reaches ?c . 	# reachability list
        }
        FROM NAMEDV <neuraxis_view>
        WHERE { GRAPH <neuraxis_view> {
                    ?a rdf:first ?noop .
                    ?a rdf:rest ?b .
                    OPTIONAL { ?b rdf:first ?a_bogus } . FILTER(!bound(?a_bogus)) .
                    ?b rdf:rest ?c . 
                } }
        UNION
        CONSTRUCT { ?a ?pred ?b .	# to be changed
    	        ?b temp:rest ?c .	# to be deleted
    	        ?a temp:starts ?b . # first node in rest list
    	        ?a temp:reaches ?c . # reachability list
        }
        FROM NAMEDV <neuraxis_view>
        WHERE { GRAPH <neuraxis_view> {
        	        ?a ?pred ?b . FILTER(?pred != rdf:rest) .
        	        ?b rdf:rest ?c . 
    	        OPTIONAL { ?b rdf:first ?b_bogus } . FILTER(!bound(?b_bogus)) .
                } }
        UNION
        CONSTRUCT { ?c temp:rest ?d .	# to be deleted
    	        ?a temp:reaches ?d . # reachability list
        }
        FROM NAMEDV <identify_rdfListEmptyNodes>
        FROM NAMEDV <neuraxis_view>
        WHERE { GRAPH <identify_rdfListEmptyNodes> { ?a temp:reaches ?c . } .
                GRAPH <neuraxis_view> {
    	      OPTIONAL { ?c rdf:first ?noop } . FILTER(!bound(?noop)) .
    	      ?c rdf:rest ?d . 
              } }
    ]
    
    # Eliminate all of the edges corresponding to RDF lists elements with no value
    FROM NAMEDV <remove_rdfListEmptyNodes> [
         CONSTRUCT { ?x ?y ?z . }
         FROM NAMEDV <identify_rdfListEmptyNodes>
         FROM NAMEDV <neuraxis_view>
         WHERE { GRAPH <neuraxis_view> { ?x ?y ?z . }
    	     OPTIONAL { GRAPH <identify_rdfListEmptyNodes> { ?x ?ynot ?z } . 
    	   	        FILTER(?ynot=temp:rest && ?y=rdf:rest) } . 
                 FILTER(!bound(?ynot)) . }
    ]
    
    # Remove all of the edges to the start of RDF lists containing empty nodes; 
    # we replace these edges with new edges in <add_startEdgeRdfListEmptyNodes>
    FROM NAMEDV <remove_startEdgeRdfListEmptyNodes> [
         CONSTRUCT { ?q ?r ?s .}
         FROM NAMEDV <identify_rdfListEmptyNodes> 
         FROM NAMEDV <remove_rdfListEmptyNodes>
         WHERE { GRAPH <remove_rdfListEmptyNodes> { ?q ?r ?s . } .
    	     OPTIONAL { GRAPH <identify_rdfListEmptyNodes> { ?q ?r ?t } . FILTER(?s = ?t) } .
    	     FILTER(!bound(?t)) . }
    ]
    
    # Add in the new edges to the RDF lists containing empty nodes
    FROM NAMEDV <add_startEdgeRdfListEmptyNodes> [
         CONSTRUCT { ?t ?u ?v .
    	         ?a2 ?pred2 ?d2 .
         }
         FROM NAMEDV <identify_rdfListEmptyNodes>
         FROM NAMEDV <remove_startEdgeRdfListEmptyNodes>
         FROM NAMEDV <neuraxis_view>
         WHERE { { GRAPH <remove_startEdgeRdfListEmptyNodes> { ?t ?u ?v  }
                 } UNION {
    	       GRAPH <identify_rdfListEmptyNodes> { 
    	     	   ?a2 temp:starts ?b2 .
    	     	   ?a2 ?pred2 ?gone2 . 
    		   FILTER(!REGEX(str(?pred2),"http://sig.biostr.washington.edu/temp#") ) .
    		   ?a2 temp:reaches ?d2 . }
      	       GRAPH <neuraxis_view> { OPTIONAL {  ?d2 rdf:first ?nxt2 } . }
    	       FILTER( (?d2 = rdf:nil) || bound(?nxt2) ) . 
                 } }
    ]
    
    ########################################################################################
    ########################################################################################
    
    # Find owl:unionOf statements that have RDF lists of 0 or 1 elements.
    # Replace the owl:unionOf statements with either the element or rdf:nil.
    FROM NAMEDV <removed_shortUnionOfs> [
         CONSTRUCT { ?q ?r ?s .
    	         ?before1 ?pred1 ?c1 .
    	         ?before2 ?pred2 rdf:nil .
         }
         FROM NAMEDV <add_startEdgeRdfListEmptyNodes> 
         # Find owl:unionOfs that have 0 or 1 element.
         FROM NAMEDV <identify_shortUnionOfs> [
              CONSTRUCT { 
    	      ?before1 ?pred1 ?a1 .
    	      ?a1 owl:unionOf ?b1 .
    	      ?a1 rdf:type owl:Class .
    	      ?b1 rdf:first ?c1 .
    	      ?b1 rdf:rest rdf:nil .
    	      ?before2 ?pred2 ?a2 .
    	      ?a2 owl:unionOf ?b2 .
    	      ?a2 rdf:type owl:Class .
    	      ?b2 rdf:rest rdf:nil .
             }
             FROM NAMEDV <add_startEdgeRdfListEmptyNodes> 
         	 WHERE { { GRAPH <add_startEdgeRdfListEmptyNodes> {
    			?before1 ?pred1 ?a1 .
    	        	?a1 owl:unionOf ?b1 .
    	        	?a1 rdf:type owl:Class .
    	        	?b1 rdf:first ?c1 .
    	        	?b1 rdf:rest rdf:nil .
    		   }
                     } UNION {
    		   GRAPH <add_startEdgeRdfListEmptyNodes> {
     	           	?before2 ?pred2 ?a2 .
    	        	?a2 owl:unionOf ?b2 .
    	        	?a2 rdf:type owl:Class .
    	        	OPTIONAL { ?b2 rdf:first ?c2 . } . FILTER(!bound(?c2)) .
    	        	?b2 rdf:rest rdf:nil .
                       }
    	         } }
         ]
         WHERE { { GRAPH <add_startEdgeRdfListEmptyNodes> { ?q ?r ?s . }
         	       OPTIONAL { GRAPH <identify_shortUnionOfs> { ?q ?r ?t . FILTER(?s = ?t) } }
    	       FILTER(!bound(?t)) .
                 } UNION {
    	       GRAPH <identify_shortUnionOfs> {
    	     	   ?before1 ?pred1 ?a1 .
    		   ?a1 owl:unionOf ?b1 .
    		   ?b1 rdf:first ?c1 . 
    		   ?b1 rdf:rest rdf:nil .
    	       }
                 } UNION {
    	       GRAPH <identify_shortUnionOfs> {
    	     	   ?before2 ?pred2 ?a2 .
    		   ?a2 owl:unionOf ?b2 .
    		   OPTIONAL { ?b2 rdf:first ?c2 . } . FILTER(!bound(?c2)) . }
    		   ?b2 rdf:rest rdf:nil .
    	     } }
    ]
    
    ########################################################################################
    ########################################################################################
    
    # Remove all owl:allValuesFrom that have empty owl:unionOf lists.
    FROM NAMEDV <remove_emptyAllValuesFrom> [
         CONSTRUCT { ?a ?b ?c . }
         FROM NAMEDV <removed_shortUnionOfs> 
    
         # identify allValuesFrom with empty RDF lists
         FROM NAMEDV <identify_emptyAllValuesFrom> [
             CONSTRUCT { ?x owl:allValuesFrom ?allB .
    	             ?allB rdf:type owl:Class .
    	             ?allB owl:unionOf rdf:nil .
             }
             FROM NAMEDV <removed_shortUnionOfs> 
             WHERE { GRAPH <removed_shortUnionOfs> {
                         ?x owl:allValuesFrom ?allB .
                         ?allB rdf:type owl:Class .
                         ?allB owl:unionOf rdf:nil .
                     } }
         ]
         WHERE { GRAPH <removed_shortUnionOfs> { ?a ?b ?c . }
    	     OPTIONAL { GRAPH <identify_emptyAllValuesFrom> { ?a ?b ?cnot . FILTER(?c=?cnot) } } .
    	     FILTER(!bound(?cnot)) . }
    ]
    
    ########################################################################################
    ########################################################################################
    
    # remove the set of owl:Restrictions that do not have values associated with
    # owl:onProperty restrictions
    FROM NAMEDV <remove_emptyOwlOnPropertyRestrictions> [
         CONSTRUCT { ?a ?b ?c . }
         FROM NAMEDV <remove_emptyAllValuesFrom> 
         # identify the set of owl:Restrictions that do not have values associated with
         # owl:onProperty restrictions
         FROM NAMEDV <identify_emptyOwlOnPropertyRestrictions> [
             CONSTRUCT { ?x rdfs:subClassOf ?owlrestrict .
    	             ?owlrestrict rdf:type owl:Restriction .
    	             ?owlrestrict owl:onProperty ?onprop .
             }
             FROM NAMEDV <remove_emptyAllValuesFrom> 
             WHERE { 
    	          GRAPH <remove_emptyAllValuesFrom> {
      	       	       ?x rdfs:subClassOf ?owlrestrict .
    		       ?owlrestrict rdf:type owl:Restriction .
       	     	       ?owlrestrict owl:onProperty ?onprop .
    	     	       OPTIONAL { ?owlrestrict ?anyp ?anyo . 
    		       		  FILTER((?anyp!=rdf:type)&&(?anyp!=owl:onProperty)) . }
    	               FILTER(!bound(?anyp)) . 
                      } }
          ]
          WHERE { GRAPH <remove_emptyAllValuesFrom> { ?a ?b ?c . }
    	      OPTIONAL { GRAPH <identify_emptyOwlOnPropertyRestrictions> { ?a ?b ?cnot . FILTER(?c=?cnot) } } .
    	      FILTER(!bound(?cnot)) . }
    ]
    WHERE {	GRAPH <remove_emptyOwlOnPropertyRestrictions> { ?x ?y ?z } }

  4. NCI Thesaurus (NCIt) simplification. This use case comes from Detwiler, Landon T and Suciu, Dan and Brinkley, James F (2008) Regular Paths in SparQL: Querying the NCI Thesaurus. In Proceedings, American Medical Informatics Association Fall Symposium, pages pp. 161-165, Washington, DC. The goal was to turn the complex chains of triples connecting classes, representing property restrictions, into direct class connections for browsing. The target was to produce via vSparQL query the same associations seen in the NCIt browser. The query:

    PREFIX nci: <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#>
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX user:<http://localhost/userFriendlyNCIT#>
    
    CONSTRUCT 
    { 
    	?selected user:simplified_relationship [[user:relationship(?sel_label,?prop_label,?val_label)]] .
    	[[user:relationship(?sel_label,?prop_label,?val_label)]] user:label ?sel_label .
    	[[user:relationship(?sel_label,?prop_label,?val_label)]] user:propertyLabel ?prop_label .
    	[[user:relationship(?sel_label,?prop_label,?val_label)]] user:valueLabel ?val_label .
    }
    FROM <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl>
    WHERE
    {
    	?selected rdfs:label "Gastric Mucosa-Associated Lymphoid Tissue Lymphoma"  .
    
    	?selected gleen:OnPath ( "(([rdfs:subClassOf]|[owl:equivalentClass])/([owl:intersectionOf]/[rdf:rest]*/[rdf:first])?)+" ?restriction ) .
    	?restriction owl:onProperty ?prop .
    	?restriction gleen:OnPath ( "([owl:someValuesFrom]|[owl:allValuesFrom])" ?val ).
    
    	?selected rdfs:label ?sel_label.
    	?prop rdfs:label ?prop_label.
    	?val rdfs:label ?val_label
    }

  5. Biosiumlation model editor. From the FMA, identify the relationship graph between a set of concepts; the graph is displayed by a biosimulation model editing tool. The application displays the relationships between the concepts as a restructured, pared down hierarchy; the only nodes that should remain in the hierarchy are those under which there is a divergence between concepts. The result changes as new concepts are added and removed from the set of interest. As the user selects concepts within the hierarchy, the application queries additional properties from the FMA and displays it.

    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX set:<http://sig.biostr.washington.edu/set#>
    PREFIX fma:<http://sig.biostr.washington.edu/fma3.0#>
    PREFIX tst:<http://localhost/tst#>
    PREFIX tmp:<http://localhost/tmp#>
    PREFIX view:<http://localhost/view#>
    
    CONSTRUCT { ?a ?b ?c }
    FROM NAMED <bob> [
    CONSTRUCT { ?a view:part ?c. }
    FROM <http://sig.biostr.washington.edu/fma3.0>
    FROM NAMED <input_list> [  
    	CONSTRUCT
    	{
    		set:set1 set:member fma:Blood_in_left_ventricle.
    		set:set1 set:member fma:Mitral_valve.
    		set:set1 set:member fma:Wall_of_left_ventricle.
    		set:set1 set:member fma:Aortic_valve.
    		set:set1 set:member fma:Blood_in_left_atrium.
    		set:set1 set:member fma:Wall_of_left_atrium.
    	}
    	FROM <http://sig.biostr.washington.edu/fma3.0>
    	WHERE{}
    ]
    FROM NAMED <temp_hierarchy> [
    	CONSTRUCT 
    	{
    		?z tst:edge ?x.
    	}
    	FROM NAMED <input_list>
    	FROM <http://sig.biostr.washington.edu/fma3.0>
    	WHERE
    	{
    		GRAPH <input_list> {set:set1 set:member ?a.}
    		(?a "(([fma:regional_part_of]|[fma:constitutional_part_of])|[fma:contained_in])+" ?b) gleen:Subgraph (?x ?y ?z).
    	} 
    ]
    FROM NAMED <restructure> [
         CONSTRUCT { fma:Human_body tmp:inter ?b1 . }
         FROM <temp_hierarchy>
         WHERE { fma:Human_body tst:edge ?b1 }
    
         UNION
    
         CONSTRUCT {
         	       ?a1 view:part ?b1 .
    	       ?b1 tmp:inter ?c1 .
    	       ?b1 tmp:inter ?c2 .
    	       ?a1 tmp:inter ?d1 .
    	       ?a1 view:part ?b3 .
         }
         FROM <temp_hierarchy>
         FROM NAMED <restructure>
         WHERE {
    		{ GRAPH <restructure> { ?a1 tmp:inter ?b1 } .
    	    	  ?b1 tst:edge ?c1 .
    		  ?b1 tst:edge ?c2 .
    		  FILTER(?c1 != ?c2) 
    		} UNION {
    		  GRAPH <restructure> { ?a1 tmp:inter ?b2 } .
    		  ?b2 tst:edge ?d1 .
    		  OPTIONAL { ?b2 tst:edge ?d2 . FILTER(?d1 != ?d2) }
    		  FILTER( !bound(?d2) ) 
    	        } UNION {
    		  GRAPH <restructure> { ?a1 tmp:inter ?b3 } .
    		  OPTIONAL { ?b3 tst:edge ?e1 } 
    		  FILTER( !bound(?e1) ) .
    	        }
         }
    ]
    WHERE { GRAPH <restructure> { ?a view:part ?c } }
    ]
    WHERE { GRAPH <bob> { ?a ?b ?c } }
    

  6. Blood contained in the heart. From the FMA, generate a graph, to be used by physiology modelers, representing portions of blood contained in the heart. The results include heart parts and the blood portions they contain, where “contains” is a modified definition than that used by the FMA. In the FMA, only spaces are allowed in the domain of the contains property; in this use case, if a space contains blood, the structures that it is a part of should also be said to contain blood.

    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX fma:<http://sig.biostr.washington.edu/fma3.0#>
    CONSTRUCT
    {
       ?a ?b ?c .
    }
    FROM NAMED <heart_parts> [
       CONSTRUCT {fma:Heart fma:part ?object}
       FROM <http://sig.biostr.washington.edu/fma3.0>
       WHERE
       {
           {fma:Heart fma:regional_part ?object}
           UNION
           {fma:Heart fma:constitutional_part ?object}
       }
       UNION
       CONSTRUCT {?a fma:part ?object. ?b fma:part ?object}
       FROM <http://sig.biostr.washington.edu/fma3.0>
       FROM NAMED <heart_parts>
       WHERE
       {
           GRAPH <heart_parts> {?a fma:part ?b} .
           {?b fma:regional_part ?object}
           UNION
           {?b fma:constitutional_part ?object}
       }
    ]
    FROM NAMED <heart_containments> [
       CONSTRUCT {?a fma:contains ?c . ?b fma:contains ?c}
       FROM <http://sig.biostr.washington.edu/fma3.0>
       FROM NAMED <heart_parts>
       WHERE
       {
           GRAPH <heart_parts> {?a fma:part ?b} .
           ?b fma:contains ?c .
       }
    ]
    WHERE
    {
       GRAPH <heart_containments> {?a ?b ?c}
    }

  7. Radiologist liver ontology. From the FMA, generate a sub-ontology to be used by an application for annotating medical images of the liver. The sub-
    ontology contains all of the visible parts of the liver and their associated superclass hierarchy; no property other than the superclass relationship should be included. Modify the structure of the subclass hierarchy to remove the concepts "Cavitated organ" and "Solid organ."

    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX fma:<http://sig.biostr.washington.edu/fma3.0#>
    
    CONSTRUCT { ?d ?part_var ?f . 
                ?g rdfs:subClassOf fma:Organ .
                ?i rdfs:subClassOf ?j .
    }
    FROM NAMED <extracted_ontology> [
    
         CONSTRUCT { ?t ?u ?v . }
         FROM NAMED <liver_with_superclasses> [
              CONSTRUCT { ?m ?n ?o . }      
              FROM NAMED <liver_with_classes> [
                   CONSTRUCT { ?j ?part_var ?k .
                               ?k rdfs:subClassOf ?l .
    			   fma:Liver rdfs:subClassOf ?lc .
                   }
                   FROM NAMED <subclass> [
                        CONSTRUCT {?x rdfs:subClassOf fma:Organ .
                                   fma:Organ rdfs:subClassOf ?w .
                                   ?y rdfs:subClassOf fma:Cardinal_organ_part .
                                   fma:Cardinal_organ_part rdfs:subClassOf ?z .
                        }    
                        FROM <http://sig.biostr.washington.edu/fma3.0>
                        WHERE { { ?x rdfs:subClassOf fma:Organ . FILTER(!isBlank(?x)) . 
                                  fma:Organ rdfs:subClassOf ?w . FILTER(!isBlank(?w)) .
                                }
                                UNION
                                { ?y rdfs:subClassOf fma:Cardinal_organ_part . FILTER(!isBlank(?y)) .
                                  fma:Cardinal_organ_part rdfs:subClassOf ?z . FILTER(!isBlank(?z)) .
                                }
                        }
    
                        UNION
    
                        CONSTRUCT {?sub ?b ?a .}
                        FROM NAMED <subclass>
                        FROM NAMED <http://sig.biostr.washington.edu/fma3.0>
                        WHERE { GRAPH <subclass> { ?a ?b ?c . } .
                                GRAPH <http://sig.biostr.washington.edu/fma3.0> 
                                      { ?sub ?b ?a . FILTER(!isBlank(?sub)) } .
                        }
                   ]
                   FROM NAMED <liver> [
                       CONSTRUCT {fma:Liver ?part_var ?obj . }
                       FROM <http://sig.biostr.washington.edu/fma3.0>
                       WHERE { fma:Liver ?part_var ?obj . 
    			  FILTER((?part_var =fma:regional_part)||(?part_var=fma:constitutional_part)||(?part_var=fma:systemic_part)) .
                       }
    
                       UNION
    
                       CONSTRUCT {?c ?part_var ?d}
                       FROM NAMED <liver>
                       FROM NAMED <http://sig.biostr.washington.edu/fma3.0>
                       WHERE { GRAPH <liver> { ?a ?b ?c . } .
                               GRAPH <http://sig.biostr.washington.edu/fma3.0> { ?c ?part_var ?d . } .
    			  FILTER((?part_var =fma:regional_part)||(?part_var=fma:constitutional_part)||(?part_var=fma:systemic_part)) .
                       }
                   ]
                   FROM <http://sig.biostr.washington.edu/fma3.0> 
                   WHERE { { GRAPH <liver> { ?j ?part_var ?k . } . 
                             GRAPH <subclass> { ?k rdfs:subClassOf ?l . FILTER(!isBlank(?l)) .} .
    		       } UNION {
    			fma:Liver rdfs:subClassOf ?lc . FILTER(!isBlank(?lc)) .
    		       }
                   }
              ]
              WHERE { GRAPH <liver_with_classes> { ?m ?n ?o . } }
    
              UNION
    
              CONSTRUCT {?r rdfs:subClassOf ?s}
              FROM NAMED <liver_with_superclasses>
              FROM NAMED <http://sig.biostr.washington.edu/fma3.0>
              WHERE { GRAPH <liver_with_superclasses> { ?p rdfs:subClassOf ?r . } .
                      GRAPH <http://sig.biostr.washington.edu/fma3.0> 
                            { ?r rdfs:subClassOf ?s . FILTER(!isBlank(?s)) . } .
              }
         ]   
         WHERE { GRAPH <liver_with_superclasses> { ?t ?u ?v . } . }
    ]
    WHERE { GRAPH <extracted_ontology> { 
                  { ?d ?part_var ?f . 
    	        FILTER((?part_var =fma:regional_part)||(?part_var=fma:constitutional_part)||(?part_var=fma:systemic_part)) .}
                  UNION
                  { ?g rdfs:subClassOf ?h .
                    FILTER ((?h = fma:Cavitated_organ || ?h = fma:Solid_organ))  .
                  }
                  UNION
                  { ?i rdfs:subClassOf ?j .
                    FILTER ((?j != fma:Cavitated_organ && ?j != fma:Solid_organ) && (?i != fma:Cavitated_organ) && (?i != fma:Solid_organ)).
                  }
          }
    }

  8. Blood fluid properties. Combine information from two independent ontologies (FMA and Ontology of Physics for Biology (OPB )[11]) to create new information for a biosimulation model editing application. Properties of fluids defined in the FMA should be combined with the kinetic properties of fluids defined in the OPB. For example, concepts like arterial blood and capillary blood in the FMA can be combined with flow, pressure, viscosity in the OPB, resulting in new concepts like arterial blood flow, capillary blood viscosity, etc. The result contains the newly created resources and their properties which can be used to annotate computational models of physiology.

    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX gleen:<java:edu.washington.sig.gleen.>
    PREFIX fma:<http://sig.biostr.washington.edu/fma3.0#>
    PREFIX opb:<http://sig.biostr.washington.edu/OPB-01.owl#>
    PREFIX annot_view:<http://sig.biostr.washington.edu/annot_v1.0#>
    
    CONSTRUCT {
    	[[annot_view:annotation(?pob,?property)]] rdf:type rdf:Statement.
    	[[annot_view:annotation(?pob,?property)]] rdf:subject ?pob .
    	[[annot_view:annotation(?pob,?property)]] rdf:predicate opb:hasProperty.
    	[[annot_view:annotation(?pob,?property)]] rdf:object ?property .
    }
    FROM NAMED <http://sig.biostr.washington.edu/fma3.0>
    FROM NAMED <http://sig.biostr.washington.edu/~detwiler/OntViews/OPB/OPB-01.owl>
    WHERE {	
    	GRAPH <http://sig.biostr.washington.edu/fma3.0>
        	  { ?pob gleen:OnPath ("[rdfs:subClassOf]+" fma:Portion_of_blood). }
    	GRAPH <http://sig.biostr.washington.edu/~detwiler/OntViews/OPB/OPB-01.owl>
    	  { ?property gleen:OnPath ("[rdfs:subClassOf]+" opb:Kinetic_property) .    
    	    ?property opb:Physical_domain_class opb:Fluid_domain .  
    	  } 
    }