Skip to content

Commit

Permalink
1.0.5 patch (#71)
Browse files Browse the repository at this point in the history
* sparcc cov and tests

* dont use nonexported huge.mb

* some general data checks

* fiddle test params

* removed git comment marker

* remove performance test, update buildignore
  • Loading branch information
zdk123 authored Mar 7, 2019
1 parent 3ecf6f9 commit 78aabd8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
^.README\.*
^inst/.README\.*
^README\.Rmd$
^inst/extdata\.*
^inst/TUTORIAL*
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: SpiecEasi
Title: Sparse Inverse Covariance for Ecological Statistical Inference
Version: 1.0.2
Version: 1.0.5
Authors@R: c(
person("Zachary", "Kurtz", role = c("aut", "cre"), email="[email protected]"),
person("Christian", "Mueller", role = "aut"),
Expand Down Expand Up @@ -31,4 +31,4 @@ Suggests:
biocViews:
License: GPL (>= 2)
LazyData: true
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
10 changes: 7 additions & 3 deletions R/SparseICov.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ sparseiCov <- function(data, method, npn=FALSE, verbose=FALSE, cov.output = TRUE
if (is.null(args$lambda.min.ratio)) args$lambda.min.ratio <- 1e-3

if (method %in% c("glasso")) {
est <- do.call(huge::huge, c(args, list(x=data, method=method, verbose=verbose,
cov.output = cov.output)))
est <- do.call(huge::huge, c(args, list(x=data,
method=method,
verbose=verbose,
cov.output = cov.output)))

} else if (method %in% c('mb')) {
est <- do.call(huge::huge.mb, c(args, list(x=data, verbose=verbose)))
est <- do.call(huge::huge, c(args, list(x=data,
method=method,
verbose=verbose)))
est$method <- 'mb'
est$data <- data
est$sym <- ifelse(!is.null(args$sym), args$sym, 'or')
Expand Down
1 change: 0 additions & 1 deletion R/spaRcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sparcc <- function(data, iter=20, inner_iter=10, th=.1) {
covs <- array(unlist(lapply(sparccs, function(x) x$Cov)),
c(ncol(data),ncol(data),iter))
covMed <- apply(covs, 1:2, median)

covMed <- cor2cov(corMed, sqrt(diag(covMed)))
list(Cov=covMed, Cor=corMed)
}
Expand Down
15 changes: 15 additions & 0 deletions R/spiec-easi.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ spiec.easi <- function(data, ...) {
return(OTU)
}

#' @keywords internal
.data.checks <- function(data) {
## data checks ##
if (isTRUE(all.equal(rowSums(data), rep(1L, nrow(data))))) {
warning('Data is normalized, but raw counts are expected')
}

if (any(data<0)) {
warning('Negative values detected, but raw counts are expected')
}
}

#' @method spiec.easi phyloseq
#' @rdname spiec.easi
#' @export
Expand Down Expand Up @@ -129,6 +141,9 @@ spiec.easi.default <- function(data, method='glasso', sel.criterion='stars',
icov.select.params=pulsar.params, ...) {

args <- list(...)

.data.checks(data)

if (verbose) msg <- .makeMessage("Applying data transformations...")
else msg <- .makeMessage('')

Expand Down
15 changes: 2 additions & 13 deletions tests/testthat/test_pulsar.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
context('setup')

p <- 20
p <- 30
e <- p
n <- 500
set.seed(10010)
g <- make_graph('erdos_renyi', p, e)
S <- cov2cor(prec2cov(graph2prec(g)))
X <- exp(rmvnorm(n, rep(0,p), S))

pargs <- list(seed=10010, rep.num=10)
pargs <- list(seed=10010, rep.num=15)

context("SPIEC-EASI fit")
lmx <- .7
Expand All @@ -28,9 +28,6 @@ bout.stars <- spiec.easi(X, method='mb', verbose=FALSE, lambda.max=lmx, lambda.m
bout.bstars <- spiec.easi(X, method='mb', verbose=FALSE, lambda.max=lmx, lambda.min.ratio=lmr, nlambda=nlam, sel.criterion='bstars', pulsar.select='batch', pulsar.params=pargs)


# save(out, out.stars, out.bstars, bout.stars, bout.bstars,
# file=system.file('testdata', 'sepulsar.RData', package='SpiecEasi'))

test_that("no pulsar has same output", {
expect_equal(as.matrix(out$est$path[[out.stars$select$stars$opt.index]]),
as.matrix(out.stars$refit$stars))
Expand All @@ -39,8 +36,6 @@ test_that("no pulsar has same output", {
test_that("stars == bstars", {
expect_equal(as.matrix(out.bstars$refit$stars),
as.matrix(out.stars$refit$stars))
expect_gt(t1[3], t2[3])

})

test_that("stars == batch stars", {
Expand All @@ -58,14 +53,8 @@ test_that("stars == batch bstars", {
as.matrix(bout.bstars$refit$stars))
})


## TODO: test pulsar params in/out


context('spiec.easi getters')

# load(system.file('testdata', 'sepulsar.RData', package='SpiecEasi'))

test_that("Getter API throws errors if no pulsar selection", {
expect_error(getOptInd(out))
expect_error(getOptNet(out))
Expand Down
13 changes: 10 additions & 3 deletions tests/testthat/test_sparcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ set.seed(10010)
g <- make_graph('erdos_renyi', p, e)
S <- cov2cor(prec2cov(graph2prec(g)))
X <- exp(rmvnorm(n, rep(0,p), S))
X.f <- t(apply(X, 1, norm_to_total))

context("SparCC ouput")
context("Input data")
test_that("data is counts", {
expect_silent(.data.checks(X))
expect_warning(.data.checks(X.f))
expect_warning(.data.checks(scale(X)))
})

context("SparCC")
test_that("sparcc gives expected output", {
out <- sparcc(X)
expect_true(all(c('Cov', 'Cor') %in% names(out)))
expect_true(all(diag(out$Cor)==1))
expect_false(all(out$Cor==out$Cov))
expect_false(any(out$Cor==out$Cov))
expect_equal(out$Cor, cov2cor(out$Cov))
expect_equal(dim(out$Cor), c(p,p))
expect_equal(dim(out$Cov), c(p,p))
Expand All @@ -31,5 +39,4 @@ test_that('sparccboot gives expected output', {
expect_lte(max(pvals$pvals, na.rm=TRUE), 1)
expect_gte(min(pvals$cors, na.rm=TRUE), -1)
expect_lte(max(pvals$cors, na.rm=TRUE), 1)

})

0 comments on commit 78aabd8

Please sign in to comment.