Skip to content

Instantly share code, notes, and snippets.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX prv: <http://www.wikidata.org/prop/reference/value/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
<wikidata-human_gene> {
PREFIX : <http://hl7.org/fhir/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
<Obs1>
:status "final" ;
:subject <Patient2> .
<Patient2>
:name "Bob" ;
:birthdate "1999-12-31"^^xsd:date .
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX prv: <http://www.wikidata.org/prop/reference/value/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
<subject> <predicate> <object> .
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT DISTINCT ?metabolite1Label ?mass1 ?mass2 ?metabolite2Label WHERE {
?metabolite2 wdt:P2067 ?mass2 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
{SELECT * WHERE {
{SELECT * WHERE {
?metabolite1 wdt:P2067 ?mass1 .
{SELECT * WHERE {
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT DISTINCT ?metabolite1Label ?metabolite2Label ?mass1 ?mass2 WHERE {
?metabolite2 wdt:P2067 ?mass2 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
{SELECT * WHERE {
?metabolite1 wdt:P2067 ?mass1 .
{SELECT * WHERE {
?pathwayItem wdt:P2410 "WP706" ;
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
?shared_concept rdfs:label "Local description of the shared concept"@en .
SERVICE <http://remote.sparqlendpoint.org/sparql> {
?local_concept ?predicate2 ?shared_concept ;
rdfs:label "Remote description of the shared concept"@en .
}
}
@andrawaag
andrawaag / WDQSRExample.R
Created May 25, 2017 06:56
R script that uses the WikidataQueryServiceR library. It scrapes the example from the Wikidata example page https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples. See line 4 on how
library(WikidataQueryServiceR)
library(rvest)
library(urltools)
sparql_query <- scrape_example(c("Variant counts by predictor type"))
results <- query_wikidata(sparql_query)
barplot(results$counts, main="Variant counts by predictor type",
las=2, names.arg=results$propertyLabel)
#QUERY <http://sparql.wikipathways.org>
# Author: Andra Waagmeester
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT * WHERE {
<http://www.wikidata.org/entity/Q17861702> <http://www.wikidata.org/prop/P704> <http://www.wikidata.org/entity/statement/Q17861702-0DBED063-9218-468C-958D-77A716E869D4> .
<http://www.wikidata.org/entity/statement/Q17861702-0DBED063-9218-468C-958D-77A716E869D4> <http://www.w3.org/ns/prov#wasDerivedFrom> <http://www.wikidata.org/reference/548aa04930b65df7ca12bc71748040453baf6186> .
<http://www.wikidata.org/reference/548aa04930b65df7ca12bc71748040453baf6186> <http://www.wikidata.org/prop/reference/P594> "ENSG00000170004" .
<http://www.wikidata.org/entity/Q17861702> <http://www.wikidata.org/prop/P639> <http://www.wikidata.org/entity/statement/Q17861702-06BB1FF8-C045-4245-BE0B-B0821319686D> .
<http://www.wikidata.org/entity/statement/Q17861702-06BB1FF8-C045-4245-BE0B-B0821319686D> <http://wikiba.se/ontology#rank> <http://wikiba.se/ontology#NormalRank> .
<http://www.wikidata.org/entity/statement/Q17861702-06BB1FF8-C045-4245-BE0B-B0821319686D> <http://www.w3.org/ns/prov#wasDerivedFrom> <http://www.wikidata.