Recursively fetch children of tax_ids in `parent_ids` until the
    rank of `rank`
329600
def get_children(engine, parent_ids, rank='species', schema=None):
    

    if not parent_ids:
        return []

    nodes = schema + '.nodes' if schema else 'nodes'
    names = schema + '.names' if schema else 'names'

    cmd = ('select tax_id, tax_name, rank '
           'from {} join {} using (tax_id) '
           'where parent_id = :tax_id and is_primary').format(nodes, names)

    species = []
    for parent_id in parent_ids:
        result = engine.execute(sqlalchemy.sql.text(cmd), tax_id=parent_id)
        keys = list(result.keys())
        rows = [dict(list(zip(keys, row))) for row in result.fetchall()]
        for r in rows:
            if r['rank'] == rank and 'sp.' not in r['tax_name']:
                species.append(r)
        others = [r for r in rows if r['rank'] not in (rank, 'no_rank')]
        if others:
            _, s = get_children(engine, [r['tax_id'] for r in others])
            species.extend(s)

    return keys, species
148053
def get_children(self):
        """"""
        if hasattr(self, '_cached_children'):
            children = self._toplevel().objects.filter(
                pk__in=[n.pk for n in self._cached_children]
            )
            children._result_cache = self._cached_children
            return children
        else:
            return self.get_descendants(include_self=False, depth=1)
119270
def recurse_taxonomy_map(tax_id_map, tax_id, parent=False):
    

    if parent:
        # TODO: allow filtering on tax_id and its parents, too
        pass
    else:

        def _child_recurse(tax_id, visited):
            try:
                children = [tax_id] + list(tax_id_map[tax_id])
            except KeyError:
                children = [tax_id]

            for child in children:
                if child not in visited:
                    visited.append(child)
                    children.extend(_child_recurse(child, visited))

            return children

        return list(set(_child_recurse(tax_id, [])))
366997
def get_id2parents(objs):
    """"""
    id2parents = {}
    for obj in objs:
        _get_id2parents(id2parents, obj.item_id, obj)
    return id2parents
486296
def _get_id2children(id2children, item_id, item_obj):
    """"""
    if item_id in id2children:
        return id2children[item_id]
    child_ids = set()
    for child_obj in item_obj.children:
        child_id = child_obj.item_id
        child_ids.add(child_id)
        child_ids |= _get_id2children(id2children, child_id, child_obj)
    id2children[item_id] = child_ids
    return child_ids
203657
def children(self, alias, bank_id):
        
        return self._root + self._safe_alias(alias) + '/child/ids/' + str(bank_id)
377276
def _traverse_child_objs(self, c2ps, goobj_parent, goids_seen):
        """"""
        # Update public(godag.go2obj godag.c2ps), private(_seen_pids)
        parent_id = goobj_parent.id
        # mark parent as seen
        goids_seen.add(parent_id)
        ##A self.go2obj[parent_id] = goobj_parent
        # Update goids_seen and go2obj with parent alt_ids
        for goid_altid in goobj_parent.alt_ids:
            goids_seen.add(goid_altid)
            ##A self.go2obj[goid_altid] = goobj_parent
        # Loop through children
        for child_obj in goobj_parent.children:
            child_id = child_obj.id
            c2ps[child_id].add(parent_id)
            # If child has not been seen, traverse
            if child_id not in goids_seen:
                ##F self._traverse_child_objs(c2ps, child_obj, go2obj, goids_seen)
                self._traverse_child_objs(c2ps, child_obj, goids_seen)
305922
def get_parents_for(self, child_ids):
        
        self._cache_init()
        parent_candidates = []
        for parent, children in self._cache_get_entry(self.CACHE_NAME_PARENTS).items():
            if set(children).intersection(child_ids):
                parent_candidates.append(parent)
        return set(parent_candidates)
1334552
def get_all_descendants(parent):
    """"""
    children = parent.__subclasses__()
    descendants = children[:]
    for child in children:
        descendants += get_all_descendants(child)
    return descendants
718091
def get_children(self, usage_id_filter=None):
        
        if not self.has_children:
            return []

        return [
            self.get_child(usage_id)
            for usage_id in self.children
            if usage_id_filter is None or usage_id_filter(usage_id)
        ]
505030
def tax_ids(self):
        '''
        
        '''
        fetch = select([self.nodes.c.tax_id]).execute().fetchall()
        ids = [t[0] for t in fetch]
        return ids
469649
private void traverseStoredDescendants(ItemData parent, DataManager dataManager, int action,
      Map<String, ItemData> ret, boolean listOnly, Collection<ItemState> transientDescendants)
      throws RepositoryException
   {

      if (parent.isNode() && !isNew(parent.getIdentifier()))
      {
         if (action != MERGE_PROPS)
         {
            List<NodeData> childNodes = dataManager.getChildNodesData((NodeData)parent);
            for (int i = 0, length = childNodes.size(); i < length; i++)
            {
               NodeData childNode = childNodes.get(i);
               ret.put(childNode.getIdentifier(), childNode);
            }
         }
         if (action != MERGE_NODES)
         {
            List<PropertyData> childProps =
               listOnly ? dataManager.listChildPropertiesData((NodeData)parent) : dataManager
                  .getChildPropertiesData((NodeData)parent);
            outer : for (int i = 0, length = childProps.size(); i < length; i++)
            {
               PropertyData childProp = childProps.get(i);
               for (ItemState transientState : transientDescendants)
               {
                  if (!transientState.isNode() && !transientState.isDeleted()
                     && transientState.getData().getQPath().getDepth() == childProp.getQPath().getDepth()
                     && transientState.getData().getQPath().getName().equals(childProp.getQPath().getName()))
                  {
                     continue outer;
                  }
               }
               if (!childProp.getQPath().isDescendantOf(parent.getQPath(), true))
               {
                  // In case we get the data from the cache, we need to set the correct path
                  QPath qpath = QPath.makeChildPath(parent.getQPath(), childProp.getQPath().getName());
                  childProp =
                     new PersistedPropertyData(childProp.getIdentifier(), qpath, childProp.getParentIdentifier(),
                        childProp.getPersistedVersion(), childProp.getType(), childProp.isMultiValued(),
                        childProp.getValues(), new SimplePersistedSize(
                           ((PersistedPropertyData)childProp).getPersistedSize()));
               }
               ret.put(childProp.getIdentifier(), childProp);
            }
         }
      }
   }
316041
def _slice(self, level):
        ''''''
        if level >= len(self.taxonomy):
            raise IndexError('Level greater than size of taxonomy')
        res = []
        for ident in sorted(list(self.keys())):
            res.append((self[ident]['taxref'], self[ident]['lineage'][level]))
        return res
297972
def verify_rank_integrity(self, tax_id, rank, parent_id, children):
        
        def _lower(n1, n2):
            return self.ranks.index(n1) < self.ranks.index(n2)

        if rank not in self.ranks:
            raise TaxonIntegrityError('rank "{}" is undefined'.format(rank))

        parent_rank = self.rank(parent_id)
        # undefined ranks can be placed anywhere in a lineage
        if not _lower(rank, parent_rank) and rank != self.NO_RANK:
            msg = ('New node "{}", rank "{}" has same or '
                   'higher rank than parent node "{}", rank "{}"')
            msg = msg.format(tax_id, rank, parent_id, parent_rank)
            raise TaxonIntegrityError(msg)

        for child in children:
            if not _lower(self.rank(child), rank):
                msg = 'Child node {} has same or lower rank as new node {}'
                msg = msg.format(tax_id, child)
                raise TaxonIntegrityError(msg)
        return True
854631
def _fetchAllChildren(self):
        
        childItems = []
        fileNames = os.listdir(self._fileName)
        absFileNames = [os.path.join(self._fileName, fn) for fn in fileNames]

        # Add subdirectories
        for fileName, absFileName in zip(fileNames, absFileNames):
            if os.path.isdir(absFileName) and not fileName.startswith('.'):
                childItems.append(DirectoryRti(fileName=absFileName, nodeName=fileName))

        # Add regular files
        for fileName, absFileName in zip(fileNames, absFileNames):
            if os.path.isfile(absFileName) and not fileName.startswith('.'):
                childItem = createRtiFromFileName(absFileName)
                childItems.append(childItem)

        return childItems
103619
def parent_name_at_rank(rank)
      return self.name if self.rank == rank
      p = @parent
      i = 0
      while !p.nil?
        return p.name if p.rank == rank
        p = p.parent
        i+= 1
        raise NameError, "Loop detected among parents for [#{self.display_name}]." if i > 75 
      end
      nil 
    end
770687
function getParents(item: Object) {
    let parents = [];

    if (!item.parent) {
      return parents;
    }

    parents.push(item.parent);
    parents = parents.concat(getParents(item.parent));

    return parents;
  }