Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
abel.vertesy committed Oct 11, 2023
1 parent 420500a commit d9b2e32
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Development/Create_the_Seurat.utils_Package.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
######################################################################################################
# Create_the_Seurat.utils_Package.R
######################################################################################################
# source("/Users/abel.vertesy/GitHub/Packages/Seurat.utils/Development/Create_the_Seurat.utils_Package.v0.1.R")
# source("~/GitHub/Packages/Seurat.utils/Development/Create_the_Seurat.utils_Package.v0.1.R")
# rm(list = ls(all.names = TRUE));
try(dev.off(), silent = TRUE)

Expand Down Expand Up @@ -58,6 +58,7 @@ if ( !dir.exists(RepositoryDir) ) { create(path = RepositoryDir, description = D
}



# go and write fun's ------------------------------------------------------------------------
# file.edit(Package_FnP)

Expand Down
3 changes: 2 additions & 1 deletion R/Seurat.Utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ recall.parameters <- function(obj = combined.obj, overwrite = FALSE) {
obj <- ww.get.1st.Seur.element(obj)

if ('p' %in% names(obj@misc)) {
if (!exists('p')) iprint("variable 'p' exits in the global namespace:", head(p))
if (exists('p')) iprint("variable 'p' exits in the global namespace:", head(p))

if (!exists('p') | (exists('p') & overwrite == TRUE) ) {
MarkdownHelpers::ww.assign_to_global(name = "p", value = obj@misc$'p'); print("Overwritten.")
Expand Down Expand Up @@ -3048,6 +3048,7 @@ multiFeaturePlot.A4 <- function(list.of.genes # Save multiple FeaturePlots, as j
, saveGeneList = FALSE
, w = wA4, h = hA4, scaling = 1
, format = c('jpg', 'pdf', 'png')[1]
# , solo = MarkdownHelpers::FALSE.unless('b.plot.solo')
, raster = MarkdownHelpers::FALSE.unless('b.raster')
, raster.dpi = c(512, 512)/4
, ...
Expand Down
84 changes: 84 additions & 0 deletions R/Test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@


plot.qUMAPs.in.a.folder <- function(genes, obj = combined.obj, foldername = NULL, intersectionAssay = 'RNA', plot.reduction = 'umap', ...) {

ParentDir = OutDir
if (is.null(foldername)) foldername = substitute(genes)
create_set_SubDir( paste0(foldername,'-', plot.reduction),'/')
list.of.genes.found = check.genes(list.of.genes = genes, obj = obj, assay.slot = intersectionAssay, makeuppercase = F)


for (g in list.of.genes.found) {
qUMAP(g, reduction = plot.reduction, ...)
}
MarkdownReports::create_set_OutDir(... = ParentDir)
}



multiFeaturePlot.A4 <- function(list.of.genes # Save multiple FeaturePlots, as jpeg, on A4 for each gene, which are stored as a list of gene names.
, obj = combined.obj
, foldername = substitute(list.of.genes), plot.reduction='umap'
, intersectionAssay = c('RNA', 'integrated')[1]
, layout = c('tall', 'wide', FALSE )[2]
, colors = c("grey", "red"), nr.Col = 2, nr.Row =4, cex = round(0.1/(nr.Col*nr.Row), digits = 2)
, gene.min.exp = 'q01', gene.max.exp = 'q99', subdir =T
, prefix = NULL , suffix = NULL
, background_col = "white"
, aspect.ratio = c(FALSE, 0.6)[2]
, saveGeneList = FALSE
, w = wA4, h = hA4, scaling = 1
, format = c('jpg', 'pdf', 'png')[1]
, solo = MarkdownHelpers::FALSE.unless('b.solo.plot')
, raster = MarkdownHelpers::FALSE.unless('b.raster')
, raster.dpi = c(512, 512)/4
, ...
# , jpeg.res = 225, jpeg.q = 90
) {
tictoc::tic()
ParentDir = OutDir
if (is.null(foldername)) foldername = "genes"
if (subdir) create_set_SubDir( paste0(foldername,'-', plot.reduction),'/')
list.of.genes.found = check.genes(list.of.genes = list.of.genes, obj = obj, assay.slot = intersectionAssay, makeuppercase = F)
DefaultAssay(obj) <- intersectionAssay

if (layout == 'tall') { w = wA4 * scaling; h = hA4 * scaling; nr.Col = 2; nr.Row = 4; print('layout active, nr.Col ignored.') }
if (layout == 'wide') { w = hA4 * scaling; h = wA4 * scaling; nr.Col = 2; nr.Row = 2; print('layout active, nr.Col ignored.') }

lsG = iterBy.over(1:length(list.of.genes.found), by = nr.Row * nr.Col)
for (i in 1:length(lsG)) {
genes = list.of.genes.found[lsG[[i]]]
iprint(i,genes )
plotname = kpp(c(prefix, plot.reduction,i, genes, suffix, format ))

if (solo) {


} else {
plot.list = Seurat::FeaturePlot(object = obj, features = genes, reduction = plot.reduction, combine = F
, ncol = nr.Col, cols = colors
, min.cutoff = gene.min.exp, max.cutoff = gene.max.exp
, raster = TRUE, raster.dpi = raster.dpi
, pt.size = cex, ...)

for (i in 1:length(plot.list)) {
plot.list[[i]] <- plot.list[[i]] + NoLegend() + NoAxes()
if (aspect.ratio) plot.list[[i]] <- plot.list[[i]] + ggplot2::coord_fixed(ratio = aspect.ratio)
}

pltGrid <- cowplot::plot_grid(plotlist = plot.list, ncol = nr.Col, nrow = nr.Row )
ggsave(filename = plotname, width = w, height = h, bg = background_col, plot = pltGrid)
}
}


if (subdir) MarkdownReports::create_set_OutDir(... = ParentDir)
if (saveGeneList) {
if (is.null(obj@misc$gene.lists)) obj@misc$gene.lists <- list()
obj@misc$gene.lists[[substitute(list.of.genes)]] <- list.of.genes.found
print("Genes saved under: obj@misc$gene.lists")
return(obj)
}
tictoc::toc()
};

5 changes: 5 additions & 0 deletions Seurat.utils.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix
Expand Down

0 comments on commit d9b2e32

Please sign in to comment.