def analyse(events, subset=None, strata=None): if strata is None: bg = estimateBackground(events.data) else: bg = estimateBackgroundStratified(events.data, strata) return fdr.mutex(events[subset], bg[subset])
def pairwise_discover_test(x, g=None, alternative="less", correct=True): """ Perform many pairwise mutual exclusivity or co-occurrence tests. Parameters ---------- x : DiscoverMatrix g : array_like, optional An optional grouping vector for the rows of `x`. Pairs of rows within the same group are not tested. alternative : {'less', 'greater'}, optional If 'less', a mutual-exclusivity analysis is performed, if 'greater' a co-occurrence analysis. correct : bool, optional If True, multiple testing correction is performed. Returns ------- result : PairwiseDiscoverResult An object containing the test results for all pairwise combinations. """ assert alternative in ["less", "greater"] events = x.events bg = x.bg if g is None: pFlat, qFlat, pi0 = fdr.mutex(events, bg, alternative == "less") p = numpy.empty((x.shape[0], ) * 2) p[:] = numpy.nan p[numpy.triu_indices_from(p, 1)] = pFlat q = numpy.empty((x.shape[0], ) * 2) q[:] = numpy.nan q[numpy.triu_indices_from(p, 1)] = qFlat else: i = numpy.argsort(g) levels, inverse = numpy.unique(g, return_inverse=True) blockSizes = numpy.bincount(inverse) p, q, pi0 = fdr.analyseblockstructure(events[i], bg[i], alternative == "less", blockSizes) j = numpy.argsort(i) p = p[j[:, numpy.newaxis], j] q = q[j[:, numpy.newaxis], j] p = pandas.DataFrame(p, index=x.rownames, columns=x.rownames) q = pandas.DataFrame(q, index=x.rownames, columns=x.rownames) return PairwiseDiscoverResult(p, q, pi0, alternative)
def pairwise_discover_test(x, g=None, alternative="less", fdr_method="DBH"): """ Perform many pairwise mutual exclusivity or co-occurrence tests. Parameters ---------- x : DiscoverMatrix g : array_like, optional An optional grouping vector for the rows of `x`. Pairs of rows within the same group are not tested. alternative : {'less', 'greater'}, optional If 'less', a mutual-exclusivity analysis is performed, if 'greater' a co-occurrence analysis. fdr_method : {'DBH', 'BH'}, optional The false discovery rate procedure used for multiple testing correction. If 'DBH', a Benjamini-Hochberg procedure adapted for discrete test statistics is used. If 'BH', the standard Benjamini-Hochberg procedure is used. The latter is much faster, but also more conservative than the discrete version. Returns ------- result : PairwiseDiscoverResult An object containing the test results for all pairwise combinations. """ assert alternative in ["less", "greater"] assert fdr_method in ["DBH", "BH"] discrete_fdr = fdr_method == "DBH" events = x.events bg = x.bg if g is None: pFlat, qFlat, pi0 = fdr.mutex(events, bg, alternative == "less", discrete_fdr) if fdr_method == "BH": qFlat = false_discovery_rate(pFlat) pi0 = 1.0 p = numpy.empty((x.shape[0], ) * 2) p[:] = numpy.nan p[numpy.triu_indices_from(p, 1)] = pFlat q = numpy.empty((x.shape[0], ) * 2) q[:] = numpy.nan q[numpy.triu_indices_from(p, 1)] = qFlat else: i = numpy.argsort(g) levels, inverse = numpy.unique(g, return_inverse=True) blockSizes = numpy.bincount(inverse) p, q, pi0 = fdr.analyseblockstructure(events[i], bg[i], alternative == "less", blockSizes, discrete_fdr) if fdr_method == "BH": q = false_discovery_rate(p) pi0 = 1.0 j = numpy.argsort(i) p = p[j[:, numpy.newaxis], j] q = q[j[:, numpy.newaxis], j] p = pandas.DataFrame(p, index=x.rownames, columns=x.rownames) q = pandas.DataFrame(q, index=x.rownames, columns=x.rownames) return PairwiseDiscoverResult(p, q, pi0, alternative, fdr_method)