mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-02 12:48:11 +08:00
Add user-generated annotations tests to the server (#1164)
* Add user-generated annotations tests to the server Partially completes https://github.com/chanzuckerberg/cellxgene/issues/969 * Auto-format python code * @skip_if: passing lambdas > than property strings * Respond to feedback from @bkmartinjr
This commit is contained in:
@@ -42,7 +42,7 @@ class Annotations(metaclass=ABCMeta):
|
||||
raise OntologyLoadFailure(f"Unable to find OBO ontology path: {path}") from e
|
||||
|
||||
except SyntaxError as e:
|
||||
msg = ''.join(traceback.format_exception_only(SyntaxError, e))
|
||||
msg = "".join(traceback.format_exception_only(SyntaxError, e))
|
||||
raise OntologyLoadFailure(msg) from e
|
||||
|
||||
except Exception as e:
|
||||
|
||||
+17
-13
@@ -13,16 +13,12 @@ class AppFeature(object):
|
||||
setattr(self, k, v)
|
||||
|
||||
def todict(self):
|
||||
d = dict(
|
||||
available=self.available,
|
||||
method=self.method,
|
||||
path=self.path)
|
||||
d = dict(available=self.available, method=self.method, path=self.path)
|
||||
d.update(self.extra)
|
||||
return d
|
||||
|
||||
|
||||
class AppConfig(object):
|
||||
|
||||
def __init__(self, **kw):
|
||||
super().__init__()
|
||||
|
||||
@@ -47,10 +43,20 @@ class AppConfig(object):
|
||||
# parameters
|
||||
self.diffexp_may_be_slow = False
|
||||
|
||||
inputs = ["datapath", "dataroot", "title", "about", "scripts", "layout",
|
||||
"max_category_items", "diffexp_lfc_cutoff",
|
||||
"obs_names", "var_names",
|
||||
"anndata_backed", "disable_diffexp"]
|
||||
inputs = [
|
||||
"datapath",
|
||||
"dataroot",
|
||||
"title",
|
||||
"about",
|
||||
"scripts",
|
||||
"layout",
|
||||
"max_category_items",
|
||||
"diffexp_lfc_cutoff",
|
||||
"obs_names",
|
||||
"var_names",
|
||||
"anndata_backed",
|
||||
"disable_diffexp",
|
||||
]
|
||||
|
||||
self.update(inputs, kw)
|
||||
|
||||
@@ -80,9 +86,7 @@ class AppConfig(object):
|
||||
title = self.get_title(data_adaptor)
|
||||
about = self.get_about(data_adaptor)
|
||||
|
||||
display_names = dict(
|
||||
engine=data_adaptor.get_name(),
|
||||
dataset=title)
|
||||
display_names = dict(engine=data_adaptor.get_name(), dataset=title)
|
||||
|
||||
# library_versions
|
||||
library_versions = {}
|
||||
@@ -90,7 +94,7 @@ class AppConfig(object):
|
||||
library_versions["cellxgene"] = cellxgene_version
|
||||
|
||||
# links
|
||||
links = {"about-dataset" : about}
|
||||
links = {"about-dataset": about}
|
||||
|
||||
# parameters
|
||||
parameters = {
|
||||
|
||||
@@ -84,7 +84,7 @@ class DataLocator:
|
||||
# and clean it up when done. If the path has a suffix/extension,
|
||||
# do our best to create a file with the same.
|
||||
ext = os.path.splitext(self.path)
|
||||
suffix = None if ext[1] == '' else ext[1]
|
||||
suffix = None if ext[1] == "" else ext[1]
|
||||
with self.open() as src, tempfile.NamedTemporaryFile(prefix="cellxgene_", suffix=suffix, delete=False) as tmp:
|
||||
tmp.write(src.read())
|
||||
tmp.close()
|
||||
|
||||
@@ -2,6 +2,7 @@ class FilterError(Exception):
|
||||
"""
|
||||
Raised when filter is malformed
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -9,6 +10,7 @@ class JSONEncodingValueError(Exception):
|
||||
"""
|
||||
Raised when data cannot be encoded into json
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -16,6 +18,7 @@ class MimeTypeError(Exception):
|
||||
"""
|
||||
Raised when incompatible MIME type selected
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -23,6 +26,7 @@ class PrepareError(Exception):
|
||||
"""
|
||||
Raised when data is misprepared
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -30,6 +34,7 @@ class DatasetAccessError(Exception):
|
||||
"""
|
||||
Raised when file loaded into a DataAdaptor is misformatted
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -37,6 +42,7 @@ class DisabledFeatureError(Exception):
|
||||
"""
|
||||
Raised when an attempt to use a disabled feature occurs
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -44,6 +50,7 @@ class AnnotationsError(Exception):
|
||||
"""
|
||||
Raised when an attempt to use the annotations feature fails
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -51,4 +58,5 @@ class OntologyLoadFailure(Exception):
|
||||
"""
|
||||
Raised when reading the ontology file fails
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
@@ -29,9 +29,7 @@ def schema_get_helper(data_adaptor, annotations):
|
||||
|
||||
def schema_get(data_adaptor, annotations):
|
||||
schema = schema_get_helper(data_adaptor, annotations)
|
||||
return make_response(
|
||||
jsonify({"schema": schema}), HTTPStatus.OK
|
||||
)
|
||||
return make_response(jsonify({"schema": schema}), HTTPStatus.OK)
|
||||
|
||||
|
||||
def config_get(app_config, data_adaptor, annotations):
|
||||
|
||||
@@ -92,20 +92,18 @@ def jsonify_numpy(data):
|
||||
def dtype_to_schema(dtype):
|
||||
schema = {}
|
||||
if dtype == np.float32:
|
||||
schema['type'] = 'float32'
|
||||
schema["type"] = "float32"
|
||||
elif dtype == np.int32:
|
||||
schema['type'] = 'int32'
|
||||
schema["type"] = "int32"
|
||||
elif dtype == np.bool_:
|
||||
schema['type'] = 'boolean'
|
||||
schema["type"] = "boolean"
|
||||
elif dtype == np.str:
|
||||
schema['type'] = 'string'
|
||||
schema["type"] = "string"
|
||||
elif dtype == "category":
|
||||
schema["type"] = "categorical"
|
||||
schema["categories"] = dtype.categories.tolist()
|
||||
else:
|
||||
raise TypeError(
|
||||
f"Annotations of type {dtype} are unsupported."
|
||||
)
|
||||
raise TypeError(f"Annotations of type {dtype} are unsupported.")
|
||||
return schema
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user