Version target: 0.3.x
Phylo3D-Trait is a Python CLI/library for interactive 3D visualization of continuous trait evolution on phylogenetic trees. It maps tree layout, supplied node-associated trait values, and—when branch lengths represent time—evolutionary age into a rectangular 3D phylogram.
It is a visualization engine. It does not infer trees, date trees, fit evolutionary models, or perform ancestral-state reconstruction (ASR).
X = tree layout
Y = continuous trait value
Z = branch-length-derived evolutionary depth / time before present
For time-calibrated trees with contemporaneous tips, Z can be interpreted as time before present. If branch lengths are substitutions/site or their meaning is unknown, do not label or interpret Z as Ma.
Top branch geometry follows the supplied trait trajectory. Curtain color can either follow geometric height (height) or project the local branch trait vertically to the baseline (branch).
Supported formats:
Before scientific interpretation verify:
The minimum columns are:
node_id,trait
Species_A,1.25
Species_B,2.10
clade:xxxxxxxxxxxx,1.64
All terminal tips, internal nodes, and the root require explicit numeric values. Missing required node values must fail loudly; never silently impute them.
Internal-node identifiers are deterministic hashes of descendant tip sets. For each internal node, Phylo3D-Trait trims descendant tip names, removes duplicates, sorts them lexicographically, joins them with a literal comma and no spaces, computes SHA-256 on the UTF-8 string, keeps the first 12 lowercase hexadecimal characters, and prefixes clade:.
Exact rule:
clade_id = "clade:" + sha256(
",".join(sorted(set(descendant_tips))).encode("utf-8")
).hexdigest()[:12]
Example:
descendant tips: Species_B, Species_A
canonical key: Species_A,Species_B
stable node ID: clade:9a97b9510492
This makes the ID independent of child ordering in the Newick tree. Tip-name spelling, capitalization, punctuation, or whitespace after trimming still matter because they change the canonical key.
Users should normally generate these IDs with template-values rather than calculate or guess them manually; the generated template includes each node_id together with its descendant-tip list.
python -m phylo3d_trait.cli template-values \
--tree tree.nwk \
--output node_values_template.csv
The template contains tip names plus stable clade:<hash> identifiers for internal nodes/root.
Fill the trait column using the values produced by the user’s scientific workflow. ASR may come from tools such as phytools::fastAnc(), ape::ace(), or other BM/OU/ML/Bayesian workflows; Phylo3D-Trait itself does not calculate these values.
Recommended Four-Layer renderer:
python -m phylo3d_trait.cli plot \
--tree tree.nwk \
--values node_values.csv \
--output tree3d.html \
--renderer four-layer \
--opacity 0.85 \
--curtain-color-mode branch \
--centerline-color trait
The HTML is standalone and can be opened locally in a modern WebGL2-capable browser.
--renderer four-layer) — recommendedFour-layer depth peeling is bounded rather than infinite-depth compositing. Very deep overlap can omit fragments beyond the peeled layers; the renderer reports the relevant omission bound.
--renderer plotly)Use for legacy workflows or when Plotly-specific interaction/layout behavior is desired. Transparent Mesh3d surfaces use Plotly/WebGL transparency semantics and may show order-dependent artifacts.
Run the live CLI help before relying on a copied command:
python -m phylo3d_trait.cli --help
python -m phylo3d_trait.cli template-values --help
python -m phylo3d_trait.cli plot --help
Frequently used options:
--renderer {four-layer,plotly}--opacity--curtain-color-mode {height,branch}--colorscale--reverse-colorscale--centerline-color--baseline-y--baseline-raw-value--trait-display-offset--trait-display-range--trait-axis-scale--camera-preset {elife,root_front,tips_front}--tip-label-offset--no-labels--no-x-axis, --no-y-axis, --no-z-axis--no-tip-hover, --no-internal-hover--no-mesh, --no-centerline--show-node-markers--reverse-colorscale reverses color lookup only; it must not be used as a substitute for changing trait geometry.
--trait-axis-scale is visual scaling only; it does not alter scientific trait values.
Stable installation from PyPI:
pip install phylo3d-trait
For development from source:
git clone https://github.com/hk20013106/Phylo3D-Trait.git
cd Phylo3D-Trait
pip install -e .
For tests:
pip install -e ".[dev]"
pytest tests/ -v
Python support declared by the package: 3.10+.
The CLI is the recommended user interface. Current public imports include:
from phylo3d_trait import (
parse_tree,
build_plot_data,
build_figure,
build_four_layer_html,
)
from phylo3d_trait.io import load_trait_values
For Four-Layer output:
tree = parse_tree("tree.nwk")
traits = load_trait_values("node_values.csv")
plot_data = build_plot_data(tree, traits)
html = build_four_layer_html(
plot_data,
opacity=0.85,
camera_preset="elife",
centerline_color="trait",
)
with open("tree3d.html", "w", encoding="utf-8") as fh:
fh.write(html)
Always check the current package API/CLI before generating code; do not infer function names from old documentation.
For AI agents and coding assistants:
README.md and this guide.template-values; do not invent internal-node IDs.pytest tests/ -v after source changes.Phylo3D-Trait is not:
It is intended to visualize already defined phylogenies and already supplied continuous node values.
Use GitHub Issues for reproducible bugs and feature requests. For rendering bugs, include:
Pull requests are welcome. See CONTRIBUTING.md.