satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.29k stars 915 forks source link

Seurat object for cosMx Nanostring data #8189

Closed olhakholod closed 10 months ago

olhakholod commented 10 months ago

Hello!

I want to use this sample (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM7473682) to generate Seurat object for clustering and subsequent cell-cell interactions inference. This sample consists of four files:

Transcript File: GSM7473682_HC_a_tx_file.csv Cell Expression File: GSM7473682_HC_a_exprMat_file.csv Cell Metadata File: GSM7473682_HC_a_metadata_file.csv FOV Positions File: GSM7473682_HC_a_fov_positions_file.csv

I used the following code to generate SpatialFeatureExperiment object:

library(SpatialFeatureExperiment)
library(SingleCellExperiment)
library(SpatialExperiment)
library(vroom)
library(sf)
library(terra)
library(EBImage)
library(rmapshaper)
library(lwgeom)
library(tidyverse)
library(jsonlite)
library(Matrix)
library(Voyager)
library(R.utils)
library(stringr)
library(glue)
library(rlang)
library(arrow)
library(DropletUtils)
library(BiocParallel)
library(DelayedArray)
library(Seurat)

### Load the data

# Data downloaded from https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM7473682
# HC a_non-IBD colon is used here. 

mat <- vroom("GSM7473682_HC_a_exprMat_file.csv")
metadata <- vroom("GSM7473682_HC_a_metadata_file.csv")
cell_poly <- vroom("GSM7473682_HC_a_tx_file.csv")

cell_poly <- cell_poly %>% unite("ID", fov:cell_ID)
mat <- mat %>% unite("ID", fov:cell_ID)
metadata <- metadata %>% unite("ID", fov:cell_ID)

mat <- mat[match(metadata$ID, mat$ID),]

cell_poly <- cell_poly %>% 
  filter(ID %in% metadata$ID)

cell_sf <- df2sf(cell_poly, spatialCoordsNames = c("x_global_px", "y_global_px"),
                 geometryType = "POLYGON")

all(st_is_valid(cell_sf))

# 2 cells have fewer than 3 vertices. Remove those
mat <- mat[mat$ID %in% cell_sf$ID,]
metadata <- metadata[metadata$ID %in% cell_sf$ID,]
m <- t(as.matrix(mat[,-1]))
colnames(m) <- mat$ID
m <- as(m, "dgCMatrix")
cell_sf <- cell_sf[match(mat$ID, cell_sf$ID),]

sfe <- SpatialFeatureExperiment(assays = list(counts = m),
                                colData = metadata,
                                spatialCoordsNames = c("CenterX_global_px",
                                                       "CenterY_global_px"))

cellSeg(sfe) <- cell_sf
saveRDS(sfe, "cosmx1.rds")

I was wondering if there is a tutorial that will help me to generate a similar object for Seurat to perform downstream clustering and cell-cell interaction inference.

Thank you for your help! Olha

longmanz commented 10 months ago

Hi, Seurat also provides a function "LoadNanostring" to load coxMx dataset as a Seurat object. You can refer to this vignette for details on how to do it (https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2#human-lung-nanostring-cosmx-spatial-molecular-imager).

Please let me know if you encounter any problem with this and I will re-open the issue.

s-e-h commented 6 months ago

Hi,

I was trying to use the vignette (https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2#human-lung-nanostring-cosmx-spatial-molecular-imager) to work with the above data as well (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM7473682). However, I am receiving errors straight away with the following:

> NS <- LoadNanostring(data.dir = "D:/CosMx/File/GSM7473682_HCa/", fov = CMX, assay = "Nanostring")
|--------------------------------------------------|
|==================================================|
Error in ReadNanostring(data.dir = data.dir, type = c("centroids", "segmentations")) : 
  object 'segs' not found

The file format is as follows:

image

I think it is missing the -polygons.csv file that it is expecting. However this file does not appear to be available at the public repository (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM7473682).

Any help would be greatly appreciated.

Rayan21100 commented 6 months ago

Hi,

I was trying to use the vignette (https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2#human-lung-nanostring-cosmx-spatial-molecular-imager) to work with the above data as well (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM7473682). However, I am receiving errors straight away with the following:

> NS <- LoadNanostring(data.dir = "D:/CosMx/File/GSM7473682_HCa/", fov = CMX, assay = "Nanostring")
|--------------------------------------------------|
|==================================================|
Error in ReadNanostring(data.dir = data.dir, type = c("centroids", "segmentations")) : 
  object 'segs' not found

The file format is as follows:

image

I think it is missing the -polygons.csv file that it is expecting. However this file does not appear to be available at the public repository (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM7473682).

Any help would be greatly appreciated.

I had the same problem for another Nanostring public dataset. I sent a message to Nanostring through the contact form on their website and they sent the polygon file to me (it took several weeks...). Did you ever load Nanostring data to a Seurat object? I'm trying to do so but I'm a bit struggling and I think I have to reformat the data, if you ever did so do not hesitate to DM me !