Skip to content

Commit

Permalink
test for import_vdj include_mutations bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sheridar committed Oct 7, 2023
1 parent c4bd652 commit 97d9c2d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
1 change: 0 additions & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ library(SingleCellExperiment)
library(djvdj)
library(Seurat)


# Load GEX data
data_dir <- system.file("extdata/splen", package = "djvdj")

Expand Down
63 changes: 44 additions & 19 deletions tests/testthat/test-import-vdj.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
# Test data
# # Load GEX data
# data_dir <- system.file("extdata/splen", package = "djvdj")
#
# gex_dirs <- c(
# BL6 = file.path(data_dir, "BL6_GEX/filtered_feature_bc_matrix"),
# MD4 = file.path(data_dir, "MD4_GEX/filtered_feature_bc_matrix")
# )
#
# splen_so <- gex_dirs |>
# Read10X() |>
# CreateSeuratObject() |>
# AddMetaData(splen_meta)

# Contig paths
ctigs <- c(
file.path(data_dir, "BL6_BCR"),
Expand Down Expand Up @@ -92,10 +79,29 @@ test_that("import_vdj number of chains represented by each column", {
purrr::reduce(expect_identical)
})

# Check include_constant
# Check include_mutations
# this checks for bug that duplicated read and umi counts with include_mutations
test_that("import_vdj include_mutations", {
res_1 <- import_vdj(
vdj_dir = ctigs,
include_mutations = TRUE
)

res_1 <- res_1 |>
dplyr::select(-matches("^(all|[vdjc]+)_(ins|del|mis)"))

res_2 <- import_vdj(
vdj_dir = ctigs,
include_mutations = FALSE
)

expect_identical(res_1, res_2)
})

# Check include_constant
test_that("import_vdj include_mutations include_constant", {

check_constant <- function(so, include_constant){
check_constant <- function(so, include_constant) {
res <- so |>
import_vdj(
vdj_dir = ctigs,
Expand All @@ -107,28 +113,35 @@ test_that("import_vdj include_mutations", {
dat <- res@meta.data
types <- c("ins", "del", "mis")

all_types <- lapply(types, function(type){
dat_all <- dat[ , grepl(paste0("PREFIX_all_", type, "$"), colnames(dat))]
all_types <- lapply(types, function(type) {
dat_all <- dat[, grepl(paste0("PREFIX_all_", type, "$"), colnames(dat))]

suppressWarnings(dat_all <- as.double(dat_all))

dat_all[is.na(dat_all)] <- 0

if(include_constant){
dat_ind <- dat[ , grepl(paste0("PREFIX_[v|d|j|c]_", type, "$"), colnames(dat))]

} else {
dat_ind <- dat[ , grepl(paste0("PREFIX_[v|d|j]_", type, "$"), colnames(dat))]
}

suppressWarnings(dat_ind <- apply(dat_ind, 2, as.double))
dat_ind[is.na(dat_ind)] <- 0

return(data.frame(sum_val = rowSums(dat_ind), all_val = dat_all))
})

all_types <- do.call(rbind, all_types)
return(all_types)
}

constant_included <- check_constant(so, include_constant = TRUE)
constant_excluded <- check_constant(so, include_constant = FALSE)

expect_identical(constant_included$sum_val, constant_included$all_val)
expect_identical(constant_included$sum_val, constant_included$all_val)
expect_identical(constant_excluded$sum_val, constant_excluded$all_val)
})

# Check arguments for data.frame input
Expand Down Expand Up @@ -315,7 +328,6 @@ test_that("import_vdj bad sep", {
})

# Check BCR and TCR
# SHOULD ALSO CHECK WHEN TOO MANY VDJ DIRS ARE PROVIDED
test_that("import_vdj BCR and TCR", {
fn <- function() {
res <- so |>
Expand All @@ -328,6 +340,19 @@ test_that("import_vdj BCR and TCR", {
expect_error(fn(), "Multiple data types detected")
})

# # SHOULD ALSO CHECK WHEN TOO MANY VDJ DIRS ARE PROVIDED
# test_that("import_vdj too may vdj_dirs provided", {
# fn <- function() {
# res <- so |>
# import_vdj(
# vdj_dir = c(tcr_ctigs[1], ctigs[1], ctigs[2]),
# include_mutations = FALSE
# )
# }
#
# expect_error(fn(), "Multiple data types detected")
# })

# Check .classify_vdj
test_that(".classify_vdj", {
dat <- vdj_sce |>
Expand Down

0 comments on commit 97d9c2d

Please sign in to comment.