ModulePreservation.Rd
Computes module preservation statistics in a query dataset for a given reference dataset
ModulePreservation(
seurat_obj,
seurat_ref,
name,
n_permutations = 500,
parallel = FALSE,
seed = 12345,
gene_mapping = NULL,
genome1_col = NULL,
genome2_col = NULL,
return_raw = FALSE,
wgcna_name = NULL,
wgcna_name_ref = NULL,
...
)
A Seurat object
A Seurat object serving as the reference for the module preservation analysis
The name to give the module preservation analysis.
Number of permutations for the module preservation test.
logical determining whether to run preservation analysis in parallel
random seed for the permutation analysis.
if TRUE, returns the module preservation statistics, else returns seurat_obj with the stats added to the hdWGCNA experiment.
The name of the hdWGCNA experiment in the seurat_obj@misc slot
The name of the hdWGCNA experiment in the seurat_ref@misc slot
ModulePreservation
#> function (seurat_obj, seurat_ref, name, n_permutations = 500,
#> parallel = FALSE, seed = 12345, gene_mapping = NULL, genome1_col = NULL,
#> genome2_col = NULL, return_raw = FALSE, wgcna_name = NULL,
#> wgcna_name_ref = NULL, ...)
#> {
#> if (is.null(wgcna_name)) {
#> wgcna_name <- seurat_obj@misc$active_wgcna
#> }
#> CheckWGCNAName(seurat_obj, wgcna_name)
#> if (is.null(wgcna_name_ref)) {
#> wgcna_name_ref <- seurat_ref@misc$active_wgcna
#> }
#> CheckWGCNAName(seurat_ref, wgcna_name_ref)
#> datExpr_ref <- GetDatExpr(seurat_ref, wgcna_name_ref)
#> datExpr_query <- GetDatExpr(seurat_obj, wgcna_name)
#> if (!is.null(gene_mapping)) {
#> gene_match <- match(colnames(datExpr_query), gene_mapping[,
#> genome2_col])
#> gene_mapping <- na.omit(gene_mapping[gene_match, ])
#> colnames(datExpr_query) <- gene_mapping[, genome1_col]
#> }
#> genes_keep <- intersect(colnames(datExpr_ref), colnames(datExpr_query))
#> datExpr_ref <- datExpr_ref[, genes_keep]
#> datExpr_query <- datExpr_query[, genes_keep]
#> setLabels <- c("ref", "query")
#> multiExpr <- list(ref = list(data = datExpr_ref), query = list(data = datExpr_query))
#> ref_modules <- GetModules(seurat_ref, wgcna_name = wgcna_name_ref)
#> ref_modules <- ref_modules[genes_keep, ]
#> ref_modules <- list(ref = ref_modules$module)
#> mp <- WGCNA::modulePreservation(multiExpr, ref_modules, referenceNetworks = 1,
#> nPermutations = n_permutations, randomSeed = seed, quickCor = 0,
#> parallelCalculation = parallel, ...)
#> if (return_raw) {
#> return(mp)
#> }
#> ref <- 1
#> test <- 2
#> statsObs <- cbind(mp$quality$observed[[ref]][[test]], mp$preservation$observed[[ref]][[test]])
#> statsZ <- cbind(mp$quality$Z[[ref]][[test]], mp$preservation$Z[[ref]][[test]])
#> mod_pres <- list(obs = statsObs, Z = statsZ)
#> seurat_obj <- SetModulePreservation(seurat_obj, mod_pres,
#> name, wgcna_name)
#> seurat_obj
#> }
#> <bytecode: 0x7fca8c32a948>
#> <environment: namespace:hdWGCNA>