Skip to content

Commit

Permalink
Add other-names processing to ids merge operation #304
Browse files Browse the repository at this point in the history
  • Loading branch information
mluypaert committed Aug 21, 2020
1 parent a016404 commit 9723201
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ids/src/wormbase/ids/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,30 @@
(defn merge-genes
"Merge two genes.
Transfer (retract and add) sequence-name from the \"from-gene\" if the \"into-gene\" is uncloned.
The \"from-gene\" will be marked as dead.
- Transfer (retract and add) sequence-name from the \"from-gene\" if the \"into-gene\" is uncloned.
- Transfer (add) other-names from the \"from-gene\" to the \"into-gene\".
- The \"from-gene\" will be marked as dead.
Return transaction data."
[db from-id into-id into-biotype]
(let [m-attr :gene/merges
attrs-signifying-cloned [:gene/biotype :gene/sequence-name]
from-gene (d/pull db [:gene/sequence-name] from-id)
into-gene (d/pull db attrs-signifying-cloned into-id)
from-gene (d/pull db [:gene/sequence-name :gene/other-names] from-id)
into-gene (d/pull db (conj attrs-signifying-cloned :gene/other-names) into-id)
from-seq-name (:gene/sequence-name from-gene)
from-other-names (:gene/other-names from-gene)
;;fn to build other-names txs
build-tx-fn (fn [id attr ^String val] (vec [:db/add id attr val]))
;;build other-names transaction statements
other-names-txes (map #(build-tx-fn into-id :gene/other-names %) from-other-names)
uncloned-gene? (fn uncloned? [gene]
(let [cloned-values ((apply juxt attrs-signifying-cloned) gene)]
(every? nil? cloned-values)))]
(concat
[['wormbase.ids.core/cas-batch from-id {:gene/status :gene.status/dead}]
['wormbase.ids.core/cas-batch into-id {:gene/biotype into-biotype}]
[:db/add into-id m-attr from-id]]
other-names-txes
(when (uncloned-gene? into-gene)
[[:db/retract from-id :gene/sequence-name from-seq-name]
[:db/cas into-id :gene/sequence-name nil from-seq-name]]))))
Expand Down

0 comments on commit 9723201

Please sign in to comment.