import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('TEMPLATE/RESOURCE', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<term>') class Foo(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, term): """ Returns list of matches """ args = parser.parse_args() return []
import logging from flask import request from flask_restplus import Resource from ontobio.golr.golr_sim import subject_pair_simj from biolink.api.restplus import api from biolink import USER_AGENT log = logging.getLogger(__name__) ns = api.namespace('pair/sim', description='pairwise similarity between two entities') parser = api.parser() parser.add_argument( 'object_category', help= 'e.g. disease, phenotype, gene. Two subjects will be compared based on overlap between associations to objects in this category' ) @ns.route('/jaccard/<id1>/<id2>/') @api.doc(params={ 'id1': 'id, e.g. NCBIGene:10891; ZFIN:ZDB-GENE-980526-166; UniProtKB:Q15465' }) @api.doc(params={ 'id2': 'id, e.g. NCBIGene:1200; ZFIN:ZDB-GENE-980528-2059; UniProtKB:P12644' }) class PairSimJaccardResource(Resource):
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('owl/ontology', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/dlquery/<query>') class DLQuery(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, query): """ Returns list of matches """ args = parser.parse_args() return []
import logging from flask import request from flask_restplus import Resource from biolink.api.restplus import api from biogolr.golr_associations import calculate_information_content import pysolr log = logging.getLogger(__name__) ns = api.namespace('ontol', description='foo bar') parser = api.parser() parser.add_argument( 'evidence', help="""Object id, e.g. ECO:0000501 (for IEA; Includes inferred by default) or a specific publication or other supporting ibject, e.g. ZFIN:ZDB-PUB-060503-2. """) @ns.route( '/information_content/<subject_category>/<object_category>/<subject_taxon>' ) class InformationContentResource(Resource): @api.expect(parser) def get(self, subject_category, object_category, subject_taxon): """ Calculates information content """ args = parser.parse_args() return calculate_information_content(subject_category=subject_category,
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('nlp/annotate', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<text>') class Annotate(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, text): """ Returns list of matches """ args = parser.parse_args() return []
from ontobio.golr.golr_associations import MAX_ROWS from biolink.datamodel.serializers import compact_association_set # https://flask-limiter.readthedocs.io/en/stable/ from flask import Flask from flask_limiter import Limiter from flask_limiter.util import get_remote_address app = Flask(__name__) limiter = Limiter(app, key_func=get_remote_address, global_limits=["200 per day", "50 per hour"]) log = logging.getLogger(__name__) ns = api.namespace('mart', description='Bulk operations') parser = api.parser() parser.add_argument( 'slim', action='append', help= 'Map objects up (slim) to a higher level category. Value can be ontology class ID or subset ID' ) @ns.route('/gene/<object_category>/<taxon>') #@limiter.limit("1 per minute") @api.doc( params={ 'object_category':
import logging from flask import request from flask_restplus import Resource, inputs from biolink.api.restplus import api from biolink.ontology.ontology_manager import get_ontology from ontobio.ontol_factory import OntologyFactory from ontobio.io.ontol_renderers import OboJsonGraphRenderer from ontobio.config import get_config import networkx as nx import pysolr log = logging.getLogger(__name__) ns = api.namespace('ontol', description='extract a subgraph from an ontology') parser = api.parser() parser.add_argument('cnode', action='append', help='Additional classes') parser.add_argument('include_ancestors', type=inputs.boolean, help='Include Ancestors') parser.add_argument('include_descendants', type=inputs.boolean, help='Include Descendants') parser.add_argument('relation', action='append', default=['subClassOf', 'BFO:0000050'], help='Additional classes') parser.add_argument('include_meta', type=inputs.boolean, help='Include metadata in response') @ns.route('/subgraph/<ontology>/<node>') @api.doc(params={'ontology': 'ontology ID, e.g. go, uberon, mp, hp'}) @api.doc(params={'node': 'class ID, e.g. HP:0001288'}) class ExtractOntologySubgraphResource(Resource): @api.expect(parser) def get(self, ontology, node):
from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import node, named_object, bio_object, association_results, association, publication, gene, substance, genotype, allele, search_result #import biolink.datamodel.serializers from biolink.api.restplus import api from ontobio.golr.golr_associations import search_associations, search_associations_go, select_distinct_subjects from scigraph.scigraph_util import SciGraph from biowikidata.wd_sparql import doid_to_wikidata, resolve_to_wikidata, condition_to_drug from ontobio.vocabulary.relations import HomologyTypes from ..closure_bins import create_closure_bin import pysolr log = logging.getLogger(__name__) ns = api.namespace('bioentity', description='Retrieval of domain entities plus associations') core_parser = api.parser() core_parser.add_argument('rows', type=int, required=False, default=100, help='number of rows') core_parser.add_argument('start', type=int, required=False, default=1, help='row to start at') core_parser.add_argument('unselect_evidence', type=bool, help='If set, excludes evidence objects in response') core_parser.add_argument('exclude_automatic_assertions', default=False, type=bool, help='If set, excludes associations that involve IEAs (ECO:0000501)') core_parser.add_argument('fetch_objects', type=bool, default=True, help='If true, returns a distinct set of association.objects (typically ontology terms). This appears at the top level of the results payload') core_parser.add_argument('use_compact_associations', type=bool, default=False, help='If true, returns results in compact associations format') core_parser.add_argument('slim', action='append', help='Map objects up (slim) to a higher level category. Value can be ontology class ID or subset ID') core_parser.add_argument('evidence', help="""Object id, e.g. ECO:0000501 (for IEA; Includes inferred by default) or a specific publication or other supporting ibject, e.g. ZFIN:ZDB-PUB-060503-2. """) scigraph = SciGraph('https://scigraph-data.monarchinitiative.org/scigraph/')
'SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER app.config['ERROR_404_HELP'] = settings.RESTPLUS_ERROR_404_HELP app.config['ERROR_INCLUDE_MESSAGE'] = settings.ERROR_INCLUDE_MESSAGE #def initialize_app(flask_app): # configure_app(flask_app) blueprint = Blueprint('api', __name__, url_prefix='/api') api.init_app(blueprint) mapping = settings.get_route_mapping().get('route_mapping') for ns in mapping['namespace']: namespace = api.namespace(ns['name'], description=ns['description']) routes = ns['routes'] for r in routes: route = r['route'] resource = r['resource'] log.debug("Registering Resource: {} to route: {}".format( resource, route)) module_name = '.'.join(resource.split('.')[0:-1]) resource_class_name = resource.split('.')[-1] module = __import__(module_name, fromlist=[resource_class_name]) resource_class = getattr(module, resource_class_name) namespace.add_resource(resource_class, route) app.register_blueprint(blueprint) db.init_app(app)
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('owl/ontology', description='OWL-level operations on an ontology') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/dlquery/<query>') class DLQuery(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, query): """ Placeholder - use OWLery for now """ args = parser.parse_args() return []
import logging from flask_restplus import reqparse from flask import request from flask_restplus import Resource from biolink.api.variation.business import create_variantset, update_variantset, delete_variantset from biolink.datamodel.serializers import association from biolink.api.restplus import api from biolink.database.models import VariantSet import pysolr log = logging.getLogger(__name__) ns = api.namespace('variation/set', description='Operations related to sets of variants') pagination_arguments = reqparse.RequestParser() pagination_arguments.add_argument('page', type=int, required=False, default=1, help='Page number') pagination_arguments.add_argument('bool', type=bool, required=False, default=1, help='Page number') pagination_arguments.add_argument('per_page', type=int, required=False, choices=[2, 10, 20, 30, 40, 50],
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association, bbop_graph from scigraph.scigraph_util import SciGraph from biolink.api.restplus import api log = logging.getLogger(__name__) ns = api.namespace('graph', description='Operations over data graphs') parser = api.parser() sg = SciGraph() @ns.route('/node/<id>') @api.doc(params={'id': 'CURIE e.g. HP:0000465'}) class NodeResource(Resource): @api.expect(parser) @api.marshal_list_with(bbop_graph) def get(self, id): """ Returns a graph node. A node is an abstract representation of some kind of entity. The entity may be a physical thing such as a patient, a molecular entity such as a gene or protein, or a conceptual entity such as a class from an ontology. """ args = parser.parse_args() return sg.graph(id)
import logging from flask import request from flask_restplus import Resource from biolink.api.restplus import api from ontobio.golr.golr_associations import calculate_information_content from biolink import USER_AGENT log = logging.getLogger(__name__) ns = api.namespace('ontol', description='ontology operations') parser = api.parser() parser.add_argument( 'evidence', help="""Object id, e.g. ECO:0000501 (for IEA; Includes inferred by default) or a specific publication or other supporting ibject, e.g. ZFIN:ZDB-PUB-060503-2. """) @ns.route( '/information_content/<subject_category>/<object_category>/<subject_taxon>' ) class InformationContentResource(Resource): @api.expect(parser) def get(self, subject_category, object_category, subject_taxon): """ Returns information content (IC) for a set of relevant ontology classes. ```
import logging from flask import request from flask_restplus import Resource from prefixcommons.curie_util import get_prefixes, expand_uri, contract_uri from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('identifier/prefixes', description='identifier prefixes') parser = api.parser() @ns.route('/') class PrefixCollection(Resource): @api.expect(parser) def get(self): """ Returns list of prefixes """ return get_prefixes() @ns.route('/expand/<id>') @api.doc(params={'id': 'ID of entity to be contracted to URI, e.g "MGI:1"'}) class PrefixExpand(Resource): @api.expect(parser) def get(self, id): """
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('nlp/annotate', description='annotate text using named entities') parser = api.parser() parser.add_argument('category', action='append', help='E.g. phenotype') @ns.route('/<text>') class Annotate(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, text): """ Not yet implemented. For now using scigraph annotator directly """ args = parser.parse_args() return []
import logging from flask import request, send_file from flask_restplus import Resource from biolink.datamodel.serializers import association, bbop_graph from biolink.util.golr_associations import get_association from biolink.api.restplus import api from biolink.core.ontology.obograph_util import convert_json_object import tempfile import pysolr import matplotlib.pyplot as plt import networkx as nx log = logging.getLogger(__name__) ns = api.namespace('evidence/graph', description='Operations on evidence graphs') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<id>') @api.doc( params={'id': 'association id, e.g. cfef92b7-bfa3-44c2-a537-579078d2de37'}) class AssociationObject(Resource): @api.expect(parser) @api.marshal_list_with(bbop_graph) def get(self, id): """ Returns evidence graph object for a given association.
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import compact_association_set, association_results from ontobio.golr.golr_associations import search_associations, GolrFields from biolink.api.restplus import api import pysolr MAX_ROWS = 10000 log = logging.getLogger(__name__) ns = api.namespace('bioentityset/homologs', description='Map gene IDs to their homologs') parser = api.parser() parser.add_argument( 'subject', action='append', help= 'Entity ids to be examined, e.g. NCBIGene:9342, NCBIGene:7227, NCBIGene:8131, NCBIGene:157570, NCBIGene:51164, NCBIGene:6689, NCBIGene:6387' ) @ns.route('/') class EntitySetHomologs(Resource): @api.expect(parser) @api.marshal_list_with(compact_association_set) def get(self):
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api from ontobio.sparql.sparql_ontol_utils import batch_fetch_labels import pysolr log = logging.getLogger(__name__) ns = api.namespace('ontol/labeler', description='Assigns labels to ids') parser = api.parser() parser.add_argument('id', action='append', help='List of ids') @ns.route('/') class OntolLabelerResource(Resource): @api.expect(parser) def get(self): """ Fetches a map from CURIEs/IDs to labels """ args = parser.parse_args() return batch_fetch_labels(args.id)
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('patient', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/individual/<id>') class Individual(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, id): """ Returns list of matches """ args = parser.parse_args() return []
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('search/entity', description='Search for entities') parser = api.parser() parser.add_argument( 'subject_taxon', type=str, help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') parser.add_argument( 'attribute', action='append', help='positive attributes, e.g. ontology terms, to include in query') parser.add_argument( 'negative_attribute', action='append', help='negative attributes, e.g. ontology terms, to exclude in query') parser.add_argument( 'weighted_attribute', action='append', help= 'weighted attributes, specified as a range from 0 to 1 plus an ontology term, e.g. 0.3*HP:0000001' )
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association, association_results from biolink.api.restplus import api from ontobio.golr.golr_associations import get_association, search_associations import pysolr log = logging.getLogger(__name__) ns = api.namespace('association', description='Retrieve associations between entities') parser = api.parser() parser.add_argument( 'subject_taxon', help= 'SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferences by default (higher level taxa can be used)' ) parser.add_argument( 'evidence', help="""Object id, e.g. ECO:0000501 (for IEA; Includes inferred by default) or a specific publication or other supporting ibject, e.g. ZFIN:ZDB-PUB-060503-2. """) parser.add_argument('graphize', type=bool, help='If set, includes graph object in response') parser.add_argument('fl_excludes_evidence', type=bool, help='If set, excludes evidence objects in response')
""" @Deprecated """ import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('ontol/slimmer', description='Mapping to an ontology subset') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<subset>') class MapToSlimResource(Resource): @api.expect(parser) def get(self, subset): """ TODO Maps to slim """ args = parser.parse_args() return []
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association, association_results from biolink.api.restplus import api from biolink.util.golr_associations import get_association, search_associations import pysolr log = logging.getLogger(__name__) ns = api.namespace( 'link', description='Associations between entities or entity and descriptors') parser = api.parser() parser.add_argument( 'subject', help='SUBJECT id, e.g. NCBIGene:84570. Includes inferred by default') parser.add_argument( 'subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') parser.add_argument( 'object', help='OBJECT id, e.g. HP:0011927. Includes inferred by default') parser.add_argument( 'evidence_class', help='CLASS id, e.g. ECO:0000501 (for IEA). Includes inferred by default') parser.add_argument('graphize', type=bool, help='If set, includes graph object in response') parser.add_argument('exclude_evidence',
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('entity/search', description='Search for entities') parser = api.parser() parser.add_argument( 'subject_taxon', type=str, help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') parser.add_argument( 'attribute', action='append', help='positive attributes, e.g. ontology terms, to include in query') parser.add_argument( 'negative_attribute', action='append', help='negative attributes, e.g. ontology terms, to exclude in query') parser.add_argument( 'weighted_attribute', action='append', help= 'weighted attributes, specified as a range from 0 to 1 plus an ontology term, e.g. 0.3*HP:0000001' )
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('image/images', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<term>') class Foo(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, term): """ Returns list of matches """ args = parser.parse_args() return []
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('genome/region', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<term>') class Foo(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, term) """ Returns list of matches """ args = parser.parse_args() return []
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import compact_association_set, association_results from ontobio.golr.golr_associations import search_associations, GolrFields from biolink.api.restplus import api from biolink import USER_AGENT MAX_ROWS = 10000 log = logging.getLogger(__name__) ns = api.namespace('bioentityset', description='operations over sets of entities') parser = api.parser() parser.add_argument( 'subject', action='append', help= 'Entity ids to be examined, e.g. NCBIGene:9342, NCBIGene:7227, NCBIGene:8131, NCBIGene:157570, NCBIGene:51164, NCBIGene:6689, NCBIGene:6387' ) parser.add_argument( 'background', action='append', help= 'Entity ids in background set, e.g. NCBIGene:84570, NCBIGene:3630; used in over-representation tests' )
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api from causalmodels.lego_sparql_util import lego_query, ModelQuery log = logging.getLogger(__name__) ns = api.namespace('cam', description='Operations on causal activity models (LEGO)') parser = api.parser() parser.add_argument('title', help='string to search for in title of model') parser.add_argument('contributor', help='string to search for in contributor of model') @ns.route('/model/') class ModelCollection(Resource): #@api.expect(parser) def get(self): """ Returns list of ALL models """ args = parser.parse_args() return lego_query(""" SELECT ?x ?title ?p ?v WHERE {?x a owl:Ontology ;
import logging from flask import request from flask_restplus import Resource, inputs from biolink.datamodel.serializers import association from ontobio.golr.golr_associations import map2slim from biolink.api.restplus import api from scigraph.scigraph_util import SciGraph from biolink import USER_AGENT log = logging.getLogger(__name__) ns = api.namespace('bioentityset/slimmer', description='maps a set of entities to a slim') INVOLVED_IN = 'involved_in' ACTS_UPSTREAM_OF_OR_WITHIN = 'acts_upstream_of_or_within' FUNCTION_CATEGORY = 'function' PHENOTYPE_CATEGORY = 'phenotype' ANATOMY_CATEGORY = 'anatomy' parser = api.parser() parser.add_argument( 'subject', action='append', help= 'Entity ids to be examined, e.g. NCBIGene:9342, NCBIGene:7227, NCBIGene:8131, NCBIGene:157570, NCBIGene:51164, NCBIGene:6689, NCBIGene:6387', required=True) parser.add_argument( 'slim',
import logging from flask import request from flask_restplus import Resource from biolink.datamodel.serializers import association from biolink.api.restplus import api import pysolr log = logging.getLogger(__name__) ns = api.namespace('ontol/slimmer', description='foo bar') parser = api.parser() #parser.add_argument('subject_taxon', help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default') @ns.route('/<subset>') class Foo(Resource): @api.expect(parser) @api.marshal_list_with(association) @api.expect(parser) @api.marshal_list_with(association) def get(self, subset): """ Maps to slim """ args = parser.parse_args() return []