Subset 10x Visium data
subset.Rd
Subset a Seurat
object while making sure that the spatial data
(images and spot coordinates) are handled correctly.
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()
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/8r/bfm2m_q17znfk0m_8dt330tm0000gp/T/RtmpLHpYU7/temp_libpath305b1609463d/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)