Skip to content

bug(gates): fix create_population argument handling #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cellengine/payloads/gate_utils/ellipse_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def format_ellipse_gate(
tailored_per_file: bool = False,
fcs_file_id: str = None,
fcs_file: str = None,
create_population: bool = True,
):
"""Formats an ellipse gate for posting to the CellEngine API.

Expand Down Expand Up @@ -60,8 +59,6 @@ def format_ellipse_gate(
files by name is slower than using the ID, as this requires
additional requests to the server. If specified, do not specify
``fcs_file_id``.
create_population (optional, bool): Automatically create corresponding
population.

Returns:
EllipseGate: An EllipseGate object.
Expand Down Expand Up @@ -101,5 +98,4 @@ def format_ellipse_gate(
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
3 changes: 0 additions & 3 deletions cellengine/payloads/gate_utils/polygon_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def format_polygon_gate(
tailored_per_file: bool = False,
fcs_file_id: str = None,
fcs_file: str = None,
create_population: bool = True,
):
"""Formats a polygon gate for posting to the CellEngine API.

Expand Down Expand Up @@ -49,7 +48,6 @@ def format_polygon_gate(
the name, an error will be thrown. Looking up files by name is
slower than using the ID, as this requires additional requests
to the server. If specified, do not specify ``fcs_file_id``.
create_population (bool): Automatically create corresponding population.

Returns:
A PolygonGate object.
Expand Down Expand Up @@ -91,5 +89,4 @@ def format_polygon_gate(
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
3 changes: 0 additions & 3 deletions cellengine/payloads/gate_utils/quadrant_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def format_quadrant_gate(
tailored_per_file: bool = False,
fcs_file_id: str = None,
fcs_file: str = None,
create_population: bool = True,
):
"""Formats a quadrant gate for posting to the CellEngine API.

Expand Down Expand Up @@ -64,7 +63,6 @@ def format_quadrant_gate(
the name, an error will be thrown. Looking up files by name is
slower than using the ID, as this requires additional requests
to the server. If specified, do not specify ``fcs_file_id``.
create_population (bool): Automatically create corresponding population.

Returns:
A QuadrantGate object.
Expand Down Expand Up @@ -132,5 +130,4 @@ def format_quadrant_gate(
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
3 changes: 0 additions & 3 deletions cellengine/payloads/gate_utils/range_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def format_range_gate(
tailored_per_file: bool = False,
fcs_file_id: str = None,
fcs_file: str = None,
create_population: bool = True,
):
"""Formats a range gate for posting to the CellEngine API.

Expand Down Expand Up @@ -52,7 +51,6 @@ def format_range_gate(
the name, an error will be thrown. Looking up files by name is
slower than using the ID, as this requires additional requests
to the server. If specified, do not specify ``fcs_file_id``.
create_population (bool): Automatically create corresponding population.

Returns:
A RangeGate object.
Expand Down Expand Up @@ -89,5 +87,4 @@ def format_range_gate(
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
3 changes: 0 additions & 3 deletions cellengine/payloads/gate_utils/rectangle_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def format_rectangle_gate(
tailored_per_file: bool = False,
fcs_file_id: str = None,
fcs_file: str = None,
create_population: bool = True,
):
"""Formats a rectangle gate for posting to the CellEngine API.

Expand Down Expand Up @@ -57,7 +56,6 @@ def format_rectangle_gate(
the name, an error will be thrown. Looking up files by name is
slower than using the ID, as this requires additional requests
to the server. If specified, do not specify ``fcs_file_id``.
create_population (bool): Automatically create corresponding population.

Returns:
A RectangleGate object.
Expand Down Expand Up @@ -99,5 +97,4 @@ def format_rectangle_gate(
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
3 changes: 0 additions & 3 deletions cellengine/payloads/gate_utils/split_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def format_split_gate(
tailored_per_file: bool = False,
fcs_file_id: str = None,
fcs_file: str = None,
create_population: bool = True,
):
"""
Formats a split gate for posting to the CellEngine API.
Expand Down Expand Up @@ -58,7 +57,6 @@ def format_split_gate(
the name, an error will be thrown. Looking up files by name is
slower than using the ID, as this requires additional requests
to the server. If specified, do not specify ``fcs_file_id``.
create_population (bool): Automatically create corresponding population.

Returns:
A SplitGate object.
Expand Down Expand Up @@ -116,5 +114,4 @@ def format_split_gate(
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
5 changes: 1 addition & 4 deletions cellengine/payloads/gate_utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import cellengine as ce


def format_common_gate(
experiment_id, body, tailored_per_file, fcs_file_id, fcs_file, create_population
):
def format_common_gate(experiment_id, body, tailored_per_file, fcs_file_id, fcs_file):
"""
Args:
experiment_id (str): The ID of the experiment to which to add the gate.
Expand All @@ -30,7 +28,6 @@ def format_common_gate(
the name, an error will be thrown. Looking up files by name is
slower than using the ID, as this requires additional requests
to the server. If specified, do not specify ``fcs_file_id``.
create_population (bool): Automatically create corresponding population.
"""
return parse_fcs_file_args(
experiment_id, body, tailored_per_file, fcs_file_id, fcs_file
Expand Down
30 changes: 24 additions & 6 deletions cellengine/resources/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,14 @@ def create_rectangle_gate(
f = inspect.currentframe()
args, _, _, values = inspect.getargvalues(f) # type: ignore
kwargs = {arg: values.get(arg, None) for arg in args}
del kwargs["create_population"]
post_body = format_rectangle_gate(
kwargs.pop("self")._id, # type: ignore
**kwargs,
)
return ce.APIClient().post_gate(self._id, post_body) # type: ignore
return ce.APIClient().post_gate(
self._id, post_body, create_population
) # type: ignore

@doc_inherit(format_polygon_gate)
def create_polygon_gate(
Expand All @@ -457,11 +460,14 @@ def create_polygon_gate(
f = inspect.currentframe()
args, _, _, values = inspect.getargvalues(f) # type: ignore
kwargs = {arg: values.get(arg, None) for arg in args}
del kwargs["create_population"]
post_body = format_polygon_gate(
kwargs.pop("self")._id, # type: ignore
**kwargs,
)
return ce.APIClient().post_gate(self._id, post_body) # type: ignore
return ce.APIClient().post_gate(
self._id, post_body, create_population
) # type: ignore

@doc_inherit(format_ellipse_gate)
def create_ellipse_gate(
Expand All @@ -487,11 +493,14 @@ def create_ellipse_gate(
f = inspect.currentframe()
args, _, _, values = inspect.getargvalues(f) # type: ignore
kwargs = {arg: values.get(arg, None) for arg in args}
del kwargs["create_population"]
post_body = format_ellipse_gate(
kwargs.pop("self")._id, # type: ignore
**kwargs,
)
return ce.APIClient().post_gate(self._id, post_body) # type: ignore
return ce.APIClient().post_gate(
self._id, post_body, create_population
) # type: ignore

@doc_inherit(format_range_gate)
def create_range_gate(
Expand All @@ -514,11 +523,14 @@ def create_range_gate(
f = inspect.currentframe()
args, _, _, values = inspect.getargvalues(f) # type: ignore
kwargs = {arg: values.get(arg, None) for arg in args}
del kwargs["create_population"]
post_body = format_range_gate(
kwargs.pop("self")._id, # type: ignore
**kwargs,
)
return ce.APIClient().post_gate(self._id, post_body) # type: ignore
return ce.APIClient().post_gate(
self._id, post_body, create_population
) # type: ignore

@doc_inherit(format_split_gate)
def create_split_gate(
Expand All @@ -541,11 +553,14 @@ def create_split_gate(
f = inspect.currentframe()
args, _, _, values = inspect.getargvalues(f) # type: ignore
kwargs = {arg: values.get(arg, None) for arg in args}
del kwargs["create_population"]
post_body = format_split_gate(
kwargs.pop("self")._id, # type: ignore
**kwargs,
)
return ce.APIClient().post_gate(self._id, post_body) # type: ignore
return ce.APIClient().post_gate(
self._id, post_body, create_population
) # type: ignore

@doc_inherit(format_quadrant_gate)
def create_quadrant_gate(
Expand All @@ -571,11 +586,14 @@ def create_quadrant_gate(
f = inspect.currentframe()
args, _, _, values = inspect.getargvalues(f) # type: ignore
kwargs = {arg: values.get(arg, None) for arg in args}
del kwargs["create_population"]
post_body = format_quadrant_gate(
kwargs.pop("self")._id, # type: ignore
**kwargs,
)
return ce.APIClient().post_gate(self._id, post_body) # type: ignore
return ce.APIClient().post_gate(
self._id, post_body, create_population
) # type: ignore

def create_population(self, population: Dict) -> Population:
"""Create a complex population
Expand Down
24 changes: 18 additions & 6 deletions cellengine/resources/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def create(
fcs_file: str = None,
create_population: bool = True,
) -> RectangleGate:
g = format_rectangle_gate(**get_args_as_kwargs(cls, locals()))
args = get_args_as_kwargs(cls, locals())
del args["create_population"]
g = format_rectangle_gate(**args)
return cls(g)


Expand All @@ -229,7 +231,9 @@ def create(
fcs_file: str = None,
create_population: bool = True,
) -> PolygonGate:
g = format_polygon_gate(**get_args_as_kwargs(cls, locals()))
args = get_args_as_kwargs(cls, locals())
del args["create_population"]
g = format_polygon_gate(**args)
return cls(g)


Expand Down Expand Up @@ -259,7 +263,9 @@ def create(
fcs_file: str = None,
create_population: bool = True,
) -> EllipseGate:
g = format_ellipse_gate(**get_args_as_kwargs(cls, locals()))
args = get_args_as_kwargs(cls, locals())
del args["create_population"]
g = format_ellipse_gate(**args)
return cls(g)


Expand All @@ -286,7 +292,9 @@ def create(
fcs_file: str = None,
create_population: bool = True,
) -> RangeGate:
g = format_range_gate(**get_args_as_kwargs(cls, locals()))
args = get_args_as_kwargs(cls, locals())
del args["create_population"]
g = format_range_gate(**args)
return cls(g)


Expand Down Expand Up @@ -316,7 +324,9 @@ def create(
fcs_file: str = None,
create_population: bool = True,
) -> QuadrantGate:
g = format_quadrant_gate(**get_args_as_kwargs(cls, locals()))
args = get_args_as_kwargs(cls, locals())
del args["create_population"]
g = format_quadrant_gate(**args)
return cls(g)


Expand All @@ -343,5 +353,7 @@ def create(
fcs_file: str = None,
create_population: bool = True,
) -> SplitGate:
g = format_split_gate(**get_args_as_kwargs(cls, locals()))
args = get_args_as_kwargs(cls, locals())
del args["create_population"]
g = format_split_gate(**args)
return cls(g)
2 changes: 1 addition & 1 deletion cellengine/utils/api_client/APIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _get_id_by_name(self, name, resource_type, experiment_id):
raise RuntimeError(str(e).format(name))

def _lookup_by_name(self, path, query, name):
params = f'query=eq({query},"{name}")&limit=2'
params = {"query": f'eq({query},"{name}")', "limit": 2}
return self._get(f"{self.base_url}/{path}", params=params)

def _handle_response(self, response):
Expand Down
13 changes: 9 additions & 4 deletions cellengine/utils/api_client/BaseAPIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from cellengine.utils.singleton import AbstractSingleton


def prepare_params(params: Dict) -> Dict:
"""Converts Booleans to lower-case strings. (Requests yields upper-case.)"""
return {k: str(v).lower() if type(v) == bool else v for k, v in params.items()}


class BaseAPIClient(metaclass=AbstractSingleton):
@property
@abstractmethod
Expand Down Expand Up @@ -67,7 +72,7 @@ def _get(self, url, params: Dict = None, headers: Dict = None, raw=False) -> Any
response = self.requests_session.get(
url,
headers=self._make_headers(headers),
params=params if params else {},
params=prepare_params(params if params else {}),
)
except Exception as error:
raise error
Expand All @@ -87,7 +92,7 @@ def _post(
url,
json=json,
headers=self._make_headers(headers),
params=params if params else {},
params=prepare_params(params if params else {}),
files=files,
data=data,
)
Expand All @@ -106,7 +111,7 @@ def _patch(
url,
json=json,
headers=self._make_headers(headers),
params=params if params else {},
params=prepare_params(params if params else {}),
files=files,
)
return self._parse_response(response, raw=raw)
Expand All @@ -115,7 +120,7 @@ def _delete(self, url, params: dict = None, headers: dict = None):
response = self.requests_session.delete(
url,
headers=self._make_headers(headers),
params=params if params else {},
params=prepare_params(params if params else {}),
)
try:
if response.ok:
Expand Down
Loading