saezlab / liana

LIANA: a LIgand-receptor ANalysis frAmework
https://saezlab.github.io/liana/
GNU General Public License v3.0
160 stars 28 forks source link

liana_wrap error, please help #117

Closed intawat closed 1 year ago

intawat commented 1 year ago

I run the wrapper using mouse ortholog table follow the vignette but got error below (command in bold)

sce <- liana_prep(dat.integrated)

Expression from the RNA assay will be used

Running LIANA with cl_names as labels!

Warning message in exec(output, ...): “19384 genes and/or 0 cells were removed as they had no counts!”

liana_res <- liana_wrap(sce, resource = 'custom', # resource has to be set to 'custom' to work with external resources external_resource = ortholog_resource, # provide orthologous resource method=c('sca', 'natmi') # run only with sca and natmi for comp. time )

Running LIANA with label as labels!

Error in map(): ℹ In index: 1. ℹ With name: custom_resource. Caused by error in map(): ℹ In index: 1. Caused by error in h(): ! error in evaluating the argument 'x' in selecting a method for function 'rowMeans': size factors should be positive Traceback:

  1. liana_wrap(sce, resource = "custom", external_resource = ortholog_resource, . method = c("sca", "natmi"))
  2. resource %>% map(function(reso) { . if (is.null(reso)) { . liana_message("Resource was NULL and LIANA's internal methods were run with the Consensus resource", . verbose = verbose, output = "warning") . reso <- select_resource("Consensus")[[1]] . } . rlang::invoke(liana_pipe, append(list(sce = sce, op_resource = decomplexify(reso), . verbose = verbose, cell.adj = cell.adj, base = base), . liana_defaults(...)[["liana_pipe"]])) . }) %>% setNames(names(resource))
  3. setNames(., names(resource))
  4. map(., function(reso) { . if (is.null(reso)) { . liana_message("Resource was NULL and LIANA's internal methods were run with the Consensus resource", . verbose = verbose, output = "warning") . reso <- select_resource("Consensus")[[1]] . } . rlang::invoke(liana_pipe, append(list(sce = sce, op_resource = decomplexify(reso), . verbose = verbose, cell.adj = cell.adj, base = base), . liana_defaults(...)[["liana_pipe"]])) . })
  5. map_("list", .x, .f, ..., .progress = .progress)
  6. with_indexed_errors(i = i, names = names, error_call = .purrr_error_call, . call_with_cleanup(map_impl, environment(), .type, .progress, . n, names, i))
  7. withCallingHandlers(expr, error = function(cnd) { . if (i == 0L) { . } . else { . message <- c(i = "In index: {i}.") . if (!is.null(names) && !is.na(names[[i]]) && names[[i]] != . "") { . name <- names[[i]] . message <- c(message, i = "With name: {name}.") . } . else { . name <- NULL . } . cli::cli_abort(message, location = i, name = name, parent = cnd, . call = error_call, class = "purrr_error_indexed") . } . })
  8. call_with_cleanup(map_impl, environment(), .type, .progress, . n, names, i)
  9. .f(.x[[i]], ...)
  10. rlang::invoke(liana_pipe, append(list(sce = sce, op_resource = decomplexify(reso), . verbose = verbose, cell.adj = cell.adj, base = base), liana_defaults(...)[["liana_pipe"]]))
  11. .fn(sce = 1, op_resource = 2, verbose = 3, cell.adj = 4, . base = 5, test.type = 6, pval.type = 7, assay = 8, . assay.type = 9)
  12. get_log2FC(sce, assay.type = assay.type, base)
  13. levels(colLabels(sce)) %>% map(function(subject) { . subject_avg <- scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(subject_avg = value) . loso_avg <- scater::calculateAverage(subset(sce, select = !(colLabels(sce) %in% . subject)), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(loso_avg = value) . left_join(subject_avg, loso_avg, by = "gene") %>% mutate(avg_log2FC = log2((subject_avg + . 1)) - log2((loso_avg + 1))) %>% select(gene, avg_log2FC) . }) %>% setNames(levels(colLabels(sce))) %>% enframe(name = "cell") %>% . unnest(value)
  14. unnest(., value)
  15. enframe(., name = "cell")
  16. setNames(., levels(colLabels(sce)))
  17. map(., function(subject) { . subject_avg <- scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(subject_avg = value) . loso_avg <- scater::calculateAverage(subset(sce, select = !(colLabels(sce) %in% . subject)), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(loso_avg = value) . left_join(subject_avg, loso_avg, by = "gene") %>% mutate(avg_log2FC = log2((subject_avg + . 1)) - log2((loso_avg + 1))) %>% select(gene, avg_log2FC) . })
  18. map_("list", .x, .f, ..., .progress = .progress)
  19. with_indexed_errors(i = i, names = names, error_call = .purrr_error_call, . call_with_cleanup(map_impl, environment(), .type, .progress, . n, names, i))
  20. withCallingHandlers(expr, error = function(cnd) { . if (i == 0L) { . } . else { . message <- c(i = "In index: {i}.") . if (!is.null(names) && !is.na(names[[i]]) && names[[i]] != . "") { . name <- names[[i]] . message <- c(message, i = "With name: {name}.") . } . else { . name <- NULL . } . cli::cli_abort(message, location = i, name = name, parent = cnd, . call = error_call, class = "purrr_error_indexed") . } . })
  21. call_with_cleanup(map_impl, environment(), .type, .progress, . n, names, i)
  22. .f(.x[[i]], ...)
  23. scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(subject_avg = value)
  24. dplyr::rename(., subject_avg = value)
  25. as_tibble(., rownames = "gene")
  26. scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts")
  27. scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts")
  28. .local(x, ...)
  29. callNextMethod(x, size.factors = size.factors, ...)
  30. eval(call, callEnv)
  31. eval(call, callEnv)
  32. .nextMethod(x, size.factors = size.factors, ...)
  33. .local(x, ...)
  34. .calculate_average(assay(x, assay.type), ...)
  35. rowMeans(normalizeCounts(x, size.factors, subset.row = subset.row, . log = FALSE))
  36. normalizeCounts(x, size.factors, subset.row = subset.row, log = FALSE)
  37. normalizeCounts(x, size.factors, subset.row = subset.row, log = FALSE)
  38. .local(x, ...)
  39. stop("size factors should be positive")
  40. .handleSimpleError(function (cond) . .Internal(C_tryCatchHelper(addr, 1L, cond)), "size factors should be positive", . base::quote(.local(x, ...)))
  41. h(simpleError(msg, call))
  42. .handleSimpleError(function (cnd) . { . if (i == 0L) { . } . else { . message <- c(i = "In index: {i}.") . if (!is.null(names) && !is.na(names[[i]]) && names[[i]] != . "") { . name <- names[[i]] . message <- c(message, i = "With name: {name}.") . } . else { . name <- NULL . } . cli::cli_abort(message, location = i, name = name, parent = cnd, . call = error_call, class = "purrr_error_indexed") . } . }, "error in evaluating the argument 'x' in selecting a method for function 'rowMeans': size factors should be positive", . base::quote(h(simpleError(msg, call))))
  43. h(simpleError(msg, call))
  44. cli::cli_abort(message, location = i, name = name, parent = cnd, . call = error_call, class = "purrr_error_indexed")
  45. rlang::abort(message, ..., call = call, use_cli_format = TRUE, . .frame = .frame)
  46. signal_abort(cnd, .file)
  47. signalCondition(cnd)
  48. (function (cnd) . { . if (i == 0L) { . } . else { . message <- c(i = "In index: {i}.") . if (!is.null(names) && !is.na(names[[i]]) && names[[i]] != . "") { . name <- names[[i]] . message <- c(message, i = "With name: {name}.") . } . else { . name <- NULL . } . cli::cli_abort(message, location = i, name = name, parent = cnd, . call = error_call, class = "purrr_error_indexed") . } . })(structure(list(message = c(i = "In index: 1."), trace = structure(list( . call = list(IRkernel::main(), kernel$run(), handle_shell(), . executor$execute(msg), tryCatch(evaluate(request$content$code, . envir = .GlobalEnv, output_handler = oh, stop_on_error = 1L), . interrupt = function(cond) { . log_debug("Interrupt during execution") . interrupted <<- TRUE . }, error = .self$handle_error), tryCatchList(expr, . classes, parentenv, handlers), tryCatchOne(tryCatchList(expr, . names[-nh], parentenv, handlers[-nh]), names[nh], . parentenv, handlers[[nh]]), doTryCatch(return(expr), . name, parentenv, handler), tryCatchList(expr, names[-nh], . parentenv, handlers[-nh]), tryCatchOne(expr, names, . parentenv, handlers[[1L]]), doTryCatch(return(expr), . name, parentenv, handler), evaluate(request$content$code, . envir = .GlobalEnv, output_handler = oh, stop_on_error = 1L), . evaluate_call(expr, parsed$src[[i]], envir = envir, enclos = enclos, . debug = debug, last = i == length(out), use_try = stop_on_error != . 2L, keep_warning = keep_warning, keep_message = keep_message, . log_echo = log_echo, log_warning = log_warning, output_handler = output_handler, . include_timing = include_timing), timing_fn(handle(ev <- withCallingHandlers(withVisible(eval_with_user_handlers(expr, . envir, enclos, user_handlers)), warning = wHandler, . error = eHandler, message = mHandler))), handle(ev <- withCallingHandlers(withVisible(eval_with_user_handlers(expr, . envir, enclos, user_handlers)), warning = wHandler, . error = eHandler, message = mHandler)), try(f, silent = TRUE), . tryCatch(expr, error = function(e) { . call <- conditionCall(e) . if (!is.null(call)) { . if (identical(call[[1L]], quote(doTryCatch))) . call <- sys.call(-4L) . dcall <- deparse(call, nlines = 1L) . prefix <- paste("Error in", dcall, ": ") . LONG <- 75L . sm <- strsplit(conditionMessage(e), "\n")[[1L]] . w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], . type = "w") . if (is.na(w)) . w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], . type = "b") . if (w > LONG) . prefix <- paste0(prefix, "\n ") . } . else prefix <- "Error : " . msg <- paste0(prefix, conditionMessage(e), "\n") . .Internal(seterrmessage(msg[1L])) . if (!silent && isTRUE(getOption("show.error.messages"))) { . cat(msg, file = outFile) . .Internal(printDeferredWarnings()) . } . invisible(structure(msg, class = "try-error", condition = e)) . }), tryCatchList(expr, classes, parentenv, handlers), . tryCatchOne(expr, names, parentenv, handlers[[1L]]), . doTryCatch(return(expr), name, parentenv, handler), withCallingHandlers(withVisible(eval_with_user_handlers(expr, . envir, enclos, user_handlers)), warning = wHandler, . error = eHandler, message = mHandler), withVisible(eval_with_user_handlers(expr, . envir, enclos, user_handlers)), eval_with_user_handlers(expr, . envir, enclos, user_handlers), eval(expr, envir, . enclos), eval(expr, envir, enclos), liana_wrap(sce, . resource = "custom", external_resource = ortholog_resource, . method = c("sca", "natmi")), resource %>% map(function(reso) { . if (is.null(reso)) { . liana_message("Resource was NULL and LIANA's internal methods were run with the Consensus resource", . verbose = verbose, output = "warning") . reso <- select_resource("Consensus")[[1]] . } . rlang::invoke(liana_pipe, append(list(sce = sce, . op_resource = decomplexify(reso), verbose = verbose, . cell.adj = cell.adj, base = base), liana_defaults(...)[["liana_pipe"]])) . }) %>% setNames(names(resource)), setNames(., names(resource)), . map(., function(reso) { . if (is.null(reso)) { . liana_message("Resource was NULL and LIANA's internal methods were run with the Consensus resource", . verbose = verbose, output = "warning") . reso <- select_resource("Consensus")[[1]] . } . rlang::invoke(liana_pipe, append(list(sce = sce, . op_resource = decomplexify(reso), verbose = verbose, . cell.adj = cell.adj, base = base), liana_defaults(...)[["lianapipe"]])) . }), map("list", .x, .f, ..., .progress = .progress), . with_indexed_errors(i = i, names = names, error_call = .purrr_error_call, . call_with_cleanup(map_impl, environment(), .type, . .progress, n, names, i)), withCallingHandlers(expr, . error = function(cnd) { . if (i == 0L) { . } . else { . message <- c(i = "In index: {i}.") . if (!is.null(names) && !is.na(names[[i]]) && . names[[i]] != "") { . name <- names[[i]] . message <- c(message, i = "With name: {name}.") . } . else { . name <- NULL . } . cli::cli_abort(message, location = i, name = name, . parent = cnd, call = error_call, class = "purrr_error_indexed") . } . }), call_with_cleanup(map_impl, environment(), .type, . .progress, n, names, i), .f(.x[[i]], ...), rlang::invoke(liana_pipe, . append(list(sce = sce, op_resource = decomplexify(reso), . verbose = verbose, cell.adj = cell.adj, base = base), . liana_defaults(...)[["liana_pipe"]])), .fn(sce = 1, . op_resource = 2, verbose = 3, cell.adj = 4, . base = 5, test.type = 6, pval.type = 7, assay = 8, . assay.type = 9), get_log2FC(sce, assay.type = assay.type, . base), levels(colLabels(sce)) %>% map(function(subject) { . subject_avg <- scater::calculateAverage(subset(sce, . select = colLabels(sce) == subject), assay.type = "normcounts") %>% . as_tibble(rownames = "gene") %>% dplyr::rename(subject_avg = value) . loso_avg <- scater::calculateAverage(subset(sce, . select = !(colLabels(sce) %in% subject)), assay.type = "normcounts") %>% . as_tibble(rownames = "gene") %>% dplyr::rename(loso_avg = value) . left_join(subject_avg, loso_avg, by = "gene") %>% . mutate(avg_log2FC = log2((subject_avg + 1)) - . log2((loso_avg + 1))) %>% select(gene, avg_log2FC) . }) %>% setNames(levels(colLabels(sce))) %>% enframe(name = "cell") %>% . unnest(value), unnest(., value), enframe(., name = "cell"), . setNames(., levels(colLabels(sce))), map(., function(subject) { . subject_avg <- scater::calculateAverage(subset(sce, . select = colLabels(sce) == subject), assay.type = "normcounts") %>% . as_tibble(rownames = "gene") %>% dplyr::rename(subject_avg = value) . loso_avg <- scater::calculateAverage(subset(sce, . select = !(colLabels(sce) %in% subject)), assay.type = "normcounts") %>% . as_tibble(rownames = "gene") %>% dplyr::rename(loso_avg = value) . left_join(subject_avg, loso_avg, by = "gene") %>% . mutate(avg_log2FC = log2((subject_avg + 1)) - . log2((loso_avg + 1))) %>% select(gene, avglog2FC) . }), map("list", .x, .f, ..., .progress = .progress), . with_indexed_errors(i = i, names = names, error_call = .purrr_error_call, . call_with_cleanup(map_impl, environment(), .type, . .progress, n, names, i)), withCallingHandlers(expr, . error = function(cnd) { . if (i == 0L) { . } . else { . message <- c(i = "In index: {i}.") . if (!is.null(names) && !is.na(names[[i]]) && . names[[i]] != "") { . name <- names[[i]] . message <- c(message, i = "With name: {name}.") . } . else { . name <- NULL . } . cli::cli_abort(message, location = i, name = name, . parent = cnd, call = error_call, class = "purrr_error_indexed") . } . }), call_with_cleanup(map_impl, environment(), .type, . .progress, n, names, i), .f(.x[[i]], ...), scater::calculateAverage(subset(sce, . select = colLabels(sce) == subject), assay.type = "normcounts") %>% . as_tibble(rownames = "gene") %>% dplyr::rename(subject_avg = value), . dplyr::rename(., subject_avg = value), as_tibble(., rownames = "gene"), . scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts"), scater::calculateAverage(subset(sce, . select = colLabels(sce) == subject), assay.type = "normcounts"), . .local(x, ...), callNextMethod(x, size.factors = size.factors, . ...), eval(call, callEnv), eval(call, callEnv), .nextMethod(x, . size.factors = size.factors, ...), .local(x, ...), . .calculate_average(assay(x, assay.type), ...), rowMeans(normalizeCounts(x, . size.factors, subset.row = subset.row, log = FALSE)), . normalizeCounts(x, size.factors, subset.row = subset.row, . log = FALSE), normalizeCounts(x, size.factors, subset.row = subset.row, . log = FALSE), .local(x, ...), stop("size factors should be positive"), . .handleSimpleError(<fn>, "size factors should be positive", . base::quote(.local(x, ...))), h(simpleError(msg, . call)), .handleSimpleError(<fn>, "error in evaluating the argument 'x' in selecting a method for function 'rowMeans': size factors should be positive", . base::quote(h(simpleError(msg, call)))), h(simpleError(msg, . call)), cli::cli_abort(message, location = i, name = name, . parent = cnd, call = error_call, class = "purrr_error_indexed"), . rlang::abort(message, ..., call = call, use_cli_format = TRUE, . .frame = .frame)), parent = c(0L, 1L, 2L, 3L, 4L, . 5L, 6L, 7L, 6L, 9L, 10L, 4L, 12L, 13L, 13L, 15L, 16L, 17L, . 18L, 19L, 13L, 13L, 13L, 23L, 24L, 0L, 26L, 0L, 0L, 29L, . 30L, 31L, 30L, 30L, 34L, 0L, 36L, 37L, 0L, 0L, 0L, 0L, 42L, . 43L, 44L, 43L, 43L, 47L, 0L, 0L, 47L, 47L, 52L, 53L, 54L, . 55L, 53L, 57L, 58L, 59L, 59L, 59L, 62L, 63L, 0L, 65L, 0L, . 67L, 68L, 69L), visible = c(TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, . TRUE, FALSE, FALSE, FALSE, FALSE), namespace = c("IRkernel", . NA, "IRkernel", NA, "base", "base", "base", "base", "base", . "base", "base", "evaluate", "evaluate", "evaluate", "evaluate", . "base", "base", "base", "base", "base", "base", "base", "evaluate", . "base", "base", "liana", NA, "stats", "purrr", "purrr", "purrr", . "base", "purrr", "liana", "rlang", "liana", "liana", NA, . "tidyr", "tibble", "stats", "purrr", "purrr", "purrr", "base", . "purrr", "liana", NA, "dplyr", "tibble", "scater", "scater", . "scuttle", "methods", "base", "base", "scuttle", "scuttle", . "scuttle", "methods", "scuttle", "scuttle", "scuttle", "base", . "base", "base", "base", "purrr", "cli", "rlang"), scope = c("::", . NA, "local", NA, "::", "local", "local", "local", "local", . "local", "local", "::", ":::", "local", "local", "::", "::", . "local", "local", "local", "::", "::", ":::", "::", "::", . "::", NA, "::", "::", ":::", ":::", "::", ":::", "local", . "::", "local", ":::", NA, "::", "::", "::", "::", ":::", . ":::", "::", ":::", "local", NA, "::", "::", "::", "::", . "local", "::", "::", "::", "local", "local", ":::", "local", . "::", "::", "local", "::", "::", "local", "::", "local", . "::", "::"), error_frame = c(FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, . FALSE, FALSE, FALSE)), row.names = c(NA, -70L), version = 2L, class = c("rlang_trace", . "rlib_trace", "tbl", "data.frame")), parent = structure(list( . message = "error in evaluating the argument 'x' in selecting a method for function 'rowMeans': size factors should be positive", . call = h(simpleError(msg, call))), class = c("simpleError", . "error", "condition")), location = 1L, name = NULL, rlang = list( . inherit = TRUE), call = map(., function(subject) { . subject_avg <- scater::calculateAverage(subset(sce, select = colLabels(sce) == . subject), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(subject_avg = value) . loso_avg <- scater::calculateAverage(subset(sce, select = !(colLabels(sce) %in% . subject)), assay.type = "normcounts") %>% as_tibble(rownames = "gene") %>% . dplyr::rename(loso_avg = value) . left_join(subject_avg, loso_avg, by = "gene") %>% mutate(avg_log2FC = log2((subject_avg + . 1)) - log2((loso_avg + 1))) %>% select(gene, avg_log2FC) . }), use_cli_format = TRUE), class = c("purrr_error_indexed", . "rlang_error", "error", "condition")))
  49. cli::cli_abort(message, location = i, name = name, parent = cnd, . call = error_call, class = "purrr_error_indexed")
  50. rlang::abort(message, ..., call = call, use_cli_format = TRUE, . .frame = .frame)
  51. signal_abort(cnd, .file)
dbdimitrov commented 1 year ago

Hi @intawat,

I assume you have are encountering some kind of an issue with the counts that you are using - you should use log-normalized. Specifically, I see that liana has filtered 19384 genes which means that something is wrong, and likely you simply have none left. Check if you are not using the residuals or any type of negative values from your integration approach.

intawat commented 1 year ago

Ok normalization using log is good, thank you for the quick response. I will probably ask you more about your great package in the future.

//Intawat

On Wed, Jun 21, 2023 at 9:02 AM Daniel Dimitrov @.***> wrote:

Hi @intawat https://github.com/intawat,

I assume you have are encountering some kind of an issue with the counts that you are using - you should use log-normalized. Specifically, I see that liana has filtered 19384 genes which means that something is wrong, and likely you simply have none left. Check if you are not using the residuals or any type of negative values from your integration approach.

— Reply to this email directly, view it on GitHub https://github.com/saezlab/liana/issues/117#issuecomment-1600897208, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4VBHWNADHDIHNLUEWF5PLXML5I7ANCNFSM6AAAAAAZN55K7Q . You are receiving this because you were mentioned.Message ID: @.***>