-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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{ | ||
|
@@ -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) | ||
|
@@ -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' )) | ||
|
||
|
||
|
@@ -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 | ||
|
@@ -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) | ||
} | ||
|
@@ -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]$") | ||
|
@@ -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) | ||
} | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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]) | ||
|
||
|
@@ -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 | ||
|
@@ -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. # | ||
|
@@ -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() # | ||
|
@@ -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 | ||
, ...) | ||
} | ||
|
||
|
||
|
@@ -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) { | ||
|
@@ -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)) { | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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)) | ||
} | ||
|
||
|
||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.