From afbbd86f316c2bfa70b86c1c51a4147a83f285ec Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 23 Aug 2023 14:23:44 +0200 Subject: Able to render group data --- gn/data/group.scm | 5 +++++ gn/data/species.scm | 4 ++-- gn/db/sparql.scm | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'gn') diff --git a/gn/data/group.scm b/gn/data/group.scm index 3d31a0b..014b689 100644 --- a/gn/data/group.scm +++ b/gn/data/group.scm @@ -10,6 +10,7 @@ #:export ( get-group-links + get-group-data )) (define (get-group-links gnid func) @@ -22,3 +23,7 @@ (func (car r)) #f)) recs) )) + +(define (get-group-data id) + (car (cdr (make-pairs (lambda () (sparql-group-info (string-append "gn:" id)))) + ))) diff --git a/gn/data/species.scm b/gn/data/species.scm index 7923101..a712bae 100644 --- a/gn/data/species.scm +++ b/gn/data/species.scm @@ -73,7 +73,7 @@ (define (get-expanded-taxon-data short-name) "Here we add information related to one taxonomy species" - (call/cc (lambda (return) + (call/cc (lambda (return) ; use call/cc to be able to return early (for-each (lambda (rec) (if (string=? (assoc-ref rec "shortName") short-name) (return (expand-species rec)))) @@ -133,5 +133,5 @@ ("meta-links" . ,(list->vector (get-group-links (gnid-species id) (lambda (r) (mk-meta (url-parse-id r)))))) ("links" . ,(list->vector (get-group-links (gnid-species id) - (lambda (r) (mk-meta (url-parse-id r)))))) + (lambda (r) (mk-data (url-parse-id r)))))) )) diff --git a/gn/db/sparql.scm b/gn/db/sparql.scm index 2665235..7e512ff 100644 --- a/gn/db/sparql.scm +++ b/gn/db/sparql.scm @@ -15,12 +15,15 @@ memo-sparql-species-meta sparql-species-meta sparql-groups-meta + sparql-group-info memo-sparql-wd-species-info compile-species compile-groups-meta get-rows tsv->scm strip-lang + make-table + make-pairs ) ) @@ -200,6 +203,14 @@ dump-species-metadata.ttl:gn:Axbxa gnt:belongsToSpecies gn:Mus_musculus . "Format results as a list of values ordered by names" (map (lambda (row) (get-values names row)) (array->list results))) +(define (get-pairs names results) + "Format results as a list of key-values ordered by names" + (map (lambda (row) + (let ([tuple (get-values names row)]) + (cons (car tuple) (car (cdr tuple))) + )) + (array->list results))) + ;; from the triples first harvest the species URIs, followed by creating records of information (define (compile-species recs rows) @@ -224,7 +235,7 @@ dump-species-metadata.ttl:gn:Axbxa gnt:belongsToSpecies gn:Mus_musculus . ;; ------------------------------------------------------------------------------ (define (sparql-groups-meta) - "Return values names recs" + "Return values names recs - (set-id, species, descr)" (sparql-scm (gn-sparql-endpoint-url) " SELECT DISTINCT ?set ?species ?descr WHERE { ?set rdf:type gnc:inbredSet ; @@ -235,8 +246,28 @@ dump-species-metadata.ttl:gn:Axbxa gnt:belongsToSpecies gn:Mus_musculus . (define memo-sparql-groups-meta (memoize2 sparql-groups-meta)) +(define (make-table sparql-thunk) + "Make a tuple of column names and rows" + (receive (names res) (sparql-thunk) + (let ([rows (get-rows names res)]) + (list names rows)))) + +(define (make-pairs sparql-thunk) + "Make a tuple of column names and rows" + (receive (names res) (sparql-thunk) + (let ([rows (get-pairs names res)]) + (list names rows)))) + (define (compile-groups-meta) "Return tuple of names and rows containing #(set species descr)" (receive (names res) (memo-sparql-groups-meta) (let ([rows (get-rows names res)]) (list names rows)))) + +(define (sparql-group-info gnid) + "Return set/group info - used by meta and data output" + (sparql-scm (gn-sparql-endpoint-url) (string-append " + SELECT DISTINCT ?key ?value WHERE { + " gnid " ?key ?value . + # FILTER ( !EXISTS{ " gnid " gnt:hasTissue ?value }) +}"))) -- cgit v1.2.3