Skip to content

Commit

Permalink
better error for invalid gate names '.' & '..' (closes #220)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitews committed Oct 28, 2024
1 parent 44e5857 commit 7982564
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/flowkit/_models/gating_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ def add_gate(self, gate, gate_path, sample_id=None):
if not isinstance(gate_path, tuple):
raise TypeError("gate_path must be a tuple not %s" % str(type(gate_path)))

# make string representation of parent path, used for anytree Resolver later
parent_abs_gate_path = "/" + "/".join(gate_path)

# Verify gate name is not "." or ".." as these are incompatible w/ the
# current version of anytree (see open issue https://github.com/c0fec0de/anytree/issues/269)
if gate.gate_name in ['.', '..']:
raise GateTreeError(
"Gate name '%s' is incompatible with FlowKit. Gate was found in path: %s" %
(gate.gate_name, parent_abs_gate_path)
)

# We need the parent gate (via its node) for 2 reasons:
# 1) To verify the parent exists when creating a new node
# 2) Verify the parent is NOT a QuadrantGate, as only
# Quadrants of a QuadrantGate can be a parent.
parent_abs_gate_path = "/" + "/".join(gate_path)
try:
parent_node = self.resolver.get(self._gate_tree, parent_abs_gate_path)
except anytree.ResolverError:
Expand Down
14 changes: 13 additions & 1 deletion tests/workspace_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# noinspection PyProtectedMember
from flowkit._models.transforms._base_transform import Transform
from flowkit._models.gating_results import GatingResults
from flowkit.exceptions import GateReferenceError
from flowkit.exceptions import GateReferenceError, GateTreeError

from tests.test_config import test_samples_8c_full_set

Expand Down Expand Up @@ -426,6 +426,18 @@ def test_parse_wsp_with_ellipse(self):
self.assertIsInstance(gate_indices, np.ndarray)
self.assertEqual(np.sum(gate_indices), 7023)

def test_parse_wsp_with_invalid_gate_name(self):
wsp_path = "data/8_color_data_set/8_color_ICS_dot_gate_name.wsp"

self.assertRaisesRegex(
GateTreeError,
r"Gate name '\.' is incompatible with FlowKit\. "
r"Gate was found in path: \/root\/Time\/Singlets\/aAmine-\/CD3\+\/CD4\+",
Workspace,
wsp_path,
ignore_missing_files=True
)

def test_parse_wsp_with_boolean_gates(self):
wsp_path = "data/8_color_data_set/8_color_ICS_boolean_gate_testing.wsp"
fcs_path = "data/8_color_data_set/fcs_files/101_DEN084Y5_15_E01_008_clean.fcs"
Expand Down

0 comments on commit 7982564

Please sign in to comment.