Skip to content

Commit 7e47156

Browse files
Merge pull request #76 from theislab/dev
Merge dev into master v0.5.0
2 parents 697f8e0 + c376527 commit 7e47156

23 files changed

+2548
-579
lines changed

diffxpy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
21
from ._version import get_versions
2+
33
__version__ = get_versions()['version']
44
del get_versions
5+
6+
from .log_cfg import logger, unconfigure_logging, enable_logging

diffxpy/api/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from .. import __version__
2+
from ..log_cfg import logger, unconfigure_logging, enable_logging
3+
14
from . import test
25
from . import enrich
36
from . import stats
4-
5-
from .. import __version__
7+
from . import utils

diffxpy/api/enrich.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from ..enrichment.enrich import RefSets
2-
from ..enrichment.enrich import test
1+
from diffxpy.enrichment.enrich import RefSets
2+
from diffxpy.enrichment.enrich import test

diffxpy/api/stats.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from ..stats.stats import hypergeom_test
2-
from ..stats.stats import likelihood_ratio_test
3-
from ..stats.stats import wald_test
4-
from ..stats.stats import wald_test_chisq
5-
from ..stats.stats import two_coef_z_test
6-
from ..stats.stats import wilcoxon_test
7-
from ..stats.stats import t_test_moments
8-
from ..stats.stats import t_test_raw
1+
from diffxpy.stats.stats import hypergeom_test
2+
from diffxpy.stats.stats import likelihood_ratio_test
3+
from diffxpy.stats.stats import wald_test
4+
from diffxpy.stats.stats import wald_test_chisq
5+
from diffxpy.stats.stats import two_coef_z_test
6+
from diffxpy.stats.stats import wilcoxon_test
7+
from diffxpy.stats.stats import t_test_moments
8+
from diffxpy.stats.stats import t_test_raw
9+
10+
from ..testing.correction import correct

diffxpy/api/test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# from ..testing.base import stats
2-
from ..testing.base import two_sample
3-
from ..testing.base import lrt
4-
from ..testing.base import wald
5-
from ..testing.base import t_test
6-
from ..testing.base import wilcoxon
7-
from ..testing.base import partition
8-
from ..testing.base import pairwise
9-
from ..testing.base import versus_rest
10-
from ..testing.base import design_matrix
11-
from ..testing.base import coef_names
1+
from diffxpy.testing.base import two_sample
2+
from diffxpy.testing.base import lrt
3+
from diffxpy.testing.base import wald
4+
from diffxpy.testing.base import t_test
5+
from diffxpy.testing.base import wilcoxon
6+
from diffxpy.testing.base import partition
7+
from diffxpy.testing.base import pairwise
8+
from diffxpy.testing.base import versus_rest
9+
from diffxpy.testing.base import continuous_1d
10+
from diffxpy.testing.base import design_matrix
11+
from diffxpy.testing.base import coef_names

diffxpy/api/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import batchglm.data as data_utils

diffxpy/log_cfg.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
3+
import logging
4+
5+
logger = logging.getLogger('.'.join(__name__.split('.')[:-1]))
6+
7+
_is_interactive = bool(getattr(sys, 'ps1', sys.flags.interactive))
8+
_hander = None
9+
10+
11+
def unconfigure_logging():
12+
if _hander is not None:
13+
logger.removeHandler(_hander)
14+
15+
logger.setLevel(logging.NOTSET)
16+
17+
18+
def enable_logging(verbosity=logging.ERROR, stream=sys.stderr, format=logging.BASIC_FORMAT):
19+
unconfigure_logging()
20+
21+
logger.setLevel(verbosity)
22+
_handler = logging.StreamHandler(stream)
23+
_handler.setFormatter(logging.Formatter(format, None))
24+
logger.addHandler(_handler)
25+
26+
27+
# If we are in an interactive environment (like Jupyter), set loglevel to INFO and pipe the output to stdout.
28+
if _is_interactive:
29+
enable_logging(logging.INFO, sys.stdout)
30+
else:
31+
enable_logging(logging.WARNING, sys.stderr)

diffxpy/pkg_constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BATCHGLM_OPTIM_GD = True
2+
BATCHGLM_OPTIM_ADAM = True
3+
BATCHGLM_OPTIM_ADAGRAD = False
4+
BATCHGLM_OPTIM_RMSPROP = False
5+
BATCHGLM_OPTIM_NEWTON = True
6+
BATCHGLM_OPTIM_IRLS = True
7+
BATCHGLM_TERMINATION_TYPE = "by_feature"

diffxpy/stats/stats.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import numpy.linalg
23
import scipy.stats
34
from typing import Union
45

@@ -218,7 +219,7 @@ def wald_test(
218219

219220
def wald_test_chisq(
220221
theta_mle: np.ndarray,
221-
theta_invcovar: np.ndarray,
222+
theta_covar: np.ndarray,
222223
theta0: Union[int, np.ndarray] = 0
223224
):
224225
"""
@@ -236,8 +237,8 @@ def wald_test_chisq(
236237
237238
:param theta_mle: np.array (par x genes)
238239
Maximum likelihood estimator of given parameter by gene.
239-
:param theta_invcovar: np.array (genes x par x par)
240-
Inverse of the covariance matrix of the parameters in theta_mle by gene.
240+
:param theta_covar: np.array (genes x par x par)
241+
Covariance matrix of the parameters in theta_mle by gene.
241242
This is the negative hessian or the inverse of the
242243
observed fisher information matrix.
243244
:param theta0: float
@@ -246,13 +247,13 @@ def wald_test_chisq(
246247
if np.size(theta0) == 1:
247248
theta0 = np.broadcast_to(theta0, theta_mle.shape)
248249

249-
if theta_mle.shape[0] != theta_invcovar.shape[1]:
250+
if theta_mle.shape[0] != theta_covar.shape[1]:
250251
raise ValueError(
251-
'stats.wald_test(): theta_mle and theta_invcovar have to contain the same number of parameters')
252-
if theta_mle.shape[1] != theta_invcovar.shape[0]:
253-
raise ValueError('stats.wald_test(): theta_mle and theta_invcovar have to contain the same number of genes')
254-
if theta_invcovar.shape[1] != theta_invcovar.shape[2]:
255-
raise ValueError('stats.wald_test(): the first two dimensions of theta_invcovar have to be of the same size')
252+
'stats.wald_test(): theta_mle and theta_covar have to contain the same number of parameters')
253+
if theta_mle.shape[1] != theta_covar.shape[0]:
254+
raise ValueError('stats.wald_test(): theta_mle and theta_covar have to contain the same number of genes')
255+
if theta_covar.shape[1] != theta_covar.shape[2]:
256+
raise ValueError('stats.wald_test(): the first two dimensions of theta_covar have to be of the same size')
256257
if theta0.shape[0] > 1:
257258
if theta_mle.shape[0] != theta0.shape[0]:
258259
raise ValueError('stats.wald_test(): theta_mle and theta0 have to contain the same number of entries')
@@ -264,7 +265,7 @@ def wald_test_chisq(
264265
np.matmul(
265266
np.matmul(
266267
theta_diff[:, [i]].T,
267-
theta_invcovar[i, :, :]
268+
numpy.linalg.inv(theta_covar[i, :, :])
268269
),
269270
theta_diff[:, [i]]
270271
)

0 commit comments

Comments
 (0)