Skip to content

Commit

Permalink
Updated BEL Specification endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Aug 29, 2018
1 parent b44aa6c commit 841b7ac
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1,713 deletions.
3 changes: 2 additions & 1 deletion api/resources/belspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ def on_get(self, req, resp, version=''):
def on_put(self, req, resp):
"""Save BEL Spec onto server"""

force = req.get_param('force', False)
belspec = req.media['belspec']
fn_version = belspec['version'].replace('.', '_')

fn = f'{belspec_dir}/bel_v{fn_version}.yaml'
with open(fn, 'w') as f:
yaml.dump(belspec, f, indent=2)

bel.lang.bel_specification.update_specifications()
bel.lang.bel_specification.update_specifications(force=force)

resp.status = falcon.HTTP_204

Expand Down
97 changes: 97 additions & 0 deletions api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from middleware.field_converters import BelConverter

from resources.status import SimpleStatusResource, HealthCheckResource, StatusResource, VersionResource
from resources.swagger import SwaggerResource

from resources.bel_lang import BelVersions
from resources.bel_lang import BelSpecificationResource
from resources.bel_lang import BelCompletion
from resources.bel_lang import BelCanonicalize
from resources.bel_lang import BelDecanonicalize

from resources.bel_lang import BelMigrate12

from resources.tasks import PipelineTasksResource
from resources.tasks import ResourcesTasksResource

from resources.nanopubs import NanopubValidateResource

from resources.edges import EdgeResource
from resources.edges import EdgesFromNanopubResource

from resources.terms import TermResource
from resources.terms import TermsResource
from resources.terms import TermCompletionsResource
from resources.terms import TermEquivalentsResource
from resources.terms import TermCanonicalizeResource
from resources.terms import TermDecanonicalizeResource
from resources.terms import TermTypesResource

from resources.orthology import OrthologResource

from resources.belspec import BelSpecResource

from resources.pubmed import PubmedResource


def add_routes(api):
# Router converter for BEL Expressions and NSArgs
# converts_FORWARDSLASH_ to / after URI template fields are extracted
#
api.router_options.converters['bel'] = BelConverter

# Routes ###############
# Add routes to skip authentication in common/middleware:AuthMiddleware.skip_routes list

# BEL Language routes
api.add_route('/bel/versions', BelVersions()) # GET
api.add_route('/bel/{version}/completion', BelCompletion()) # GET
api.add_route('/bel/{version}/completion/{belstr:bel}', BelCompletion()) # GET
api.add_route('/bel/{version}/canonicalize/{belstr:bel}', BelCanonicalize()) # GET
api.add_route('/bel/{version}/decanonicalize/{belstr:bel}', BelDecanonicalize()) # GET

# BEL1->2 Migration
api.add_route('/bel/migrate12/{belstr:bel}', BelMigrate12()) # GET

# api.add_route('/bel/{version}/functions', BelSpecificationResource()) # GET
# api.add_route('/bel/{version}/relations', BelSpecificationResource()) # GET

# Edges and EdgeStore
api.add_route('/edges/{edge_id}', EdgeResource()) # GET
api.add_route('/edges/nanopub/', EdgesFromNanopubResource()) # GET

# Nanopub routes
api.add_route('/nanopubs/validate', NanopubValidateResource()) # POST

# Task routes
api.add_route('/tasks/pipeline', PipelineTasksResource()) # POST
api.add_route('/tasks/resources', ResourcesTasksResource()) # POST

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

api.add_route('/terms/{term_id:bel}', TermResource()) # GET
api.add_route('/terms/{term_id:bel}/equivalents', TermEquivalentsResource()) # GET
api.add_route('/terms/{term_id:bel}/canonicalized', TermCanonicalizeResource()) # GET
api.add_route('/terms/{term_id:bel}/decanonicalized', TermDecanonicalizeResource()) # GET
api.add_route('/terms/types', TermTypesResource()) # GET

# Orthology routes
api.add_route('/orthologs', OrthologResource()) # GET
api.add_route('/orthologs/{gene_id:bel}', OrthologResource()) # GET
api.add_route('/orthologs/{gene_id:bel}/{species}', OrthologResource()) # GET

# BEL Specification routes
api.add_route('/belspec', BelSpecResource()) # GET listing, PUT update
api.add_route('/belspec/{version}', BelSpecResource()) # GET, PUT, DELETE

# Text routes
api.add_route('/text/pubmed/{pmid}', PubmedResource()) # GET

# Status endpoints - used to check that API is running correctly
api.add_route('/simple_status', SimpleStatusResource()) # GET un-authenticated
api.add_route('/healthcheck', HealthCheckResource()) # GET un-authenticated
api.add_route('/status', StatusResource()) # GET authenticated
api.add_route('/version', VersionResource()) # version
api.add_route('/swagger', SwaggerResource())
127 changes: 66 additions & 61 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ servers:
- description: Local BEL API
url: /
- description: Demo BEL API
url: https://api.bel.bio
url: http://api.bel.bio

info:
title: BELBio REST API
Expand Down Expand Up @@ -69,27 +69,6 @@ paths:
items:
type: string

/bel/{version}/specification:
get:
summary: BEL Specification
tags:
- BEL
parameters:
- name: version
in: path
required: true
description: BEL Version
schema:
type: string
example: 2.0.0
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object

/bel/{version}/completion/{text}:
get:
summary: BEL Assertion Completion
Expand Down Expand Up @@ -695,6 +674,51 @@ paths:
schema:
$ref: '#/components/schemas/ErrorModel'

put:
summary: Put a BEL Specification
description: |
Create a new or update a prior BEL Specification.
We use semantic versioning (https://semver.org). If you want to add
a custom BEL Spec to your API endpoint, please use a tag to the version
number you want to use.
If you try to use an official BEL Spec version number
(pulled from https://github.com/belbio/bel_specifications),
it will be overwritten by the official BEL Spec as part of the PUT/update/create
process.
tags:
- BelSpecs
operationId: belspecPut
parameters:
- name: force
in: query
description: |
Forces reprocessing of BEL Specifications including pulling the public
BEL Specifications from BEL.bio. Otherwise, it will only attempt to
re-download the BEL Specifications if more than 1 day old.
required: false
default: false
schema:
type: string
requestBody:
description: BEL Specification JSON document
required: false
content:
application/json:
schema:
type: object
responses:
'204':
description: Successful response
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorModel'

/belspec/{version}:
get:
summary: Get a BEL Specification
Expand Down Expand Up @@ -730,39 +754,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorModel'
put:
summary: Put a BEL Specification
description: |
Create a new or update a prior BEL Specification.
We use semantic versioning (https://semver.org). If you want to add
a custom BEL Spec to your API endpoint, please use a tag to the version
number you want to use.
If you try to use an official BEL Spec version number
(pulled from https://github.com/belbio/bel_specifications),
it will be overwritten by the official BEL Spec as part of the PUT/update/create
process.
tags:
- BelSpecs
operationId: belspecPut
parameters:
- name: version
in: path
description: BEL version string
required: true
schema:
type: string
example: 2.0.0
responses:
'204':
description: Successful response
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorModel'

delete:
summary: Delete a BEL Specification
Expand Down Expand Up @@ -1149,6 +1140,7 @@ paths:
- name: term_id
in: path
required: true
example: "HGNC:5"
description: |
Term ID (or alternate Term ID)
Expand All @@ -1160,18 +1152,31 @@ paths:
an extra path component.
schema:
type: string
- name: primary
in: query
required: false
default: true
description: |
Only return primary (preferred namespace) IDs if true (default), otherwise
return all equivalent IDs including alternate IDs.
schema:
type: boolean
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
additionalProperties:
type: string
example:
EG: EG:207
UP: UP:P31749
type: array
items:
type: object
properties:
term_id:
type: string
namespace:
type: string
primary:
type: boolean
default:
description: Error
content:
Expand Down
Loading

0 comments on commit 841b7ac

Please sign in to comment.