diff --git a/server/__init__.py b/server/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/server/app/__init__.py b/server/app/__init__.py index 92415348..07220711 100644 --- a/server/app/__init__.py +++ b/server/app/__init__.py @@ -1,55 +1 @@ -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 - -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") +from . import app \ No newline at end of file diff --git a/server/app/app.py b/server/app/app.py new file mode 100644 index 00000000..cb3ee110 --- /dev/null +++ b/server/app/app.py @@ -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) + diff --git a/server/app/rest_api/rest.py b/server/app/rest_api/rest.py index a953d7ff..be9cc39c 100644 --- a/server/app/rest_api/rest.py +++ b/server/app/rest_api/rest.py @@ -88,7 +88,7 @@ class InitializeAPI(Resource): } }) def get(self): - from .. import data, REACTIVE_LIMIT + from ..app import data, REACTIVE_LIMIT return make_payload({ "schema": data.schema, "cellcount": data.cell_count, @@ -191,7 +191,7 @@ class CellsAPI(Resource): } }) def get(self): - from .. import data + from ..app import data payload = { "metadata": [], "cellcount": 0, @@ -251,7 +251,7 @@ class ExpressionAPI(Resource): } }) def get(self): - from .. import data + from ..app import data expression_data = data.expression() return make_payload(expression_data) @@ -309,7 +309,7 @@ class ExpressionAPI(Resource): } }) def post(self): - from .. import data + from ..app import data args = request.get_json() cell_list = args.get("celllist", []) gene_list = args.get("genelist", []) @@ -415,7 +415,7 @@ class DifferentialExpressionAPI(Resource): } }) def post(self): - from .. import data + from ..app import data args = request.get_json() cell_list_1 = args.get("celllist1", []) cell_list_2 = args.get("celllist2", []) diff --git a/server/requirements.txt b/server/requirements.txt index 93131d27..21b90d84 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1,5 +1,5 @@ aniso8601==3.0.2 -anndata==0.6.1 +anndata==0.6.4 certifi==2018.4.16 chardet==3.0.4 click==6.7 @@ -30,7 +30,7 @@ pyparsing==2.2.0 python-dateutil==2.7.3 pytz==2018.4 requests==2.19.1 -scanpy==1.2.2 +scanpy==1.0.4 scikit-learn==0.19.1 scipy==1.1.0 seaborn==0.8.1 diff --git a/server/run.py b/server/run.py index c7afec43..dd4feb33 100644 --- a/server/run.py +++ b/server/run.py @@ -1,3 +1,3 @@ -from app import app +from app.app import app app.run(host="0.0.0.0", debug=True, port=5005) diff --git a/setup.py b/setup.py index 993abc62..f591a66f 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,6 @@ setup( author_email='cweaver@chanzuckerberg.com', description='Web application for exploration of large scale scRNA-seq datasets', long_description=long_description, - long_description_content_type="text/markdown", install_requires=requirements, include_package_data=True, zip_safe=False, @@ -24,4 +23,8 @@ setup( "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", ), + entry_points={ + 'console_scripts': + ['cellxgene = server.app.app:main'] + } )