# Path: scripts_of/newick.py
# def read_newick(newick, root_node=None, format=0):
#     """ Reads a newick tree from either a string or a file, and returns
#     an ETE tree structure.
# 
#     A previously existent node object can be passed as the root of the
#     tree, which means that all its new children will belong to the same
#     class as the root(This allows to work with custom TreeNode
#     objects).
# 
#     You can also take advantage from this behaviour to concatenate
#     several tree structures.
#     """
# 
#     if root_node is None:
#         from .tree import TreeNode   
#         root_node = TreeNode()
# 
#     if isinstance(newick, basestring):
#         if os.path.exists(newick):
#             nw = open(newick, 'rU').read()
#         else:
#             nw = newick
#         nw = nw.strip()
#         if not nw.startswith('(') and nw.endswith(';'):
#             return _read_node_data(nw, root_node, "single", format)
#             
#         elif not nw.startswith('(') or not nw.endswith(';'):
#             raise NewickError('Unexisting tree file or Malformed newick tree structure.')
#         else:
#             return _read_newick_from_string(nw, root_node, format)
# 
#     else:
#         raise NewickError("'newick' argument must be either a filename or a newick string.")
# 
# def write_newick(rootnode, features=None, format=1, format_root_node=True,
#                  is_leaf_fn=None):
#     """ Iteratively export a tree structure and returns its NHX
#     representation. """
#     newick = []
#     leaf = is_leaf_fn if is_leaf_fn else lambda n: not bool(n.children)
#     for postorder, node in rootnode.iter_prepostorder(is_leaf_fn=is_leaf_fn):
#         if postorder:
#             newick.append(")")
#             if node.up is not None or format_root_node:
#                 newick.append(format_node(node, "internal", format))
#                 newick.append(_get_features_string(node, features))
#         else:
#             if node is not rootnode and node != node.up.children[0]:
#                 newick.append(",")
#                 
#             if leaf(node):
#                 safe_name = re.sub("["+_ILEGAL_NEWICK_CHARS+"]", "_", \
#                                str(getattr(node, "name")))
#                 newick.append(format_node(node, "leaf", format))
#                 newick.append(_get_features_string(node, features))
#             else:
#                 newick.append("(")
# 
#     newick.append(";")
#     return ''.join(newick)


import os
    import cPickle as pickle
    import pickle
import random
import copy
import itertools
import functools
from collections import deque 
from .newick import read_newick, write_newick
        Returns the newick representation of current node. Several
        arguments control the way in which extra data is shown for
        every node:

        :argument features: a list of feature names to be exported
          using the Extended Newick Format (i.e. features=["name",
          "dist"]). Use an empty list to export all available features
          in each node (features=[])

        :argument outfile: writes the output to a given file

        :argument format: defines the newick standard used to encode the
          tree. See tutorial for details.

        :argument False format_root_node: If True, it allows features
          and branch information from root node to be exported as a
          part of the newick text string. For newick compatibility
          reasons, this is False by default.

        :argument is_leaf_fn: See :func:`TreeNode.traverse` for
          documentation.
          
        **Example:**

        ::

             t.get_newick(features=["species","name"], format=1)

        """


# Path: scripts_of/newick.py
# def read_newick(newick, root_node=None, format=0):
#     """ Reads a newick tree from either a string or a file, and returns
#     an ETE tree structure.
# 
#     A previously existent node object can be passed as the root of the
#     tree, which means that all its new children will belong to the same
#     class as the root(This allows to work with custom TreeNode
#     objects).
# 
#     You can also take advantage from this behaviour to concatenate
#     several tree structures.
#     """
# 
#     if root_node is None:
#         from .tree import TreeNode   
#         root_node = TreeNode()
# 
#     if isinstance(newick, basestring):
#         if os.path.exists(newick):
#             nw = open(newick, 'rU').read()
#         else:
#             nw = newick
#         nw = nw.strip()
#         if not nw.startswith('(') and nw.endswith(';'):
#             return _read_node_data(nw, root_node, "single", format)
#             
#         elif not nw.startswith('(') or not nw.endswith(';'):
#             raise NewickError('Unexisting tree file or Malformed newick tree structure.')
#         else:
#             return _read_newick_from_string(nw, root_node, format)
# 
#     else:
#         raise NewickError("'newick' argument must be either a filename or a newick string.")
# 
# def write_newick(rootnode, features=None, format=1, format_root_node=True,
#                  is_leaf_fn=None):
#     """ Iteratively export a tree structure and returns its NHX
#     representation. """
#     newick = []
#     leaf = is_leaf_fn if is_leaf_fn else lambda n: not bool(n.children)
#     for postorder, node in rootnode.iter_prepostorder(is_leaf_fn=is_leaf_fn):
#         if postorder:
#             newick.append(")")
#             if node.up is not None or format_root_node:
#                 newick.append(format_node(node, "internal", format))
#                 newick.append(_get_features_string(node, features))
#         else:
#             if node is not rootnode and node != node.up.children[0]:
#                 newick.append(",")
#                 
#             if leaf(node):
#                 safe_name = re.sub("["+_ILEGAL_NEWICK_CHARS+"]", "_", \
#                                str(getattr(node, "name")))
#                 newick.append(format_node(node, "leaf", format))
#                 newick.append(_get_features_string(node, features))
#             else:
#                 newick.append("(")
# 
#     newick.append(";")
#     return ''.join(newick)


# Path: scripts_of/tree.py
import os
    import cPickle as pickle
    import pickle
import random
import copy
import itertools
import functools
from collections import deque 
from .newick import read_newick, write_newick

        Returns the newick representation of current node. Several
        arguments control the way in which extra data is shown for
        every node:

        :argument features: a list of feature names to be exported
          using the Extended Newick Format (i.e. features=["name",
          "dist"]). Use an empty list to export all available features
          in each node (features=[])

        :argument outfile: writes the output to a given file

        :argument format: defines the newick standard used to encode the
          tree. See tutorial for details.

        :argument False format_root_node: If True, it allows features
          and branch information from root node to be exported as a
          part of the newick text string. For newick compatibility
          reasons, this is False by default.

        :argument is_leaf_fn: See :func:`TreeNode.traverse` for
          documentation.
          
        **Example:**

        ::

             t.get_newick(features=["species","name"], format=1)

        """


        nw = write_newick(self, features = features, format=format,