code: def extract_context(annotations, annot_manager):
      def get_annot(annotations, key):
          val = annotations.pop(key, None)
          if val:
              val_list = [v for v, tf in val.items() if tf]
              if len(val_list) > 1:
                  logger.warning('More than one "%s" in annotations' % key)
              elif not val_list:
                  return None
              return val_list[0]
          return None
      bc = BioContext()
      species = get_annot(annotations, 'Species')
      if species:
          name = annot_manager.get_mapping('Species', species)
          bc.species = RefContext(name=name, db_refs={'TAXONOMY': species})
      mappings = (('CellLine', 'cell_line', None),
                  ('Disease', 'disease', None),
                  ('Anatomy', 'organ', None),
                  ('Cell', 'cell_type', None),
                  ('CellStructure', 'location', 'MESH'))
      for bel_name, indra_name, ns in mappings:
          ann = get_annot(annotations, bel_name)
          if ann:
              ref = annot_manager.get_mapping(bel_name, ann)
              if ref is None:
                  continue
              if not ns:
                  db_ns, db_id = ref.split('_', 1)
              else:
                  db_ns, db_id = ns, ref
              setattr(bc, indra_name,
                      RefContext(name=ann, db_refs={db_ns: db_id}))
      if not bc:
          bc = None
      return bc