Example #1
0
    def test_basic(self):
        test_datas = [(
            "test_a",
            fcs.FCSData(
                (np.array([[1, 2, 3, 10], [4, 2, 5, 99]]).T, np.ones((4, 2))),
                channels=["A", "B"],
            ),
            fcs.FCSData(
                (np.array([[-0.84852815, -0.56568545, -0.28284273, 1.6970563],
                           [-0.56908065, -0.61751306, -0.5448645, 1.7314582]
                           ]).T, np.ones((4, 2))),
                channels=[
                    Marker.name_to_marker(
                        "A",
                        fcs.ChannelMeta(-0.84852815,
                                        1.6970563,
                                        pne=(0, 0),
                                        png=0)),
                    Marker.name_to_marker(
                        "B",
                        fcs.ChannelMeta(-0.61751306,
                                        1.7314582,
                                        pne=(0, 0),
                                        png=0)),
                ]),
        )]

        for name, testdata, expected, in test_datas:
            with self.subTest(name=name):
                model = scalers.FCSStandardScaler()
                result = model.fit_transform(testdata)
                assert_array_almost_equal(result.data, expected.data)
                assert_array_almost_equal(result.ranges_array,
                                          expected.ranges_array)
Example #2
0
    def test_join(self):
        with self.subTest("diff_same_channels"):
            data = np.random.rand(10, 4)
            mask = np.ones((10, 4))
            channels = ["a", "b", "c", "d"]
            first = fcs.FCSData((data, mask), channels=channels)
            data = np.random.rand(10, 4)
            mask = np.ones((10, 4))
            channels = ["a", "b", "c", "d"]
            second = fcs.FCSData((data, mask), channels=channels)
            joined = fcs.join_fcs_data([first, second])
            self.assertEqual(joined.shape, (20, 4))
            self.assertEqual(set(joined.channels), {"a", "b", "c", "d"})

        with self.subTest("diff channels"):
            data = np.random.rand(10, 4)
            mask = np.ones((10, 4))
            channels = ["a", "b", "c", "d"]
            first = fcs.FCSData((data, mask), channels=channels)
            data = np.random.rand(10, 4)
            mask = np.ones((10, 4))
            channels = ["e", "f", "c", "d"]
            second = fcs.FCSData((data, mask), channels=channels)
            joined = fcs.join_fcs_data([first, second])
            self.assertEqual(joined.shape, (20, 6))
            self.assertEqual(set(joined.channels), {
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
            })
Example #3
0
    def test_basic(self):
        fit_to_range = False

        test_datas = [
            ("test_a",
             fcs.FCSData(
                 (np.array([[1, 2, 3, 10], [4, 2, 5, 99]]).T, np.ones((4, 2))),
                 channels=["A", "B"],
             ),
             fcs.FCSData(
                 (np.array([[0.0, 0.111111, 0.222222, 1.0],
                            [0.020619, 0.0, 0.030928, 1.0]]).T, np.ones(
                                (4, 2))),
                 channels=[
                     Marker.name_to_marker(
                         "A", fcs.ChannelMeta(0.0, 1.0, pne=(0, 0), png=0)),
                     Marker.name_to_marker(
                         "B", fcs.ChannelMeta(0.0, 1.0, pne=(0, 0), png=0))
                 ]), False)
        ]

        for name, testdata, expected, fit_to_range in test_datas:
            with self.subTest(name=name, fit_to_range=fit_to_range):
                model = scalers.FCSMinMaxScaler(fit_to_range=fit_to_range)
                result = model.fit_transform(testdata)
                assert_array_almost_equal(result.data, expected.data)
                assert_array_almost_equal(result.ranges_array,
                                          expected.ranges_array)
Example #4
0
 def test_indexing(self):
     data = np.array([
         [0, 1, 2],
         [0, 1, 2],
         [7, 8, 9],
     ])
     testdata = fcs.FCSData((data, np.ones(data.shape)),
                            channels=["A", "B", "C"])
     res = testdata[["A", "B"]]
     assert_array_equal(res.data, np.array([
         [0, 1],
         [0, 1],
         [7, 8],
     ]))
     res = testdata[:, ["A", "B"]]
     assert_array_equal(res.data, np.array([
         [0, 1],
         [0, 1],
         [7, 8],
     ]))
     res = testdata[:, ["B", "A"]]
     assert_array_equal(res.data, np.array([
         [1, 0],
         [1, 0],
         [8, 7],
     ]))
Example #5
0
    def test_add_missing(self):
        data = np.array([
            [0, 1, 2],
            [0, 1, 2],
            [7, 8, 9],
        ])
        testdata = fcs.FCSData((data, np.ones(data.shape)),
                               channels=["A", "B", "C"])
        testdata.add_missing_channels(["D"])
        self.assertEqual(testdata.channels, ["A", "B", "C", "D"])
        assert_array_equal(
            testdata.data,
            np.array([
                [0, 1, 2, 0],
                [0, 1, 2, 0],
                [7, 8, 9, 0],
            ]))
        assert_array_equal(
            testdata.mask,
            np.array([
                [1, 1, 1, 0],
                [1, 1, 1, 0],
                [1, 1, 1, 0],
            ]))

        with self.assertRaises(ValueError):
            testdata.add_missing_channels(["A"])
Example #6
0
 def test_simple(self):
     """Test simple creation of FCS data objects."""
     with self.subTest("from np array"):
         data = np.random.rand(10, 4)
         mask = np.ones((10, 4))
         channels = ["a", "b", "c", "d"]
         fcs.FCSData((data, mask), channels=channels)
Example #7
0
    def get_data(self) -> fcs.FCSData:
        """
        Returns:
            FCS data in dataframe.
        """
        if self.data:
            return self.data

        data = fcs.FCSData(self.complete_path)
        return data
Example #8
0
    def test_basic_train(self):
        model = fcssom.FCSSom(
            (2, 2, 2),
            seed=SEED,
            markers=MARKERS,
        )

        traindata = fcs.FCSData(
            (np.random.rand(1000, 2), np.ones((1000, 2))),
            channels=MARKERS,
        )
        testdata = fcs.FCSData(
            (np.random.rand(1000, 2), np.ones((1000, 2))),
            channels=MARKERS,
        )

        # expected = np.array([
        #     [[0.29068232, 0.3177734], [0.6773688, 0.29500887]],
        #     [[0.3204862, 0.7031209], [0.69967717, 0.672693]],
        # ])
        model.train([traindata])
        result = model.transform(testdata)
Example #9
0
 def test_drop_channels(self):
     data = np.array([
         [0, 1, 2],
         [0, 1, 2],
         [7, 8, 9],
     ])
     testdata = fcs.FCSData((data, np.ones(data.shape)),
                            channels=["A", "B", "C"])
     testdata = testdata.drop_channels(["A"])
     self.assertEqual(testdata.channels, ["B", "C"])
     assert_array_equal(testdata.data, np.array([
         [1, 2],
         [1, 2],
         [8, 9],
     ]))
Example #10
0
 def test_align(self):
     data = np.array([
         [0, 1, 2],
         [0, 1, 2],
         [7, 8, 9],
     ])
     testdata = fcs.FCSData((data, np.ones(data.shape)),
                            channels=["A", "B", "C"])
     aligned = testdata.align(["B", "D", "A"])
     self.assertEqual(aligned.channels, ["B", "D", "A"])
     assert_array_equal(aligned.data,
                        np.array([
                            [1, 0, 0],
                            [1, 0, 0],
                            [8, 0, 7],
                        ]))
     assert_array_equal(aligned.mask,
                        np.array([
                            [1, 0, 1],
                            [1, 0, 1],
                            [1, 0, 1],
                        ]))
Example #11
0
 def test_reorder_channels(self):
     data = np.array([
         [0, 1, 2],
         [0, 1, 2],
         [7, 8, 9],
     ])
     testdata = fcs.FCSData((data, np.ones(data.shape)),
                            channels=["A", "B", "C"])
     testdata = testdata.reorder_channels(["B", "A", "C"])
     self.assertEqual(testdata.channels, ["B", "A", "C"])
     assert_array_equal(testdata.data,
                        np.array([
                            [1, 0, 2],
                            [1, 0, 2],
                            [8, 7, 9],
                        ]))
     testdata = testdata.reorder_channels(["C", "B", "A"])
     self.assertEqual(testdata.channels, ["C", "B", "A"])
     assert_array_equal(testdata.data,
                        np.array([
                            [2, 1, 0],
                            [2, 1, 0],
                            [9, 8, 7],
                        ]))
Example #12
0
 def test_marker_to_name_only(self):
     testdata = fcs.FCSData((np.zeros((10, 4)), np.zeros((10, 4))),
                            channels=["a-a", "b-b", "c-c", "d-d"])
     testdata.marker_to_name_only()
     self.assertEqual(testdata.channels, ["a", "b", "c", "d"])
Example #13
0
 def test_rename(self):
     testdata = fcs.FCSData((np.zeros((10, 4)), np.zeros((10, 4))),
                            channels=["a", "b", "c", "d"])
     testdata.rename({"a": "z"})
     self.assertEqual(testdata.channels, ["z", "b", "c", "d"])