From ca27acdd39ecdca5653938a38c6e12e10f3647e2 Mon Sep 17 00:00:00 2001 From: "david.seb.fischer" Date: Thu, 28 Mar 2019 14:06:06 +0100 Subject: [PATCH] fixed some unit tests --- diffxpy/unit_test/test_continuous.py | 2 +- diffxpy/unit_test/test_numeric.py | 2 -- diffxpy/unit_test/test_pairwise.py | 23 +++++++++++-------- .../test_single_training_strategies.py | 16 ------------- 4 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 diffxpy/unit_test/test_single_training_strategies.py diff --git a/diffxpy/unit_test/test_continuous.py b/diffxpy/unit_test/test_continuous.py index 7079b6e..642ece4 100644 --- a/diffxpy/unit_test/test_continuous.py +++ b/diffxpy/unit_test/test_continuous.py @@ -80,7 +80,7 @@ def test_null_distribution_wald(self, n_cells: int = 2000, n_genes: int = 100): :param n_cells: Number of cells to simulate (number of observations per test). :param n_genes: Number of genes to simulate (number of tests). """ - logging.getLogger("tensorflow").setLevel(logging.INFO) + logging.getLogger("tensorflow").setLevel(logging.ERROR) logging.getLogger("batchglm").setLevel(logging.WARNING) logging.getLogger("diffxpy").setLevel(logging.WARNING) diff --git a/diffxpy/unit_test/test_numeric.py b/diffxpy/unit_test/test_numeric.py index 9675637..05e53b6 100644 --- a/diffxpy/unit_test/test_numeric.py +++ b/diffxpy/unit_test/test_numeric.py @@ -1,8 +1,6 @@ import unittest import numpy as np -import pandas as pd -import scipy.stats as stats import logging from batchglm.api.models.glm_nb import Simulator diff --git a/diffxpy/unit_test/test_pairwise.py b/diffxpy/unit_test/test_pairwise.py index 45a0701..5e373fb 100644 --- a/diffxpy/unit_test/test_pairwise.py +++ b/diffxpy/unit_test/test_pairwise.py @@ -4,7 +4,7 @@ import pandas as pd import scipy.stats as stats -from batchglm.api.models.glm_nb import Simulator, Estimator, InputData +from batchglm.api.models.glm_nb import Simulator import diffxpy.api as de @@ -247,18 +247,21 @@ def test_ztest_de(self, n_cells: int = 2000, n_genes: int = 500): ) summary = test.summary() + frac_nonde_sig = np.mean( + np.sum(test.qval[~np.eye(test.pval.shape[0]).astype(bool), :num_non_de] < 0.05) / + (2 * num_non_de) + ) + frac_de_sig = np.mean( + np.sum(test.qval[~np.eye(test.pval.shape[0]).astype(bool), num_non_de:] < 0.05) / + (2 * (n_genes - num_non_de)) + ) logging.getLogger("diffxpy").info('fraction of non-DE genes with q-value < 0.05: %.1f%%' % - float(100 * np.mean( - np.sum(test.qval[~np.eye(test.pval.shape[0]).astype(bool), :num_non_de] < 0.05) / - (2 * num_non_de) - ))) + str(np.round(100. * frac_nonde_sig, 3))) logging.getLogger("diffxpy").info('fraction of DE genes with q-value < 0.05: %.1f%%' % - float(100 * np.mean( - np.sum(test.qval[~np.eye(test.pval.shape[0]).astype(bool), num_non_de:] < 0.05) / - (2 * (n_genes - num_non_de)) - ))) + str(np.round(100. * frac_de_sig, 3))) - # TODO asserts + assert frac_de_sig > 0.5, "too many DE" + assert frac_nonde_sig < 0.5, "too many non-DE" return True diff --git a/diffxpy/unit_test/test_single_training_strategies.py b/diffxpy/unit_test/test_single_training_strategies.py deleted file mode 100644 index 0e4badb..0000000 --- a/diffxpy/unit_test/test_single_training_strategies.py +++ /dev/null @@ -1,16 +0,0 @@ -import unittest -import numpy as np -import pandas as pd -import scipy.stats as stats -import logging - -from batchglm.api.models.glm_nb import Simulator, Estimator, InputData -import diffxpy.api as de - - - -class TestSingleFeaturewiseTermination(unittest.TestCase): - pass - -if __name__ == '__main__': - unittest.main()