phylox.newick_parser.extended_newick_to_dinetwork
- phylox.newick_parser.extended_newick_to_dinetwork(newick, internal_labels=False)
Converts a Newick string to a networkx DAG with leaf labels. The newick string may or may not have length:bootstrap:probability annotations. The newick string may or may not have internal node labels. The newick string may or may not have hybrid nodes.
- Parameters:
newick – a string in extended Newick format for phylogenetic networks.
internal_labels – a boolean, indicating whether the internal nodes of the network are labeled.
- Returns:
a phylogenetic network, i.e., a networkx digraph with leaf labels represented by the `label’ node attribute.
- Example:
>>> newick = "(A:1.1,B:1.2,(C:1.3,D:1.4)E:1.6)F;" >>> network = extended_newick_to_dinetwork(newick) >>> {network.nodes[leaf].get("label") for leaf in network.leaves} == {'A', 'B', 'C', 'D'} True >>> node_for_label_A = network.label_to_node_dict['A'] >>> p = network.parent(node_for_label_A) >>> network[p][node_for_label_A]['length'] 1.1