from itertools import groupby from flask import request, abort from flask_restx import Resource from webserver.endpoints import api from webserver.endpoints.request_models import sequence_post_parameters_annotations, sequence_get_parameters_annotations from webserver.endpoints.task_interface import get_features from webserver.endpoints.utils import check_valid_sequence from webserver.utilities.parsers import (Source, Evidence, annotations_to_protvista_converter, SecondaryStructure, Disorder) ns = api.namespace("annotations", description="Get annotations on the fly.") def _filter_ontology(annotations, ontology): if annotations.get(ontology): first_k = next(goannotations for identifier, goannotations in groupby( annotations[ontology], lambda x: x["identifier"])) annotations[ontology] = list(first_k) def _get_annotations_from_params(params): sequence = params.get('sequence') if not sequence or len(sequence) > 2000 or not check_valid_sequence( sequence): return abort(400, "Sequence is too long or contains invalid characters.") model_name = params.get('model', 'seqvec')
import io import h5py from flask import request, send_file, abort from flask_restx import Resource from webserver.endpoints import api from webserver.endpoints.request_models import sequence_post_parameters from webserver.endpoints.task_interface import get_embedding from webserver.endpoints.utils import check_valid_sequence ns = api.namespace("embeddings", description="Calculate embeddings on the fly.") @ns.route('') class Embeddings(Resource): @api.expect(sequence_post_parameters, validate=True) @api.response(200, "Returns an hdf5 file with one dataset called `sequence` " "containing the embedding of the supplied sequence.") @api.response(400, "Invalid input. See return message for details.") @api.response(505, "Server error") def post(self): params = request.json sequence = params.get('sequence') if not sequence or len(sequence) > 2000 or not check_valid_sequence(sequence): return abort(400, "Sequence is too long or contains invalid characters.") model_name = params.get('model', 'seqvec')
import uuid from flask import request, send_file, abort from flask_restx import Resource from webserver.database import get_file, get_list_of_files from webserver.endpoints import api from webserver.endpoints.request_models import ( file_post_parser, request_status_parser, request_results_parser, ) from webserver.endpoints.utils import validate_FASTA_submission from webserver.tasks.pipeline import run_pipeline ns = api.namespace("pipeline", description="Run pipeline jobs") @ns.route('') class Pipeline(Resource): @api.expect(file_post_parser, validate=True) @api.response(200, "Calculated embeddings") @api.response(400, "Invalid input. See message for details") @api.response(505, "Server error") def post(self): validated_request = validate_FASTA_submission(request) job_id = uuid.uuid4().hex pipeline_type = request.form.get('pipeline_type', 'annotations_from_bert') async_call = run_pipeline.apply_async(args=(job_id, validated_request.sequences, pipeline_type), task_id=job_id)
from flask import abort from flask_restx import Resource from webserver.endpoints import api from webserver.endpoints.utils import get_queues ns = api.namespace("status", description="Get the status of the workers.") _workers = [ 'prott5', 'prott5_annotations', 'pipeline', 'colabfold', 'prott5_residue_landscape_annotations' ] @ns.route('') class Status(Resource): @api.response(200, "Returns an object with active workers.") @api.response(505, "Server error") def get(self): queues = get_queues() active_workers = dict() for worker in _workers: active_workers[worker] = worker in queues return active_workers @ns.route('/<worker>') class Status(Resource): @api.response(
from flask import request from flask_restx import Resource from webserver.endpoints import api from webserver.endpoints.request_models import sequence_get_parameters_structure, sequence_post_parameters_structure from webserver.endpoints.task_interface import get_structure from webserver.endpoints.utils import abort, check_valid_sequence ns = api.namespace("structure", description="Get structure predictions on the fly.") def _get_structure_from_params(params): predictor = params.get('predictor', "colabfold") sequence = params.get('sequence') if not sequence or len(sequence) > 500 or not check_valid_sequence(sequence): return abort(400, "Sequence is too long or contains invalid characters.") if predictor not in {"colabfold"}: return abort(400, "Invalid predictor specified") ret = get_structure(predictor, sequence) return ret @ns.route('') class Annotations(Resource): @api.expect(sequence_get_parameters_structure, validate=True) @api.response(200, "Annotations in specified format") @api.response(201, "Created job for structure prediction") @api.response(202, "Structure prediction request accepted") @api.response(400, "Invalid input. See return message for details.") @api.response(505, "Server error")