Parsers

Newick

Parser for trees represented in newick format.

exception NewickError
content_repr(node, props=None, parser=None)

Return content of a node as represented in newick format.

dump(tree, fp, props=None, parser=None, format_root_node=True, is_leaf_fn=None)
dumps(tree, props=None, parser=None, format_root_node=True, is_leaf_fn=None)

Return newick representation of the given tree.

error(text)
get_extended_props(text)

Return a dict with the properties extracted from the text in NHX format.

Example: ‘&&NHX:x=foo:y=bar’ -> {‘x’: ‘foo’, ‘y’: ‘bar’}

get_props(content, is_leaf, parser=None)

Return the properties from the content (as a newick) of a node.

Example (for the default format of a leaf node):

‘abc:123[&&NHX:x=foo]’ -> {‘name’: ‘abc’, ‘dist’: 123, ‘x’: ‘foo’}

load(fp, parser=None)
loads(tree_text, parser=None, tree_class=Tree)

Return tree from its newick representation.

make_parser(number=1, name='%s', dist='%g', support='%g')

Return “int” parser changing the format of name, dist or support.

prop_repr(prop)

Return a newick-acceptable representation of the given property.

quote(name, escaped_chars=" \t\r\n()[]':;,")

Return the name quoted if it has any characters that need escaping.

read_content(unicode text, long pos, endings=u', );')

Return content starting at position pos in text, and where it ends.

read_nodes(nodes_text, parser, long pos=0, tree_class=Tree)

Return a list of nodes and the position in the text where they end.

repr_short(obj, max_len=50)

Return a representation of the given object, limited in length.

skip_quoted_name(unicode text, long pos)

Return the position where a quoted name ends.

skip_spaces_and_comments(text, long pos)

Return position in text after pos and all whitespaces and comments.

unquote(name)

Return the name unquoted if it was quoted.

Nexus

Read trees from a file in nexus format.

exception NexusError[source]
apply_translations(translate, newick, parser=None)[source]

Return newick with node names translated according to the given dict.

get_commands(text_section)[source]

Return a dict that for each command has a list with its arguments.

get_section(text, section_name)[source]

Return commands ({name: [args]}) that correspond to the given section.

get_sections(text)[source]

Return {section: commands} read from the full text of a nexus file.

get_trees(text, parser=None)[source]

Return trees as {name: newick} with all the name transformations done.

load(fp, parser=None)[source]
loads(text, parser=None)[source]