Example #1
0
    def test_all_gates():
        gml_path = 'examples/gate_ref/gml/gml_all_gates.xml'
        truth_pattern = 'examples/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

        gs = GatingStrategy(gml_path)
        gs_results = gs.gate_sample(data1_sample)

        for row in gs_results.report.itertuples():
            np.testing.assert_array_equal(
                truth_dict[row[0][1]], gs_results.get_gate_indices(row[0][1]))
Example #2
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'

        gs = GatingStrategy(gml_path)
        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

        result = gs.gate_sample(data1_sample)

        np.testing.assert_array_equal(truth1,
                                      result.get_gate_indices('FL2N-FL4N'))
        np.testing.assert_array_equal(truth2,
                                      result.get_gate_indices('FL2N-FL4P'))
        np.testing.assert_array_equal(truth3,
                                      result.get_gate_indices('FL2P-FL4N'))
        np.testing.assert_array_equal(truth4,
                                      result.get_gate_indices('FL2P-FL4P'))
Example #3
0
    def __init__(self,
                 fcs_samples=None,
                 comp_bead_samples=None,
                 gating_strategy=None):
        self.samples = []
        self.bead_samples = []
        self.bead_lut = {}
        self.report = None
        self._results = None

        if comp_bead_samples == fcs_samples and isinstance(fcs_samples, str):
            # there's a mix of regular FCS files with bead files in the same directory,
            # which isn't supported at this time. Raise error
            raise ValueError(
                "Specify bead samples as a list of paths if in the same directory as other samples"
            )

        self.samples = load_samples(fcs_samples)
        self.bead_samples = load_samples(comp_bead_samples)
        self.process_bead_samples()

        if isinstance(gating_strategy, GatingStrategy):
            self.gating_strategy = gating_strategy
        elif isinstance(gating_strategy, str):
            # assume a path to a GatingML XML file
            self.gating_strategy = GatingStrategy(gating_strategy)
        elif gating_strategy is None:
            self.gating_strategy = GatingStrategy()
        else:
            raise ValueError(
                "'gating_strategy' must be either a GatingStrategy instance or a path to a GatingML document"
            )
Example #4
0
    def test_boolean_or2_not_gate():
        gml_path = 'examples/gate_ref/gml/gml_boolean_or2_gate.xml'
        res_path = 'examples/gate_ref/truth/Results_Or2.txt'

        gs = GatingStrategy(gml_path)
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        result = gs.gate_sample(data1_sample, 'Or2')

        np.testing.assert_array_equal(truth, result.get_gate_indices('Or2'))
Example #5
0
    def test_poly3_non_solid_gate():
        gml_path = 'examples/gate_ref/gml/gml_poly3ns_gate.xml'
        res_path = 'examples/gate_ref/truth/Results_Polygon3NS.txt'

        gs = GatingStrategy(gml_path)
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        result = gs.gate_sample(data1_sample, 'Polygon3NS')

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('Polygon3NS'))
Example #6
0
    def test_parent_quadrant_rect_gate():
        gml_path = 'examples/gate_ref/gml/gml_parent_quadrant_rect_gate.xml'
        res_path = 'examples/gate_ref/truth/Results_ParQuadRect.txt'

        gs = GatingStrategy(gml_path)
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        result = gs.gate_sample(data1_sample, 'ParRectangle1')

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('ParRectangle1'))
Example #7
0
    def test_matrix_transform_logicle_rect1_gate():
        gml_path = 'examples/gate_ref/gml/gml_matrix_transform_logicle_rect1_gate.xml'
        res_path = 'examples/gate_ref/truth/Results_ScaleRect1.txt'

        gs = GatingStrategy(gml_path)
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        result = gs.gate_sample(data1_sample, 'ScaleRect1')

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('ScaleRect1'))
Example #8
0
    def test_log_ratio_range1_gate():
        gml_path = 'examples/gate_ref/gml/gml_log_ratio_range1_gate.xml'
        res_path = 'examples/gate_ref/truth/Results_RatRange1a.txt'

        gs = GatingStrategy(gml_path)
        truth = pd.read_csv(res_path, header=None, squeeze=True,
                            dtype='bool').values

        result = gs.gate_sample(data1_sample, 'RatRange1a')

        np.testing.assert_array_equal(truth,
                                      result.get_gate_indices('RatRange1a'))
Example #9
0
    def test_quadrant_gate_relative_percent(self):
        gml_path = 'examples/gate_ref/gml/gml_quadrant1_gate.xml'

        gs = GatingStrategy(gml_path)

        result = gs.gate_sample(data1_sample)

        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)