def test_map_cell_types(self): data = np.random.randint(1, 5, size=(7, 10)) labels = [0, 0, 4, 4, 2, 3, 5] cell_types = ["0", "1", "2", "3", "4", "5"] dataset = GeneExpressionDataset() dataset.populate_from_data(data, labels=labels, cell_types=cell_types) dataset.map_cell_types({("0", "2"): "6", ("3", "4"): "7"}) dataset.remap_categorical_attributes() self.assertListEqual(dataset.cell_types.tolist(), ["5", "6", "7"]) self.assertListEqual( np.squeeze(dataset.labels).tolist(), [1, 1, 2, 2, 1, 2, 0])
def test_merge_cell_types(self): data = np.random.randint(1, 5, size=(8, 20)) labels = [0, 0, 1, 2, 2, 1, 0, 1] cell_types = ["0", "1", "2"] dataset = GeneExpressionDataset() dataset.populate_from_data(data, labels=labels, cell_types=cell_types) dataset.merge_cell_types(["0", "1"], new_cell_type_name="0 and 1") self.assertListEqual([[3], [3], [3], [2], [2], [3], [3], [3]], dataset.labels.tolist()) dataset.remap_categorical_attributes() self.assertListEqual([[1], [1], [1], [0], [0], [1], [1], [1]], dataset.labels.tolist()) self.assertListEqual(["2", "0 and 1"], dataset.cell_types.tolist())