Skip to content

Commit a7907fe

Browse files
committed
bug(gates): fix create_population argument handling
1 parent b046408 commit a7907fe

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

cellengine/resources/experiment.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -394,65 +394,65 @@ def delete_gate(
394394
"""
395395
return self.client.delete_gate(self._id, _id, gid, exclude)
396396

397-
def create_rectangle_gate(self, *args, **kwargs) -> RectangleGate:
397+
def create_rectangle_gate(
398+
self, *args, create_population=True, **kwargs
399+
) -> RectangleGate:
398400
"""Create a RectangleGate.
399401
400402
Accepts all args and kwargs available for
401403
[`RectangleGate.create()`][cellengine.resources.gate.RectangleGate.create].
402404
"""
403405
gate = RectangleGate.create(self._id, *args, **kwargs)
404-
gate.update()
405-
return gate
406+
return ce.APIClient().create(gate, createPopulation=create_population)
406407

407-
def create_polygon_gate(self, *args, **kwargs) -> PolygonGate:
408+
def create_polygon_gate(
409+
self, *args, create_population=True, **kwargs
410+
) -> PolygonGate:
408411
"""Create a PolygonGate.
409412
410413
Accepts all args and kwargs available for
411414
[`PolygonGate.create()`][cellengine.resources.gate.PolygonGate.create].
412415
"""
413416
gate = PolygonGate.create(self._id, *args, **kwargs)
414-
gate.update()
415-
return gate
417+
return ce.APIClient().create(gate, createPopulation=create_population)
416418

417-
def create_ellipse_gate(self, *args, **kwargs):
419+
def create_ellipse_gate(self, *args, create_population=True, **kwargs):
418420
"""Create a EllipseGate.
419421
420422
Accepts all args and kwargs available for
421423
[`EllipseGate.create()`][cellengine.resources.gate.EllipseGate.create].
422424
"""
423425
gate = EllipseGate.create(self._id, *args, **kwargs)
424-
gate.update()
425-
return gate
426+
return ce.APIClient().create(gate, createPopulation=create_population)
426427

427-
def create_range_gate(self, *args, **kwargs) -> RangeGate:
428+
def create_range_gate(self, *args, create_population=True, **kwargs) -> RangeGate:
428429
"""Create a RangeGate.
429430
430431
Accepts all args and kwargs available for
431432
[`RangeGate.create()`][cellengine.resources.gate.RangeGate.create].
432433
"""
433434
gate = RangeGate.create(self._id, *args, **kwargs)
434-
gate.update()
435-
return gate
435+
return ce.APIClient().create(gate, createPopulation=create_population)
436436

437-
def create_split_gate(self, *args, **kwargs) -> SplitGate:
437+
def create_split_gate(self, *args, create_population=True, **kwargs) -> SplitGate:
438438
"""Create a SplitGate.
439439
440440
Accepts all args and kwargs available for
441441
[`SplitGate.create()`][cellengine.resources.gate.SplitGate.create].
442442
"""
443443
gate = SplitGate.create(self._id, *args, **kwargs)
444-
gate.update()
445-
return gate
444+
return ce.APIClient().create(gate, createPopulation=create_population)
446445

447-
def create_quadrant_gate(self, *args, **kwargs) -> QuadrantGate:
446+
def create_quadrant_gate(
447+
self, *args, create_population=True, **kwargs
448+
) -> QuadrantGate:
448449
"""Create a QuadrantGate.
449450
450451
Accepts all args and kwargs available for
451452
[`QuadrantGate.create()`][cellengine.resources.gate.QuadrantGate.create].
452453
"""
453454
gate = QuadrantGate.create(self._id, *args, **kwargs)
454-
gate.update()
455-
return gate
455+
return ce.APIClient().create(gate, createPopulation=create_population)
456456

457457
def create_population(self, population: Dict) -> Population:
458458
"""Create a complex population

cellengine/resources/gate.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def create(
116116
tailored_per_file: bool = False,
117117
fcs_file_id: str = None,
118118
fcs_file: str = None,
119-
create_population: bool = True,
120119
) -> RectangleGate:
121120
"""Formats a rectangle gate for posting to the CellEngine API.
122121
@@ -154,7 +153,6 @@ def create(
154153
by name is slower than using the ID, as this requires
155154
additional requests to the server. If specified, do not specify
156155
``fcs_file_id``.
157-
create_population (bool): Automatically create corresponding population.
158156
159157
Returns:
160158
A RectangleGate object.
@@ -199,7 +197,6 @@ def create(
199197
model=model,
200198
y_channel=y_channel,
201199
name=name,
202-
# TODO: create_population
203200
) # type: ignore
204201

205202

@@ -246,7 +243,6 @@ def create(
246243
files by name is slower than using the ID, as this requires
247244
additional requests to the server. If specified, do not specify
248245
``fcs_file_id``.
249-
create_population (bool): Automatically create corresponding population.
250246
251247
Returns:
252248
A PolygonGate object.
@@ -348,8 +344,6 @@ def create(
348344
files by name is slower than using the ID, as this requires
349345
additional requests to the server. If specified, do not specify
350346
``fcs_file_id``.
351-
create_population (optional, bool): Automatically create corresponding
352-
population.
353347
354348
Returns:
355349
EllipseGate: An EllipseGate object.
@@ -447,7 +441,6 @@ def create(
447441
files by name is slower than using the ID, as this requires
448442
additional requests to the server. If specified, do not specify
449443
``fcs_file_id``.
450-
create_population (bool): Automatically create corresponding population.
451444
452445
Returns:
453446
A RangeGate object.
@@ -551,7 +544,6 @@ def create(
551544
files by name is slower than using the ID, as this requires
552545
additional requests to the server. If specified, do not specify
553546
``fcs_file_id``.
554-
create_population (bool): Automatically create corresponding population.
555547
556548
Returns:
557549
A QuadrantGate object.
@@ -678,7 +670,6 @@ def create(
678670
files by name is slower than using the ID, as this requires
679671
additional requests to the server. If specified, do not specify
680672
``fcs_file_id``.
681-
create_population (bool): Automatically create corresponding population.
682673
683674
Returns:
684675
A SplitGate object.

tests/unit/resources/test_gates.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,30 @@ def test_create_rectangle_gate(ENDPOINT_BASE, client, experiment, rectangle_gate
268268
assert m["y2"] == 215000
269269

270270

271+
@responses.activate
272+
def test_create_rectangle_gate_without_create_population(
273+
ENDPOINT_BASE, client, experiment, rectangle_gate
274+
):
275+
"""Regression test for #118."""
276+
responses.add(
277+
responses.POST,
278+
f"{ENDPOINT_BASE}/experiments/{EXP_ID}/gates",
279+
status=201,
280+
json=rectangle_gate,
281+
)
282+
rectangle_gate = experiment.create_rectangle_gate(
283+
x_channel="FSC-A",
284+
y_channel="FSC-W",
285+
name="my gate",
286+
x1=60000,
287+
x2=200000,
288+
y1=75000,
289+
y2=215000,
290+
create_population=False,
291+
)
292+
assert "createPopulation=false" in responses.calls[0].request.url
293+
294+
271295
@responses.activate
272296
def test_create_ellipse_gate(ENDPOINT_BASE, client, experiment, ellipse_gate):
273297
responses.add(

0 commit comments

Comments
 (0)