|
12 | 12 | from middleware.graphers.turtle_utils import actual_filename |
13 | 13 | from routes.job_utils import fetch_job |
14 | 14 |
|
15 | | -# def _convert_model(model): |
16 | | -# # Convert the model to a generic JSON structure. |
17 | | -# struct = model.to_struct() |
18 | | -# # Check that struct isn't empty. |
19 | | -# assert struct |
20 | | -# if 'rows' in struct: |
21 | | -# # This is not strictly json; more like a list than a dict structure. |
22 | | -# rows_list = struct['rows'] |
23 | | -# return rows_list |
24 | | -# else: |
25 | | -# return struct |
26 | | - |
27 | | -def model_to_json(model): |
28 | | - """ |
29 | | - Converts models to json for the front-end. |
30 | | - """ |
31 | | - #TODO: can access the list directly, no longer need this. |
32 | | - # Validate the model submitted before processing. |
33 | | - assert isinstance(model, list) |
34 | | - # model.validate() |
35 | | - # Conversion. |
36 | | - # print("model_to_json() called with model: {0}".format(str(model))) |
37 | | - return model |
38 | | - # if isinstance(model, models.Base): |
39 | | - # return _convert_model(model) |
40 | | - # else: |
41 | | - # raise Exception('model_to_json() called for a model without a handler.') |
42 | | - |
43 | 15 | def store(pipeline): |
44 | 16 | """ |
45 | 17 | Stores the pipeline (via Pickle) to Redis DB and creates a pipeline id for return. |
@@ -95,39 +67,6 @@ def unpickle(pickled_file): |
95 | 67 | def dump(obj, path): |
96 | 68 | dill.dump(obj, open(path, 'wb')) |
97 | 69 |
|
98 | | -class SubtypingRow(models.Base): |
99 | | - def __init__(self, analysis="", contigid="", filename="", hitcutoff="", hitname="", hitorientation="", hitstart="",hitstop=""): |
100 | | - self.analysis = analysis |
101 | | - self.contigid = contigid |
102 | | - self.filename = filename |
103 | | - self.hitcutoff = hitcutoff |
104 | | - self.hitname = hitname |
105 | | - self.hitorientation = hitorientation |
106 | | - self.hitstart = hitstart |
107 | | - self.hitstop = hitstop |
108 | | - |
109 | | - |
110 | | -class SubtypingResult(models.Base): |
111 | | - def __init__(self, rows=None): |
112 | | - if not rows: |
113 | | - rows = [] |
114 | | - self.rows = rows |
115 | | - |
116 | | -class PhylotyperRow(models.Base): |
117 | | - def __init__(self): |
118 | | - self.contig = fields.StringField(nullable=True) |
119 | | - self.genome = fields.StringField() |
120 | | - self.probability = fields.StringField(nullable=True) # actually float |
121 | | - self.start = fields.StringField(nullable=True) # actually int |
122 | | - self.stop = fields.StringField(nullable=True) # actually int |
123 | | - self.subtype = fields.StringField() |
124 | | - self.subtype_gene = fields.StringField(nullable=True) |
125 | | - |
126 | | -class PhylotyperResult(models.Base): |
127 | | - def __init__(self): |
128 | | - self.rows = fields.ListField([PhylotyperRow], nullable=True) |
129 | | - |
130 | | - |
131 | 70 | class Job(): |
132 | 71 | def __init__(self, rq_job, name="", transitory=True, backlog=True, display=False): |
133 | 72 | """ |
@@ -385,14 +324,12 @@ def to_json(self): |
385 | 324 | l = [] |
386 | 325 | for j in completed_jobs: |
387 | 326 | rq_job = j.rq_job |
388 | | - model = rq_job.result |
| 327 | + lr = rq_job.result |
389 | 328 | try: |
390 | | - # TODO: This is not correct as while the new ECTYper call does return a model, the display_subtyping() call that the return job is associated with will already convert the result to a list and return it. |
391 | | - assert isinstance(model, (models.Base,list)) |
| 329 | + assert isinstance(l, (models.Base,list)) |
392 | 330 | except: |
393 | 331 | raise Exception("to_json() called for job {0} with result of type {1} and info {2}".format(j.name, type(model), str(model))) |
394 | | - list_json = model_to_json(model) |
395 | | - l += list_json |
| 332 | + l += lr |
396 | 333 | return jsonify(l) |
397 | 334 |
|
398 | 335 | def _function_signature(self): |
|
0 commit comments