Big Tree Python Package
Tree Implementation and Methods for Python, integrated with list, dictionary, pandas and polars DataFrame.
It is pythonic, making it easy to learn and extendable to many types of workflows.
Related Links:
Components
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
- From polars DataFrame, using paths or parent-child columns
- Add nodes to existing tree using path string
- Add nodes and attributes to existing tree using dictionary, pandas DataFrame, or polars DataFrame, using path
- Add only attributes to existing tree using dictionary, pandas DataFrame, or polars DataFrame, using node name
- ➰ 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
- 📊 Plotting Tree
- Enhanced Reingold Tilford Algorithm to retrieve (x, y) coordinates for a tree structure
- Plot tree using matplotlib (optional dependency)
- 🔨 Exporting Tree
- Print to console, in vertical or horizontal orientation
- Export to Newick string notation, dictionary, nested dictionary, pandas DataFrame, or polars 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)
Installation
bigtree
requires Python 3.8+. There are two ways to install bigtree
, with pip (recommended) or conda.
a) Installation with pip
Basic Installation
To install bigtree
, run the following line in command prompt:
$ pip install bigtree
Installing optional dependencies
bigtree
have a number of optional dependencies, which can be installed using "extras" syntax.
$ pip install 'bigtree[extra_1, extra_2]'
Examples of extra packages include:
all
: include all optional dependenciesimage
: for exporting tree to imagematplotlib
: for plotting treespandas
: for pandas methodspolars
: for polars methods
For image
extra dependency, you may need to install more plugins.
$ brew install gprof2dot
$ conda install graphviz
b) Installation with conda
To install bigtree
with conda, run the following line in command prompt:
$ conda install -c conda-forge bigtree
Star History