Return a list of species tax_ids under *tax_id* such that
        node under *tax_id* and above the species has two children.
4107
def nary_subtree(self, tax_id, n=2):
        
        if tax_id is None:
            return None
        parent_id, rank = self._node(tax_id)
        if rank == 'species':
            return [tax_id]
        else:
            children = self.children_of(tax_id, 2)
            species_taxids = []
            for t in children:
                species_taxids.extend(self.nary_subtree(t, n))
            return species_taxids
135030
function collectSiblings(node, name, endNode) {
          var siblings = [];

          for (; node && node != endNode; node = node[name]) {
            siblings.push(node);
          }

          return siblings;
        }
656555
def collect(self, parents=None):
        
        results = self.execute(parents=parents)
        ids = results.keys()
        for child in self.nested():
            name = child.node.name
            for child_data in child.collect(parents=ids).values():
                parent_id = child_data.pop('$parent', None)
                if child.node.many:
                    if name not in results[parent_id]:
                        results[parent_id][name] = []
                    results[parent_id][name].append(child_data)
                else:
                    results[parent_id][name] = child_data
        return results
36458
def taxon_info(taxid, ncbi, outFH):
    
    taxid = int(taxid)
    tax_name = ncbi.get_taxid_translator([taxid])[taxid]
    rank = list(ncbi.get_rank([taxid]).values())[0]
    lineage = ncbi.get_taxid_translator(ncbi.get_lineage(taxid))
    lineage = ['{}:{}'.format(k,v) for k,v in lineage.items()]
    lineage = ';'.join(lineage)
    x = [str(x) for x in [tax_name, taxid, rank, lineage]]
    outFH.write('\t'.join(x) + '\n')
475079
def _get_id2parents(id2parents, item_id, item_obj):
    """"""
    if item_id in id2parents:
        return id2parents[item_id]
    parent_ids = set()
    for parent_obj in item_obj.parents:
        parent_id = parent_obj.item_id
        parent_ids.add(parent_id)
        parent_ids |= _get_id2parents(id2parents, parent_id, parent_obj)
    id2parents[item_id] = parent_ids
    return parent_ids
704249
def iterchildren(self):
        """"""

        child_iter = self.model.iter_children(self.iter)
        return TreeModelRowIter(self.model, child_iter)
1047156
def getchildren(self):
        '''
        
        '''
        try:
            if self.hidden:
                return [os.path.join(self.name, child)
                        for child in sorted(self.listdir(self.name))]
            else:
                return [os.path.join(self.name, child)
                        for child in sorted(os.listdir(self.name))]
        except OSError:
            return None
220678
def get_tree_for_studio_id(self, studio_id):
        
        channel_parent = {'children': []}  # this is like _ with children
        def _build_subtree(parent, studio_id):
            subtree = self.get_nodes_by_ids_complete(studio_id)
            if 'children' in subtree:
                children_refs = subtree['children']
                subtree['children'] = []
                for child_studio_id in children_refs:
                    _build_subtree(subtree, child_studio_id)
            parent['children'].append(subtree)
        _build_subtree(channel_parent, studio_id)
        channel = channel_parent['children'][0]
        return channel
451904
def combine_tax_scales(node):
    
    combined_tax_scales = None
    for child_name in node:
        child = node[child_name]

        if not isinstance(child, AbstractTaxScale):
            log.info('Skipping {} with value {} because it is not a tax scale'.format(child_name, child))
            continue

        if combined_tax_scales is None:
            combined_tax_scales = MarginalRateTaxScale(name = child_name)
            combined_tax_scales.add_bracket(0, 0)
        combined_tax_scales.add_tax_scale(child)
    return combined_tax_scales
129275
def __descendants(self):
        
        return itertools.chain(self.contents,
                               *[c.descendants for c in self.children])
870697
def lonely_company(taxonomy, tax_ids):
    
    return [taxonomy.species_below(taxonomy.sibling_of(t)) for t in tax_ids]
1339312
def get_children(self, depth=1):
        """"""
        yield self
        if depth == 0: return
        for child in self.children.values():
            for node in child.get_children(depth-1): yield node
583085
def get_child_nodes(docgraph, parent_node_id, data=False):
    """"""
    return select_neighbors_by_edge_attribute(
        docgraph=docgraph,
        source=parent_node_id,
        attribute='edge_type',
        value=[EdgeTypes.dominance_relation],
        data=data)
1301369
def get_nucsat_subtrees(parented_tree):
    
    if is_leaf(parented_tree):
        return [parented_tree]
    
    nucsat_children = []
    for child in parented_tree:
        if  is_leaf(child) or child.label() in ('N', 'S'):
            nucsat_children.append(child)
        else:
            nucsat_children.extend( get_nucsat_subtrees(child) )
    return nucsat_children
982917
def parents( self, node ):
        """"""
        if 'index' in node:
            index = node['index']()
            parents = list(meliaeloader.children( node, index, 'parents' ))
            return parents 
        return []
366997
def get_id2parents(objs):
    """"""
    id2parents = {}
    for obj in objs:
        _get_id2parents(id2parents, obj.item_id, obj)
    return id2parents
1121698
def iter_child_nodes(node):
    """"""
    for name, field in iter_fields(node):
        if isinstance(field, AST):
            yield field
        elif isinstance(field, list):
            for item in field:
                if isinstance(item, AST):
                    yield item