Skip to content

Commit

Permalink
Allow tryCatch when pseudo-bulk does not work with small clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
mvfki committed Jun 11, 2024
1 parent 6280088 commit 16351ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
28 changes: 24 additions & 4 deletions R/DEG_marker.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,33 @@ runMarkerDEG <- function(
} else {
result <- list()
for (i in seq_along(levels(splitBy))) {
if (isTRUE(verbose)) {
cli::cli_alert_info(
"Running psuedo-bulk DEG on: {.val {levels(splitBy)[i]}}"
)
}

subIdx <- splitBy == levels(splitBy)[i]
subCellIdx <- allCellIdx[subIdx]
groups <- split(subCellIdx, conditionBy[subIdx])
result[[levels(splitBy)[i]]] <- .runDEG(
object, groups = groups, method = method, usePeak = usePeak,
useReplicate = useReplicate, nPsdRep = nPsdRep,
minCellPerRep = minCellPerRep, seed = seed, verbose = verbose
result[[levels(splitBy)[i]]] <- tryCatch(
{
.runDEG(
object, groups = groups, method = method,
usePeak = usePeak, useReplicate = useReplicate,
nPsdRep = nPsdRep, minCellPerRep = minCellPerRep,
seed = seed, verbose = verbose
)
},
error = function(e) {
cli::cli_alert_danger(
"Error when computing on {.val {levels(splitBy)[i]}}: {e$message}"
)
cli::cli_alert_warning(
"Empty result (NULL) returned for this test."
)
return(NULL)
}
)
}
}
Expand Down
14 changes: 8 additions & 6 deletions R/visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -702,22 +702,24 @@ plotProportionBox <- function(
fill = .data[[conditionBy]]
)
else ggplot2::aes(
x = .data[[conditionBy]],
x = .data[[useCluster]],
y = .data[["Proportion"]]
)
)
) +
(if (isTRUE(dot))
) + (
if (isTRUE(dot))
ggplot2::geom_point(
size = dotSize,
color = "black",
position =
if (isTRUE(dotJitter)) ggplot2::position_jitter()
else "identity"
)
else
NULL) +
ggplot2::geom_boxplot()
else
NULL
) +
ggplot2::geom_boxplot() +
ggplot2::ggtitle(paste0(useCluster, ": ", cluster))
return(.ggplotLigerTheme(p, ...))
})
names(plist) <- levels(clusterVar)
Expand Down

0 comments on commit 16351ec

Please sign in to comment.