Skip to main content

High-level description

The PercolationSolver 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

The PercolationSolver 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 (from cassiopeia.solver)
  • dissimilarity_functions (from cassiopeia.solver)
  • solver_utilities (from cassiopeia.solver)
  • CassiopeiaTree (from cassiopeia.data)
  • data_utilities (from cassiopeia.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 input CassiopeiaTree object to store the reconstructed tree.

Internal Logic

  1. Initialization: The class is initialized with a joining solver, prior transformation function, similarity function, and a threshold.
  2. Solve: The solve method 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 percolate method.
    • Finally, it adds duplicate samples to the tree and populates the input CassiopeiaTree object.
  3. Percolate: The percolate method 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_solver and returns the two resulting groups.
  4. Add Duplicates: The __add_duplicates_to_tree method 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 CassiopeiaTree object 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

  1. Similarity Graph: Constructs a weighted graph with samples as nodes and edges weighted by their similarity calculated using the provided similarity_function.
  2. Percolation: Iteratively removes the minimum weighted edges until the graph is disconnected into multiple connected components.
  3. Component Merging (if necessary): If more than two connected components are formed, it clusters them using the joining_solver based on the LCA of each component and returns the two resulting groups.
  4. 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

  1. Identify Duplicates: Identifies groups of samples with identical character states in the character matrix.
  2. 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.
  3. Return Tree: Returns the modified tree with the duplicate samples added.