High-level description
ThePercolationSolver class implements a top-down, percolation-based algorithm for reconstructing phylogenetic trees. It recursively partitions a set of samples based on their similarity in observed mutations, creating a tree structure where similar samples are grouped closer together.
Code Structure
ThePercolationSolver class is initialized with a joining solver, prior transformation function, similarity function, and a threshold. The solve method orchestrates the tree reconstruction process by recursively partitioning the sample set using the percolate method. The percolate method constructs a similarity graph, removes edges based on similarity, and partitions the graph into clades. If more than two clades are formed, the joining_solver is used to cluster them. Finally, the __add_duplicates_to_tree method adds duplicate samples to the tree.
References
This code references the following symbols:CassiopeiaSolver(fromcassiopeia.solver)dissimilarity_functions(fromcassiopeia.solver)solver_utilities(fromcassiopeia.solver)CassiopeiaTree(fromcassiopeia.data)data_utilities(fromcassiopeia.data.utilities)
Symbols
PercolationSolver
Description
This class implements the Percolation algorithm for phylogenetic tree reconstruction. It takes a character matrix and optional priors as input and builds a tree by recursively partitioning the sample set based on their similarity in observed mutations.Inputs
Outputs
This class doesn’t directly return any output. It modifies the inputCassiopeiaTree object to store the reconstructed tree.
Internal Logic
- Initialization: The class is initialized with a joining solver, prior transformation function, similarity function, and a threshold.
- Solve: The
solvemethod orchestrates the tree reconstruction process.- It first extracts the character matrix and transforms the priors into weights if provided.
- It then creates a NetworkX graph and recursively partitions the sample set using the
percolatemethod. - Finally, it adds duplicate samples to the tree and populates the input
CassiopeiaTreeobject.
- Percolate: The
percolatemethod partitions a set of samples into two groups based on their similarity.- It constructs a similarity graph with samples as nodes and edges weighted by their similarity.
- It then iteratively removes the minimum weighted edges until the graph is disconnected into multiple components.
- If more than two components are formed, it clusters them using the
joining_solverand returns the two resulting groups.
- Add Duplicates: The
__add_duplicates_to_treemethod adds duplicate samples to the tree by finding groups of samples with identical character states and placing them as sister nodes under a new internal node.
Side Effects
- Modifies the input
CassiopeiaTreeobject to store the reconstructed tree.
percolate
Description
Partitions a set of samples into two groups based on their similarity in the character matrix.Inputs
Outputs
Internal Logic
- Similarity Graph: Constructs a weighted graph with samples as nodes and edges weighted by their similarity calculated using the provided
similarity_function. - Percolation: Iteratively removes the minimum weighted edges until the graph is disconnected into multiple connected components.
- Component Merging (if necessary): If more than two connected components are formed, it clusters them using the
joining_solverbased on the LCA of each component and returns the two resulting groups. - Return Partitions: Returns a tuple containing two lists of sample names, representing the left and right partitions.
__add_duplicates_to_tree
Description
Adds duplicate samples to the tree.Inputs
Outputs
Internal Logic
- Identify Duplicates: Identifies groups of samples with identical character states in the character matrix.
- Add Duplicates: For each group of duplicates:
- Creates a new internal node as the parent of the duplicates.
- Connects the original sample and all its duplicates as children of this new internal node.
- Return Tree: Returns the modified tree with the duplicate samples added.
