mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-21 03:48:12 +08:00
This will give us the ability to specify different config options for different dataroots. the key of the dataroot dictionary is no longer the same as the dataroot_url. Previously key==dataroot_url, and now those are separated. Added an "is_multi_dataset" function to simplify logic where it branched on single vs multi. Simplified the rest.py interface by no longer passing in the user annotations object, since that can be retrieved from the dataset.
83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
import unittest
|
|
import json
|
|
|
|
from server.data_anndata.anndata_adaptor import AnndataAdaptor
|
|
from server.common.data_locator import DataLocator
|
|
from server.common.app_config import AppConfig
|
|
from server.test import PROJECT_ROOT
|
|
|
|
|
|
class DataLoadAdaptorTest(unittest.TestCase):
|
|
"""
|
|
Test file loading, including deferred loading/update.
|
|
"""
|
|
|
|
def setUp(self):
|
|
self.data_file = DataLocator(f"{PROJECT_ROOT}/example-dataset/pbmc3k.h5ad")
|
|
config = AppConfig()
|
|
config.update_server_config(single_dataset__datapath=self.data_file.path)
|
|
config.complete_config()
|
|
self.data = AnndataAdaptor(self.data_file, config)
|
|
|
|
def test_delayed_load_data(self):
|
|
self.data._create_schema()
|
|
self.assertEqual(self.data.cell_count, 2638)
|
|
self.assertEqual(self.data.gene_count, 1838)
|
|
epsilon = 0.000_005
|
|
self.assertTrue(self.data.data.X[0, 0] - -0.171_469_51 < epsilon)
|
|
|
|
def test_diffexp_topN(self):
|
|
f1 = {"filter": {"obs": {"index": [[0, 500]]}}}
|
|
f2 = {"filter": {"obs": {"index": [[500, 1000]]}}}
|
|
result = json.loads(self.data.diffexp_topN(f1["filter"], f2["filter"]))
|
|
self.assertEqual(len(result), 10)
|
|
result = json.loads(self.data.diffexp_topN(f1["filter"], f2["filter"], 20))
|
|
self.assertEqual(len(result), 20)
|
|
|
|
|
|
class DataLocatorAdaptorTest(unittest.TestCase):
|
|
"""
|
|
Test various types of data locators we expect to consume
|
|
"""
|
|
|
|
def get_basic_config(self):
|
|
config = AppConfig()
|
|
config.update_server_config(
|
|
single_dataset__obs_names=None,
|
|
single_dataset__var_names=None,
|
|
)
|
|
config.update_default_dataset_config(
|
|
embeddings__names=["umap"],
|
|
presentation__max_categories=100,
|
|
diffexp__lfc_cutoff=0.01,
|
|
)
|
|
return config
|
|
|
|
def stdAsserts(self, data):
|
|
""" run these each time we load the data """
|
|
self.assertIsNotNone(data)
|
|
self.assertEqual(data.cell_count, 2638)
|
|
self.assertEqual(data.gene_count, 1838)
|
|
|
|
def test_posix_file(self):
|
|
locator = DataLocator("../example-dataset/pbmc3k.h5ad")
|
|
config = self.get_basic_config()
|
|
config.update_server_config(single_dataset__datapath=locator.path)
|
|
config.complete_config()
|
|
data = AnndataAdaptor(locator, config)
|
|
self.stdAsserts(data)
|
|
|
|
def test_url_https(self):
|
|
url = "https://raw.githubusercontent.com/chanzuckerberg/cellxgene/main/example-dataset/pbmc3k.h5ad"
|
|
locator = DataLocator(url)
|
|
config = self.get_basic_config()
|
|
data = AnndataAdaptor(locator, config)
|
|
self.stdAsserts(data)
|
|
|
|
def test_url_http(self):
|
|
url = "http://raw.githubusercontent.com/chanzuckerberg/cellxgene/main/example-dataset/pbmc3k.h5ad"
|
|
locator = DataLocator(url)
|
|
config = self.get_basic_config()
|
|
data = AnndataAdaptor(locator, config)
|
|
self.stdAsserts(data)
|