Skip to content

Commit

Permalink
Merge pull request #209 from drieslab/dev
Browse files Browse the repository at this point in the history
chore: catch up to dev
  • Loading branch information
jiajic authored Jul 15, 2024
2 parents 9ad5829 + 1acad0c commit 3458c24
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion R/NN_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ createNearestNetwork <- function(
expression_values
))
)
expr_obj <- get_expression_values(
expr_obj <- getExpression(
gobject = gobject,
feat_type = feat_type,
spat_unit = spat_unit,
Expand Down
2 changes: 1 addition & 1 deletion R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ aggregateStacksExpression <- function(gobject,
# aggregate matrices
matrix_list <- list()
for (spat_unit in spat_units) {
mat <- get_expression_values(gobject,
mat <- getExpression(gobject,
spat_unit = spat_unit,
feat_type = feat_type,
values = values,
Expand Down
8 changes: 4 additions & 4 deletions R/auxilliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ create_average_DT <- function(gobject,
expression_values,
unique(c("normalized", "scaled", "custom", expression_values))
)
expr_data <- get_expression_values(
expr_data <- getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down Expand Up @@ -863,7 +863,7 @@ create_average_detection_DT <- function(gobject,
expression_values,
unique(c("normalized", "scaled", "custom", expression_values))
)
expr_data <- get_expression_values(
expr_data <- getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down Expand Up @@ -1081,7 +1081,7 @@ calculateMetaTable <- function(gobject,
expression_values
))
)
expr_values <- get_expression_values(
expr_values <- getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down Expand Up @@ -1396,7 +1396,7 @@ createMetafeats <- function(gobject,
expression_values
))
)
exprobj <- get_expression_values(
exprobj <- getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down
12 changes: 6 additions & 6 deletions R/interoperability.R
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ giottoToAnnData <- function(

for (en in expr_names) {
if (en == "raw") {
raw_x <- get_expression_values(
raw_x <- getExpression(
gobject = gobject,
values = en,
spat_unit = su,
Expand All @@ -703,7 +703,7 @@ giottoToAnnData <- function(
} else {
ad_layer_name <- paste0(su, "_", ft, "_", en)

x <- get_expression_values(
x <- getExpression(
gobject = gobject,
values = en,
spat_unit = su,
Expand Down Expand Up @@ -1222,7 +1222,7 @@ giottoToSeuratV4 <- function(
expr_use <- lapply(
avail_expr[feat_type == assay_use, name],
function(x) {
get_expression_values(
getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = assay_use,
Expand Down Expand Up @@ -1503,7 +1503,7 @@ giottoToSeuratV5 <- function(
expr_use <- lapply(
avail_expr[feat_type == assay_use, name],
function(x) {
get_expression_values(
getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = assay_use,
Expand Down Expand Up @@ -2613,7 +2613,7 @@ giottoToSpatialExperiment <- function(giottoObj, verbose = TRUE) {
"' for spatial unit: '", spatialUnits[su], "'"
)
}
exprMat <- get_expression_values(
exprMat <- getExpression(
gobject = giottoObj,
spat_unit = spatialUnits[su],
feat_type = giottoExpr[1]$feat_type,
Expand Down Expand Up @@ -2657,7 +2657,7 @@ giottoToSpatialExperiment <- function(giottoObj, verbose = TRUE) {
spatialUnits[su]
),
withDimnames = FALSE
) <- get_expression_values(
) <- getExpression(
gobject = giottoObj,
spat_unit = spatialUnits[su],
feat_type = giottoExpr[i]$feat_type,
Expand Down
2 changes: 1 addition & 1 deletion R/join.R
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ joinGiottoObjects <- function(gobject_list,
} else {
for (exprObj_i in seq(nrow(avail_expr))) {
expr_list <- lapply(updated_object_list, function(gobj) {
get_expression_values(
getExpression(
gobject = gobj,
spat_unit = avail_expr$spat_unit[[exprObj_i]],
feat_type = avail_expr$feat_type[[exprObj_i]],
Expand Down
2 changes: 1 addition & 1 deletion R/methods-initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ setMethod("initialize", signature("giotto"), function(.Object, ...) {
if (!is.null(avail_expr)) {
if (nrow(avail_expr[spat_unit == spatial_unit &
feat_type == feature_type]) != 0L) {
provenance <- prov(get_expression_values(
provenance <- prov(getExpression(
gobject = .Object,
spat_unit = spatial_unit,
feat_type = feature_type,
Expand Down
4 changes: 2 additions & 2 deletions R/slot_accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ set_cell_id <- function(gobject,
# get cell ID values
if (spat_unit %in% expr_avail$spat_unit) { # preferred from expression

cell_IDs <- spatIDs(get_expression_values(
cell_IDs <- spatIDs(getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = expr_avail$feat_type[[1L]],
Expand Down Expand Up @@ -424,7 +424,7 @@ set_feat_id <- function(gobject,

if (feat_type %in% expr_avail$feat_type) { # preferred from expression

feat_IDs <- featIDs(get_expression_values(
feat_IDs <- featIDs(getExpression(
gobject = gobject,
spat_unit = expr_avail$spat_unit[[1L]],
feat_type = feat_type,
Expand Down
2 changes: 1 addition & 1 deletion R/slot_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
}

if (!nrow(avail_ex[spat_unit == su_i & feat_type == ft_i]) == 0L) {
IDs <- featIDs(get_expression_values(
IDs <- featIDs(getExpression(
gobject = gobject,
spat_unit = su_i,
feat_type = ft_i,
Expand Down
2 changes: 1 addition & 1 deletion R/slot_show.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ showGiottoExpression <- function(gobject, nrows = 4, ncols = 4) {
objPrints <- list()
for (obj_i in seq(nrow(available_data))) {
# get object
dataObj <- get_expression_values(
dataObj <- getExpression(
gobject = gobject,
values = available_data$name[[obj_i]],
spat_unit = available_data$spat_unit[[obj_i]],
Expand Down
28 changes: 21 additions & 7 deletions tests/testthat/test-auxiliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ m <- matrix(
e <- exprObj(
exprMat = m,
spat_unit = "cell",
provenance = "cell",
feat_type = "test_feat",
name = "test"
)
Expand All @@ -36,13 +37,15 @@ df_clus_weight <- data.frame(
)

test_that("createMetafeat can calculate mean values", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_m <- matrix(rep(c(2, 5, 8), 3), nrow = 3)

g <- createMetafeats(
g, stat = "mean",
expression_values = "test",
feat_clusters = num_vec_clus,
name = "chara_vec_mean"
name = "chara_vec_mean",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "chara_vec_mean",
output = "data.table")
Expand All @@ -55,7 +58,8 @@ test_that("createMetafeat can calculate mean values", {
g, stat = "mean",
expression_values = "test",
feat_clusters = df_clus,
name = "df_mean"
name = "df_mean",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "df_mean", output = "data.table")

Expand All @@ -65,13 +69,15 @@ test_that("createMetafeat can calculate mean values", {
})

test_that("createMetafeat can calculate sum values", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_m <- matrix(c(6, 15, 24, 4, 10, 16, 2, 5, 8), nrow = 3)

g <- createMetafeats(
g, stat = "sum",
expression_values = "test",
feat_clusters = num_vec_clus,
name = "sum"
name = "sum",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "sum", output = "data.table")

Expand All @@ -81,13 +87,15 @@ test_that("createMetafeat can calculate sum values", {
})

test_that("createMetafeat can calculate min values", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_m <- matrix(c(1L, 4L, 7L, 1L, 4L, 7L, 2L, 5L, 8L), nrow = 3)

g <- createMetafeats(
g, stat = "min",
expression_values = "test",
feat_clusters = num_vec_clus,
name = "min"
name = "min",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "min", output = "data.table")

Expand All @@ -97,13 +105,15 @@ test_that("createMetafeat can calculate min values", {
})

test_that("createMetafeat can calculate max values", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_m <- matrix(c(3L, 6L, 9L, 3L, 6L, 9L, 2L, 5L, 8L), nrow = 3)

g <- createMetafeats(
g, stat = "max",
expression_values = "test",
feat_clusters = num_vec_clus,
name = "max"
name = "max",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "max", output = "data.table")

Expand All @@ -113,13 +123,15 @@ test_that("createMetafeat can calculate max values", {
})

test_that("createMetafeat can use weights", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_m <- matrix(c(4, 10, 16, 0.4, 1.3, 2.2, 2, 5, 8), nrow = 3)

g <- createMetafeats(
g, stat = "mean",
expression_values = "test",
feat_clusters = df_clus_weight,
name = "weighted_means"
name = "weighted_means",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "weighted_means",
output = "data.table")
Expand All @@ -130,14 +142,16 @@ test_that("createMetafeat can use weights", {
})

test_that("createMetafeat can use rescale", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_m <- matrix(rep(c(0, 0.5, 1), 3), nrow = 3)

g <- createMetafeats(
g, stat = "mean",
expression_values = "test",
feat_clusters = num_vec_clus,
rescale_to = c(0, 1),
name = "scaled_means"
name = "scaled_means",
verbose = FALSE
)
enr <- getSpatialEnrichment(g, name = "scaled_means",
output = "data.table")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-save_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ g <- GiottoData::loadGiottoMini("viz")
test <- tempdir()

test_that("gobject can be saved and loaded - qs", {
rlang::local_options(lifecycle_verbosity = "quiet")
saveGiotto(g, dir = test, method = "qs", overwrite = TRUE, verbose = FALSE)
g2 <<- loadGiotto(file.path(test, "saveGiottoDir"))

expect_true(methods::validObject(g2))
})

test_that("gobject an be ovewritten and loaded - qs", {
rlang::local_options(lifecycle_verbosity = "quiet")
saveGiotto(g2, dir = test, method = "qs", overwrite = TRUE, verbose = FALSE)
g3 <- loadGiotto(file.path(test, "saveGiottoDir"))

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-slot_accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ test_that("Not found exprObj returns error", {
expect_error(
getExpression(giotto_object,
spat_unit = "none",
feat_type = "none", values = "raw"
feat_type = "none",
values = "raw"
)
)
})
Expand All @@ -31,8 +32,7 @@ test_that("Not found CellMetadata returns error", {
getCellMetadata(
giotto_object,
spat_unit = "none",
feat_type = "none",
values = "raw"
feat_type = "none"
)
)
})
Expand Down

0 comments on commit 3458c24

Please sign in to comment.