Function to calculate gene signature enrichment scores per spatial position using a rank based approach.

runRankEnrich(
  gobject,
  spat_unit = NULL,
  feat_type = NULL,
  sign_matrix,
  expression_values = c("normalized", "raw", "scaled", "custom"),
  reverse_log_scale = TRUE,
  logbase = 2,
  output_enrichment = c("original", "zscore"),
  ties_method = c("average", "max"),
  p_value = FALSE,
  n_times = 1000,
  rbp_p = 0.99,
  num_agg = 100,
  name = NULL,
  return_gobject = TRUE
)

Arguments

gobject

Giotto object

spat_unit

spatial unit

feat_type

feature type

sign_matrix

Matrix of signature genes for each cell type / process

expression_values

expression values to use

reverse_log_scale

reverse expression values from log scale

logbase

log base to use if reverse_log_scale = TRUE

output_enrichment

how to return enrichment output

ties_method

how to handle rank ties

p_value

calculate p-values (boolean, default = FALSE)

n_times

number of permutations to calculate for p_value

rbp_p

fractional binarization threshold (default = 0.99)

num_agg

number of top genes to aggregate (default = 100)

name

to give to spatial enrichment results, default = rank

return_gobject

return giotto object

Value

data.table with enrichment results

Details

sign_matrix: a rank-fold matrix with genes as row names and cell-types as column names. Alternatively a scRNA-seq matrix and vector with clusters can be provided to makeSignMatrixRank, which will create the matrix for you.

First a new rank is calculated as R = (R1*R2)^(1/2), where R1 is the rank of fold-change for each gene in each spot and R2 is the rank of each marker in each cell type. The Rank-Biased Precision is then calculated as: RBP = (1 - 0.99) * (0.99)^(R - 1) and the final enrichment score is then calculated as the sum of top 100 RBPs.

Examples

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
#> cell_spatInfo_spatVector.shp
#> cell
#> 
#> 3.2 read Giotto spatial centroid information
#> cell
#> 
#> 3.3 read Giotto spatial overlap information
#> No overlaps were found, overlap loading will be
#>  skipped
#> 
#> 4. read Giotto image information
#> a giotto python environment was found
#> Using python path:
#>  "/Users/yuanlab/Library/r-miniconda/envs/giotto_env/bin/pythonw"
x <- findMarkers_one_vs_all(g, 
cluster_column = "leiden_clus", min_feats = 20)
#> using 'Scran' to detect marker feats. If used in published
#>       research, please cite: Lun ATL, McCarthy DJ, Marioni JC (2016).
#>       'A step-by-step workflow for low-level analysis of single-cell RNA-seq
#>       data with Bioconductor.'
#>       F1000Res., 5, 2122. doi: 10.12688/f1000research.9501.2. 
#> start with cluster  1start with cluster  2start with cluster  3start with cluster  4start with cluster  5start with cluster  6start with cluster  7
sign_gene <- x$feats

sign_matrix <- matrix(rnorm(length(sign_gene)*8, mean  = 10), 
nrow = length(sign_gene))
rownames(sign_matrix) <- sign_gene
colnames(sign_matrix) <- paste0("celltype_",unique(x$cluster))
#> Error in dimnames(x) <- dn: length of 'dimnames' [2] not equal to array extent

runRankEnrich(gobject = g, sign_matrix = sign_matrix, 
expression_values = "normalized")
#> An object of class giotto 
#> >Active spat_unit:  cell 
#> >Active feat_type:  rna 
#> [SUBCELLULAR INFO]
#> polygons      : cell 
#> [AGGREGATE INFO]
#> expression -----------------------
#>   [cell][rna] raw normalized scaled
#> spatial locations ----------------
#>   [cell] raw
#> spatial networks -----------------
#>   [cell] Delaunay_network spatial_network
#> spatial enrichments --------------
#>   [cell][rna] cluster_metagene DWLS rank
#> dim reduction --------------------
#>   [cell][rna] pca custom_pca umap custom_umap tsne
#> nearest neighbor networks --------
#>   [cell][rna] sNN.pca custom_NN
#> attached images ------------------
#> images      : alignment image 
#> 
#> 
#> Use objHistory() to see steps and params used