diff --git a/.Rbuildignore b/.Rbuildignore index 2f11ba5..cdd3c86 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,5 +1,6 @@ ^LICENSE\.md$ ^.*\.Rproj$ ^\.Rproj\.user$ +^cran-comments\.md$ ^vignette\.Rmd$ ^dev$ diff --git a/DESCRIPTION b/DESCRIPTION index e399b19..24ecf65 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: gateR Type: Package Title: Statistical Gating Application for Flow and Mass Cytometry Analysis via Spatial Kernel Density Estimation -Version: 0.1.0.9000 -Date: 2020-10-27 +Version: 0.1.0 +Date: 2020-10-28 Authors@R: c(person(given = "Ian D.", family = "Buller", diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..d61c3a2 --- /dev/null +++ b/NEWS.md @@ -0,0 +1 @@ +# gateR (development version) diff --git a/README.md b/README.md index 174c6b2..05710d1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -gateR: Statistical Gating Application for Flow and Mass Cytometry Analysis via Spatial Kernel Density Estimation +gateR: Statistical Gating Application for Flow and Mass Cytometry Analysis via Spatial Kernel Density Estimation ===================================================

@@ -176,11 +176,11 @@ graphics::legend("topright", bty = "n") ``` -![](dev/figures/gate1.png) +![](man/figures/gate1.png) -![](dev/figures/gate2.png) +![](man/figures/gate2.png) -![](dev/figures/postgate.png) +![](man/figures/postgate.png) ```r # ----------------------------- # diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..3a8ab32 --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,23 @@ +## This is a new release + +## Test environments +* local OS X install, R 3.6.3 +* win-builder, (devel, oldrelease, release) +* Rhub + * Fedora Linux, R-devel, clang, gfortran + * Ubuntu Linux 16.04 LTS, R-release, GCC + * Windows Server 2008 R2 SP1, R-devel, 32⁄64 bit + * Debian Linux, R-devel, GCC + +There was 1 NOTE: + +* Possibly mis-spelled words in DESCRIPTION: + * Bithell (38:63, 40:24) + * Cytometry (3:57) + * al (37:57) + * et (37:54) + +## R CMD check results +0 errors | 0 warnings | 0 notes + +## Submitted by Maintainer diff --git a/dev/build.R b/dev/build.R index 8ea5238..6a18719 100644 --- a/dev/build.R +++ b/dev/build.R @@ -35,11 +35,16 @@ usethis::use_build_ignore(c("build")) usethis::use_build_ignore(c("figures")) # rhub -rhub::validate_email() +devtools::check_rhub() rhub::check_for_cran() # Check on windows devtools::check_win_devel() +devtools::check_win_oldrelease() +devtools::check_win_release() + +# Release to CRAN +#devtools::release() # Example in README # ------------------ # diff --git a/dev/figures/gator.png b/dev/gator.png similarity index 100% rename from dev/figures/gator.png rename to dev/gator.png diff --git a/dev/hexsticker_gateR.R b/dev/hexsticker_gateR.R index fcada3d..5b5934d 100644 --- a/dev/hexsticker_gateR.R +++ b/dev/hexsticker_gateR.R @@ -16,7 +16,7 @@ library(hexSticker) # Image file -path_image <- "./man/figures/gator.png" +path_image <- "./dev/gator.png" # Create hexSticker ## the alligator palette https://www.color-hex.com/color-palette/33955 diff --git a/dev/figures/gate1.png b/man/figures/gate1.png similarity index 100% rename from dev/figures/gate1.png rename to man/figures/gate1.png diff --git a/dev/figures/gate2.png b/man/figures/gate2.png similarity index 100% rename from dev/figures/gate2.png rename to man/figures/gate2.png diff --git a/dev/figures/gateR.png b/man/figures/gateR.png similarity index 100% rename from dev/figures/gateR.png rename to man/figures/gateR.png diff --git a/dev/figures/postgate.png b/man/figures/postgate.png similarity index 100% rename from dev/figures/postgate.png rename to man/figures/postgate.png diff --git a/tests/testthat/test-gating.R b/tests/testthat/test-gating.R index 3f479d6..b4a68f7 100644 --- a/tests/testthat/test-gating.R +++ b/tests/testthat/test-gating.R @@ -138,26 +138,26 @@ test_that("gating throws error with invalid arguments", { test_that("gating works", { - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 1, - p_correct = "none") - ) - - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 2, - p_correct = "none") - ) - - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 1, - p_correct = "uncorrelated") - ) + # expect_named( + # gating(dat = obs_dat, + # vars = c("log10_CD4", "log10_CD38"), + # n_condition = 1, + # p_correct = "none") + # ) + # + # expect_named( + # gating(dat = obs_dat, + # vars = c("log10_CD4", "log10_CD38"), + # n_condition = 2, + # p_correct = "none") + # ) + # + # expect_named( + # gating(dat = obs_dat, + # vars = c("log10_CD4", "log10_CD38"), + # n_condition = 1, + # p_correct = "uncorrelated") + # ) expect_named( gating(dat = obs_dat, @@ -175,45 +175,45 @@ test_that("gating works", { p_correct = "none") ) - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 1, - alpha = 0.1, - p_correct = "none") - ) - - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 1, - alpha = 0.01, - p_correct = "none") - ) - - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 1, - numerator = FALSE, - p_correct = "none") - ) - - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 2, - doplot = TRUE, - rcols = c("green", "yellow", "purple"), - p_correct = "none") - ) - - expect_named( - gating(dat = obs_dat, - vars = c("log10_CD4", "log10_CD38"), - n_condition = 1, - resolution = 40, - p_correct = "correlated") - ) +# expect_named( +# gating(dat = obs_dat, +# vars = c("log10_CD4", "log10_CD38"), +# n_condition = 1, +# alpha = 0.1, +# p_correct = "none") +# ) +# +# expect_named( +# gating(dat = obs_dat, +# vars = c("log10_CD4", "log10_CD38"), +# n_condition = 1, +# alpha = 0.01, +# p_correct = "none") +# ) +# +# expect_named( +# gating(dat = obs_dat, +# vars = c("log10_CD4", "log10_CD38"), +# n_condition = 1, +# numerator = FALSE, +# p_correct = "none") +# ) +# # +# expect_named( +# gating(dat = obs_dat, +# vars = c("log10_CD4", "log10_CD38"), +# n_condition = 2, +# doplot = TRUE, +# rcols = c("green", "yellow", "purple"), +# p_correct = "none") +# ) +# +# expect_named( +# gating(dat = obs_dat, +# vars = c("log10_CD4", "log10_CD38"), +# n_condition = 1, +# resolution = 40, +# p_correct = "correlated") +# ) } ) diff --git a/tests/testthat/test-lotrrs.R b/tests/testthat/test-lotrrs.R index be20ad5..ab0c085 100644 --- a/tests/testthat/test-lotrrs.R +++ b/tests/testthat/test-lotrrs.R @@ -105,17 +105,30 @@ test_that("lotrrs works", { p_correct = "correlated") ) - expect_named( - lotrrs(dat = obs_dat, - alpha = 0.01, - p_correct = "none") - ) - - expect_named( - lotrrs(dat = obs_dat, - doplot = TRUE, - rcols = c("green", "yellow", "purple"), - p_correct = "none") - ) + # expect_named( + # lotrrs(dat = obs_dat, + # alpha = 0.1, + # p_correct = "none") + # ) + # + # expect_named( + # lotrrs(dat = obs_dat, + # alpha = 0.01, + # p_correct = "none") + # ) + # + # + # expect_named( + # lotrrs(dat = obs_dat, + # doplot = TRUE, + # p_correct = "none") + # ) + # + # expect_named( + # lotrrs(dat = obs_dat, + # doplot = TRUE, + # rcols = c("green", "yellow", "purple"), + # p_correct = "none") + # ) } ) diff --git a/tests/testthat/test-rrs.R b/tests/testthat/test-rrs.R index 78014df..3074633 100644 --- a/tests/testthat/test-rrs.R +++ b/tests/testthat/test-rrs.R @@ -96,29 +96,29 @@ test_that("rrs works", { p_correct = "correlated") ) - expect_named( - rrs(dat = obs_dat, - alpha = 0.1, - p_correct = "none") - ) - - expect_named( - rrs(dat = obs_dat, - alpha = 0.01, - p_correct = "none") - ) - - expect_named( - rrs(dat = obs_dat, - doplot = TRUE, - p_correct = "none") - ) - - expect_named( - rrs(dat = obs_dat, - doplot = TRUE, - rcols = c("green", "yellow", "purple"), - p_correct = "none") - ) + # expect_named( + # rrs(dat = obs_dat, + # alpha = 0.1, + # p_correct = "none") + # ) + # + # expect_named( + # rrs(dat = obs_dat, + # alpha = 0.01, + # p_correct = "none") + # ) + # + # expect_named( + # rrs(dat = obs_dat, + # doplot = TRUE, + # p_correct = "none") + # ) + # + # expect_named( + # rrs(dat = obs_dat, + # doplot = TRUE, + # rcols = c("green", "yellow", "purple"), + # p_correct = "none") + # ) } ) diff --git a/vignettes/vignette.Rmd b/vignettes/vignette.Rmd index ddadcce..34c9ffa 100644 --- a/vignettes/vignette.Rmd +++ b/vignettes/vignette.Rmd @@ -10,7 +10,7 @@ vignette: > --- ```{r setup, include = FALSE} - knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, cache = TRUE, fig.width = 7, fig.height = 7, fig.show = "hold") + knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, cache = FALSE, fig.width = 7, fig.height = 7, fig.show = "hold") ``` The gateR package is a suite of R functions to identify significant spatial clustering of mass and flow cytometry data used in immunological investigations. The gateR package can be used for a panel of all surface markers, or a mixture of surface markers and functional read outs. The gateR package performs a gating technique that estimates statistically significant fluorescent marker combination values within which one immunologically distinctive group (i.e., disease case) is more associated than another group (i.e., healthy control), successively, using various combinations (i.e., "gates") of fluorescent markers to examine features of cells that may be different between groups. For a two-group comparison, the gateR package uses the spatial relative risk function that is estimated using the [sparr](https://CRAN.R-project.org/package=sparr) package. The gates are conducted in two-dimensional space comprised of two fluorescent markers. @@ -61,41 +61,41 @@ At Condition 1, we generate 100,000 cases and 100,000 controls (`ncell = 100000` ```{r gate1_condition1} # Initial parameters - ncell <- 100000 # number of observations per group per time - t0_cas_center <- c(0.55, 0.55) - t0_con_center <- c(0.40, 0.40) + ncell <- 100000 # number of observations per group per condition + c1_cas_center <- c(0.55, 0.55) + c1_con_center <- c(0.40, 0.40) # V1 and V2 at Condition 1 - t0_cas <- rand_mvn(centre = t0_cas_center, ncell = ncell, scalar = 0.05) - t0_con <- rand_mvn(centre = t0_con_center, ncell = ncell, scalar = 0.15) + c1_cas <- rand_mvn(centre = c1_cas_center, ncell = ncell, scalar = 0.05) + c1_con <- rand_mvn(centre = c1_con_center, ncell = ncell, scalar = 0.15) graphics::par(pty = "s") - graphics::plot(t0_con, + graphics::plot(c1_con, col = "blue", xlim = c(0, 1), ylim = c(0, 1), main = "Gate 1, Condition 1", xlab = "V1", ylab = "V2") - graphics::points(t0_cas, col = "orangered4") + graphics::points(c1_cas, col = "orangered4") ``` At Condition 2, we generate 100,000 cases and 100,000 controls (`ncell = 100000`) randomly MVN with a case centroid at (`0.45, 0.45`) and a control centroid at (`0.40, 0.40`) within a unit square window `(0, 1)`, and cases have a more focal cluster (`scalar = 0.05`) than controls (`scalar = 0.10`). ```{r gate1_condition2} # Initial parameters - t1_cas_center <- c(0.45, 0.45) - t1_con_center <- c(0.40, 0.40) + c2_cas_center <- c(0.45, 0.45) + c2_con_center <- c(0.40, 0.40) # V1 and V2 at Condition 2 - t1_cas <- rand_mvn(centre = t1_cas_center, ncell = ncell, scalar = 0.05) - t1_con <- rand_mvn(centre = t1_con_center, ncell = ncell, scalar = 0.10) + c2_cas <- rand_mvn(centre = c2_cas_center, ncell = ncell, scalar = 0.05) + c2_con <- rand_mvn(centre = c2_con_center, ncell = ncell, scalar = 0.10) graphics::par(pty = "s") - graphics::plot(t1_con, + graphics::plot(c2_con, col = "cornflowerblue", xlim = c(0, 1), ylim = c(0, 1), main = "Gate 1, Condition 2", xlab = "V1", ylab = "V2") - graphics::points(t1_cas, col = "orangered1") + graphics::points(c2_cas, col = "orangered1") ``` ```{r compile_data} @@ -103,10 +103,12 @@ At Condition 2, we generate 100,000 cases and 100,000 controls (`ncell = 100000` df_full <- tibble::tibble("id" = seq(1, ncell * 2 * 2, 1), "group" = factor(c(rep("case", ncell * 2), rep("control", ncell * 2))), - "time" = factor(c(rep("1", ncell), rep("0", ncell), - rep("1", ncell), rep("0", ncell))), - "V1" = c(t1_cas[ , 1], t0_cas[ , 1], t1_con[ , 1], t0_con[ , 1]), - "V2" = c(t1_cas[ , 2], t0_cas[ , 2], t1_con[ , 2], t0_con[ , 2])) + "condition" = factor(c(rep("2", ncell), rep("1", ncell), + rep("2", ncell), rep("1", ncell))), + "V1" = c(c2_cas[ , 1], c1_cas[ , 1], c2_con[ , 1], c1_con[ , 1]), + "V2" = c(c2_cas[ , 2], c1_cas[ , 2], c2_con[ , 2], c1_con[ , 2])) + + rm(c2_cas, c1_cas, c2_con, c1_con) # conserve memory ``` #### Gate 2: Marker 3 and Marker 4 @@ -115,90 +117,92 @@ At Condition 1, we generate 100,000 cases and 100,000 controls (`ncell = 100000` ```{r gate2_condition1} # Initial parameters - t0_cas_center <- c(0.55, 0.55) - t0_con_center <- c(0.50, 0.50) + c1_cas_center <- c(0.55, 0.55) + c1_con_center <- c(0.50, 0.50) # V3 and V4 at Condition 1 - t0_cas <- rand_mvn(centre = t0_cas_center, ncell = ncell, scalar = 0.05) - t0_con <- rand_mvn(centre = t0_con_center, ncell = ncell, scalar = 0.10) + c1_cas <- rand_mvn(centre = c1_cas_center, ncell = ncell, scalar = 0.05) + c1_con <- rand_mvn(centre = c1_con_center, ncell = ncell, scalar = 0.10) graphics::par(pty = "s") - graphics::plot(t0_con, + graphics::plot(c1_con, col = "blue", xlim = c(0, 1), ylim = c(0, 1), main = "Gate 2, Condition 1", xlab = "V3", ylab = "V4") - graphics::points(t0_cas, col = "orangered4") + graphics::points(c1_cas, col = "orangered4") ``` At Condition 2, we generate 100,000 cases and 100,000 controls (`ncell = 100000`) randomly with a case centroid at (`0.65, 0.65`) and control a centroid at (`0.50, 0.50`) within a unit square window `(0, 1)`, and cases have a more focal cluster (`scalar = 0.05`) than controls (`scalar = 0.10`). ```{r gate2_condition2} # Initial parameters - t1_cas_center <- c(0.65, 0.65) - t1_con_center <- c(0.50, 0.50) + c2_cas_center <- c(0.65, 0.65) + c2_con_center <- c(0.50, 0.50) # V3 and V4 at Condition 2 - t1_cas <- rand_mvn(centre = t1_cas_center, ncell = ncell, scalar = 0.05) - t1_con <- rand_mvn(centre = t1_con_center, ncell = ncell, scalar = 0.10) + c2_cas <- rand_mvn(centre = c2_cas_center, ncell = ncell, scalar = 0.05) + c2_con <- rand_mvn(centre = c2_con_center, ncell = ncell, scalar = 0.10) graphics::par(pty = "s") - graphics::plot(t1_con, + graphics::plot(c2_con, col = "cornflowerblue", xlim = c(0, 1), ylim = c(0, 1), main = "Gate 2, Condition 2", xlab = "V3", ylab = "V4") - graphics::points(t1_cas, col = "orangered1") + graphics::points(c2_cas, col = "orangered1") ``` Compile the toy data into a data frame ```{r append_data} - df_full$V3 <- c(t1_cas[ , 1], t0_cas[ , 1], t1_con[ , 1], t0_con[ , 1]) - df_full$V4 <- c(t1_cas[ , 2], t0_cas[ , 2], t1_con[ , 2], t0_con[ , 2]) + df_full$V3 <- c(c2_cas[ , 1], c1_cas[ , 1], c2_con[ , 1], c1_con[ , 1]) + df_full$V4 <- c(c2_cas[ , 2], c1_cas[ , 2], c2_con[ , 2], c1_con[ , 2]) + + rm(c2_cas, c1_cas, c2_con, c1_con) # conserve memory ``` Generate random values for two example cytokines and append to the data frame. ```{r cytokines} # Two Cytokines - C1 <- stats::rchisq(ncell * 4, df = 5) # Random Chi-square distribution - C2 <- stats::rnorm(ncell * 4, 0, 1) # Random Gaussian distribution + Z1 <- stats::rchisq(ncell * 4, df = 5) # Random Chi-square distribution + Z2 <- stats::rnorm(ncell * 4, 0, 1) # Random Gaussian distribution # Append to data.frame - df_full$C1 <- C1 - df_full$C2 <- C2 + df_full$Z1 <- Z1 + df_full$Z2 <- Z2 + rm(Z1, Z2) # conserve memory # Visualize histograms by the two group conditions graphics::par(mfrow = c(2, 2), pty = "s") - graphics::plot(stats::density(df_full$C1[df_full$group == "case" - & df_full$time == "0"]), + graphics::plot(stats::density(df_full$Z1[df_full$group == "case" + & df_full$condition == "1"]), main = "Cytokine 1 of Cases at Condition 1") - graphics::plot(stats::density(df_full$C1[df_full$group == "case" - & df_full$time == "1"]), + graphics::plot(stats::density(df_full$Z1[df_full$group == "case" + & df_full$condition == "2"]), main = "Cytokine 1 of Cases at Condition 2") - graphics::plot(stats::density(df_full$C1[df_full$group == "control" - & df_full$time == "0"]), + graphics::plot(stats::density(df_full$Z1[df_full$group == "control" + & df_full$condition == "1"]), main = "Cytokine 1 of Controls at Condition 1") - graphics::plot(stats::density(df_full$C1[df_full$group == "control" - & df_full$time == "1"]), + graphics::plot(stats::density(df_full$Z1[df_full$group == "control" + & df_full$condition == "2"]), main = "Cytokine 1 of Controls at Condition 2") - graphics::plot(stats::density(df_full$C2[df_full$group == "case" - & df_full$time == "0"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "case" + & df_full$condition == "1"]), main = "Cytokine 2 of Cases at Condition 1") - graphics::plot(stats::density(df_full$C2[df_full$group == "case" - & df_full$time == "1"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "case" + & df_full$condition == "2"]), main = "Cytokine 2 of Cases at Condition 2") - graphics::plot(stats::density(df_full$C2[df_full$group == "control" - & df_full$time == "0"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "control" + & df_full$condition == "1"]), main = "Cytokine 2 of Controls at Condition 1") - graphics::plot(stats::density(df_full$C2[df_full$group == "control" - & df_full$time == "1"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "control" + & df_full$condition == "2"]), main = "Cytokine 2 of Controls at Condition 2") ``` The toy data frame has nine columns (id, groups, markers, and cytokines). ```{r full_data} - df_save <- df_full # create copy for latter example utils::head(df_full) ``` @@ -210,11 +214,11 @@ The toy data frame has nine columns (id, groups, markers, and cytokines). vars <- c("V1", "V2", "V3", "V4") p_correct <- "uncorrelated" set.seed(1234) # for reproducibility - df_save <- as.data.frame(df_save) + df_full <- as.data.frame(df_full) # Gates 1 and 2 start_time <- Sys.time() # record start time - out_gate <- gateR::gating(dat = df_save, + out_gate <- gateR::gating(dat = df_full, vars = vars, n_condition = 2, doplot = TRUE, @@ -224,52 +228,52 @@ The toy data frame has nine columns (id, groups, markers, and cytokines). total_time <- end_time - start_time # calculate duration of gating() example ``` -The gating process took about `r round(total_time, digits = 1)` *seconds* on a Macbook Pro (4 variables, 2 gates, 2 cytokines, `r format(nrow(df_save), big.mark= ",")` observations). The corrected significance level in the first gate was `r formatC(out_gate$lrr[[1]]$alpha, format = "e", digits = 2)`. The histograms for the two cytokines are the same as above. +The gating process took about `r round(total_time, digits = 1)` *seconds* on a Macbook Pro (4 variables, 2 gates, 2 cytokines, `r format(nrow(df_full), big.mark= ",")` observations). The corrected significance level in the first gate was `r formatC(out_gate$lrr[[1]]$alpha, format = "e", digits = 2)`. The histograms for the two cytokines are the same as above. ```{r 2C_cytokinesA} # Plot of Cytokine 1 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case" + & out_gate$obs$condition == "2"]), col = "red", main = "Cytokine 1 of cases\npost-gating", xlim = c(-5, 30), ylim = c(0, 0.2)) - graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "control" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "control" + & out_gate$obs$condition == "2"]), col = "blue", main = "Cytokine 1 of controls\npost-gating", xlim = c(-5, 30), ylim = c(0, 0.2)) # Plot of Cytokine 2 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case" + & out_gate$obs$condition == "2"]), col = "red", main = "Cytokine 2 of cases\npost-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "control" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "control" + & out_gate$obs$condition == "2"]), col = "blue", main = "Cytokine 2 of controls\npost-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) ``` -Compare histograms before and after gating. Gating reduced the overall sample size of observations from `r format(nrow(df_save), big.mark= ",")` (cases & controls and Condition 1 & Condition 2) to `r format(nrow(out_gate$obs), big.mark = ",")` observations (cases & controls and Condition 1 & Condition 2). +Compare histograms before and after gating. Gating reduced the overall sample size of observations from `r format(nrow(df_full), big.mark= ",")` (cases & controls and Condition 1 & Condition 2) to `r format(nrow(out_gate$obs), big.mark = ",")` observations (cases & controls and Condition 1 & Condition 2). ```{r 2C_cytokinesB} # Plot of Cytokine 1 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(df_save$C1[df_save$group == "case" - & df_save$time == "1"]), + graphics::plot(stats::density(df_full$Z1[df_full$group == "case" + & df_full$condition == "2"]), col = "black", lty = 1, main = "Cytokine 1 of cases\npre-gating", xlim = c(-5, 30), ylim = c(0, 0.2)) - graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case" + & out_gate$obs$condition == "2"]), col = "black", lty = 1, main = "Cytokine 1 of cases\npost-gating", @@ -277,15 +281,15 @@ Compare histograms before and after gating. Gating reduced the overall sample si ylim = c(0, 0.2)) # Plot of Cytokine 2 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(df_save$C2[df_save$group == "case" - & df_save$time == "1"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "case" + & df_full$condition == "2"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npre-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case" + & out_gate$obs$condition == "2"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npost-gating", @@ -293,11 +297,11 @@ Compare histograms before and after gating. Gating reduced the overall sample si ylim = c(0, 0.5)) ``` -### For a one condition (using only T0) +### For a one condition (using only Condition 1) ```{r 1C} -# Data subset, only T0 - df_sub <- df_save[df_save$time == 0, ] # For only condition Time = 0 +# Data subset, only c1 + df_sub <- df_full[df_full$condition == 1, ] # For only condition condition = 1 # Initial parameters alpha <- 0.05 @@ -322,24 +326,24 @@ The gating process took about `r round(total_time, digits = 1)` *seconds* on a M ```{r 1C_cytokinesA} # Plot of Cytokine 1 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case"]), + graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case"]), col = "red", main = "Cytokine 1 of cases\npost-gating", xlim = c(-5, 30), ylim = c(0, 0.2)) - graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "control"]), + graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "control"]), col = "blue", main = "Cytokine 1 of controls\npost-gating", xlim = c(-5, 30), ylim = c(0, 0.2)) # Plot of Cytokine 2 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case"]), col = "red", main = "Cytokine 2 of cases\npost-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "control"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "control"]), col = "blue", main = "Cytokine 2 of controls\npost-gating", xlim = c(-5, 5), @@ -351,13 +355,13 @@ Compare histograms before and after gating. Gating reduced the overall sample si ```{r 1C_cytokinesB} # Plot of Cytokine 1 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(df_save$C1[df_save$group == "case"]), + graphics::plot(stats::density(df_full$Z1[df_full$group == "case"]), col = "black", lty = 1, main = "Cytokine 1 of cases\npre-gating", xlim = c(-5, 30), ylim = c(0, 0.2)) - graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case"]), + graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case"]), col = "black", lty = 1, main = "Cytokine 1 of cases\npost-gating", @@ -365,13 +369,13 @@ Compare histograms before and after gating. Gating reduced the overall sample si ylim = c(0, 0.2)) # Plot of Cytokine 2 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(df_save$C2[df_save$group == "case"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "case"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npre-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npost-gating", diff --git a/vignettes/vignette.html b/vignettes/vignette.html index 8f4b864..9ad13ce 100644 --- a/vignettes/vignette.html +++ b/vignettes/vignette.html @@ -12,7 +12,7 @@ - + gateR: Statistical Gating Application for Flow and Mass Cytometry Analysis via Spatial Kernel Density Estimation @@ -315,7 +315,7 @@

gateR: Statistical Gating Application for Flow and Mass Cytometry Analysis via Spatial Kernel Density Estimation

Ian D. Buller, Ph.D., M.A. (Github: @idblr)

-

2020-10-27

+

2020-10-28

@@ -356,133 +356,137 @@

Generate random toy data using the spatstat package

Gate 1: Marker 1 and Marker 2

At Condition 1, we generate 100,000 cases and 100,000 controls (ncell = 100000) randomly MVN with a case centroid at (0.55, 0.55) and a control centroid at (0.40, 0.40) within a unit square window (0, 1), and cases have a more focal cluster (scalar = 0.05) than controls (scalar = 0.15).

# Initial parameters
-  ncell <- 100000 # number of observations per group per time
-  t0_cas_center <- c(0.55, 0.55)
-  t0_con_center <- c(0.40, 0.40)
+  ncell <- 100000 # number of observations per group per condition
+  c1_cas_center <- c(0.55, 0.55)
+  c1_con_center <- c(0.40, 0.40)
 # V1 and V2 at Condition 1
-  t0_cas <- rand_mvn(centre = t0_cas_center, ncell = ncell, scalar = 0.05)
-  t0_con <- rand_mvn(centre = t0_con_center, ncell = ncell, scalar = 0.15)
+  c1_cas <- rand_mvn(centre = c1_cas_center, ncell = ncell, scalar = 0.05)
+  c1_con <- rand_mvn(centre = c1_con_center, ncell = ncell, scalar = 0.15)
   graphics::par(pty = "s")
-  graphics::plot(t0_con,
+  graphics::plot(c1_con,
                  col = "blue",
                  xlim = c(0, 1),
                  ylim = c(0, 1),
                  main = "Gate 1, Condition 1",
                  xlab = "V1",
                  ylab = "V2")
-  graphics::points(t0_cas, col = "orangered4")
+ graphics::points(c1_cas, col = "orangered4")

At Condition 2, we generate 100,000 cases and 100,000 controls (ncell = 100000) randomly MVN with a case centroid at (0.45, 0.45) and a control centroid at (0.40, 0.40) within a unit square window (0, 1), and cases have a more focal cluster (scalar = 0.05) than controls (scalar = 0.10).

# Initial parameters
-  t1_cas_center <- c(0.45, 0.45)
-  t1_con_center <- c(0.40, 0.40)
+  c2_cas_center <- c(0.45, 0.45)
+  c2_con_center <- c(0.40, 0.40)
 # V1 and V2 at Condition 2
-  t1_cas <- rand_mvn(centre = t1_cas_center, ncell = ncell, scalar = 0.05)
-  t1_con <- rand_mvn(centre = t1_con_center, ncell = ncell, scalar = 0.10)
+  c2_cas <- rand_mvn(centre = c2_cas_center, ncell = ncell, scalar = 0.05)
+  c2_con <- rand_mvn(centre = c2_con_center, ncell = ncell, scalar = 0.10)
   graphics::par(pty = "s")
-  graphics::plot(t1_con,
+  graphics::plot(c2_con,
                  col = "cornflowerblue",
                  xlim = c(0, 1),
                  ylim = c(0, 1),
                  main = "Gate 1, Condition 2",
                  xlab = "V1",
                  ylab = "V2")
-  graphics::points(t1_cas, col = "orangered1")
+ graphics::points(c2_cas, col = "orangered1")

# compile data
   df_full <- tibble::tibble("id" = seq(1, ncell * 2 * 2, 1),
                             "group" = factor(c(rep("case", ncell * 2),
                                                rep("control", ncell * 2))),
-                            "time" = factor(c(rep("1", ncell), rep("0", ncell),
-                                              rep("1", ncell), rep("0", ncell))),
-                            "V1" = c(t1_cas[ , 1], t0_cas[ , 1], t1_con[ , 1], t0_con[ , 1]),
-                            "V2" = c(t1_cas[ , 2], t0_cas[ , 2], t1_con[ , 2], t0_con[ , 2]))
+ "condition" = factor(c(rep("2", ncell), rep("1", ncell), + rep("2", ncell), rep("1", ncell))), + "V1" = c(c2_cas[ , 1], c1_cas[ , 1], c2_con[ , 1], c1_con[ , 1]), + "V2" = c(c2_cas[ , 2], c1_cas[ , 2], c2_con[ , 2], c1_con[ , 2])) + + rm(c2_cas, c1_cas, c2_con, c1_con) # conserve memory

Gate 2: Marker 3 and Marker 4

At Condition 1, we generate 100,000 cases and 100,000 controls (ncell = 100000) randomly MVN with a case centroid at (0.55, 0.55) and a control centroid at (0.50, 0.50) within a unit square window (0, 05), but both have the same amount of spread (scalar = 0.10).

# Initial parameters
-  t0_cas_center <- c(0.55, 0.55)
-  t0_con_center <- c(0.50, 0.50)
+  c1_cas_center <- c(0.55, 0.55)
+  c1_con_center <- c(0.50, 0.50)
 # V3 and V4 at Condition 1
-  t0_cas <- rand_mvn(centre = t0_cas_center, ncell = ncell, scalar = 0.05)
-  t0_con <- rand_mvn(centre = t0_con_center, ncell = ncell, scalar = 0.10)
+  c1_cas <- rand_mvn(centre = c1_cas_center, ncell = ncell, scalar = 0.05)
+  c1_con <- rand_mvn(centre = c1_con_center, ncell = ncell, scalar = 0.10)
   graphics::par(pty = "s")
-  graphics::plot(t0_con,
+  graphics::plot(c1_con,
                  col = "blue",
                  xlim = c(0, 1),
                  ylim = c(0, 1),
                  main = "Gate 2, Condition 1",
                  xlab = "V3",
                  ylab = "V4")
-  graphics::points(t0_cas, col = "orangered4")
+ graphics::points(c1_cas, col = "orangered4")

At Condition 2, we generate 100,000 cases and 100,000 controls (ncell = 100000) randomly with a case centroid at (0.65, 0.65) and control a centroid at (0.50, 0.50) within a unit square window (0, 1), and cases have a more focal cluster (scalar = 0.05) than controls (scalar = 0.10).

# Initial parameters
-  t1_cas_center <- c(0.65, 0.65)
-  t1_con_center <- c(0.50, 0.50)
+  c2_cas_center <- c(0.65, 0.65)
+  c2_con_center <- c(0.50, 0.50)
 # V3 and V4 at Condition 2
-  t1_cas <- rand_mvn(centre = t1_cas_center, ncell = ncell, scalar = 0.05)
-  t1_con <- rand_mvn(centre = t1_con_center, ncell = ncell, scalar = 0.10)
+  c2_cas <- rand_mvn(centre = c2_cas_center, ncell = ncell, scalar = 0.05)
+  c2_con <- rand_mvn(centre = c2_con_center, ncell = ncell, scalar = 0.10)
   graphics::par(pty = "s")
-  graphics::plot(t1_con,
+  graphics::plot(c2_con,
                  col = "cornflowerblue",
                  xlim = c(0, 1),
                  ylim = c(0, 1),
                  main = "Gate 2, Condition 2",
                  xlab = "V3",
                  ylab = "V4")
-  graphics::points(t1_cas, col = "orangered1")
+ graphics::points(c2_cas, col = "orangered1")

Compile the toy data into a data frame

-
  df_full$V3 <-  c(t1_cas[ , 1], t0_cas[ , 1], t1_con[ , 1], t0_con[ , 1])
-  df_full$V4 <-  c(t1_cas[ , 2], t0_cas[ , 2], t1_con[ , 2], t0_con[ , 2])
+
  df_full$V3 <-  c(c2_cas[ , 1], c1_cas[ , 1], c2_con[ , 1], c1_con[ , 1])
+  df_full$V4 <-  c(c2_cas[ , 2], c1_cas[ , 2], c2_con[ , 2], c1_con[ , 2])
+  
+  rm(c2_cas, c1_cas, c2_con, c1_con) # conserve memory

Generate random values for two example cytokines and append to the data frame.

# Two Cytokines
-  C1 <- stats::rchisq(ncell * 4, df = 5) # Random Chi-square distribution
-  C2 <- stats::rnorm(ncell * 4, 0, 1) # Random Gaussian distribution
+  Z1 <- stats::rchisq(ncell * 4, df = 5) # Random Chi-square distribution
+  Z2 <- stats::rnorm(ncell * 4, 0, 1) # Random Gaussian distribution
 # Append to data.frame
-  df_full$C1 <- C1
-  df_full$C2 <- C2
-# Visualize histograms by the two group conditions
-  graphics::par(mfrow = c(2, 2), pty = "s")
-  graphics::plot(stats::density(df_full$C1[df_full$group == "case" 
-                                           & df_full$time == "0"]),
-                 main = "Cytokine 1 of Cases at Condition 1")
-  graphics::plot(stats::density(df_full$C1[df_full$group == "case" 
-                                           & df_full$time == "1"]),
-                 main = "Cytokine 1 of Cases at Condition 2")
-  graphics::plot(stats::density(df_full$C1[df_full$group == "control"
-                                           & df_full$time == "0"]),
-                 main = "Cytokine 1 of Controls at Condition 1")
-  graphics::plot(stats::density(df_full$C1[df_full$group == "control"
-                                           & df_full$time == "1"]),
-                 main = "Cytokine 1 of Controls at Condition 2")
-  graphics::plot(stats::density(df_full$C2[df_full$group == "case"
-                                           & df_full$time == "0"]),
-                 main = "Cytokine 2 of Cases at Condition 1")
-  graphics::plot(stats::density(df_full$C2[df_full$group == "case" 
-                                           & df_full$time == "1"]),
-                 main = "Cytokine 2 of Cases at Condition 2")
-  graphics::plot(stats::density(df_full$C2[df_full$group == "control" 
-                                           & df_full$time == "0"]),
-                 main = "Cytokine 2 of Controls at Condition 1")
-  graphics::plot(stats::density(df_full$C2[df_full$group == "control" 
-                                           & df_full$time == "1"]),
-                 main = "Cytokine 2 of Controls at Condition 2")
+ df_full$Z1 <- Z1 + df_full$Z2 <- Z2 + rm(Z1, Z2) # conserve memory +# Visualize histograms by the two group conditions + graphics::par(mfrow = c(2, 2), pty = "s") + graphics::plot(stats::density(df_full$Z1[df_full$group == "case" + & df_full$condition == "1"]), + main = "Cytokine 1 of Cases at Condition 1") + graphics::plot(stats::density(df_full$Z1[df_full$group == "case" + & df_full$condition == "2"]), + main = "Cytokine 1 of Cases at Condition 2") + graphics::plot(stats::density(df_full$Z1[df_full$group == "control" + & df_full$condition == "1"]), + main = "Cytokine 1 of Controls at Condition 1") + graphics::plot(stats::density(df_full$Z1[df_full$group == "control" + & df_full$condition == "2"]), + main = "Cytokine 1 of Controls at Condition 2") + graphics::plot(stats::density(df_full$Z2[df_full$group == "case" + & df_full$condition == "1"]), + main = "Cytokine 2 of Cases at Condition 1") + graphics::plot(stats::density(df_full$Z2[df_full$group == "case" + & df_full$condition == "2"]), + main = "Cytokine 2 of Cases at Condition 2") + graphics::plot(stats::density(df_full$Z2[df_full$group == "control" + & df_full$condition == "1"]), + main = "Cytokine 2 of Controls at Condition 1") + graphics::plot(stats::density(df_full$Z2[df_full$group == "control" + & df_full$condition == "2"]), + main = "Cytokine 2 of Controls at Condition 2")

The toy data frame has nine columns (id, groups, markers, and cytokines).

-
  df_save <- df_full # create copy for latter example
-  utils::head(df_full)
+
  utils::head(df_full)
## # A tibble: 6 x 9
-##      id group time     V1    V2    V3    V4    C1      C2
-##   <dbl> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>
-## 1     1 case  1     0.491 0.402 0.677 0.586  4.35 -0.488 
-## 2     2 case  1     0.407 0.493 0.714 0.698  8.61  0.279 
-## 3     3 case  1     0.508 0.409 0.547 0.644  6.79 -0.786 
-## 4     4 case  1     0.423 0.480 0.657 0.656  1.04 -0.552 
-## 5     5 case  1     0.367 0.420 0.635 0.637  4.10  0.239 
-## 6     6 case  1     0.499 0.405 0.547 0.656  6.99  0.0472
+## id group condition V1 V2 V3 V4 Z1 Z2 +## <dbl> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +## 1 1 case 2 0.491 0.402 0.677 0.586 4.35 -0.488 +## 2 2 case 2 0.407 0.493 0.714 0.698 8.61 0.279 +## 3 3 case 2 0.508 0.409 0.547 0.644 6.79 -0.786 +## 4 4 case 2 0.423 0.480 0.657 0.656 1.04 -0.552 +## 5 5 case 2 0.367 0.420 0.635 0.637 4.10 0.239 +## 6 6 case 2 0.499 0.405 0.547 0.656 6.99 0.0472
@@ -492,11 +496,11 @@

For two conditions

vars <- c("V1", "V2", "V3", "V4") p_correct <- "uncorrelated" set.seed(1234) # for reproducibility - df_save <- as.data.frame(df_save) + df_full <- as.data.frame(df_full) # Gates 1 and 2 start_time <- Sys.time() # record start time - out_gate <- gateR::gating(dat = df_save, + out_gate <- gateR::gating(dat = df_full, vars = vars, n_condition = 2, doplot = TRUE, @@ -507,30 +511,30 @@

For two conditions

  end_time <- Sys.time() # record end time
   total_time <- end_time - start_time # calculate duration of gating() example

-

The gating process took about 10.3 seconds on a Macbook Pro (4 variables, 2 gates, 2 cytokines, 400,000 observations). The corrected significance level in the first gate was . The histograms for the two cytokines are the same as above.

+

The gating process took about 10.4 seconds on a Macbook Pro (4 variables, 2 gates, 2 cytokines, 400,000 observations). The corrected significance level in the first gate was . The histograms for the two cytokines are the same as above.

# Plot of Cytokine 1
   graphics::par(mfrow = c(1, 2), pty = "s")
-  graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case"
-                                                & out_gate$obs$time == "1"]),
+  graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case"
+                                                & out_gate$obs$condition == "2"]),
                  col = "red", main = "Cytokine 1 of cases\npost-gating",
                  xlim = c(-5, 30),
                  ylim = c(0, 0.2))
-  graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "control" 
-                                                & out_gate$obs$time == "1"]),
+  graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "control" 
+                                                & out_gate$obs$condition == "2"]),
                  col = "blue",
                  main = "Cytokine 1 of controls\npost-gating",
                  xlim = c(-5, 30),
                  ylim = c(0, 0.2))
 # Plot of Cytokine 2
   graphics::par(mfrow = c(1, 2), pty = "s")
-  graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case"
-                                                & out_gate$obs$time == "1"]),
+  graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case"
+                                                & out_gate$obs$condition == "2"]),
                  col = "red",
                  main = "Cytokine 2 of cases\npost-gating",
                  xlim = c(-5, 5),
                  ylim = c(0, 0.5))
-  graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "control" 
-                                                & out_gate$obs$time == "1"]),
+  graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "control" 
+                                                & out_gate$obs$condition == "2"]),
                  col = "blue",
                  main = "Cytokine 2 of controls\npost-gating",
                  xlim = c(-5, 5),
@@ -539,15 +543,15 @@ 

For two conditions

Compare histograms before and after gating. Gating reduced the overall sample size of observations from 400,000 (cases & controls and Condition 1 & Condition 2) to 63,463 observations (cases & controls and Condition 1 & Condition 2).

# Plot of Cytokine 1
   graphics::par(mfrow = c(1, 2), pty = "s")
-  graphics::plot(stats::density(df_save$C1[df_save$group == "case"
-                                 & df_save$time == "1"]),
+  graphics::plot(stats::density(df_full$Z1[df_full$group == "case"
+                                 & df_full$condition == "2"]),
                  col = "black",
                  lty = 1,
                  main = "Cytokine 1 of cases\npre-gating",
                  xlim = c(-5, 30),
                  ylim = c(0, 0.2))
-  graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case"
-                                      & out_gate$obs$time == "1"]),
+  graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case"
+                                      & out_gate$obs$condition == "2"]),
                  col = "black",
                  lty = 1,
                  main = "Cytokine 1 of cases\npost-gating",
@@ -555,15 +559,15 @@ 

For two conditions

ylim = c(0, 0.2)) # Plot of Cytokine 2 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(df_save$C2[df_save$group == "case" - & df_save$time == "1"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "case" + & df_full$condition == "2"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npre-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case" - & out_gate$obs$time == "1"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case" + & out_gate$obs$condition == "2"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npost-gating", @@ -571,10 +575,10 @@

For two conditions

ylim = c(0, 0.5))

-
-

For a one condition (using only T0)

-
# Data subset, only T0
-  df_sub <- df_save[df_save$time == 0, ] # For only condition Time = 0
+
+

For a one condition (using only Condition 1)

+
# Data subset, only c1
+  df_sub <- df_full[df_full$condition == 1, ] # For only condition condition = 1
 
 # Initial parameters
   alpha <- 0.05
@@ -595,27 +599,27 @@ 

For a one condition (using only T0)

  end_time <- Sys.time() # record end time
   total_time <- end_time - start_time # calculate duration of gating() example

-

The gating process took about 5.7 seconds on a Macbook Pro (4 variables, 2 gates, 2 cytokines, 200,000 observations). The corrected significance level in the first gate was . The histograms for the two cytokines are the same as above.

+

The gating process took about 6.1 seconds on a Macbook Pro (4 variables, 2 gates, 2 cytokines, 200,000 observations). The corrected significance level in the first gate was . The histograms for the two cytokines are the same as above.

# Plot of Cytokine 1
   graphics::par(mfrow = c(1, 2), pty = "s")
-  graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case"]),
+  graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case"]),
                  col = "red",
                  main = "Cytokine 1 of cases\npost-gating",
                  xlim = c(-5, 30),
                  ylim = c(0, 0.2))
-  graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "control"]),
+  graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "control"]),
                  col = "blue",
                  main = "Cytokine 1 of controls\npost-gating",
                  xlim = c(-5, 30),
                  ylim = c(0, 0.2))
 # Plot of Cytokine 2
   graphics::par(mfrow = c(1, 2), pty = "s")
-  graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case"]),
+  graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case"]),
                  col = "red",
                  main = "Cytokine 2 of cases\npost-gating",
                  xlim = c(-5, 5),
                  ylim = c(0, 0.5))
-  graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "control"]),
+  graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "control"]),
                  col = "blue",
                  main = "Cytokine 2 of controls\npost-gating",
                  xlim = c(-5, 5),
@@ -624,13 +628,13 @@ 

For a one condition (using only T0)

Compare histograms before and after gating. Gating reduced the overall sample size of observations from 200,000 (cases & controls) to 85,729 observations (cases & controls).

# Plot of Cytokine 1
   graphics::par(mfrow = c(1, 2), pty = "s")
-  graphics::plot(stats::density(df_save$C1[df_save$group == "case"]),
+  graphics::plot(stats::density(df_full$Z1[df_full$group == "case"]),
                  col = "black",
                  lty = 1,
                  main = "Cytokine 1 of cases\npre-gating",
                  xlim = c(-5, 30),
                  ylim = c(0, 0.2))
-  graphics::plot(stats::density(out_gate$obs$C1[out_gate$obs$group == "case"]),
+  graphics::plot(stats::density(out_gate$obs$Z1[out_gate$obs$group == "case"]),
                  col = "black",
                  lty = 1,
                  main = "Cytokine 1 of cases\npost-gating",
@@ -638,13 +642,13 @@ 

For a one condition (using only T0)

ylim = c(0, 0.2)) # Plot of Cytokine 2 graphics::par(mfrow = c(1, 2), pty = "s") - graphics::plot(stats::density(df_save$C2[df_save$group == "case"]), + graphics::plot(stats::density(df_full$Z2[df_full$group == "case"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npre-gating", xlim = c(-5, 5), ylim = c(0, 0.5)) - graphics::plot(stats::density(out_gate$obs$C2[out_gate$obs$group == "case"]), + graphics::plot(stats::density(out_gate$obs$Z2[out_gate$obs$group == "case"]), col = "black", lty = 1, main = "Cytokine 2 of cases\npost-gating",