|
| 1 | +import attr |
| 2 | +import munch |
| 3 | +<<<<<<< HEAD |
| 4 | +from . import helpers |
| 5 | +from .Gates import ( |
| 6 | + create_rectangle_gate, |
| 7 | + create_ellipse_gate, |
| 8 | + create_polygon_gate, |
| 9 | + create_range_gate, |
| 10 | + create_split_gate, |
| 11 | + create_quadrant_gate, |
| 12 | +) |
| 13 | +======= |
| 14 | +from . import helpers |
| 15 | +from .Gates import (create_rectangle_gate, create_ellipse_gate, |
| 16 | + create_polygon_gate, create_range_gate, create_split_gate, |
| 17 | + create_quadrant_gate) |
| 18 | +>>>>>>> a55497c... changed helpers to helpers |
| 19 | +from .Gates.gate_util import create_gates |
| 20 | + |
| 21 | + |
| 22 | +@attr.s(repr=False) |
| 23 | +class Gate(object): |
| 24 | + """A class representing a CellEngine gate. |
| 25 | + |
| 26 | + Gates are geometric shapes that define boundaries within which events |
| 27 | + (cells) must be contained to be considered part of a population. |
| 28 | + |
| 29 | + Gates may be any one of RectangleGate, PolygonGate, EllipseGate, RangeGate, |
| 30 | + QuadrantGate or SplitGate. See ``help(cellengine.Gate.<Gate Type>)`` for |
| 31 | + specific args. |
| 32 | + |
| 33 | + When tailoring a gate to a file, a new gate is created with the same GID as |
| 34 | + the original gate, but with an fcs_file_id property set to the file to which |
| 35 | + the gate is tailored. To create a tailored gate, first create a global |
| 36 | + tailored gate by passing ``tailored_per_file=True`` and |
| 37 | + ``fcs_file_id=None`` to a gate creation method. Subsequent tailored gates |
| 38 | + may be created with ``tailored_per_file=True`` and ``gid=<global gate |
| 39 | + gid>``. |
| 40 | + |
| 41 | + The update and delete API endpoints accept requests by GID to make |
| 42 | + for efficient updates to families of tailored gates. |
| 43 | + |
| 44 | + Compound gates (quadrant and split) are made up of "sectors." Quadrant |
| 45 | + gates have four sectors (upper-right, upper-left, lower-left, lower-right) |
| 46 | + and split gates have two sectors (left and right). In addition to the |
| 47 | + top-level GID (like simple gates), these gates have model.gids and names |
| 48 | + lists that specify the GID and name for each sector, in the order shown |
| 49 | + above. Populations using compound gates must reference these sector GIDs; |
| 50 | + referencing the top-level GID of a compound gate is meaningless. |
| 51 | + """ |
| 52 | + |
| 53 | + def __repr__(self): |
| 54 | + return "Gate(_id='{0}', name='{1}', type={2})".format( |
| 55 | + self._id, self.name, self.type |
| 56 | + ) |
| 57 | + |
| 58 | + _properties = attr.ib(default={}, repr=False) |
| 59 | + |
| 60 | +<<<<<<< HEAD |
| 61 | + _id = helpers.GetSet("_id", read_only=True) |
| 62 | + |
| 63 | + name = helpers.GetSet("name") |
| 64 | + |
| 65 | + # TODO: bad usage of a Python builtin; can we change this? (is functional) |
| 66 | + type = helpers.GetSet("type") |
| 67 | + |
| 68 | + experiment_id = helpers.GetSet("experimentId", read_only=True) |
| 69 | + |
| 70 | + gid = helpers.GetSet("gid") |
| 71 | + |
| 72 | + x_channel = helpers.GetSet("xChannel") |
| 73 | + |
| 74 | + y_channel = helpers.GetSet("yChannel") |
| 75 | + |
| 76 | + tailored_per_file = helpers.GetSet("tailoredPerFile") |
| 77 | + |
| 78 | + fcs_file_id = helpers.GetSet("fcsFileId") |
| 79 | + |
| 80 | + parent_population_id = helpers.GetSet("parentPopulationId") |
| 81 | + |
| 82 | + names = helpers.GetSet("names") |
| 83 | +======= |
| 84 | + _id = helpers.GetSet('_id', read_only=True) |
| 85 | + |
| 86 | + name = helpers.GetSet('name') |
| 87 | + |
| 88 | + # TODO: bad usage of a Python builtin; can we change this? (is functional) |
| 89 | + type = helpers.GetSet('type') |
| 90 | + |
| 91 | + experiment_id = helpers.GetSet('experimentId', read_only=True) |
| 92 | + |
| 93 | + gid = helpers.GetSet('gid') |
| 94 | + |
| 95 | + x_channel = helpers.GetSet('xChannel') |
| 96 | + |
| 97 | + y_channel = helpers.GetSet('yChannel') |
| 98 | + |
| 99 | + tailored_per_file = helpers.GetSet('tailoredPerFile') |
| 100 | + |
| 101 | + fcs_file_id = helpers.GetSet('fcsFileId') |
| 102 | + |
| 103 | + parent_population_id = helpers.GetSet('parentPopulationId') |
| 104 | + |
| 105 | + names = helpers.GetSet('names') |
| 106 | +>>>>>>> a55497c... changed helpers to helpers |
| 107 | + |
| 108 | + @property |
| 109 | + def model(self): |
| 110 | + """Return an attribute-style dict of the model. |
| 111 | + |
| 112 | + NOTE: This approach does allow users to change the model properties to |
| 113 | + invalid values (i.e. 'rectangle' to a str from a dict). We could |
| 114 | + prevent this by making Gate.model return a __slot__ class "Model", where each |
| 115 | + attr of Model was built dynamically. I wrote it this way at first, but |
| 116 | + couldn't figure out a way to write both get and set attribute-style accessors |
| 117 | + for the class. Munch does this really nicely. |
| 118 | + |
| 119 | + As it is, this relies on the API to validate the model. If necessary, I |
| 120 | + can write validators in here as well. |
| 121 | + """ |
| 122 | + model = self._properties["model"] |
| 123 | + if type(model) is not Gate._Munch: |
| 124 | + self._properties["model"] = munch.munchify(model, factory=self._Munch) |
| 125 | + return model |
| 126 | + |
| 127 | + @model.setter |
| 128 | + def model(self, val): |
| 129 | + model = self._properties["model"] |
| 130 | + model.update(val) |
| 131 | + |
| 132 | + class _Munch(munch.Munch): |
| 133 | + """Extend the Munch class for a dict-like __repr__""" |
| 134 | + |
| 135 | + def __repr__(self): |
| 136 | + return "{0}".format(dict.__repr__(self)) |
| 137 | + |
| 138 | + # gate creation methods |
| 139 | + |
| 140 | + create_gates = staticmethod(create_gates) |
| 141 | + |
| 142 | + create_rectangle_gate = staticmethod(create_rectangle_gate) |
| 143 | + |
| 144 | + create_polygon_gate = staticmethod(create_polygon_gate) |
| 145 | + |
| 146 | + create_ellipse_gate = staticmethod(create_ellipse_gate) |
| 147 | + |
| 148 | + create_range_gate = staticmethod(create_range_gate) |
| 149 | + |
| 150 | + create_split_gate = staticmethod(create_split_gate) |
| 151 | + |
| 152 | + create_quadrant_gate = staticmethod(create_quadrant_gate) |
0 commit comments