A set of SPARQL examples that are used in different SIB resources
The ChEBI hierarchy is not consistent between conjugate base/acid relationships this query pretends that these can be transfered as is. In the example specifically for lipids
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX CHEBI:<http://purl.obolibrary.org/obo/CHEBI_>
PREFIX chebislash: <http://purl.obolibrary.org/obo/chebi/>
PREFIX chebihash: <http://purl.obolibrary.org/obo/chebi#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT
?chebi
WHERE {
# Specifically for lipids
BIND(CHEBI:18059 AS ?chebiClass)
{
?chebi rdfs:subClassOf+ ?chebiRestriction .
?chebiRestriction a owl:Restriction .
{
?chebiRestriction owl:onProperty chebihash:is_conjugate_acid_of .
} UNION {
?chebiRestriction owl:onProperty chebihash:is_conjugate_base_of .
}
?chebiRestriction owl:someValuesFrom ?chebiRelationTarget .
?chebiRelationTarget rdfs:subClassOf+ ?chebiClass .
FILTER(NOT EXISTS{
# Zwiterions should b excluded from being considered for transfering the hierarchy
?chebi rdfs:subClassOf CHEBI:27369 .
})
# If the charge is zero then don't expand the hierarchy.
OPTIONAL {
?chebi chebislash:charge "0" .
BIND(true AS ?chebiChargeZero)
}
FILTER(!BOUND(?chebiChargeZero))
} UNION {
#Also look directly in the upper classes to follow the normal hierarchy path.
?chebi rdfs:subClassOf+ ?chebiClass .
}
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?chebi"):::projected
v6("?chebiChargeZero")
v1("?chebiClass")
v5("?chebiRelationTarget")
v4("?chebiRestriction")
c10(["0"]):::literal
c4(["owl:Restriction"]):::iri
c2(["CHEBI:27369"]):::iri
c7(["chebihash:is_conjugate_base_of"]):::iri
c6(["chebihash:is_conjugate_acid_of"]):::iri
bind0[/"'CHEBI:18059'"/]
bind0 --as--o v1
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v3 --"rdfs:subClassOf"--> v1
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
f1[["not bound(?chebiChargeZero)"]]
f1 --> v6
f2[["not "]]
subgraph f2e0["Exists Clause"]
e0v1 --"rdfs:subClassOf"--> e0c2
e0v1("?chebi"):::projected
e0c2(["CHEBI:27369"]):::iri
end
f2--EXISTS--> f2e0
f2 --> v3
f2 --> c1
f2 --> c2
v3 --"rdfs:subClassOf"--> c2
v3 --"rdfs:subClassOf"--> v4
v4 --"a"--> c4
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v4 --"owl:onProperty"--> c7
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v4 --"owl:onProperty"--> c6
end
union1r <== or ==> union1l
end
v4 --"owl:someValuesFrom"--> v5
v5 --"rdfs:subClassOf"--> v1
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."chebislash:charge".-> c10
bind3[/"'true^^xsd:boolean'"/]
bind3 --as--o v6
end
end
union0r <== or ==> union0l
end