mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-17 05:47:58 +08:00
* Scanpy engine now required Without the --engine param we need to error if scanpy engine cannot be imported rather than waiting for all engines * CLI options and help matches proposal (but not all options hooked up yet) * Flesh out top level args * Move computation args to engine * CLI input file (#374) * Fix test command (tests still won't work) * Input is file instead of directory - also renamed example file * Csweaver/debug (#376) * Respect debug flag for logging flask calls * Add loading messages * max categories (#377) * Add max categories * Rename max_categories to category_selection_limit * ensure whole numbers
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
import json
|
|
from argparse import ArgumentTypeError
|
|
|
|
from numpy import float32, integer
|
|
|
|
|
|
class Float32JSONEncoder(json.JSONEncoder):
|
|
def default(self, obj):
|
|
if isinstance(obj, float32):
|
|
return float(obj)
|
|
elif isinstance(obj, integer):
|
|
return int(obj)
|
|
return json.JSONEncoder.default(self, obj)
|
|
|
|
|
|
class MimeTypeError(Exception):
|
|
|
|
def __init__(self, message):
|
|
self.message = message
|
|
|
|
|
|
class FilterError(Exception):
|
|
|
|
def __init__(self, message):
|
|
self.message = message
|
|
|
|
|
|
class InteractiveError(Exception):
|
|
|
|
def __init__(self, message):
|
|
self.message = message
|
|
|
|
|
|
class PrepareError(Exception):
|
|
|
|
def __init__(self, message):
|
|
self.message = message
|
|
|
|
|
|
def get_mime_type(default="application/json", acceptable_types=["application/json", "text/csv"], query_param=None,
|
|
header=None):
|
|
mime_type = default
|
|
if query_param:
|
|
if query_param in acceptable_types:
|
|
mime_type = query_param
|
|
else:
|
|
raise MimeTypeError(f"Unsupported mime type {query_param} specified in query parameter 'accept-type'")
|
|
elif len(header):
|
|
mime_type = header.best_match(acceptable_types)
|
|
if not mime_type:
|
|
raise MimeTypeError(f"Unsupported mime type(s) {header} in HTTP Accept header")
|
|
return mime_type
|
|
|
|
|
|
def whole_number(value):
|
|
try:
|
|
value = int(value)
|
|
except ValueError as e:
|
|
raise ArgumentTypeError(f"{value} is not type int") from e
|
|
if value < 0:
|
|
raise ArgumentTypeError(f"{value} is not >= 0")
|
|
return value
|