Ejemplo n.º 1
0
def test_threshold_match_children_2d():
    threshold = gate.ThresholdGate(gate_name="test",
                                   parent="test parent",
                                   x="X",
                                   y="Y",
                                   method="density")
    x = np.random.normal(loc=1., scale=1.5, size=1000)
    y = np.random.normal(loc=1., scale=1.5, size=1000)
    data = pd.DataFrame({"X": x, "Y": y})
    threshold.add_child(
        gate.ChildThreshold(name="positive",
                            definition="++,+-",
                            geom=ThresholdGeom(x_threshold=0.5)))
    threshold.add_child(
        gate.ChildThreshold(name="negative",
                            definition="--,-+",
                            geom=ThresholdGeom(x_threshold=0.5)))
    pos = gate.Population(population_name="p1",
                          parent="root",
                          definition="++",
                          geom=ThresholdGeom(x_threshold=0.6),
                          index=data[data.X >= 0.6].index.values)
    neg = gate.Population(population_name="p2",
                          parent="root",
                          definition="--,-+",
                          geom=ThresholdGeom(x_threshold=0.6),
                          index=data[data.X < 0.6].index.values)
    pops = threshold._match_to_children([neg, pos])
    pos = [p for p in pops if p.definition == "++"][0]
    assert pos.population_name == "positive"
    neg = [p for p in pops if p.definition == "--,-+"][0]
    assert neg.population_name == "negative"
Ejemplo n.º 2
0
def test_threshold_match_children_1d():
    threshold = gate.ThresholdGate(gate_name="test",
                                   parent="test parent",
                                   x="X",
                                   method="density")
    data = np.random.normal(loc=1., scale=1.5, size=1000)
    threshold.add_child(
        gate.ChildThreshold(name="positive",
                            definition="+",
                            geom=ThresholdGeom(x_threshold=0.5)))
    threshold.add_child(
        gate.ChildThreshold(name="negative",
                            definition="-",
                            geom=ThresholdGeom(x_threshold=0.5)))
    pos = gate.Population(population_name="p1",
                          parent="root",
                          definition="+",
                          geom=ThresholdGeom(x_threshold=0.6),
                          index=data[np.where(data >= 0.6)])
    neg = gate.Population(population_name="p2",
                          parent="root",
                          definition="-",
                          geom=ThresholdGeom(x_threshold=0.6),
                          index=data[np.where(data >= 0.6)])
    pops = threshold._match_to_children([neg, pos])
    pos = [p for p in pops if p.definition == "+"][0]
    assert pos.population_name == "positive"
    neg = [p for p in pops if p.definition == "-"][0]
    assert neg.population_name == "negative"
Ejemplo n.º 3
0
def test_childthreshold_init():
    test_child = gate.ChildThreshold(name="test",
                                     signature={
                                         "x": 2423,
                                         "y": 2232,
                                         "z": 4543
                                     },
                                     definition="+",
                                     geom=ThresholdGeom(x="x",
                                                        y="y",
                                                        x_threshold=0.5,
                                                        y_threshold=0.5,
                                                        transform_x="logicle",
                                                        transform_y="logicle"))
    assert test_child.name == "test"
    assert test_child.signature.get("x") == 2423
    assert test_child.signature.get("y") == 2232
    assert test_child.signature.get("z") == 4543
    assert test_child.definition == "+"
    assert test_child.geom.x == "x"
    assert test_child.geom.y == "y"
    assert test_child.geom.x_threshold == 0.5
    assert test_child.geom.y_threshold == 0.5
    assert test_child.geom.transform_x == "logicle"
    assert test_child.geom.transform_x == "logicle"
Ejemplo n.º 4
0
def test_threshold_add_child_invalid_1d(d):
    threshold = gate.ThresholdGate(gate_name="test",
                                   parent="test parent",
                                   method="manual",
                                   x="X")
    child = gate.ChildThreshold(name="test child",
                                definition=d,
                                geom=ThresholdGeom(x="X",
                                                   x_threshold=0.56,
                                                   y_threshold=0.75))
    with pytest.raises(AssertionError) as err:
        threshold.add_child(child)
    assert str(
        err.value) == "Invalid child definition, should be either '+' or '-'"
Ejemplo n.º 5
0
def test_childthreshold_match_definition_2d(definition, expected):
    test_child = gate.ChildThreshold(name="test",
                                     signature={
                                         "x": 2423,
                                         "y": 2232,
                                         "z": 4543
                                     },
                                     definition=definition,
                                     geom=ThresholdGeom(x="x",
                                                        y="y",
                                                        x_threshold=0.5,
                                                        y_threshold=0.5,
                                                        transform_x="logicle",
                                                        transform_y="logicle"))
    assert test_child.match_definition("++") == expected
Ejemplo n.º 6
0
def test_threshold_add_child():
    threshold = gate.ThresholdGate(gate_name="test",
                                   parent="test parent",
                                   x="X",
                                   y="Y",
                                   method="manual",
                                   transform_x="logicle")
    child = gate.ChildThreshold(name="test child",
                                definition="++",
                                geom=ThresholdGeom(x_threshold=0.56,
                                                   y_threshold=0.75))
    threshold.add_child(child)
    assert len(threshold.children)
    assert threshold.children[0].geom.x == threshold.x
    assert threshold.children[0].geom.y == threshold.y
    assert threshold.children[0].geom.transform_x == "logicle"
    assert not threshold.children[0].geom.transform_y