mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-15 12:47:56 +08:00
The default branch has been changed. This PR cleans up references to `master` and fixes links that would otherwise be broken. For more background see the following references: * https://www.independent.co.uk/life-style/gadgets-and-tech/news/github-master-slave-slavery-whitelist-language-inclusive-a9568576.html * https://tools.ietf.org/id/draft-knodel-terminology-00.html
82 lines
2.8 KiB
Python
82 lines
2.8 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(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 setUp(self):
|
|
self.args = {
|
|
"embeddings__names": ["umap"],
|
|
"presentation__max_categories": 100,
|
|
"single_dataset__obs_names": None,
|
|
"single_dataset__var_names": None,
|
|
"diffexp__lfc_cutoff": 0.01,
|
|
}
|
|
|
|
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 = AppConfig()
|
|
config.update(**self.args)
|
|
config.update(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 = AppConfig()
|
|
config.update(**self.args)
|
|
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 = AppConfig()
|
|
config.update(**self.args)
|
|
data = AnndataAdaptor(locator, config)
|
|
self.stdAsserts(data)
|