示例#1
0
    def test_read_events_num(self):
        df = DataFrame(self.data, columns=self.short_channels)
        s3_file_path = f"s3://{self.bucket_name}/test.fcs"
        df.to_fcs(s3_file_path)

        num = read_events_num(s3_file_path)
        assert num == len(self.data)
示例#2
0
文件: test_fcs.py 项目: nehcgnay/fcsy
 def test_data(self):
     with TmpDir() as dir_:
         filename = os.path.join(dir_, self.name)
         df = DataFrame(self.data, columns=self.channels)
         df.to_fcs(filename)
         fcs = Fcs.from_file(filename)
         assert np.array_equal(fcs.values, self.data)
示例#3
0
    def test_rename_channels(self):
        cols = pd.MultiIndex.from_tuples(
            list(zip(self.short_channels, self.long_channels)),
            names=["short", "long"],
        )
        df = DataFrame(self.data, columns=cols)
        s3_file_path = f"s3://{self.bucket_name}/test.fcs"
        df.to_fcs(s3_file_path)

        rename_channels(s3_file_path, {
            "a": "a_1",
            "d": "d_1"
        },
                        "short",
                        allow_rewrite=True)

        dfr = DataFrame.from_fcs(s3_file_path, channel_type="multi")

        np.testing.assert_array_equal(
            ["a_1", "b", "c", "d_1"],
            dfr.columns.get_level_values("short").values,
        )
        np.testing.assert_array_equal(
            list("ABCD"),
            dfr.columns.get_level_values("long").values,
        )

        ln = ""
        for i in range(30):
            ln = ln + str(i)
        rename_channels(s3_file_path, {"C": ln}, "long", allow_rewrite=True)
        assert ["A", "B", ln, "D"] == read_channels(s3_file_path, "long")
示例#4
0
    def test_rename_channels_alt(self):
        with TmpDir() as dir_:
            df = DataFrame(
                self.data,
                columns=pd.MultiIndex.from_tuples(
                    zip(self.short_channels, self.long_channels),
                    names=["short", "long"],
                ),
            )
            filename = os.path.join(dir_, self.name)
            df.to_fcs(filename)

            ln = ""
            for i in range(30):
                ln = ln + str(i)

            with pytest.raises(ValueError) as err:
                rename_channels(filename, {"a_di": ln}, "short")
            assert (
                str(err.value) ==
                "New channel names are too long causing overlap with Data Segment."
            )

            rename_channels(filename, {"a_di": ln},
                            "short",
                            allow_rewrite=True)
            df2 = DataFrame.from_fcs(filename)

            assert_almost_equal(df.values, df2.values)
示例#5
0
文件: test_fcs.py 项目: nehcgnay/fcsy
 def test_count(self):
     with TmpDir() as dir_:
         filename = os.path.join(dir_, self.name)
         df = DataFrame(self.data, columns=self.channels)
         df.to_fcs(filename)
         fcs = Fcs.from_file(filename)
         assert fcs.count == len(self.data)
示例#6
0
 def test_read_fcs(self):
     with TmpDir() as dir_:
         filename = os.path.join(dir_, self.name)
         df = DataFrame(self.data, columns=self.short_channels)
         df.to_fcs(filename)
         df2 = read_fcs(filename)
         assert_frame_equal(df, df2)
示例#7
0
    def test_rename_channels_alt(self):
        cols = pd.MultiIndex.from_tuples(
            list(zip(self.short_channels, self.long_channels)),
            names=["short", "long"],
        )
        df = DataFrame(self.data, columns=cols)
        s3_file_path = f"s3://{self.bucket_name}/test.fcs"
        df.to_fcs(s3_file_path)

        with pytest.raises(ValueError) as e:
            rename_channels(s3_file_path,
                            dict(zip(self.short_channels, list("abcd"))),
                            "short")
        assert str(
            e.value) == "S3 url is only supported when allow_rewrite is set."

        ln = ""
        for i in range(30):
            ln = ln + str(i)
        with pytest.raises(ValueError) as e:
            rename_channels(s3_file_path, {"c": ln}, "short")
        assert (
            str(e.value) ==
            "New channel names are too long causing overlap with Data Segment."
        )
示例#8
0
文件: test_fcs.py 项目: nehcgnay/fcsy
 def test_read_text_segment(self):
     with TmpDir() as dir_:
         filename = os.path.join(dir_, self.name)
         cols = pd.MultiIndex.from_tuples(
             list(zip(self.channels, self.long_channels)),
             names=["short", "long"],
         )
         df = DataFrame(self.data, columns=cols)
         df.to_fcs(filename)
         seg = Fcs.read_text_segment(filename)
         assert seg.pnn == self.channels
         assert seg.pns == self.long_channels
示例#9
0
 def test_read_channels(self):
     cols = pd.MultiIndex.from_tuples(
         list(zip(self.short_channels, self.long_channels)),
         names=["short", "long"],
     )
     df = DataFrame(self.data, columns=cols)
     s3_file_path = f"s3://{self.bucket_name}/test.fcs"
     df.to_fcs(s3_file_path)
     assert read_channels(s3_file_path, "short") == self.short_channels
     assert read_channels(s3_file_path, "long") == self.long_channels
     np.testing.assert_array_equal(read_channels(s3_file_path, "multi"),
                                   cols)
示例#10
0
    def test_to_fcs(self):
        with TmpDir() as dir_:
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.short_channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            df.to_fcs(f"s3://{self.bucket_name}/test.fcs")
            filename = os.path.join(dir_, "test.fcs")
            self.s3.download_file(self.bucket_name, "test.fcs", filename)

            dfr = DataFrame.from_fcs(filename, channel_type="multi")
            assert_frame_equal(df, dfr)
示例#11
0
    def test_read_events_num(self):
        with TmpDir() as dir_:
            filename = os.path.join(dir_, "test.fcs")
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.short_channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            df.to_fcs(filename)

            with open(filename, "rb") as fp:
                num = read_events_num(fp)
            assert num == len(self.data)
示例#12
0
    def test_to_fcs(self):
        with TmpDir() as dir_:
            filename = os.path.join(dir_, "test.fcs")
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.short_channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            with open(filename, "wb") as fp:
                df.to_fcs(fp)

            dfr = DataFrame.from_fcs(filename, channel_type="multi")
            assert_frame_equal(df, dfr)
示例#13
0
    def test_read_channels(self):
        with TmpDir() as dir_:
            filename = os.path.join(dir_, "test.fcs")
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.short_channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            df.to_fcs(filename)

            assert read_channels(filename, "short") == self.short_channels
            assert read_channels(filename, "long") == self.long_channels
            np.testing.assert_array_equal(read_channels(filename, "multi"),
                                          cols)
示例#14
0
 def test_write_fcs(self):
     with TmpDir() as dir_:
         filename = os.path.join(dir_, self.name)
         df = DataFrame(self.data, columns=self.short_channels)
         write_fcs(df, filename, long_names=self.long_channels)
         df = DataFrame.from_fcs(filename, "multi")
         np.testing.assert_array_equal(df.values, self.data)
         np.testing.assert_array_equal(
             df.columns,
             pd.MultiIndex.from_tuples(
                 zip(self.short_channels, self.long_channels),
                 names=["short", "long"],
             ),
         )
示例#15
0
 def test_read_events_num(self):
     with TmpDir() as dir_:
         filename = os.path.join(dir_, self.name)
         df = DataFrame(self.data, columns=self.short_channels)
         write_fcs(df, filename, long_names=self.long_channels)
         num = read_events_num(filename)
         assert num == 2
示例#16
0
    def test_read_text_segment(self):
        with TmpDir() as dir_:
            filename = os.path.join(dir_, "test.fcs")
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            df.to_fcs(filename)

            self.s3.upload_file(filename, self.bucket_name, "test.fcs")

            parse_func = create_open_func(S3ReadBuffer, bucket=self.bucket_name)

            with parse_func("test.fcs") as fp:
                seg = Fcs.read_text_segment(fp)
            assert seg.pnn == self.channels
            assert seg.pns == self.long_channels
示例#17
0
    def test_from_fcs(self):
        with TmpDir() as dir_:
            filename = os.path.join(dir_, "test.fcs")
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            df.to_fcs(filename)

            self.s3.upload_file(filename, self.bucket_name, "test.fcs")
            parse_func = create_open_func(S3ReadBuffer, bucket=self.bucket_name)

            with parse_func("test.fcs") as fp:
                fcs = Fcs.from_file(fp)
                assert fcs.short_channels == self.channels
                assert fcs.long_channels == self.long_channels
                assert fcs.count == len(self.data)
                assert np.array_equal(fcs.values, self.data)
示例#18
0
    def test_rename_channels(self):
        with TmpDir() as dir_:
            filename = os.path.join(dir_, "test.fcs")
            cols = pd.MultiIndex.from_tuples(
                list(zip(self.short_channels, self.long_channels)),
                names=["short", "long"],
            )
            df = DataFrame(self.data, columns=cols)
            df.to_fcs(filename)

            with open(filename, "rb+") as fp:
                rename_channels(fp, dict(zip(self.short_channels,
                                             list("wxyz"))), "short")

            with open(filename, "rb+") as fp:
                rename_channels(fp, dict(zip(self.long_channels,
                                             list("WXYZ"))), "long")

            assert read_channels(filename, "short") == list("wxyz")
            assert read_channels(filename, "long") == list("WXYZ")
示例#19
0
    def test_rename_channels(self):
        with TmpDir() as dir_:
            df = DataFrame(
                self.data,
                columns=pd.MultiIndex.from_tuples(
                    zip(self.short_channels, self.long_channels),
                    names=["short", "long"],
                ),
            )
            filename = os.path.join(dir_, self.name)
            df.to_fcs(filename)
            rename_channels(filename,
                            dict(zip(self.short_channels, list("abcd"))),
                            "short")
            short_channels = read_channels(filename, "short")
            assert short_channels == list("abcd")

            rename_channels(filename,
                            dict(zip(self.long_channels, list("ABCD"))),
                            "long")
            long_channels = read_channels(filename, "long")
            assert long_channels == list("ABCD")

            data = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
            columns = pd.MultiIndex.from_tuples(list(zip("abc", "ABC")),
                                                names=["short", "long"])
            df = DataFrame(data, columns=columns)
            filename = os.path.join(dir_, self.name)
            df.to_fcs(filename)
            rename_channels(filename, {
                "a": "a_1",
                "b": "b_1",
                "c": "c_1"
            },
                            channel_type="short")
            short_channels = read_channels(filename, "short")
            long_channels = read_channels(filename, "long")
            assert short_channels == ["a_1", "b_1", "c_1"]
            assert long_channels == list("ABC")