Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/mashWrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ mashRandNullSample <- function(dat, nRandom, nNull, excludeCondition, seed = NUL
stop(paste("Error: excludeCondition are not present in", dat$region))
}
for (key in intersect(names(dat), c("z", "bhat", "sbhat"))) {
dat[[key]] <- dat[[key]][, -excludeCondition, drop = FALSE]
keep <- setdiff(colnames(dat[[key]]), excludeCondition)
dat[[key]] <- dat[[key]][, keep, drop = FALSE]
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test_mashWrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,19 @@ test_that("mashRandNullSample errors when excludeCondition not found (bhat path)
)
})

test_that("mashRandNullSample excludeCondition with column names errors due to numeric indexing", {
test_that("mashRandNullSample drops excluded condition by column name", {
dat <- list(
z = data.frame(
cond1 = c(0.1, 0.2, 0.3, 0.4, 0.5),
cond2 = c(0.5, 0.4, 0.3, 0.2, 0.1),
cond3 = c(0.3, 0.3, 0.3, 0.3, 0.3)
)
)
expect_error(
mashRandNullSample(dat, nRandom = 3, nNull = 2,
excludeCondition = "cond3", seed = 42),
"invalid argument to unary operator"
)
result <- mashRandNullSample(dat, nRandom = 3, nNull = 2,
excludeCondition = "cond3", seed = 42)
expect_equal(colnames(result$random$z), c("cond1", "cond2"))
expect_equal(colnames(result$null$z), c("cond1", "cond2"))
expect_false("cond3" %in% colnames(result$random$z))
})

test_that("mashRandNullSample extracts null data with z scores when enough null variants exist", {
Expand Down
Loading