@newick.writer(TreeNode)
def _tree_node_to_newick(obj, fh):
    operators = set(",:_;()[]")
    current_depth = 0
    nodes_left = [(obj, 0)]
    while len(nodes_left) > 0:
        entry = nodes_left.pop()
        node, node_depth = entry
        if node.children and node_depth >= current_depth:
            fh.write('(')
            nodes_left.append(entry)
            nodes_left += ((child, node_depth + 1) for child in
                           reversed(node.children))
            current_depth = node_depth + 1
        else:
            if node_depth < current_depth:
                fh.write(')')
                current_depth -= 1

            # Note we don't check for None because there is no way to represent
            # an empty string as a label in Newick. Therefore, both None and ''
            # are considered to be the absence of a label.
            if node.name:
                escaped = "%s" % node.name.replace("'", "''")
                if any(t in operators for t in node.name):
                    fh.write("'")
                    fh.write(escaped)
                    fh.write("'")
                else:
                    fh.write(escaped.replace(" ", "_"))
            if node.length is not None:
                fh.write(':')
                fh.write("%s" % node.length)
            if nodes_left and nodes_left[-1][1] == current_depth:
                fh.write(',')

    fh.write(';\n')
dataset/ETHPy150Open biocore/scikit-bio/skbio/io/format/newick.py/_tree_node_to_newick/original