Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I subset a Xenium SeuratObject based on gene list #8461

Open
An17aV0 opened this issue Feb 12, 2024 Discussed in #8459 · 1 comment
Open

How do I subset a Xenium SeuratObject based on gene list #8461

An17aV0 opened this issue Feb 12, 2024 Discussed in #8459 · 1 comment

Comments

@An17aV0
Copy link

An17aV0 commented Feb 12, 2024

Discussed in #8459

Originally posted by An17aV0 February 12, 2024
Hello everyone!
I would like to subset my data based on the genes in the 10X gene panel and my custom gene panel and analyze them separately. I am using the subset function like this xenium.obj.subset <- subset(xenium.obj, features = keep.genes)

The number of features (genes) is reduced after subsetting but it appears the expression data and coordinates are still present in the new object.

Below is a reproducible example where I am removing 4 genes from the "mouse-brain-10x-genomics-xenium-in-situ " and then plot these 4 genes as molecules in ImageDimPlot before and after subsetting. The plots look basically the same although after subsetting these 4 features should not be present anymore. I also get a couple of warnings while subsetting
such as : 1: Not validating FOV objects 2: Not validating Centroids objects ... 9: Not validating Seurat objects

1.) How do I accurately subset the SeuratObject and resolve those warnings?
2.) On a side note, how do I deal with the signal detected outside the tissue (as visible in the Images below)?

Thank you, any help is very much appreciated.

Data and most code from here: https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2#mouse-brain-10x-genomics-xenium-in-situ

wget https://cf.10xgenomics.com/samples/xenium/1.0.2/Xenium_V1_FF_Mouse_Brain_Coronal_Subset_CTX_HP/Xenium_V1_FF_Mouse_Brain_Coronal_Subset_CTX_HP_outs.zip
unzip Xenium_V1_FF_Mouse_Brain_Coronal_Subset_CTX_HP_outs.zip

Load the Xenium data

xenium.obj <- LoadXenium("Xenium_V1_FF_Mouse_Brain_Coronal_Subset_CTX_HP_outs", fov = "fov")
Output: 10X data contains more than one type and is being returned as a list containing matrices of each type.
Output: Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')

Remove cells with 0 counts

xenium.obj <- subset(xenium.obj, subset = nCount_Xenium > 0)
Output: Warning messages:
#1: Not validating FOV objects
#2: Not validating Centroids objects
[...]
#9: Not validating Seurat objects

dim(xenium.obj) # [1] 248 36553

Remove 4 genes

molecules.to.remove = c("Gad1", "Sst", "Pvalb", "Gfap")
all.features <-Features(xenium.obj) # grab all genes from the Seurat object
length(all.features) # [1] 248

keep.genes <- all.features[!all.features %in% molecules.to.remove]
length(keep.genes) # [1] 244

Subset Seurat object

xenium.obj.subset <- subset(xenium.obj, features = keep.genes)
Output: Warning messages:
#1: Not validating FOV objects
#2: Not validating Centroids objects
[...]
#9: Not validating Seurat objects

dim(xenium.obj.subset) # [1] 244 36553

Plot data before and after subsetting

plot.xenium.obj <- ImageDimPlot(xenium.obj, fov = "fov", molecules = c("Gad1", "Sst", "Pvalb", "Gfap"), nmols = 20000)+ggtitle("Before")

plot.xenium.obj.subset <- ImageDimPlot(xenium.obj.subset, fov = "fov", molecules = c("Gad1", "Sst", "Pvalb", "Gfap"), nmols = 20000) +ggtitle("After subsetting")

ggarrange(plot.xenium.obj, plot.xenium.obj.subset)

Screenshot 2024-02-11 at 11 41 53 PM
@alikhuseynov
Copy link

Hi, this can help I hope, though it's a temporary solution. Also check this discussion #7462
this would be the run:
xenium.obj.subset <- subset_opt(xenium.obj, features = keep.genes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants