FilterPseudobulkContrasts: FilterPseudobulkContrasts

View source: R/PseudoBulk.R

FilterPseudobulkContrastsR Documentation

FilterPseudobulkContrasts

Description

This is designed to accept a study design defined by a series of logical gates applied to metadata fields, test them for equivalence to some criterion, and then filter pairwise contrasts accordingly.

Usage

FilterPseudobulkContrasts(
  logicList = NULL,
  design = NULL,
  useRequireIdenticalLogic = T,
  requireIdenticalFields = NULL,
  filteredContrastsOutputFile = "./filtered_contrasts.tsv"
)

Arguments

logicList

The list that defines the study design. Please see examples for the setup and use. This list be a list of lists where each sub-list has three entries. The first defines the metadata field (e.g. Tissue or Timepoint) to which the logic gate will be applied. The second defines the logic gate that will be used for that field (one of: all (AND), any (OR), xor, nand, nor, or xnor. The third defines the specific value of the metadata field that will be tested for equivalence against the positive and negative contrasts within the gate.

design

a design/model matrix returned by DesignModelMatrix().

useRequireIdenticalLogic

Whether or not to apply require_identical logic using requireIdenticalFields. It is possible to use logic gates to keep metadata fields constant, but using this saves time & effort/iteration.

requireIdenticalFields

The metadata columns of the SeuratObj that you wish to keep constant. For example: defining "Tissue" in this vector would filter all contrasts comparing Liver to PBMC, as their tissue is not identical.

filteredContrastsOutputFile

The file to write the list of filtered contrasts to (one pair of samples per row, separated into their metadata fields).

Details

Filtered Reason positive_contrast_Challenge positive_contrast_Tissue positive_contrast_cell_type positive_contrast_SampleType negative_contrast_Challenge negative_contrast_Tissue negative_contrast_cell_type negative_contrast_SampleType
yes non-identical cell_types Mtb Spleen Myeloid Necropsy Mock.challenged Spleen Bcell Necropsy
no N/A Mtb Lung T.NK Necropsy Mock.challenged Lung T.NK Necropsy
yes fails Challenge xor gate Mock.challenged Lung T.NK Necropsy Mock.challenged Lung T.NK Necropsy
yes fails SampleType AND gate Mock.challenged MesLN Bcell Baseline Mock.challenged MesLN Bcell Necropsy

Value

A dataframe of pairwise contrasts, with column names indicating the directionality (positive vs negative) and associated metadata column (inferred by contrast_columns).

Examples

## Not run: 
#Set up design matrix
design <- DesignModelMatrix(pseudobulked_seuratObj, 
                            contrast_columns = c('Challenge', 'Tissue', 'cell_type', 'SampleType'), 
                            sampleIdCol = 'cDNA_ID')


#Form the study design. This should be a list of gates (each specified as a list itself) with three elements. 
#The first element defines the metadata column or field that will be used for filtering. 
#The second defines the logic gate (AND -> any, OR -> any, xor, xnor, nand, nor). 
#The third defines the specific value of the metadata field that will be tested for equivalence against the positive and negative contrasts within the gate.
logicList <- list(
                    list('Challenge', 'xor', 'Mock.challenged'), 
                    list('SampleType', 'all', 'Necropsy')
            )


#Finally, enumerate all possible contrasts, then filter and return them according to the study design defined by logicList.
#If you want to perform "Like-vs-Like" contrasts (i.e. T cell vs T cell within a cell_type metadata field), specify those columns as required to be identical and set useRequireIdenticalLogic to TRUE.
filtered_contrasts <- FilterPseudobulkContrasts(logicList = logicList, 
                                                design = design, 
                                                useRequireIdenticalLogic = T, 
                                                requireIdenticalFields = c('Tissue','cell_type', 'SampleType'), 
                                                filteredContrastsOutputFile = './filtered_contrasts.tsv')
                                                

## End(Not run)

bimberlabinternal/CellMembrane documentation built on Dec. 20, 2024, 11:13 p.m.