Quickstart#

Get started with PhyloZoo in minutes! This guide walks you through installation, creating networks, and working with related data types, at every step referring to the corresponding section in the manual.

Getting Started#

Install PhyloZoo using pip. For most users (including visualization), use:

pip install phylozoo[viz]

For a minimal install without plotting, use pip install phylozoo. See the Installation Guide for full details.

Networks#

Let’s create a simple phylogenetic network:

from phylozoo import DirectedPhyNetwork

# Create a simple tree network
network = DirectedPhyNetwork(
    edges=[("root", "A"), ("root", "B"), ("root", "C")],
    nodes=[
        ("A", {"label": "A"}),
        ("B", {"label": "B"}),
        ("C", {"label": "C"})
    ]
)

print(f"Network has {network.number_of_nodes()} nodes")
print(f"Leaves: {network.leaves}")
print(f"Is tree: {network.is_tree()}")

This creates a simple tree with three leaves.

Now let’s create a network with a hybrid node. Hybrid edges use a gamma value (must sum to 1.0 for edges into the same hybrid):

from phylozoo.core.network.dnetwork.classifications import level

# Create a network with hybridization
# Edge attributes (e.g. gamma) are passed as dicts with "u" and "v" keys
hybrid_net = DirectedPhyNetwork(
    edges=[
        ("root", "u1"), ("root", "u2"),          # Root to tree nodes
        {"u": "u1", "v": "h", "gamma": 0.6},     # Hybrid edge
        {"u": "u2", "v": "h", "gamma": 0.4},     # Hybrid edge (must sum to 1.0)
        ("h", "leaf_a"),                          # Hybrid to leaf
        ("u1", "leaf_b"),                         # Extra leaf on u1
        ("u2", "leaf_c"),                         # Extra leaf on u2
    ],
    nodes=[
        ("leaf_a", {"label": "A"}),
        ("leaf_b", {"label": "B"}),
        ("leaf_c", {"label": "C"}),
    ]
)

print(f"Network level: {level(hybrid_net)}")

PhyloZoo also supports semi-directed networks, which allow undirected tree edges for modeling root uncertainty. See Semi-Directed Networks for details.

Load and Save#

Networks can be saved and loaded in standard formats:

# Save network to file (eNewick format)
network.save("my_network.enewick")

# Load network from file
loaded_net = DirectedPhyNetwork.load("my_network.enewick")

Supported formats include eNewick, NEXUS, and DOT. See the I/O overview for all formats.

Visualization#

Plot networks with the built-in visualization module:

import matplotlib.pyplot as plt
from phylozoo.viz import plot

# Plot network (opens interactive window)
plot(network, show=True)

# Save to file via matplotlib
fig, ax = plt.subplots()
plot(network, ax=ax)
fig.savefig("network.png")

For layout options and styling, see Visualization.

Next Steps#

Ready to dive deeper? Check out:

  1. The Manual for comprehensive guides on all modules

  2. The API Reference for complete function signatures and examples