|
5 | 5 | from .. import _helpers
|
6 | 6 |
|
7 | 7 |
|
8 |
| -def common_gate_create(experiment_id, body, tailored_per_file, fcs_file_id, |
9 |
| - fcs_file, create_population): |
| 8 | +def common_gate_create( |
| 9 | + experiment_id, body, tailored_per_file, fcs_file_id, fcs_file, create_population |
| 10 | +): |
10 | 11 | """
|
11 | 12 | <Description>
|
12 | 13 |
|
@@ -46,36 +47,39 @@ def common_gate_create(experiment_id, body, tailored_per_file, fcs_file_id,
|
46 | 47 | Example:
|
47 | 48 | <Example>
|
48 | 49 | """
|
49 |
| - body = parse_fcs_file_args(experiment_id, body, tailored_per_file, |
50 |
| - fcs_file_id, fcs_file) |
51 |
| - |
52 |
| - body = _helpers.convert_dict(body, 'snake_to_camel') |
53 |
| - res = _helpers.base_create(gate.Gate, |
54 |
| - url="experiments/{0}/gates".format(experiment_id), |
55 |
| - expected_status=201, |
56 |
| - json=body, params={'createPopulation': |
57 |
| - create_population} |
58 |
| - ) |
| 50 | + body = parse_fcs_file_args( |
| 51 | + experiment_id, body, tailored_per_file, fcs_file_id, fcs_file |
| 52 | + ) |
| 53 | + |
| 54 | + body = _helpers.convert_dict(body, "snake_to_camel") |
| 55 | + res = _helpers.base_create( |
| 56 | + gate.Gate, |
| 57 | + url="experiments/{0}/gates".format(experiment_id), |
| 58 | + expected_status=201, |
| 59 | + json=body, |
| 60 | + params={"createPopulation": create_population}, |
| 61 | + ) |
59 | 62 | return res
|
60 | 63 |
|
61 | 64 |
|
62 |
| -def parse_fcs_file_args(experiment_id, body, tailored_per_file, fcs_file_id, |
63 |
| - fcs_file): |
| 65 | +def parse_fcs_file_args(experiment_id, body, tailored_per_file, fcs_file_id, fcs_file): |
64 | 66 | """Find the fcs file ID if 'tailored_per_file' and either 'fcs_file' or
|
65 | 67 | 'fcs_file_id' are specified."""
|
66 | 68 | if fcs_file is not None and fcs_file_id is not None:
|
67 | 69 | raise ValueError("Please specify only 'fcs_file' or 'fcs_file_id'.")
|
68 | 70 | if fcs_file is not None and tailored_per_file is True: # lookup by name
|
69 | 71 | _file = get_fcsfile(experiment_id, name=fcs_file)
|
70 | 72 | fcs_file_id = _file._id
|
71 |
| - body['tailoredPerFile'] = tailored_per_file |
72 |
| - body['fcsFileId'] = fcs_file_id |
| 73 | + body["tailoredPerFile"] = tailored_per_file |
| 74 | + body["fcsFileId"] = fcs_file_id |
73 | 75 | return body
|
74 | 76 |
|
75 | 77 |
|
76 | 78 | def get_fcsfile(experiment_id, _id=None, name=None):
|
77 | 79 | if _id:
|
78 |
| - content = _helpers.base_get("experiments/{0}/fcsfiles/{1}".format(experiment_id, _id)) |
| 80 | + content = _helpers.base_get( |
| 81 | + "experiments/{0}/fcsfiles/{1}".format(experiment_id, _id) |
| 82 | + ) |
79 | 83 | content = FcsFile(properties=content)
|
80 | 84 | else:
|
81 | 85 | content = _helpers.load_fcsfile_by_name(experiment_id, name)
|
@@ -119,23 +123,25 @@ def create_gates(experiment_id=None, gates=None, create_all_populations=True):
|
119 | 123 | """
|
120 | 124 | prepared_gates = []
|
121 | 125 | for g in gates:
|
122 |
| - g.update({'_id': _helpers.generate_id()}) |
123 |
| - if 'gid' not in g.keys(): |
124 |
| - g.update({'gid': _helpers.generate_id()}) |
| 126 | + g.update({"_id": _helpers.generate_id()}) |
| 127 | + if "gid" not in g.keys(): |
| 128 | + g.update({"gid": _helpers.generate_id()}) |
125 | 129 | prepared_gates.append(g)
|
126 | 130 |
|
127 | 131 | new_gates = []
|
128 | 132 | for each_gate in prepared_gates:
|
129 | 133 | if create_all_populations is False:
|
130 |
| - create_populations = each_gate.get('create_population', False) |
| 134 | + create_populations = each_gate.get("create_population", False) |
131 | 135 | else:
|
132 | 136 | create_populations = create_all_populations
|
133 |
| - new_gate = common_gate_create(experiment_id=each_gate.get('experiment_id', experiment_id), |
134 |
| - body=each_gate, |
135 |
| - tailored_per_file=each_gate.get('tailored_per_file', False), |
136 |
| - fcs_file_id=each_gate.get('fcs_file_id', None), |
137 |
| - fcs_file=each_gate.get('fcs_file', None), |
138 |
| - create_population=create_populations) |
| 137 | + new_gate = common_gate_create( |
| 138 | + experiment_id=each_gate.get("experiment_id", experiment_id), |
| 139 | + body=each_gate, |
| 140 | + tailored_per_file=each_gate.get("tailored_per_file", False), |
| 141 | + fcs_file_id=each_gate.get("fcs_file_id", None), |
| 142 | + fcs_file=each_gate.get("fcs_file", None), |
| 143 | + create_population=create_populations, |
| 144 | + ) |
139 | 145 | new_gates.append(new_gate)
|
140 | 146 |
|
141 | 147 | return new_gates
|
@@ -175,12 +181,14 @@ def delete_gates(experiment_id, _id=None, gid=None, exclude=None):
|
175 | 181 |
|
176 | 182 |
|
177 | 183 | def gate_style(prnt_doc, child_doc):
|
178 |
| - desc = child_doc[:child_doc.index('Args')].strip() |
179 |
| - args = child_doc[child_doc.index('Args')+5:child_doc.index('Returns')].strip() |
180 |
| - args = re.sub('\n', '\n ', args) |
181 |
| - returns = child_doc[child_doc.index('Returns')+10:child_doc.index('Example')].strip() |
182 |
| - example = child_doc[child_doc.index('Example')+10:].strip() |
183 |
| - keys = ['<Description>', '<Gate Args>', '<Returns>', '<Example>'] |
| 184 | + desc = child_doc[: child_doc.index("Args")].strip() |
| 185 | + args = child_doc[child_doc.index("Args") + 5 : child_doc.index("Returns")].strip() |
| 186 | + args = re.sub("\n", "\n ", args) |
| 187 | + returns = child_doc[ |
| 188 | + child_doc.index("Returns") + 10 : child_doc.index("Example") |
| 189 | + ].strip() |
| 190 | + example = child_doc[child_doc.index("Example") + 10 :].strip() |
| 191 | + keys = ["<Description>", "<Gate Args>", "<Returns>", "<Example>"] |
184 | 192 | sections = [desc, args, returns, example]
|
185 | 193 | docs = prnt_doc
|
186 | 194 | for key, section in zip(keys, sections):
|
|
0 commit comments