Skip to content

Commit

Permalink
Added gene other-names support to DB scheme and /gene REST API patter…
Browse files Browse the repository at this point in the history
…n search #304
  • Loading branch information
mluypaert committed Jul 6, 2020
1 parent 7047d83 commit 11d4c22
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
3 changes: 3 additions & 0 deletions resources/schema/definitions.edn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
:valueType :db.type/string
:cardinality :db.cardinality/one
:unique :db.unique/value}
#:db{:ident :gene/other-names
:valueType :db.type/string
:cardinality :db.cardinality/many}
#:db{:ident :gene/status
:valueType :db.type/ref
:cardinality :db.cardinality/one}
Expand Down
32 changes: 12 additions & 20 deletions src/wormbase/names/entity.clj
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,16 @@
(count numbers))})))

(defn build-find-query
[find-attrs unqualified-attrs rule-head]
[rule-head]
;; generated symbols are used to bind result variables in the datalog query.
;; this is done to avoid confusion with variable names used to bind
;; predicates.
(let [query-vars (repeatedly (count unqualified-attrs)
(partial gensym "?"))
rule-clause (cons (symbol rule-head) '(?pattern ?name ?eid))
var->ident (zipmap query-vars find-attrs)
q-spec {:in '[$ % ?pattern]
:where
[rule-clause
'[?eid ?id-ident ?id]]}
get-else-clauses (->> query-vars
(map (fn [sym]
[(list 'get-else '$ '?eid (sym var->ident) "") sym]))
(vec))]
(-> q-spec
(update :where (fn [clause]
(concat clause get-else-clauses)))
(assoc :find query-vars :keys find-attrs))))
(let [rule-clause (cons (symbol rule-head) '(?pattern ?name ?eid))
q-spec {:find '[[?eid ...]]
:in '[$ % ?pattern]
:where [rule-clause
'[?eid ?id-ident ?id]]}]
q-spec))

(defn finder
[entity-type unqualified-attrs]
Expand All @@ -336,9 +326,11 @@
find-attrs (map (partial keyword entity-type) unqualified-attrs)
rule-head (str entity-type "-name")
matching-rules (wnm/make-rules rule-head find-attrs)
query (build-find-query find-attrs unqualified-attrs rule-head)
regexp-pattern (re-pattern (str "^" s-pattern))
q-result (d/q query db matching-rules regexp-pattern)
query (build-find-query rule-head)
matching-pattern (re-pattern (str "^" s-pattern))
pull-pattern (vec find-attrs)
q-ids (d/q query db matching-rules matching-pattern)
q-result (d/pull-many db pull-pattern q-ids)
res {:matches (if (seq q-result)
(vec (map #(wnu/unqualify-keys % entity-type) q-result))
[])}]
Expand Down
2 changes: 1 addition & 1 deletion src/wormbase/names/gene.clj
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
:responses (wnu/http-responses-for-read {:schema ::wsg/find-result})
:parameters {:query-params ::wsc/find-request}
:x-name ::find-gene
:handler (wne/finder "gene" ["cgc-name" "sequence-name" "id"])}
:handler (wne/finder "gene" ["cgc-name" "sequence-name" "id" "other-names"])}
:post
{:summary "Create new names for a gene (cloned or un-cloned)"
:x-name ::new-gene
Expand Down
10 changes: 9 additions & 1 deletion src/wormbase/specs/gene.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

(s/def ::name (s/and string?))

(s/def ::names-coll (s/coll-of ::name))

(s/def :gene/id (stc/spec {:spec ::name
:swagger/example "WBGene00000421"
:description "The primary identifier of a Gene."}))
Expand All @@ -20,6 +22,10 @@
:swagger/example "unc-22"
:description "The CGC name."}))

(s/def :gene/other-names (stc/spec {:spec (s/nilable ::names-coll)
:swagger/example "[\"UNCoordinated-22\", \"Other-name\"]"
:description "Alternative gene name(s)."}))

(s/def :gene/sequence-name (stc/spec {:spec (s/nilable ::name)
:swagger/example "AAH1.1"
:description "The sequence name of the Gene."}))
Expand Down Expand Up @@ -77,6 +83,7 @@

(s/def ::update (stc/spec {:spec (s/and (s/keys :opt-un [:gene/cgc-name
:gene/sequence-name
:gene/other-names
:gene/biotype
:gene/species])
seq)
Expand Down Expand Up @@ -166,7 +173,8 @@

(s/def ::find-match (stc/spec {:spec (s/keys :req-un [:gene/id]
:opt-un [:gene/cgc-name
:gene/sequence-name])
:gene/sequence-name
:gene/other-names])
:description "A mappings describing a search result match."}))
(s/def ::matches (stc/spec {:spec (s/coll-of ::find-match :kind vector?)
:description "A collection of search result matches."}))
Expand Down

0 comments on commit 11d4c22

Please sign in to comment.