Open jdrnevich opened 3 years ago
I will give this a bump because the way this has to be fixed on the user's end is very tricky. As jdrnevich pointed out, this error occurs if graph_test is run when there are more than 10,000 cells, leading to the data being split into blocks, calling the defunct rBind function. If one were to copy the graph_test code, it will not work given monocle and its dependencies if you are intending to identify genes differentially expressed by pseudotime (i.e. using the argument neighbor_graph=principal_graph
. In order for this function to work, the call of jaccard_index()
needs to be changed to monocle3:::jaccard index
and a copy of RcppExports.cpp (found in the github src) needs to copied into the user's path_to_libraries/R/library/monocle3/
directory within a user-created directory src
within path_to_libraries/R/library/monocle3
.
Changing tmp <- Matrix::rBind(tmp, cur_tmp)
to tmp <- rbind(tmp, cur_tmp)
on line 392 in graph_test.py in the Monocle3 source code would be much appreciated and save the above headache
How did you solve this quesion? What should users do to avoid this now? @jdrnevich @mleventh
I don't know, @Sophia409 - that's a question for @ctrapnell or @brgew to see if they ever fixed the bug. In my case, I just slightly increased my cell filtering criteria to get under 10K cells since I only had 10,084 cells to start.
@Sophia409 I defined my own function called graph_test_large()
, copying thegraph_test()
code into this new function. I then changed the call of jaccard_index()
in this function to monocle3:::jaccard_index()
and copying Rcppexports.R from this github into the path to a src directory in my monocle3 library (i.e. copying to path_to_libraries/R/library/monocle3/src). Once these changes were made I could call graph_test_large()
where I had previously used graph_test()
@mleventh Hi, thank you for your answer. I tried your method, but it has two problems. Firstly, I couldn't find jaccard_index() function in graph_test function.
function (cds, neighbor_graph = c("knn", "principal_graph"),
reduction_method = "UMAP", k = 25, method = c("Moran_I"),
alternative = "greater", expression_family = "quasipoisson",
cores = 1, verbose = FALSE)
{
neighbor_graph <- match.arg(neighbor_graph)
lw <- calculateLW(cds, k = k, verbose = verbose, neighbor_graph = neighbor_graph,
reduction_method = reduction_method)
if (verbose) {
message("Performing Moran's I test: ...")
}
exprs_mat <- SingleCellExperiment::counts(cds)[, attr(lw,
"region.id"), drop = FALSE]
sz <- size_factors(cds)[attr(lw, "region.id")]
wc <- spdep::spweights.constants(lw, zero.policy = TRUE,
adjust.n = TRUE)
test_res <- pbmcapply::pbmclapply(row.names(exprs_mat),
FUN = function(x, sz, alternative, method, expression_family) {
exprs_val <- exprs_mat[x, ]
if (expression_family %in% c("uninormal", "binomialff")) {
exprs_val <- exprs_val
}
else {
exprs_val <- log10(exprs_val/sz + 0.1)
}
test_res <- tryCatch({
if (method == "Moran_I") {
mt <- suppressWarnings(my.moran.test(exprs_val,
lw, wc, alternative = alternative))
data.frame(status = "OK", p_value = mt$p.value,
morans_test_statistic = mt$statistic, morans_I = mt$estimate[["Moran I statistic"]])
}
else if (method == "Geary_C") {
gt <- suppressWarnings(my.geary.test(exprs_val,
lw, wc, alternative = alternative))
data.frame(status = "OK", p_value = gt$p.value,
geary_test_statistic = gt$statistic, geary_C = gt$estimate[["Geary C statistic"]])
}
}, error = function(e) {
data.frame(status = "FAIL", p_value = NA, morans_test_statistic = NA,
morans_I = NA)
})
}, sz = sz, alternative = alternative, method = method,
expression_family = expression_family, mc.cores = cores,
ignore.interactive = TRUE)
if (verbose) {
message("returning results: ...")
}
test_res <- do.call(rbind.data.frame, test_res)
row.names(test_res) <- row.names(cds)
test_res <- merge(test_res, rowData(cds), by = "row.names")
row.names(test_res) <- test_res[, 1]
test_res[, 1] <- NULL
test_res$q_value <- 1
test_res$q_value[which(test_res$status == "OK")] <- stats::p.adjust(subset(test_res,
status == "OK")[, "p_value"], method = "BH")
test_res$status = as.character(test_res$status)
test_res[row.names(cds), ]
}
Secondly, since I use R in windows system, I couldn't find src file in my library. What's your advice? Would be greatly appreciated!
Hi, sorry for some of the confusion! I also had re-instantiated the functions called by graph_test
, those being my.moran.test,
my.geary.test, and
calculateLW. It is in
calculateLW` where jaccard_index() is called and should be changed to monocle3:::jaccard_index()
As for the src directory, what I had to do was go into my libs directory, find monocle3, make a src directory and put the Rccp file into it. I might suggest looking into your "libs" folder, finding monocle3 and making a src directory to put the Rccp file.
Describe the bug I had a similar issue to #509 when running
graph_test()
and getting the errorError: 'rBind' is defunct.
. I tried KforKuma's solution of rebooting my computer but still had the same error. Again, like KforKuma,traceback()
indicatedcalculateLW()
is where the error occurred. Looking at the code formonocle3:::calculateLW()
, it hard-codesblock_size <- 10000
and then runs a for loop on the blocks then usesMatrix::rBind()
at the end of the for loop. My data set has 10,084 cells butgraph_test()
works if I subset it to 9999 cells.To Reproduce The code that produced the bug:
traceback() After the error, run traceback() in R and post the output:
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
sessionInfo(): Run sessionInfo() in R and post the output
Additional context You probably just need to replace
Matrix::rBind
withrbind
incalculateLW()
and any other functions it may be in. Thanks!