Skip to content

Commit

Permalink
Adding to the testing menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ncborcherding committed Dec 12, 2023
1 parent 6f4d1c4 commit 30529b7
Show file tree
Hide file tree
Showing 22 changed files with 8,141 additions and 3,886 deletions.
12 changes: 8 additions & 4 deletions R/clonalScatter.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#'
#' @export
#' @concept Visualizing_Clones
#' @return ggplot of the relative clonotype numbers between two sequencing runs
#' @return ggplot of the relative clone numbers between two sequencing runs or groups

clonalScatter <- function(input.data,
cloneCall ="strict",
Expand Down Expand Up @@ -109,8 +109,12 @@ clonalScatter <- function(input.data,
y <- mat[,y.axis] }
if (dot.size != "total") {
size <- mat[,dot.size]
} else { size <- mat[,"sum"] }
if (exportTable == TRUE) { return(mat) }
} else {
mat[,"size"] <- mat[,"sum"]
}
if (exportTable == TRUE) {
return(mat)
}

plot <- ggplot(mat, aes(x=x, y = y, fill = class)) +
theme_classic() +
Expand All @@ -129,7 +133,7 @@ clonalScatter <- function(input.data,
xlim(0, max(x,y))
}
plot <- plot +
geom_jitter(aes(size = size,), shape = 21, color = "black", stroke = 0.25)
geom_point(aes(size = size), shape = 21, color = "black", stroke = 0.25)

return(plot)
}
10 changes: 8 additions & 2 deletions R/loadContigs.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,15 @@ loadContigs <- function(input,

.parseOmniscope <- function(df) {
for (i in seq_along(df)) {
df[[i]] <- df[[i]][,c("contig_id", "locus", "umi_count", "v_call", "d_call", "j_call", "c_call", "cdr3", "cdr3_aa")]
colnames(df[[i]]) <- c("barcode", "chain", "reads", "v_gene", "d_gene", "j_gene", "c_gene", "cdr3_nt", "cdr3")
if("c_call" %in% colnames(df[[i]])) {
df[[i]] <- df[[i]][,c("contig_id", "locus", "umi_count", "v_call", "d_call", "j_call", "c_call", "cdr3", "cdr3_aa")]
colnames(df[[i]]) <- c("barcode", "chain", "reads", "v_gene", "d_gene", "j_gene", "c_gene", "cdr3_nt", "cdr3")
} else { #TCR contigs do not include C gene
df[[i]] <- df[[i]][,c("contig_id", "locus", "umi_count", "v_call", "d_call", "j_call", "cdr3", "cdr3_aa")]
colnames(df[[i]]) <- c("barcode", "chain", "reads", "v_gene", "d_gene", "j_gene", "cdr3_nt", "cdr3")
df[[i]][,"c_gene"] <- NA
df[[i]] <- df[[i]][with(df[[i]], order(reads, chain)),]
}
}
return(df)
}
Expand Down
5 changes: 2 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ is_seurat_or_se_object <- function(obj) {
colData(sc)[["evalNA"]]<-evalNA
return(sc[, !is.na(sc$cloneSize)])
}else{
col.name <- names(evalNA) %||% colnames(evalNA)
sc[[col.name]] <- evalNA
sc <- subset(sc, cloneSize != 0)
pos <- which(evalNA[,"indicator"] != 0)
sc <- subset(sc, cells = rownames(evalNA)[pos])
return(sc)
}
}
Expand Down
2 changes: 1 addition & 1 deletion man/clonalScatter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

825 changes: 825 additions & 0 deletions tests/testthat/_snaps/alluvialClones/alluvialclones-alpha-plot.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.
797 changes: 797 additions & 0 deletions tests/testthat/_snaps/alluvialClones/alluvialclones-trb-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
179 changes: 179 additions & 0 deletions tests/testthat/_snaps/clonalLength/clonallength-tra-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions tests/testthat/_snaps/clonalLength/clonallength-trb-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,914 changes: 2,457 additions & 2,457 deletions tests/testthat/_snaps/clonalScatter/clonalscatter-proportion-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,176 changes: 2,758 additions & 1,418 deletions tests/testthat/_snaps/clonalScatter/clonalscatter-raw-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions tests/testthat/test-alluvialClones.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ test_that("alluvialClones works", {
color = "Type")
)

expect_doppelganger(
"alluvialClones_TRB_plot",
alluvialClones(test_obj,
cloneCall = "aa",
chain = "TRB",
y.axes = c("Patient", "ident"),
color = "Type")
)

expect_doppelganger(
"alluvialClones_nocolor_plot",
alluvialClones(test_obj,
Expand All @@ -23,6 +32,24 @@ test_that("alluvialClones works", {
color = NULL)
)

expect_doppelganger(
"alluvialClones_alpha_plot",
alluvialClones(test_obj,
cloneCall = "aa",
y.axes = c("Type", "ident"),
alpha = "Patient")
)

expect_doppelganger(
"alluvialClones_alphapluscolor_plot",
alluvialClones(test_obj,
cloneCall = "aa",
y.axes = c("Type", "ident"),
alpha = "Patient",
color = "Type")
)


expect_doppelganger(
"alluvialClones_facet_plot",
alluvialClones(test_obj,
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-clonalCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ test_that("clonalCluster works", {
getdata("clustering", "clonalCluster_TRBaa_data")
)

set.seed(42)
expect_equal(
clonalCluster(combined[1:2],
chain = "TRB",
sequence = "aa"),
getdata("clustering", "clonalCluster_2sample_data")
)

set.seed(42)
test_obj <- clonalCluster(test_obj,
Expand All @@ -26,5 +33,17 @@ test_that("clonalCluster works", {
test_obj@meta.data[, 7:16],
getdata("clustering", "clonalCluster_TRBaa_metadata")
)


BCR <- read.csv("https://www.borch.dev/uploads/contigs/b_contigs.csv")
combined.BCR <- combineBCR(BCR,
samples = "S1")
expect_equal(
clonalCluster(combined.BCR,
chain = "IGH",
sequence = "aa"),
getdata("clustering", "clonalCluster_IGHaa_data")
)

})
#TODO Add exportgraph test
12 changes: 12 additions & 0 deletions tests/testthat/test-clonalLength.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ test_that("clonalLength works", {
scale = TRUE)
)

expect_doppelganger(
"clonalLength_TRB_plot",
clonalLength(getCombined(),
chain = "TRB")
)

expect_doppelganger(
"clonalLength_TRA_plot",
clonalLength(getCombined(),
chain = "TRA")
)

combined <- addVariable(getCombined(),
variable.name = "Type",
variables = rep(c("B", "L"), 4))
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-loadContigs.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ test_that("loadContigs works", {
getdata("load", "loadContigs_Immcantation")
)

OS <- read.csv("https://www.borch.dev/uploads/contigs/OS_contigs.csv")
trial7 <- loadContigs(OS, format = "Omniscope")
expect_identical(trial7,
getdata("load", "loadContigs_Omniscope")
)
})

# TODO Add tests for .json and AIRR and OS
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-percentKmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ test_that("percentKmer works for NTs", {
)
})

test_that("tokenize_sequence works", {
expect_equal(.tokenize_sequence("CAYRSAQAGGTSYGKLTF", 3),
c("CAY", "AYR", "YRS", "RSA", "SAQ","AQA", "QAG",
"AGG", "GGT", "GTS", "TSY", "SYG", "YGK", "GKL", "KLT", "LTF")
)
})

test_that("tokenize_multiple_sequences works", {
expect_equal(.tokenize_multiple_sequences(c("TESTING", "MULTIPLE", "SEQUENCE", "TOKENIZER"), 4),
list(TESTING = c("TEST", "ESTI", "STIN", "TING"),
MULTIPLE = c("MULT", "ULTI", "LTIP", "TIPL", "IPLE"),
SEQUENCE = c("SEQU", "EQUE", "QUEN", "UENC", "ENCE"),
TOKENIZER = c("TOKE", "OKEN", "KENI", "ENIZ", "NIZE", "IZER"))
)

})

# TODO test for cases where no kmers were counted (NA columns present)
16 changes: 15 additions & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ test_that("'%!in%' works", {
})

# TODO off.the.chain
# TODO groupList
# TODO checkSingleObject
# TODO .parseBCR
# TODO lengthDF

test_that(".removingMulti works", {
combined <- getCombined()
expect_equal(.removingMulti(combined[1:2]),
getdata("utils", "removingMulti_data"))

})

test_that(".filteringNA works", {
data("scRep_example")
test_obj <- combineExpression(getCombined(), scRep_example)
test_obj <- .filteringNA(test_obj)
expect_equal(test_obj@meta.data[, 7:13],
getdata("utils", "filteringNA_metadata"))

})


test_that(".list.input.return works", {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 30529b7

Please sign in to comment.