def test_export_fcs_as_raw(self): # This test uses a file where the preprocessing makes the orig & raw events different. # The purpose here is to verify that importing the exported file has the same raw events # as the original file's raw events. fcs_file_path = "examples/data/8_color_data_set/fcs_files/101_DEN084Y5_15_E01_008_clean.fcs" sample = Sample(fcs_path_or_data=fcs_file_path) sample.export("test_fcs_export.fcs", source='raw', directory="examples") exported_fcs_file = "examples/test_fcs_export.fcs" exported_sample = Sample(fcs_path_or_data=exported_fcs_file) os.unlink(exported_fcs_file) self.assertIsInstance(exported_sample, Sample) # When the events are exported, they are saved as single precision (32-bit). We'll test the # arrays with the original sample data converted to 32-bit float. The original sample data # was also originally in 32-bit. Comparing both in single precision is then the most # "correct" thing to do here. np.testing.assert_array_equal( sample._raw_events.astype(np.float32), exported_sample._raw_events.astype(np.float32))
def test_export_fcs_as_raw_with_gain(self): # This test uses a file where the preprocessing makes the orig & raw events different. # File data1.fcs has 2 channels that specify a gain value other than 1.0. # The purpose here is to verify that importing the exported file has the same raw events # as the original file's raw events. sample = Sample(fcs_path_or_data=data1_fcs_path, cache_original_events=True) sample.export("test_fcs_export.fcs", source='raw', directory="examples") exported_fcs_file = "examples/test_fcs_export.fcs" exported_sample = Sample(fcs_path_or_data=exported_fcs_file) os.unlink(exported_fcs_file) self.assertIsInstance(exported_sample, Sample) # When the events are exported, they are saved as single precision (32-bit). We'll test the # arrays with the original sample data converted to 32-bit float. The original sample data # was also originally in 32-bit. Comparing both in single precision is then the most # "correct" thing to do here. np.testing.assert_array_equal( sample._raw_events.astype(np.float32), exported_sample._raw_events.astype(np.float32))
def test_export_exclude_negative_scatter(self): # there are 2 negative SSC-A events in this file (of 65016 total events) fcs_file_path = "examples/data/100715.fcs" sample = Sample(fcs_path_or_data=fcs_file_path) sample.filter_negative_scatter() neg_scatter_count = len(sample.negative_scatter_indices) exported_fcs_file = "examples/test_fcs_export.fcs" sample.export(exported_fcs_file, source='raw', exclude_neg_scatter=True) exported_sample = Sample(exported_fcs_file) os.unlink(exported_fcs_file) orig_event_count = sample.event_count exp_event_count = exported_sample.event_count self.assertEqual(exp_event_count, orig_event_count - neg_scatter_count)
def test_create_csv(self): fcs_file_path = "examples/test_comp_example.fcs" comp_file_path = Path("examples/comp_complete_example.csv") sample = Sample(fcs_path_or_data=fcs_file_path, compensation=comp_file_path) sample.export("test_fcs_export.csv", source='comp', directory="examples") exported_csv_file = "examples/test_fcs_export.csv" exported_df = pd.read_csv(exported_csv_file) exported_sample = Sample(exported_df) os.unlink(exported_csv_file) self.assertIsInstance(exported_sample, Sample) # TODO: Need to investigate why the exported comp data isn't exactly equal np.testing.assert_almost_equal(sample._comp_events[:, :], exported_sample._raw_events[:, :], decimal=3)
def test_create_fcs(self): fcs_file_path = "examples/test_comp_example.fcs" comp_file_path = Path("examples/comp_complete_example.csv") sample = Sample(fcs_path_or_data=fcs_file_path, compensation=comp_file_path) sample.export("test_fcs_export.fcs", source='comp', directory="examples") exported_fcs_file = "examples/test_fcs_export.fcs" exported_sample = Sample(fcs_path_or_data=exported_fcs_file) os.unlink(exported_fcs_file) self.assertIsInstance(exported_sample, Sample) # TODO: Excluding time channel here, as the difference was nearly 0.01. Need to investigate why the # exported comp data isn't exactly equal np.testing.assert_almost_equal(sample._comp_events[:, :-1], exported_sample._raw_events[:, :-1], decimal=3)