1
+ from cellengine import loader
1
2
import re
2
-
3
- from ..fcsfile import FcsFile
4
3
from .. import gate # circular import here
5
4
from .. import _helpers
6
5
6
+ cellengine = __import__ (__name__ .split ("." )[0 ])
7
+
7
8
8
- def common_gate_create (experiment_id , body , tailored_per_file , fcs_file_id ,
9
- fcs_file , create_population ):
9
+ def common_gate_create (
10
+ experiment_id , body , tailored_per_file , fcs_file_id , fcs_file , create_population
11
+ ):
10
12
"""
11
13
<Description>
12
14
@@ -46,40 +48,37 @@ def common_gate_create(experiment_id, body, tailored_per_file, fcs_file_id,
46
48
Example:
47
49
<Example>
48
50
"""
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
- )
51
+ body = parse_fcs_file_args (
52
+ experiment_id , body , tailored_per_file , fcs_file_id , fcs_file
53
+ )
54
+
55
+ body = _helpers .convert_dict (body , "snake_to_camel" )
56
+ res = _helpers .base_create (
57
+ gate .Gate ,
58
+ url = "experiments/{0}/gates" .format (experiment_id ),
59
+ expected_status = 201 ,
60
+ json = body ,
61
+ params = {"createPopulation" : create_population },
62
+ )
59
63
return res
60
64
61
65
62
- def parse_fcs_file_args (experiment_id , body , tailored_per_file , fcs_file_id ,
63
- fcs_file ):
66
+ def parse_fcs_file_args (experiment_id , body , tailored_per_file , fcs_file_id , fcs_file ):
64
67
"""Find the fcs file ID if 'tailored_per_file' and either 'fcs_file' or
65
68
'fcs_file_id' are specified."""
66
69
if fcs_file is not None and fcs_file_id is not None :
67
70
raise ValueError ("Please specify only 'fcs_file' or 'fcs_file_id'." )
68
71
if fcs_file is not None and tailored_per_file is True : # lookup by name
69
72
_file = get_fcsfile (experiment_id , name = fcs_file )
70
73
fcs_file_id = _file ._id
71
- body [' tailoredPerFile' ] = tailored_per_file
72
- body [' fcsFileId' ] = fcs_file_id
74
+ body [" tailoredPerFile" ] = tailored_per_file
75
+ body [" fcsFileId" ] = fcs_file_id
73
76
return body
74
77
75
78
76
79
def get_fcsfile (experiment_id , _id = None , name = None ):
77
- if _id :
78
- content = _helpers .base_get ("experiments/{0}/fcsfiles/{1}" .format (experiment_id , _id ))
79
- content = FcsFile (properties = content )
80
- else :
81
- content = _helpers .load_fcsfile_by_name (experiment_id , name )
82
- return content
80
+ fcs_loader = loader .FcsFileLoader (experiment_id = experiment_id , id = _id , name = name )
81
+ return fcs_loader .load ()
83
82
84
83
85
84
def create_gates (experiment_id = None , gates = None , create_all_populations = True ):
@@ -108,8 +107,9 @@ def create_gates(experiment_id=None, gates=None, create_all_populations=True):
108
107
``help(cellengine.Gate.<Gate Type>)``.
109
108
fcs_file_id (optional): ``str``: ID of FCS file, if tailored per file. Use
110
109
``None`` for the global gate in the tailored gate group.
111
- tailored_per_file (optional): ``bool``: Whether this gate is tailored per FCS file.
112
- names (optional): ``list(str)``: For compound gates, a list of gate names.
110
+ tailored_per_file (optional): ``bool``: Whether this gate is
111
+ tailored per FCS file. names (optional): ``list(str)``: For
112
+ compound gates, a list of gate names.
113
113
create_population (optional): Whether to create populations for each gate.
114
114
create_populations: Whether to create populations for all gates. If set
115
115
to False, ``create_population`` may be specified for each gate.
@@ -119,23 +119,25 @@ def create_gates(experiment_id=None, gates=None, create_all_populations=True):
119
119
"""
120
120
prepared_gates = []
121
121
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 ()})
122
+ g .update ({" _id" : _helpers .generate_id ()})
123
+ if " gid" not in g .keys ():
124
+ g .update ({" gid" : _helpers .generate_id ()})
125
125
prepared_gates .append (g )
126
126
127
127
new_gates = []
128
128
for each_gate in prepared_gates :
129
129
if create_all_populations is False :
130
- create_populations = each_gate .get (' create_population' , False )
130
+ create_populations = each_gate .get (" create_population" , False )
131
131
else :
132
132
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 )
133
+ new_gate = common_gate_create (
134
+ experiment_id = each_gate .get ("experiment_id" , experiment_id ),
135
+ body = each_gate ,
136
+ tailored_per_file = each_gate .get ("tailored_per_file" , False ),
137
+ fcs_file_id = each_gate .get ("fcs_file_id" , None ),
138
+ fcs_file = each_gate .get ("fcs_file" , None ),
139
+ create_population = create_populations ,
140
+ )
139
141
new_gates .append (new_gate )
140
142
141
143
return new_gates
@@ -175,12 +177,14 @@ def delete_gates(experiment_id, _id=None, gid=None, exclude=None):
175
177
176
178
177
179
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>' ]
180
+ desc = child_doc [: child_doc .index ("Args" )].strip ()
181
+ args = child_doc [child_doc .index ("Args" ) + 5 : child_doc .index ("Returns" )].strip ()
182
+ args = re .sub ("\n " , "\n " , args )
183
+ returns = child_doc [
184
+ child_doc .index ("Returns" ) + 10 : child_doc .index ("Example" )
185
+ ].strip ()
186
+ example = child_doc [child_doc .index ("Example" ) + 10 :].strip ()
187
+ keys = ["<Description>" , "<Gate Args>" , "<Returns>" , "<Example>" ]
184
188
sections = [desc , args , returns , example ]
185
189
docs = prnt_doc
186
190
for key , section in zip (keys , sections ):
0 commit comments