mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-05 07:28:12 +08:00
Fix various bugs with CXG format at annotations (#1173)
- Enable testing for this path - Fixes #1166 - Fixes #1167 - Fixes #1168
This commit is contained in:
@@ -213,6 +213,8 @@ class DataAdaptor(metaclass=ABCMeta):
|
|||||||
return
|
return
|
||||||
|
|
||||||
labels_df.index = self.get_obs_index()
|
labels_df.index = self.get_obs_index()
|
||||||
|
if labels_df.index.name is None:
|
||||||
|
labels_df.index.name = "index"
|
||||||
|
|
||||||
# all labels must have a name, which must be unique and not used in obs column names
|
# all labels must have a name, which must be unique and not used in obs column names
|
||||||
if not labels_df.columns.is_unique:
|
if not labels_df.columns.is_unique:
|
||||||
|
|||||||
@@ -292,19 +292,17 @@ class CxgAdaptor(DataAdaptor):
|
|||||||
def annotation_to_fbs_matrix(self, axis, fields=None, labels=None):
|
def annotation_to_fbs_matrix(self, axis, fields=None, labels=None):
|
||||||
with ServerTiming.time(f"annotations.{axis}.query"):
|
with ServerTiming.time(f"annotations.{axis}.query"):
|
||||||
A = self.open_array(str(axis))
|
A = self.open_array(str(axis))
|
||||||
if fields is not None and len(fields) > 0:
|
if axis == Axis.OBS:
|
||||||
try:
|
if labels is not None and not labels.empty:
|
||||||
df = pd.DataFrame(A.query(attrs=fields)[:])
|
df = pd.DataFrame.from_dict(A[:])
|
||||||
except tiledb.libtiledb.TileDBError:
|
df = df.join(labels, self.get_obs_names())
|
||||||
raise KeyError("bad field {fields}")
|
else:
|
||||||
|
df = pd.DataFrame.from_dict(A[:])
|
||||||
else:
|
else:
|
||||||
df = pd.DataFrame.from_dict(A[:])
|
df = pd.DataFrame.from_dict(A[:])
|
||||||
|
|
||||||
if axis == Axis.OBS:
|
if fields is not None and len(fields) > 0:
|
||||||
if labels is not None and not labels.empty:
|
df = df[fields]
|
||||||
obs_names = self.get_obs_names()
|
|
||||||
df = df.join(labels, obs_names)
|
|
||||||
|
|
||||||
with ServerTiming.time(f"annotations.{axis}.encode"):
|
with ServerTiming.time(f"annotations.{axis}.encode"):
|
||||||
fbs = encode_matrix_fbs(df, col_idx=df.columns)
|
fbs = encode_matrix_fbs(df, col_idx=df.columns)
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import pandas as pd
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
import server.test.decode_fbs as decode_fbs
|
import server.test.decode_fbs as decode_fbs
|
||||||
from server.test import skip_if, data_with_tmp_annotations, make_fbs
|
from server.test import data_with_tmp_annotations, make_fbs
|
||||||
from server.data_common.matrix_loader import MatrixDataType
|
from server.data_common.matrix_loader import MatrixDataType
|
||||||
|
|
||||||
BAD_FILTER = {"filter": {"obs": {"annotation_value": [{"name": "xyz"}]}}}
|
BAD_FILTER = {"filter": {"obs": {"annotation_value": [{"name": "xyz"}]}}}
|
||||||
|
|
||||||
# TODO (mweiden): remove ANNOTATIONS_ENABLED and Annotation subclasses when annotations are no longer experimental
|
# TODO (mweiden): remove ANNOTATIONS_ENABLED and Annotation subclasses when annotations are no longer experimental
|
||||||
# TODO (mweiden): remove MATRIX_DATA_TYPE and skip_if when user annotations for the CXG format is complete
|
|
||||||
|
|
||||||
|
|
||||||
class EndPoints(object):
|
class EndPoints(object):
|
||||||
@@ -91,10 +90,6 @@ class EndPoints(object):
|
|||||||
+ (["cluster-test"] if self.ANNOTATIONS_ENABLED else []),
|
+ (["cluster-test"] if self.ANNOTATIONS_ENABLED else []),
|
||||||
)
|
)
|
||||||
|
|
||||||
@skip_if(
|
|
||||||
lambda slf: hasattr(slf, "MATRIX_DATA_TYPE") and slf.MATRIX_DATA_TYPE == MatrixDataType.CXG,
|
|
||||||
"CXG file annotations are not feature-complete!",
|
|
||||||
)
|
|
||||||
def test_get_annotations_obs_keys_fbs(self):
|
def test_get_annotations_obs_keys_fbs(self):
|
||||||
endpoint = "annotations/obs"
|
endpoint = "annotations/obs"
|
||||||
query = "annotation-name=n_genes&annotation-name=percent_mito"
|
query = "annotation-name=n_genes&annotation-name=percent_mito"
|
||||||
@@ -275,13 +270,11 @@ class EndPointsAnnotations(EndPoints):
|
|||||||
def test_get_schema_existing_writable(self):
|
def test_get_schema_existing_writable(self):
|
||||||
self._test_get_schema_writable("cluster-test")
|
self._test_get_schema_writable("cluster-test")
|
||||||
|
|
||||||
@skip_if(lambda slf: slf.MATRIX_DATA_TYPE == MatrixDataType.CXG, "CXG file annotations are not feature-complete!")
|
|
||||||
def test_get_user_annotations_existing_obs_keys_fbs(self):
|
def test_get_user_annotations_existing_obs_keys_fbs(self):
|
||||||
self._test_get_user_annotations_obs_keys_fbs(
|
self._test_get_user_annotations_obs_keys_fbs(
|
||||||
"cluster-test", {"unassigned", "one", "two", "three", "four", "five"},
|
"cluster-test", {"unassigned", "one", "two", "three", "four", "five"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@skip_if(lambda slf: slf.MATRIX_DATA_TYPE == MatrixDataType.CXG, "CXG file annotations are not feature-complete!")
|
|
||||||
def test_put_user_annotations_obs_fbs(self):
|
def test_put_user_annotations_obs_fbs(self):
|
||||||
endpoint = "annotations/obs"
|
endpoint = "annotations/obs"
|
||||||
query = "annotation-collection-name=test_annotations"
|
query = "annotation-collection-name=test_annotations"
|
||||||
|
|||||||
Reference in New Issue
Block a user