Function to calculate gene signature enrichment scores per spatial position using a hypergeometric test.
Giotto object
spatial unit
feature type
Matrix of signature genes for each cell type / process
expression values to use
reverse expression values from log scale
log base to use if reverse_log_scale = TRUE
percentage of cells that will be considered to have gene expression with matrix binarization
how to return enrichment output
calculate p-values (boolean, default = FALSE)
to give to spatial enrichment results, default = hypergeometric
return giotto object
data.table with enrichment results
The enrichment score is calculated based on the p-value from the hypergeometric test, -log10(p-value).
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 <- 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
runHyperGeometricEnrich(gobject = g, sign_matrix = sign_matrix)
#> Setting spatial enrichment [cell][rna] hypergeometric
#> An object of class giotto
#> >Active spat_unit: cell
#> >Active feat_type: rna
#> dimensions : 634, 624 (features, cells)
#> [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 hypergeometric
#> 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