sparql-examples

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

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

examples016

rq turtle/ttl

List of possible natural locations of plants, which produce senkyunolide (wd:Q27251426) which is a thalide for cerebral disorders (https://doi.org/10.3390/molecules28083636).

Use at

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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 wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX prov: <http://www.w3.org/ns/prov#>
SELECT DISTINCT ?organismName ?organismWD ?loc ?lats ?longs WHERE {
	# metabolite data
	{
		SELECT DISTINCT ?organismWD ?organismName WHERE {
			?material sosa:hasSample ?extract ;
		        	sosa:isSampleOf ?organe .
			?organe emi:inTaxon ?organismWD ; # filter metabolite data which is found in wikidata-ids wdx	
				rdfs:label ?organismName .
			?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
			VALUES ?wd_chem { wd:Q27251426 } # filter wikidata_id of metabolites matches wd:Q27251426
		}
	} 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 ?organismWD .
			 VALUES ?wd_chem { wd:Q27251426 }
			 FILTER(?organismWD = ?source_wdx || ?organismWD = ?target_wdx)	# ensure that organism-wd is either from source or target
			 OPTIONAL { ?organismWD wdt:P225 ?organismName . }
		}
	}
	# interaction data			
	?intxn emi:hasSource ?source ; # retrieve interaction-pairs
		emi:hasTarget ?target .
	?source emi:inTaxon ?source_wdx . # retrieve wikidata-id of source
		?target emi:inTaxon ?target_wdx . # retrieve wikidata-id of target
		?intxn prov:atLocation ?loc ; # retrieve the location of the interaction, and the latitude/longitude
			wgs:lat ?lats ;					
			wgs:long ?longs .
} LIMIT 4000
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?extract")
  v8("?feature")
  v7("?feature_list")
  v12("?ik")
  v10("?ik2d")
  v16("?intxn")
  v20("?lats"):::projected 
  v6("?lcms")
  v19("?loc"):::projected 
  v21("?longs"):::projected 
  v1("?material")
  v3("?organe")
  v5("?organismName"):::projected 
  v4("?organismWD"):::projected 
  v9("?sirius_annotation")
  v11("?smiles")
  v17("?source")
  v14("?source_wdx")
  v18("?target")
  v15("?target_wdx")
  v16("?wd_chem")
  c10(["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;
      f0[["(?organismWD = ?source_wdx || ?organismWD = ?target_wdx)"]]
      f0 --> v4
      f0 --> v14
      f0 --> v15
      v16 --"wdt:P235"-->  v12
      v16 --"wdt:P703"-->  v4
      bind1[/VALUES ?wd_chem/]
      bind1-->v16
      bind10(["wd:Q27251426"])
      bind10 --> bind1
      subgraph optional0["(optional)"]
      style optional0 fill:#bbf,stroke-dasharray: 5 5;
        v4 -."wdt:P225".->  v5
      end
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v1 --"sosa:hasSample"-->  v2
    v1 --"sosa:isSampleOf"-->  v3
    v3 --"emi:inTaxon"-->  v4
    v3 --"rdfs:label"-->  v5
    v2 --"sosa:isFeatureOfInterestOf"-->  v6
    v6 --"sosa:hasResult"-->  v7
    v7 --"emi:hasLCMSFeature"-->  v8
    v8 --"emi:hasAnnotation"-->  v9
    v9 --"a"-->  c10
    v9 --"emi:hasChemicalStructure"-->  v10
    v10 --"emi:hasSMILES"-->  v11
    v10 --"emi:isInChIKey2DOf"-->  v12
    v12 --"emi:isInChIKeyOf"-->  v16
    bind2[/VALUES ?wd_chem/]
    bind2-->v16
    bind20(["wd:Q27251426"])
    bind20 --> bind2
  end
  union0r <== or ==> union0l
  end
  v16 --"emi:hasSource"-->  v17
  v16 --"emi:hasTarget"-->  v18
  v17 --"emi:inTaxon"-->  v14
  v18 --"emi:inTaxon"-->  v15
  v16 --"prov:atLocation"-->  v19
  v16 --"wgs:lat"-->  v20
  v16 --"wgs:long"-->  v21