PhyNetPy Documentation

Library for the Development and Use of Phylogenetic Network Methods

Newick Module v1.0.0

Newick format label extraction and Nexus file generation utilities.

Author:
Mark Kessler
Last Edit:
3/11/25
Source:
Newick.py

Exceptions

exception NewickParserError(Exception)

Error class for any exceptions relating to failing to parse a newick string into a Network/Graph object

NexusTemplate

class NexusTemplate

Class that generates a nexus file given tree and biological data.

Constructor

__init__() -> None

Initialize a blank nexus template

Methods

add(newick_str: str) -> None

Create a new line in the "TREES" block.

Parameter Type Description
newick_str str The next network to be added, in newick format.
add_phylonet_cmd(cmd: str) -> None

Add a phylonet command to the nexus file.

Parameter Type Description
cmd str A phylonet command.
load_gene_trees(filename: str) -> None

Load a set of gene trees from a file into the nexus template.

Parameter Type Description
filename str The path to the file containing the gene trees.
generate(loc: Union[Path, str], end_name: str) -> None

Create a nexus file at "<loc>/<end_name>", end_name should include .nex extension.

Parameter Type Description
loc Union[Path, str] Directory location to save the file to. Can either be a python Path obj or simply a string.
end_name str The new file name. Must include .nex extension.
Raises: NewickParserError: If the file location already exists or cannot be found.

Module Functions

get_labels(newick_str: str) -> set[str]

Given a newick string, gather a set of all unique taxa labels present in the string. Strips branch lengths (after ``:``) and NHX comments (after ``[``) so that only bare taxon names are returned.

Parameter Type Description
newick_str str A newick format string (may include a trailing semicolon).
Returns: set[str]: A set of unique taxa labels.

Navigation

Modules

This Page