code: def get_counts(entities=None,
                 object_category=None,
                 min_count=1,
                 **kwargs):
      
      if entities is None:
          entities = []
      results = search_associations(subjects=entities,
                                    subject_direct=True,
                                    rows=0,
                                    facet_fields=[M.IS_DEFINED_BY, M.SUBJECT_TAXON, M.SUBJECT_CATEGORY],
                                    object_category=object_category,
                                    facet_mincount=3, # TODO
                                    facet_limit=-1,
                                    json_facet={
                                        'categories':{
                                            'limit':-1,
                                            'type': 'terms',
                                            'field' : M.OBJECT_CLOSURE,
                                            'facet' : {
                                                'uniq_subject': "unique(subject)"
                                            }
                                        }
                                    },
                                    **kwargs)
      buckets = results['facets']['categories']['buckets']
      cmap = {}
      for bucket in buckets:
          if bucket['uniq_subject'] >= min_count:
              cmap[bucket['val']] = bucket['uniq_subject']
      return (cmap, results)
docs: given a set of entities (genes, diseases, etc), finds the number of entities associated with each descriptor in a given category.
  
      The result is a tuple (cmap, results), where cmap is a dict of TERM:COUNT