sparql-examples

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

View the Project on GitHub BiGCAT-UM/sparql-examples

0

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edam: <http://edamontology.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT  distinct  ?keid ?ketitle ?id ?ncbi
WHERE {
    ?ke a aopo:KeyEvent; edam:data_1025 ?object; dc:title ?ketitle; rdfs:label ?keid.
    ?object skos:exactMatch ?id.
    ?id a edam:data_1027; edam:data_1027 ?ncbi.
}

1

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edam: <http://edamontology.org/>
PREFIX pato: <http://purl.obolibrary.org/obo/PATO_>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT  distinct  ?keid ?ketitle ?objectname ?uniprot ?prot
WHERE {
    ?aop a aopo:AdverseOutcomePathway ;
        rdfs:label ?aop_id;
        aopo:has_key_event ?ke.
    ?ke pato:0001241 ?object; dc:title ?ketitle; rdfs:label ?keid.
    ?object dc:title ?objectname; skos:exactMatch ?prot.
    ?prot a edam:data_2291; edam:data_2291 ?uniprot.
}

2

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?AOP ?AOPName
WHERE {
 ?AOP a aopo:AdverseOutcomePathway ;
 dc:title ?AOPName . 
}

3

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edam: <http://edamontology.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT  distinct  ?keid ?ketitle ?hgnc
WHERE {
    ?ke a aopo:KeyEvent; edam:data_1025 ?object; dc:title ?ketitle; rdfs:label ?keid.
    ?object edam:data_2298 ?hgnc.
}

4

[fill out comment here]

Use at

PREFIX cheminf: <http://semanticscience.org/resource/CHEMINF_>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?CAS ?ChemicalName
WHERE {
 ?cas a cheminf:000000 ;
 dc:title ?ChemicalName ;
 cheminf:000446 ?CAS . 
}

5

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edam: <http://edamontology.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT  distinct  ?keid ?ketitle ?id ?ensembl
WHERE {
    ?ke a aopo:KeyEvent; edam:data_1025 ?object; dc:title ?ketitle; rdfs:label ?keid.
    ?object skos:exactMatch ?id.
    ?id a edam:data_2291; edam:data_2291 ?ensembl.
}

6

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edam: <http://edamontology.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT  distinct  ?keid ?ketitle ?id ?ensembl
WHERE {
    ?ke a aopo:KeyEvent; edam:data_1025 ?object; dc:title ?ketitle; rdfs:label ?keid.
    ?object skos:exactMatch ?id.
    ?id a edam:data_1033; edam:data_1033 ?ensembl.
}

7

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edam: <http://edamontology.org/>
PREFIX pato: <http://purl.obolibrary.org/obo/PATO_>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT  distinct  ?keid ?ketitle ?objectname ?prot
WHERE {
    ?aop a aopo:AdverseOutcomePathway ;
        rdfs:label ?aop_id;
        aopo:has_key_event ?ke.
    ?ke pato:0001241 ?object; dc:title ?ketitle; rdfs:label ?keid.
    ?object dc:title ?objectname; skos:exactMatch ?prot.
    ?prot a edam:data_1027.
}

8

[fill out comment here]

Use at

select (COUNT(?p) as ?Predicates)  where {?s ?p ?o. FILTER regex(?p, "http://aopkb.org/aop_ontology#")}

9

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX nci: <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#>
SELECT ?AO ?AOname ?AOP (CONCAT('"',GROUP_CONCAT(?ChemicalName;SEPARATOR='","'),'"') AS ?ChemicalNames) WHERE {
  ?AO a aopo:KeyEvent ; 
  dc:identifier ?AOLookup ; 
  dc:title ?AOname . 
  ?AOP a aopo:AdverseOutcomePathway ; 
  aopo:has_adverse_outcome ?AOLookup ;
  nci:C54571 ?Stressor .
  ?Stressor dc:title ?StressorName.
  OPTIONAL {?Stressor aopo:has_chemical_entity ?Chemical. 
            ?Chemical dc:title ?ChemicalName.}
  FILTER regex (?AOname, "fibrosis", "i")}
  GROUP BY ?AO ?AOname ?AOP
  ORDER BY DESC (?AO)

10

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX mmo: <http://purl.obolibrary.org/obo/MMO_>
PREFIX ncbitaxon: <http://purl.bioontology.org/ontology/NCBITAXON/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT  DISTINCT ?aop ?ke (group_concat(distinct ?speciesname;separator=" | ") as ?speciesnames) ?method
WHERE {
    ?aop a aopo:AdverseOutcomePathway ;
        rdfs:label ?aop_id;
        aopo:has_key_event ?ke.
    ?ke ncbitaxon:131567 ?taxon.
    ?taxon a ncbitaxon:131567; dc:title ?speciesname
    OPTIONAL {?ke mmo:0000000 ?method.}
VALUES ?aop_id {"AOP 12" "AOP 57"}
} 
GROUP BY ?aop ?ke ?method
ORDER BY ASC (?aop)

11

[fill out comment here]

Use at

select (COUNT(?o) as ?Objects)  where {?s ?p ?o. FILTER regex(?o, "http://aopkb.org/aop_ontology#")}

12

[fill out comment here]

Use at

PREFIX aop.events: <https://identifiers.org/aop.events/>
PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?AOP ?AOPTitle WHERE { 
  ?AOP a aopo:AdverseOutcomePathway ; 
  dc:title ?AOPTitle ;
  aopo:has_adverse_outcome aop.events:1276.}

13

[fill out comment here]

Use at

PREFIX aop.events: <https://identifiers.org/aop.events/>
PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?MIEwebpage ?MolecularInitiatingEventName ?AOwebpage  ?AdverseOutcomeName WHERE { 
  ?MIEwebpage dc:identifier ?MIELookup ; 
  dc:title ?MolecularInitiatingEventName . 
  ?AOPwebpage a aopo:AdverseOutcomePathway ; 
  aopo:has_molecular_initiating_event ?MIELookup; 
  aopo:has_adverse_outcome ?AOwebpage. 
  ?AOwebpage dc:title ?AdverseOutcomeName .
  FILTER (?MIEwebpage = aop.events:18)}

14

[fill out comment here]

Use at

select (COUNT(distinct *) as ?Triples)  where {?s ?p ?o}

15

[fill out comment here]

Use at

PREFIX pav: <http://purl.org/pav/>
PREFIX void: <http://rdfs.org/ns/void#>
SELECT DISTINCT ?dataset ?date
WHERE {
   ?dataset a void:Dataset ;
   pav:createdOn ?date .
 }

16

[fill out comment here]

Use at

select (COUNT(?p) as ?Predicates)  where {?s ?p ?o. FILTER regex(?p, "http://aopkb.org/aop_ontology#")}

17

[fill out comment here]

Use at

select (COUNT(?o) as ?Objects)  where {?s ?p ?o. FILTER regex(?o, "http://aopkb.org/aop_ontology#")}

18

[fill out comment here]

Use at

PREFIX aopo: <http://aopkb.org/aop_ontology#>
PREFIX cheminf: <http://semanticscience.org/resource/CHEMINF_>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX nci: <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#>
SELECT ?aop ?aoptitle ?CASID ?chemicalname
WHERE{
?aop a aopo:AdverseOutcomePathway; nci:C54571 ?Stressor; dc:title ?aoptitle.
?Stressor aopo:has_chemical_entity ?Chemical.
?Chemical cheminf:000446 ?CASID ; dc:title ?chemicalname.
}

19

[fill out comment here]

Use at

PREFIX cheminf: <http://semanticscience.org/resource/CHEMINF_>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?CAS ?ChemicalName ?MatchingIDs
WHERE {
 ?CAS a cheminf:000000 ;
 dc:title ?ChemicalName ;
 cheminf:000446 ?CAS  ;
  skos:exactMatch ?MatchingIDs .   
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?id"):::projected 
  v1("?ke")
  v4("?keid"):::projected 
  v3("?ketitle"):::projected 
  v6("?ncbi"):::projected 
  v2("?object")
  c2(["aopo:KeyEvent"]):::iri 
  c7(["edam:data_1027"]):::iri 
  v1 --"a"-->  c2
  v1 --"edam:data_1025"-->  v2
  v1 --"dc:title"-->  v3
  v1 --"rdfs:label"-->  v4
  v2 --"skos:exactMatch"-->  v5
  v5 --"a"-->  c7
  v5 -->c7--> v6
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?aop")
  v2("?aop_id")
  v3("?ke")
  v6("?keid"):::projected 
  v5("?ketitle"):::projected 
  v4("?object")
  v7("?objectname"):::projected 
  v8("?prot"):::projected 
  v9("?uniprot"):::projected 
  c8(["edam:data_2291"]):::iri 
  c2(["aopo:AdverseOutcomePathway"]):::iri 
  v1 --"a"-->  c2
  v1 --"rdfs:label"-->  v2
  v1 --"aopo:has_key_event"-->  v3
  v3 --"pato:0001241"-->  v4
  v3 --"dc:title"-->  v5
  v3 --"rdfs:label"-->  v6
  v4 --"dc:title"-->  v7
  v4 --"skos:exactMatch"-->  v8
  v8 --"a"-->  c8
  v8 -->c8--> v9
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?AOP"):::projected 
  v2("?AOPName"):::projected 
  c2(["aopo:AdverseOutcomePathway"]):::iri 
  v1 --"a"-->  c2
  v1 --"dc:title"-->  v2
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?hgnc"):::projected 
  v1("?ke")
  v4("?keid"):::projected 
  v3("?ketitle"):::projected 
  v2("?object")
  c2(["aopo:KeyEvent"]):::iri 
  v1 --"a"-->  c2
  v1 --"edam:data_1025"-->  v2
  v1 --"dc:title"-->  v3
  v1 --"rdfs:label"-->  v4
  v2 --"edam:data_2298"-->  v5
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?CAS"):::projected 
  v2("?ChemicalName"):::projected 
  v1("?cas")
  c2(["cheminf:000000"]):::iri 
  v1 --"a"-->  c2
  v1 --"dc:title"-->  v2
  v1 --"cheminf:000446"-->  v3
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?ensembl"):::projected 
  v5("?id"):::projected 
  v1("?ke")
  v4("?keid"):::projected 
  v3("?ketitle"):::projected 
  v2("?object")
  c2(["aopo:KeyEvent"]):::iri 
  c7(["edam:data_2291"]):::iri 
  v1 --"a"-->  c2
  v1 --"edam:data_1025"-->  v2
  v1 --"dc:title"-->  v3
  v1 --"rdfs:label"-->  v4
  v2 --"skos:exactMatch"-->  v5
  v5 --"a"-->  c7
  v5 -->c7--> v6
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?ensembl"):::projected 
  v5("?id"):::projected 
  v1("?ke")
  v4("?keid"):::projected 
  v3("?ketitle"):::projected 
  v2("?object")
  c7(["edam:data_1033"]):::iri 
  c2(["aopo:KeyEvent"]):::iri 
  v1 --"a"-->  c2
  v1 --"edam:data_1025"-->  v2
  v1 --"dc:title"-->  v3
  v1 --"rdfs:label"-->  v4
  v2 --"skos:exactMatch"-->  v5
  v5 --"a"-->  c7
  v5 -->c7--> v6
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?aop")
  v2("?aop_id")
  v3("?ke")
  v6("?keid"):::projected 
  v5("?ketitle"):::projected 
  v4("?object")
  v7("?objectname"):::projected 
  v8("?prot"):::projected 
  c8(["edam:data_1027"]):::iri 
  c2(["aopo:AdverseOutcomePathway"]):::iri 
  v1 --"a"-->  c2
  v1 --"rdfs:label"-->  v2
  v1 --"aopo:has_key_event"-->  v3
  v3 --"pato:0001241"-->  v4
  v3 --"dc:title"-->  v5
  v3 --"rdfs:label"-->  v6
  v4 --"dc:title"-->  v7
  v4 --"skos:exactMatch"-->  v8
  v8 --"a"-->  c8
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?Predicates")
  v3("?o")
  v1("?p"):::projected 
  v2("?s")
  f0[["regex(?p,'http://aopkb.org/aop_ontology#')"]]
  f0 --> v1
  v2 -->v1--> v3
  bind2[/"count(?p)"/]
  v1 --o bind2
  bind2 --as--o v4
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?AO"):::projected 
  v3("?AOLookup")
  v4("?AOP"):::projected 
  v2("?AOname"):::projected 
  v7("?Chemical")
  v8("?ChemicalName")
  v9("?ChemicalNames")
  v5("?Stressor")
  v6("?StressorName")
  c4(["aopo:KeyEvent"]):::iri 
  c7(["aopo:AdverseOutcomePathway"]):::iri 
  f0[["regex(?AOname,'fibrosis','i')"]]
  f0 --> v2
  v1 --"a"-->  c4
  v1 --"dc:identifier"-->  v3
  v1 --"dc:title"-->  v2
  v4 --"a"-->  c7
  v4 --"aopo:has_adverse_outcome"-->  v3
  v4 --"nci:C54571"-->  v5
  v5 --"dc:title"-->  v6
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v5 -."aopo:has_chemical_entity".->  v7
    v7 --"dc:title"-->  v8
  end
  bind2[/"concat('"',,'"')"/]
  null --o bind2
  bind2 --as--o v9
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?aop"):::projected 
  v7("?aop_id")
  v3("?ke"):::projected 
  v6("?method"):::projected 
  v5("?speciesname"):::projected 
  v7("?speciesnames")
  v4("?taxon")
  c5(["ncbitaxon:131567"]):::iri 
  c2(["aopo:AdverseOutcomePathway"]):::iri 
  v1 --"a"-->  c2
  v1 --"rdfs:label"-->  v7
  v1 --"aopo:has_key_event"-->  v3
  v3 -->c5--> v4
  v4 --"a"-->  c5
  v4 --"dc:title"-->  v5
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v3 -."mmo:0000000".->  v6
  end
  bind0[/VALUES ?aop_id/]
  bind0-->v7
  bind00(["AOP 12"])
  bind00 --> bind0
  bind01(["AOP 57"])
  bind01 --> bind0
  bind2[/"?speciesname"/]
  v5 --o bind2
  bind2 --as--o v7
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?Objects")
  v1("?o"):::projected 
  v3("?p")
  v2("?s")
  f0[["regex(?o,'http://aopkb.org/aop_ontology#')"]]
  f0 --> v1
  v2 -->v3--> v1
  bind2[/"count(?o)"/]
  v1 --o bind2
  bind2 --as--o v4
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?AOP"):::projected 
  v2("?AOPTitle"):::projected 
  c5(["aop.events:1276"]):::iri 
  c2(["aopo:AdverseOutcomePathway"]):::iri 
  v1 --"a"-->  c2
  v1 --"dc:title"-->  v2
  v1 --"aopo:has_adverse_outcome"-->  c5
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?AOPwebpage")
  v5("?AOwebpage"):::projected 
  v6("?AdverseOutcomeName"):::projected 
  v2("?MIELookup")
  v1("?MIEwebpage"):::projected 
  v3("?MolecularInitiatingEventName"):::projected 
  c5(["aopo:AdverseOutcomePathway"]):::iri 
  f0[["?MIEwebpage = 'aop.events:18'"]]
  f0 --> v1
  v1 --"dc:identifier"-->  v2
  v1 --"dc:title"-->  v3
  v4 --"a"-->  c5
  v4 --"aopo:has_molecular_initiating_event"-->  v2
  v4 --"aopo:has_adverse_outcome"-->  v5
  v5 --"dc:title"-->  v6
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?Triples")
  v3("?o")
  v2("?p")
  v1("?s")
  v1 -->v2--> v3
  bind1[/"count(*)"/]
  bind1 --as--o v4
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?dataset"):::projected 
  v2("?date"):::projected 
  c2(["void:Dataset"]):::iri 
  v1 --"a"-->  c2
  v1 --"pav:createdOn"-->  v2
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?Predicates")
  v3("?o")
  v1("?p"):::projected 
  v2("?s")
  f0[["regex(?p,'http://aopkb.org/aop_ontology#')"]]
  f0 --> v1
  v2 -->v1--> v3
  bind2[/"count(?p)"/]
  v1 --o bind2
  bind2 --as--o v4
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?Objects")
  v1("?o"):::projected 
  v3("?p")
  v2("?s")
  f0[["regex(?o,'http://aopkb.org/aop_ontology#')"]]
  f0 --> v1
  v2 -->v3--> v1
  bind2[/"count(?o)"/]
  v1 --o bind2
  bind2 --as--o v4
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?CASID"):::projected 
  v4("?Chemical")
  v2("?Stressor")
  v1("?aop"):::projected 
  v3("?aoptitle"):::projected 
  v6("?chemicalname"):::projected 
  c2(["aopo:AdverseOutcomePathway"]):::iri 
  v1 --"a"-->  c2
  v1 --"nci:C54571"-->  v2
  v1 --"dc:title"-->  v3
  v2 --"aopo:has_chemical_entity"-->  v4
  v4 --"cheminf:000446"-->  v5
  v4 --"dc:title"-->  v6
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?CAS"):::projected 
  v2("?ChemicalName"):::projected 
  v3("?MatchingIDs"):::projected 
  a1((" "))
  c2(["cheminf:000000"]):::iri 
  v1 --"a"-->  c2
  v1 --"dc:title"-->  v2
  f0[["sameterm(?CAS,)"]]
  f0 --> v1
  f0 --> a1
  v1 --"cheminf:000446"-->  a1
  v1 --"skos:exactMatch"-->  v3