Added entry point to run cellxgene from console

This commit is contained in:
Charlotte Weaver
2018-07-10 12:56:42 -07:00
parent a3bf802aec
commit f466ef6553
7 changed files with 75 additions and 64 deletions
View File
+1 -55
View File
@@ -1,55 +1 @@
import os from . import app
from flask import Flask
from flask_compress import Compress
from flask_cors import CORS
from flask_restful_swagger_2 import get_swagger_blueprint
from .web import webapp
from .rest_api.rest import get_api_resources
app = Flask(__name__)
Compress(app)
CORS(app)
# Config
CXG_DIR = os.environ.get("CXG_DIRECTORY", default="/Users/charlotteweaver/Documents/Git/cxg-v2/data/")
SECRET_KEY = os.environ.get("CXG_SECRET_KEY", default="SparkleAndShine")
ENGINE = os.environ.get("CXG_ENGINE", default="scanpy")
TITLE = os.environ.get("DATASET_TITLE", default="PBMC 3K")
# TODO remove the 2 when this is prod
CXG_API_BASE = os.environ.get("CXG_API_BASE2", default="http://0.0.0.0:5005/api/")
app.config.update(
SECRET_KEY=SECRET_KEY,
CXG_API_BASE=CXG_API_BASE,
ENGINE=ENGINE,
DATA=CXG_DIR,
DATASET_TITLE=TITLE
)
app.config["PROFILE"] = True
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[15])
# Application Data
data = None
if app.config["ENGINE"] == "scanpy":
from .scanpy_engine.scanpy_engine import ScanpyEngine
data = ScanpyEngine(app.config["DATA"], schema="data_schema.json")
REACTIVE_LIMIT = 1_000_000
# A list of swagger document objects
docs = []
resources = get_api_resources()
docs.append(resources.get_swagger_doc())
app.register_blueprint(webapp.bp)
app.register_blueprint(resources.blueprint)
app.register_blueprint(
get_swagger_blueprint(docs, "/api/swagger", produces=["application/json"], title="cellxgene rest api",
description="An API connecting ExpressionMatrix2 clustering algorithm to cellxgene"))
app.add_url_rule("/", endpoint="index")
+62
View File
@@ -0,0 +1,62 @@
import os
from flask import Flask
from flask_compress import Compress
from flask_cors import CORS
from flask_restful_swagger_2 import get_swagger_blueprint
from .web import webapp
from .rest_api.rest import get_api_resources
REACTIVE_LIMIT = 1_000_000
app = Flask(__name__)
Compress(app)
CORS(app)
# Config
CXG_DIR = os.environ.get("CXG_DIRECTORY", default="/Users/charlotteweaver/Documents/Git/cxg-v2/data/")
SECRET_KEY = os.environ.get("CXG_SECRET_KEY", default="SparkleAndShine")
ENGINE = os.environ.get("CXG_ENGINE", default="scanpy")
TITLE = os.environ.get("DATASET_TITLE", default="PBMC 3K")
# TODO remove the 2 when this is prod
CXG_API_BASE = os.environ.get("CXG_API_BASE2", default="http://0.0.0.0:5005/api/")
app.config.update(
SECRET_KEY=SECRET_KEY,
CXG_API_BASE=CXG_API_BASE,
ENGINE=ENGINE,
DATA=CXG_DIR,
DATASET_TITLE=TITLE
)
app.config["PROFILE"] = True
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[15])
# Application Data
data = None
if app.config["ENGINE"] == "scanpy":
from .scanpy_engine.scanpy_engine import ScanpyEngine
data = ScanpyEngine(app.config["DATA"], schema="data_schema.json")
# A list of swagger document objects
docs = []
resources = get_api_resources()
docs.append(resources.get_swagger_doc())
app.register_blueprint(webapp.bp)
app.register_blueprint(resources.blueprint)
app.register_blueprint(
get_swagger_blueprint(docs, "/api/swagger", produces=["application/json"], title="cellxgene rest api",
description="An API connecting ExpressionMatrix2 clustering algorithm to cellxgene"))
app.add_url_rule("/", endpoint="index")
def main():
app.run(host="0.0.0.0", debug=True, port=5005)
+5 -5
View File
@@ -88,7 +88,7 @@ class InitializeAPI(Resource):
} }
}) })
def get(self): def get(self):
from .. import data, REACTIVE_LIMIT from ..app import data, REACTIVE_LIMIT
return make_payload({ return make_payload({
"schema": data.schema, "schema": data.schema,
"cellcount": data.cell_count, "cellcount": data.cell_count,
@@ -191,7 +191,7 @@ class CellsAPI(Resource):
} }
}) })
def get(self): def get(self):
from .. import data from ..app import data
payload = { payload = {
"metadata": [], "metadata": [],
"cellcount": 0, "cellcount": 0,
@@ -251,7 +251,7 @@ class ExpressionAPI(Resource):
} }
}) })
def get(self): def get(self):
from .. import data from ..app import data
expression_data = data.expression() expression_data = data.expression()
return make_payload(expression_data) return make_payload(expression_data)
@@ -309,7 +309,7 @@ class ExpressionAPI(Resource):
} }
}) })
def post(self): def post(self):
from .. import data from ..app import data
args = request.get_json() args = request.get_json()
cell_list = args.get("celllist", []) cell_list = args.get("celllist", [])
gene_list = args.get("genelist", []) gene_list = args.get("genelist", [])
@@ -415,7 +415,7 @@ class DifferentialExpressionAPI(Resource):
} }
}) })
def post(self): def post(self):
from .. import data from ..app import data
args = request.get_json() args = request.get_json()
cell_list_1 = args.get("celllist1", []) cell_list_1 = args.get("celllist1", [])
cell_list_2 = args.get("celllist2", []) cell_list_2 = args.get("celllist2", [])
+2 -2
View File
@@ -1,5 +1,5 @@
aniso8601==3.0.2 aniso8601==3.0.2
anndata==0.6.1 anndata==0.6.4
certifi==2018.4.16 certifi==2018.4.16
chardet==3.0.4 chardet==3.0.4
click==6.7 click==6.7
@@ -30,7 +30,7 @@ pyparsing==2.2.0
python-dateutil==2.7.3 python-dateutil==2.7.3
pytz==2018.4 pytz==2018.4
requests==2.19.1 requests==2.19.1
scanpy==1.2.2 scanpy==1.0.4
scikit-learn==0.19.1 scikit-learn==0.19.1
scipy==1.1.0 scipy==1.1.0
seaborn==0.8.1 seaborn==0.8.1
+1 -1
View File
@@ -1,3 +1,3 @@
from app import app from app.app import app
app.run(host="0.0.0.0", debug=True, port=5005) app.run(host="0.0.0.0", debug=True, port=5005)
+4 -1
View File
@@ -16,7 +16,6 @@ setup(
author_email='cweaver@chanzuckerberg.com', author_email='cweaver@chanzuckerberg.com',
description='Web application for exploration of large scale scRNA-seq datasets', description='Web application for exploration of large scale scRNA-seq datasets',
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown",
install_requires=requirements, install_requires=requirements,
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
@@ -24,4 +23,8 @@ setup(
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
), ),
entry_points={
'console_scripts':
['cellxgene = server.app.app:main']
}
) )