Return empty colors for .cxg v0.0 files (#1441)

* Return empty colors for .cxg v0.0 files

Fixes https://github.com/chanzuckerberg/cellxgene/issues/1440

The CxgAdaptor.get_colors method currently assumes that the .cxg file has
cxg_group_metadata. As a result, the /api/v0.2/colors endpoint always fails for
.cxg v0.0 files.

* Add test fixture
This commit is contained in:
Matt Weiden
2020-04-30 17:21:20 -07:00
committed by GitHub
parent 40fbc42b13
commit a17fff83cf
42 changed files with 11 additions and 5 deletions
+2
View File
@@ -195,6 +195,8 @@ class CxgAdaptor(DataAdaptor):
return diffexp_cxg.diffexp_ttest(self, maskA, maskB, top_n, lfc_cutoff)
def get_colors(self):
if self.cxg_version == "0.0":
return dict()
meta = self.open_array("cxg_group_metadata").meta
return json.loads(meta["cxg_category_colors"]) if "cxg_category_colors" in meta else dict()
+9 -5
View File
@@ -7,10 +7,14 @@ from server.test.test_datasets.fixtures import pbmc3k_colors
class TestCxgAdaptor(unittest.TestCase):
def setUp(self):
data_locator = f"{PROJECT_ROOT}/server/test/test_datasets/pbmc3k.cxg"
config = app_config(data_locator)
self.data = CxgAdaptor(DataLocator(data_locator), config)
def test_get_colors(self):
self.assertEqual(self.data.get_colors(), pbmc3k_colors)
data = self.get_data("pbmc3k.cxg")
self.assertDictEqual(data.get_colors(), pbmc3k_colors)
data = self.get_data("pbmc3k_v0.cxg")
self.assertDictEqual(data.get_colors(), dict())
def get_data(self, fixture):
data_locator = f"{PROJECT_ROOT}/server/test/test_datasets/{fixture}"
config = app_config(data_locator)
return CxgAdaptor(DataLocator(data_locator), config)