This S4 generic converts miscellaneous objects into a SPATA2 object, transferring relevant data and metadata.

asSPATA2(object, ...)

# S4 method for class 'giotto'
asSPATA2(
  object,
  sample_name,
  coordinates,
  image_ebi,
  spatial_method,
  transfer_meta_data = TRUE,
  verbose = TRUE,
  ...
)

# S4 method for class 'Seurat'
asSPATA2(
  object,
  sample_name,
  platform = "Undefined",
  square_res = NULL,
  assay_name = NULL,
  assay_modality = NULL,
  img_name = NULL,
  img_scale_fct = "lowres",
  transfer_meta_data = TRUE,
  transfer_dim_red = TRUE,
  dim_red_naming = list(pca = "pca", tsne = "tsne", umap = "umap"),
  verbose = TRUE
)

Arguments

object

Objects of classes for which a method has been defined.

sample_name

Character. The name of the sample.

transfer_meta_data

Logical. If TRUE, the metadata will be transferred. Default is TRUE.

verbose

Logical. If TRUE, progress messages will be printed. Default is TRUE.

platform

Character. The platform used for the experiment. Should be one of names(spatial_methods).

assay_name

Character. The name of the Seurat assay containing the matrices of interest. If NULL, Seurat's default assay is used.

assay_modality

Character or NULL. The molecular modality modality of the assay data (e.g., "gene"). If NULL, not provided the input for assay_name is used as the molecular modality. This, however, is suboptimal and will likely result in many incompatibilities in downstream analysis. We recommend to specifiy this argument.

img_name

Character. The name of the image in the Seurat object to be transferred. If NULL, the function will attempt to use the only available image or throw an error if multiple images are found.

img_scale_fct

Character. The scale factor to use for image scaling if the Seurat object contains data from Visium. Depending on the image loaded in the Seurat object should likely be either 'lowres' or 'hires'.

transfer_dim_red

Logical. If TRUE, dimensionality reduction data (PCA, t-SNE, UMAP) will be transferred. Default is TRUE.

Value

A SPATA2 object containing the converted data.

From Seurat

The asSPATA2 method transforms a Seurat object into a SPATA2 object, preserving and adapting key data elements such as assays, images, metadata, and dimensional reduction data. Below are the specifics of the transformation process:

  • Assays:

    • Input: The assay to be transferred is specified via the assay_name parameter. If assay_name is not provided, the active assay of the Seurat object is used.

    • Molecular modality: In SPATA2 every assay is associated with a molecular modality. If argument assay_modality is not provided, the input for assay_name is used as the molecular modality. This, however, is suboptimal and will result in many incompatibilities downstream.

  • Images:

    • Input: The spatial image is selected using the img_name parameter. If not specified, the method chooses the sole available image or prompts for selection if multiple images exist.

    • Scale factors: If the of the Seurat object contains scale factors with which the coordinates must be scaled to align with the image specify the respective scale factor name in scale_with.

  • Metadata:

    • Input: Observational metadata is transferred if transfer_meta_data = TRUE (the default) and picked from @meta.data from the Seurat object.

  • Dimensional Reduction Data:

    • Input: Dimensional reduction embeddings (PCA, t-SNE, UMAP) are transferred if transfer_dim_red = TRUE (the default). The data must be stored in the Seurat object's reductions slot with specific naming conventions:

      • PCA: Expected in reductions$pca, with columns named PC_1, PC_2, etc., which are renamed to PC1, PC2, etc., in SPATA2.

      • t-SNE: Expected in reductions$tsne, with columns named tSNE_1, tSNE_2, renamed to tsne1, tsne2 in SPATA2.

      • UMAP: Expected in reductions$umap, with columns named UMAP_1, UMAP_2, renamed to umap1, umap2 in SPATA2.

    • Naming: These embeddings must follow the specific naming conventions for compatibility with SPATA2's visualization and analysis functions. If the embeddings are not found or named incorrectly, warnings are issued. dim_red_naming can be used to adjust what the function expects.

Examples


# ----- example for Seurat conversion
library(SPATA2)
library(Seurat)
library(SeuratData)

# unhash and run the command, if not installed yet
# SeuratData::InstallData("stxBrain")

brain <- SeuratData::LoadData("stxBrain", type = "anterior1")
brain <- SCTransform(brain, assay = "Spatial")
brain <- RunPCA(brain, assay = "SCT", verbose = FALSE)
brain <- FindNeighbors(brain, reduction = "pca", dims = 1:30)
brain <- FindClusters(brain, verbose = FALSE)
brain <- RunUMAP(brain, reduction = "pca", dims = 1:30)

# use assay Spatial
spata_object1 <-
 asSPATA2(
   object = brain,
   sample_name = "mouse_brain",
   platform = "VisiumSmall",
   img_name = "anterior1",
   img_scale_fct = "lowres",
   assay_name = "Spatial",
   assay_modality = "gene"
   )

show(spata_object1)

# use assay SCT
spata_object2 <-
 asSPATA2(
   object = brain,
   sample_name = "mouse_brain",
   platform = "VisiumSmall",
   img_name = "anterior1",
   img_scale_fct = "lowres",
   assay_name = "SCT",
   assay_modality = "gene"
   )

show(spata_object2)

# with Seurat
SpatialFeaturePlot(brain, "nCount_Spatial")

# with SPATA2
plotSurface(spata_object1, "nCount_Spatial")