mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-02 10:58:11 +08:00
remove --nan-to-num CLI parameter (#548)
* remove --nan-to-num CLI parameter * factor tests better * lint - remove unused variables
This commit is contained in:
@@ -49,48 +49,3 @@ class WithNaNs(unittest.TestCase):
|
||||
url = f"{URL_BASE}{endpoint}"
|
||||
result = self.session.get(url)
|
||||
self.assertEqual(result.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
|
||||
|
||||
|
||||
class WithoutNaNs(unittest.TestCase):
|
||||
"""Test Case for endpoints"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.ps = Popen(
|
||||
[
|
||||
"cellxgene",
|
||||
"launch",
|
||||
"server/test/test_datasets/nan.h5ad",
|
||||
"--nan-to-num",
|
||||
"--debug",
|
||||
]
|
||||
)
|
||||
session = requests.Session()
|
||||
for i in range(90):
|
||||
try:
|
||||
session.get(f"{URL_BASE}schema")
|
||||
except requests.exceptions.ConnectionError:
|
||||
time.sleep(1)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
try:
|
||||
cls.ps.terminate()
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
|
||||
def setUp(self):
|
||||
self.session = requests.Session()
|
||||
|
||||
def test_initialize(self):
|
||||
endpoint = "schema"
|
||||
url = f"{URL_BASE}{endpoint}"
|
||||
result = self.session.get(url)
|
||||
self.assertEqual(result.status_code, HTTPStatus.OK)
|
||||
|
||||
def test_errors(self):
|
||||
endpoints = ["annotations/obs", "annotations/var", "data/obs", "data/var"]
|
||||
for endpoint in endpoints:
|
||||
url = f"{URL_BASE}{endpoint}"
|
||||
result = self.session.get(url)
|
||||
self.assertEqual(result.status_code, HTTPStatus.OK)
|
||||
|
||||
@@ -2,6 +2,9 @@ import json
|
||||
import pytest
|
||||
import unittest
|
||||
import warnings
|
||||
import math
|
||||
|
||||
import decode_fbs
|
||||
|
||||
from server.app.scanpy_engine.scanpy_engine import ScanpyEngine
|
||||
from server.app.util.errors import JSONEncodingValueError
|
||||
@@ -16,24 +19,15 @@ class NaNTest(unittest.TestCase):
|
||||
"obs_names": None,
|
||||
"var_names": None,
|
||||
"diffexp_lfc_cutoff": 0.01,
|
||||
"nan_to_num": False,
|
||||
}
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", category=UserWarning)
|
||||
self.data = ScanpyEngine("server/test/test_datasets/nan.h5ad", self.args)
|
||||
self.data._create_schema()
|
||||
self.args_nan = dict(self.args)
|
||||
self.args_nan["nan_to_num"] = True
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", category=UserWarning)
|
||||
self.data_nan = ScanpyEngine(
|
||||
"server/test/test_datasets/nan.h5ad", self.args_nan
|
||||
)
|
||||
self.data_nan._create_schema()
|
||||
|
||||
def test_load(self):
|
||||
with self.assertWarns(UserWarning):
|
||||
ScanpyEngine("server/test/test_datasets/nan.h5ad", self.args_nan)
|
||||
ScanpyEngine("server/test/test_datasets/nan.h5ad", self.args)
|
||||
|
||||
def test_init(self):
|
||||
self.assertEqual(self.data.cell_count, 100)
|
||||
@@ -41,45 +35,38 @@ class NaNTest(unittest.TestCase):
|
||||
epsilon = 0.000_005
|
||||
self.assertTrue(self.data.data.X[0, 0] - -0.171_469_51 < epsilon)
|
||||
|
||||
self.assertEqual(self.data_nan.cell_count, 100)
|
||||
self.assertEqual(self.data_nan.gene_count, 100)
|
||||
epsilon = 0.000_005
|
||||
self.assertTrue(self.data_nan.data.X[0, 0] - -0.171_469_51 < epsilon)
|
||||
|
||||
def test_dataframe(self):
|
||||
data_frame_obs = json.loads(self.data_nan.data_frame(None, "obs"))
|
||||
self.assertEqual(len(data_frame_obs["var"]), 100)
|
||||
self.assertEqual(len(data_frame_obs["obs"]), 100)
|
||||
data_frame_var = json.loads(self.data_nan.data_frame(None, "var"))
|
||||
self.assertEqual(len(data_frame_var["var"]), 100)
|
||||
self.assertEqual(len(data_frame_var["obs"]), 100)
|
||||
with pytest.raises(JSONEncodingValueError):
|
||||
data_frame_obs = json.loads(self.data.data_frame(None, "obs"))
|
||||
with pytest.raises(JSONEncodingValueError):
|
||||
data_frame_var = json.loads(self.data.data_frame(None, "var"))
|
||||
data_frame_var = decode_fbs.decode_matrix_FBS(self.data.data_frame_to_fbs_matrix(None, "var"))
|
||||
self.assertIsNotNone(data_frame_var)
|
||||
self.assertEqual(data_frame_var["n_rows"], 100)
|
||||
self.assertEqual(data_frame_var["n_cols"], 100)
|
||||
self.assertTrue(math.isnan(data_frame_var["columns"][3][3]))
|
||||
|
||||
def test_dataframe_nan_to_0(self):
|
||||
data_frame_obs = json.loads(self.data_nan.data_frame(None, "obs"))
|
||||
self.assertEqual(data_frame_obs["obs"][1][3], 0.0)
|
||||
data_frame_var = json.loads(self.data_nan.data_frame(None, "var"))
|
||||
self.assertEqual(data_frame_var["var"][1][5], 0.0)
|
||||
with pytest.raises(JSONEncodingValueError):
|
||||
json.loads(self.data.data_frame(None, "obs"))
|
||||
with pytest.raises(JSONEncodingValueError):
|
||||
json.loads(self.data.data_frame(None, "var"))
|
||||
|
||||
def test_annotation_nan_to_0(self):
|
||||
annotations_obs = json.loads(self.data_nan.annotation(None, "obs"))
|
||||
self.assertEqual(annotations_obs["data"][0][3], 0.0)
|
||||
annotations_var = json.loads(self.data_nan.annotation(None, "var"))
|
||||
self.assertEqual(annotations_var["data"][0][3], 0.0)
|
||||
def test_dataframe_obs_not_implemented(self):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
decode_fbs.decode_matrix_FBS(self.data.data_frame_to_fbs_matrix(None, "obs"))
|
||||
self.assertIsNotNone(cm.exception)
|
||||
|
||||
def test_annotation(self):
|
||||
annotations = json.loads(self.data_nan.annotation(None, "obs"))
|
||||
annotations = decode_fbs.decode_matrix_FBS(self.data.annotation_to_fbs_matrix("obs"))
|
||||
self.assertEqual(
|
||||
annotations["names"],
|
||||
["name", "n_genes", "percent_mito", "n_counts", "louvain"],
|
||||
annotations["col_idx"],
|
||||
["name", "n_genes", "percent_mito", "n_counts", "louvain"]
|
||||
)
|
||||
annotations = json.loads(self.data_nan.annotation(None, "var"))
|
||||
self.assertEqual(annotations["names"], ["name", "n_cells", "var_with_nans"])
|
||||
self.assertEqual(len(annotations["data"]), 100)
|
||||
self.assertEqual(annotations["n_rows"], 100)
|
||||
self.assertTrue(math.isnan(annotations["columns"][2][0]))
|
||||
|
||||
annotations = decode_fbs.decode_matrix_FBS(self.data.annotation_to_fbs_matrix("var"))
|
||||
self.assertEqual(annotations["col_idx"], ["name", "n_cells", "var_with_nans"])
|
||||
self.assertEqual(annotations["n_rows"], 100)
|
||||
self.assertTrue(math.isnan(annotations["columns"][2][0]))
|
||||
|
||||
with pytest.raises(JSONEncodingValueError):
|
||||
annotations = json.loads(self.data.annotation(None, "obs"))
|
||||
json.loads(self.data.annotation(None, "obs"))
|
||||
with pytest.raises(JSONEncodingValueError):
|
||||
annotations = json.loads(self.data.annotation(None, "var"))
|
||||
json.loads(self.data.annotation(None, "var"))
|
||||
|
||||
@@ -19,7 +19,6 @@ class UtilTest(unittest.TestCase):
|
||||
"obs_names": None,
|
||||
"var_names": None,
|
||||
"diffexp_lfc_cutoff": 0.01,
|
||||
"nan_to_num": True,
|
||||
}
|
||||
|
||||
self.data = ScanpyEngine("example-dataset/pbmc3k.h5ad", args)
|
||||
|
||||
Reference in New Issue
Block a user