Skip to content

Commit 9ca5815

Browse files
committed
bug(gates): fix create_population argument handling
1 parent 1bd0005 commit 9ca5815

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

cellengine/resources/experiment.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -394,65 +394,59 @@ 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(self, *args, create_population=True, **kwargs) -> RectangleGate:
398398
"""Create a RectangleGate.
399399
400400
Accepts all args and kwargs available for
401401
[`RectangleGate.create()`][cellengine.resources.gate.RectangleGate.create].
402402
"""
403403
gate = RectangleGate.create(self._id, *args, **kwargs)
404-
gate.update()
405-
return gate
404+
return ce.APIClient().create(gate, createPopulation=create_population)
406405

407-
def create_polygon_gate(self, *args, **kwargs) -> PolygonGate:
406+
def create_polygon_gate(self, *args, create_population=True, **kwargs) -> PolygonGate:
408407
"""Create a PolygonGate.
409408
410409
Accepts all args and kwargs available for
411410
[`PolygonGate.create()`][cellengine.resources.gate.PolygonGate.create].
412411
"""
413412
gate = PolygonGate.create(self._id, *args, **kwargs)
414-
gate.update()
415-
return gate
413+
return ce.APIClient().create(gate, createPopulation=create_population)
416414

417-
def create_ellipse_gate(self, *args, **kwargs):
415+
def create_ellipse_gate(self, *args, create_population=True, **kwargs):
418416
"""Create a EllipseGate.
419417
420418
Accepts all args and kwargs available for
421419
[`EllipseGate.create()`][cellengine.resources.gate.EllipseGate.create].
422420
"""
423421
gate = EllipseGate.create(self._id, *args, **kwargs)
424-
gate.update()
425-
return gate
422+
return ce.APIClient().create(gate, createPopulation=create_population)
426423

427-
def create_range_gate(self, *args, **kwargs) -> RangeGate:
424+
def create_range_gate(self, *args, create_population=True, **kwargs) -> RangeGate:
428425
"""Create a RangeGate.
429426
430427
Accepts all args and kwargs available for
431428
[`RangeGate.create()`][cellengine.resources.gate.RangeGate.create].
432429
"""
433430
gate = RangeGate.create(self._id, *args, **kwargs)
434-
gate.update()
435-
return gate
431+
return ce.APIClient().create(gate, createPopulation=create_population)
436432

437-
def create_split_gate(self, *args, **kwargs) -> SplitGate:
433+
def create_split_gate(self, *args, create_population=True, **kwargs) -> SplitGate:
438434
"""Create a SplitGate.
439435
440436
Accepts all args and kwargs available for
441437
[`SplitGate.create()`][cellengine.resources.gate.SplitGate.create].
442438
"""
443439
gate = SplitGate.create(self._id, *args, **kwargs)
444-
gate.update()
445-
return gate
440+
return ce.APIClient().create(gate, createPopulation=create_population)
446441

447-
def create_quadrant_gate(self, *args, **kwargs) -> QuadrantGate:
442+
def create_quadrant_gate(self, *args, create_population=True, **kwargs) -> QuadrantGate:
448443
"""Create a QuadrantGate.
449444
450445
Accepts all args and kwargs available for
451446
[`QuadrantGate.create()`][cellengine.resources.gate.QuadrantGate.create].
452447
"""
453448
gate = QuadrantGate.create(self._id, *args, **kwargs)
454-
gate.update()
455-
return gate
449+
return ce.APIClient().create(gate, createPopulation=create_population)
456450

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

cellengine/resources/gate.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def create(
104104
tailored_per_file: bool = False,
105105
fcs_file_id: str = None,
106106
fcs_file: str = None,
107-
create_population: bool = True,
108107
) -> RectangleGate:
109108
"""Formats a rectangle gate for posting to the CellEngine API.
110109
@@ -135,7 +134,6 @@ def create(
135134
by name is slower than using the ID, as this requires
136135
additional requests to the server. If specified, do not specify
137136
``fcs_file_id``.
138-
create_population (bool): Automatically create corresponding population.
139137
140138
Returns:
141139
A RectangleGate object.
@@ -179,7 +177,6 @@ def create(
179177
model=model,
180178
y_channel=y_channel,
181179
name=name,
182-
# TODO: create_population
183180
) # type: ignore
184181

185182

@@ -199,7 +196,6 @@ def create(
199196
tailored_per_file: Optional[bool] = False,
200197
fcs_file_id: Optional[str] = None,
201198
fcs_file: Optional[str] = None,
202-
create_population: Optional[bool] = True,
203199
) -> PolygonGate:
204200
"""Formats a polygon gate for posting to the CellEngine API.
205201
@@ -224,7 +220,6 @@ def create(
224220
files by name is slower than using the ID, as this requires
225221
additional requests to the server. If specified, do not specify
226222
``fcs_file_id``.
227-
create_population (bool): Automatically create corresponding population.
228223
229224
Returns:
230225
A PolygonGate object.
@@ -268,7 +263,6 @@ def create(
268263
model=model,
269264
y_channel=y_channel,
270265
name=name,
271-
# TODO: create_population
272266
) # type: ignore
273267

274268

@@ -292,7 +286,6 @@ def create(
292286
tailored_per_file: bool = False,
293287
fcs_file_id: str = None,
294288
fcs_file: str = None,
295-
create_population: bool = True,
296289
) -> EllipseGate:
297290
"""Formats an ellipse gate for posting to the CellEngine API.
298291
@@ -324,8 +317,6 @@ def create(
324317
files by name is slower than using the ID, as this requires
325318
additional requests to the server. If specified, do not specify
326319
``fcs_file_id``.
327-
create_population (optional, bool): Automatically create corresponding
328-
population.
329320
330321
Returns:
331322
EllipseGate: An EllipseGate object.
@@ -372,7 +363,6 @@ def create(
372363
model=model,
373364
y_channel=y_channel,
374365
name=name,
375-
# TODO: create_population
376366
) # type: ignore
377367

378368

@@ -393,7 +383,6 @@ def create(
393383
tailored_per_file: bool = False,
394384
fcs_file_id: str = None,
395385
fcs_file: str = None,
396-
create_population: bool = True,
397386
) -> RangeGate:
398387
"""Formats a range gate for posting to the CellEngine API.
399388
@@ -421,7 +410,6 @@ def create(
421410
files by name is slower than using the ID, as this requires
422411
additional requests to the server. If specified, do not specify
423412
``fcs_file_id``.
424-
create_population (bool): Automatically create corresponding population.
425413
426414
Returns:
427415
A RangeGate object.
@@ -464,7 +452,6 @@ def create(
464452
model=model,
465453
y_channel=None,
466454
name=name,
467-
# TODO: create_population
468455
) # type: ignore
469456

470457

@@ -488,7 +475,6 @@ def create(
488475
tailored_per_file: bool = False,
489476
fcs_file_id: str = None,
490477
fcs_file: str = None,
491-
create_population: bool = True,
492478
) -> QuadrantGate:
493479
"""Formats a quadrant gate for posting to the CellEngine API.
494480
@@ -523,7 +509,6 @@ def create(
523509
files by name is slower than using the ID, as this requires
524510
additional requests to the server. If specified, do not specify
525511
``fcs_file_id``.
526-
create_population (bool): Automatically create corresponding population.
527512
528513
Returns:
529514
A QuadrantGate object.
@@ -593,7 +578,6 @@ def create(
593578
model=model,
594579
y_channel=y_channel,
595580
names=names,
596-
# TODO: create_population
597581
) # type: ignore
598582

599583

@@ -614,7 +598,6 @@ def create(
614598
tailored_per_file: bool = False,
615599
fcs_file_id: str = None,
616600
fcs_file: str = None,
617-
create_population: bool = True,
618601
) -> SplitGate:
619602
"""
620603
Formats a split gate for posting to the CellEngine API.
@@ -648,7 +631,6 @@ def create(
648631
files by name is slower than using the ID, as this requires
649632
additional requests to the server. If specified, do not specify
650633
``fcs_file_id``.
651-
create_population (bool): Automatically create corresponding population.
652634
653635
Returns:
654636
A SplitGate object.
@@ -709,5 +691,4 @@ def create(
709691
model=model,
710692
y_channel=None,
711693
names=names,
712-
# TODO: create_population
713694
) # type: ignore

cellengine/utils/api_client/APIClient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def create(self, entity: CE, **kwargs) -> CE:
147147
if body["_id"] == "None" or body["_id"] is None:
148148
del body["_id"] # https://github.com/primitybio/cellengine/issues/5800
149149

150+
import pdb; pdb.set_trace() #fmt: skip
150151
res = self._post(path, json=body, params=kwargs)
151152
return converter.structure(res, structure_class) # type: ignore
152153

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)