Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions tests/testthat/test-celltypist.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ test_that("celltypist runs", {

# This appears to differ in bioconductor 3.15 vs devel
# This should be identical to the test below
expect_equal(11, length(unique(seuratObj$majority_voting)), info = 'using default model', tolerance = 1)
expect_equal(11, length(unique(seuratObj$majority_voting)), info = 'using default model', tolerance = 1, scale = 1)
expect_equal(110, length(unique(seuratObj$predicted_labels)))
expect_equal(289, unname(table(seuratObj$predicted_labels)['B cells']))

# ensure the RIRA model works:
seuratObj <- RunCellTypist(seuratObj, modelName = 'RIRA_Immune_v2', columnPrefix = 'RIRA.')
print(sort(table(seuratObj$RIRA.majority_voting)))
expect_equal(4, length(unique(seuratObj$RIRA.majority_voting)), info = 'using RIRA model', tolerance = 1)
expect_equal(346, unname(table(seuratObj$RIRA.majority_voting)['Bcell']), tolerance = 1)
expect_equal(1653, unname(table(seuratObj$RIRA.majority_voting)['T_NK']), tolerance = 1)
expect_equal(4, length(unique(seuratObj$RIRA.majority_voting)), info = 'using RIRA model', tolerance = 1, scale = 1)
expect_equal(346, unname(table(seuratObj$RIRA.majority_voting)['Bcell']), tolerance = 1, scale = 1)
expect_equal(1653, unname(table(seuratObj$RIRA.majority_voting)['T_NK']), tolerance = 1, scale = 1)
expect_equal(686, unname(table(seuratObj$RIRA.majority_voting)['Myeloid']))

# NOTE: this is very slow, so skip in automated testing for now
Expand All @@ -74,9 +74,9 @@ test_that("celltypist runs", {

print(table(seuratObj$majority_voting))
print(table(seuratObj$predicted_labels))
expect_equal(10, length(unique(seuratObj$majority_voting)), info = 'using custom model', tolerance = 1)
expect_equal(54, length(unique(seuratObj$predicted_labels)), tolerance = 3)
expect_equal(356, unname(table(seuratObj$predicted_labels)['B cells']), tolerance = 2)
expect_equal(10, length(unique(seuratObj$majority_voting)), info = 'using custom model', tolerance = 1, scale = 1)
expect_equal(47, length(unique(seuratObj$predicted_labels)), tolerance = 3, scale = 1)
expect_equal(335, unname(table(seuratObj$predicted_labels)['B cells']), tolerance = 2, scale = 1)
})

test_that("celltypist runs with batchSize", {
Expand All @@ -93,8 +93,8 @@ test_that("celltypist runs with batchSize", {
print(table(seuratObj$majority_voting))

# This should be identical to the test above
expect_equal(13, length(unique(seuratObj$cellclass)), info = 'using default model', tolerance = 0)
expect_equal(28, length(unique(seuratObj$majority_voting)), info = 'using default model', tolerance = 1) # NOTE: getting different outcomes on devel vs. 3.16, perhaps due to some package difference? the difference is ambugious calls
expect_equal(13, length(unique(seuratObj$cellclass)), info = 'using default model')
expect_equal(28, length(unique(seuratObj$majority_voting)), info = 'using default model', tolerance = 1, scale = 1) # NOTE: getting different outcomes on devel vs. 3.16, perhaps due to some package difference? the difference is ambugious calls
expect_equal(110, length(unique(seuratObj$predicted_labels)))
expect_equal(289, unname(table(seuratObj$predicted_labels)['B cells']))
})
Expand All @@ -106,13 +106,13 @@ test_that("celltypist runs for RIRA models", {
print(table(seuratObj$RIRA_TNK_v2.cellclass))

expect_equal('RIRA_TNK_v2', seuratObj@misc$RIRA_TNK_Model)
expect_equal(4, length(unique(seuratObj$RIRA_TNK_v2.cellclass)), info = 'using RIRA T_NK', tolerance = 1)
expect_equal(221, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['CD4+ T Cells']), tolerance = 1)
expect_equal(1028, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['CD8+ T Cells']), tolerance = 1)
expect_equal(66, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['NK Cells']), tolerance = 1)
expect_equal(1366, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['Unassigned']), tolerance = 1)
expect_equal(4, length(unique(seuratObj$RIRA_TNK_v2.cellclass)), info = 'using RIRA T_NK', tolerance = 1, scale = 1)
expect_equal(221, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['CD4+ T Cells']), tolerance = 1, scale = 1)
expect_equal(1028, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['CD8+ T Cells']), tolerance = 1, scale = 1)
expect_equal(66, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['NK Cells']), tolerance = 1, scale = 1)
expect_equal(1366, unname(table(seuratObj$RIRA_TNK_v2.cellclass)['Unassigned']), tolerance = 1, scale = 1)

expect_equal(6.64e-08, min(seuratObj$RIRA_TNK_v2.prob.NK.Cells), tolerance = 0.00001)
expect_equal(6.64e-08, min(seuratObj$RIRA_TNK_v2.prob.NK.Cells), tolerance = 0.00001, scale = 1)

seuratObj <- Classify_Myeloid(seuratObj, retainProbabilityMatrix = TRUE)
print('RIRA_Myeloid_v3:')
Expand All @@ -121,8 +121,8 @@ test_that("celltypist runs for RIRA models", {

expect_equal('RIRA_FineScope_Myeloid_v3', seuratObj@misc$RIRA_Myeloid_Model)
expect_equal(5, length(unique(seuratObj$RIRA_Myeloid_v3.cellclass)), info = 'using RIRA Myeloid')
expect_equal(32, unname(table(seuratObj$RIRA_Myeloid_v3.cellclass)['DC']), tolerance = 1)
expect_equal(32, unname(table(seuratObj$RIRA_Myeloid_v3.coarseclass)['DC']), tolerance = 1)
expect_equal(32, unname(table(seuratObj$RIRA_Myeloid_v3.cellclass)['DC']), tolerance = 1, scale = 1)
expect_equal(32, unname(table(seuratObj$RIRA_Myeloid_v3.coarseclass)['DC']), tolerance = 1, scale = 1)
})

test_that("FilterDisallowedClasses works as expected", {
Expand All @@ -136,18 +136,18 @@ test_that("FilterDisallowedClasses works as expected", {
print(table(seuratObj$RIRA_Immune_v2.cellclass))

expect_equal('RIRA_Immune_v2', seuratObj@misc$RIRA_Immune_Model)
expect_equal(256, sum(seuratObj$RIRA_Immune_v2.cellclass == 'Bcell', na.rm = T), tolerance = 1)
expect_equal(258, sum(seuratObj$RIRA_Immune_v2.cellclass == 'Bcell', na.rm = T), tolerance = 1, scale = 1)
expect_equal(577, sum(seuratObj$RIRA_Immune_v2.cellclass == 'Myeloid', na.rm = T))
expect_equal(1340, sum(seuratObj$RIRA_Immune_v2.cellclass == 'T_NK', na.rm = T))

print('DisallowedUCellCombinations:')
print(table(seuratObj$DisallowedUCellCombinations))

# NOTE: these are producing different results on 3.16 vs devel. This is possibly scGate versions?
expect_equal(347, sum(seuratObj$DisallowedUCellCombinations == 'NeutrophilLineage.RM_UCell', na.rm = T), tolerance = 3)
expect_equal(21, sum(seuratObj$DisallowedUCellCombinations == 'Erythrocyte.RM_UCell', na.rm = T), tolerance = 1)
expect_equal(55, sum(seuratObj$DisallowedUCellCombinations == 'NK.RM_UCell', na.rm = T), tolerance = 3)
expect_equal(57, sum(seuratObj$DisallowedUCellCombinations == 'Platelet.RM_UCell', na.rm = T), tolerance = 1)
expect_equal(301, sum(seuratObj$DisallowedUCellCombinations == 'NeutrophilLineage.RM_UCell', na.rm = T), tolerance = 3, scale = 1)
expect_equal(15, sum(seuratObj$DisallowedUCellCombinations == 'Erythrocyte.RM_UCell', na.rm = T), tolerance = 1, scale = 1)
expect_equal(51, sum(seuratObj$DisallowedUCellCombinations == 'NK.RM_UCell', na.rm = T), tolerance = 3, scale = 1)
expect_equal(51, sum(seuratObj$DisallowedUCellCombinations == 'Platelet.RM_UCell', na.rm = T), tolerance = 1, scale = 1)

# Create fake clustering:
print(table(seuratObj$RIRA_Immune_v2.cellclass, seuratObj$scGateConsensus))
Expand All @@ -160,7 +160,7 @@ test_that("FilterDisallowedClasses works as expected", {
expect_equal(1340, sum(seuratObj$RIRA_Immune_v2.cellclass == 'T_NK', na.rm = T))

expect_equal(336, sum(seuratObj$RIRA_Immune_v2.cellclass.recovered == 'Bcell', na.rm = T))
expect_equal(665, sum(seuratObj$RIRA_Immune_v2.cellclass.recovered == 'Myeloid', na.rm = T))
expect_equal(1615, sum(seuratObj$RIRA_Immune_v2.cellclass.recovered == 'T_NK', na.rm = T))
expect_equal(664, sum(seuratObj$RIRA_Immune_v2.cellclass.recovered == 'Myeloid', na.rm = T))
expect_equal(1616, sum(seuratObj$RIRA_Immune_v2.cellclass.recovered == 'T_NK', na.rm = T), tolerance = 1, scale = 1)

})
42 changes: 21 additions & 21 deletions tests/testthat/test-scgate.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ test_that("scGate Runs", {

# Try without reductions present:
seuratObj <- RunScGate(seuratObj, gate)
expect_equal(sum(seuratObj$is.pure == 'Pure'), 1486, info = 'Before DimRedux', tolerance = 1)
expect_equal(sum(seuratObj$is.pure == 'Pure'), 1500, info = 'Before DimRedux', tolerance = 1, scale = 1)

# Try with aliasing of models:
seuratObj <- RunScGateForModels(seuratObj, modelNames = c('Bcell', 'Tcell', 'NK', 'Myeloid'), labelRename = list(Tcell = 'T_NK', NK = 'T_NK'))
print(sort(table(seuratObj$scGateConsensus)))
dat <- table(seuratObj$scGateConsensus)
expect_equal(unname(dat[['Bcell']]), 244, info = 'With aliasing', tolerance = 2)
expect_equal(unname(dat[['T_NK']]), 1657, info = 'With aliasing', tolerance = 1)
expect_equal(unname(dat[['Bcell']]), 308, info = 'With aliasing', tolerance = 2, scale = 1)
expect_equal(unname(dat[['T_NK']]), 1645, info = 'With aliasing', tolerance = 1, scale = 1)

expect_false('Tcell' %in% names(dat), info = 'With aliasing')
expect_false('NK' %in% names(dat), info = 'With aliasing')
Expand All @@ -68,7 +68,7 @@ test_that("scGate Runs", {
if (packageVersion('UCell') < '2.5.0') {
expect_equal(sum(seuratObj$is.pure == 'Pure'), 1505, info = 'After DimRedux')
} else {
expect_equal(sum(seuratObj$is.pure == 'Pure'), 1493, info = 'After DimRedux', tolerance = 1)
expect_equal(sum(seuratObj$is.pure == 'Pure'), 1511, info = 'After DimRedux', tolerance = 1, scale = 1)
}

#At least execute this code once, so overt errors are caught
Expand All @@ -81,7 +81,7 @@ test_that("scGate works with built-in gates", {
# Use with built-in gate:
seuratObj <- getBaseSeuratData()
seuratObj <- RunScGate(seuratObj, model = 'Bcell')
expect_equal(sum(seuratObj$is.pure == 'Pure'), 340, tolerance = 1)
expect_equal(sum(seuratObj$is.pure == 'Pure'), 329, tolerance = 1, scale = 1)

})

Expand All @@ -95,7 +95,7 @@ test_that("scGates runs on all", {
print('RunScGateWithDefaultModels, using dropAmbiguousConsensusValues = FALSE')
print(dat)

expect_equal(unname(dat[['Bcell,Bcell.NonGerminalCenter,Immune,PanBcell']]), 285, tolerance = 1)
expect_equal(unname(dat[['Bcell,Bcell.NonGerminalCenter,Immune,PanBcell']]), 296, tolerance = 1, scale = 1)

# Now with ambiguous cleanup:
seuratObj <- RunScGateWithDefaultModels(seuratObj, dropAmbiguousConsensusValues = TRUE)
Expand All @@ -104,9 +104,9 @@ test_that("scGates runs on all", {
print(dat)
expect_false('MoMacDC,Myeloid' %in% names(dat))
if (packageVersion('UCell') < '2.5.0') {
expect_equal(unname(dat[['Immune']]), 7, tolerance = 1)
expect_equal(unname(dat[['Immune']]), 7, tolerance = 1, scale = 1)
} else {
expect_equal(unname(dat[['Immune']]), 131, tolerance = 1)
expect_equal(unname(dat[['Immune']]), 116, tolerance = 1, scale = 1)
}
})

Expand All @@ -127,15 +127,15 @@ test_that("scGate Runs", {
)
} else {
expected <- c(
Bcell.RM = 337,
Myeloid.RM = 676,
T_NK = 1647,
Bcell.RM = 333,
Myeloid.RM = 648,
T_NK = 1614,
'Bcell.RM,T_NK' = 15
)
}

for (pop in names(expected)) {
expect_equal(unname(dat[[pop]]), expected[[pop]], info = paste0('RM models: ', pop), tolerance = 3)
expect_equal(unname(dat[[pop]]), expected[[pop]], info = paste0('RM models: ', pop), tolerance = 3, scale = 1)
}

# Now use wrapper
Expand All @@ -145,28 +145,28 @@ test_that("scGate Runs", {
dat <- table(seuratObj$scGateConsensus)

expected <- c(
Bcell = 337,
Myeloid = 680,
T_NK = 1647,
Bcell = 332,
Myeloid = 650,
T_NK = 1614,
'Bcell,T_NK' = 15,
Platelet = 14
)

for (pop in names(expected)) {
expect_equal(unname(dat[[pop]]), expected[[pop]], info = 'RM models using wrapper', tolerance = 4)
expect_equal(unname(dat[[pop]]), expected[[pop]], info = 'RM models using wrapper', tolerance = 4, scale = 1)
}

print(sort(table(seuratObj$scGateRaw)))
dat <- table(seuratObj$scGateRaw)

expected <- c(
NK.RM = 72,
Myeloid.RM = 679,
Tcell.RM = 1301,
'NK.RM,Tcell.RM' = 274
NK.RM = 65,
Myeloid.RM = 648,
Tcell.RM = 1284,
'NK.RM,Tcell.RM' = 265
)

for (pop in names(expected)) {
expect_equal(unname(dat[[pop]]), expected[[pop]], info = 'RM models, raw calls', tolerance = 4)
expect_equal(unname(dat[[pop]]), expected[[pop]], info = 'RM models, raw calls', tolerance = 4, scale = 1)
}
})