CalculateClusterEnrichmentGLMM: CalculateClusterEnrichmentGLMM

View source: R/Analysis.R

CalculateClusterEnrichmentGLMMR Documentation

CalculateClusterEnrichmentGLMM

Description

A function that calculates the enrichment of a cluster under a given treatment variable using a Generalized Linear Mixed Model (GLMM). This allows for more complex treatment of enrichment where you want to account for subject-driven random effects and variable cellular recovery.

Usage

CalculateClusterEnrichmentGLMM(
  seuratObj,
  subjectField = "SubjectId",
  clusterField = "ClusterNames_0.2",
  biologicalReplicateGroupingVariables = c("cDNA_ID"),
  treatmentField = NULL,
  referenceValue = NULL,
  pValueCutoff = 0.05,
  showPlots = TRUE,
  returnSeuratObjectOrPlots = "SeuratObject",
  includeDepletions = FALSE,
  pvalueAdjustmentMethod = "holm"
)

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 and represent biological replicates.

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.

biologicalReplicateGroupingVariables

A vector of metadata fields that should be used to group biological replicates. This can identical to subjectField, but in the case of repeated sample collections, the variables specified here will uniquely identify samples/collections.

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.

referenceValue

The reference value for the treatment field. This is the value that will be used as the baseline for comparison. Since this method requires a baseline, a reference value must be provided. Consider using CalculateClusterEnrichment for an omnibus test style of enrichment if a change from an individual reference value is not particularly insightful.

pValueCutoff

The p-value cutoff for significance. This is used to determine which clusters are significantly enriched or depleted.

showPlots

A boolean that determines if the function should print Volcano and DimPlots.

returnSeuratObjectOrPlots

A string that determines if the function should return a Seurat object with the enrichment results or a list of plots. If "SeuratObject", the function will return a Seurat object with the enrichment results in the metadata. If "Plots", the function will return a list of volcano plots and the dataframe used to plot them.

includeDepletions

A boolean that determines if the function should include depletions in the enrichment results. If TRUE, the function will include depletions in the enrichment results. If FALSE, the function will only include enrichments. Since we typically recover variable numbers of cells, depletions can be difficult to interpret/easily explained by low sampling volume compared to transcriptional complexity, so this is set to FALSE by default.

pvalueAdjustmentMethod

The method to use for p-value adjustment. This is passed to the p.adjust function. Default is "holm", but can be set to "BH" or "bonferroni" if desired.

Value

A SeuratObject or a list of plots + dataframe, depending on the value of returnSeuratObjectOrPlots.

Examples

 ## Not run: 
 seuratObj$cDNA_ID <- rep(1:4, ncol(seuratObj)) # This is a dummy variable for the sake of example.
 seuratObj$Vaccine <- rep(c("Vaccine1", "Vaccine2"), each = ncol(seuratObj)/2) # This is a dummy variable for the sake of example.
 seuratObj$SubjectId <- rep(1:4, each = ncol(seuratObj)/4) # This is a dummy variable for the sake of example.
 
 seuratObj <- CalculateClusterEnrichmentGLMM(seuratObj,
                                          subjectField = 'SubjectId',
                                           clusterField = 'ClusterNames_0.2',
                                           biologicalReplicateGroupingVariables = c("cDNA_ID"),
                                           treatmentField = "Vaccine",
                                           referenceValue = "Vaccine1",
                                           pValueCutoff = 0.05,
                                           showPlots = TRUE, 
                                           returnSeuratObjectOrPlots = "SeuratObject", 
                                           includeDepletions = FALSE)
  DimPlot(seuratObj, group.by = "GLMM_Enrichment", label = TRUE) + NoLegend()
  
## End(Not run)
 

bimberlabinternal/CellMembrane documentation built on June 9, 2025, 6:59 p.m.