sparql-examples

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

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

examples015

List metabolites of plants that interact with plant parasite moth Orgyia postica (wd:Q7102162) .

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 ?intxnLabel ?targetWD ?targetNameURI ?ik ?wd_chem
                WHERE {   
                	{SELECT DISTINCT ?sourceWD ?sourceName ?intxnName ?intxnLabel ?targetWD ?targetName WHERE {
                		
                		?intxn emi:hasSource ?source ;					#retrieve interaction-pairs
                		       emi:hasTarget ?target ;
                                       emi:isClassifiedWith ?intxnName .	
                            	?target emi:inTaxon ?targetWD ;					#retrieve wikidata-id for target plant 
					sosa:isSampleOf ?targetName .
				?source emi:inTaxon ?sourceWD ;					#retrieve wikidata-id for source parasite
					sosa:isSampleOf ?sourceName .
				?intxnName rdfs:label ?intxnLabel
                            	VALUES ?sourceWD { wd:Q7102162 }				#retain results only if the source-WD matches the wikidata-id of Orgyia postica
                        }
                      }   
                      { SELECT DISTINCT ?targetWD ?ik ?wd_chem WHERE {
                      		?material sosa:hasSample ?extract ;
                      		          sosa:isSampleOf ?organe .
                      		?organe emi:inTaxon ?targetWD .					#filter metabolite data which is found in wikidata-ids targetWD
                      		?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 wikidata-ids for metabolites
                      }} UNION									#union with data from lotus (integrated in wikidata)
		      { SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
		      		?wd_chem wdt:P235 ?ik ;
					 wdt:P703 ?targetWD .			
		      }}
		      BIND(REPLACE(STR(?sourceName), "%20", " ") AS ?sourceNameX)		#remove percent encodings from the sourceName
		      BIND(IRI(?sourceNameX) AS ?sourceNameURI)
		      BIND(REPLACE(STR(?targetName), "%20", " ") AS ?targetNameX)		#remove percent encodings from the targetName
		      BIND(IRI(?targetNameX) AS ?targetNameURI)
                }  

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v11("?extract")
  v15("?feature")
  v14("?feature_list")
  v19("?ik"):::projected 
  v17("?ik2d")
  v1("?intxn")
  v9("?intxnLabel"):::projected 
  v4("?intxnName"):::projected 
  v13("?lcms")
  v10("?material")
  v12("?organe")
  v16("?sirius_annotation")
  v18("?smiles")
  v2("?source")
  v8("?sourceName")
  v22("?sourceNameURI"):::projected 
  v21("?sourceNameX")
  v10("?sourceWD"):::projected 
  v3("?target")
  v6("?targetName")
  v24("?targetNameURI"):::projected 
  v23("?targetNameX")
  v5("?targetWD"):::projected 
  v20("?wd_chem"):::projected 
  c13(["emi:StructuralAnnotation"]):::iri 
  v1 --"emi:hasSource"-->  v2
  v1 --"emi:hasTarget"-->  v3
  v1 --"emi:isClassifiedWith"-->  v4
  v3 --"emi:inTaxon"-->  v5
  v3 --"sosa:isSampleOf"-->  v6
  v2 --"emi:inTaxon"-->  v10
  v2 --"sosa:isSampleOf"-->  v8
  v4 --"rdfs:label"-->  v9
  bind0[/VALUES ?sourceWD/]
  bind0-->v10
  bind00(["wd:Q7102162"])
  bind00 --> bind0
  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;
      v20 --"wdt:P235"-->  v19
      v20 --"wdt:P703"-->  v5
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v10 --"sosa:hasSample"-->  v11
    v10 --"sosa:isSampleOf"-->  v12
    v12 --"emi:inTaxon"-->  v5
    v11 --"sosa:isFeatureOfInterestOf"-->  v13
    v13 --"sosa:hasResult"-->  v14
    v14 --"emi:hasLCMSFeature"-->  v15
    v15 --"emi:hasAnnotation"-->  v16
    v16 --"a"-->  c13
    v16 --"emi:hasChemicalStructure"-->  v17
    v17 --"emi:hasSMILES"-->  v18
    v17 --"emi:isInChIKey2DOf"-->  v19
    v19 --"emi:isInChIKeyOf"-->  v20
  end
  union0r <== or ==> union0l
  end
  bind1[/"replace(str(?sourceName),'%20',' ')"/]
  v8 --o bind1
  bind1 --as--o v21
  bind2[/"?sourceNameX"/]
  v21 --o bind2
  bind2 --as--o v22
  bind3[/"replace(str(?targetName),'%20',' ')"/]
  v6 --o bind3
  bind3 --as--o v23
  bind4[/"?targetNameX"/]
  v23 --o bind4
  bind4 --as--o v24