Skip to content

Ge/19 #20

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 5 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
23 changes: 0 additions & 23 deletions Makefile

This file was deleted.

64 changes: 42 additions & 22 deletions cellengine/Gates/ellipse_gate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
from custom_inherit import doc_inherit
from .gate_util import common_gate_create, gate_style
# from custom_inherit import doc_inherit
from .gate_util import create_common_gate, gate_style
from .. import _helpers

@doc_inherit(common_gate_create, style=gate_style)
def create_ellipse_gate(experiment_id, x_channel, y_channel, name,
x, y, angle, major, minor, label=[], gid=None, locked=False,
parent_population_id=None, parent_population=None,
tailored_per_file=False, fcs_file_id=None,
fcs_file=None, create_population=True):
# @doc_inherit(create_common_gate, style=gate_style)
def create_ellipse_gate(
experiment_id,
x_channel,
y_channel,
name,
x,
y,
angle,
major,
minor,
label=[],
gid=None,
locked=False,
parent_population_id=None,
parent_population=None,
tailored_per_file=False,
fcs_file_id=None,
fcs_file=None,
create_population=True,
):
"""Creates an ellipse gate.

Args:
Expand All @@ -33,22 +48,27 @@ def create_ellipse_gate(experiment_id, x_channel, y_channel, name,
gid = _helpers.generate_id()

model = {
'locked': locked,
'label': label,
'ellipse': {'angle': angle, 'major': major, 'minor': minor, 'center': [x, y]}
"locked": locked,
"label": label,
"ellipse": {"angle": angle, "major": major, "minor": minor, "center": [x, y]},
}

body = {
'experimentId': experiment_id,
'name': name,
'type': 'EllipseGate',
'gid': gid,
'xChannel': x_channel,
'yChannel': y_channel,
'parentPopulationId': parent_population_id,
'model': model
"experimentId": experiment_id,
"name": name,
"type": "EllipseGate",
"gid": gid,
"xChannel": x_channel,
"yChannel": y_channel,
"parentPopulationId": parent_population_id,
"model": model,
}

return common_gate_create(experiment_id, body=body,
tailored_per_file=tailored_per_file, fcs_file_id=fcs_file_id,
fcs_file=fcs_file, create_population=create_population)
return create_common_gate(
experiment_id,
body=body,
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
68 changes: 35 additions & 33 deletions cellengine/Gates/gate_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from .. import _helpers


def common_gate_create(experiment_id, body, tailored_per_file, fcs_file_id,
fcs_file, create_population):
def create_common_gate(
experiment_id, body, tailored_per_file, fcs_file_id, fcs_file, create_population
):
"""
<Description>

Expand Down Expand Up @@ -46,36 +47,33 @@ def common_gate_create(experiment_id, body, tailored_per_file, fcs_file_id,
Example:
<Example>
"""
body = parse_fcs_file_args(experiment_id, body, tailored_per_file,
fcs_file_id, fcs_file)
body = parse_fcs_file_args(
experiment_id, body, tailored_per_file, fcs_file_id, fcs_file
)

body = _helpers.convert_dict(body, 'snake_to_camel')
res = _helpers.base_create(gate.Gate,
url="experiments/{0}/gates".format(experiment_id),
expected_status=201,
json=body, params={'createPopulation':
create_population}
)
return res
body = _helpers.convert_dict(body, "snake_to_camel")

return body


def parse_fcs_file_args(experiment_id, body, tailored_per_file, fcs_file_id,
fcs_file):
def parse_fcs_file_args(experiment_id, body, tailored_per_file, fcs_file_id, fcs_file):
"""Find the fcs file ID if 'tailored_per_file' and either 'fcs_file' or
'fcs_file_id' are specified."""
if fcs_file is not None and fcs_file_id is not None:
raise ValueError("Please specify only 'fcs_file' or 'fcs_file_id'.")
if fcs_file is not None and tailored_per_file is True: # lookup by name
_file = get_fcsfile(experiment_id, name=fcs_file)
fcs_file_id = _file._id
body['tailoredPerFile'] = tailored_per_file
body['fcsFileId'] = fcs_file_id
body["tailoredPerFile"] = tailored_per_file
body["fcsFileId"] = fcs_file_id
return body


def get_fcsfile(experiment_id, _id=None, name=None):
if _id:
content = _helpers.base_get("experiments/{0}/fcsfiles/{1}".format(experiment_id, _id))
content = _helpers.base_get(
"experiments/{0}/fcsfiles/{1}".format(experiment_id, _id)
)
content = FcsFile(properties=content)
else:
content = _helpers.load_fcsfile_by_name(experiment_id, name)
Expand Down Expand Up @@ -119,23 +117,25 @@ def create_gates(experiment_id=None, gates=None, create_all_populations=True):
"""
prepared_gates = []
for g in gates:
g.update({'_id': _helpers.generate_id()})
if 'gid' not in g.keys():
g.update({'gid': _helpers.generate_id()})
g.update({"_id": _helpers.generate_id()})
if "gid" not in g.keys():
g.update({"gid": _helpers.generate_id()})
prepared_gates.append(g)

new_gates = []
for each_gate in prepared_gates:
if create_all_populations is False:
create_populations = each_gate.get('create_population', False)
create_populations = each_gate.get("create_population", False)
else:
create_populations = create_all_populations
new_gate = common_gate_create(experiment_id=each_gate.get('experiment_id', experiment_id),
body=each_gate,
tailored_per_file=each_gate.get('tailored_per_file', False),
fcs_file_id=each_gate.get('fcs_file_id', None),
fcs_file=each_gate.get('fcs_file', None),
create_population=create_populations)
new_gate = create_common_gate(
experiment_id=each_gate.get("experiment_id", experiment_id),
body=each_gate,
tailored_per_file=each_gate.get("tailored_per_file", False),
fcs_file_id=each_gate.get("fcs_file_id", None),
fcs_file=each_gate.get("fcs_file", None),
create_population=create_populations,
)
new_gates.append(new_gate)

return new_gates
Expand Down Expand Up @@ -175,12 +175,14 @@ def delete_gates(experiment_id, _id=None, gid=None, exclude=None):


def gate_style(prnt_doc, child_doc):
desc = child_doc[:child_doc.index('Args')].strip()
args = child_doc[child_doc.index('Args')+5:child_doc.index('Returns')].strip()
args = re.sub('\n', '\n ', args)
returns = child_doc[child_doc.index('Returns')+10:child_doc.index('Example')].strip()
example = child_doc[child_doc.index('Example')+10:].strip()
keys = ['<Description>', '<Gate Args>', '<Returns>', '<Example>']
desc = child_doc[: child_doc.index("Args")].strip()
args = child_doc[child_doc.index("Args") + 5 : child_doc.index("Returns")].strip()
args = re.sub("\n", "\n ", args)
returns = child_doc[
child_doc.index("Returns") + 10 : child_doc.index("Example")
].strip()
example = child_doc[child_doc.index("Example") + 10 :].strip()
keys = ["<Description>", "<Gate Args>", "<Returns>", "<Example>"]
sections = [desc, args, returns, example]
docs = prnt_doc
for key, section in zip(keys, sections):
Expand Down
65 changes: 41 additions & 24 deletions cellengine/Gates/polygon_gate.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import numpy
from custom_inherit import doc_inherit
from .gate_util import common_gate_create, gate_style

# from custom_inherit import doc_inherit
from .gate_util import create_common_gate, gate_style
from .. import _helpers


@doc_inherit(common_gate_create, style=gate_style)
def create_polygon_gate(experiment_id, x_channel, y_channel, name,
x_vertices, y_vertices, label=[], gid=None, locked=False,
parent_population_id=None, parent_population=None,
tailored_per_file=False, fcs_file_id=None,
fcs_file=None, create_population=True):
# @doc_inherit(create_common_gate, style=gate_style)
def create_polygon_gate(
experiment_id,
x_channel,
y_channel,
name,
x_vertices,
y_vertices,
label=[],
gid=None,
locked=False,
parent_population_id=None,
parent_population=None,
tailored_per_file=False,
fcs_file_id=None,
fcs_file=None,
create_population=True,
):
"""Creates a polygon gate.

Args:
Expand All @@ -22,7 +35,7 @@ def create_polygon_gate(experiment_id, x_channel, y_channel, name,
A PolygonGate object.

Example:
experiment.create_polygon_gate(experiment_id, x_channel="FSC-A",
experiment.create_polygon_gate(x_channel="FSC-A",
y_channel="FSC-W", name="my gate", x_vertices=[1, 2, 3], y_vertices=[4,
5, 6])
"""
Expand All @@ -32,23 +45,27 @@ def create_polygon_gate(experiment_id, x_channel, y_channel, name,
gid = _helpers.generate_id()

model = {
'locked': locked,
'label': label,
'polygon': {'vertices': [[a, b] for (a, b) in zip(x_vertices, y_vertices)]}
"locked": locked,
"label": label,
"polygon": {"vertices": [[a, b] for (a, b) in zip(x_vertices, y_vertices)]},
}

body = {
'experimentId': experiment_id,
'name': name,
'type': 'PolygonGate',
'gid': gid,
'xChannel': x_channel,
'yChannel': y_channel,
'parentPopulationId': parent_population_id,
'model': model
"experimentId": experiment_id,
"name": name,
"type": "PolygonGate",
"gid": gid,
"xChannel": x_channel,
"yChannel": y_channel,
"parentPopulationId": parent_population_id,
"model": model,
}

return common_gate_create(experiment_id, body=body,
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id, fcs_file=fcs_file,
create_population=create_population)
return create_common_gate(
experiment_id,
body=body,
tailored_per_file=tailored_per_file,
fcs_file_id=fcs_file_id,
fcs_file=fcs_file,
create_population=create_population,
)
Loading