コード例 #1
0
    def test_wsp_export_simple_poly50(self):
        wsp_path = "examples/data/simple_line_example/simple_poly_and_rect_v2_poly50.wsp"
        fcs_path = "examples/data/simple_line_example/data_set_simple_line_100.fcs"
        sample_group = 'my_group'
        sample_id = 'data_set_simple_line_100.fcs'

        fks = Session(fcs_path)
        fks.import_flowjo_workspace(wsp_path)

        with BytesIO() as fh_out:
            fks.export_wsp(fh_out, sample_group)
            fh_out.seek(0)

            fks2 = Session(fcs_path)
            fks2.import_flowjo_workspace(fh_out)

        fks.analyze_samples(sample_group)
        fks_results = fks.get_gating_results(sample_group, sample_id)

        fks2.analyze_samples(sample_group)
        fks2_results = fks2.get_gating_results(sample_group, sample_id)

        gate_refs = fks.get_gate_ids(sample_group)

        self.assertEqual(len(gate_refs), 2)

        fks_rect1_count = fks_results.get_gate_count('rect1')
        fks2_rect1_count = fks2_results.get_gate_count('rect1')
        fks_poly1_count = fks_results.get_gate_count('poly1')
        fks2_poly1_count = fks2_results.get_gate_count('poly1')

        self.assertEqual(fks_rect1_count, 0)
        self.assertEqual(fks2_rect1_count, 0)
        self.assertEqual(fks_poly1_count, 50)
        self.assertEqual(fks2_poly1_count, 50)
コード例 #2
0
    def test_load_wsp_single_quad(self):
        wsp_path = "examples/data/simple_diamond_example/simple_diamond_example_quad_gate.wsp"
        fcs_path = "examples/data/simple_diamond_example/test_data_diamond_01.fcs"

        fks = Session(fcs_samples=fcs_path)
        fks.import_flowjo_workspace(wsp_path)

        # FlowJo quadrant gates are not true quadrant gates, rather a collection of rectangle gates
        self.assertIsInstance(
            fks.get_gate('All Samples',
                         'Q1: channel_A- , channel_B+',
                         sample_id='test_data_diamond_01.fcs'),
            gates.RectangleGate)

        fks.analyze_samples(group_name='All Samples')
        results = fks.get_gating_results('All Samples',
                                         'test_data_diamond_01.fcs')

        gate_count_q1 = results.get_gate_count('Q1: channel_A- , channel_B+')
        gate_count_q2 = results.get_gate_count('Q2: channel_A+ , channel_B+')
        gate_count_q3 = results.get_gate_count('Q3: channel_A+ , channel_B-')
        gate_count_q4 = results.get_gate_count('Q4: channel_A- , channel_B-')
        self.assertEqual(gate_count_q1, 49671)
        self.assertEqual(gate_count_q2, 50596)
        self.assertEqual(gate_count_q3, 50330)
        self.assertEqual(gate_count_q4, 49403)
コード例 #3
0
    def test_get_sample_gate_events(self):
        wsp_path = "examples/data/8_color_data_set/8_color_ICS_simple.wsp"
        sample_grp = 'DEN'
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        gate_name = 'CD3+'

        fks = Session(copy.deepcopy(test_samples_8c_full_set))
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        fks.analyze_samples(sample_grp, sample_id)

        sample_comp = fks.get_sample_comp_matrices(sample_grp, sample_id)[0]
        sample_xform = transforms.LogicleTransform('my_logicle',
                                                   param_t=262144.0,
                                                   param_w=1.0,
                                                   param_m=4.418539922,
                                                   param_a=0.0)

        df_gated_events = fks.get_gate_events(sample_grp,
                                              sample_id,
                                              gate_name,
                                              matrix=sample_comp,
                                              transform=sample_xform)

        self.assertIsInstance(df_gated_events, pd.DataFrame)
        self.assertEqual(len(df_gated_events), 133670)
コード例 #4
0
ファイル: gatingml_tests.py プロジェクト: whitews/FlowKit
    def test_all_gates():
        gml_path = 'examples/data/gate_ref/gml/gml_all_gates.xml'
        truth_pattern = 'examples/data/gate_ref/truth/Results*.txt'

        res_files = glob.glob(truth_pattern)

        truth_dict = {}

        for res_path in res_files:
            match = re.search("Results_(.+)\\.txt$", res_path)
            if match is not None:
                g_id = match.group(1)
                truth = pd.read_csv(res_path,
                                    header=None,
                                    squeeze=True,
                                    dtype='bool').values

                truth_dict[g_id] = truth

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_samples(data1_sample.original_filename, group_name)
        s.analyze_samples(group_name=group_name)
        results = s.get_gating_results(group_name,
                                       data1_sample.original_filename)

        for row in results.report.itertuples():
            np.testing.assert_array_equal(
                truth_dict[row.gate_name],
                results.get_gate_membership(row.gate_name))
コード例 #5
0
    def test_quadrant2_gate():
        gml_path = 'examples/gate_ref/gml/gml_quadrant2_gate.xml'
        res1_path = 'examples/gate_ref/truth/Results_FSCN-SSCN.txt'
        res2_path = 'examples/gate_ref/truth/Results_FSCD-SSCN-FL1N.txt'
        res3_path = 'examples/gate_ref/truth/Results_FSCP-SSCN-FL1N.txt'
        res4_path = 'examples/gate_ref/truth/Results_FSCD-FL1P.txt'
        res5_path = 'examples/gate_ref/truth/Results_FSCN-SSCP-FL1P.txt'

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_sample(data1_sample.original_filename, group_name)
        s.analyze_samples(sample_group=group_name)

        truth1 = pd.read_csv(res1_path, header=None, squeeze=True, dtype='bool').values
        truth2 = pd.read_csv(res2_path, header=None, squeeze=True, dtype='bool').values
        truth3 = pd.read_csv(res3_path, header=None, squeeze=True, dtype='bool').values
        truth4 = pd.read_csv(res4_path, header=None, squeeze=True, dtype='bool').values
        truth5 = pd.read_csv(res5_path, header=None, squeeze=True, dtype='bool').values

        result = s.get_gating_results(group_name, data1_sample.original_filename)

        np.testing.assert_array_equal(truth1, result.get_gate_indices('FSCN-SSCN'))
        np.testing.assert_array_equal(truth2, result.get_gate_indices('FSCD-SSCN-FL1N'))
        np.testing.assert_array_equal(truth3, result.get_gate_indices('FSCP-SSCN-FL1N'))
        np.testing.assert_array_equal(truth4, result.get_gate_indices('FSCD-FL1P'))
        np.testing.assert_array_equal(truth5, result.get_gate_indices('FSCN-SSCP-FL1P'))
コード例 #6
0
    def test_quadrant1_gate():
        gml_path = 'examples/gate_ref/gml/gml_quadrant1_gate.xml'
        res1_path = 'examples/gate_ref/truth/Results_FL2N-FL4N.txt'
        res2_path = 'examples/gate_ref/truth/Results_FL2N-FL4P.txt'
        res3_path = 'examples/gate_ref/truth/Results_FL2P-FL4N.txt'
        res4_path = 'examples/gate_ref/truth/Results_FL2P-FL4P.txt'

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_sample(data1_sample.original_filename, group_name)

        truth1 = pd.read_csv(res1_path, header=None, squeeze=True, dtype='bool').values
        truth2 = pd.read_csv(res2_path, header=None, squeeze=True, dtype='bool').values
        truth3 = pd.read_csv(res3_path, header=None, squeeze=True, dtype='bool').values
        truth4 = pd.read_csv(res4_path, header=None, squeeze=True, dtype='bool').values

        s.analyze_samples(group_name)
        results = s.get_gating_results(group_name, data1_sample.original_filename)
        result1 = results.get_gate_indices('FL2N-FL4N')
        result2 = results.get_gate_indices('FL2N-FL4P')
        result3 = results.get_gate_indices('FL2P-FL4N')
        result4 = results.get_gate_indices('FL2P-FL4P')

        np.testing.assert_array_equal(truth1, result1)
        np.testing.assert_array_equal(truth2, result2)
        np.testing.assert_array_equal(truth3, result3)
        np.testing.assert_array_equal(truth4, result4)
コード例 #7
0
    def test_add_poly1_gate():
        fks = Session(fcs_samples=data1_sample)
        fks.add_gate(poly1_gate)
        fks.analyze_samples()
        result = fks.get_gating_results('default',
                                        data1_sample.original_filename)

        res_path = 'examples/gate_ref/truth/Results_Polygon1.txt'
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('Polygon1'))
コード例 #8
0
    def test_analyze_single_sample(self):
        wsp_path = "examples/data/8_color_data_set/8_color_ICS_simple.wsp"
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        sample_grp = 'DEN'

        fks = Session(copy.deepcopy(test_samples_8c_full_set))
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        sample_ids = fks.get_group_sample_ids(sample_grp)
        self.assertEqual(len(sample_ids), 3)

        fks.analyze_samples(sample_grp, sample_id=sample_id)
        report = fks.get_group_report(sample_grp)

        self.assertEqual(report['sample'].nunique(), 1)
コード例 #9
0
    def test_poly2_gate():
        gml_path = 'examples/gate_ref/gml/gml_poly2_gate.xml'
        res_path = 'examples/gate_ref/truth/Results_Polygon2.txt'

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_sample(data1_sample.original_filename, group_name)
        s.analyze_samples(sample_group=group_name)

        truth = pd.read_csv(res_path, header=None, squeeze=True, dtype='bool').values
        result = s.get_gate_indices(group_name, data1_sample.original_filename, 'Polygon2')

        np.testing.assert_array_equal(truth, result)
コード例 #10
0
    def test_analyze_samples_multiproc(self):
        wsp_path = "examples/data/8_color_data_set/8_color_ICS_simple.wsp"
        sample_grp = 'DEN'
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        gate_name = 'CD3+'

        fks = Session(copy.deepcopy(test_samples_8c_full_set))
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        fks.analyze_samples(sample_grp)

        gate_membership = fks.get_gate_membership(sample_grp, sample_id,
                                                  gate_name)

        self.assertEqual(gate_membership.sum(), 133670)
コード例 #11
0
    def test_load_wsp_single_ellipse(self):
        wsp_path = "examples/simple_line_example/single_ellipse_51_events.wsp"
        fcs_path = "examples/simple_line_example/data_set_simple_line_100.fcs"

        fks = Session(fcs_samples=fcs_path)
        fks.import_flowjo_workspace(wsp_path)

        self.assertIsInstance(
            fks.get_gate('All Samples', 'data_set_simple_line_100.fcs',
                         'ellipse1'), gates.EllipsoidGate)

        fks.analyze_samples(sample_group='All Samples')
        results = fks.get_gating_results('All Samples',
                                         'data_set_simple_line_100.fcs')
        gate_count = results.get_gate_count('ellipse1')
        self.assertEqual(gate_count, 48)
コード例 #12
0
    def test_get_wsp_gated_events(self):
        wsp_path = "examples/data/8_color_data_set/8_color_ICS_simple.wsp"
        sample_grp = 'DEN'
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        gate_name = 'CD3+'

        fks = Session(copy.deepcopy(test_samples_8c_full_set))
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        fks.analyze_samples(sample_grp, sample_id)

        df_gated_events = fks.get_wsp_gated_events(sample_grp, [sample_id],
                                                   gate_name)

        self.assertIsInstance(df_gated_events, list)
        self.assertEqual(len(df_gated_events[0]), 133670)
コード例 #13
0
    def test_analyze_single_sample(self):
        wsp_path = "examples/8_color_data_set/8_color_ICS_simple.wsp"
        fcs_path = "examples/8_color_data_set/fcs_files"
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        sample_grp = 'DEN'

        fks = Session(fcs_samples=fcs_path)
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        sample_ids = fks.get_group_sample_ids(sample_grp)
        self.assertEqual(len(sample_ids), 3)

        fks.analyze_samples(sample_grp, sample_id=sample_id)
        report = fks.get_group_report(sample_grp)

        self.assertEqual(report.index.get_level_values('sample').nunique(), 1)
コード例 #14
0
ファイル: gatingml_tests.py プロジェクト: whitews/FlowKit
    def test_boolean_or2_complement_gate():
        gml_path = 'examples/data/gate_ref/gml/gml_boolean_or2_gate.xml'
        res_path = 'examples/data/gate_ref/truth/Results_Or2.txt'

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_samples(data1_sample.original_filename, group_name)
        s.analyze_samples(group_name=group_name)

        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values
        result = s.get_gate_membership(group_name,
                                       data1_sample.original_filename, 'Or2')

        np.testing.assert_array_equal(truth, result)
コード例 #15
0
    def test_quadrant_gate_relative_percent(self):
        gml_path = 'examples/gate_ref/gml/gml_quadrant1_gate.xml'

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_sample(data1_sample.original_filename, group_name)
        s.analyze_samples(sample_group=group_name)

        result = s.get_gating_results(group_name, data1_sample.original_filename)

        total_percent = result.get_gate_relative_percent('FL2N-FL4N') + \
            result.get_gate_relative_percent('FL2N-FL4P') + \
            result.get_gate_relative_percent('FL2P-FL4N') + \
            result.get_gate_relative_percent('FL2P-FL4P')

        self.assertEqual(100.0, total_percent)
コード例 #16
0
ファイル: gatingml_tests.py プロジェクト: whitews/FlowKit
    def test_matrix_transform_logicle_rect1_gate():
        gml_path = 'examples/data/gate_ref/gml/gml_matrix_transform_logicle_rect1_gate.xml'
        res_path = 'examples/data/gate_ref/truth/Results_ScaleRect1.txt'

        s = Session()
        group_name = 'gml'
        s.add_sample_group(group_name, gating_strategy=gml_path)
        s.add_samples(data1_sample)
        s.assign_samples(data1_sample.original_filename, group_name)
        s.analyze_samples(group_name=group_name)

        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values
        result = s.get_gate_membership(group_name,
                                       data1_sample.original_filename,
                                       'ScaleRect1')

        np.testing.assert_array_equal(truth, result)
コード例 #17
0
    def test_wsp_fasinh_transform(self):
        wsp_path = "examples/data/simple_diamond_example/test_data_diamond_asinh_rect.wsp"
        fcs_path = "examples/data/simple_diamond_example/test_data_diamond_01.fcs"

        fks = Session(fcs_samples=fcs_path)
        fks.import_flowjo_workspace(wsp_path)

        self.assertIsInstance(
            fks.get_gate('All Samples',
                         'upper_right',
                         sample_id='test_data_diamond_01.fcs'),
            gates.RectangleGate)

        fks.analyze_samples(group_name='All Samples')
        results = fks.get_gating_results('All Samples',
                                         'test_data_diamond_01.fcs')
        gate_count = results.get_gate_count('upper_right')
        self.assertEqual(gate_count, 50559)
コード例 #18
0
    def test_parse_wsp_with_ellipse(self):
        wsp_path = "examples/data/8_color_data_set/8_color_ICS_with_ellipse.wsp"
        fcs_path = "examples/data/8_color_data_set/fcs_files/101_DEN084Y5_15_E01_008_clean.fcs"
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        sample_grp = 'DEN'
        gate_name = 'ellipse1'
        gate_path = ('root', 'Time', 'Singlets', 'aAmine-', 'CD3+')

        fks = Session(fcs_samples=fcs_path)
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        fks.analyze_samples(sample_grp, sample_id=sample_id)
        gate_indices = fks.get_gate_membership(sample_grp,
                                               sample_id,
                                               gate_name,
                                               gate_path=gate_path)

        self.assertIsInstance(gate_indices, np.ndarray)
        self.assertEqual(np.sum(gate_indices), 7018)
コード例 #19
0
    def test_get_ambiguous_gate_objects(self):
        wsp_path = "examples/8_color_data_set/8_color_ICS.wsp"
        fcs_path = "examples/8_color_data_set/fcs_files/101_DEN084Y5_15_E01_008_clean.fcs"
        sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'
        sample_grp = 'DEN'
        gate_id = 'TNFa+'
        gate_path = ['root', 'Time', 'Singlets', 'aAmine-', 'CD3+', 'CD4+']

        fks = Session(fcs_samples=fcs_path)
        fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)

        fks.analyze_samples(sample_grp)
        gate_indices = fks.get_gate_indices(sample_grp,
                                            sample_id,
                                            gate_id,
                                            gate_path=gate_path)

        self.assertIsInstance(gate_indices, np.ndarray)
        self.assertEqual(np.sum(gate_indices), 21)
コード例 #20
0
    def test_add_matrix_poly4_gate():
        fks = Session(fcs_samples=data1_sample)

        fks.add_comp_matrix(comp_matrix_01)

        dim1 = Dimension('PE', compensation_ref='MySpill')
        dim2 = Dimension('PerCP', compensation_ref='MySpill')
        dims = [dim1, dim2]

        poly_gate = gates.PolygonGate('Polygon4', None, dims, poly1_vertices)
        fks.add_gate(poly_gate)

        res_path = 'examples/gate_ref/truth/Results_Polygon4.txt'
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        fks.analyze_samples()
        result = fks.get_gating_results('default',
                                        data1_sample.original_filename)

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('Polygon4'))
コード例 #21
0
    def test_add_transform_asinh_range1_gate():
        fks = Session(fcs_samples=data1_sample)
        fks.add_transform(asinh_xform1)

        dim1 = Dimension('FL1-H',
                         'uncompensated',
                         'AsinH_10000_4_1',
                         range_min=0.37,
                         range_max=0.63)
        dims = [dim1]

        rect_gate = gates.RectangleGate('ScaleRange1', None, dims)
        fks.add_gate(rect_gate)

        res_path = 'examples/gate_ref/truth/Results_ScaleRange1.txt'
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        fks.analyze_samples()
        result = fks.get_gating_results('default',
                                        data1_sample.original_filename)

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('ScaleRange1'))
コード例 #22
0
"""
Tests for GatingResults class
"""
import copy
import unittest
from flowkit import Session
from .session_tests import test_samples_8c_full_set

wsp_path = "examples/data/8_color_data_set/reused_quad_gate_with_child.wsp"
group_name = 'All Samples'
sample_id = '101_DEN084Y5_15_E01_008_clean.fcs'

fks = Session(copy.deepcopy(test_samples_8c_full_set))
fks.import_flowjo_workspace(wsp_path, ignore_missing_files=True)
fks.analyze_samples(group_name=group_name, sample_id=sample_id)
results_8c_sample_008 = fks.get_gating_results(group_name=group_name,
                                               sample_id=sample_id)


class GatingResultsTestCase(unittest.TestCase):
    def test_get_gate_count_ambiguous_raises_value_error(self):
        gate_name = 'some_child_gate'

        self.assertRaises(ValueError, results_8c_sample_008.get_gate_count,
                          gate_name)

    def test_get_gate_count_with_gate_path(self):
        gate_name = 'some_child_gate'
        gate_path_1 = ('root', 'good cells', 'cd4+', 'Q2: CD107a+, IL2+')

        gate_count = results_8c_sample_008.get_gate_count(