sparql-examples

A set of SPARQL examples that are used in different SIB resources

View the Project on GitHub sib-swiss/sparql-examples

45

Retrieve drugs that target human enzymes involved in sterol metabolism (federated query with WikiData and Rhea).

Use at

PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_>
PREFIX chebihash: <http://purl.obolibrary.org/obo/chebi#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
PREFIX uniprotkb: <http://purl.uniprot.org/uniprot/>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?protein ?proteinFullName ?wikiChemical ?wikiChemicalLabel ?medicalConditionTreatedLabel
WHERE {
  # ChEBI: retrieve members of the ChEBI class ChEBI:15889 (sterol)
  # Rhea: retrieve the reactions involving these ChEBI as participants
  SERVICE <https://sparql.rhea-db.org/sparql> {
    ?reaction rdfs:subClassOf rh:Reaction ;
      rh:status rh:Approved ;
      rh:side ?reactionSide .
    ?reactionSide
      rh:contains ?participant .
    ?participant rh:compound ?compound
    {
      ?compound rh:chebi ?chebi .
      ?chebi (rdfs:subClassOf)+ CHEBI:15889
    } UNION {
      ?compound rh:chebi ?chebi .
      ?chebi2 rdfs:subClassOf ?chebiRestriction .
      ?chebiRestriction
		a owl:Restriction ;
		owl:onProperty chebihash:has_major_microspecies_at_pH_7_3 ;
		owl:someValuesFrom ?chebi .
      ?chebi2 (rdfs:subClassOf)+ CHEBI:15889
    }
  }
  # UniProt: retrieve the human (taxid:9606) enzymes catalyzing these Rhea reactions
  ?ca up:catalyzedReaction  ?reaction .
  ?a up:catalyticActivity  ?ca .
  ?proteinIRI  up:annotation ?a ;
    up:organism taxon:9606 ;
    up:recommendedName ?proteinRecName .
  ?proteinRecName up:fullName ?proteinFullName .
  # Find drugs in wikidata that interact with the UniProt Proteins
  BIND (SUBSTR(STR(?proteinIRI), STRLEN(STR(uniprotkb:))+1) AS ?protein)
  SERVICE <https://query.wikidata.org/sparql> {
    ?wp wdt:P352  ?protein .
    ?wikiChemical wdt:P129 ?wp . # Physically interacts with
    ?wikiChemical rdfs:label ?wikiChemicalLabel .
    ?wikiChemical wdt:P2175 ?wmc . # Medical conndition treated
    ?wmc rdfs:label ?medicalConditionTreatedLabel .
    FILTER(lang(?medicalConditionTreatedLabel) = 'en')
    FILTER(lang(?wikiChemicalLabel) = 'en')
  }
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v9("?a")
  v8("?ca")
  v5("?chebi")
  v6("?chebi2")
  v7("?chebiRestriction")
  v4("?compound")
  v15("?medicalConditionTreatedLabel"):::projected 
  v3("?participant")
  v13("?protein"):::projected 
  v12("?proteinFullName"):::projected 
  v10("?proteinIRI")
  v11("?proteinRecName")
  v1("?reaction")
  v2("?reactionSide")
  v17("?wikiChemical"):::projected 
  v14("?wikiChemicalLabel"):::projected 
  v18("?wmc")
  v16("?wp")
  c5(["rh:Approved"]):::iri 
  c10(["CHEBI:15889"]):::iri 
  c12(["owl:Restriction"]):::iri 
  c14(["chebihash:has_major_microspecies_at_pH_7_3"]):::iri 
  c3(["rh:Reaction"]):::iri 
  c20(["taxon:9606"]):::iri 
  subgraph s1["https://sparql.rhea-db.org/sparql"]
    style s1 stroke-width:4px;
    v1 --"rdfs:subClassOf"-->  c3
    v1 --"rh:status"-->  c5
    v1 --"rh:side"-->  v2
    v2 --"rh:contains"-->  v3
    v3 --"rh:compound"-->  v4
    subgraph union0[" Union "]
    subgraph union0l[" "]
      style union0l fill:#abf,stroke-dasharray: 3 3;
      v4 --"rh:chebi"-->  v5
      v6 --"rdfs:subClassOf"-->  v7
      v7 --"a"-->  c12
      v7 --"owl:onProperty"-->  c14
      v7 --"owl:someValuesFrom"-->  v5
      v6 --"rdfs:subClassOf"-->  c10
    end
    subgraph union0r[" "]
      style union0r fill:#abf,stroke-dasharray: 3 3;
      v4 --"rh:chebi"-->  v5
      v5 --"rdfs:subClassOf"-->  c10
    end
    union0r <== or ==> union0l
    end
  end
  v8 --"up:catalyzedReaction"-->  v1
  v9 --"up:catalyticActivity"-->  v8
  v10 --"up:annotation"-->  v9
  v10 --"up:organism"-->  c20
  v10 --"up:recommendedName"-->  v11
  v11 --"up:fullName"-->  v12
  bind0[/"substring(str(?proteinIRI),string-length(str('uniprotkb:')) + '+1^^xsd:integer')"/]
  v10 --o bind0
  bind0 --as--o v13
  subgraph s2["https://query.wikidata.org/sparql"]
    style s2 stroke-width:4px;
    f1[["?wikiChemicalLabel = 'en'"]]
    f1 --> v14
    f2[["?medicalConditionTreatedLabel = 'en'"]]
    f2 --> v15
    v16 --"wdt:P352"-->  v13
    v17 --"wdt:P129"-->  v16
    v17 --"rdfs:label"-->  v14
    v17 --"wdt:P2175"-->  v18
    v18 --"rdfs:label"-->  v15
  end