 )
 
 (re-frame/register-handler
- :aggregate-search-results
- (fn [db [_ search-results]]
-   ;(.log js/console "Aggregate: (aggregate-by-species search-results)" (clj->js (aggregate-by-species search-results)))
-   (assoc db :aggregate-results (aggregate-by-species search-results)))
-)
-
-
-(re-frame/register-handler
  :concat-results
  (fn [db [_ search-results source]]
-;   (.log js/console (clj->js source) "Concat: " (clj->js (:results search-results)))
    (assoc-in db [:multi-mine-results source] search-results)
    (assoc-in db [:multi-mine-aggregate source] (aggregate-by-orthologue (:results search-results))))
 )

    (assoc db :search-term term)
    ))

(re-frame/register-handler
 ;
 :update-search-results
 (fn [db [_ search-results]]
   (assoc db :search-results search-results)
))

(defn aggregate-by-species [search-results]
  "helper to get the counts of aggregate go terms per organism / go term / ontology branch "
  (reduce (fn [new-map [_ _ _ _ _ primary-id secondary-id symbol organism & args ]]
    (update-in new-map [(keyword organism ) (keyword (utils/get-id primary-id secondary-id symbol)) (keyword (last args))] inc))
      {} search-results)
)

(defn aggregate-by-orthologue [search-results]
  "helper to get the counts of aggregate go terms per organism / go term / ontology branch "
  (reduce (fn [new-map [_ _ _ _ _ primary-id secondary-id symbol organism & args ]]

  ;;What do we do when a search button is pressed? This.
  :perform-search
  (fn [db [_ _]]
    ;asynchronously query all dem mines and add the results to the db
    (go
      (comms/query-all-selected-organisms (:selected-organism db) (:search-term db))
) db))
