Skip to content

Commit

Permalink
In getFlowJoLabels(), if one of the cellTypes is not found in any…
Browse files Browse the repository at this point in the history
… sample

of any group, issue warning instead of error, populates corresponding output
with NA's
  • Loading branch information
phauchamps committed Feb 8, 2024
1 parent e061937 commit 5e692b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## CytoPipelineUtils 0.99.4
- Added `getEventNbFromFJGates()`
- In `getFlowJoLabels()`, if one of the `cellTypes` is not found in any sample
of any group, issue warning instead of error, populates corresponding output
with NA's

## CytoPipelineUtils 0.99.3
- `applyFlowJoGate()` can now match sample file with sample names in wsp file,
Expand Down
14 changes: 10 additions & 4 deletions R/gating.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ getFlowJoLabels <- function(ff,
for (j in seq_along(cellTypes)) {
if (!foundCellType[j]) {
ct <- cellTypes[j]
stop("Cell type [", ct, "] not found in any sample of any group !")
warning("Cell type [", ct, "] not found in any sample of any group !")
}
}

Expand All @@ -292,10 +292,14 @@ getFlowJoLabels <- function(ff,
dimnames = list(NULL ,c(cellTypes, "unlabeled")))

for (ct in cellTypes){
res$matrix[cellMap[[ct]], ct] <- TRUE
if (is.null(cellMap[[ct]])) {
res$matrix[, ct] <- NA
} else {
res$matrix[cellMap[[ct]], ct] <- TRUE
}
}

res$matrix[, nCellTypes+1] <- (rowSums(res$matrix) == 0)
res$matrix[, nCellTypes+1] <- (rowSums(res$matrix, na.rm = TRUE) == 0)


# 2. 'labels' with one label attached to each cell. If conflict, take the
Expand All @@ -308,7 +312,9 @@ getFlowJoLabels <- function(ff,
}

for (ct in cellTypes[order(nCellsByType, decreasing = TRUE)]) {
res$labels[cellMap[[ct]]] <- ct
if(!is.null(cellMap[[ct]])) {
res$labels[cellMap[[ct]]] <- ct
}
}

# 3. computed actualDiffTime (for withFJv10TimeCorrection work-around)
Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-gating.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,21 @@ test_that("getFlowJoLabels works", {
# what happens when cell type not found ?
cellTypes <- c("Cells", "Debrais", "CD4+")

expect_error(getFlowJoLabels(agg,
expect_warning(resW <- getFlowJoLabels(agg,
wspFile = wspFile,
groups = groups,
cellTypes = cellTypes),
regexp = "not found in any sample of any group")
regexp = "not found in any sample of any group")

labels <- resW$labels

expect_equal(sum(labels == "Cells"), 5518)
expect_equal(sum(labels == "CD4+"), 2552)
expect_equal(sum(labels == "Debrais"), 0)
expect_equal(sum(labels == "unlabeled"), 1930)

expect_equal(sum(resW$matrix[,"Cells"]), 8070)
expect_true(all(is.na(resW$matrix[,"Debrais"])))

# with subset file from sample two only (special case where file 1 is not
# represented in aggregate)
Expand Down

0 comments on commit 5e692b3

Please sign in to comment.