Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add connexion #99

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import os
import json
import flask
import connexion
from flask_cors import CORS
from app import database, geneset, drugset, download, statistics

ROOT_PATH = os.environ.get('ROOT_PATH', '/covid19/')
# Load any additional configuration parameters via
# environment variables--`../.env` can be used
# for sensitive information!

app = flask.Flask(__name__, static_url_path=ROOT_PATH + 'static')

connexionApp = connexion.App(__name__)
connexionApp.add_api(os.path.join(os.path.dirname(__file__), 'swagger.yaml'), base_path=ROOT_PATH)
app = connexionApp.app
app.static_url_path = ROOT_PATH + 'static'
CORS(app)

app.before_first_request(database.init)


Expand All @@ -20,27 +28,23 @@ def route_index():
def route_genesets_table():
return geneset.serve_geneset_datatable(int(flask.request.values.get('reviewed')))(**json.loads(flask.request.values.get('body')))

@app.route(ROOT_PATH + 'genesets', methods=['GET', 'POST'])
@app.route(ROOT_PATH + 'genesets', methods=['GET'])
def route_genesets():
if flask.request.method == 'GET':
reviewed = flask.request.args.get('reviewed', 1)
return geneset.get_genesets(reviewed)
elif flask.request.method == 'POST':
return geneset.add_geneset(flask.request.form)

@app.route(ROOT_PATH + 'drugsets_table', methods=['POST'])
def route_drugsets_table():
return drugset.serve_drugset_datatable(int(flask.request.values.get('reviewed')))(
**json.loads(flask.request.values.get('body'))
)

@app.route(ROOT_PATH + 'drugsets', methods=['GET', 'POST'])
@app.route(ROOT_PATH + 'drugsets', methods=['GET'])
def route_drugs():
if flask.request.method == 'GET':
reviewed = flask.request.args.get('reviewed', 1)
return drugset.get_drugsets(reviewed)
elif flask.request.method == 'POST':
return drugset.add_drugset(flask.request.form)


@app.route(ROOT_PATH + 'review', methods=['GET', 'POST'])
Expand Down
21 changes: 13 additions & 8 deletions app/download.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import flask
from app.database import Session
from app.models import Geneset, Drugset

def genesets():
sess = Session()
for geneset in sess.query(Geneset).filter(Geneset.reviewed == 1):
yield geneset.to_gmt() + '\n'
sess.close()
def geneset_generator():
sess = Session()
for geneset in sess.query(Geneset).filter(Geneset.reviewed == 1):
yield geneset.to_gmt() + '\n'
sess.close()
return flask.Response(geneset_generator(), mimetype='text/gmt')

def drugsets():
sess = Session()
for drugset in sess.query(Drugset).filter(Drugset.reviewed == 1):
yield drugset.to_gmt() + '\n'
sess.close()
def drugset_generator():
sess = Session()
for drugset in sess.query(Drugset).filter(Drugset.reviewed == 1):
yield drugset.to_gmt() + '\n'
sess.close()
return flask.Response(drugset_generator(), mimetype='text/gmt')
2 changes: 1 addition & 1 deletion app/geneset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def add_geneset(form):
author_name = form['authorName']
author_email = form['authorEmail']
author_aff = form['authorAff']
show_contacts = 1 if 'showContacts' in form else 0
show_contacts = 1 if form.get('showContacts') else 0
enrichr_ids = enrichr_submit(gene_set, desc_short)
enrichr_shortid = enrichr_ids['shortId']
enrichr_userlistid = enrichr_ids['userListId']
Expand Down
175 changes: 175 additions & 0 deletions app/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
swagger: '2.0'
info:
title: COVID-19 Crowd Generated Gene and Drug Set Library API
version: "0.1"
description: A collection of drugs and gene sets related to COVID-19 research contributed by the community
consumes:
- application/json
produces:
- application/json
paths:
/genesets:
post:
operationId: app.geneset.add_geneset
consumes:
- application/x-www-form-urlencoded
parameters:
- name: body
in: body
schema:
type: object
properties:
source:
type: string
format: url
description: The source URL
geneSet:
type: string
description: The actual newline-separated set
descrFull:
type: string
description: A long description of the set
descrShort:
type: string
description: A short description of the set
authorName:
type: string
description: Author Name
authorEmail:
type: string
description: Author Email
authorAff:
type: string
description: Author affiliation
showContacts:
type: boolean
description: true to show, false otherwise (defaults to false)
meta:
type: object
description: Additional key-value metadata properties
additionalProperties:
type: string
required:
- source
- geneSet
- descrFull
- descrShort
- authorName
- authorEmail
- authorAff
- showContacts
- meta
required: true
responses:
200:
description: Success
schema:
type: object
properties:
success:
type: boolean
description: true on success, false otherwise
500:
description: Error occurred
schema:
type: object
properties:
success:
type: boolean
description: true on success, false otherwise
error:
type: string
description: A error string possibly explaining the error

/genesets.gmt:
get:
operationId: app.download.genesets
description: Download the genesets
produces:
- text/gmt
responses:
200:
description: A GMT containing all the genesets

/drugsets:
post:
operationId: app.drugset.add_drugset
consumes:
- application/x-www-form-urlencoded
parameters:
- name: body
in: body
schema:
type: object
properties:
source:
type: string
format: url
description: The source URL
geneSet:
type: string
description: The actual newline-separated set
descrFull:
type: string
description: A long description of the set
descrShort:
type: string
description: A short description of the set
authorName:
type: string
description: Author Name
authorEmail:
type: string
description: Author Email
authorAff:
type: string
description: Author affiliation
showContacts:
type: boolean
description: true to show, false otherwise (defaults to false)
meta:
type: object
description: Additional key-value metadata properties
additionalProperties:
type: string
required:
- source
- geneSet
- descrFull
- descrShort
- authorName
- authorEmail
- authorAff
- showContacts
- meta
required: true
responses:
200:
description: Success
schema:
type: object
properties:
success:
type: boolean
description: true on success, false otherwise
500:
description: Error occurred
schema:
type: object
properties:
success:
type: boolean
description: true on success, false otherwise
error:
type: string
description: A error string possibly explaining the error

/drugsets.gmt:
get:
operationId: app.download.drugsets
description: Download the drugsets
produces:
- text/gmt
responses:
200:
description: A GMT containing all the genesets
4 changes: 2 additions & 2 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h1 class="display-5">COVID-19 Crowd Generated Gene and Drug Set Library</h1>
style="width:100%">
</table>
<div class="row">
<a href="{{ url_for('download_drugsets') }}"><i class="fas fa-download mr-1"
<a href="./drugsets.gmt"><i class="fas fa-download mr-1"
style="font-size: 0.9rem;"></i>Download
all drug sets</a>
</div>
Expand All @@ -71,7 +71,7 @@ <h1 class="display-5">COVID-19 Crowd Generated Gene and Drug Set Library</h1>
style="width:100%">
</table>
<div class="row">
<a href="{{ url_for('download_genesets') }}"><i class="fas fa-download mr-1"
<a href="./genesets.gmt"><i class="fas fa-download mr-1"
style="font-size: 0.9rem;"> </i>Download
all gene sets</a>
</div>
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Python dependencies
alembic
connexion
cryptography
Flask
flask_cors
pymysql
python-dotenv
pytz
requests
sqlalchemy
swagger-ui-bundle
uwsgi
5 changes: 4 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import json
from app.app import app
from app.app import connexionApp as app

ROOT_PATH = os.environ.get('ROOT_PATH', '/covid19/')
DEBUG_PORT = json.loads(os.environ.get('DEBUG_PORT', 'null'))
DEBUG = json.loads(os.environ.get('DEBUG', 'true'))
# HOST = os.environ.get('HOST', '0.0.0.0')
Expand All @@ -16,4 +17,6 @@
PORT = DEBUG_PORT

# TODO: Add `HOST` when DB `HOST` is fully removed
print(f'Application at http://0.0.0.0:{PORT}{ROOT_PATH}')
print(f'Swagger UI at http://0.0.0.0:{PORT}{ROOT_PATH}ui/')
app.run(host='0.0.0.0', port=PORT, debug=DEBUG)