def boolean_gating(gate_params): points = gate_params['points'] points2 = gate_params['1'] boolean_op = gate_params['0'] reverse_gate = '0' if 'reverse' in gate_params: if (gate_params['reverse']): reverse_gate = '1' ## Generate unique datastore path, ensuring uniqueness. while True: new_name = str(uuid1()) new_path = ds.generate_path(DATA_BUCKET, None, new_name) if not ds.check_exists(new_path, None): break if (gate_params['tool'] == "boolean_gating"): if (len(points)%2 == 0) and (len(points2)%2 == 0): if (reverse_gate == '1'): if (boolean_op == 'or'): boolean_op = 'and' elif (boolean_op == 'and'): boolean_op = 'or' else: return generate_gating_feedback("fail", "The boolean operator must be either 'and' or 'or'") gate1_points = " ".join(str(p) for p in points) gate2_points = " ".join(str(p) for p in points2) queue.gate_boolean(gate_params['filename'], new_name, boolean_op, 'poly', gate1_points, reverse_gate, 'poly', gate2_points, reverse_gate, gate_params['axes']['x'], gate_params['axes']['y'], gate_params['axes']['x'], gate_params['axes']['y']); return generate_gating_feedback("success", "the boolean gating was performed correctly", new_name, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect, wrong number of arguments")
def file_complete(self, file_size): self.file_handle.close() self.upload.size = file_size ## Start analysis. queue.visualise(self.name) ## Load balance instances in the background. background.run(instances.balance, 0) return self.upload
def balance(): ## Calculate ratio of tasks to instances and acceptable limits. (ratio, instance_count, task_count) = stats() lower_ratio_limit = CE_SCALING * (1 - CE_SLACK) upper_ratio_limit = CE_SCALING * (1 + CE_SLACK) ## If ratio is outside acceptable limits, kill or start instances. if (ratio < lower_ratio_limit and instance_count > MIN_INSTANCES) or (instance_count > MAX_INSTANCES): queue.kill() elif (ratio > upper_ratio_limit and instance_count < MAX_INSTANCES) or (instance_count < MIN_INSTANCES): start()
def change_axes(tool_params): ## Generate unique datastore path, ensuring uniqueness. while True: new_name = str(uuid1()) new_path = ds.generate_path(DATA_BUCKET, None, new_name) if not ds.check_exists(new_path, None): break if tool_params['newAxes']['x'] == tool_params['newAxes']['y']: return generate_gating_feedback("fail", "Please choose two different axes") # todo: check if the axes exist. queue.change_axis(tool_params['filename'], tool_params['newAxes']['x'], tool_params['newAxes']['y'], new_name) return generate_gating_feedback("success","the axis change was performed", new_name, tool_params['filename'], tool_params['newAxes']['x'], tool_params['newAxes']['y'])
def multiple_gating(gate_params): points = gate_params['points'] while True: new_name = str(uuid1()) new_path = ds.generate_path(DATA_BUCKET, None, new_name) if not ds.check_exists(new_path, None): break if (gate_params['tool'] == 'kmeans_gating') : if len(points) == 1 : clusters = new_name number_gates = points[0] new_names = [new_name] for i in range(0, number_gates-1): while True: next_new_name = str(uuid1()) path = ds.generate_path(DATA_BUCKET, None, next_new_name) if not ds.check_exists(path, None): new_names.append(next_new_name) clusters = next_new_name + " " + clusters break queue.gate_kmeans(gate_params['filename'], clusters, str(number_gates), gate_params['axes']['x'], gate_params['axes']['y']); return generate_gating_feedback("success", "the kmeans gate was performed correctly", new_names, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect, wrong number of arguments") elif (gate_params['tool'] == 'quadrant_gating') : if len(points) == 2 : other_new_names = [] for i in range(0, 3): while True: next_new_name = str(uuid1()) path = ds.generate_path(DATA_BUCKET, None, next_new_name) if not ds.check_exists(path, None): other_new_names.append(next_new_name) break x_coord = str(points[0]) y_coord = str(points[1]) queue.gate_quadrant(gate_params['filename'], x_coord, y_coord, new_name, other_new_names[0], other_new_names[1], other_new_names[2], gate_params['axes']['x'], gate_params['axes']['y']); new_paths = [new_name] + other_new_names new_paths.reverse() #Make sure the user polls for the last graph to be created return generate_gating_feedback("success", "the quadrant gate was performed correctly", new_paths, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect, wrong number of arguments")
def stats(): instance_count = count() task_count = queue.task_count() if instance_count == 0: if task_count == 0: ratio = 1 else: ratio = float('inf') else: ratio = task_count / instance_count return (ratio, instance_count, task_count)
'gate_cir' : shape_gating, 'gate_poly' : shape_gating, 'gate_bool' : shape_gating, 'change_axis' : axis_change, 'dot_plot' : change_plot, 'contour_plot' : change_plot, 'gate_quad' : quadrant_gate, 'gate_norm' : data_gate, 'gate_kmeans' : data_gate } # Check task queue until 'kill' command is received. alive = True while alive: # Lease a command. try: task = Queue.lease('jobs', 30) except Exception, e: print e # If there are tasks in queue extract id and commands, else restart loop and check queue again. if task is not None: task_id = task[0] commands = task[1] else: time.sleep(0.9) continue functionToCall = AVAILABLE_TASKS[commands[0]] alive = functionToCall(commands) # Delete any processed tasks from queue. if task_id is not None: Queue.delete('jobs', task_id)
def simple_gating(gate_params): points = gate_params['points'] reverse_gate = '0' if 'reverse' in gate_params: if (gate_params['reverse']): reverse_gate = '1' ## Generate unique datastore path, ensuring uniqueness. while True: new_name = str(uuid1()) new_path = ds.generate_path(DATA_BUCKET, None, new_name) if not ds.check_exists(new_path, None): break if (gate_params['tool'] == "rectangular_gating") : if len(points) == 4 : #Reoder the point to take the topLeft and bottomRight points of the square if points[0] > points[2]: tempcoor = points[0] points[0] = points[2] points[2] = tempcoor if points[1] > points[3]: tempcoor = points[1] points[1] = points[3] points[3] = tempcoor gating_request = " ".join(str(p) for p in points) queue.gate_rectangle(gate_params['filename'], gating_request, new_name, reverse_gate, gate_params['axes']['x'], gate_params['axes']['y']); return generate_gating_feedback("success", "the rectangular gating was performed correctly", new_name, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect " + params + " length:" + str(len(points)) + " is not equal to 4") elif (gate_params['tool'] == "polygon_gating") : if len(points)%2 == 0 : gating_request = " ".join(str(p) for p in points) queue.gate_polygon(gate_params['filename'], gating_request, new_name, reverse_gate, gate_params['axes']['x'], gate_params['axes']['y']); return generate_gating_feedback("success", "the polygonal gating was performed correctly", new_name, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect " + params + " #pointCoordinates:" + str(len(points))-1 + " is not pair") elif (gate_params['tool'] == "oval_gating") : if len(points) == 6 : gating_request = " ".join(str(p) for p in points) queue.gate_circle(gate_params['filename'], gating_request, new_name, reverse_gate, gate_params['axes']['x'], gate_params['axes']['y']); return generate_gating_feedback("success", "the oval gating was performed correctly", new_name, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect " + params + " #pointCoordinates:" + str(len(points)) + " is not even") elif (gate_params['tool'] == 'normal_gating') : if len(points) == 1 : gating_request = str(points[0]) queue.gate_normal(gate_params['filename'], new_name, reverse_gate, gate_params['axes']['x'], gate_params['axes']['y'], gating_request); return generate_gating_feedback("success", "the normal gating was performed correctly", new_name, gate_params['filename'], gate_params['axes']['x'], gate_params['axes']['y']) else: return generate_gating_feedback("fail", "notcorrect, wrong number of arguments") else : return generate_gating_feedback("fail", "The gate " + gate_params['tool'] + " is not known")