#! Wikidata queries, initially lifted over from the gn3 gene-alias code (that was written in Racket). Note you can take a SPARQL query and push it into https://query.wikidata.org/. E.g. generate a query and copy paste into the query service: scheme@(guile-user) [3]> (display (wikidata-query-geneids "Shh")) ``` SELECT DISTINCT ?wikidata_id WHERE { ?wikidata_id wdt:P31 wd:Q7187; wdt:P703 ?species . VALUES (?species) { (wd:Q15978631 ) ( wd:Q83310 ) ( wd:Q184224 ) } . ?wikidata_id rdfs:label "Shh"@en . } ``` It is possible to run queries through curl with ``` curl -G https://query.wikidata.org/sparql -H "Accept: application/json; charset=utf-8" --data-urlencode query=" SELECT DISTINCT ?alias WHERE { wd:Q24420953 rdfs:label ?name ; skos:altLabel ?alias . FILTER(LANG(?name) = \"en\" && LANG(?alias) = \"en\"). }" ``` !# (define-module (gn db sources wikidata) #:export (wikidata-query-geneids wikidata-query-gene-aliases ) ) (define ps-encoded-by "ps:P702") (define wdt-instance-of "wdt:P31") (define wdt-in-taxon "wdt:P703") (define wd-human "wd:Q15978631") (define wd-mouse "wd:Q83310") (define wd-rat "wd:Q184224") (define wd-gene "wd:Q7187") (define wd-shh-rat "wd:Q24420953") (define (wikidata-query-geneids gene_name) "SPARQL query to get the wikidata identifiers pointing to genes of listed species, e.g. 'Shh'" (string-append "SELECT DISTINCT ?wikidata_id WHERE { ?wikidata_id " wdt-instance-of " " wd-gene "; " wdt-in-taxon " ?species . VALUES (?species) { (" wd-human " ) ( " wd-mouse" ) ( " wd-rat" ) } . ?wikidata_id rdfs:label \"" gene_name "\"@en .}")) (define (wikidata-query-gene-aliases wikidata_id) "SPARQL query to get a list of gene aliases based on a wikidata identifier, e.g. for Q24420953" (string-append "SELECT DISTINCT ?alias WHERE { wd:" wikidata_id " rdfs:label ?name ; skos:altLabel ?alias . FILTER(LANG(?name) = \"en\" && LANG(?alias) = \"en\").}"))