diff options
author | Pjotr Prins | 2023-08-11 10:37:05 +0200 |
---|---|---|
committer | Pjotr Prins | 2023-08-11 10:37:05 +0200 |
commit | 566537f47eff45f17e0da9c28ca965f600b6b9a9 (patch) | |
tree | 5a9297e917befabdf3dff7d22d131c461d59e1b1 /web/webserver.scm | |
parent | 4720feda6419ab3ceb6332ceb37ee214a0274e54 (diff) | |
download | gn-guile-566537f47eff45f17e0da9c28ca965f600b6b9a9.tar.gz |
Get expanded species1
Diffstat (limited to 'web/webserver.scm')
-rwxr-xr-x | web/webserver.scm | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/web/webserver.scm b/web/webserver.scm index 771bebd..7690159 100755 --- a/web/webserver.scm +++ b/web/webserver.scm @@ -144,35 +144,50 @@ ("up" . ,(mk-meta "species")) )) +(define (expand-species rec) + (let ([wd-id (url-parse-id (assoc-ref rec "22-rdf-syntax-ns#isDefinedBy"))] + [short-name (normalize-id (assoc-ref rec "name"))]) + (if (string=? wd-id "unknown") + rec + ; wikidata query: + (receive (names row) (tsv->scm (memo-sparql-wd-species-info wd-id)) + (match (pk (car row)) + ((taxonomy-name ncbi descr) + (let ([ncbi-id (strip-lang ncbi)] + [taxonomy-lnk (string-replace-substring (strip-lang taxonomy-name) " " "_")]) + (cons `("id" . ,short-name) + (cons `("wikidata" . ,wd-id) + (cons `("taxonomy-id" . ,ncbi-id) + (cons `("ncbi-url" . ,(string-append "https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=" ncbi-id)) + (cons `("uniprot-url" . ,(string-append "https://www.uniprot.org/taxonomy/" ncbi-id)) + (cons `("wikidata-url" . ,(string-append "http://www.wikidata.org/entity/" wd-id)) + (cons `("wikispecies-url" . ,(string-append "https://species.wikimedia.org/wiki/" taxonomy-lnk)) + (cons `("taxonomy-name" . ,(strip-lang taxonomy-name)) + (cons `("meta" . ,(mk-meta short-name)) + (cons `("description" . ,(strip-lang descr)) + rec)))))))))))) + ) + ))) + ) + + (define (get-expanded-species) "Here we add information related to each species" (map (lambda (rec) - (let ([wd-id (url-parse-id (assoc-ref rec "22-rdf-syntax-ns#isDefinedBy"))] - [short-name (normalize-id (assoc-ref rec "name"))]) - (if (string=? wd-id "unknown") - rec - ; wikidata query: - (receive (names row) (tsv->scm (memo-sparql-wd-species-info wd-id)) - (match (pk (car row)) - ((taxonomy-name ncbi descr) - (let ([ncbi-id (strip-lang ncbi)] - [taxonomy-lnk (string-replace-substring (strip-lang taxonomy-name) " " "_")]) - (cons `("id" . ,short-name) - (cons `("wikidata" . ,wd-id) - (cons `("taxonomy-id" . ,ncbi-id) - (cons `("ncbi-url" . ,(string-append "https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=" ncbi-id)) - (cons `("uniprot-url" . ,(string-append "https://www.uniprot.org/taxonomy/" ncbi-id)) - (cons `("wikidata-url" . ,(string-append "http://www.wikidata.org/entity/" wd-id)) - (cons `("wikispecies-url" . ,(string-append "https://species.wikimedia.org/wiki/" taxonomy-lnk)) - (cons `("taxonomy-name" . ,(strip-lang taxonomy-name)) - ; (cons `("shortname" . ,shortname) - problematic - (cons `("description" . ,(strip-lang descr)) - rec))))))))))) - ) - ))) + (expand-species rec) ) (get-species) )) +(define (get-expanded-species1 short-name) + "Here we add information related to one taxonomy species" + (call/cc (lambda (return) + (for-each (lambda (rec) + (if (string=? (assoc-ref rec "shortName") short-name) + (return (expand-species rec)))) + (get-species)) + (return #f) +))) + (define (get-species-api-str) (scm->json-string #("https://genenetwork.org/api/v2/mouse/" "https://genenetwork.org/api/v2/rat/"))) @@ -260,7 +275,8 @@ (let ([names (get-species-shortnames (get-expanded-species))]) (match (string->list id) [(name ... #\. #\m #\e #\t #\a #\. #\j #\s #\o #\n) (render-json (get-expanded-taxon-meta (list->string name)))] - [rest (render-json "WIP")]))) + [(name ... #\. #\j #\s #\o #\n) (render-json (get-expanded-species1 (list->string name)))] + [rest (render-json "NOP")]))) (_ (not-found (request-uri request))) )) |