High-level description

This file contains unit tests for the iTOL plotting utilities in the cassiopeia.plotting.itol_utilities module. It tests various functions related to generating files for iTOL visualization, including gradient files, colorbar files, and allele heatmaps. The tests also cover the integrated pipeline for uploading and exporting trees to iTOL.

Code Structure

The code is structured as a single test class TestITOLPlotting that inherits from unittest.TestCase. It contains several test methods, each testing a specific functionality of the iTOL plotting utilities. The class uses a setUp method to initialize common test data and a tearDown method to clean up temporary files.

Symbols

TestITOLPlotting

Description

A test class that contains unit tests for iTOL plotting utilities.

Internal Logic

  1. Sets up test data in setUp method, including a temporary directory, random state, indel priors, allele table, and a test tree.
  2. Implements various test methods to check different functionalities.
  3. Cleans up temporary files in tearDown method.

test_generate_gradient_file

Description

Tests the creation of a gradient file for iTOL visualization.

Internal Logic

  1. Calls itol_utilities.create_gradient_from_df with test data.
  2. Verifies that the file is created and its content matches the expected output.

test_generate_colorbar_file

Description

Tests the creation of a colorbar file for iTOL visualization without a legend.

Internal Logic

  1. Defines a color map for test data.
  2. Calls itol_utilities.create_colorbar with test data and color map.
  3. Verifies that the file is created and its content matches the expected output.

test_generate_colorbar_file_with_legend

Description

Tests the creation of a colorbar file for iTOL visualization with a legend.

Internal Logic

Similar to test_generate_colorbar_file, but sets create_legend=True and verifies the legend content in the output file.

test_create_allele_heatmap_specified_colors

Description

Tests the creation of an allele heatmap with specified colors.

Internal Logic

  1. Defines indel colors.
  2. Calls itol_utilities.create_indel_heatmap with test data and specified colors.
  3. Verifies that the correct number of files are created and that they exist.

test_create_allele_heatmap_specified_priors

Description

Tests the creation of an allele heatmap with specified indel priors.

Internal Logic

Similar to test_create_allele_heatmap_specified_colors, but uses indel priors instead of specified colors.

test_create_allele_heatmap_no_priors_or_colormap

Description

Tests the creation of an allele heatmap without specifying priors or a color map.

Internal Logic

Calls itol_utilities.create_indel_heatmap with only the basic required parameters and verifies the output files.

test_integrated_pipeline_simple_tree

Description

Tests the integrated pipeline for uploading and exporting a simple tree to iTOL.

Internal Logic

  1. Calls cas.pl.upload_and_export_itol with a simple tree.
  2. Verifies that the exported file exists.

test_integrated_pipeline_tree_with_allele_heatmap

Description

Tests the integrated pipeline for uploading and exporting a tree with an allele heatmap to iTOL.

Internal Logic

Similar to test_integrated_pipeline_simple_tree, but includes an allele table in the parameters.

test_integrated_pipeline_tree_with_meta_data

Description

Tests the integrated pipeline for uploading and exporting a tree with metadata to iTOL.

Internal Logic

Similar to test_integrated_pipeline_simple_tree, but includes metadata parameters.

Dependencies

  • unittest
  • os
  • shutil
  • tempfile
  • networkx
  • numpy
  • pandas
  • cassiopeia

Configuration

The tests use a configuration file ~/.itolconfig for iTOL credentials. Some tests are skipped if this file doesn’t exist.

Error Handling

The tests use unittest assertions to check for expected outcomes and file existence.

Performance Considerations

The tests create and delete temporary files and directories, which may impact performance on slower file systems.

TODOs

None explicitly mentioned in the code.