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

0
server/__init__.py Normal file
View File

View File

@@ -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

62
server/app/app.py Normal file
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)

View File

@@ -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", [])

View File

@@ -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

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)

View File

@@ -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']
}
)