Skip to content

Commit 025acac

Browse files
authored
Merge pull request #154 from kayjan/v0.15.1
V0.15.1
2 parents 411bc6d + 82aab30 commit 025acac

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [0.15.1] - 2024-01-05
88
### Added
99
- Tree Constructor: `newick_to_tree` to convert Newick notation to tree.
10+
- Tree Exporter: `hprint_tree` and `hyield_tree` to print and retrieve results for tree in horizontal orientation.
11+
- Node: Added `hshow` method to print tree in horizontal orientation to console.
1012
### Changed
1113
- Tree Exporter: `tree_to_newick` to accept more parameters to parse length and attributes.
1214
### Fixed

README.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ For **Tree** implementation, there are 9 main components.
6666
7. [**📊 Plotting Tree**](https://bigtree.readthedocs.io/en/latest/bigtree/utils/plot.html)
6767
1. Enhanced Reingold Tilford Algorithm to retrieve (x, y) coordinates for a tree structure
6868
8. [**🔨 Exporting Tree**](https://bigtree.readthedocs.io/en/latest/bigtree/tree/export.html)
69-
1. Print to console
69+
1. Print to console, in vertical or horizontal orientation
7070
2. Export to *Newick string notation*, *dictionary*, *nested dictionary*, or *pandas DataFrame*
7171
3. Export tree to *dot* (can save to .dot, .png, .svg, .jpeg files)
7272
4. Export tree to *Pillow* (can save to .png, .jpg)
@@ -182,6 +182,11 @@ root.show()
182182
# │ └── d
183183
# └── c
184184

185+
root.hshow()
186+
# ┌─ b ─── d
187+
# ─ a ─┤
188+
# └─ c
189+
185190
graph = tree_to_dot(root, node_colour="gold")
186191
graph.write_png("assets/docs/demo_tree.png")
187192
```
@@ -389,12 +394,13 @@ root.show(attr_list=["age"])
389394
390395
### Print Tree
391396

392-
After tree is constructed, it can be viewed by printing to console using `show` method directly.
393-
Alternatively, the `print_tree` method can be used.
397+
After tree is constructed, it can be viewed by printing to console using `show` or `hshow` method directly,
398+
for vertical and horizontal orientation respectively.
399+
Alternatively, the `print_tree` or `hprint_tree` method can be used.
394400

395-
{emphasize-lines="8,16,21,27,34,41,49,56,63,70,77,84,91-95"}
401+
{emphasize-lines="8,15,22,27,33,40,47,55,62,69,76,83,90,97-101"}
396402
```python
397-
from bigtree import Node, print_tree
403+
from bigtree import Node, print_tree, hprint_tree
398404

399405
root = Node("a", age=90, gender="F")
400406
b = Node("b", age=65, gender="M", parent=root)
@@ -408,6 +414,12 @@ print_tree(root)
408414
# │ └── e
409415
# └── c
410416

417+
hprint_tree(root)
418+
# ┌─ d
419+
# ┌─ b ─┤
420+
# ─ a ─┤ └─ e
421+
# └─ c
422+
411423
# Print subtree
412424
print_tree(root, node_name_or_path="b")
413425
# b
@@ -531,6 +543,7 @@ Below are the tables of attributes available to `BaseNode` and `Node` classes.
531543
| Check if leaf node | `root.is_leaf` | False |
532544
| Check depth of node | `node_b.depth` | 2 |
533545
| Check depth of tree | `node_b.max_depth` | 4 |
546+
| Get root of tree | `node_b.root` | Node(/a, ) |
534547
| Get node path | `node_b.node_path` | (Node(/a, ), Node(/a/b, )) |
535548
| Get node name (only for `Node`) | `node_b.node_name` | 'b' |
536549
| Get node path name (only for `Node`) | `node_b.path_name` | '/a/b' |
@@ -548,14 +561,18 @@ Below are the tables of attributes available to `BaseNode` and `Node` classes.
548561

549562
Below is the table of operations available to `BaseNode` and `Node` classes.
550563

551-
| Operations | Code | Returns |
552-
|------------------------------------|------------------------------------------------------------|--------------------------------------------|
553-
| Get node information | `root.describe(exclude_prefix="_")` | [('name', 'a')] |
554-
| Find path from one node to another | `root.go_to(node_e)` | [Node(/a, ), Node(/a/b, ), Node(/a/b/e, )] |
555-
| Set attribute(s) | `root.set_attrs({"description": "root-tag"})` | None |
556-
| Get attribute | `root.get_attr("description")` | 'root-tag' |
557-
| Copy tree | `root.copy()` | None |
558-
| Sort children | `root.sort(key=lambda node: node.node_name, reverse=True)` | None |
564+
| Operations | Code | Returns |
565+
|-------------------------------------------------|------------------------------------------------------------|--------------------------------------------|
566+
| Visualize tree (only for `Node`) | `root.show()` | None |
567+
| Visualize tree (horizontally) (only for `Node`) | `root.hshow()` | None |
568+
| Get node information | `root.describe(exclude_prefix="_")` | [('name', 'a')] |
569+
| Find path from one node to another | `root.go_to(node_e)` | [Node(/a, ), Node(/a/b, ), Node(/a/b/e, )] |
570+
| Add child to node | `root.append(Node("j"))` | None |
571+
| Add multiple children to node | `root.extend([Node("k"), Node("l")])` | None |
572+
| Set attribute(s) | `root.set_attrs({"description": "root-tag"})` | None |
573+
| Get attribute | `root.get_attr("description")` | 'root-tag' |
574+
| Copy tree | `root.copy()` | None |
575+
| Sort children | `root.sort(key=lambda node: node.node_name, reverse=True)` | None |
559576

560577
### Traverse Tree
561578

bigtree/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
str_to_tree,
2424
)
2525
from bigtree.tree.export import (
26+
hprint_tree,
27+
hyield_tree,
2628
print_tree,
2729
tree_to_dataframe,
2830
tree_to_dict,

bigtree/tree/export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ def hyield_tree(
494494
>>> c = Node("c", parent=root)
495495
>>> d = Node("d", parent=b)
496496
>>> e = Node("e", parent=b)
497-
>>> tree_str = hyield_tree
498-
>>> print("\n".join(tree_str))
497+
>>> result = hyield_tree(root)
498+
>>> print("\\n".join(result))
499499
┌─ d
500500
┌─ b ─┤
501501
─ a ─┤ └─ e

docs/source/_static/custom.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ header {
2121
h1, h2, h3, h4, p, a {
2222
font-family: Nobile, sans-serif !important;
2323
}
24+
pre {
25+
font-family: monospace;
26+
}
2427
p {
2528
margin-bottom: 2rem;
2629
}

0 commit comments

Comments
 (0)