CalculateClusterEnrichment: CalculateClusterEnrichment

View source: R/Analysis.R

CalculateClusterEnrichmentR Documentation

CalculateClusterEnrichment

Description

A function that calculates the enrichment of a cluster under a given treatment variable.

Usage

CalculateClusterEnrichment(
  seuratObj,
  subjectField = "SubjectId",
  clusterField = "ClusterNames_0.2",
  treatmentField = NULL,
  alternative = "two.sided",
  pValueCutoff = 0.05,
  showPlots = TRUE,
  paired = "infer",
  removePriorPvalues = TRUE,
  postHocTest = TRUE
)

Arguments

seuratObj

The Seurat object containing a subjectField, clusterField, and treatmentField. Please see the individual arguments for more information.

subjectField

The column of the Seurat object's metadata that contains the subject field. This field should denote individual samples that are independently collected.

clusterField

The column of the Seurat object's metadata that contains the clustering field. This field should denote cluster membership, generally given by louvain/leiden clustering, but any subject-independent clustering method is valid.

treatmentField

The column of the Seurat object's metadata that contains the treatment field. This field should denote the treatment of the subject, and should be the primary variable of interest within your study.

alternative

A passthrough variable to wilcox.test. If "greater", the alternative hypothesis is that the difference in medians is greater than the null hypothesis. If "less", the alternative hypothesis is that the difference in medians is less than the null hypothesis. If "two.sided", the alternative hypothesis is that the difference in medians is simply "different" from the null hypothesis. In the case of the wilcoxon rank sum (e.g. paired = FALSE), this will test the difference of the medians, rather than the medians themselves.

pValueCutoff

The p-value cutoff for significance.

showPlots

A boolean that determines if the cluster significance should be shown in a DimPlot.

paired

A passthrough variable to wilcox.test. If TRUE, the function will perform a paired Wilcoxon test. If FALSE, the function will perform an unpaired Wilcoxon test. If you're testing (for instance, timepoint) enrichment on repeated measures, this should be TRUE. If you're testing different treatments on different subjects, this should be FALSE. If set to "infer", the function will attempt to infer the correct value based on the name of the treatment field. Specifically, this will search for "time" in your treatment field. If it finds it, it will set paired = TRUE. If it doesn't, it will set paired = FALSE.

removePriorPvalues

A boolean that determines if the prior p-values should be removed from the Seurat object metadata. It's likely that you'll want to iteratively compute significance on different metadata fields, so this is set to TRUE by default and will remove the Cluster_pValue and Cluster_p_adj fields from the Seurat object's metadata.

postHocTest

A boolean that determines if a post-hoc test should be performed. If TRUE, the function will perform a Conover-Iman post-hoc test to determine which pairs of treatmentField groups are significantly different from each other.

Value

A Seurat object with the p-values of the clusters in the metadata columns Cluster_pValue and Cluster_p_adj. If showPlots = TRUE, a DimPlot will be shown with significant clusters highlighted.

Examples

 ## Not run: 
 seuratObj <- CalculateClusterEnrichment(seuratObj,
                                       clusterField = "ClusterNames_0.4",
                                       treatmentField = "vaccine_cohort",
                                       subjectField = "SubjectId",
                                       paired = "infer", 
                                       showPlots = TRUE)
                                       
## End(Not run)

bimberlabinternal/CellMembrane documentation built on Oct. 16, 2024, 6:53 a.m.