mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-03 08:18:13 +08:00
core library (#711)
* move app creation to function * create engine without load * flake 8 fixes * cleanup original scanpy test * add default config * handle missing data * test data changes * unify update * load data isn't static anymore * make app a class
This commit is contained in:
@@ -30,3 +30,4 @@ class DiffExpMode(AugmentedEnum):
|
||||
JSON_NaN_to_num_warning_msg = (
|
||||
"JSON encoding failure - please verify all data are finite values (no NaN or Infinities)"
|
||||
)
|
||||
REACTIVE_LIMIT = 1_000_000
|
||||
|
||||
@@ -50,3 +50,12 @@ class ScanpyFileError(Exception):
|
||||
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
|
||||
class DriverError(Exception):
|
||||
"""
|
||||
Raised when file loaded into scanpy is misformatted
|
||||
"""
|
||||
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
from functools import wraps
|
||||
|
||||
from flask import json
|
||||
from numpy import float32, integer
|
||||
|
||||
from server.app.util.errors import DriverError
|
||||
|
||||
|
||||
class Float32JSONEncoder(json.JSONEncoder):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -28,3 +32,12 @@ def custom_format_warning(msg, *args, **kwargs):
|
||||
|
||||
def jsonify_scanpy(data):
|
||||
return json.dumps(data, cls=Float32JSONEncoder, allow_nan=False)
|
||||
|
||||
|
||||
def requires_data(func):
|
||||
@wraps(func)
|
||||
def wrapped_function(self, *args, **kwargs):
|
||||
if self.data is None:
|
||||
raise DriverError(f"error data must be loaded before you call {func.__name__}")
|
||||
return func(self, *args, **kwargs)
|
||||
return wrapped_function
|
||||
|
||||
Reference in New Issue
Block a user