Skip to content

Commit

Permalink
ensure exporting of QuadrantGate raises NotImplementedError (see #209)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitews committed Aug 31, 2024
1 parent 1c46f22 commit 531cb59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/flowkit/_utils/wsp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# noinspection PyProtectedMember
from .._models.gates._wsp_gates import WSPEllipsoidGate
from .._models.gating_strategy import GatingStrategy
from ..exceptions import QuadrantReferenceError

wsp_gate_constructor_lut = {
'RectangleGate': GMLRectangleGate,
Expand Down Expand Up @@ -930,7 +931,7 @@ def _recurse_add_sub_populations(
elif isinstance(gate, RectangleGate):
_add_rectangle_gate(gate_el, gate, fj_id, parent_fj_id, gating_strategy, comp_prefix, ns_map)
else:
raise NotImplementedError("Exporting %s gates is not yet implemented" % str(gate.__class__))
raise NotImplementedError("Exporting %s gates is not yet implemented" % str(gate.__class__.__name__))

# If there are child gates, create a new Sub-pop element and recurse
child_gate_ids = gating_strategy.get_child_gate_ids(gate_id, gate_path)
Expand Down Expand Up @@ -1060,7 +1061,12 @@ def export_flowjo_wsp(gating_strategy, group_name, samples, file_handle):

# Also assume the xforms for all samples are the same
for g_id, g_path in gate_ids:
gate = gating_strategy.get_gate(g_id, g_path)
# need to avoid Quadrant instances of a QuadrantGate,
# they will get included w/ the QuadrantGate later.
try:
gate = gating_strategy.get_gate(g_id, g_path)
except QuadrantReferenceError:
continue

for dim in gate.dimensions:
if dim.id not in dim_xform_lut.keys():
Expand Down
10 changes: 9 additions & 1 deletion tests/session_export_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest
from io import BytesIO
from flowkit import Session, Workspace, gates
from tests.test_config import test_samples_8c_full_set
from tests.test_config import test_samples_8c_full_set, quad1_gate, data1_sample


class SessionExportTestCase(unittest.TestCase):
Expand Down Expand Up @@ -113,3 +113,11 @@ def test_export_wsp(self):

self.assertEqual(wsp_gate.gate_name, gate_name)
self.assertEqual(wsp_out_gate.gate_name, gate_name)

def test_export_quadrant_gate_raises(self):
session = Session()

session.add_samples(data1_sample)
session.add_gate(quad1_gate, ("root",))

self.assertRaises(NotImplementedError, session.export_wsp, 'tmp.wsp', group_name='All Samples')

0 comments on commit 531cb59

Please sign in to comment.