Skip to content

Commit

Permalink
Updated vignette for different versions of Seurat
Browse files Browse the repository at this point in the history
  • Loading branch information
vdsukhov committed Oct 7, 2024
1 parent 2f27248 commit 077afd8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 5 additions & 2 deletions R/geseca-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ plotCoregulationProfileSpatial <- function(pathway,
title=NULL,
assay=DefaultAssay(object),
colors=c("darkblue", "lightgrey", "darkred"),
guide="colourbar", ...) {
guide="colourbar",
image.alpha = 0,
...) {
stopifnot(requireNamespace("Seurat"))
# TODO duplicated code with plotCoregulationProfileReduction
if (is.list(pathway)) {
Expand All @@ -286,6 +288,7 @@ plotCoregulationProfileSpatial <- function(pathway,
title = titles[i],
assay = assay,
colors = colors,
image.alpha = image.alpha,
...))
names(ps) <- names(pathway)
ps <- unlist(ps, recursive = FALSE)
Expand All @@ -296,7 +299,7 @@ plotCoregulationProfileSpatial <- function(pathway,
obj2 <- addGesecaScores(list(pathway = pathway), object,
assay = assay, scale = TRUE)
ps <- Seurat::SpatialFeaturePlot(obj2, features = "pathway",
combine = FALSE, image.alpha = 0, ...)
combine = FALSE, image.alpha = image.alpha, ...)
# suppress message of replacing existing color palette
suppressMessages(ps <- lapply(ps, function(p){
res <- p + scale_fill_gradientn(limits = c(-3, 3),
Expand Down
6 changes: 6 additions & 0 deletions vignettes/fgsea-tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,9 @@ bg <- names(exampleRanks)
foraRes <- fora(genes=fg, universe=bg, pathways=examplePathways)
head(foraRes)
```

## Session info

```{r}
sessionInfo()
```
23 changes: 21 additions & 2 deletions vignettes/geseca-tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,20 @@ Finally, let us plot spatial expression of the top four pathways:
topPathways <- gesecaRes[, pathway] |> head(4)
titles <- sub("HALLMARK_", "", topPathways)
pt.size.factor <- 1.6
# Starting from Seurat version 5.1.0, the scaling method for spatial plots was changed.
# As mentioned here: https://github.com/satijalab/seurat/issues/9049
# This code provides a workaround to adapt to the new scaling behavior.
if (packageVersion("Seurat") >= "5.1.0"){
sfactors <- ScaleFactors(obj@images$slice1)
pt.size.factor <- 1.5 * sfactors$fiducial / sfactors$hires
}
ps <- plotCoregulationProfileSpatial(pathways[topPathways], obj,
title=titles)
title=titles,
pt.size.factor=pt.size.factor)
cowplot::plot_grid(plotlist=ps, ncol=2)
```

Expand All @@ -363,8 +375,15 @@ is more characteristic to the "normal" tissue region:
```{r fig.width=5, fig.height=3.5, out.width="50%"}
plotCoregulationProfileSpatial(pathways$HALLMARK_OXIDATIVE_PHOSPHORYLATION,
obj,
title=sprintf("HALLMARK_OXIDATIVE_PHOSPHORYLATION (pval=%.2g)",
pt.size.factor=pt.size.factor,
title=sprintf("HALLMARK_OXIDATIVE_PHOSPHORYLATION\n(pval=%.2g)",
gesecaRes[
match("HALLMARK_OXIDATIVE_PHOSPHORYLATION", pathway),
pval]))
```

## Session info

```{r echo=TRUE}
sessionInfo()
```

0 comments on commit 077afd8

Please sign in to comment.