aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn/data/group.scm5
-rw-r--r--gn/data/species.scm4
-rw-r--r--gn/db/sparql.scm33
-rwxr-xr-xweb/webserver.scm12
4 files changed, 50 insertions, 4 deletions
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 })
+}")))
diff --git a/web/webserver.scm b/web/webserver.scm
index 17f5716..a60f477 100755
--- a/web/webserver.scm
+++ b/web/webserver.scm
@@ -29,6 +29,7 @@
(web gn-uri)
(gn db sparql)
(gn data species)
+ (gn data group)
(web sxml)
(web view doc))
@@ -51,6 +52,14 @@
(,(mk-url "datasets")."Get a list of datasets")))))
+(define (get-id-data id)
+ "Get data based on identifier id. If it is a taxon return the taxon data,
+otherwise search for set/group data"
+ (let ([taxoninfo (get-expanded-taxon-data id)])
+ (if taxoninfo
+ taxoninfo
+ (cdr (get-group-data id)))))
+
;; ---- REST API web server handler
(define (not-found2 request)
@@ -104,7 +113,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)))]
- [(name ... #\. #\j #\s #\o #\n) (render-json (get-expanded-taxon-data (list->string name)))]
+ [(name ... #\. #\j #\s #\o #\n) (render-json
+ (get-id-data (list->string name)))]
[rest (render-json "NOP")])))
(_ (not-found (request-uri request)))
))