Skip to content

Commit 086659d

Browse files
committed
Merge branch 'develop'
2 parents 7effde1 + 81b37ac commit 086659d

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

src/flowkit/_models/gating_strategy.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def rename_gate(self, gate_name, new_gate_name, gate_path=None):
234234
gate_node = self._get_gate_node(gate_name, gate_path=gate_path)
235235
gate = gate_node.gate
236236
orig_full_gate_path = tuple(n.name for n in gate_node.path)
237+
new_full_gate_path = orig_full_gate_path[:-1] + (new_gate_name,) # needed for updating Boolean refs later
237238

238239
# check successors for any Boolean gates that reference the renamed gate
239240
# Note, these needs to be retrieved before modifying the gate name
@@ -244,15 +245,6 @@ def rename_gate(self, gate_name, new_gate_name, gate_path=None):
244245
# so clear cached events
245246
self.clear_cache()
246247

247-
# Need to change the gate node name & the gate's gate_name attribute
248-
gate_node.name = new_gate_name
249-
gate.gate_name = new_gate_name
250-
new_full_gate_path = tuple(n.name for n in gate_node.path)
251-
252-
# check for custom gates, need to change those too
253-
for custom_gate in gate_node.custom_gates.values():
254-
custom_gate.gate_name = new_gate_name
255-
256248
# Check successor gates for a Boolean gate.
257249
# If present, it references the renamed gate & that reference needs updating
258250
for s_tuple in successor_node_tuples:
@@ -287,6 +279,14 @@ def rename_gate(self, gate_name, new_gate_name, gate_path=None):
287279
# Any other case, the reference gate path is longer than the modified gate,
288280
# so not affected by the change.
289281

282+
# Need to change the gate node name & the gate's gate_name attribute
283+
gate_node.name = new_gate_name
284+
gate.gate_name = new_gate_name
285+
286+
# check for custom gates, need to change those too
287+
for custom_gate in gate_node.custom_gates.values():
288+
custom_gate.gate_name = new_gate_name
289+
290290
# rebuild DAG
291291
self._rebuild_dag()
292292

src/flowkit/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""
22
FlowKit version
33
"""
4-
__version__ = "1.2.1"
4+
__version__ = "1.2.2b0"

tests/gating_strategy_modify_gate_tree_tests.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
# noinspection PyProtectedMember
99
from flowkit._models.gating_results import GatingResults
1010

11-
from tests.test_config import (
12-
test_samples_8c_full_set_dict,
13-
csv_8c_comp_file_path,
14-
detectors_8c,
15-
)
11+
from tests import test_config
1612

1713

1814
class GatingStrategyRemoveGatesTestCase(unittest.TestCase):
@@ -43,8 +39,8 @@ def setUp(self):
4339
:return: None
4440
"""
4541
sample_id = "101_DEN084Y5_15_E01_008_clean.fcs"
46-
sample = copy.deepcopy(test_samples_8c_full_set_dict[sample_id])
47-
comp = fk.Matrix(csv_8c_comp_file_path, detectors_8c)
42+
sample = copy.deepcopy(test_config.test_samples_8c_full_set_dict[sample_id])
43+
comp = fk.Matrix(test_config.csv_8c_comp_file_path, test_config.detectors_8c)
4844

4945
session = fk.Session()
5046
session.add_samples(sample)
@@ -355,6 +351,42 @@ def test_remove_gate_keep_children(self):
355351
#
356352
# Rename gate tests
357353
#
354+
def test_rename_gate_with_children(self):
355+
# This test covers the bug reported in issue #231
356+
poly1_vertices = test_config.poly1_vertices
357+
poly1_dims = test_config.poly1_dims
358+
359+
top1_gate = fk.gates.PolygonGate("top1", poly1_dims, poly1_vertices)
360+
top2_gate = fk.gates.PolygonGate("top2", poly1_dims, poly1_vertices)
361+
a_gate = fk.gates.PolygonGate("A", poly1_dims, poly1_vertices)
362+
a1_gate = fk.gates.PolygonGate("A1", poly1_dims, poly1_vertices)
363+
a2_gate = fk.gates.PolygonGate("A2", poly1_dims, poly1_vertices)
364+
365+
gs = fk.GatingStrategy()
366+
gs.add_gate(top1_gate, gate_path=('root',))
367+
gs.add_gate(top2_gate, gate_path=('root',))
368+
369+
gs.add_gate(a_gate, gate_path=('root', 'top1'))
370+
gs.add_gate(copy.deepcopy(a_gate), gate_path=('root', 'top2'))
371+
372+
gs.add_gate(a1_gate, gate_path=('root', 'top1', 'A'))
373+
gs.add_gate(a2_gate, gate_path=('root', 'top1', 'A'))
374+
375+
gs.add_gate(copy.deepcopy(a1_gate), gate_path=('root', 'top2', 'A'))
376+
gs.add_gate(copy.deepcopy(a2_gate), gate_path=('root', 'top2', 'A'))
377+
378+
# now rename 'top1' > 'A'
379+
# This step caused a GateReferenceError prior to #231 fix
380+
gs.rename_gate('A', 'A_new', ('root', 'top1'))
381+
382+
# verify we can retrieve the gate by its new gate name
383+
renamed_gate = gs.get_gate('A_new', gate_path=('root', 'top1'))
384+
self.assertEqual(renamed_gate.gate_name, 'A_new')
385+
386+
# And verify the other 'A' gate name didn't change
387+
other_a_gate = gs.get_gate('A', gate_path=('root', 'top2'))
388+
self.assertEqual(other_a_gate.gate_name, 'A')
389+
358390
def test_rename_gate_with_bool_dep(self):
359391
gs = copy.deepcopy(self.gating_strategy)
360392
gate_name_to_rename = "CD3-pos-range"

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
poly1_vertices = [[5, 5], [500, 5], [500, 500]]
5252
poly1_dim1 = fk.Dimension("FL2-H", compensation_ref="FCS")
5353
poly1_dim2 = fk.Dimension("FL3-H", compensation_ref="FCS")
54-
poly1_dims1 = [poly1_dim1, poly1_dim2]
54+
poly1_dims = [poly1_dim1, poly1_dim2]
5555

56-
poly1_gate = fk.gates.PolygonGate("Polygon1", poly1_dims1, poly1_vertices)
56+
poly1_gate = fk.gates.PolygonGate("Polygon1", poly1_dims, poly1_vertices)
5757

5858
quad1_div1 = fk.QuadrantDivider("FL2", "FL2-H", "FCS", [12.14748])
5959
quad1_div2 = fk.QuadrantDivider("FL4", "FL4-H", "FCS", [14.22417])

0 commit comments

Comments
 (0)