Skip to content

Commit

Permalink
bf qSeuViolin
Browse files Browse the repository at this point in the history
  • Loading branch information
vertesy committed Nov 18, 2024
1 parent 20f4d5d commit 5adfab8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion R/Seurat.Utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ filterExpressedGenes <- function(genes, gene_list = all.genes

# browser()
# Step 1: Intersect the gene symbols with the names in the list and report statistics
matching_genes <- CodeAndRoll2::intersect.w.Names(x = genes, y = names(gene_list), names = "x")
matching_genes <- CodeAndRoll2::intersect.wNames(x = genes, y = names(gene_list), names = "x")
message("Number of matching genes: ", length(matching_genes), " from ", length(genes)
, ". Missing: ", head(setdiff(genes, names(gene_list))), " ...")

Expand All @@ -1268,6 +1268,9 @@ filterExpressedGenes <- function(genes, gene_list = all.genes
return(filtered_genes)
}

# r$CodeAndRoll2()
# filterExpressedGenes(AstrocyteMarkers)




Expand Down
20 changes: 17 additions & 3 deletions R/Seurat.Utils.Visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,8 @@ qSeuViolin <- function(
obj,
feature = "nFeature_RNA",
ident = GetNamedClusteringRuns(obj = obj, v = FALSE)[1],
assay = "RNA",
slot = "data",
split.by = NULL,
colors = NULL,
clip.outliers = TRUE,
Expand Down Expand Up @@ -2006,6 +2008,17 @@ qSeuViolin <- function(
feature %in% colnames(obj@meta.data) || feature %in% rownames(obj)
)

is_meta_feature <- feature %in% colnames(obj@meta.data) # check if feature is in meta.data, otherwise it is a gene name

value_vector <-
if(is_meta_feature){
obj@meta.data[[feature]]
} else {
# Extract normalized expression values ("data" slot) from the RNA assay
GetAssayData(obj, assay = assay, slot = slot)[feature, ]
}


if (exists("idents")) warning("Use arg. ident instead of idents!\n", immediate. = TRUE)
if (exists("features")) warning("Use arg. feature instead of features!\n", immediate. = TRUE)

Expand All @@ -2024,14 +2037,14 @@ qSeuViolin <- function(

if (replace.na) {
warning("NA's are not, but zeros are displayed on the plot. Avoid replace.na when possible", immediate. = TRUE)
obj@meta.data[[feature]] <- na.replace(x = obj@meta.data[[feature]], replace = 0)
value_vector <- na.replace(x = value_vector, replace = 0)
}

# browser()

if (clip.outliers) {
warning("Outliers are clipped at percentiles 0.5% and 99.5%", immediate. = TRUE)
obj@meta.data[[feature]] <- CodeAndRoll2::clip.outliers.at.percentile(
x = obj@meta.data[[feature]], percentiles = c(.005, .995)
x = value_vector, percentiles = c(.005, .995)
)
}

Expand All @@ -2041,6 +2054,7 @@ qSeuViolin <- function(
colors <- as.factor.numeric(sapply(split(col_long, split_col), unique))
stopifnot("colors cannot be uniquely split by ident. Set colors = NULL!" = length(colors) == length(unique(split_col)))
}
# browser()

p.obj <- Seurat::VlnPlot(
object = obj,
Expand Down
1 change: 1 addition & 0 deletions man/dot-replace_by_most_frequent_categories.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/matchBestIdentity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/qSeuViolin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5adfab8

Please sign in to comment.