Use a fast KNN classifier to predict labels from a smaller giotto object
doClusterProjection(
target_gobject,
target_cluster_label_name = "knn_labels",
spat_unit = NULL,
feat_type = NULL,
source_gobject,
source_cluster_labels = NULL,
reduction = "cells",
reduction_method = "pca",
reduction_name = "pca",
dimensions_to_use = 1:10,
knn_k = 10,
prob = FALSE,
algorithm = c("kd_tree", "cover_tree", "brute"),
return_gobject = TRUE
)
target giotto object
name for predicted clusters
spatial unit
feature type
source giotto object with annotation data
annotation/labels to use to train KNN classifier
reduction on cells or features (default = cells)
shared reduction method (default = pca space)
name of shared reduction space (default name = 'pca')
dimensions to use in shared reduction space (default = 1:10)
number of k-neighbors to train a KNN classifier
output probabilities together with label predictions
nearest neighbor search algorithm
return giotto object
giotto object (default) or data.table with cell metadata
Function to train a KNN with knn
. The training
data is obtained from the source giotto object (source_gobject) using
existing annotations within the cell metadata. Cells without
annotation/labels from the target giotto object (target_gobject) will
receive predicted labels (and optional probabilities with prob = TRUE).
**IMPORTANT** This projection assumes that you're using the same dimension reduction space (e.g. PCA) and number of dimensions (e.g. first 10 PCs) to train the KNN classifier as you used to create the initial annotations/labels in the source Giotto object.
Altogether this is a convenience function that allow you to work with very big data as you can predict cell labels on a smaller & subsetted Giotto object and then project the cell labels to the remaining cells in the target Giotto object.
g <- GiottoData::loadGiottoMini("visium")
#> 1. read Giotto object
#> 2. read Giotto feature information
#> 3. read Giotto spatial information
#> 3.1 read Giotto spatial shape information
#> 3.2 read Giotto spatial centroid information
#> 3.3 read Giotto spatial overlap information
#> 4. read Giotto image information
#> python already initialized in this session
#> active environment : '/usr/bin/python3'
#> python version : 3.10
#> checking default envname 'giotto_env'
#> a system default python environment was found
#> Using python path:
#> "/usr/bin/python3"
x <- pDataDT(g)
g_small <- subsetGiotto(g, cell_ids = sample(x$cell_ID, 300))
doClusterProjection(
target_gobject = g, source_gobject = g_small,
source_cluster_labels = "leiden_clus"
)
#> Warning: `doClusterProjection()` was deprecated in Giotto 4.1.2.
#> ℹ Please use `labelTransfer()` instead.