Skip to contents

Subset a Seurat object while making sure that the spatial data (images and spot coordinates) are handled correctly.

Usage

SubsetSTData(object, expression, spots = NULL, features = NULL, idents = NULL)

Arguments

object

A Seurat object

expression

Logical expression indicating features/variables to keep

spots

A vector of spots to keep

features

A vector of features to keep

idents

A vector of identity classes to keep

Value

A filtered Seurat object

Details

If you use the default subset function you will most likely not be able to use any of the semla visualization methods on the output object as the Staffli object will be broken. The exception is when filtering is only done at the feature level.

See also

Other subset-and-merge: MergeSTData()

Author

Ludvig Larsson

Examples


se_mbrain <- readRDS(system.file("extdata", "mousebrain/se_mbrain", package = "semla"))

# Create Seurat object
se_mbrain <- se_mbrain |> LoadImages()
#> 
#> ── Loading H&E images ──
#> 
#>  Loading image from /private/var/folders/91/twz8ld_x3f98sr9yc2hq9xpn47blx2/T/RtmpQDm3p7/temp_libpathed1b712617f8/semla/extdata/mousebrain/spatial/tissue_lowres_image.jpg
#>  Scaled image from 600x565 to 400x377 pixels
#>  Saving loaded H&E images as 'rasters' in Seurat object
se_mbrain
#> An object of class Seurat 
#> 188 features across 2560 samples within 1 assay 
#> Active assay: Spatial (188 features, 170 variable features)

# Subset by spot IDs (first 100)
se_fewspots <- SubsetSTData(se_mbrain, spots = colnames(se_mbrain)[1:1000])
se_fewspots
#> An object of class Seurat 
#> 188 features across 1000 samples within 1 assay 
#> Active assay: Spatial (188 features, 170 variable features)

# Subset by feature IDs (first 50)
se_fewgenes <- SubsetSTData(se_mbrain, features = rownames(se_mbrain)[1:50])
se_fewgenes
#> An object of class Seurat 
#> 50 features across 2560 samples within 1 assay 
#> Active assay: Spatial (50 features, 38 variable features)

# Subset using an expression
se_filtered <- SubsetSTData(se_mbrain, expression = nFeature_Spatial > 20)
se_filtered
#> An object of class Seurat 
#> 188 features across 2550 samples within 1 assay 
#> Active assay: Spatial (188 features, 170 variable features)