|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +"""Tests for ClusterPlot.""" |
| 4 | + |
| 5 | +import unittest |
| 6 | + |
| 7 | +from stlearn.adds import row_annotations |
| 8 | +from tests.utils import read_test_data, test_data_path |
| 9 | + |
| 10 | + |
| 11 | +class TestRowAnnotations(unittest.TestCase): |
| 12 | + """Tests for row annotations.""" |
| 13 | + |
| 14 | + @classmethod |
| 15 | + def setUpClass(cls): |
| 16 | + cls._base_adata = read_test_data() |
| 17 | + cls.annotations_path = ( |
| 18 | + f"{test_data_path()}/" + "v1_human_breast_cancer_block_a_section_1.csv" |
| 19 | + ) |
| 20 | + |
| 21 | + |
| 22 | +def setUp(self): |
| 23 | + """Set up test data with known clusters.""" |
| 24 | + self.adata = self.__class__._base_adata.copy() |
| 25 | + |
| 26 | + |
| 27 | +def test_add_row_annotations(self): |
| 28 | + row_annotations.row_annotations(self.adata, self.__class__.annotations_path, "ID") |
| 29 | + |
| 30 | + assert "annot_type" in self.adata.obs.columns |
| 31 | + assert "fine_annot_type" in self.adata.obs.columns |
| 32 | + |
| 33 | + # Check annotated the same number |
| 34 | + annotated = self.adata.obs["annot_type"].dropna() |
| 35 | + fine_annotated = self.adata.obs["fine_annot_type"].dropna() |
| 36 | + assert len(fine_annotated) == len(annotated) |
| 37 | + |
| 38 | + |
| 39 | +def test_add_row_annotations_with_missing_column(self): |
| 40 | + with self.assertRaises(ValueError): |
| 41 | + row_annotations.row_annotations( |
| 42 | + self.adata, |
| 43 | + self.__class__.annotations_path, |
| 44 | + join_column="nonexistent_column", |
| 45 | + ) |
0 commit comments