Skip to content

Commit

Permalink
chore: update deprecated accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Sep 12, 2024
1 parent 3b738f7 commit efdf9c0
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 215 deletions.
4 changes: 2 additions & 2 deletions R/ONTraC_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ plotNicheClusterConnectivity <- function( # nolint: object_name_linter.
)
gpl <- gpl + ggraph::scale_edge_alpha(range = c(0.1, 1))
gpl <- gpl + ggraph::scale_edge_colour_gradientn(
colours = RColorBrewer::brewer.pal(9, "Reds"),
colours = getColors("Reds", 9, src = "RColorBrewer"),
name = "Value"
)

Expand Down Expand Up @@ -764,4 +764,4 @@ plotCellTypeNTScore <- function(gobject, # nolint: object_name_linter.
save_param = save_param,
else_return = NULL
))
}
}
38 changes: 9 additions & 29 deletions R/auxiliary_giotto.R
Original file line number Diff line number Diff line change
Expand Up @@ -933,19 +933,12 @@ filterGiotto <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_expression_values(
gobject = gobject,
values = norm_expr
)

gobject <- set_expression_values(
gobject = gobject,
values = norm_scaled_expr
)
gobject <- setGiotto(gobject, norm_expr, initialize = FALSE)
gobject <- setGiotto(gobject, norm_scaled_expr, initialize = FALSE)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

## 6. return Giotto object
return(gobject)
return(initialize(gobject))
}


Expand Down Expand Up @@ -991,13 +984,9 @@ filterGiotto <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_expression_values(
gobject = gobject,
values = norm_feats_cells
)
gobject <- setGiotto(giotto, norm_feats_cells)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###


return(gobject)
}

Expand Down Expand Up @@ -1088,10 +1077,7 @@ filterGiotto <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_expression_values(
gobject = gobject,
values = z
)
gobject <- setGiotto(gobject, z)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

return(gobject)
Expand Down Expand Up @@ -1391,10 +1377,7 @@ adjustGiottoMatrix <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_expression_values(
gobject = gobject,
values = adjusted_matrix
)
gobject <- setGiotto(gobject, adjusted_matrix)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

## update parameters used ##
Expand Down Expand Up @@ -1456,14 +1439,14 @@ processGiotto <- function(
adjust_params = list(),
verbose = TRUE) {
# filter Giotto
if (verbose == TRUE) message("1. start filter step")
vmsg(.v = verbose, "1. start filter step")
if (!inherits(filter_params, "list")) {
stop("filter_params need to be a list of parameters for filterGiotto")
}
gobject <- do.call("filterGiotto", c(gobject = gobject, filter_params))

# normalize Giotto
if (verbose == TRUE) message("2. start normalization step")
vmsg(.v = verbose, "2. start normalization step")
if (!inherits(norm_params, "list")) {
stop("norm_params need to be a list of parameters for normalizeGiotto")
}
Expand Down Expand Up @@ -1623,10 +1606,7 @@ addFeatStatistics <- function(
"mean_expr_det"
) := NULL]
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_feature_metadata(gobject,
metadata = feat_metadata,
verbose = FALSE
)
gobject <- setGiotto(gobject, feat_metadata, verbose = FALSE)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
}

Expand Down
2 changes: 1 addition & 1 deletion R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ doKmeans <- function(
if(!is.null(dim_reduction_to_use)) {

# use only available dimensions if dimensions < dimensions_to_use
dim_coord <- get_dimReduction(
dim_coord <- getDimReduction(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down
7 changes: 3 additions & 4 deletions R/convenience_cosmx.R
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ createGiottoCosMxObject <- function(
provenance = "cell_agg"
)

cosmx_gobject <- set_expression_values(cosmx_gobject, values = s4_expr)
cosmx_gobject <- setGiotto(cosmx_gobject, s4_expr)

# Add spatial locations
if (isTRUE(verbose)) wrap_msg(
Expand All @@ -1669,9 +1669,8 @@ createGiottoCosMxObject <- function(
provenance = "cell_agg"
)

cosmx_gobject <- set_spatial_locations(cosmx_gobject, spatlocs = locsObj)
cosmx_gobject <- set_spatial_locations(cosmx_gobject,
spatlocs = locsObj_fov)
cosmx_gobject <- setGiotto(cosmx_gobject, locsObj, initialize = FALSE)
cosmx_gobject <- setGiotto(cosmx_gobject, locsObj_fov, initialize = FALSE)

# initialize cell and feat IDs and metadata slots for 'cell_agg' spat_unit
agg_cell_ID <- colnames(s4_expr[])
Expand Down
37 changes: 13 additions & 24 deletions R/dimension_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,7 @@ runPCA <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(
gobject = gobject, dimObject = dimObject, verbose = verbose
)
gobject <- setGiotto(gobject, dimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###


Expand Down Expand Up @@ -945,7 +943,7 @@ runPCAprojection <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(gobject = gobject, dimObject = dimObject)
gobject <- setGiotto(gobject, dimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###


Expand Down Expand Up @@ -1349,7 +1347,7 @@ runPCAprojectionBatch <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(gobject = gobject, dimObject = dimObject)
gobject <- setGiotto(gobject, dimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###


Expand Down Expand Up @@ -2168,7 +2166,7 @@ runUMAP <- function(
## using dimension reduction ##
if (!is.null(dim_reduction_to_use)) {
## TODO: check if reduction exists
dimObj_to_use <- get_dimReduction(
dimObj_to_use <- getDimReduction(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down Expand Up @@ -2291,10 +2289,7 @@ runUMAP <- function(


### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(
gobject = gobject,
dimObject = dimObject
)
gobject <- setGiotto(gobject, dimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###


Expand Down Expand Up @@ -2566,7 +2561,7 @@ runUMAPprojection <- function(


### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(gobject = gobject, dimObject = dimObject)
gobject <- setGiotto(gobject, dimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

## update parameters used ##
Expand Down Expand Up @@ -2794,10 +2789,7 @@ runtSNE <- function(
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(
gobject = gobject,
dimObject = dimObject
)
gobject <- setGiotto(gobject, dimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

## update parameters used ##
Expand Down Expand Up @@ -2931,7 +2923,7 @@ runGiottoHarmony <- function(
## using dimension reduction ##
if (!is.null(dim_reduction_to_use)) {
## TODO: check if reduction exists
matrix_to_use <- get_dimReduction(
matrix_to_use <- getDimReduction(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
Expand Down Expand Up @@ -3000,14 +2992,14 @@ runGiottoHarmony <- function(
colnames(harmony_results) <- paste0("Dim.", seq_len(ncol(harmony_results)))
rownames(harmony_results) <- rownames(matrix_to_use)

harmdimObject <- create_dim_obj(
harmdimObject <- createDimObj(
coordinates = harmony_results,
name = name,
spat_unit = spat_unit,
feat_type = feat_type,
provenance = provenance,
method = "harmony",
reduction = "cells", # set to spat_unit?
reduction_method = "harmony",
coordinates = harmony_results,
provenance = provenance,
misc = NULL
)

Expand All @@ -3029,10 +3021,7 @@ runGiottoHarmony <- function(
}

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- set_dimReduction(
gobject = gobject,
dimObject = harmdimObject
)
gobject <- setGiotto(gobject, harmdimObject, verbose = verbose)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###


Expand Down
11 changes: 7 additions & 4 deletions R/giotto_viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ exportGiottoViewer <- function(

# data.table variables
sdimx <- sdimy <- NULL
spatial_location <- get_spatial_locations(
spatial_location <- getSpatialLocations(
gobject = gobject,
spat_loc_name = spat_loc_name
spat_unit = spat_unit,
name = spat_loc_name
)
spatial_location <- spatial_location[, .(sdimx, sdimy)]
write.table(spatial_location,
Expand All @@ -241,6 +242,7 @@ exportGiottoViewer <- function(
cell_metadata <- combineMetadata(
gobject = gobject,
feat_type = feat,
spat_unit = spat_unit,
spat_enr_names = spat_enr_names
)

Expand Down Expand Up @@ -361,11 +363,12 @@ exportGiottoViewer <- function(
values <- match.arg(expression_values, unique(c("scaled", "normalized", "custom", expression_values)))

for (feat in feat_type) {
expr_values <- get_expression_values(
expr_values <- getExpression(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat,
values = values
values = values,
output = "matrix"
)
expr_values <- as.matrix(expr_values)

Expand Down
Loading

0 comments on commit efdf9c0

Please sign in to comment.