Skip to content

Commit

Permalink
v1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vertesy committed Nov 30, 2021
1 parent 33e4872 commit f411c73
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 30 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Seurat.utils
Title: Seurat.utils - utility functions for Seurat
Version: 1.2.2
Version: 1.2.3
Authors@R:
person("Abel", "Vertesy", , "[email protected]", role = c("aut", "cre"))
Author: Abel Vertesy <[email protected]> [aut, cre]
Expand Down Expand Up @@ -50,7 +50,7 @@ Imports:
Suggests:
SoupX
Encoding: UTF-8
Packaged: 2021-11-27 23:09:18
Packaged: 2021-11-30 23:24:31
Repository: CRAN
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
2 changes: 1 addition & 1 deletion Development/Create_the_Seurat.utils_Package.v0.1.0.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ DESCRIPTION <- list("Title" = "Seurat.utils - utility functions for Seurat"
Functions allow the automation / multiplexing of plotting, 3D plotting, visualisation of statistics &
QC, interaction with the Seurat object, etc. Some functionalities require functions from CodeAndRoll and MarkdownReports libraries."
, "License" = "GPL-3 + file LICENSE"
, "Version" = "1.2.2"
, "Version" = "1.2.3"
, "Packaged" = Sys.time()
, "Repository" = "CRAN"
, "Depends" = "Stringendo, CodeAndRoll2, ggExpress, ggplot2"
Expand Down
75 changes: 51 additions & 24 deletions Development/Development.bac
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SmallestNonAboveX <- function(vec, X = 0) { # replace small values with the next
#' @param p_val_min PARAM_DESCRIPTION, Default: 1e-25
#' @param pval_scaling PARAM_DESCRIPTION, Default: 0.001
#' @param colP PARAM_DESCRIPTION, Default: 'p_val'
#' @param colLFC PARAM_DESCRIPTION, Default: grepv(pattern = c("avg_logFC|avg_log2FC"), x = colnames(df),
#' @param colLFC PARAM_DESCRIPTION, Default: CodeAndRoll2::grepv(pattern = c("avg_logFC|avg_log2FC"), x = colnames(df),
#' perl = T)
#' @examples
#' \dontrun{
Expand All @@ -48,7 +48,7 @@ SmallestNonAboveX <- function(vec, X = 0) { # replace small values with the next
#' }
#' @export
Add.DE.combined.score <- function(df = df.markers, p_val_min = 1e-25, pval_scaling = 0.001, colP = "p_val"
, colLFC = grepv(pattern = c("avg_logFC|avg_log2FC"), x = colnames(df), perl = T)
, colLFC = CodeAndRoll2::grepv(pattern = c("avg_logFC|avg_log2FC"), x = colnames(df), perl = T)
# , colLFC = "avg_log2FC"
) { # Score = -LOG10(p_val) * avg_log2FC
p_cutoff <- SmallestNonAboveX(vec = df[[colP]], X = p_val_min)
Expand Down Expand Up @@ -253,7 +253,7 @@ AutoLabel.KnownMarkers <- function(obj = combined.obj, topN =1, res = 0.5 # Crea
, df_markers = obj@misc$"df.markers"[[paste0("res.",res)]] ) {
stopifnot(!is.null("df_markers"))

lfcCOL <- grepv(pattern = c("avg_logFC|avg_log2FC"), x = colnames(df_markers), perl = T)
lfcCOL <- CodeAndRoll2::grepv(pattern = c("avg_logFC|avg_log2FC"), x = colnames(df_markers), perl = T)
keep <- unique(c(lfcCOL, 'p_val_adj', 'cluster', order.by, 'gene' ))


Expand Down Expand Up @@ -684,7 +684,7 @@ add.meta.fraction <- function(col.name = "percent.mito", gene.symbol.pattern = c

geneset <- check.genes(list.of.genes = gene.set, obj = obj)
total_expr <- Matrix::colSums(GetAssayData(object = obj))
genes.matching <- if (!isFALSE(gene.set)) intersect(gene.set, rownames(obj)) else grepv(pattern = gene.symbol.pattern, x = rownames(obj))
genes.matching <- if (!isFALSE(gene.set)) intersect(gene.set, rownames(obj)) else CodeAndRoll2::grepv(pattern = gene.symbol.pattern, x = rownames(obj))

genes.expr = GetAssayData(object = obj)[genes.matching, ]
target_expr <- if (length(genes.matching) >1) Matrix::colSums(genes.expr) else genes.expr
Expand Down Expand Up @@ -712,7 +712,7 @@ add.meta.fraction <- function(col.name = "percent.mito", gene.symbol.pattern = c
#' @export
GetClusteringRuns <- function(obj = combined.obj, res = F, pat = "*snn_res.*[0-9]$") { # Get Clustering Runs: metadata column names
if (res) pat = gsub(x = pat, pattern = '\\[.*\\]', replacement = res)
clustering.results <- grepv(x = colnames([email protected]), pattern = pat)
clustering.results <- CodeAndRoll2::grepv(x = colnames([email protected]), pattern = pat)
if ( identical(clustering.results, character(0)) ) warning("No matching column found!")
return(clustering.results)
}
Expand All @@ -737,7 +737,7 @@ GetNamedClusteringRuns <- function(obj = combined.obj # Get Clustering Runs: me
, res = c(F, 0.5)[1], topgene = F, pat = "^cl.names.Known.*[0,1]\\.[0-9]$") {
if (res) pat = gsub(x = pat, pattern = '\\[.*\\]', replacement = res)
if (topgene) pat = gsub(x = pat, pattern = 'Known', replacement = 'top')
clustering.results <- grepv(x = colnames([email protected]), pattern = pat)
clustering.results <- CodeAndRoll2::grepv(x = colnames([email protected]), pattern = pat)
if ( identical(clustering.results, character(0)) ) {
print("Warning: NO matching column found! Trying GetClusteringRuns(..., pat = '*_res.*[0,1]\\.[0-9]$)")
clustering.results <- GetClusteringRuns(obj = obj, res = F, pat = "*_res.*[0,1]\\.[0-9]$")
Expand All @@ -762,7 +762,7 @@ GetNamedClusteringRuns <- function(obj = combined.obj # Get Clustering Runs: me
#' @export
GetOrderedClusteringRuns <- function(obj = combined.obj, res = F, pat = "*snn_res.*[0,1]\\.[0-9]\\.ordered$") { # Get Clustering Runs: metadata column names
if (res) pat = gsub(x = pat, pattern = '\\[.*\\]', replacement = res)
clustering.results <- grepv(x = colnames([email protected]), pattern = pat)
clustering.results <- CodeAndRoll2::grepv(x = colnames([email protected]), pattern = pat)
if ( identical(clustering.results, character(0)) ) warning("No matching column found!")
return(clustering.results)
}
Expand Down Expand Up @@ -944,6 +944,7 @@ seu.map.and.add.new.ident.to.meta <- function(obj = combined.obj, ident.table =
#' }
#' @export
#' @importFrom Stringendo percentage_formatter

calc.cluster.averages <- function(col_name = "Score.GO.0006096"
, plot.UMAP.too = TRUE
, return.plot = F
Expand All @@ -959,6 +960,7 @@ calc.cluster.averages <- function(col_name = "Score.GO.0006096"
, filter = c(FALSE, 'above', 'below')[1]
, ylab.text = paste("Cluster", stat, "score")
, title = paste("Cluster", stat, col_name)
, prefix.cl.names= FALSE
, report = TRUE
, subtitle = NULL
, width = 8, height =6
Expand Down Expand Up @@ -990,7 +992,7 @@ calc.cluster.averages <- function(col_name = "Score.GO.0006096"

if (simplify) {
av.score <- df.summary[[stat]]
names(av.score) <- ppp("cl",df.summary[[1]])
names(av.score) <- if ( !isFALSE(prefix.cl.names)) ppp("cl",df.summary[[1]]) else df.summary[[1]]
av.score <- sortbyitsnames(av.score)
if (scale.zscore) av.score <- (scale(av.score)[,1])

Expand Down Expand Up @@ -1018,7 +1020,7 @@ calc.cluster.averages <- function(col_name = "Score.GO.0006096"
} else {
p <- qbarplot(vec = av.score, save = F
, hline = cutoff
, title = title
, plotname = title
, suffix = quantile.thr
, subtitle = subtitle
, ylab = ylab.text
Expand Down Expand Up @@ -1050,6 +1052,7 @@ calc.cluster.averages <- function(col_name = "Score.GO.0006096"
}
}


# _________________________________________________________________________________________________
#' @title seu.add.meta.from.table
#' @description Add multiple new metadata columns to a Seurat object from a table. #
Expand Down Expand Up @@ -1220,6 +1223,25 @@ fix.orig.ident <- function(obj = merged.obj) {
set.all.genes <- function(obj = combined.obj) iprint("Use calc.q90.Expression.and.set.all.genes()")



# _________________________________________________________________________________________________
#' @title set.mm
#' @description Helps to find metadata columns. It creates a list with the names of of '[email protected]'.
#' @param obj Seurat object, Default: combined.obj
#' @examples
#' \dontrun{
#' if(interactive()){
#' set.mm(); mm
#' }
#' }
#' @export
set.mm <- function(obj = combined.obj) {
mm <- CodeAndRoll2::list.fromNames(colnames([email protected]))
assign(x = 'mm', value = mm, envir = as.environment(1))
}



# _________________________________________________________________________________________________
#' @title recall.all.genes
#' @description all.genes set by calc.q90.Expression.and.set.all.genes() #
Expand Down Expand Up @@ -3296,14 +3318,17 @@ CellFractionsBarplot2 <- function(obj = combined.obj
#' }
#' }
#' @export barplot.cells.per.cluster
barplot.cells.per.cluster <- function(obj = combined.obj, ident = "cl.names.KnownMarkers.0.5", sort = F) {
barplot.cells.per.cluster <- function(obj = combined.obj
, ident = "cl.names.KnownMarkers.0.5"
, sort = F, ...) {
cell.per.cluster <- (table(obj[[ident]][,1]))
if (sort) cell.per.cluster <- sort(cell.per.cluster)
qbarplot(cell.per.cluster, subtitle = ident, suffix = ident
, col = rainbow(length(cell.per.cluster))
, xlab.angle = 45
# , col = getClusterColors(ident = ident, show = T)
, palette_use = NULL, )
, palette_use = NULL
, ...)
}


Expand Down Expand Up @@ -3606,7 +3631,7 @@ plot.Gene.Cor.Heatmap <- function(genes = WU.2017.139.IEGsf

if (is.null(cor.mat)) {
iprint(slotname_cor.mat, " not found in @misc.")
iprint("Correlation slots present in @misc:",grepv(names(obj@misc), pattern = "^cor"))
iprint("Correlation slots present in @misc:", CodeAndRoll2::grepv(names(obj@misc), pattern = "^cor"))

# Calculate ------------------------------------
if (calc.COR) {
Expand Down Expand Up @@ -3904,7 +3929,7 @@ Convert10Xfolders <- function(InputDir # Take a parent directory with a number o

# finOrig <- list.dirs(InputDir, recursive = subdirs)
finOrig <- list.dirs.depth.n(InputDir, depth = 2)
fin <- grepv(x = finOrig, pattern = folderPattern, perl = regex)
fin <- CodeAndRoll2::grepv(x = finOrig, pattern = folderPattern, perl = regex)

iprint(length(fin), "samples found.")
if (length(fin)) {
Expand Down Expand Up @@ -3960,7 +3985,7 @@ Convert10Xfolders.old <- function(InputDir # Take a parent directory with a numb
, folderPattern = c("filtered", "SoupX_decont")[1]
, min.cells = 10, min.features = 200, updateHGNC = T, ShowStats = T) {
fin <- list.dirs(InputDir, recursive = F)
fin <- grepv(x = fin, pattern = folderPattern, perl = F)
fin <- CodeAndRoll2::grepv(x = fin, pattern = folderPattern, perl = F)

for (i in 1:length(fin)) {
pathIN = fin[i]; print(pathIN)
Expand Down Expand Up @@ -4021,7 +4046,7 @@ ConvertDropSeqfolders <- function(InputDir # Take a parent directory with a numb
, min.cells = 10, min.features = 200, updateHGNC = T, ShowStats = T, minDimension = 10, overwrite = FALSE) {
InputDir <- FixPath(InputDir)
fin <- list.dirs(InputDir, recursive = F)
fin <- grepv(x = fin, pattern = folderPattern, perl = F)
fin <- CodeAndRoll2::grepv(x = fin, pattern = folderPattern, perl = F)

for (i in 1:length(fin)) { print(i)
pathIN <- FixPath(fin[i]); print(pathIN)
Expand Down Expand Up @@ -4450,21 +4475,21 @@ gene.name.check <- function(Seu.obj = ls.Seurat[[1]] ) { # Check gene names in a
llprint("### Gene name pattern")

llogit('`rn = rownames(GetAssayData(object = ls.Seurat[[1]], slot = "counts"))`')
llogit('`head(grepv(rn, pattern = "-"), 10)`')
llogit('`head(CodeAndRoll2::grepv(rn, pattern = "-"), 10)`')
print('pattern = -')
llprint(head(grepv(rn, pattern = "-"), 10))
llprint(head(CodeAndRoll2::grepv(rn, pattern = "-"), 10))

llogit('`head(grepv(rn, pattern = "_"), 10)`')
llogit('`head(CodeAndRoll2::grepv(rn, pattern = "_"), 10)`')
print('pattern = _')
llprint(head(grepv(rn, pattern = "_"), 10))
llprint(head(CodeAndRoll2::grepv(rn, pattern = "_"), 10))

llogit('`head(grepv(rn, pattern = "\\."), 10)`')
llogit('`head(CodeAndRoll2::grepv(rn, pattern = "\\."), 10)`')
print('pattern = \\.')
llprint(head(grepv(rn, pattern = "\\."), 10))
llprint(head(CodeAndRoll2::grepv(rn, pattern = "\\."), 10))

llogit('`head(grepv(rn, pattern = "\\.AS[1-9]"), 10)`')
llogit('`head(CodeAndRoll2::grepv(rn, pattern = "\\.AS[1-9]"), 10)`')
print('pattern = \\.AS[1-9]')
llprint(head(grepv(rn, pattern = "\\.AS[1-9]"), 10))
llprint(head(CodeAndRoll2::grepv(rn, pattern = "\\.AS[1-9]"), 10))
}


Expand Down Expand Up @@ -5040,7 +5065,7 @@ plotTheSoup <- function(CellRangerOutputDir = "~/Data/114593/114593"
soup.LINC.sum <- sum(soupProfile[grep('^LINC', names(soupProfile))])
soup.AC.sum <- sum(soupProfile[grep('^AC', names(soupProfile))])
soup.AL.sum <- sum(soupProfile[grep('^AL', names(soupProfile))])
genes.non.Above <- soupProfile[grepv('^RPL|^RPS|^MT-|^LINC|^AC|^AL', names(soupProfile), invert = T)]
genes.non.Above <- soupProfile[CodeAndRoll2::grepv('^RPL|^RPS|^MT-|^LINC|^AC|^AL', names(soupProfile), invert = T)]
}
head(sort(genes.non.Above), n = 50)

Expand Down Expand Up @@ -5235,3 +5260,5 @@ parallel.computing.by.future <- function(workers_ = 6, maxMemSize = 4000 * 1024^
# So to set Max mem size to 2GB, you would run :
options(future.globals.maxSize = maxMemSize)
}


1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export(saveRDS.compress.in.BG)
export(scBarplotFractionAboveThr)
export(scBarplotFractionBelowThr)
export(set.all.genes)
export(set.mm)
export(seu.Make.Cl.Label.per.cell)
export(seu.PC.var.explained)
export(seu.add.meta.from.table)
Expand Down
5 changes: 3 additions & 2 deletions man/Add.DE.combined.score.Rd

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

2 changes: 1 addition & 1 deletion man/barplot.cells.per.cluster.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/calc.cluster.averages.Rd

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

21 changes: 21 additions & 0 deletions man/set.mm.Rd

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

0 comments on commit f411c73

Please sign in to comment.