示例#1
0
def get_simple_parser():
    """
        A simple flaskrest parser object that includes basic http params
        """
    p = api.parser()
    p.add_argument('category', action='append', help='e.g. gene, disease')
    p.add_argument('prefix',
                   action='append',
                   help='ontology prefix: HP, -MONDO')
    p.add_argument('boost_fx',
                   action='append',
                   help='boost function e.g. pow(edges,0.334)')
    p.add_argument('boost_q',
                   action='append',
                   help='boost query e.g. category:genotype^-10')
    p.add_argument(
        'taxon',
        action='append',
        help='taxon filter, eg NCBITaxon:9606, includes inferred taxa')
    #p.add_argument('engine', help='Name of engine to perform search')
    p.add_argument('rows',
                   type=int,
                   required=False,
                   default=20,
                   help='number of rows')
    p.add_argument('start',
                   type=str,
                   required=False,
                   default='0',
                   help='row number to start from')
    p.add_argument('highlight_class',
                   type=str,
                   required=False,
                   help='highlight class')
    return p
示例#2
0
class EdgeResource(Resource):

    parser = api.parser()
    parser.add_argument('depth',
                        type=int,
                        help='How far to traverse for neighbors',
                        default=1)
    parser.add_argument(
        'direction',
        choices=['INCOMING', 'OUTGOING', 'BOTH'],
        help=
        'Which direction to traverse (used only if relationship_type is defined)',
        default='BOTH')
    parser.add_argument('relationship_type',
                        action='append',
                        help='Relationship type to traverse')
    parser.add_argument(
        'entail',
        type=inputs.boolean,
        help='Include sub-properties and equivalent properties',
        default=False)

    @api.expect(parser)
    @api.marshal_list_with(bbop_graph)
    def get(self, id):
        """
        Returns edges emanating from a given node.

        """
        args = self.parser.parse_args()
        response = sg.get_response("dynamic/cliqueLeader",
                                   q=id,
                                   format="json",
                                   depth=1)
        nodes = response.json()['nodes']
        if not nodes:
            raise NoResultFoundException(
                'SciGraph dynamic/cliqueLeader yields no result for {}'.format(
                    id))

        clique_leader = nodes[0]['id']
        final_graph = BBOPGraph({'nodes': [], 'edges': []})
        if args.relationship_type:
            for relationship in args.relationship_type:
                graph = sg.neighbors(id=clique_leader,
                                     relationshipType=relationship,
                                     direction=args.direction,
                                     depth=args.depth,
                                     entail=args.entail)
                final_graph.merge(graph)

        else:
            graph = sg.neighbors(id=clique_leader,
                                 depth=args.depth,
                                 entail=args.entail)
            final_graph.merge(graph)

        return final_graph
示例#3
0
def get_simple_parser():
        """
        A simple flaskrest parser object that includes basic http params
        """
        p = api.parser()
        #p.add_argument('taxon', type=str, help='SUBJECT TAXON id, e.g. NCBITaxon:9606. Includes inferred by default')
        p.add_argument('category', action='append', help='e.g. gene, disease')
        #p.add_argument('subclass_of', action='append', help='restrict search to entities that are subclasses of the specified class')
        #p.add_argument('engine', help='Name of engine to perform search')
        p.add_argument('rows', type=int, required=False, default=20, help='number of rows')
        p.add_argument('start', type=int, required=False, default=1, help='row number to start from')
        return p
示例#4
0
def get_compare_parser():

    help_msg = 'A phenotype or identifier that is composed of phenotypes (eg disease, gene)'

    sim_get_parser = api.parser()
    sim_get_parser.add_argument('ref_id',
                                action='append',
                                help=help_msg,
                                default=[])
    sim_get_parser.add_argument('query_id',
                                action='append',
                                help=help_msg,
                                default=[])
    return sim_get_parser
示例#5
0
def get_simple_parser():
    """
        A simple flaskrest parser object that includes basic http params
        """
    p = api.parser()
    p.add_argument(
        'fq',
        action='append',
        required=False,
        help='fq string passed directly to solr, note that multiple filters '
        'will be combined with an AND operator. Combining fq_string with '
        'other parameters may result in unexpected behavior.')
    p.add_argument('category', action='append', help='e.g. gene, disease')
    p.add_argument('prefix',
                   action='append',
                   help='ontology prefix: HP, -MONDO')
    p.add_argument('boost_fx',
                   action='append',
                   help='boost function e.g. pow(edges,0.334)')
    p.add_argument('boost_q',
                   action='append',
                   help='boost query e.g. category:genotype^-10')
    p.add_argument(
        'taxon',
        action='append',
        help='taxon filter, eg NCBITaxon:9606, includes inferred taxa')
    p.add_argument('rows',
                   type=int,
                   required=False,
                   default=20,
                   help='number of rows')
    p.add_argument('start',
                   type=str,
                   required=False,
                   default='0',
                   help='row number to start from')
    p.add_argument('highlight_class',
                   type=str,
                   required=False,
                   help='highlight class')
    p.add_argument(
        'min_match',
        type=str,
        help='minimum should match parameter, see solr docs for details')
    p.add_argument('minimal_tokenizer',
                   type=inputs.boolean,
                   default=False,
                   help='set to true to use the minimal tokenizer, '
                   'good for variants and genotypes')
    return p
示例#6
0
def get_layperson_parser():
    """
    A simple flaskrest parser object that includes basic http params
    """
    p = api.parser()
    p.add_argument('rows', type=int, required=False, default=10, help='number of rows')
    p.add_argument('start', type=str, required=False, default='0', help='row number to start from')
    p.add_argument('phenotype_group', type=str, required=False, help='phenotype group id')
    p.add_argument('phenotype_group_label', type=str, required=False, help='phenotype group label')
    p.add_argument('anatomical_system', type=str, required=False, help='anatomical system id')
    p.add_argument('anatomical_system_label', type=str, required=False, help='anatomical system label')
    p.add_argument('highlight_class', type=str, required=False, help='highlight class')

    return p
示例#7
0
def get_search_parser():
    sim_search_parser = api.parser()

    sim_search_parser.add_argument(
        'id',
        action='append',
        help=
        'A phenotype or identifier that is composed of phenotypes (eg disease, gene)',
        default=[])
    sim_search_parser.add_argument('limit',
                                   type=int,
                                   required=False,
                                   default=100,
                                   help='number of rows')
    sim_search_parser.add_argument('taxon',
                                   type=int,
                                   required=False,
                                   help='ncbi taxon id')
    return sim_search_parser
示例#8
0
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__)

parser = api.parser()
parser.add_argument('id', action='append', help='List of ids')


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)
示例#9
0
class EdgeResource(Resource):

    parser = api.parser()
    parser.add_argument('depth',
                        type=int,
                        help='How far to traverse for neighbors',
                        default=1)
    parser.add_argument(
        'direction',
        choices=['INCOMING', 'OUTGOING', 'BOTH'],
        help=
        'Which direction to traverse (used only if relationship_type is defined)',
        default='BOTH')
    parser.add_argument('relationship_type',
                        action='append',
                        help='Relationship type to traverse')
    parser.add_argument(
        'entail',
        type=inputs.boolean,
        help='Include sub-properties and equivalent properties',
        default=False)
    parser.add_argument('graph',
                        choices=['data', 'ontology'],
                        help='Which monarch graph to query',
                        default='data')

    @api.expect(parser)
    @api.marshal_list_with(bbop_graph)
    def get(self, id):
        """
        Returns edges emanating from a given node.

        """
        args = self.parser.parse_args()
        if args['graph'] == 'data':
            scigraph = sg_data
        elif args['graph'] == 'ontology':
            scigraph = sg_ont
        else:
            raise UnhandledException('{} not supported graph'.format(
                args['graph']))

        node = scigraph.get_clique_leader(id)
        if not node:
            raise NoResultFoundException(
                'SciGraph dynamic/cliqueLeader yields no result for {}'.format(
                    id))

        clique_leader = node.id
        final_graph = BBOPGraph({'nodes': [], 'edges': []})
        if args.relationship_type:
            for relationship in args.relationship_type:
                graph = scigraph.neighbors(id=clique_leader,
                                           relationshipType=relationship,
                                           direction=args.direction,
                                           depth=args.depth,
                                           entail=args.entail)
                final_graph.merge(graph)

        else:
            graph = scigraph.neighbors(id=clique_leader,
                                       depth=args.depth,
                                       entail=args.entail)
            final_graph.merge(graph)

        return final_graph.as_dict()
示例#10
0
from flask_restplus import Resource
from flask import request
from ontobio.sim.annotation_scorer import AnnotationScorer
from ontobio.sim.api.owlsim2 import OwlSim2Api
from biolink.api.restplus import api
from biolink.datamodel.sim_serializers import sufficiency_input, sufficiency_output

annotation_scorer = AnnotationScorer(OwlSim2Api())

score_get = api.parser()
score_get.add_argument('id',
                       action='append',
                       help='Phenotype identifier (eg HP:0004935)')
score_get.add_argument('absent_id',
                       default=[],
                       action='append',
                       help='absent phenotype (eg HP:0002828)')


class AnnotationScore(Resource):
    @api.expect(sufficiency_input)
    @api.marshal_with(sufficiency_output)
    def post(self):
        """
        Get annotation score
        """
        data = request.json
        phenotypes = [
            feature['id'] for feature in data['features']
            if feature['isPresent'] is True
        ]
示例#11
0
from flask_restplus import Resource, inputs
from flask import request
from ontobio.sim.api.owlsim2 import OwlSim2Api
from ontobio.sim.phenosim_engine import PhenoSimEngine
from ontobio.vocabulary.similarity import SimAlgorithm
from biolink.api.restplus import api
from biolink.api.sim.endpoints.owlsim import get_owlsim_api
from biolink.datamodel.sim_serializers import sim_result, compare_input

metrics = [matcher.value for matcher in OwlSim2Api.matchers()]

# Common args
sim_parser = api.parser()
sim_parser.add_argument(
        'is_feature_set',
        type=inputs.boolean,
        help='set to true if *all* input ids are phenotypic features, else set to false',
        default=True
    )

sim_parser.add_argument(
    'metric', type=str, choices=metrics,
    default='phenodigm', help='Metric for computing similarity')


def get_compare_parser():

    help_msg = 'A phenotype or identifier that is composed of phenotypes (eg disease, gene)'

    sim_get_parser = sim_parser.copy()
    sim_get_parser.add_argument(
示例#12
0
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/')

homol_rel = HomologyTypes.Homolog.value
from ontobio.sparql.sparql_ontol_utils import run_sparql_on, EOntology, transform, transformArray

from ontobio.golr.golr_query import GolrSearchQuery, run_solr_on, ESOLR, ESOLRDoc, replace

from ontobio.ontol_factory import OntologyFactory
from biolink.ontology.ontology_manager import get_ontology
from ontobio.io.ontol_renderers import OboJsonGraphRenderer

import json

### Some query parameters & parsers
IS_A = "isa"
IS_A_PART_OF = "isa_partof"
REGULATES = "regulates"

related_params = api.parser()
related_params.add_argument(
    'relationship_type',
    choices=[IS_A, IS_A_PART_OF, REGULATES],
    default=IS_A_PART_OF,
    help="relationship type ('{}', '{}' or '{}')".format(
        IS_A, IS_A_PART_OF, REGULATES))

TOPOLOGY = "topology_graph"
REGULATES_TRANSITIVITY = "regulates_transitivity_graph"
NEIGHBORHOOD_GRAPH = "neighborhood_graph"
NEIGHBORHOOD_LIMITED_GRAPH = "neighborhood_limited_graph"
graph_params = api.parser()
graph_params.add_argument('graph_type',
                          choices=[
                              TOPOLOGY, REGULATES_TRANSITIVITY,
示例#14
0
import logging

from flask import request
from flask_restplus import Resource
from biolink.datamodel.serializers import association_results, association, gene, drug, genotype, allele, search_result
#import biolink.datamodel.serializers
from biolink.api.restplus import api
from biolink.util.golr_associations import search_associations
import pysolr

log = logging.getLogger(__name__)

ns = api.namespace('bio',
                   description='Retrieval of domain objects plus associations')

core_parser = api.parser()
core_parser.add_argument('exclude_evidence',
                         type=bool,
                         help='If set, excludes evidence objects in response')


@ns.route('/gene/<id>')
@api.doc(params={'id': 'id, e.g. NCBIGene:84570'})
class GeneObject(Resource):
    @api.expect(core_parser)
    @api.marshal_list_with(gene)
    def get(self, id):
        """
        TODO Returns gene object
        """
        return {'foo': 'bar'}
from ontobio.golr.golr_query import GolrSearchQuery, run_solr_on, run_solr_text_on, ESOLR, ESOLRDoc, replace

from ontobio.ontol_factory import OntologyFactory
from biolink.ontology.ontology_manager import get_ontology
from ontobio.io.ontol_renderers import OboJsonGraphRenderer

from biolink.api.entityset.endpoints.slimmer import gene_to_uniprot_from_mygene, uniprot_to_gene_from_mygene

import json

### Some query parameters & parsers
IS_A = "isa"
IS_A_PART_OF = "isa_partof"
REGULATES = "regulates"

related_params = api.parser()
related_params.add_argument(
    'relationship_type',
    choices=[IS_A, IS_A_PART_OF, REGULATES],
    default=IS_A_PART_OF,
    help="relationship type ('{}', '{}' or '{}')".format(
        IS_A, IS_A_PART_OF, REGULATES))

TOPOLOGY = "topology_graph"
REGULATES_TRANSITIVITY = "regulates_transitivity_graph"
NEIGHBORHOOD_GRAPH = "neighborhood_graph"
NEIGHBORHOOD_LIMITED_GRAPH = "neighborhood_limited_graph"
graph_params = api.parser()
graph_params.add_argument('graph_type',
                          choices=[
                              TOPOLOGY, REGULATES_TRANSITIVITY,