Fill childgoid2obj with all child key GO IDs and their objects.
778397
def fill_childgoid2obj(childgoid2obj, parent_obj):
    """"""
    for child_obj in parent_obj.children:
        if child_obj.id not in childgoid2obj:
            childgoid2obj[child_obj.id] = child_obj
            fill_childgoid2obj(childgoid2obj, child_obj)
517090
private void createCompleteKey(Key parent, long id) {
    String kind = entityMetadata.getKind();
    if (parent == null) {
      key = entityManager.newNativeKeyFactory().setKind(kind).newKey(id);
    } else {
      key = Key.newBuilder(parent, kind, id).build();
    }
  }
744439
def _traverse_parent_objs(self, goobj_child):
        """"""
        child_id = goobj_child.id
        # mark child as seen
        self.seen_cids.add(child_id)
        self.godag.go2obj[child_id] = goobj_child
        # Loop through parents of child object
        for parent_obj in goobj_child.parents:
            parent_id = parent_obj.id
            self.godag.p_from_cs[parent_id].add(child_id)
            # If parent has not been seen, traverse
            if parent_id not in self.seen_cids:
                self._traverse_parent_objs(parent_obj)
273044
def _get_go2nt(goids, go2nt_all):
    """"""
    go_nt_list = []
    goids_seen = set()
    for goid_usr in goids:
        ntgo = go2nt_all[goid_usr]
        goid_main = ntgo.id
        if goid_main not in goids_seen:
            goids_seen.add(goid_main)
            go_nt_list.append((goid_main, ntgo))
    return go_nt_list
1192774
def _recursive_upsert(context, params, data):
    """"""
    children = params.get("children", {})
    nested_calls = []
    for child_params in children:
        key = child_params.get("key")
        child_data_list = ensure_list(data.pop(key))
        if isinstance(child_data_list, dict):
            child_data_list = [child_data_list]
        if not (isinstance(child_data_list, list) and
                all(isinstance(i, dict) for i in child_data_list)):
            context.log.warn(
                "Expecting a dict or a lost of dicts as children for key", key
            )
            continue
        if child_data_list:
            table_suffix = child_params.get("table_suffix", key)
            child_params["table"] = params.get("table") + "_" + table_suffix
            # copy some properties over from parent to child
            inherit = child_params.get("inherit", {})
            for child_data in child_data_list:
                for dest, src in inherit.items():
                    child_data[dest] = data.get(src)
                nested_calls.append((child_params, child_data))
    # Insert or update data
    _upsert(context, params, data)
    for child_params, child_data in nested_calls:
        _recursive_upsert(context, child_params, child_data)
1308684
function flattenById(obj, keyedObj = {}) {
  if (obj.hasOwnProperty('id')) {
    keyedObj[obj.id] = obj;
  }
  for (var key in obj) {
    if (isObject(obj[key])) {
      flattenById(obj[key], keyedObj);
    }
  }
  return keyedObj;
}
437728
def populate_schema_objects(self, schema, obj_type):
        """"""
        metadata = self.dbmetadata[obj_type]
        schema = schema or self.dbname

        try:
            objects = metadata[schema].keys()
        except KeyError:
            # schema doesn't exist
            objects = []

        return objects
264577
def get_key_goids(self, goids):
        """"""
        go2obj = self.go2obj
        return set(go2obj[go].id for go in goids)
1144124
def add_alt_goids(go2values, altgo2goobj):
    """"""
    for goobj_key in altgo2goobj.values():
        values_curr = go2values[goobj_key.id]
        for goid_alt in goobj_key.alt_ids:
            go2values[goid_alt] = values_curr
    return go2values
548708
def bind_keys(self, objects):
        """"""
        for object in objects:
            if object.keys != None:
                for key in object.keys:
                    if key != None:
                        self.bind_key_name(key, object.name)
254158
def _init_usrgos(self, goids):
        """"""
        usrgos = set()
        goids_missing = set()
        _go2obj = self.gosubdag.go2obj
        for goid in goids:
            if goid in _go2obj:
                usrgos.add(goid)
            else:
                goids_missing.add(goid)
        if goids_missing:
            print("MISSING GO IDs: {GOs}".format(GOs=goids_missing))
            print("{N} of {M} GO IDs ARE MISSING".format(N=len(goids_missing), M=len(goids)))
        return usrgos
766346
def get_id2gos_all(taxid2asscs_a2b):
        """"""
        id2gos_all = {}
        for a2b in taxid2asscs_a2b.values():
            for geneid, gos in a2b['ID2GOs'].items():
                id2gos_all[geneid] = gos
        return id2gos_all
348748
def populate_keys_tree(self):
        
        for group in HOTKEYS:
            parent = self.store.append(None, [None, group['label'], None, None])
            for item in group['keys']:
                if item['key'] == "show-hide" or item['key'] == "show-focus":
                    accel = self.settings.keybindingsGlobal.get_string(item['key'])
                else:
                    accel = self.settings.keybindingsLocal.get_string(item['key'])
                gsettings_path = item['key']
                keycode, mask = Gtk.accelerator_parse(accel)
                keylabel = Gtk.accelerator_get_label(keycode, mask)
                self.store.append(parent, [gsettings_path, item['label'], keylabel, accel])
        self.get_widget('treeview-keys').expand_all()
906814
def add_child(self, child):
        
        child_id = getattr(child, 'id', None)
        if child_id:
            if not hasattr(self, 'children'):
                self.children = {}
            if child_id not in self.children:
                self.children[child_id] = child
1234754
def fill(self, key, mor_dict):
        
        with self._objects_queue_lock:
            self._objects_queue[key] = mor_dict
248185
private static <K, V> HamtPMap<K, V>[] insertChild(
      HamtPMap<K, V>[] children, int index, HamtPMap<K, V> child) {
    @SuppressWarnings("unchecked") // only used internally.
    HamtPMap<K, V>[] newChildren = (HamtPMap<K, V>[]) new HamtPMap<?, ?>[children.length + 1];
    newChildren[index] = child;
    System.arraycopy(children, 0, newChildren, 0, index);
    System.arraycopy(children, index, newChildren, index + 1, children.length - index);
    return newChildren;
  }
840937
def import_from_dict(cls, session, dict_rep, parent=None,
                         recursive=True, sync=[]):
        """"""
        parent_refs = cls._parent_foreign_key_mappings()
        export_fields = set(cls.export_fields) | set(parent_refs.keys())
        new_children = {c: dict_rep.get(c) for c in cls.export_children
                        if c in dict_rep}
        unique_constrains = cls._unique_constrains()

        filters = []  # Using these filters to check if obj already exists

        # Remove fields that should not get imported
        for k in list(dict_rep):
            if k not in export_fields:
                del dict_rep[k]

        if not parent:
            if cls.export_parent:
                for p in parent_refs.keys():
                    if p not in dict_rep:
                        raise RuntimeError(
                            '{0}: Missing field {1}'.format(cls.__name__, p))
        else:
            # Set foreign keys to parent obj
            for k, v in parent_refs.items():
                dict_rep[k] = getattr(parent, v)

        # Add filter for parent obj
        filters.extend([getattr(cls, k) == dict_rep.get(k)
                        for k in parent_refs.keys()])

        # Add filter for unique constraints
        ucs = [and_(*[getattr(cls, k) == dict_rep.get(k)
               for k in cs if dict_rep.get(k) is not None])
               for cs in unique_constrains]
        filters.append(or_(*ucs))

        # Check if object already exists in DB, break if more than one is found
        try:
            obj_query = session.query(cls).filter(and_(*filters))
            obj = obj_query.one_or_none()
        except MultipleResultsFound as e:
            logging.error('Error importing %s \n %s \n %s', cls.__name__,
                          str(obj_query),
                          yaml.safe_dump(dict_rep))
            raise e

        if not obj:
            is_new_obj = True
            # Create new DB object
            obj = cls(**dict_rep)
            logging.info('Importing new %s %s', obj.__tablename__, str(obj))
            if cls.export_parent and parent:
                setattr(obj, cls.export_parent, parent)
            session.add(obj)
        else:
            is_new_obj = False
            logging.info('Updating %s %s', obj.__tablename__, str(obj))
            # Update columns
            for k, v in dict_rep.items():
                setattr(obj, k, v)

        # Recursively create children
        if recursive:
            for c in cls.export_children:
                child_class = cls.__mapper__.relationships[c].argument.class_
                added = []
                for c_obj in new_children.get(c, []):
                    added.append(child_class.import_from_dict(session=session,
                                                              dict_rep=c_obj,
                                                              parent=obj,
                                                              sync=sync))
                # If children should get synced, delete the ones that did not
                # get updated.
                if c in sync and not is_new_obj:
                    back_refs = child_class._parent_foreign_key_mappings()
                    delete_filters = [getattr(child_class, k) ==
                                      getattr(obj, back_refs.get(k))
                                      for k in back_refs.keys()]
                    to_delete = set(session.query(child_class).filter(
                        and_(*delete_filters))).difference(set(added))
                    for o in to_delete:
                        logging.info('Deleting %s %s', c, str(obj))
                        session.delete(o)

        return obj