def get_seq_file_data(): if 'file' not in request.files: abort(Response('No file part', 400)) file = request.files['file'] if file.filename == '': abort(Response('No selected file', 400)) if file and allowed_file(file.filename): secure_filename(file.filename) # TODO: secure_filename return correct filename, we should do sth with this data = dict() data['sequences'] = file.read().decode() data['threshold'] = request.form['threshold'] consensus_seq = ConsensusSequence(data) result = consensus_seq.file_seq() add_calculation( module_name=ModuleName.CONSENSUS_SEQUENCE_FILE_SEQ, user_data=data, result=result, ip_address=request.remote_addr, ) slack_notification.consensus_sequence_file_seq_calculation(data, result, request.remote_addr) response = make_response(base64.b64encode(result.encode())) response.headers['Content-Type'] = 'text/plain' response.mimetype = 'text/plain' return response, 200 else: abort(Response('Illegal file extension', 400))
def get_sequences_data(): try: data = request.get_json() seq_tools = SequencesTools(data) result = seq_tools.calculate() add_calculation( module_name=ModuleName.SEQUENCES_TOOLS, user_data=data, result=result, ip_address=request.remote_addr ) slack_notification.sequences_tool_calculation(data, result, request.remote_addr) return jsonify({'data': result}) except Exception as e: abort(Response(str(e), 400))
def dot_plot_genebank_ids(): try: data = request.get_json() dot_plot = DotPlot(data) result = dot_plot.genebank_seq() add_calculation( module_name=ModuleName.DOT_PLOT_GENEBANK_IDS, user_data=data, result=result, ip_address=request.remote_addr ) slack_notification.dot_plot_genebank_calculation(data, result, request.remote_addr) return jsonify( {'data': result, 'dotplot_base64': dot_plot.get_dot_plot_image(), 'alignment': dot_plot.get_alignments()} ) except Exception as e: abort(Response(str(e), 400))
def get_goodness_data(): try: data = request.get_json() chi_goodness = ChiSquareGoodness(data["observed"], data["expected"]) result = chi_goodness.calculate() add_calculation( module_name=ModuleName.CHI_SQUARE_GOODNESS, user_data=data, result=result, ip_address=request.remote_addr ) slack_notification.chi_square_goodness_calculation(data, result, request.remote_addr) return jsonify({'data': result}) except TypeError as e: abort(Response(f'Please check type of input data, {str(e)}', 422)) except Exception as e: abort(Response(str(e), 400))
def get_data(): try: data = request.get_json() chi = ChiSquareCalculation(data) result = chi.calculate() add_calculation( module_name=ModuleName.CHI_SQUARE, user_data=data, result=result, ip_address=request.remote_addr ) slack_notification.chi_square_calculation(data, result, request.remote_addr) return jsonify({'data': result}) except TypeError as e: abort(Response(f'Please check type of input data, {str(e)}', 422)) except Exception as e: abort(Response(str(e), 400))
def get_raw_seq_data(): try: data = request.get_json() consensus_seq = ConsensusSequence(data) result = consensus_seq.raw_sequence() add_calculation( module_name=ModuleName.CONSENSUS_SEQUENCE_RAW_SEQ, user_data=data, result=result, ip_address=request.remote_addr, ) slack_notification.consensus_sequence_raw_seq_calculation(data, result, request.remote_addr) return jsonify({'data': result}) except Exception as e: abort(Response(str(e), 400))
def pic_dominant(): try: data = request.get_json() do = Dominant(data) result = do.calculate() add_calculation(module_name=ModuleName.PIC_DOMINANT, user_data=data, result=result, ip_address=request.remote_addr) slack_notification.pic_dominant_calculation(data, result, request.remote_addr) return jsonify({'data': result}) except TypeError as e: abort(Response(f'Please check type of input data. {e}', 422)) except Exception as e: abort(Response(str(e), 400))
def get_data(): try: data = request.get_json() hw = HardyWeinbergCalculation(data) result = hw.calculate() add_calculation(module_name=ModuleName.HARDY_WEINBERG, user_data=data, result=result, ip_address=request.remote_addr) slack_notification.hardy_weinberg_calculation(data, result, request.remote_addr) return jsonify({'data': result}) except TypeError: abort(Response("Please check type of input data", 409)) except Exception as e: abort(Response(str(e), 400))
def get_seq_genebank(): try: data = request.get_json() consensus_seq = ConsensusSequence(data) result = consensus_seq.genebank_seq() add_calculation( module_name=ModuleName.CONSENSUS_SEQUENCE_GENE_BANK, user_data=data, result=result, ip_address=request.remote_addr, ) slack_notification.consensus_sequence_genebank_calculation(data, result, request.remote_addr) response = make_response(base64.b64encode(result.encode())) response.headers['Content-Type'] = 'text/plain' response.mimetype = 'text/plain' return response, 200 except Exception as e: abort(Response(str(e), 400))
def get_data(): try: data = request.get_json() distance_choice = data.get("type_of_distance") distance_type = { 'standard': StandardDistance(data), 'geometric': GeometricDistance(data), 'takezaki-nei': TakezakiNeiDistance(data), } gen_distance = distance_type[distance_choice] gen_distance.calculate_distances() gen_distance.build_matrix() add_calculation( module_name=f'{ModuleName.GENETIC_DISTANCE}_{distance_choice}', user_data=data, result=gen_distance.get_matrix().tolist(), ip_address=request.remote_addr, ) slack_notification.genetic_distance_calculation( data, gen_distance.get_matrix(), request.remote_addr) return jsonify({ 'data': { 'dendro_base64': gen_distance.render_dendrogram(), 'matrix': gen_distance.render_matrix() } }) except TypeError as e: abort(Response(f'Please check type of input data. {str(e)}', 422)) except ValueError as e: abort( Response( f'The quantity or quality of the data is inappropriate! {str(e)}', 422)) except Exception as e: abort(Response(str(e), 400))