Skip to content

Commit

Permalink
amended subsample() as to keep the original order of events
Browse files Browse the repository at this point in the history
- amended subsample()
- updated unit tests accordingly
- reactivated all unit tests related to ggplot category
  • Loading branch information
phauchamps committed Aug 10, 2023
1 parent 49ec6a6 commit 3d5a9de
Show file tree
Hide file tree
Showing 25 changed files with 1,621 additions and 748 deletions.
3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ subsample <- function(ff, nEvents, seed = NULL, ...) {
replace = FALSE
)
}

# order the kept events to maintain chronology of events !
keep <- sort(keep)

# add Original_ID as a new column if necessary
ff <- appendCellID(ff)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 182 additions & 0 deletions tests/testthat/_snaps/gating/singletsgate-default-channels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 182 additions & 0 deletions tests/testthat/_snaps/gating/singletsgate-selected-channels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 86 additions & 86 deletions tests/testthat/_snaps/ggplots/ggplotfilterevents-2d-5000-points.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 86 additions & 86 deletions tests/testthat/_snaps/ggplots/ggplotfilterevents-2d-all-points.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 86 additions & 86 deletions tests/testthat/_snaps/ggplots/ggplotfilterevents-2d-small-size.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 86 additions & 86 deletions tests/testthat/_snaps/ggplots/ggplotfilterevents-2d-translist-run.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/fixtures/ff_QC_flowAI.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_c.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_cells_manual_gate.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_lcells_manual_gate.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_m.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_m2.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_m3.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_m4.rds
Binary file not shown.
Binary file modified tests/testthat/fixtures/ff_s3.rds
Binary file not shown.
34 changes: 2 additions & 32 deletions tests/testthat/test-CytoProcessingStepImplementations.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,6 @@ test_that("estimateScaleTransforms work", {
)
})

# test_that("selectRandomSamples works", {
# rawDataDir <-
# system.file("extdata", package = "CytoPipeline")
# sampleFiles <-
# file.path(rawDataDir, list.files(rawDataDir, pattern = "Donor"))
#
# seed <- 2
# nSamples <- 1
#
# newSampleFiles <- selectRandomSamples(sampleFiles,
# nSamples = nSamples,
# seed = seed)
# expected <- sampleFiles[1]
# expect_equal(newSampleFiles,
# expected)
#
# newSampleFiles <- selectRandomSamples(sampleFiles,
# nSamples = 3,
# seed = seed)
#
# expect_equal(newSampleFiles,
# sampleFiles)
#
# expect_error(selectRandomSamples(sampleFiles,
# nSamples = 0,
# seed = seed),
# regexp = "should be a numeric >= 1")
#
#
# })

test_that("readSampleFiles with no sample files gives an error", {
rawDataDir <-
Expand Down Expand Up @@ -551,7 +521,7 @@ test_that("removeDebrisManualGate works", {

ref_ff_cells <- readRDS(test_path("fixtures", "ff_cells_manual_gate.rds"))

#saveRDS(ff_cells, test_path("fixtures", "ff_cells_manual_gate.rds"))
# saveRDS(ff_cells, test_path("fixtures", "ff_cells_manual_gate.rds"))

expect_equal(
flowCore::exprs(ff_cells),
Expand All @@ -575,7 +545,7 @@ test_that("removeDeadCellsManualGate works", {

ref_ff_lcells <- readRDS(test_path("fixtures", "ff_lcells_manual_gate.rds"))

#saveRDS(ff_lcells, test_path("fixtures", "ff_lcells_manual_gate.rds"))
# saveRDS(ff_lcells, test_path("fixtures", "ff_lcells_manual_gate.rds"))

expect_equal(
flowCore::exprs(ff_lcells),
Expand Down
217 changes: 103 additions & 114 deletions tests/testthat/test-gating.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,117 +21,106 @@ path <- system.file("scripts",

source(file.path(path,"MakeOMIP021UTSamples.R"))

# TO DO: reactivate tests when ggplot version is fixed
# error message (issue with vdiffr::expect_doppelganger())
# Backtrace:
# 1. └─vdiffr::expect_doppelganger(...) at test-ggplots.R:58:4
# 2. └─vdiffr (local) writer(fig, testcase, title)
# 3. └─vdiffr:::svglite(file)
# 4. └─vdiffr:::svglite_(...)
# ── Error ('test-ggplots.R:175'): ggplotEvents with 2D works ────────────────────
# Error in `svglite_(filename, bg, width, height, pointsize, standalone,
# always_valid)`: Graphics API version mismatch

# test_that("singletsGate works", {
# mySingletsGate <- singletsGate(OMIP021UTSamples[[1]])
#
# selectedSinglets <- flowCore::filter(
# OMIP021UTSamples[[1]],
# mySingletsGate
# )
# ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)
#
# linRange <- c(0, 250000)
# p <- ggplotFilterEvents(
# ffPre = OMIP021UTSamples[[1]],
# ffPost = ff_l,
# seed = 1,
# xChannel = "FSC-A", xLinearRange = linRange,
# yChannel = "FSC-H", yLinearRange = linRange
# )
#
# vdiffr::expect_doppelganger("singletsGate default channels", fig = p)
#
# mySingletsGate <- singletsGate(OMIP021UTSamples[[1]], nmad = 3)
#
# selectedSinglets <- flowCore::filter(
# OMIP021UTSamples[[1]],
# mySingletsGate
# )
# ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)
#
# p <- ggplotFilterEvents(
# ffPre = OMIP021UTSamples[[1]],
# ffPost = ff_l,
# seed = 1,
# xChannel = "FSC-A", xLinearRange = linRange,
# yChannel = "FSC-H", yLinearRange = linRange
# )
#
# vdiffr::expect_doppelganger(
# "singletsGate default channels with fixed nmad",
# fig = p
# )
#
# mySingletsGate <- singletsGate(OMIP021UTSamples[[1]],
# channel1 = "SSC-A",
# channel2 = "SSC-H"
# )
#
# selectedSinglets <- flowCore::filter(
# OMIP021UTSamples[[1]],
# mySingletsGate
# )
# ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)
#
# p <- ggplotFilterEvents(
# ffPre = OMIP021UTSamples[[1]],
# ffPost = ff_l,
# seed = 1,
# xChannel = "SSC-A", xLinearRange = linRange,
# yChannel = "SSC-H", yLinearRange = linRange
# )
#
# vdiffr::expect_doppelganger("singletsGate selected channels", fig = p)
#
# # test application of two gates one after the other
# singletsGate1 <- singletsGate(OMIP021UTSamples[[1]], nmad = 3)
# singletsGate2 <- singletsGate(OMIP021UTSamples[[1]],
# channel1 = "SSC-A",
# channel2 = "SSC-H",
# filterId = "Singlets2"
# )
#
# singletCombinedGate <- singletsGate1 & singletsGate2
#
# selectedSinglets <- flowCore::filter(
# OMIP021UTSamples[[1]],
# singletCombinedGate
# )
#
# ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)
#
# p1 <- ggplotFilterEvents(
# ffPre = OMIP021UTSamples[[1]],
# ffPost = ff_l,
# seed = 1,
# xChannel = "FSC-A", xLinearRange = linRange,
# yChannel = "FSC-H", yLinearRange = linRange
# )
#
# p2 <- ggplotFilterEvents(
# ffPre = OMIP021UTSamples[[1]],
# ffPost = ff_l,
# seed = 1,
# xChannel = "SSC-A", xLinearRange = linRange,
# yChannel = "SSC-H", yLinearRange = linRange
# )
#
#
# vdiffr::expect_doppelganger("singletsGates one after the other - fig1",
# fig = p1
# )
# vdiffr::expect_doppelganger("singletsGates one after the other - fig2",
# fig = p2
# )
# })
test_that("singletsGate works", {
mySingletsGate <- singletsGate(OMIP021UTSamples[[1]])

selectedSinglets <- flowCore::filter(
OMIP021UTSamples[[1]],
mySingletsGate
)
ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)

linRange <- c(0, 250000)
p <- ggplotFilterEvents(
ffPre = OMIP021UTSamples[[1]],
ffPost = ff_l,
seed = 1,
xChannel = "FSC-A", xLinearRange = linRange,
yChannel = "FSC-H", yLinearRange = linRange
)

vdiffr::expect_doppelganger("singletsGate default channels", fig = p)

mySingletsGate <- singletsGate(OMIP021UTSamples[[1]], nmad = 3)

selectedSinglets <- flowCore::filter(
OMIP021UTSamples[[1]],
mySingletsGate
)
ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)

p <- ggplotFilterEvents(
ffPre = OMIP021UTSamples[[1]],
ffPost = ff_l,
seed = 1,
xChannel = "FSC-A", xLinearRange = linRange,
yChannel = "FSC-H", yLinearRange = linRange
)

vdiffr::expect_doppelganger(
"singletsGate default channels with fixed nmad",
fig = p
)

mySingletsGate <- singletsGate(OMIP021UTSamples[[1]],
channel1 = "SSC-A",
channel2 = "SSC-H"
)

selectedSinglets <- flowCore::filter(
OMIP021UTSamples[[1]],
mySingletsGate
)
ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)

p <- ggplotFilterEvents(
ffPre = OMIP021UTSamples[[1]],
ffPost = ff_l,
seed = 1,
xChannel = "SSC-A", xLinearRange = linRange,
yChannel = "SSC-H", yLinearRange = linRange
)

vdiffr::expect_doppelganger("singletsGate selected channels", fig = p)

# test application of two gates one after the other
singletsGate1 <- singletsGate(OMIP021UTSamples[[1]], nmad = 3)
singletsGate2 <- singletsGate(OMIP021UTSamples[[1]],
channel1 = "SSC-A",
channel2 = "SSC-H",
filterId = "Singlets2"
)

singletCombinedGate <- singletsGate1 & singletsGate2

selectedSinglets <- flowCore::filter(
OMIP021UTSamples[[1]],
singletCombinedGate
)

ff_l <- flowCore::Subset(OMIP021UTSamples[[1]], selectedSinglets)

p1 <- ggplotFilterEvents(
ffPre = OMIP021UTSamples[[1]],
ffPost = ff_l,
seed = 1,
xChannel = "FSC-A", xLinearRange = linRange,
yChannel = "FSC-H", yLinearRange = linRange
)

p2 <- ggplotFilterEvents(
ffPre = OMIP021UTSamples[[1]],
ffPost = ff_l,
seed = 1,
xChannel = "SSC-A", xLinearRange = linRange,
yChannel = "SSC-H", yLinearRange = linRange
)


vdiffr::expect_doppelganger("singletsGates one after the other - fig1",
fig = p1
)
vdiffr::expect_doppelganger("singletsGates one after the other - fig2",
fig = p2
)
})
1 change: 1 addition & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details (<http://www.gnu.org/licenses/>).

data("OMIP021Samples")

test_that("areSignalCols works", {
ff <- OMIP021Samples[[1]]
Expand Down

0 comments on commit 3d5a9de

Please sign in to comment.