Seurat - unordered cells
0
0
Entering edit mode
19 days ago
solo.albif • 0

Hi all, I have a Seurat object from which I removed the data from the image slot before I performed an integration (by splitting the object):

# Save the spatial information to an object
spatial_information <- breast_cancer_patients_no_rbc@images
# Remove the spatial information from the new Seurat object
breast_cancer_patients_no_rbc_no_spatial@images <- list()
# Split the global Seurat object by patient
breast_cancer_patients_split <- SplitObject(breast_cancer_patients_no_rbc_no_spatial, split.by = "Patient.ID")

After performing the integration, merging all the subsets and other operations I added back the spatial data:

# Add back the spatial data
breast_cancer_patients_all_cells@images <- spatial_information

The problem is that setting the default boundary throws a warning:

DefaultBoundary(patient_data[[patient_image]]) <- "segmentation"

Warning message:
Adding image with unordered cells 

This seems to be because the order of the cells in the metadata is not the same as the order of the cells in the image slot. I tried to change the order in the metadata but then Seurat complains about a misalignment between the metadata and the assays. Reordering the centroids in the image slot also does not solve the problem. Do you know how I can fix this warning? The cells are the same because:

> identical(patient_data@images$LU001FFP03@boundaries$centroids@cells, rownames(patient_data@meta.data))
[1] TRUE

Thank you!

R Seurat • 382 views
ADD COMMENT
0
Entering edit mode

Have you tried reordering your cells in your spatial_information before importing it into breast_cancer_patients_all_cells ?

ADD REPLY
0
Entering edit mode

spatial_information (SeuratObject::FOV) is a rather complicated object which contains many other objects (like SeuratObject::Centroids and SeuratObject::Segmentation) and I can not find a way to sort it properly, this is what I tried (it does not work):

# Get current boundary centroids
boundaries_centroids <- breast_cancer_patients_all_cells@images$LU001FFP03@boundaries$centroids

# Reorder the centroids according to the metadata row names
reordered_centroids <- boundaries_centroids[match(rownames(patient_data@meta.data), boundaries_centroids@cells), ]

# Get current boundary polygons
boundaries_polygons <- breast_cancer_patients_all_cells@images$LU001FFP03@boundaries$segmentation@polygons

# Reorder the polygons according to the metadata row names
reordered_polygons <- boundaries_polygons[match(rownames(patient_data@meta.data), boundaries_polygons), ]

# Assign the reordered centroids and polygons back to the image boundaries
patient_data@images$LU001FFP03@boundaries$centroids <- reordered_centroids
patient_data@images$LU001FFP03@boundaries$segmentation@polygons <- reordered_polygons

But honestly I do not fell like this is the right approach :(

ADD REPLY
0
Entering edit mode

It is hard to say what is "not working" without an overview of what your data look like, or the architecture of your spatial objects.

Do you have to integrate, maybe just SCTransform is enough ? What is your experimental design ? Do you have controls ?

I guess you sequenced your patient independently, did you merge your expression matrices ? what did you do with the spatial context ?

ADD REPLY
0
Entering edit mode

I started my analysis with a single Seurat object and used SplitObject(object, split.by = "ident") to split by Patient ID. The problem with this approach is that when merging back the objects the spatial data is not correctly handled. I solved the problem by splitting as explained by the integration vignette of Seurat 5, it differs in that you can choose which assays to split and the split is done by creating separated layers instead of separated objects.

ADD REPLY

Login before adding your answer.

Traffic: 1600 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6