Skip to content

Commit dbb1c3e

Browse files
committed
Project import generated by Copybara.
GitOrigin-RevId: 2f667fe27fbc2bc80379001010bf4fca9703b8b9
1 parent 2dab4ef commit dbb1c3e

31 files changed

Lines changed: 416 additions & 216 deletions

CHANGES.rst

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,48 @@ of the Python package would have features that do not exist in version
2121
0.9 series
2222
==========
2323

24-
:Latest Python version: 0.9.3 (June 18, 2019)
25-
:Latest R version: 0.9.3 (June 18, 2019)
24+
:Latest Python version: 0.9.4 (July 28, 2021)
25+
:Latest R version: 0.9.4 (July 28, 2021)
2626

2727

2828
Python package
2929
--------------
3030

31+
0.9.4 (July 28, 2021)
32+
~~~~~~~~~~~~~~~~~~~~~
33+
34+
**Added**:
35+
36+
- The new fdr_method argument of the pairwise_discover_test function
37+
selects the false discovery rate estimation method used for multiple
38+
testing correction. Its default value selects a Benjamini-Hochberg
39+
procedure adapted for discrete test statistics. As an alternative,
40+
the standard Benjamini-Hochberg procedure can be selected. While the
41+
latter is much faster, it is also more conservative than the
42+
discrete version. The discrete method was always used in previous
43+
versions and is still the recommended choice.
44+
45+
**Changed**:
46+
47+
- Speed improvements in DiscoverMatrix and
48+
pairwise_discover_test. DiscoverMatrix finishes instantaneously for
49+
small to medium-sized data sets and takes only a few seconds for
50+
very large data sets. pairwise_discover_test (with discrete
51+
Benjamini-Hochberg) is about twice as fast as in previous versions.
52+
53+
- Python 2.7 is no longer supported.
54+
55+
**Fixed**:
56+
57+
- If pandas >= 1.0 was installed, subsetting a DiscoverMatrix object
58+
gave rise to "AttributeError: 'DataFrame' objects has no attribute
59+
'ix'".
60+
61+
- Fixed the underlying Fortran code to make it compile with GNU
62+
Fortran >= 10. Due to these changes the minimum supported GNU
63+
Fortran version is now version 5.
64+
65+
3166
0.9.3 (June 18, 2019)
3267
~~~~~~~~~~~~~~~~~~~~~
3368

@@ -68,6 +103,41 @@ First public release
68103
R package
69104
---------
70105

106+
0.9.4 (July 28, 2021)
107+
~~~~~~~~~~~~~~~~~~~~~
108+
109+
**Added**:
110+
111+
- The new fdr.method argument of the pairwise.discover.test function
112+
selects the false discovery rate estimation method used for multiple
113+
testing correction. Its default value selects a Benjamini-Hochberg
114+
procedure adapted for discrete test statistics. As an alternative,
115+
the standard Benjamini-Hochberg procedure can be selected. While the
116+
latter is much faster, it is also more conservative than the
117+
discrete version. The discrete method was always used in previous
118+
versions and is still the recommended choice.
119+
120+
**Changed**:
121+
122+
- Speed improvements in discover.matrix and
123+
pairwise.discover.test. discover.matrix finishes instantaneously for
124+
small to medium-sized data sets and takes only a few seconds for
125+
very large data sets. pairwise.discover.test (with discrete
126+
Benjamini-Hochberg) is about twice as fast as in previous versions.
127+
128+
- The matrixStats package is no longer a dependency.
129+
130+
**Fixed**:
131+
132+
- Re-enabled OpenMP, which distributes the computations in
133+
pairwise.discover.test across multiple CPUs. OpenMP was disabled
134+
since R 4.0.
135+
136+
- Fixed the underlying Fortran code to make it compile with GNU
137+
Fortran >= 10. Due to these changes the minimum supported GNU
138+
Fortran version is now version 5.
139+
140+
71141
0.9.3 (June 18, 2019)
72142
~~~~~~~~~~~~~~~~~~~~~
73143

R/.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
^\.bumpversion\.cfg$

R/.bumpversion.cfg

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ commit = True
33
message = [R package] Bump version: {current_version} → {new_version}
44
tag = True
55
tag_name = r_v{new_version}
6-
current_version = 0.9.3
7-
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
6+
current_version = 0.9.4
7+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>release|9000))?
88
serialize =
99
{major}.{minor}.{patch}-{release}
1010
{major}.{minor}.{patch}
@@ -14,6 +14,5 @@ serialize =
1414
[bumpversion:part:release]
1515
optional_value = release
1616
values =
17-
dev
17+
9000
1818
release
19-

R/DESCRIPTION

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
Package: discover
2-
Version: 0.9.3
3-
Date: 2019-06-18
2+
Version: 0.9.4
3+
Date: 2021-07-27
44
Title: DISCOVER mutual exclusivity and co-occurrence analysis
55
Author: Sander Canisius
66
Maintainer: Sander Canisius <s.canisius@nki.nl>
7-
Description: DISCOVER method for mutual exclusivity detection in genomic data.
7+
Description: DISCOVER method for mutual exclusivity and co-occurrence detection in genomic data.
88
License: Apache License (== 2.0)
9-
Depends:
10-
matrixStats
119
RoxygenNote: 5.0.0
1210
VignetteBuilder: knitr
13-
Suggests: knitr
11+
Suggests: rmarkdown

R/R/analysis.R

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
#' Perform many pairwise mutual exclusivity or co-occurrence tests.
22
#'
33
#' @param x A \code{discover.matrix} object.
4-
#' @param g An optional grouping vector for the rows of \code{events}. Pairs of rows within the same group are not tested.
5-
#' @param alternative Either \code{"less"} for mutual-exclusivity analysis, or \code{"greater"} for co-occurrence analysis.
6-
#' @param correct If \code{TRUE}, multiple testing correction is performed.
4+
#' @param g An optional grouping vector for the rows of \code{events}. Pairs of rows
5+
#' within the same group are not tested.
6+
#' @param alternative Either \code{"less"} for mutual-exclusivity analysis, or
7+
#' \code{"greater"} for co-occurrence analysis.
8+
#' @param fdr.method The false discovery rate procedure used for multiple testing correction.
9+
#' If \code{"DBH"}, a Benjamini-Hochberg procedure adapted for discrete test statistics is
10+
#' used. If \code{"BH"}, the standard Benjamini-Hochberg procedure is used. The latter is
11+
#' much faster, but also more conservative than the discrete version.
712
#' @return An object of type \code{pairwise.discover.out}.
813
#'
914
#' @useDynLib discover
1015
#' @export
11-
pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"), correct=TRUE) {
16+
pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"), fdr.method=c("DBH", "BH")) {
1217
alternative <- match.arg(alternative)
18+
fdr.method <- match.arg(fdr.method)
19+
discrete.fdr <- fdr.method == "DBH"
1320

1421
events <- x$events
1522
bg <- x$bg
@@ -18,9 +25,16 @@ pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"),
1825
result <- .Fortran("mutex",
1926
as.integer(nrow(events)), as.integer(ncol(events)),
2027
as.integer(events), as.double(bg), as.integer(alternative == "less"),
28+
as.integer(discrete.fdr),
2129
p=double(nrow(events) * (nrow(events) - 1) / 2),
2230
q=double(nrow(events) * (nrow(events) - 1) / 2),
2331
pi0=double(1))
32+
33+
if (fdr.method == "BH") {
34+
result$q <- p.adjust(result$p, "BH")
35+
result$pi0 <- 1.0
36+
}
37+
2438
p <- matrix(NA, nrow(events), nrow(events))
2539
p[lower.tri(p)] <- result$p
2640

@@ -34,8 +48,14 @@ pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"),
3448
as.integer(nrow(events)), as.integer(ncol(events)),
3549
as.integer(events[i, ]), as.double(bg[i, ]), as.integer(alternative == "less"),
3650
as.integer(length(block.sizes)), as.integer(block.sizes),
51+
as.integer(discrete.fdr),
3752
p=double(nrow(events)**2), q=double(nrow(events)**2), pi0=double(1))
3853

54+
if (fdr.method == "BH") {
55+
result$q <- p.adjust(result$p, "BH")
56+
result$pi0 <- 1.0
57+
}
58+
3959
j <- order(i)
4060
p <- matrix(result$p, nrow=nrow(events))[j, j]
4161
p[is.nan(p)] <- NA
@@ -54,7 +74,8 @@ pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"),
5474
p.values=p,
5575
q.values=q,
5676
pi0=result$pi0,
57-
alternative=alternative)
77+
alternative=alternative,
78+
fdr.method=fdr.method)
5879
class(result) <- "pairwise.discover.out"
5980
result
6081
}

R/R/background.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' x <- matrix(as.integer(runif(100) < 0.3), 10, 10)
99
#' bg <- estimateBackground(x)
1010
#'
11+
#' @noRd
1112
#' @useDynLib discover
1213
estimateBackground <- function (events, strata=NULL) {
1314
if (is.null(strata)) {
@@ -27,7 +28,7 @@ estimateBackground <- function (events, strata=NULL) {
2728
mu=double(length(row.values) + length(col.values)), PACKAGE="discover")$mu
2829

2930
num.rows <- length(row.values)
30-
eA <- exp(mu[1:num.rows] / row.weights) %*% t(exp(mu[(num.rows+1):length(mu)] / col.weights))
31+
eA <- exp(mu[1:num.rows]) %*% t(exp(mu[(num.rows+1):length(mu)]))
3132
bg <- 1.0 / (eA + 1)
3233

3334
bg <- bg[row.inverse, col.inverse]

R/R/grouptests.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ groupwise.discover.test.coverage <- function (events, bg) {
1313
groupwise.discover.test.exclusivity <- function (events, bg) {
1414
log.p <- log(bg)
1515
log.not.p <- log1p(-bg)
16-
p.exactly.one <- exp(matrixStats::colLogSumExps(rep.row(colSums(log.not.p), nrow(events)) + log.p - log.not.p))
16+
p.exactly.one <- exp(colLogSumExps(rep.row(colSums(log.not.p), nrow(events)) + log.p - log.not.p))
1717
x <- sum(colSums(events) == 1)
1818
ppoisbinom(x, p.exactly.one, lower.tail=FALSE)
1919
}
@@ -22,7 +22,7 @@ groupwise.discover.test.exclusivity <- function (events, bg) {
2222
groupwise.discover.test.impurity <- function (events, bg) {
2323
log.p <- log(bg)
2424
log.not.p <- log1p(-bg)
25-
p.exactly.one <- exp(matrixStats::colLogSumExps(rep.row(colSums(log.not.p), nrow(events)) + log.p - log.not.p))
25+
p.exactly.one <- exp(colLogSumExps(rep.row(colSums(log.not.p), nrow(events)) + log.p - log.not.p))
2626
p.none <- exp(colSums(log.not.p))
2727
p.more.than.one <- 1 - p.none - p.exactly.one
2828
x <- sum(colSums(events) > 1)

R/R/logspace.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#' Compute the logarithm of the sum of exponentials for each column in a matrix.
2+
#'
3+
#' @param x a real-valued matrix.
4+
#' @return a vector with elements corresponding to the log sums of exponentials of the columns of \code{x}.
5+
#'
6+
#' @useDynLib discover
7+
colLogSumExps <- function (x) {
8+
.Fortran("colLogSumExps", as.double(x), as.integer(nrow(x)), as.integer(ncol(x)), result=double(ncol(x)), NAOK=TRUE)$result
9+
}

R/R/print.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ print.pairwise.discover.out <- function (x, fdr.threshold=0.01) {
44
cat("Pairwise DISCOVER", type, "test\n")
55
cat("alternative hypothesis: observed overlap is", x$alternative, "than expected by chance\n")
66

7+
fdr.method <- switch(x$fdr.method, DBH="discrete Benjamini-Hochberg", BH="Benjamini-Hochberg")
8+
cat("FDR estimation method:", fdr.method)
9+
cat("\n")
10+
711
cat("\n")
812

913
cat("number of pairs tested:", sum(!is.na(x$p.values)))

R/src/Makevars

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
PKG_FCFLAGS = -ffree-line-length-none $(SHLIB_OPENMP_FCFLAGS)
2-
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(BLAS_LIBS)
1+
PKG_FCFLAGS = -ffree-line-length-none $(SHLIB_OPENMP_FFLAGS)
2+
PKG_LIBS = $(SHLIB_OPENMP_FFLAGS) $(BLAS_LIBS)
33

44
$(SHLIB) : rwrappers.o
55

66
rwrappers.o : maxent.o fdr.o types.o poisbinom.o
77
maxent.o : types.o
8-
fdr.o : poisbinom.o util.o types.o ieee_constants.o
8+
fdr.o : poisbinom.o util.o types.o
99
poisbinom.o : logspace.o types.o
10-
logspace.o : ieee_constants.o types.o
10+
logspace.o : types.o
1111
util.o : uniinv.o types.o
12-
ieee_constants.o : types.o

0 commit comments

Comments
 (0)