|
1 | 1 | from __future__ import annotations
|
2 |
| -from datetime import datetime |
3 |
| - |
4 |
| -from marshmallow import fields |
5 |
| -from pandas.core.frame import DataFrame |
6 |
| - |
7 |
| -from cellengine.utils.dataclass_mixin import DataClassMixin, ReadOnly |
8 | 2 | from dataclasses import dataclass, field
|
| 3 | +from datetime import datetime |
9 | 4 | import inspect
|
10 | 5 | from math import pi
|
11 |
| -from custom_inherit import doc_inherit |
12 |
| -from typing import Any, Optional, Dict, Union, List |
| 6 | +from typing import Any, Dict, List, Optional, Union |
13 | 7 |
|
| 8 | +from custom_inherit import doc_inherit |
14 | 9 | from dataclasses_json.cfg import config
|
| 10 | +from marshmallow import fields |
| 11 | +from pandas.core.frame import DataFrame |
15 | 12 |
|
16 | 13 | import cellengine as ce
|
17 |
| -from cellengine.resources.population import Population |
18 |
| -from cellengine.resources.scaleset import ScaleSet |
19 |
| -from cellengine.resources.fcs_file import FcsFile |
20 |
| -from cellengine.resources.compensation import Compensation |
| 14 | +from cellengine.payloads.gate_utils import ( |
| 15 | + format_ellipse_gate, |
| 16 | + format_polygon_gate, |
| 17 | + format_quadrant_gate, |
| 18 | + format_range_gate, |
| 19 | + format_rectangle_gate, |
| 20 | + format_split_gate, |
| 21 | +) |
21 | 22 | from cellengine.resources.attachment import Attachment
|
| 23 | +from cellengine.resources.compensation import Compensation |
| 24 | +from cellengine.resources.fcs_file import FcsFile |
22 | 25 | from cellengine.resources.gate import (
|
| 26 | + EllipseGate, |
23 | 27 | Gate,
|
24 |
| - RectangleGate, |
25 | 28 | PolygonGate,
|
| 29 | + QuadrantGate, |
26 | 30 | RangeGate,
|
| 31 | + RectangleGate, |
27 | 32 | SplitGate,
|
28 |
| - EllipseGate, |
29 |
| - QuadrantGate, |
30 | 33 | )
|
| 34 | +from cellengine.resources.population import Population |
| 35 | +from cellengine.resources.scaleset import ScaleSet |
| 36 | +from cellengine.utils.dataclass_mixin import DataClassMixin, ReadOnly |
31 | 37 | from cellengine.utils.helpers import (
|
32 | 38 | CommentList,
|
33 | 39 | datetime_to_timestamp,
|
| 40 | + is_valid_id, |
34 | 41 | timestamp_to_datetime,
|
35 | 42 | )
|
36 | 43 |
|
37 |
| -from cellengine.payloads.gate_utils import ( |
38 |
| - format_rectangle_gate, |
39 |
| - format_polygon_gate, |
40 |
| - format_ellipse_gate, |
41 |
| - format_range_gate, |
42 |
| - format_split_gate, |
43 |
| - format_quadrant_gate, |
44 |
| -) |
45 |
| - |
46 | 44 |
|
47 | 45 | @dataclass
|
48 | 46 | class Experiment(DataClassMixin):
|
@@ -74,7 +72,7 @@ class Experiment(DataClassMixin):
|
74 | 72 | ),
|
75 | 73 | default=ReadOnly(),
|
76 | 74 | ) # type: ignore
|
77 |
| - _active_comp: Optional[Union[int, str, Compensation]] = field( |
| 75 | + _active_comp: Optional[Union[int, str]] = field( |
78 | 76 | default=None, metadata=config(field_name="activeCompensation")
|
79 | 77 | )
|
80 | 78 | data: Optional[Dict[Any, Any]] = field(default=None)
|
@@ -213,28 +211,43 @@ def undelete(self):
|
213 | 211 | del self.deleted
|
214 | 212 |
|
215 | 213 | @property
|
216 |
| - def active_compensation(self) -> Optional[Union[Compensation, int]]: |
217 |
| - active_comp = self._active_comp |
218 |
| - if type(active_comp) is str: |
219 |
| - return ce.APIClient().get_compensation(self._id, active_comp) |
220 |
| - elif type(active_comp) is int: |
221 |
| - return active_comp |
222 |
| - elif active_comp is None: |
223 |
| - return None |
224 |
| - raise ValueError( |
225 |
| - f"Value '{active_comp}' is not a valid for activeCompensation." |
226 |
| - ) |
| 214 | + def active_compensation(self) -> Optional[Union[str, int]]: |
| 215 | + """The most recently used compensation. |
| 216 | +
|
| 217 | + Accepted values are: |
| 218 | +
|
| 219 | + - A Compensation object (value will be set to its `_id`) |
| 220 | + - A Compensation ID |
| 221 | + - A `cellengine` Compensation constant: |
| 222 | + [`UNCOMPENSATED`][cellengine.UNCOMPENSATED], |
| 223 | + [`FILE_INTERNAL`][cellengine.FILE_INTERNAL] or |
| 224 | + [`PER_FILE`][cellengine.PER_FILE]. |
| 225 | +
|
| 226 | + Example: |
| 227 | + ```python |
| 228 | + import cellengine |
| 229 | + exp = cellengine.get_experiment(name='my experiment') |
| 230 | + experiment.active_compensation = cellengine.UNCOMPENSATED |
| 231 | + ``` |
| 232 | + """ |
| 233 | + return self._active_comp |
227 | 234 |
|
228 | 235 | @active_compensation.setter
|
229 |
| - def active_compensation(self, compensation: Union[Compensation, int]): |
230 |
| - if type(compensation) is Compensation: |
| 236 | + def active_compensation(self, compensation: Union[Compensation, int, str]): |
| 237 | + if isinstance(compensation, Compensation): |
231 | 238 | self._active_comp = compensation._id
|
232 |
| - elif ( |
233 |
| - compensation == "UNCOMPENSATED" |
234 |
| - or compensation == "FILE_INTERNAL" |
235 |
| - or compensation == "PER_FILE" |
236 |
| - ): |
| 239 | + elif isinstance(compensation, str) and is_valid_id(compensation): |
| 240 | + self._active_comp = compensation |
| 241 | + elif isinstance(compensation, int) and compensation in [ |
| 242 | + ce.UNCOMPENSATED, |
| 243 | + ce.PER_FILE, |
| 244 | + ce.FILE_INTERNAL, |
| 245 | + ]: |
237 | 246 | self._active_comp = compensation
|
| 247 | + else: |
| 248 | + raise ValueError( |
| 249 | + f"Value '{compensation}' can not be set as the active compensation." |
| 250 | + ) |
238 | 251 |
|
239 | 252 | @property
|
240 | 253 | def attachments(self) -> List[Attachment]:
|
|
0 commit comments