read10xVisium {SpatialExperiment}R Documentation

Load data from a 10x Genomics Visium experiment

Description

Creates a SpatialExperiment from the Space Ranger output directories for 10x Genomics Visium spatial gene expression data.

Usage

read10xVisium(
  samples = "",
  sample_id = paste0("sample", sprintf("%02d", seq_along(samples))),
  type = c("HDF5", "sparse"),
  data = c("filtered", "raw"),
  images = "lowres",
  load = TRUE
)

Arguments

samples

a character vector specifying one or more directories, each corresponding to a 10x Genomics Visium sample (see details); if provided, names will be used as sample identifiers

sample_id

character string specifying unique sample identifiers, one for each directory specified via samples; ignored if !is.null(names(samples))

type

character string specifying the type of format to read count data from (see read10xCounts)

data

character string specifying whether to read in filtered (spots mapped to tissue) or raw data (all spots).

images

character vector specifying which images to include. Valid values are "lowres", "hires", "fullres", "detected", "aligned"

load

logical; should the image(s) be loaded into memory as a grob? If FALSE, will store the path/URL instead.

Details

The constructor assumes data from each sample are located in a single output directory as returned by Space Ranger, thus having the following file organization:

sample
|—outs
· · |—raw/filtered_feature_bc_matrix.h5
· · |—raw/filtered_feature_bc_matrix
· · · · |—barcodes.tsv
· · · · |—features.tsv
· · · · |—matrix.mtx
· · |—spatial
· · · · |—scalefactors_json.json
· · · · |—tissue_lowres_image.png
· · · · |—tissue_positions_list.csv

Value

a SpatialExperiment object

Author(s)

Helena L. Crowell

Examples

dir <- system.file(
  file.path("extdata", "10xVisium"), 
  package = "SpatialExperiment")
  
sample_ids <- c("section1", "section2")
samples <- file.path(dir, sample_ids)
  
list.files(samples[1])
list.files(file.path(samples[1], "spatial"))
file.path(samples[1], "raw_feature_bc_matrix")

(spe <- read10xVisium(samples, sample_ids, 
  type = "sparse", data = "raw", 
  images = "lowres", load = FALSE))

# tabulate number of spots mapped to tissue
cd <- colData(spe, spatialData = TRUE)
table(
  in_tissue = cd$in_tissue, 
  sample_id = cd$sample_id)

# view available images
imgData(spe)


[Package SpatialExperiment version 1.3.4 Index]