Generate image embddings from spatial omics data.
Usage
generate_embeddings(
vesalius_assay,
dim_reduction = "PCA",
normalization = "log_norm",
use_counts = "raw",
dimensions = 30,
tensor_resolution = 1,
filter_grid = 1,
filter_threshold = 1,
nfeatures = 2000,
features = NULL,
min_cutoff = "q5",
remove_lsi_1 = TRUE,
verbose = TRUE
)
Arguments
- vesalius_assay
vesalius_assay object.
- dim_reduction
string describing which dimensionality reduction method should be used. One of the following: "PCA", "PCA_L", "UMAP", "LSI", "LSI_UMAP".
- normalization
string describing which normalisation method to use. One of the following "log_norm", "SCT", "TFIDF", "none".
- use_counts
string describing which counts should be used for the generating emebddings. Default = "raw". See details.
- dimensions
numeric describing the number of Principle Components or Latent space dimension to use. Default dimensions = 30
- tensor_resolution
numeric (range 0 - 1) describing the compression ratio to be applied to the final image. Default = 1
- filter_grid
numeric (range 0 - 1) size of the grid used when filtering outlier beads. Defined as a proportion of total image size. Default = 0.1
- filter_threshold
numeric (range 0 -1) describing the quantile threshold at which tiles should be retained (seed details)
- nfeatures
numeric describing the number of variable features to use.
- features
custom set of features to generate embeddings
- min_cutoff
only used when dimensionality reduction method is LSI or LSI_UMAP cutoff for feature to be included in the VariableFeatures for the object.
- remove_lsi_1
logical only used when dimensionality reduction method is LSI or LSI_UMAP indicating if the first LSI component should be removed from further analysis as it usually captures sequencing depth (technical variation)
- verbose
logical output progress message or not. Default = TRUE
Details
The core principle behind vesalius is to convert spatial omics
data into an image. generate_embeddings
allows you to convert
your omics data into a stack of gray scale images.
The stack hight will be equal to the number of dimenions you
selected excluding UMAP embeddings as only 3 dimesnions are availbale.
If tiles have not yet been generated (see generate_tiles
),
pixel will be generated from the spatial coordinates provided.
If tiles are already present, `generate_embeddings` will skip the
tile creation step.
The algorithm is broadly applicable to many spatial omics assays. Vesalius provides a 3 nornalization methods log_norm, SCTransform, and TF-IDF.
The `use_counts` argument specifies which count matrix should be used
for normalization. This argument is only necessary if you use a custom
normalised count matrix. In this case, set this argument to the name
you gave your count matrix (see add_counts
) and
`generate_embeddings` will skip the normalization and use your custom
count matrix to generate image embeddings.
Note that it is also possible to add custom embeddings by using the
add_embeddings
function.
Embeddings can be created using a custom set of genes. These genes can be provided to the `features` argument in the form of a character vector. Note that this will not filter the count matrix hence you will still have access to the whole matrix for downsteam analysis.
Examples
if (FALSE) { # \dontrun{
data(vesalius)
# First we build a simple object
ves <- build_vesalius_object(coordinates, counts)
# We can do a simple run
ves <- generate_embeddings(ves)
# maybe we want to try a different method
# both will be stored in the object
ves <- generate_embeddings(ves, dim_reduction = "UMAP")
} # }