sparql-examples

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

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

050

rq turtle/ttl

Chemical aspect: related chemical structures

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX target: <http://www.wikidata.org/entity/Q2270>

# title: related chemical structures
SELECT ?mol ?molLabel ?InChIKey ?CAS ?ChemSpider ?PubChem_CID WHERE {
  target: wdt:P235 ?queryKey .
  ?mol wdt:P235 ?InChIKey .
  OPTIONAL { ?mol wdt:P231 ?CAS }
  OPTIONAL { ?mol wdt:P661 ?ChemSpider }
  OPTIONAL { ?mol wdt:P662 ?PubChem_CID }
  FILTER (regex(str(?InChIKey), concat("^", substr($queryKey,1,14), "-")))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
}

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?CAS"):::projected 
  v5("?ChemSpider"):::projected 
  v1("?InChIKey"):::projected 
  v6("?PubChem_CID"):::projected 
  v3("?mol"):::projected 
  v2("?queryKey")
  c13(["#91;AUTO_LANGUAGE#93;,mul,en"]):::literal 
  c11([http://www.bigdata.com/rdf#serviceParam]):::iri 
  c5([http://www.wikidata.org/entity/Q2270]):::iri 
  f0[["regex(str(?InChIKey),concat('^',substring(?queryKey,'1^^xsd:integer','14^^xsd:integer'),'-'))"]]
  f0 --> v1
  f0 --> v2
  c5 --"p:direct/P235"-->  v2
  v3 --"p:direct/P235"-->  v1
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v3 -."p:direct/P231".->  v4
  end
  subgraph optional1["(optional)"]
  style optional1 fill:#bbf,stroke-dasharray: 5 5;
    v3 -."p:direct/P661".->  v5
  end
  subgraph optional2["(optional)"]
  style optional2 fill:#bbf,stroke-dasharray: 5 5;
    v3 -."p:direct/P662".->  v6
  end
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c11 --"wikibase:language"-->  c13
  end