Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
vertesy committed Jun 22, 2024
1 parent c0bdbda commit 3eb9479
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
6 changes: 2 additions & 4 deletions R/Seurat.Utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1183,14 +1183,13 @@ GetClusteringRuns <- function(obj = combined.obj,

clustering.results <- sort(CodeAndRoll2::grepv(x = colnames(obj@meta.data), pattern = pat))

if (identical(clustering.results, character(0))) warning("No matching (simple) clustering column found!", immediate. = TRUE)
if (identical(clustering.results, character(0))) if(v) warning("No matching (simple) clustering column found!", immediate. = TRUE)

if(v) {
message("Clustering runs found:")
dput(clustering.results)
}


return(clustering.results)
}

Expand Down Expand Up @@ -1227,8 +1226,7 @@ GetNamedClusteringRuns <- function(
clustering.results <- CodeAndRoll2::grepv(x = colnames(obj@meta.data), pattern = pat)

if (identical(clustering.results, character(0))) {
warning("No matching (named) clustering column found! Trying GetClusteringRuns(..., pat = '*_res.*[0,1]\\.[0-9]$)",
immediate. = TRUE )
if(v) warning("No matching (named) clustering column found! Trying GetClusteringRuns(..., pat = '*_res.*[0,1]\\.[0-9]$)", immediate. = TRUE )
if (find.alternatives) clustering.results <-
GetClusteringRuns(obj = obj, res = FALSE, pat = "*_res.*[0,1]\\.[0-9]$", v = F)
}
Expand Down
30 changes: 14 additions & 16 deletions R/Seurat.Utils.Visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ plotGeneExprHistAcrossCells <- function(
slot_ %in% c("data", "counts")
)

# browser()

# Aggregate genes if necessary
aggregate <- length(genes) > 1
SummedExpressionPerCell <- colSums(GetAssayData(object = obj, assay = assay,
Expand Down Expand Up @@ -606,7 +606,7 @@ PctCellsAboveX <- function(obj = combined.obj,

# Calculate the percentage of cells above the threshold for each split_ident
Fraction.of.Cells.Above.Threshold <- sapply(ls_feat, function(x) sum(x > threshold) / length(x))
# browser()


if(box) {

Expand Down Expand Up @@ -1531,7 +1531,7 @@ getDiscretePaletteObj <- function(ident.used,
)

n.clusters <- CodeAndRoll2::nr.unique(obj[[ident.used]])
# browser()

colorz <- DiscretePaletteSafe(
n = n.clusters,
palette.used = palette.used,
Expand Down Expand Up @@ -2189,7 +2189,7 @@ clUMAP <- function(
} # overwrite, if directly defined

if (is.null(cols)) {
# browser()

cols <- if (NtCategs > max.cols.for.std.palette) {
getDiscretePaletteObj(
ident.used = ident, palette.used = palette,
Expand Down Expand Up @@ -2854,7 +2854,7 @@ qQC.plots.BrainOrg <- function(
message(kppws(n.found, " found: ", QC.Features.Found))
stopifnot(n.found > 1)

# browser()

# Count the number of NAs in specified columns
na_counts <- sapply(X = obj@meta.data[, QC.Features.Found], function(x) sum(is.na(x)))

Expand Down Expand Up @@ -3157,7 +3157,7 @@ scEnhancedVolcano <- function(
stopifnot(nrow(toptable) >5)

cat(1)
# browser()


# Filter min. cells expressing.
toptable <- toptable |> dplyr::filter(pct.1 > min.pct.cells | pct.2 > min.pct.cells)
Expand All @@ -3168,15 +3168,15 @@ scEnhancedVolcano <- function(
# Clip p-values.
toptable[["p_val_adj"]] <-
clip.at.fixed.value(distribution = toptable[["p_val_adj"]], thr = min.p, high = F)
cat(1)
cat(2)
# Clip log2FC.
if (max.l2fc < Inf) {
toptable[["avg_log2FC"]] <-
clip.at.fixed.value(distribution = toptable[["avg_log2FC"]], thr = -max.l2fc, high = F)
toptable[["avg_log2FC"]] <-
clip.at.fixed.value(distribution = toptable[["avg_log2FC"]], thr = max.l2fc, high = T)
}
cat(3)

# Add statistical information to the subtitle.
if (count_stats) {
enr_stats <- unlist(countRelevantEnrichments(df = toptable, logfc_col = x, pval_col = y,
Expand Down Expand Up @@ -3885,15 +3885,15 @@ plot3D.umap.gene <- function(
plotting.data <- obj@misc$reductions.backup$"umap3d"@cell.embeddings
colnames(plotting.data) <- toupper(col.names)

# browser()

Expression <- Seurat::FetchData(object = obj, vars = gene)
plotting.data <- cbind(plotting.data, Expression)

plotting.data$"Expression" <- ww.check.quantile.cutoff.and.clip.outliers(
expr.vec = plotting.data[, gene],
quantileCutoffX = quantileCutoff, min.cells.expressing = 10
)
# browser()

# CodeAndRoll2::clip.outliers.at.percentile(plotting.data[, gene], probs = c(1 - quantileCutoff, quantileCutoff))
plotting.data$"label" <- paste(rownames(plotting.data), " - ", plotting.data[, gene], sep = "")

Expand Down Expand Up @@ -3961,7 +3961,7 @@ plot3D.umap <- function(
message("category: ", category)
message("annotate.by: ", annotate.by)

# browser()


# Input assertions ____________________________________
stopifnot(
Expand Down Expand Up @@ -4372,25 +4372,23 @@ suPlotVariableFeatures <- function(obj = combined.obj, NrVarGenes = 15,

obj.name <- deparse(substitute(obj))

cat("1", "\n")
# browser()
plot1 <- Seurat::VariableFeaturePlot(obj, assay = assay) +
theme(panel.background = element_rect(fill = "white")) +
labs(title = "Variable Genes",
subtitle = kppws(obj.name, suffix),
caption = paste("Assay:", assay, "|", idate()))
cat("2", "\n")


# Assuming LabelPoints is defined elsewhere and available for use.
TopVarGenes <- VariableFeatures(obj, assay = assay)[1:NrVarGenes]
labeledPlot <- LabelPoints(
plot = plot1, points = TopVarGenes, repel = repel,
xnudge = 0, ynudge = 0, max.overlaps = 15
)
cat("3", "\n")

print(labeledPlot)
filename <- ppp("Var.genes", obj.name, suffix, idate(), "png")
cat("4", "\n")

# if (save) ggplot2::ggsave(plot = labeledPlot, filename = filename, width = plotWidth, height = plotHeight)
if (save) {
qqSave(
Expand Down

0 comments on commit 3eb9479

Please sign in to comment.