High-level description

This code defines a test suite for the ClonalSpatialDataSimulator class, which is responsible for simulating spatial data with clonal spatial autocorrelation constraints. The tests cover the initialization of the simulator and the overlay of spatial data onto a CassiopeiaTree object.

Code Structure

The main class TestClonalSpatialDataSimulator contains several test methods that check different aspects of the ClonalSpatialDataSimulator functionality. The setUp method initializes common objects used across multiple tests.

Symbols

TestClonalSpatialDataSimulator

Description

A test class that inherits from unittest.TestCase to test the ClonalSpatialDataSimulator class.

Internal Logic

  1. Sets up a basic tree structure and cell metadata for testing.
  2. Tests the initialization of the simulator with different parameters.
  3. Tests the overlay of spatial data onto a tree without existing cell metadata.
  4. Tests the overlay of spatial data onto a tree with existing cell metadata.

setUp

Description

Initializes the test environment by creating a basic tree structure and cell metadata.

Internal Logic

  1. Sets a random seed for reproducibility.
  2. Creates a directed graph representing a tree topology.
  3. Initializes a CassiopeiaTree object with the created topology.
  4. Creates a DataFrame with cell metadata for some leaves of the tree.

test_init

Description

Tests the initialization of the ClonalSpatialDataSimulator with different parameters.

Internal Logic

  1. Checks that initializing without parameters raises a DataSimulatorError.
  2. Tests initialization with a 2D space, verifying the dimension and space shape.
  3. Tests initialization with a 3D space, verifying the dimension and space shape.

test_overlay_data

Description

Tests the overlay_data method of ClonalSpatialDataSimulator on a basic tree without existing cell metadata.

Internal Logic

  1. Initializes a simulator with a 2D space.
  2. Overlays spatial data onto the basic tree.
  3. Checks that spatial coordinates are assigned to all nodes in the tree.
  4. Verifies that the cell metadata is correctly updated with spatial coordinates for leaf nodes.

test_overlay_data_with_space

Description

Tests the overlay_data method with a custom space parameter.

Internal Logic

Similar to test_overlay_data, but initializes the simulator with a custom space parameter.

test_overlay_data_with_existing_cell_meta

Description

Tests the overlay_data method on a tree with existing cell metadata.

Internal Logic

  1. Initializes a simulator with a 2D space.
  2. Overlays spatial data onto the tree with existing cell metadata.
  3. Verifies that spatial coordinates are assigned to all nodes.
  4. Checks that the existing cell metadata is preserved and new spatial coordinates are added correctly.

Dependencies

DependencyPurpose
unittestProvides the testing framework
networkxUsed for creating and manipulating graph structures
numpyUsed for numerical operations and testing array equality
pandasUsed for handling DataFrames (cell metadata)
cassiopeiaThe main package being tested, provides CassiopeiaTree and ClonalSpatialDataSimulator

Error Handling

The test cases use self.assertRaises to check for expected exceptions, particularly DataSimulatorError when initializing the simulator incorrectly.

Notes

  • The tests use fixed random seeds to ensure reproducibility of spatial coordinate generation.
  • The expected coordinate values in the tests are hardcoded, which might make the tests brittle if the underlying simulation algorithm changes.