コード例 #1
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_names_setter_wrong_type(self):
        l = Lineage(
            np.random.random((10, 3)),
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        with pytest.raises(TypeError):
            l.names = ["foo1", "bar1", 3]
コード例 #2
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_names_setter_non_unique(self):
        l = Lineage(
            np.random.random((10, 3)),
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        with pytest.raises(ValueError):
            l.names = ["foo1", "bar1", "bar1"]
コード例 #3
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_color_setter_wrong_colors(self):
        l = Lineage(
            np.random.random((10, 3)),
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        with pytest.raises(ValueError):
            l.colors = ["#ffffff", "#ffffff", "foo"]
コード例 #4
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_colors_setter(self):
        l = Lineage(
            np.random.random((10, 3)),
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        colors = ["#ffffff", "#ffffff", "#ffffff"]
        l.colors = colors

        np.testing.assert_array_equal(l.colors, np.array(colors))
コード例 #5
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_names_setter(self):
        l = Lineage(
            np.random.random((10, 3)),
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        names = ["foo1", "bar1", "baz1"]
        l.names = names

        np.testing.assert_array_equal(l.names, np.array(names))
コード例 #6
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_normal_run(self, lineage: Lineage):
        lin = lineage.reduce(["foo", "bar"])

        assert lin.shape == (10, 2)
        np.testing.assert_allclose(np.sum(lin, axis=1), 1.0)
        np.testing.assert_array_equal(lin.names, ["foo", "bar"])
        np.testing.assert_array_equal(lin.colors, lineage[["foo", "bar"]].colors)
コード例 #7
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_non_unique_names(self):
     with pytest.raises(ValueError):
         _ = Lineage(
             np.random.random((10, 3, 1)),
             names=["foo", "bar", "baz"],
             colors=[(0, 0, 0), "#ffffff", "#ff00FF"],
         )
コード例 #8
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_wrong_colors(self):
     with pytest.raises(ValueError):
         _ = Lineage(
             np.random.random((10, 3)),
             names=["foo", "bar", "baz"],
             colors=[(0, 0, 0), (0.5, 0.5, 0.5), "foobar"],
         )
コード例 #9
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_correct_names_to_ixs(self):
        x = np.random.random((10, 3))
        l = Lineage(x, names=["foo", "bar", "baz"])

        y = l[["baz", "bar"]]

        assert y._names_to_ixs == {"baz": 0, "bar": 1}
コード例 #10
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_automatic_color_assignment(self):
        x = np.random.random((10, 3))
        l = Lineage(x, names=["foo", "bar", "baz"])

        gt_colors = [colors.to_hex(c) for c in _create_categorical_colors(3)]

        np.testing.assert_array_equal(l.colors, gt_colors)
コード例 #11
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_colors_length_mismatch(self):
     with pytest.raises(ValueError):
         _ = Lineage(
             np.random.random((10, 3)),
             names=["foo", "bar", "baz"],
             colors=[(0, 0, 0), (0.5, 0.5, 0.5)],
         )
コード例 #12
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_mutual_info(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce(["foo", "bar"], dist_measure="mutual_info", mode="dist")
     except ValueError:
         pass
     finally:
         mocker.assert_called_once()
コード例 #13
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_wrong_number_of_dimensions(self):
     with pytest.raises(ValueError):
         _ = Lineage(
             np.random.random((10, 3, 1)),
             names=["foo", "bar", "baz"],
             colors=[(0, 0, 0), "#ffffff", "#ff00FF"],
         )
コード例 #14
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_row_normalize(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce(["foo", "bar"], mode="scale")
     except ValueError:
         pass
     finally:
         mocker.assert_called_once()
コード例 #15
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_softmax(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce(["foo", "bar"], normalize_weights="softmax", mode="dist")
     except ValueError:
         pass
     finally:
         mocker.assert_called_once()
コード例 #16
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_rest_all(self):
        x = Lineage(np.random.random((10, 4)), names=["foo", "bar", "baz", "quux"])
        y = x[[Lin.REST]]

        assert y.shape == (10, 1)
        np.testing.assert_array_equal(y.X[:, 0], np.sum(x.X, axis=1))
        np.testing.assert_array_equal(y.names, ["rest"])
コード例 #17
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
 def test_equal(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce(["foo", "bar"], dist_measure="equal", mode="dist")
     except ValueError:
         pass
     finally:
         # should be twice, but we have extra check inside and we're mocking that does nothing
         mocker.assert_called_once()
コード例 #18
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_others_no_effect(self):
        names = ["foo", "bar", "baz", "quux"]
        x = Lineage(np.random.random((10, 4)), names=names)

        y = x[names + [Lin.OTHERS]]

        np.testing.assert_array_equal(x.X, y.X)
        np.testing.assert_array_equal(x.names, y.names)
        np.testing.assert_array_equal(x.colors, y.colors)
コード例 #19
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_creation(self):
        x = np.random.random((10, 3))
        names = ["foo", "bar", "baz"]
        colors = ["#000000", "#ababab", "#ffffff"]
        l = Lineage(x, names=names, colors=colors)

        np.testing.assert_array_equal(l, x)
        np.testing.assert_array_equal(l.names, np.array(names))
        np.testing.assert_array_equal(l.colors, np.array(colors))
コード例 #20
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_same_names(self):
        x = Lineage(np.random.random((10, 4)), names=["foo", "bar", "baz", "quux"])
        y = x[np.arange(len(x)), ["foo"] * len(x)]

        expected = x["foo"]

        assert y.shape == (10, 1)
        np.testing.assert_array_equal(y.X, expected.X)
        np.testing.assert_array_equal(y.names, ["mixture"])
        np.testing.assert_array_equal(y.colors, ["#000000"])
コード例 #21
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_row_subset(self):
        x = Lineage(np.random.random((10, 4)), names=["foo", "bar", "baz", "quux"])
        y = x[:5, ["foo, bar"]]

        expected = np.sum(x.X[:5, [0, 1]], axis=1)[..., np.newaxis]

        assert y.shape == (5, 1)
        np.testing.assert_array_equal(y.X, expected)
        np.testing.assert_array_equal(y.names, ["bar or foo"])
        np.testing.assert_array_equal(y.colors, [_compute_mean_color(x.colors[:2])])
コード例 #22
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_column_subset_boolean_invalid_dim(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x,
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        with pytest.raises(IndexError):
            y = l[:, [True]]
コード例 #23
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_reordering(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x, names=["foo", "bar", "baz"], colors=["#ff0000", "#00ff00", "#0000ff"]
        )

        y = l[["baz", "bar", "foo"]]

        np.testing.assert_array_equal(y.names, ["baz", "bar", "foo"])
        np.testing.assert_array_equal(y.colors, ["#0000ff", "#00ff00", "#ff0000"])
コード例 #24
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_column_invalid_name(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x,
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        with pytest.raises(KeyError):
            y = l["quux"]
コード例 #25
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_others(self):
        names = ["foo", "bar", "baz", "quux"]
        x = Lineage(np.random.random((10, 4)), names=names)

        y = x[["foo, baz"] + [Lin.OTHERS]]
        expected = x[["foo, baz", "bar", "quux"]]

        np.testing.assert_array_equal(y.X, expected.X)
        np.testing.assert_array_equal(y.names, expected.names)
        np.testing.assert_array_equal(y.colors, expected.colors)
コード例 #26
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_row_subset_with_ints(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x,
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        y = l[[1, 2, 3], :]

        np.testing.assert_array_equal(x[[1, 2, 3], :], np.array(y))
コード例 #27
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_same_indices(self):
        x = Lineage(np.random.random((10, 4)), names=["foo", "bar", "baz", "quux"])
        half = len(x) // 2
        y = x[[0] * len(x), ["foo"] * half + ["bar"] * half]

        expected = np.array([x[0, "foo"].X[0, 0]] * half + [x[0, "bar"].X[0, 0]] * half)

        assert y.shape == (10, 1)
        np.testing.assert_array_equal(y.X.squeeze(), expected)
        np.testing.assert_array_equal(y.names, ["mixture"])
        np.testing.assert_array_equal(y.colors, ["#000000"])
コード例 #28
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_column_subset_boolean(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x,
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        y = l[:, [False, False, True]]

        np.testing.assert_array_equal(x[:, -1], y.X.squeeze())
コード例 #29
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_column_subset_with_names(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x,
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        y = l[:, ["foo", "bar"]]

        np.testing.assert_array_equal(x[:, [0, 1]], np.array(y))
コード例 #30
0
ファイル: test_lineage.py プロジェクト: dpeerlab/cellrank
    def test_comb_row_int_col_names(self):
        x = np.random.random((10, 3))
        l = Lineage(
            x,
            names=["foo", "bar", "baz"],
            colors=[(0, 0, 0), (0.5, 0.5, 0.5), (1, 1, 1)],
        )

        y = l[[0, 1], "baz"]

        np.testing.assert_array_equal(x[[0, 1], :][:, [2]], np.array(y))