src/newick.py
def parse_node(s, strip_comments=False, **kw):
    """
    Parse a Newick formatted string into a `Node` object.

    :param s: Newick formatted string to parse.
    :param strip_comments: Flag signaling whether to strip comments enclosed in square \
    brackets.
    :param kw: Keyword arguments are passed through to `Node.create`.
    :return: `Node` instance.
    """
    if strip_comments:
        s = COMMENT.sub('', s)
    s = s.strip()
    parts = s.split(')')
    if len(parts) == 1:
        descendants, label = [], s
    else:
        if not parts[0].startswith('('):
            raise ValueError('unmatched braces %s' % parts[0][:100])
        descendants = list(_parse_siblings(')'.join(parts[:-1])[1:], **kw))
        label = parts[-1]
    name, length = _parse_name_and_length(label)
    return Node.create(name=name, length=length, descendants=descendants, **kw)
def parse_node(s, strip_comments=False, **kw):
    if strip_comments:
        s = COMMENT.sub('', s)
    s = s.strip()
    parts = s.split(')')
    if len(parts) == 1:
        descendants, label = [], s
    else:
        if not parts[0].startswith('('):
            raise ValueError('unmatched braces %s' % parts[0][:100])
        descendants = list(_parse_siblings(')'.join(parts[:-1])[1:], **kw))
        label = parts[-1]
    name, length = _parse_name_and_length(label)
    return Node.create(name=name, length=length, descendants=descendants, **kw)
def parse_node ( s , strip_comments = False , * * kw ) : if strip_comments : s = COMMENT . sub ( '' , s ) s = s . strip ( ) parts = s . split ( ')' ) if len ( parts ) == 1 : descendants , label = [ ] , s else : if not parts [ 0 ] . startswith ( '(' ) : raise ValueError ( 'unmatched braces %s' % parts [ 0 ] [ : 100 ] ) descendants = list ( _parse_siblings ( ')' . join ( parts [ : - 1 ] ) [ 1 : ] , * * kw ) ) label = parts [ - 1 ] name , length = _parse_name_and_length ( label ) return Node . create ( name = name , length = length , descendants = descendants , * * kw )
Parse a Newick formatted string into a `Node` object.

    :param s: Newick formatted string to parse.
    :param strip_comments: Flag signaling whether to strip comments enclosed in square \
    brackets.
    :param kw: Keyword arguments are passed through to `Node.create`.
    :return: `Node` instance.
Parse a Newick formatted string into a Node object .