Browse Source

Notes and functions on adding resources to redis

master
Christian Fischer 9 months ago
parent
commit
527b243149
2 changed files with 85 additions and 8 deletions
  1. +33
    -2
      docs/integration.org
  2. +52
    -6
      server/resource.rkt

+ 33
- 2
docs/integration.org View File

@@ -163,7 +163,9 @@ so we want a constructor function:
#+end_src


*** Chromosome queries
*** Other queries

The chromosome queries are almost, but not quite the same:

Line 305
#+begin_src python
@@ -182,7 +184,10 @@ query = """SELECT kgID, chromosome, txStart, txEnd
WHERE geneSymbol = '{}'""".format(self.this_trait.symbol)
#+end_src

*** Geno query
The only differences are the presence of the ~kgID~ column in the 2nd
query, and the table that's being searched.

There's also this geno query, that's very similar to what already exists:

Line 503
#+begin_src python
@@ -194,3 +199,29 @@ query = """SELECT Geno.Name
GenoFreeze.Name = '{}'
ORDER BY ABS( Geno.Mb - {}) LIMIT 1""".format(this_chr, this_db.group.name+"Geno", this_mb)
#+end_src


Thinking about it, it probably doesn't make sense to have the proxy
handle these requests, so I won't waste time on them for now.

** Populating Redis

For the proxy to be able to execute actions on these resources, they
need to have entries in the Redis database. I've added functions
to ~resource.rkt~ that take the required IDs/names and add them to
Redis if they don't exist, ~add-probe-resource~, ~add-publish-resource~
and ~add-geno-resource~.

To add a dataset-publish resource with the dataset ID 1, trait ID 17465,
with name "resource1" at Redis ID 0:

#+begin_src racket
(add-publish-resource "0"
"resource1"
"1"
"17465")
#+end_src

Additionally, users and groups have to exist in Redis. We can
use the GN2 users already in Redis from GN2, but for completeness'
sake:

+ 52
- 6
server/resource.rkt View File

@@ -58,8 +58,7 @@
'owner_id (resource-owner res)
'data (resource-data res)
'type (symbol->string (resource-type res))
'default_mask (hash-symbol->string
(resource-default-mask res))
'default_mask (resource-default-mask res)
'group_masks (resource-group-masks res))))

(define (deserialize-resource res)
@@ -70,10 +69,16 @@
(parse 'owner_id)
(parse 'data)
(string->symbol (parse 'type))
(hash-string->symbol
(parse 'default_mask))
(parse 'default_mask)
(parse 'group_masks))))

(define (add-resource id res)
(redis-hash-set! (redis-conn)
"resources"
id
(serialize-resource res)))


(define (get-resource id)
(~> (redis-hash-ref (redis-conn) "resources" id)
(deserialize-resource)))
@@ -265,8 +270,8 @@
(action "view"
(lambda (data
params)
(select-geno (hash-ref data 'dataset)
(hash-ref data 'trait)))
(select-publish (hash-ref data 'dataset)
(hash-ref data 'trait)))
'()))

(define dataset-publish-data
@@ -367,6 +372,47 @@
(hasheq 'data dataset-probe-data))


;; Helpers for adding new resources to Redis

(define (add-probe-resource id
name
dataset-name
trait-name)
(define mask
(hash 'data "view"))
(let ((res (new-probe-resource name
0
dataset-name
trait-name
mask)))
(add-resource id res)))

(define (add-publish-resource id
name
dataset-name
trait-name)
(define mask
(hash 'data "view"))
(let ((res (new-publish-resource name
0
dataset-name
trait-name
mask)))
(add-resource id res)))

(define (add-geno-resource id
name
dataset-name
trait-name)
(define mask
(hash 'data "view"))
(let ((res (new-geno-resource name
0
dataset-name
trait-name
mask)))
(add-resource id res)))

;; The global mapping from resource type to action set.
(define resource-types
(hash 'dataset-file dataset-file-actions


Loading…
Cancel
Save