Date repository last updated: February 01, 2023
Overview
The gateR
package is a suite of R
functions
to identify significant spatial clustering of flow and mass cytometry
data used in immunological investigations. For a twogroup comparison,
we detect clusters using the kernelbased spatial relative risk function
estimated using the sparr package. The
tests are conducted in a twodimensional space comprised of two
fluorescent markers.
Examples of a single condition with two groups:
For a twogroup comparison of two conditions, we estimate two relative risk surfaces for one condition and then a ratio of the relative risks. For example:
\[\frac{ \big(\frac{Condition2B}{Condition2A}\big)}{\big(\frac{Condition1B}{Condition1A}\big)}\]
Within areas where the relative risk exceeds an asymptotic normal
assumption, the gateR
package has the functionality to
examine the features of these cells. Basic visualization is also
supported.
Installation
To install the release version from CRAN:
install.packages("gateR")
To install the development version from GitHub:
devtools::install_github("lancewallerlab/gateR")
Available functions
Function  Description 

gating

Main function. Conduct a gating strategy for flow and mass cytometry data. 
rrs

Called within gating , one condition comparison.

lotrrs

Called within gating , two condition comparison.

pval_correct

Called within rrs and lotrrs , calculates
various multiple testing corrections for the alpha level. Five methods
account for (spatially) dependent, multiple testing.

lrr_plot

Called within rrs and lotrrs , provides
functionality for basic visualization of a log relative risk surface.

pval_plot

Called within rrs and lotrrs , provides
functionality for basic visualization of a significant pvalue surface.

The repository also includes the code and resources to create the project hexagon sticker.
Available sample data sets
Data  Description 

randCyto

A sample dataset containing information about flow cytometry data with
two binary conditions and four markers. The data are a random subset of
the ‘extdata’ data in the
flowWorkspaceData
package found on Bioconductor and
formatted for gateR input.

Authors
See also the list of contributors who participated in this project. Main contributors include:
set.seed(1234) # for reproducibility
#  #
# Necessary packages #
#  #
library(gateR)
library(dplyr)
library(flowWorkspaceData)
library(ncdfFlow)
library(stats)
#  #
# Data preparation #
#  #
# Use 'extdata' from the {flowWorkspaceData} package
< system.file("extdata", package = "flowWorkspaceData")
flowDataPath < list.files(pattern = "CytoTrol", flowDataPath, full = TRUE)
fcsFiles < ncdfFlow::read.ncdfFlowSet(fcsFiles)
ncfs < ncfs[[1]]
fr1 < ncfs[[2]]
fr2
## Comparison of two samples (single condition) "g1"
## Two gates (four markers) "CD4", "CD38", "CD8", and "CD3"
## Arcsinh Transformation for all markers
## Remove cells with NA and Inf values
# First sample
< data.frame("id" = seq(1, nrow(fr1@exprs), 1),
obs_dat1 "g1" = rep(1, nrow(fr1@exprs)),
"arcsinh_CD4" = asinh(fr1@exprs[ , 5]),
"arcsinh_CD38" = asinh(fr1@exprs[ , 6]),
"arcsinh_CD8" = asinh(fr1@exprs[ , 7]),
"arcsinh_CD3" = asinh(fr1@exprs[ , 8]))
# Second sample
< data.frame("id" = seq(1, nrow(fr2@exprs), 1),
obs_dat2 "g1" = rep(2, nrow(fr2@exprs)),
"arcsinh_CD4" = asinh(fr2@exprs[ , 5]),
"arcsinh_CD38" = asinh(fr2@exprs[ , 6]),
"arcsinh_CD8" = asinh(fr2@exprs[ , 7]),
"arcsinh_CD3" = asinh(fr2@exprs[ , 8]))
# Full set
< rbind(obs_dat1, obs_dat2)
obs_dat < obs_dat[complete.cases(obs_dat), ] # remove NAs
obs_dat < obs_dat[is.finite(rowSums(obs_dat)), ] # remove Infs
obs_dat $g1 < as.factor(obs_dat$g1) # set "g1" as binary factor
obs_dat
## Create a second condition (randomly split the data)
## In practice, use data with a measured second condition
< stats::rbinom(nrow(obs_dat), 1, 0.5)
g2 $g2 < as.factor(g2)
obs_dat< obs_dat[ , c(1:2,7,3:6)]
obs_dat
# Export 'randCyto' data for CRAN examples
< dplyr::sample_frac(obs_dat, size = 0.1) # random subsample
randCyto
#  #
# Run gateR with one condition #
#  #
# Single condition
## A pvalue uncorrected for multiple testing
< gateR::gating(dat = obs_dat,
test_gating vars = c("arcsinh_CD4", "arcsinh_CD38",
"arcsinh_CD8", "arcsinh_CD3"),
n_condition = 1,
plot_gate = TRUE,
upper_lrr = 1,
lower_lrr = 1)
#  #
# Postgate assessment #
#  #
# Density of arcsinhtransformed CD4 postgating
::plot(stats::density(test_gating$obs[test_gating$obs$g1 == 1, 4]),
graphicsmain = "arcsinh CD4",
lty = 2)
::lines(stats::density(test_gating$obs[test_gating$obs$g1 == 2, 4]),
graphicslty = 3)
::legend("topright",
graphicslegend = c("Sample 1", "Sample 2"),
lty = c(2, 3),
bty = "n")
#  #
# Run gateR with two conditions #
#  #
## A pvalue uncorrected for multiple testing
< gateR::gating(dat = obs_dat,
test_gating2 vars = c("arcsinh_CD4", "arcsinh_CD38",
"arcsinh_CD8", "arcsinh_CD3"),
n_condition = 2)
#  #
# Perform a single gate without data extraction #
#  #
# Single condition
## A pvalue uncorrected for multiple testing
## For "arcsinh_CD4" and "arcsinh_CD38"
< gateR::rrs(dat = obs_dat[ , 7:6])
test_rrs
# Two conditions
## A pvalue uncorrected for multiple testing
## For "arcsinh_CD8" and "arcsinh_CD3"
< gateR::lotrrs(dat = obs_dat[ , 5:4]) test_lotrrs
This package was developed while the author was originally a doctoral student at in the Environmental Health Sciences doctoral program at Emory University and later as a postdoctoral fellow supported by the Cancer Prevention Fellowship Program at the National Cancer Institute. Any modifications since December 05, 2022 were made while the author was an employee of Social & Scientific Systems, Inc., a division of DLH Corporation.
When citing this package for publication, please follow:
citation("gateR")
For questions about the package, please contact the maintainer Dr. Ian D. Buller or submit a new issue.