sparql-examples

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

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

examples018

List possible interactions of plants that can produce asimcin (wd:Q100138042), a cytotoxin.

Use at


		PREFIX wd: <http://www.wikidata.org/entity/>
                PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                PREFIX enpkg: <https://enpkg.commons-lab.org/kg/>
                PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                PREFIX wdt: <http://www.wikidata.org/prop/direct/>
                PREFIX emi: <https://purl.org/emi#>
                PREFIX sosa: <http://www.w3.org/ns/sosa/>
                PREFIX dcterms: <http://purl.org/dc/terms/>
                PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
                PREFIX prov: <http://www.w3.org/ns/prov#>
               
		SELECT DISTINCT ?sourceWD ?sourceNameURI ?intxnName ?targetWD ?targetNameURI WHERE {
		{ SELECT DISTINCT ?wd_chem WHERE {				#retrieve metabolite data for sourceWD
			?material sosa:hasSample ?extract ;
				  sosa:isSampleOf ?organe .
			?organe emi:inTaxon ?sourceWD .
                        ?extract sosa:isFeatureOfInterestOf ?lcms .
                        ?lcms sosa:hasResult ?feature_list .
                        ?feature_list emi:hasLCMSFeature ?feature .
                        ?feature emi:hasAnnotation ?sirius_annotation .
                        ?sirius_annotation a emi:StructuralAnnotation ;
                                emi:hasChemicalStructure ?ik2d .
                        ?ik2d emi:hasSMILES ?smiles ;
			      emi:isInChIKey2DOf ?ik .
                        ?ik emi:isInChIKeyOf ?wd_chem .				#retrieve wikidats-ids for metabolites
                        VALUES ?wd_chem { wd:Q100138042 }			#filter on wikidata-id of asimicin
                   }} UNION							#union with results from lotus (integrated in wikidata)
		   { SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
			?wd_chem wdt:P235 ?ik ;
				 wdt:P703 ?sourceWD .
			VALUES ?wd_chem { wd:Q100138042 }
		   }}
		   
                   ?intxn emi:hasSource ?xOrg ;					#retrieve interaction-pairs
                          emi:hasTarget ?yOrg ;
                          emi:isClassifiedWith ?intxnName .
                   ?xOrg emi:inTaxon ?sourceWD ;				#retrieve wikidata-id of the interaction-source
			 sosa:isSampleOf ?sourceName .				#retrieve its scientific name as listed in GloBI
		   ?yOrg emi:inTaxon ?targetWD ;				#retrieve wikidata-id of the interaction-target
			 sosa:isSampleOf ?targetName .				#retrieve its scientific names as listed in GloBI
		   BIND(REPLACE(STR(?sourceName), "%20", " ") AS ?sourceNameX)  #remove percent encodings from source and target names
		   BIND(IRI(?sourceNameX) AS ?sourceNameURI)
		   BIND(REPLACE(STR(?targetName), "%20", " ") AS ?targetNameX)
		   BIND(IRI(?targetNameX) AS ?targetNameURI)   
                } LIMIT 1000

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?extract")
  v7("?feature")
  v6("?feature_list")
  v11("?ik")
  v9("?ik2d")
  v13("?intxn")
  v16("?intxnName"):::projected 
  v5("?lcms")
  v1("?material")
  v3("?organe")
  v8("?sirius_annotation")
  v10("?smiles")
  v17("?sourceName")
  v21("?sourceNameURI"):::projected 
  v20("?sourceNameX")
  v4("?sourceWD"):::projected 
  v19("?targetName")
  v23("?targetNameURI"):::projected 
  v22("?targetNameX")
  v18("?targetWD"):::projected 
  v13("?wd_chem")
  v14("?xOrg")
  v15("?yOrg")
  c9(["emi:StructuralAnnotation"]):::iri 
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    subgraph s1["https://qlever.cs.uni-freiburg.de/api/wikidata"]
      style s1 stroke-width:4px;
      v13 --"wdt:P235"-->  v11
      v13 --"wdt:P703"-->  v4
      bind0[/VALUES ?wd_chem/]
      bind0-->v13
      bind00(["wd:Q100138042"])
      bind00 --> bind0
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v1 --"sosa:hasSample"-->  v2
    v1 --"sosa:isSampleOf"-->  v3
    v3 --"emi:inTaxon"-->  v4
    v2 --"sosa:isFeatureOfInterestOf"-->  v5
    v5 --"sosa:hasResult"-->  v6
    v6 --"emi:hasLCMSFeature"-->  v7
    v7 --"emi:hasAnnotation"-->  v8
    v8 --"a"-->  c9
    v8 --"emi:hasChemicalStructure"-->  v9
    v9 --"emi:hasSMILES"-->  v10
    v9 --"emi:isInChIKey2DOf"-->  v11
    v11 --"emi:isInChIKeyOf"-->  v13
    bind1[/VALUES ?wd_chem/]
    bind1-->v13
    bind10(["wd:Q100138042"])
    bind10 --> bind1
  end
  union0r <== or ==> union0l
  end
  v13 --"emi:hasSource"-->  v14
  v13 --"emi:hasTarget"-->  v15
  v13 --"emi:isClassifiedWith"-->  v16
  v14 --"emi:inTaxon"-->  v4
  v14 --"sosa:isSampleOf"-->  v17
  v15 --"emi:inTaxon"-->  v18
  v15 --"sosa:isSampleOf"-->  v19
  bind2[/"replace(str(?sourceName),'%20',' ')"/]
  v17 --o bind2
  bind2 --as--o v20
  bind3[/"?sourceNameX"/]
  v20 --o bind3
  bind3 --as--o v21
  bind4[/"replace(str(?targetName),'%20',' ')"/]
  v19 --o bind4
  bind4 --as--o v22
  bind5[/"?targetNameX"/]
  v22 --o bind5
  bind5 --as--o v23