Translate leaf names using a dictionary of names
        :param dct: Dictionary of current names -> updated names
        :return: Copy of tree with names changed
483493
def translate(self, dct):
        
        new_tree = self.copy()
        for leaf in new_tree._tree.leaf_node_iter():
            curr_name = leaf.taxon.label
            leaf.taxon.label = dct.get(curr_name, curr_name)
        return new_tree
887451
def convert_tree(message, config, indent=0, wrap_alternative=True, charset=None):
    
    ct = message.get_content_type()
    cs = message.get_content_subtype()
    if charset is None:
        charset = get_charset_from_message_fragment(message)
    if not message.is_multipart():
        # we're on a leaf
        converted = None
        disposition = message.get('Content-Disposition', 'inline')
        if disposition == 'inline' and ct in ('text/plain', 'text/markdown'):
            converted = convert_one(message, config, charset)
        if converted is not None:
            if wrap_alternative:
                new_tree = MIMEMultipart('alternative')
                _move_headers(message, new_tree)
                new_tree.attach(message)
                new_tree.attach(converted)
                return new_tree, True
            else:
                return converted, True
        return message, False
    else:
        if ct == 'multipart/signed':
            # if this is a multipart/signed message, then let's just
            # recurse into the non-signature part
            new_root = MIMEMultipart('alternative')
            if message.preamble:
                new_root.preamble = message.preamble
            _move_headers(message, new_root)
            converted = None
            for part in message.get_payload():
                if part.get_content_type() != 'application/pgp-signature':
                    converted, did_conversion = convert_tree(part, config, indent=indent + 1,
                                                             wrap_alternative=False,
                                                             charset=charset)
                    if did_conversion:
                        new_root.attach(converted)
            new_root.attach(message)
            return new_root, did_conversion
        else:
            did_conversion = False
            new_root = MIMEMultipart(cs, message.get_charset())
            if message.preamble:
                new_root.preamble = message.preamble
            _move_headers(message, new_root)
            for part in message.get_payload():
                part, did_this_conversion = convert_tree(part, config, indent=indent + 1, charset=charset)
                did_conversion |= did_this_conversion
                new_root.attach(part)
            return new_root, did_conversion
1062603
def renamed_tree(self, source, dest):
        """"""
        dirname = osp.abspath(to_text_string(source))
        tofile = to_text_string(dest)
        for fname in self.get_filenames():
            if osp.abspath(fname).startswith(dirname):
                new_filename = fname.replace(dirname, tofile)
                self.renamed(source=fname, dest=new_filename)
738745
public List<JCAnnotation> translateAnnotations(List<JCAnnotation> trees) {
        for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail)
            l.head = translate(l.head);
        return trees;
    }
671492
def leaves(tree):
    
    lvs = []
    def _leaves(node):
        if np.isscalar(node):
            lvs.append(node)
        elif isinstance(node, tuple) and len(node) == 2:
            _leaves(node[0])
            _leaves(node[1])
        else:
            raise Exception("Not a tree!")

    _leaves(tree)
    return lvs
927662
def get_flattened(dct, names, path_joiner="_"):
  
  new_dct = dict()
  for key, val in dct.items():
    if key in names:
      child = {path_joiner.join(k): v for k, v in flatten_dict(val, (key, ))}
      new_dct.update(child)
    else:
      new_dct[key] = dct[key]
  return new_dct
1340880
def clean_dict(dct):
    ''''''
    return dict((key, val) for key, val in dct.items() if val is not None)
954918
def attr_to_dict(obj, attr, dct):
    
    if hasattr(obj, attr):
        dct[attr] = getattr(obj, attr)
    return dct
551228
def leaf_asts(self):
        
        seen = set()

        ast_queue = deque([self])
        while ast_queue:

            ast = ast_queue.pop()
            if isinstance(ast, Base) and id(ast.cache_key) not in seen:
                seen.add(id(ast.cache_key))

                if ast.depth == 1:
                    yield ast
                    continue

                ast_queue.extend(ast.args)
                continue
992136
def _recursive_merge(dct, merge_dct, raise_on_missing):
    # type: (Dict[str, Any], Dict[str, Any], bool) -> Dict[str, Any]
    
    for k, v in merge_dct.items():
        if k in dct:
            if isinstance(dct[k], dict) and isinstance(merge_dct[k], BaseMapping):
                dct[k] = _recursive_merge(dct[k], merge_dct[k], raise_on_missing)
            else:
                dct[k] = merge_dct[k]
        elif isinstance(dct, Extensible):
            dct[k] = merge_dct[k]
        else:
            message = "Unknown configuration key: '{k}'".format(k=k)
            if raise_on_missing:
                raise KeyError(message)
            else:
                logging.getLogger(__name__).warning(message)

    return dct
909665
def _defaultdict(dct, fallback=_illegal_character):
    
    out = defaultdict(lambda: fallback)
    for k, v in six.iteritems(dct):
        out[k] = v
    return out
1273076
def to_dict(self, info_filename, tree_filename, dash_f_e=False):
        
        logger.debug('info_filename: {} {}'
                     .format(info_filename, '(FOUND)' if os.path.exists(info_filename) else '(NOT FOUND)'))
        logger.debug('tree_filename: {} {}'
                     .format(tree_filename, '(FOUND)' if os.path.exists(tree_filename) else '(NOT FOUND)'))
        if dash_f_e:
            return self._dash_f_e_to_dict(info_filename, tree_filename)
        else:
            return self._to_dict(info_filename, tree_filename)
1269679
def sort_list_of_dicts(lst_of_dct, keys, reverse=False, **sort_args):
    

    if type(keys) != list:
        keys = [keys]
    # dcmdir = lst_of_dct[:]
    # lst_of_dct.sort(key=lambda x: [x[key] for key in keys], reverse=reverse, **sort_args)
    lst_of_dct.sort(key=lambda x: [((False, x[key]) if key in x else (True, 0)) for key in keys], reverse=reverse, **sort_args)
    return lst_of_dct
361362
def load_dict(self, dct):
        """"""
        for k, v in dct.items():
            setattr(self, k, v)
651160
def calculate_leaf_paths(self):
        
        reverse_xref = {}
        leaves = set()
        for v in self.value.values():
            if v.leaf:
                leaves.add(v)
            for xref in v.value_xref:
                reverse_xref.setdefault(xref, []).append(v.ident)
        for leaf in leaves:
            self.calculate_leaf_path(leaf, reverse_xref)
1032876
def tree(self):
        
        from cmdtree.tree import CmdTree
        if self._tree is None:
            self._tree = CmdTree()
        return self._tree
107580
def translate(root_list, use_bag_semantics=False):
    
    translator = (Translator() if use_bag_semantics else SetTranslator())
    return [translator.translate(root).to_sql() for root in root_list]