about summary refs log tree commit diff
path: root/gn/db/sources/wikidata.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gn/db/sources/wikidata.scm')
-rw-r--r--gn/db/sources/wikidata.scm49
1 files changed, 42 insertions, 7 deletions
diff --git a/gn/db/sources/wikidata.scm b/gn/db/sources/wikidata.scm
index 7397426..fe495c5 100644
--- a/gn/db/sources/wikidata.scm
+++ b/gn/db/sources/wikidata.scm
@@ -1,10 +1,38 @@
 #!
 
-Wikidata queries
+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")
@@ -14,16 +42,23 @@ Wikidata queries
 (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)
-  "Return the wikidata identifiers pointing to genes of listed species"
+(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 .
-        }
-"
-              ))
+              ?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\").}"))