Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capacity to use arbitrary differential expression functions #1682

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
daff328
Added `as.CellDataSet` generic.
miretchin Mar 6, 2019
ae32278
Finished `as.Seurat.CellDataSet`. Limited by fact that monocle only h…
miretchin Mar 15, 2019
2aa9b37
Added `as.CellDataSet.Seurat`. Works without any warnings.
miretchin Mar 15, 2019
a7db3d8
Removed my silly flags for where my code is. Also, fixed one of the d…
miretchin Mar 15, 2019
e4b3ad6
Added mapping dimensionality reduction to auxClusteringData for Seura…
miretchin Mar 18, 2019
6030049
Revamped the dimensionality reduction transfer technique for monocle …
miretchin Mar 18, 2019
80ebdda
Merge branch 'release/3.0' of github.com:satijalab/seurat into releas…
Mar 18, 2019
7d9273a
Remove compiled DLL
Mar 18, 2019
0c976ef
Style fixes
Mar 18, 2019
19bcd78
Add documentation
Mar 18, 2019
394ac95
Merge branch 'release/3.0' of github.com:satijalab/seurat into releas…
Mar 18, 2019
65f60f7
Merge branch 'develop' into release/3.0
mojaveazure May 21, 2019
ed7082e
finish up CellDataSet converters
andrewwbutler May 22, 2019
964520c
minor fix
andrewwbutler May 22, 2019
c434852
Merge branch 'develop' of github.com:satijalab/seurat into release/3.0
mojaveazure Jun 10, 2019
b7642f9
Merge branch 'develop' of github.com:satijalab/seurat into release/3.0
mojaveazure Jun 11, 2019
db2f9f4
Update as.Seurat.CellDataSet
mojaveazure Jun 11, 2019
da5a395
Minor fixes
mojaveazure Jun 12, 2019
026c09d
minor fix to as.CellDataSet
andrewwbutler Jun 12, 2019
841a2ed
Bump develop version
mojaveazure Jun 12, 2019
d599bb9
Merge branch 'release/3.0' of github.com:miretchin/seurat into releas…
mojaveazure Jun 12, 2019
e5c7317
Merge pull request #1241 from miretchin/release/3.0
mojaveazure Jun 12, 2019
9b4757a
added capability to use arbitrary differential expression functions i…
jspaezp Jun 13, 2019
c0f8d7b
fixed bug where arbitrary functions in FindMarkers were called in the…
jspaezp Jun 13, 2019
c6cd6c7
Merge branch 'develop' into feature-generic-marker-calling
jspaezp Jun 17, 2019
edc45a9
Update DESCRIPTION
jspaezp Jun 17, 2019
5ad4247
Update DESCRIPTION
jspaezp Jun 18, 2019
91c0628
Merge branch 'develop' of github.com:satijalab/seurat into feature-ge…
mojaveazure Aug 9, 2019
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
121 changes: 59 additions & 62 deletions R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -593,74 +593,71 @@ FindMarkers.default <- function(
if (!test.use %in% c('wilcox', 'MAST', 'DESeq2')) {
CheckDots(...)
}

std.arguments <- list(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1, cells.2 = cells.2, verbose = verbose)

de.results <- switch(
EXPR = test.use,
'wilcox' = WilcoxDETest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
verbose = verbose,
...
),
'bimod' = DiffExpTest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
verbose = verbose
),
'roc' = MarkerTest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
verbose = verbose
),
't' = DiffTTest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
verbose = verbose
),
'negbinom' = GLMDETest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
min.cells = min.cells.feature,
latent.vars = latent.vars,
test.use = test.use,
verbose = verbose
),
'poisson' = GLMDETest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
min.cells = min.cells.feature,
latent.vars = latent.vars,
test.use = test.use,
verbose = verbose
'wilcox' = do.call(what = "WilcoxDETest", args = c(std.arguments, ...)),
'bimod' = do.call(what = "DiffExpTest", args = c(std.arguments, ...)),
'roc' = do.call(what = "MarkerTest", args = std.arguments),
't' = do.call(what = "DiffTTest", args = std.arguments),
'negbinom' = do.call(
what = "GLMDETest",
args = c(
std.arguments,
min.cells = min.cells.feature,
latent.vars = latent.vars,
test.use = test.use
)
),
'MAST' = MASTDETest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
latent.vars = latent.vars,
verbose = verbose,
...
'poisson' = do.call(
what = "GLMDETest",
args = c(
std.arguments,
min.cells = min.cells.feature,
latent.vars = latent.vars,
test.use = test.use
)
),
"DESeq2" = DESeq2DETest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
verbose = verbose,
...
'MAST' = do.call(
what = "MASTDETest",
args = c(
std.arguments,
min.cells = min.cells.feature,
latent.vars = latent.vars,
test.use = test.use
)
),
"LR" = LRDETest(
data.use = object[features, c(cells.1, cells.2), drop = FALSE],
cells.1 = cells.1,
cells.2 = cells.2,
latent.vars = latent.vars,
verbose = verbose
"DESeq2" = do.call(what = "DESeq2DETest", args = std.arguments),
"LR" = do.call(
what = "LRDETest",
args = c(std.arguments, latent.vars = latent.vars)
),
stop("Unknown test: ", test.use)
{
de.results <- try(
expr = {
do.call(
what = test.use,
args = c(std.arguments, ...),
envir = parent.frame(2)
)
},
silent = TRUE
)
# This section makes sure that the correct error is raised, the
if (class(de.results) == "try-error") {
if (grepl(paste0("could not find function.*", test.use), de.results)) {
stop("Unknown test: ", test.use)
} else {
stop(de.results)
}
}

de.results
}
)
if (is.null(x = reduction)) {
diff.col <- ifelse(
Expand Down
26 changes: 25 additions & 1 deletion tests/testthat/test_differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test_that("Default settings work as expected", {
expect_error(FindMarkers(object = pbmc_small))
expect_error(FindMarkers(object = pbmc_small, ident.1 = "test"))
expect_error(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = "test"))
expect_error(FindMarkers(object = pbmc_small, ident.1 = 0, test.use = "areallyfaketest"), regexp = "Unknown test: ")
expect_equal(colnames(x = markers.0), c("p_val", "avg_logFC", "pct.1", "pct.2", "p_val_adj"))
expect_equal(markers.0[1, "p_val"], 9.572778e-13)
expect_equal(markers.0[1, "avg_logFC"], -4.034691, tolerance = 1e-6)
Expand Down Expand Up @@ -221,7 +222,30 @@ test_that("LR test works", {
expect_equal(rownames(x = results)[1], "LYZ")
})

# Tests for FindConservedMarkers
test_that("Arbitrary marker function calling works", {
return_fakedata <- function(data.use, ...) data.frame(p_val = rep(1, nrow(data.use)), row.names = rownames(data.use))

results <- suppressWarnings(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, test.use = "return_fakedata", verbose = FALSE))

expect_equal(nrow(x = results), 201)
expect_equal(results["CST3", "p_val"], 1)
expect_equal(results["CST3", "avg_logFC"], -2.552769, tolerance = 1e-6)
expect_equal(results["CST3", "pct.1"], 0.306)
expect_equal(results["CST3", "pct.2"], 1.00)
expect_equal(results["CST3", "p_val_adj"], 1)
expect_equal(rownames(x = results)[1], "PF4")

})

test_that("Arbitrary marker function propagates the right error", {
buggyfunction <- function(...) stop("I dont work")

expect_error(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, test.use = "buggyfunction", verbose = FALSE), "I dont work")
expect_error(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, test.use = "nonexistent", verbose = FALSE), "Unknown test: nonexistent")
})


# Tests for FindConservedMarkers
# --------------------------------------------------------------------------------
context("FindConservedMarkers")
pbmc_small$groups
Expand Down