Post

VISIUM data from Seurat to Giotto

SeurattoGiotto function은 이제 더이상 지원되지 않는다.

사용하려고 하는 방법은, Seurat -> SpatialExperiment -> Giotto

SpatialExperimentTOGiotto function은 지원하고 있기 때문에, Seurat object에서 spatialExperiment object로 변경하는 과정만 추가하면 될것 같았음

Function seurat_to_spe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#BiocManager::install("SpatialExperiment")
# https://github.com/drighelli/SpatialExperiment/issues/115
seurat_to_spe <- function(seu, sample_id, img_id) { 
    ## Convert to SCE
    sce <- Seurat::as.SingleCellExperiment(seu)
    
    ## Extract spatial coordinates
    spatialCoords <- as.matrix(seu@images[[img_id]]@coordinates[, c("imagecol", "imagerow")])
    
    ## Extract and process image data
    img <- SpatialExperiment::SpatialImage(x = as.raster(seu@images[[img_id]]@image))
    
    imgData <- DataFrame(
        sample_id = sample_id,
        image_id = img_id,
        data = I(list(img)),
        scaleFactor = seu@images[[img_id]]@scale.factors$lowres)
    
    # Convert to SpatialExperiment
    spe <- SpatialExperiment(
        assays = assays(sce),
        rowData = rowData(sce),
        colData = colData(sce),
        metadata = metadata(sce),
        reducedDims = reducedDims(sce),
        altExps = altExps(sce),
        sample_id = sample_id,
        spatialCoords = spatialCoords,
        imgData = imgData
    )
    # indicate all spots are on the tissue
    spe$in_tissue <- 1
    spe$sample_id <- sample_id
    # Return Spatial Experiment object
    spe
}

Seurat to Giotto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# start with seurat obj 아래 spatial folder, expression matrix (h5) 파일 있어야함.
seuratOBJ <- Load10X_Spatial(paste0(data_path,"Day",day,"_",old),slice=paste0("Day ",day," ",old))
# (optional) metadata추가
seuratOBJ <- RenameCells(seuratOBJ, add.cell.id = paste0("Day",day,"_",old))
seuratOBJ$orig.ident <- paste0("Day",day,"_",old)
seuratOBJ$Timepoint <- paste0("Day ",day)
seuratOBJ$Age <- old
# DefaultAssay setting
DefaultAssay(seuratOBJ) <- "Spatial"

# Seurat to SPE    
spe <- seurat_to_spe(seuratOBJ,img_id=paste0("Day.",day,".",old),sample_id=paste0("Day",day,"_",old))

# SPE to Giotto
gOBJ <- spatialExperimentToGiotto(spe)
This post is licensed under CC BY 4.0 by the author.

© Subin Cho. Some rights reserved.

Using the Chirpy theme for Jekyll.