Accessor function to retrieve the 'top_result' dataframe from an 'glm_mg_result' object.
Value
A data frame with detailed information for each gene and the most relevant cluster label.
gene
Gene nametop_cluster
The name of the most relevant cluster after thresholding the coefficients.glm_coef
The coefficient of the selected cluster in the generalised linear model.pearson
Pearson correlation between the gene vector and the selected cluster vector.max_gg_corr
A number showing the maximum pearson correlation for this gene vector and all other gene vectors in the inputgene_mt
max_gc_corr
A number showing the maximum pearson correlation for this gene vector and every cluster vectors in the inputcluster_mt
Examples
library(SpatialExperiment)
set.seed(100)
# simulate coordinates for clusters
df_clA <- data.frame(x = rnorm(n=100, mean=20, sd=5),
y = rnorm(n=100, mean=20, sd=5), cluster="A")
df_clB <- data.frame(x = rnorm(n=100, mean=100, sd=5),
y = rnorm(n=100, mean=100, sd=5), cluster="B")
clusters <- rbind(df_clA, df_clB)
clusters$sample<-"sample1"
# simulate coordinates for genes
trans_info <- data.frame(rbind(cbind(x = rnorm(n=100, mean=20,sd=5),
y = rnorm(n=100, mean=20, sd=5),
feature_name="gene_A1"),
cbind(x = rnorm(n=100, mean=20, sd=5),
y = rnorm(n=100, mean=20, sd=5),
feature_name="gene_A2"),
cbind(x = rnorm(n=100, mean=100, sd=5),
y = rnorm(n=100, mean=100, sd=5),
feature_name="gene_B1"),
cbind(x = rnorm(n=100, mean=100, sd=5),
y = rnorm(n=100, mean=100, sd=5),
feature_name="gene_B2")))
trans_info$x<-as.numeric(trans_info$x)
trans_info$y<-as.numeric(trans_info$y)
trans_info$cell<-sample(c("cell1","cell2","cell2"),replace=TRUE,
size=nrow(trans_info))
trans_mol <- BumpyMatrix::splitAsBumpyMatrix(
trans_info[, c("x", "y")],
row = trans_info$feature_name, col = trans_info$cell )
spe<- SpatialExperiment(
assays = list(molecules = trans_mol),sample_id ="sample1" )
w_x <- c(min(floor(min(trans_info$x)),
floor(min(clusters$x))),
max(ceiling(max(trans_info$x)),
ceiling(max(clusters$x))))
w_y <- c(min(floor(min(trans_info$y)),
floor(min(clusters$y))),
max(ceiling(max(trans_info$y)),
ceiling(max(clusters$y))))
vecs_lst <- get_vectors(x=spe,sample_names=c("sample1"),
cluster_info = clusters,
bin_type = "square",
bin_param = c(20,20),
test_genes =c("gene_A1","gene_A2","gene_B1","gene_B2"),
w_x = w_x, w_y=w_y)
lasso_res <- lasso_markers(gene_mt=vecs_lst$gene_mt,
cluster_mt = vecs_lst$cluster_mt,
sample_names=c("sample1"),
keep_positive=TRUE,
background=NULL)
# the top result
top_result<- get_top_mg(lasso_res, coef_cutoff=0.05)