Skip to content

Commit b9faf8b

Browse files
Test(cleaning): cleaning the unit tests - getting the custom checker function to work for weird case where there are errors and warnings to be expected + added a renv.lock file
1 parent f08d814 commit b9faf8b

18 files changed

Lines changed: 4826 additions & 207 deletions

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
^renv$
2+
^renv\.lock$
13
^\.github$
24
^src/\.cargo$
35
^_pkgdown\.yml$

.Rprofile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source("renv/activate.R")

R/cost.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#' compute fast pearson correlation between matrices
2-
#'
2+
#' @param seed matrix/sparse matrix of seed cells
3+
#' @param query matrix/sparse matrix of query cells
4+
#' @return correlation matrix between all cells in seed and query
35
pearson_approx <- function(seed, query) {
4-
n <- nrow(seed)
6+
n <- nrow(seed)
57
sums <- outer(colSums(query), colSums(seed))
68
stds <- outer(apply(query, 2, sd), apply(seed, 2, sd))
79
correlation <- (t(query) %*% seed - sums / n) / stds / n
@@ -10,7 +12,9 @@ pearson_approx <- function(seed, query) {
1012

1113

1214

13-
15+
#' convert niche composition into matrix format for jaccard compute
16+
#' @param niches list of niches with the cell composition of each niche
17+
#' @return matrix with columns as cells and rows as cell types
1418
make_composition_matrix <- function(niches){
1519
max_elements <- max(lengths(niches))
1620
barcodes <- names(niches)

R/dispatch.R

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
#' @param ter_2 integer vector containing territories in group 2
1212
#' @param cells cell barcodes
1313
dispatch_territory <- function(territories, ter_1, ter_2, cells) {
14-
if (is.null(ter_1) && is.null(ter_2)) {
15-
territories <- select(territories, c("barcodes", "x", "y", "trial"))
16-
}else if (!is.null(ter_1) && is.null(ter_2)) {
17-
territories$trial[!territories$trial %in% ter_1] <- "other"
18-
}else if (is.null(ter_1) && !is.null(ter_2)) {
19-
territories$trial[!territories$trial %in% ter_2] <- "other"
20-
}else {
21-
territories$trial[!territories$trial %in% c(ter_1, ter_2)] <- "other"
22-
}
23-
if (!is.null(cells)) {
24-
territories$trial[territories$trial %in% ter_1 &
25-
territories$barcodes %in% cells] <- paste0(ter_1, collapse = " ")
26-
territories$trial[territories$trial %in% ter_2 &
27-
territories$barcodes %in% cells] <- paste0(ter_2, collapse = " ")
28-
}
29-
return(territories)
14+
if (is.null(ter_1) && is.null(ter_2)) {
15+
territories <- select(territories, c("barcodes", "x", "y", "trial"))
16+
}else if (!is.null(ter_1) && is.null(ter_2)) {
17+
territories$trial[!territories$trial %in% ter_1] <- "other"
18+
}else if (is.null(ter_1) && !is.null(ter_2)) {
19+
territories$trial[!territories$trial %in% ter_2] <- "other"
20+
}else {
21+
territories$trial[!territories$trial %in% c(ter_1, ter_2)] <- "other"
22+
}
23+
if (!is.null(cells)) {
24+
territories$trial[territories$trial %in% ter_1 &
25+
territories$barcodes %in% cells] <- paste0(ter_1, collapse = " ")
26+
territories$trial[territories$trial %in% ter_2 &
27+
territories$barcodes %in% cells] <- paste0(ter_2, collapse = " ")
28+
}
29+
return(territories)
3030
}
3131

3232

@@ -199,7 +199,9 @@ dispatch_cost_groups <- function(vesalius_assay,
199199

200200
}
201201

202-
202+
#' clean trial annotation
203+
#' @param trial vector of strings with trial tag
204+
#' @return vector of strings with sanitize numeric value
203205
clean_trial <- function(trial) {
204206
trial <- sapply(strsplit(trial, "-"), function(str){
205207
return(paste0(str[seq(1, length(str) - 1)], collapse = "-"))

R/interoperability.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
#--------------------------------/ From Vesalius /----------------------------#
66

77

8-
as.Seurat.vesalius_assay <- function(obj, assay = NULL) {
9-
8+
as.Seurat.vesalius_assay <- function(obj) {
9+
coord <- get_coordinates(obj)
10+
counts <- get_counts(obj, type = "all")
11+
raw <- counts[names(counts) == "raw"]
12+
counts <- counts[names(counts) != "raw"]
13+
embeddings <- get_embeddings(obj, active = FALSE)
14+
img <- obj@img
1015
}
1116

1217

man/clean_trial.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/make_composition_matrix.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pearson_approx.Rd

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)