Skip to content

Commit a9a8ee2

Browse files
committed
Strip NAs from bad_genes_all before checking length
The condition !all(is.na(bad_genes_all)) could still be TRUE even if bad_genes_all only contains NAs from legitimate NA rows. The solution is to remove all NAs first, and then see how long the vector is.
1 parent e9786af commit a9a8ee2

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

R/convert.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ convert_gene <- function(df, frm, to, species = "human", frm_cols = NULL,
217217
}
218218

219219
# Display genes we couldn't convert
220-
if (!all(is.na(bad_genes_all))) {
221-
bad_genes <- unique(bad_genes_all)
220+
bad_genes <- unique(bad_genes_all[!is.na(bad_genes_all)])
221+
if (length(bad_genes) > 0) {
222222
warning(paste(
223223
"These genes are not in IMGT for this species and will be replaced with NA:\n",
224-
paste(unique(bad_genes), collapse = ", ")
224+
paste(bad_genes, collapse = ", ")
225225
))
226226
}
227227

tests/testthat/test-convert.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ test_that("convert_gene verbose flag works", {
306306
})
307307

308308

309+
test_that("NA gene values do not trigger a bad-genes warning", {
310+
adapt_v2_df <- data.frame(
311+
vMaxResolved = c("TCRAV12-01*01", NA),
312+
jMaxResolved = c("TCRAJ16-01*01", NA),
313+
aminoAcid = c("CAVLIF", NA)
314+
)
315+
suppressMessages({
316+
expect_no_warning(convert_gene(adapt_v2_df, "adaptivev2", "imgt", verbose = FALSE))
317+
})
318+
})
319+
320+
309321
test_that("bad_genes_col flag works", {
310322
# Test dataframe with some genes that won't convert
311323
tenx_df_bad <- data.frame(

0 commit comments

Comments
 (0)