snpio.analysis.tree_parser.TreeParser
- class snpio.analysis.tree_parser.TreeParser(genotype_data, treefile, qmatrix=None, siterates=None, verbose=False, debug=False)[source]
TreeParser class for reading and manipulating phylogenetic trees.
This class provides methods for reading, writing, and manipulating phylogenetic trees. The TreeParser class provides functionality for working with phylogenetic trees. The TreeParser class can read phylogenetic trees from Newick or NEXUS format files, calculate basic statistics for the tree, extract subtrees, prune the tree, reroot the tree, and calculate pairwise distance matrices.
Example
>>> tp = TreeParser( ... genotype_data=gd_filt, ... treefile="snpio/example_data/trees/test.tre", ... qmatrix="snpio/example_data/trees/test.iqtree", ... siterates="snpio/example_data/trees/test14K.rate", ... show_plots=True, ... verbose=True, ... debug=False, ... ) >>> >>> tree = tp.read_tree() >>> print(tp.tree_stats()) >>> tp.reroot_tree("~EA") >>> print(tp.get_distance_matrix()) >>> print(tp.qmat) >>> print(tp.site_rates) >>> subtree = tp.get_subtree("~EA") >>> pruned_tree = tp.prune_tree("~ON") >>> print(tp.write_tree(subtree, save_path=None)) >>> print(tp.write_tree(pruned_tree, save_path=None)
- genotype_data
GenotypeData object containing the SNP data.
- Type:
GenotypeData
- treefile
Path to the phylogenetic tree file.
- Type:
str
- qmatrix
Path to the Q matrix file.
- Type:
str
- siterates
Path to the site rates file.
- Type:
str
- verbose
Whether to display verbose output.
- Type:
bool
- debug
Whether to display debug output.
- Type:
bool
- __init__(genotype_data, treefile, qmatrix=None, siterates=None, verbose=False, debug=False)[source]
Initialize the TreeParser object.
This class provides methods for reading, writing, and manipulating phylogenetic trees. The TreeParser class provides functionality for working with phylogenetic trees. The TreeParser class can read phylogenetic trees from Newick or NEXUS format files, calculate basic statistics for the tree, extract subtrees, prune the tree, reroot the tree, and calculate pairwise distance matrices.
- Parameters:
genotype_data (Any) – GenotypeData object containing the SNP data.
treefile (str) – Path to the phylogenetic tree file.
qmatrix (str, optional) – Path to the Q matrix file. Defaults to None.
siterates (str, optional) – Path to the site rates file. Defaults to None.
verbose (bool, optional) – Whether to display verbose output. Defaults to False.
debug (bool, optional) – Whether to display debug output. Defaults to False.
Methods
__init__(genotype_data, treefile[, qmatrix, ...])Initialize the TreeParser object.
get_distance_matrix()Calculate the pairwise distance matrix between all tips in the tree.
get_subtree(regex)Get a subtree rooted at a specified node or tip.
load_tree_from_string(newick_str)Load a phylogenetic tree from a Newick string.
prune_tree(taxa)Prune the tree by removing a set of taxa (leaf nodes).
read_tree()Read Newick or NEXUS-style phylogenetic tree into toytree object.
reroot_tree(node)Reroot the tree at a specific node or tip.
tree_stats()Calculate basic statistics for the phylogenetic tree.
write_tree(tree[, save_path, nexus])Write the phylogenetic tree to a file.
Attributes
qmatGet q-matrix object for a corresponding phylogenetic tree.
site_ratesGet site rate data for phylogenetic tree.
treeGet newick tree from provided path.