Skip to content
Snippets Groups Projects
Commit f9ec40ba authored by Gilquin's avatar Gilquin
Browse files

feat: change default behavior of visualize_markers

parent 466069c0
No related branches found
No related tags found
No related merge requests found
......@@ -405,6 +405,8 @@ visualize_markers <- function(
height = 8,
...
){
# catch extra arguments
extra_args <- list(...)
# define colormap
cmap <- get(colormap, envir = loadNamespace("pals"))
cols <- unname(cmap(nlevels(object@active.ident)))
......@@ -418,34 +420,52 @@ visualize_markers <- function(
ifelse(!dir.exists(file.path(savedir, subdir)),
dir.create(file.path(savedir, subdir), recursive=TRUE),
FALSE)
# save the violin plot
filepath <- file.path(savedir, subdir, prefix)
gg <- suppressMessages(
VlnPlot(object, features = features, pt.size = 0, cols = cols)
for (feat in features){
filepath <- file.path(savedir, subdir, feat)
vln_args <- c(
list("object" = object, "features" = feat, "pt.size" = 0, "cols" = cols),
extra_args[names(extra_args) %in% names(as.list(args(VlnPlot)))]
)
gg <- suppressMessages(do.call(VlnPlot, vln_args))
ggsave(file=paste0(filepath, "_vlnplot", ".", device), device = device,
width = width, height = width, gg, ...)
width = width, height = width, gg)
}
# save the feature plot with custom gradient
max_cmap <- SeuratObject::FetchData(
object = object,
vars = features,
slot = "data"
) %>% max()
for (feat in features){
filepath <- file.path(savedir, subdir, feat)
feat_args <- c(
list("object" = object, "features" = feat),
extra_args[names(extra_args) %in% names(as.list(args(FeaturePlot)))]
)
gg <- suppressMessages(
FeaturePlot(object, features = features) &
do.call(FeaturePlot, feat_args) &
scale_color_gradientn(
colors = cmap_vir, limits = c(na_cutoff, NA), na.value = na_color)
colors = cmap_vir, limits = c(na_cutoff, max_cmap), na.value = na_color)
)
ggsave(file=paste0(filepath, "_featplot", ".", device), device = device,
width = width, height = height, gg, ...)
width = width, height = height, gg)
}
# save the dot plot with custom gradient
filepath <- file.path(savedir, subdir, prefix)
dot_args <- c(
list("object" = object, "features" = features),
extra_args[names(extra_args) %in% names(as.list(args(DotPlot)))]
)
gg <- suppressWarnings(suppressMessages(
DotPlot(object, features = features) &
do.call(DotPlot, dot_args) &
theme_custom() &
scale_x_discrete(guide = guide_axis(n.dodge = 2)) &
scale_color_gradientn(
colors = cmap_vir, limits = c(na_cutoff, NA), na.value = na_color)
))
ggsave(file=paste0(filepath, "_dotplot", ".", device), device = device,
width = width, height = height, gg, ...)
width = width, height = height, gg)
return(NULL)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment