Tree Implementation and Methods for Python, integrated with Python list, dictionary, and pandas DataFrame.
It is pythonic, making it easy to learn and extendable to many types of workflows.
Related Links:
- Documentation
- GitHub
- Community
- Package
- Articles
There are 3 segments to Big Tree consisting of Tree, Binary Tree, and Directed Acyclic Graph (DAG) implementation.
For Tree implementation, there are 9 main components.
- ๐บ Node
BaseNode
, extendable classNode
, BaseNode with node name attribute
- โจ Constructing Tree
- From
Node
, using parent and children constructors - From str, using tree display or Newick string notation
- From list, using paths or parent-child tuples
- From nested dictionary, using path-attribute key-value pairs or recursive structure
- From pandas DataFrame, using paths or parent-child columns
- Add nodes to existing tree using path string
- Add nodes and attributes to existing tree using dictionary or pandas DataFrame, using path
- Add only attributes to existing tree using dictionary or pandas DataFrame, using node name
- From
- โฐ Traversing Tree
- Pre-Order Traversal
- Post-Order Traversal
- Level-Order Traversal
- Level-Order-Group Traversal
- ZigZag Traversal
- ZigZag-Group Traversal
- ๐ Modifying Tree
- Copy nodes from location to destination
- Shift nodes from location to destination
- Shift and replace nodes from location to destination
- Copy nodes from one tree to another
- Copy and replace nodes from one tree to another
- ๐ Tree Search
- Find multiple nodes based on name, partial path, relative path, attribute value, user-defined condition
- Find single nodes based on name, partial path, relative path, full path, attribute value, user-defined condition
- Find multiple child nodes based on user-defined condition
- Find single child node based on name, user-defined condition
- ๐ง Helper Function
- Cloning tree to another
Node
type - Get subtree (smaller tree with different root)
- Prune tree (smaller tree with same root)
- Get difference between two trees
- Cloning tree to another
- ๐ Plotting Tree
- Enhanced Reingold Tilford Algorithm to retrieve (x, y) coordinates for a tree structure
- ๐จ Exporting Tree
- Print to console, in vertical or horizontal orientation
- Export to Newick string notation, dictionary, nested dictionary, or pandas DataFrame
- Export tree to dot (can save to .dot, .png, .svg, .jpeg files)
- Export tree to Pillow (can save to .png, .jpg)
- Export tree to Mermaid Flowchart (can display on .md)
- โ๏ธ Workflows
- Sample workflows for tree demonstration!
For Binary Tree implementation, there are 3 main components. Binary Node inherits from Node, so the components in Tree implementation are also available in Binary Tree.
- ๐ฟ Node
BinaryNode
, Node with binary tree rules
- โจ Constructing Binary Tree
- From list, using flattened list structure
- โฐ Traversing Binary Tree
- In-Order Traversal
For Directed Acyclic Graph (DAG) implementation, there are 4 main components.
- ๐ผ Node
DAGNode
, extendable class for constructing Directed Acyclic Graph (DAG)
- โจ Constructing DAG
- From list, containing parent-child tuples
- From nested dictionary
- From pandas DataFrame
- โฐ Traversing DAG
- Generic traversal method
- ๐จ Exporting DAG
- Export to list, dictionary, or pandas DataFrame
- Export DAG to dot (can save to .dot, .png, .svg, .jpeg files)
There are two ways to install bigtree
, with pip (recommended) or conda.
To install bigtree
, run the following line in command prompt:
$ pip install bigtree
If tree needs to use pandas methods, it requires additional dependencies. Run the following line in command prompt:
$ pip install 'bigtree[pandas]'
If tree needs to be exported to image, it requires additional dependencies. Run the following lines in command prompt:
$ pip install 'bigtree[image]'
$ brew install gprof2dot # for MacOS
$ conda install graphviz # for Windows
Alternatively, install all optional dependencies with the following line in command prompt:
$ pip install 'bigtree[all]'
To install bigtree
with conda, run the following line in command prompt:
$ conda install -c conda-forge bigtree