Skip to contents

Create a Staffli object from a set of images and associated spot coordinates

Usage

CreateStaffliObject(
  imgs = NULL,
  meta_data,
  image_height = 400,
  image_info,
  scalefactors
)

Arguments

imgs

Character vector specifying paths to images in JPG, PNG or TIF format

meta_data

Spot-level metadata to add to the Staffli object. This should be a tbl with required columns 'barcode' representing the spot IDs, 'pxl_col_in_fullres' and 'pxl_row_in_fullres' which specifies the 10x Visium array coordinates and a 'sampleID' column with sample IDs

image_height

Specifies the height of the scaled images in pixels [default: 400 pixels]

image_info

a tibble with image information

scalefactors

a tibble with scalefactors sued to transform coordinates from the original image space to the downscaled images

Value

A Staffli object

Author

Ludvig Larsson

Examples


library(semla)

# Multiple samples
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Create an object with multiple samples
he_imgs <- c(system.file("extdata/mousebrain", 
                         "spatial/tissue_lowres_image.jpg", 
                         package = "semla"),
             system.file("extdata/mousecolon", 
                         "spatial/tissue_lowres_image.jpg", 
                         package = "semla"))
spotfiles <- c(system.file("extdata/mousebrain", 
                           "spatial/tissue_positions_list.csv", 
                           package = "semla"),
               system.file("extdata/mousecolon", 
                           "spatial/tissue_positions_list.csv", 
                           package = "semla"))
jsonfiles <- c(system.file("extdata/mousebrain", 
                           "spatial/scalefactors_json.json", 
                           package = "semla"),
               system.file("extdata/mousecolon", 
                           "spatial/scalefactors_json.json", 
                           package = "semla"))

# Read coordinates and select relevant columns
coordinates <- LoadSpatialCoordinates(spotfiles) |> 
  select(all_of(c("barcode", "x", "y", "pxl_col_in_fullres", "pxl_row_in_fullres", "sampleID")))
#>  Loading coordinates:
#> →   Finished loading coordinates for sample 1
#> →   Finished loading coordinates for sample 2
#>  Collected coordinates for 5164 spots.

# Create image_info
image_info <- LoadImageInfo(he_imgs)

# Read scalefactors
scalefactors <- LoadScaleFactors(jsonfiles)

# Add additional columns to image_info using scalefactors
image_info <- UpdateImageInfo(image_info, scalefactors)

# Create Staffli object
staffli_object <- CreateStaffliObject(imgs = he_imgs, 
                                      meta_data = coordinates, 
                                      image_info = image_info, 
                                      scalefactors = scalefactors)
staffli_object
#> An object of class Staffli 
#> 5164 spots across 2 samples.