Skip to content

Commit

Permalink
Merge branch 'release/v0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Jul 3, 2020
2 parents 11b94da + 03ce9d6 commit fe74273
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 196 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Expand Up @@ -14,7 +14,9 @@
"titleBar.inactiveForeground": "#15202b99",
"statusBar.background": "#eaca7f",
"statusBarItem.hoverBackground": "#e3b853",
"statusBar.foreground": "#15202b"
"statusBar.foreground": "#15202b",
"statusBar.border": "#eaca7f",
"titleBar.border": "#eaca7f"
},
"python.pythonPath": ".venv/bin/python",
"python.analysis.openFilesOnly": false,
Expand Down
39 changes: 28 additions & 11 deletions app/main.py
Expand Up @@ -10,9 +10,11 @@
import sys

import gevent.monkey

gevent.monkey.patch_all()

import bel.lang.bel_specification

# import logging
# import logging.config
# # from pythonjsonlogger import jsonlogger
Expand All @@ -30,22 +32,36 @@
import services.swaggerui
from middleware.field_converters import BelConverter
from middleware.stats import FalconStatsMiddleware
from resources.bel_lang import (BelCanonicalize, BelCompletion,
BelDecanonicalize, BelMigrate12,
BelSpecificationResource, BelVersions)
from resources.bel_lang import (
BelCanonicalize,
BelCompletion,
BelDecanonicalize,
BelMigrate12,
BelSpecificationResource,
BelVersions,
)
from resources.belspec import BelSpecResource
from resources.nanopubs import NanopubValidateResource
from resources.orthology import OrthologResource
from resources.pubmed import PubmedResource
from resources.status import (HealthCheckResource, PingResource,
SimpleStatusResource, StatusResource,
VersionResource)
from resources.status import (
HealthCheckResource,
PingResource,
SimpleStatusResource,
StatusResource,
VersionResource,
)
from resources.swagger import SwaggerResource
from resources.tasks import ResourcesTasksResource
from resources.terms import (TermCanonicalizeResource, TermCompletionsResource,
TermDecanonicalizeResource,
TermEquivalentsResource, TermResource,
TermsResource, TermTypesResource)
from resources.terms import (
TermCanonicalizeResource,
TermCompletionsResource,
TermDecanonicalizeResource,
TermEquivalentsResource,
TermResource,
TermsResource,
TermTypesResource,
)

# import logging_tree
# from logging_tree import printout
Expand Down Expand Up @@ -128,8 +144,9 @@ def user_loader(payload):


# Term routes
app.add_route("/terms/completions/{completion_text}", TermCompletionsResource())
app.add_route("/terms", TermsResource()) # GET
app.add_route("/terms/completions/{completion_text:bel}", TermCompletionsResource())


app.add_route("/terms/{term_id:bel}", TermResource()) # GET
app.add_route("/terms/{term_id:bel}/equivalents", TermEquivalentsResource()) # GET
Expand Down
72 changes: 54 additions & 18 deletions app/resources/terms.py
Expand Up @@ -21,7 +21,10 @@ def on_get(self, req, resp, term_id=None):
"""

if term_id is None:
resp.media = {'title': 'Term endpoint Error', 'message': 'Must provide a term id, e.g. /term/HGNC:AKT1'}
resp.media = {
"title": "Term endpoint Error",
"message": "Must provide a term id, e.g. /term/HGNC:AKT1",
}
resp.status = falcon.HTTP_200
return

Expand All @@ -30,8 +33,8 @@ def on_get(self, req, resp, term_id=None):
resp.media = term
resp.status = falcon.HTTP_200
else:
description = 'No term found for {}'.format(term_id)
resp.media = {'title': 'No Term', 'message': description}
description = "No term found for {}".format(term_id)
resp.media = {"title": "No Term", "message": description}
resp.status = falcon.HTTP_404


Expand All @@ -48,7 +51,7 @@ def on_get(self, req, resp):
Results:
List[Mapping[str, Any]]: list of terms
"""
resp.media = {'title': 'Terms GET query', 'message': 'To be implemented.'}
resp.media = {"title": "Terms GET query", "message": "To be implemented."}
resp.status = falcon.HTTP_200


Expand All @@ -59,7 +62,7 @@ def on_get(self, req, resp, term_id):
"""GET User Profile"""

results = terms.get_equivalents(term_id)
resp.media = {'equivalents': results}
resp.media = {"equivalents": results}
resp.status = falcon.HTTP_200


Expand All @@ -69,11 +72,11 @@ class TermCanonicalizeResource(object):
def on_get(self, req, resp, term_id):
"""GET User Profile"""

namespace_targets = req.get_param('namespace_targets')
namespace_targets = req.get_param("namespace_targets")
if namespace_targets:
namespace_targets = json.loads(namespace_targets)
term_id = terms.canonicalize(term_id, namespace_targets=namespace_targets)
resp.media = {'term_id': term_id}
resp.media = {"term_id": term_id}
resp.status = falcon.HTTP_200


Expand All @@ -83,21 +86,20 @@ class TermDecanonicalizeResource(object):
def on_get(self, req, resp, term_id):
"""GET User Profile"""

namespace_targets = req.get_param('namespace_targets')
namespace_targets = req.get_param("namespace_targets")
if namespace_targets:
namespace_targets = json.loads(namespace_targets)

term_id = terms.decanonicalize(term_id)
resp.media = {'term_id': term_id}
resp.media = {"term_id": term_id}
resp.status = falcon.HTTP_200


class TermCompletionsResource(object):

"""Get NSArgs that match completion request"""

# TODO https://github.com/belbio/bel/issues/88 - fix when upgrading to FastAPI

def on_get(self, req, resp, completion_text):
"""GET List of Terms
Expand All @@ -108,14 +110,48 @@ def on_get(self, req, resp, completion_text):
List[Mapping[str, Any]]: list of terms
"""

size = req.get_param('size', default=21)
entity_types = req.get_param('entity_types', [])
species = req.get_param('species', [])
annotation_types = req.get_param('annotation_types', [])
namespaces = req.get_param('namespaces', [])
log.info("Here 1")
log.info(f"Here {completion_text}")
log.info("Here 2")

completions = terms.get_term_completions(completion_text, size, entity_types, annotation_types, species, namespaces)
resp.media = {'completion_text': completion_text, 'completions': completions}
size = req.get_param("size")
entity_types = req.get_param("entity_types")
species = req.get_param("species")
annotation_types = req.get_param("annotation_types")
namespaces = req.get_param("namespaces")

if not size:
size = 21
if not entity_types:
entity_types = []
else:
entity_types = [et.strip() for et in entity_types.split(",")]
if not species:
species = []
else:
species = [a.strip() for a in species.split(",")]
if not annotation_types:
annotation_types = []
else:
annotation_types = [a.strip() for a in annotation_types.split(",")]
if not namespaces:
namespaces = []
else:
namespaces = [a.strip() for a in namespaces.split(",")]

# log.info(
# f"Term Completion endpoint",
# completion_text=completion_text,
# size=size,
# species=species,
# namespace=namespaces,
# entity_types=entity_types,
# )

completions = terms.get_term_completions(
completion_text, size, entity_types, annotation_types, species, namespaces
)
resp.media = {"completion_text": completion_text, "completions": completions}
resp.status = falcon.HTTP_200


Expand Down

0 comments on commit fe74273

Please sign in to comment.