Skip to content

Commit

Permalink
Sync with NIDAP Global code, 2024-05-31
Browse files Browse the repository at this point in the history
  • Loading branch information
lobanovav authored Jun 3, 2024
1 parent 7cba94e commit e3bcb53
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions R/Filter_Seurat_Object_by_Metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ filterSeuratObjectByMetadata <- function(object,
## --------------- ##





## --------------- ##
## Functions ##
## --------------- ##
Expand Down Expand Up @@ -216,7 +213,7 @@ filterSeuratObjectByMetadata <- function(object,
xlab("umap-1") + ylab("umap-2")
return(plot2)
}

.distinctColorPalette <- function(k = 1, seed) {
current.color.space <- our.color.space@coords
# Set iter.max to 20 to avoid convergence warnings.
Expand Down Expand Up @@ -264,12 +261,12 @@ filterSeuratObjectByMetadata <- function(object,

## Get colors from user parameter and add more if the default list is too short.
if (class(object@meta.data[[category.to.filter[1]]]) != "numeric") {
col.length = length(levels(as.factor(Filter.orig[colname])))
col.length = length(levels(as.factor(Filter.orig)))
if (length(colors) < col.length) {
more.cols = .distinctColorPalette(col.length - length(colors), 10)
colors <- c(colors, more.cols)
}
names(colors) <- levels(as.factor(Filter.orig[colname]))
names(colors) <- levels(as.factor(Filter.orig))

## Keep or remove cells based on user input values.
if (keep.or.remove) {
Expand Down Expand Up @@ -316,14 +313,16 @@ filterSeuratObjectByMetadata <- function(object,
## Make before and after plots.
title <-
paste0("filtered by ",
category.to.filter[1],
" and split by ",
category.to.filter[2])
category.to.filter[1]#,
## " and split by ",
## category.to.filter[2]
)
plot1 = DimPlot(
object,
reduction = reduction,
group.by = colname,
pt.size = dot.size
pt.size = dot.size,
raster=FALSE
) +
theme_classic() +
scale_color_manual(values = colors) +
Expand All @@ -338,7 +337,8 @@ filterSeuratObjectByMetadata <- function(object,
reduction = reduction,
cells.highlight = idx,
cols.highlight = rev(cols2[1:filt.length]),
sizes.highlight = dot.size.highlighted.cells
sizes.highlight = dot.size.highlighted.cells,
raster=FALSE
) +
theme_classic() +
theme(legend.position = legend.position) +
Expand Down Expand Up @@ -389,7 +389,7 @@ filterSeuratObjectByMetadata <- function(object,

}



result.list <- list("object" = SO.sub,
"plot1" = plot1,
Expand Down

0 comments on commit e3bcb53

Please sign in to comment.