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/db/sparql.scm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'gn/db') 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