mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-25 14:28:11 +08:00
Consistency with quotes
' -> "
This commit is contained in:
@@ -34,7 +34,7 @@ app.config.update(
|
||||
DATASET_TITLE=TITLE
|
||||
)
|
||||
|
||||
app.config['PROFILE'] = True
|
||||
app.config["PROFILE"] = True
|
||||
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[15])
|
||||
|
||||
# Application Data
|
||||
@@ -54,8 +54,8 @@ 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'))
|
||||
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')
|
||||
app.add_url_rule("/", endpoint="index")
|
||||
|
||||
+61
-61
@@ -9,14 +9,14 @@ from ..util.filter import parse_filter
|
||||
|
||||
class InitializeAPI(Resource):
|
||||
@swagger.doc({
|
||||
'summary': 'get metadata schema, ranges for values, and cell count to initialize cellxgene app',
|
||||
'tags': ['initialize'],
|
||||
'parameters': [],
|
||||
'responses': {
|
||||
'200': {
|
||||
'description': 'initialization data for UI',
|
||||
'examples': {
|
||||
'application/json': {
|
||||
"summary": "get metadata schema, ranges for values, and cell count to initialize cellxgene app",
|
||||
"tags": ["initialize"],
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "initialization data for UI",
|
||||
"examples": {
|
||||
"application/json": {
|
||||
"data": {
|
||||
"cellcount": 3589,
|
||||
"options": {
|
||||
@@ -101,21 +101,21 @@ class InitializeAPI(Resource):
|
||||
|
||||
class CellsAPI(Resource):
|
||||
@swagger.doc({
|
||||
'summary': 'filter based on metadata fields to get a subset cells, expression data, and metadata',
|
||||
'tags': ['cells'],
|
||||
'description': "Cells takes query parameters defined in the schema retrieved from the /initialize enpoint. "
|
||||
"summary": "filter based on metadata fields to get a subset cells, expression data, and metadata",
|
||||
"tags": ["cells"],
|
||||
"description": "Cells takes query parameters defined in the schema retrieved from the /initialize enpoint. "
|
||||
"<br>For categorical metadata keys filter based on `key=value` <br>"
|
||||
" For continuous metadata keys filter by `key=min,max`<br> Either value "
|
||||
"can be replaced by a \*. To have only a minimum value `key=min,\*` To have only a maximum "
|
||||
"value `key=\*,max` <br>Graph data (if retrieved) is normalized"
|
||||
" To only retrieve cells that don't have a value for the key filter by `key`",
|
||||
'parameters': [],
|
||||
"parameters": [],
|
||||
|
||||
'responses': {
|
||||
'200': {
|
||||
'description': 'initialization data for UI',
|
||||
'examples': {
|
||||
'application/json': {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "initialization data for UI",
|
||||
"examples": {
|
||||
"application/json": {
|
||||
"data": {
|
||||
"badmetadatacount": 0,
|
||||
"cellcount": 0,
|
||||
@@ -185,8 +185,8 @@ class CellsAPI(Resource):
|
||||
},
|
||||
},
|
||||
|
||||
'400': {
|
||||
'description': 'bad query params',
|
||||
"400": {
|
||||
"description": "bad query params",
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -212,21 +212,21 @@ class CellsAPI(Resource):
|
||||
|
||||
class ExpressionAPI(Resource):
|
||||
@swagger.doc({
|
||||
'summary': 'Json with gene list and expression data by cell, limited to first 40 cells',
|
||||
'tags': ['expression'],
|
||||
'parameters': [
|
||||
"summary": "Json with gene list and expression data by cell, limited to first 40 cells",
|
||||
"tags": ["expression"],
|
||||
"parameters": [
|
||||
{
|
||||
'name': 'include_unexpressed_genes',
|
||||
'description': "Include genes that have 0 expression across all cells in set",
|
||||
'in': 'path',
|
||||
'type': 'bool',
|
||||
"name": "include_unexpressed_genes",
|
||||
"description": "Include genes that have 0 expression across all cells in set",
|
||||
"in": "path",
|
||||
"type": "bool",
|
||||
}
|
||||
],
|
||||
'responses': {
|
||||
'200': {
|
||||
'description': 'Json for heatmap',
|
||||
'examples': {
|
||||
'application/json': {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Json for heatmap",
|
||||
"examples": {
|
||||
"application/json": {
|
||||
"data": {
|
||||
"cells": [
|
||||
{
|
||||
@@ -258,12 +258,12 @@ class ExpressionAPI(Resource):
|
||||
return make_payload(expression_data)
|
||||
|
||||
@swagger.doc({
|
||||
'summary': 'Json with gene list and expression data by cell',
|
||||
'tags': ['expression'],
|
||||
'parameters': [
|
||||
"summary": "Json with gene list and expression data by cell",
|
||||
"tags": ["expression"],
|
||||
"parameters": [
|
||||
{
|
||||
'name': 'body',
|
||||
'in': 'body',
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"example": {
|
||||
"celllist": ["1001000173.G8", "1001000173.D4"],
|
||||
@@ -275,11 +275,11 @@ class ExpressionAPI(Resource):
|
||||
}
|
||||
},
|
||||
],
|
||||
'responses': {
|
||||
'200': {
|
||||
'description': 'Json for expressiondata',
|
||||
'examples': {
|
||||
'application/json': {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Json for expressiondata",
|
||||
"examples": {
|
||||
"application/json": {
|
||||
"data": {
|
||||
"cells": [
|
||||
{
|
||||
@@ -305,24 +305,24 @@ class ExpressionAPI(Resource):
|
||||
}
|
||||
}
|
||||
},
|
||||
'400': {
|
||||
'description': 'Required parameter missing/incorrect',
|
||||
"400": {
|
||||
"description": "Required parameter missing/incorrect",
|
||||
}
|
||||
}
|
||||
})
|
||||
def post(self):
|
||||
from app import data
|
||||
args = request.get_json()
|
||||
cell_list = args.get('celllist', [])
|
||||
gene_list = args.get('genelist', [])
|
||||
cell_list = args.get("celllist", [])
|
||||
gene_list = args.get("genelist", [])
|
||||
if not cell_list and not gene_list:
|
||||
return make_payload([], "must include celllist and/or genelist parameter", 400)
|
||||
|
||||
expression_data = data.expression(cell_list, gene_list)
|
||||
|
||||
if cell_list and len(expression_data['cells']) < len(cell_list):
|
||||
if cell_list and len(expression_data["cells"]) < len(cell_list):
|
||||
return make_payload([], "Some cell ids not available", 400)
|
||||
if gene_list and len(expression_data['genes']) < len(gene_list):
|
||||
if gene_list and len(expression_data["genes"]) < len(gene_list):
|
||||
return make_payload([], "Some genes not available", 400)
|
||||
|
||||
return make_payload(expression_data)
|
||||
@@ -330,13 +330,13 @@ class ExpressionAPI(Resource):
|
||||
|
||||
class DifferentialExpressionAPI(Resource):
|
||||
@swagger.doc({
|
||||
'summary': 'Get the top expressed genes for two cell sets. Calculated using t-test',
|
||||
'tags': ['expression'],
|
||||
'parameters': [
|
||||
"summary": "Get the top expressed genes for two cell sets. Calculated using t-test",
|
||||
"tags": ["expression"],
|
||||
"parameters": [
|
||||
{
|
||||
'name': 'body',
|
||||
'in': 'body',
|
||||
'schema': {
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"example": {
|
||||
"celllist1": ["1001000176.C12", "1001000176.C7", "1001000177.F11"],
|
||||
"celllist2": ["1001000012.D2", "1001000017.F10", "1001000033.C3", "1001000229.D4"],
|
||||
@@ -347,10 +347,10 @@ class DifferentialExpressionAPI(Resource):
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
'200': {
|
||||
'description': 'top expressed genes for cellset1, cellset2',
|
||||
'examples': {
|
||||
'application/json': {
|
||||
"200": {
|
||||
"description": "top expressed genes for cellset1, cellset2",
|
||||
"examples": {
|
||||
"application/json": {
|
||||
"data": {
|
||||
"celllist1": {
|
||||
"ave_diff": [
|
||||
@@ -419,10 +419,10 @@ class DifferentialExpressionAPI(Resource):
|
||||
def post(self):
|
||||
from app import data
|
||||
args = request.get_json()
|
||||
cell_list_1 = args.get('celllist1', [])
|
||||
cell_list_2 = args.get('celllist2', [])
|
||||
cell_list_1 = args.get("celllist1", [])
|
||||
cell_list_2 = args.get("celllist2", [])
|
||||
num_genes = args.get("num_genes", 7)
|
||||
pval = args.get('pval', 0.5)
|
||||
pval = args.get("pval", 0.5)
|
||||
if not (cell_list_1 and cell_list_2):
|
||||
return make_payload([],
|
||||
"must include celllist1 and celllist2 parameters",
|
||||
@@ -432,7 +432,7 @@ class DifferentialExpressionAPI(Resource):
|
||||
|
||||
|
||||
def get_api_resources():
|
||||
bp = Blueprint('api', __name__, url_prefix='/api/v2.0')
|
||||
bp = Blueprint("api", __name__, url_prefix="/api/v2.0")
|
||||
api = Api(bp, add_api_spec_resource=False)
|
||||
api.add_resource(InitializeAPI, "/initialize")
|
||||
api.add_resource(CellsAPI, "/cells")
|
||||
|
||||
@@ -33,9 +33,9 @@ class ScanpyEngine(CXGDriver):
|
||||
return data_schema
|
||||
|
||||
def _set_cell_ids(self):
|
||||
self.data.obs['cxg_cell_id'] = list(range(self.data.obs.shape[0]))
|
||||
self.data.obs["cxg_cell_id"] = list(range(self.data.obs.shape[0]))
|
||||
self.data.obs["cell_name"] = list(self.data.obs.index)
|
||||
self.data.obs.set_index('cxg_cell_id', inplace=True)
|
||||
self.data.obs.set_index("cxg_cell_id", inplace=True)
|
||||
|
||||
def cells(self):
|
||||
return list(self.data.obs.index)
|
||||
@@ -78,7 +78,7 @@ class ScanpyEngine(CXGDriver):
|
||||
if self.schema[field]["variabletype"] == "categorical":
|
||||
group_by = field
|
||||
if group_by == "CellName":
|
||||
group_by = 'cell_name'
|
||||
group_by = "cell_name"
|
||||
metadata_ranges[field] = {"options": df.obs.groupby(group_by).size().to_dict()}
|
||||
else:
|
||||
metadata_ranges[field] = {
|
||||
|
||||
@@ -2,10 +2,10 @@ from flask import (
|
||||
Blueprint, render_template, url_for, current_app
|
||||
)
|
||||
|
||||
bp = Blueprint('webapp', __name__, template_folder='templates')
|
||||
bp = Blueprint("webapp", __name__, template_folder="templates")
|
||||
|
||||
|
||||
@bp.route('/')
|
||||
@bp.route("/")
|
||||
def index():
|
||||
url_base = current_app.config["CXG_API_BASE"]
|
||||
dataset_title = current_app.config["DATASET_TITLE"]
|
||||
@@ -13,12 +13,12 @@ def index():
|
||||
|
||||
|
||||
# renders swagger documentation
|
||||
@bp.route('/swagger')
|
||||
@bp.route("/swagger")
|
||||
def swag():
|
||||
return render_template("swagger.html")
|
||||
|
||||
|
||||
# renders swagger documentation
|
||||
@bp.route('/favicon.png')
|
||||
@bp.route("/favicon.png")
|
||||
def favicon():
|
||||
return url_for("static", filename="img/favicon.png")
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
from 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)
|
||||
|
||||
Reference in New Issue
Block a user