High-level description

This directory contains unit tests for the plotting functionality in the Cassiopeia project. It includes tests for various plotting utilities, local 2D and 3D plotting, and iTOL (Interactive Tree of Life) plotting. The tests cover a wide range of functions and classes related to tree visualization, color manipulation, coordinate transformations, and data representation.

What does it do?

The test suite in this directory ensures the correctness and reliability of Cassiopeia’s plotting capabilities. It verifies:

  1. Basic utility functions for color manipulation, coordinate transformations, and tree placement.
  2. Generation of color strips and indel heatmaps for tree visualization.
  3. 2D plotting functionality using both matplotlib and plotly backends.
  4. 3D tree plotting and spatial data representation.
  5. Integration with iTOL for online tree visualization and export.

These tests help maintain the integrity of Cassiopeia’s plotting features, ensuring that researchers can reliably visualize and analyze their phylogenetic data.

Key Files

itol_plotting_test.py

This file tests the iTOL plotting utilities. It verifies the creation of gradient files, colorbar files, and allele heatmaps for iTOL visualization. It also tests the integrated pipeline for uploading and exporting trees to iTOL.

Key tests include:

  • Generation of gradient and colorbar files
  • Creation of allele heatmaps with various color specifications
  • Integrated pipeline for uploading and exporting trees to iTOL

local_3d_test.py

This file contains tests for 3D plotting of tree structures. It verifies functions related to coordinate interpolation, color manipulation, label generation, and the main Tree3D class.

Key tests include:

  • Interpolation of branch coordinates
  • Color mixing and manipulation functions
  • Generation of labels from spatial coordinates
  • Initialization and basic functionality of the Tree3D class

local_test.py

This file tests the local 2D plotting functionality. It covers color strip creation, indel heatmap generation, and the main plotting functions for both matplotlib and plotly backends.

Key tests include:

  • Computation of color strip sizes
  • Creation of categorical and continuous color strips
  • Generation of indel heatmaps
  • Plotting using matplotlib and plotly
  • Creation of clade colors for nodes and branches

utilities_test.py

This file tests various utility functions used in plotting trees and other visualizations. It covers functions for coordinate transformations, color generation, and tree placement.

Key tests include:

  • Conversion between degrees and radians
  • Conversion between polar and Cartesian coordinates
  • Generation of random colors
  • Placement of tree nodes and branches
  • Color conversion between hex and RGB formats
  • Generation of indel colors based on priors

Dependencies

The test suite relies on the following main dependencies:

  • unittest: For the testing framework
  • networkx: For graph and tree operations
  • numpy: For numerical computations
  • pandas: For data manipulation
  • matplotlib and plotly: For plotting backends
  • cassiopeia: The main package being tested

Configuration

Some tests, particularly those related to iTOL integration, may require a configuration file (~/.itolconfig) for iTOL credentials. Tests that depend on this configuration are skipped if the file is not present.

The tests use various fixtures and setup methods to create sample data, including:

  • Random number generation with fixed seeds for reproducibility
  • Sample trees and allele tables
  • Indel priors and color maps

These configurations ensure consistent and reproducible test results across different environments.