TreeSwift is a Python library for parsing, manipulating, and iterating over (rooted) tree structures. TreeSwift places an emphasis on speed.
TreeSwift can be installed using pip
:
sudo pip install treeswift
If you are using a machine on which you lack administrative powers, TreeSwift can be installed locally using pip
:
pip install --user treeswift
Typical usage should be as follows:
- Import the
treeswift
package - Use
treeswift.read_tree_newick
to load your Newick tree - Use the various
Tree
class functions on the resulting object as you need
import treeswift
tree = treeswift.read_tree_newick(my_newick_string)
for node in tree.traverse_postorder():
print(node)
Full documentation can be found at https://niemasd.github.io/TreeSwift/, and more examples can be found in the TreeSwift Wiki.