From efdf9c0163dd8e1a270e4a7da8319929e945610a Mon Sep 17 00:00:00 2001 From: George Chen <72078254+jiajic@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:30:19 -0400 Subject: [PATCH] chore: update deprecated accessors --- R/ONTraC_wrapper.R | 4 +- R/auxiliary_giotto.R | 38 ++------ R/clustering.R | 2 +- R/convenience_cosmx.R | 7 +- R/dimension_reduction.R | 37 +++----- R/giotto_viewer.R | 11 ++- R/image_registration.R | 162 +++++++++++++++++------------------ R/interactivity.R | 4 +- R/python_hmrf.R | 4 +- R/spatial_enrichment.R | 29 ++----- R/spatial_interaction_spot.R | 7 +- R/wnn.R | 21 ++--- man/enrichment_PAGE.Rd | 2 +- man/screePlot.Rd | 7 +- man/spatCellCellcomSpots.Rd | 58 +++++++------ 15 files changed, 178 insertions(+), 215 deletions(-) diff --git a/R/ONTraC_wrapper.R b/R/ONTraC_wrapper.R index e33abeac7..bf11d6075 100644 --- a/R/ONTraC_wrapper.R +++ b/R/ONTraC_wrapper.R @@ -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" ) @@ -764,4 +764,4 @@ plotCellTypeNTScore <- function(gobject, # nolint: object_name_linter. save_param = save_param, else_return = NULL )) -} \ No newline at end of file +} diff --git a/R/auxiliary_giotto.R b/R/auxiliary_giotto.R index 3276c90f5..8fbb26857 100644 --- a/R/auxiliary_giotto.R +++ b/R/auxiliary_giotto.R @@ -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)) } @@ -991,13 +984,9 @@ filterGiotto <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_expression_values( - gobject = gobject, - values = norm_feats_cells - ) + gobject <- setGiotto(giotto, norm_feats_cells) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - return(gobject) } @@ -1088,10 +1077,7 @@ filterGiotto <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_expression_values( - gobject = gobject, - values = z - ) + gobject <- setGiotto(gobject, z) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### return(gobject) @@ -1391,10 +1377,7 @@ adjustGiottoMatrix <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_expression_values( - gobject = gobject, - values = adjusted_matrix - ) + gobject <- setGiotto(gobject, adjusted_matrix) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## update parameters used ## @@ -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") } @@ -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) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### } diff --git a/R/clustering.R b/R/clustering.R index bd1b0ff66..c0f767dbf 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -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, diff --git a/R/convenience_cosmx.R b/R/convenience_cosmx.R index f22ed482d..c3a503a6a 100644 --- a/R/convenience_cosmx.R +++ b/R/convenience_cosmx.R @@ -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( @@ -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[]) diff --git a/R/dimension_reduction.R b/R/dimension_reduction.R index 8825258c4..de7906d1c 100644 --- a/R/dimension_reduction.R +++ b/R/dimension_reduction.R @@ -541,9 +541,7 @@ runPCA <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction( - gobject = gobject, dimObject = dimObject, verbose = verbose - ) + gobject <- setGiotto(gobject, dimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -945,7 +943,7 @@ runPCAprojection <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction(gobject = gobject, dimObject = dimObject) + gobject <- setGiotto(gobject, dimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -1349,7 +1347,7 @@ runPCAprojectionBatch <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction(gobject = gobject, dimObject = dimObject) + gobject <- setGiotto(gobject, dimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -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, @@ -2291,10 +2289,7 @@ runUMAP <- function( ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction( - gobject = gobject, - dimObject = dimObject - ) + gobject <- setGiotto(gobject, dimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -2566,7 +2561,7 @@ runUMAPprojection <- function( ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction(gobject = gobject, dimObject = dimObject) + gobject <- setGiotto(gobject, dimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## update parameters used ## @@ -2794,10 +2789,7 @@ runtSNE <- function( ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction( - gobject = gobject, - dimObject = dimObject - ) + gobject <- setGiotto(gobject, dimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## update parameters used ## @@ -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, @@ -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 ) @@ -3029,10 +3021,7 @@ runGiottoHarmony <- function( } ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_dimReduction( - gobject = gobject, - dimObject = harmdimObject - ) + gobject <- setGiotto(gobject, harmdimObject, verbose = verbose) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### diff --git a/R/giotto_viewer.R b/R/giotto_viewer.R index c21f66f75..8b044855d 100644 --- a/R/giotto_viewer.R +++ b/R/giotto_viewer.R @@ -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, @@ -241,6 +242,7 @@ exportGiottoViewer <- function( cell_metadata <- combineMetadata( gobject = gobject, feat_type = feat, + spat_unit = spat_unit, spat_enr_names = spat_enr_names ) @@ -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) diff --git a/R/image_registration.R b/R/image_registration.R index a98e9a280..f163b30f2 100644 --- a/R/image_registration.R +++ b/R/image_registration.R @@ -163,7 +163,7 @@ img_type = img_type )))) { giottoImage_list <- lapply( - X = gobject_list, FUN = get_giottoImage, name = image_unreg, + X = gobject_list, FUN = getGiottoImage, name = image_unreg, image_type = img_type ) image_corners <- lapply(giottoImage_list, .get_img_corners) @@ -431,10 +431,10 @@ registerGiottoObjectListFiji <- function( spatloc_list <- list() for (gobj_i in seq_along(gobject_list)) { gobj <- gobject_list[[gobj_i]] - spatloc <- get_spatial_locations( + spatloc <- getSpatialLocations( gobject = gobj, spat_unit = spat_unit, - spat_loc_name = spatloc_unreg + name = spatloc_unreg ) #------ Put all spatial location data together spatloc_list[[gobj_i]] <- spatloc @@ -526,24 +526,24 @@ registerGiottoObjectListFiji <- function( # Rename original spatial locations to 'unregistered' if conflicting # with output if (spatloc_unreg == spatloc_reg_name) { - gobj <- set_spatial_locations( + gobj <- setSpatialLocations( gobject = gobj, spat_unit = spat_unit, - spat_loc_name = spatloc_replace_name, - spatlocs = get_spatial_locations( + name = spatloc_replace_name, + spatlocs = getSpatialLocations( gobject = gobj, spat_unit = spat_unit, - spat_loc_name = spatloc_unreg + name = spatloc_unreg ) ) } # Assign registered spatial locations from spatloc_list to gobject_list - gobj <- set_spatial_locations( + gobj <- setSpatialLocations( gobject = gobj, spat_unit = spat_unit, - spat_loc_name = spatloc_reg_name, + name = spatloc_reg_name, spatlocs = spatloc_list[[gobj_i]] ) @@ -637,9 +637,9 @@ registerGiottoObjectListRvision <- function( spatloc_list <- list() for (gobj_i in seq_along(gobject_list)) { gobj <- gobject_list[[gobj_i]] - spatloc <- get_spatial_locations( + spatloc <- getSpatialLocations( gobject = gobj, - spat_loc_name = spatloc_unreg, + name = spatloc_unreg, output = "spatLocsObj", copy_obj = TRUE ) @@ -744,22 +744,22 @@ registerGiottoObjectListRvision <- function( gobj <- gobject_list[[gobj_i]] # Rename original spatial locations to 'unregistered' - unreg_locs <- get_spatial_locations(gobj, - spat_loc_name = spatloc_unreg, + unreg_locs <- getSpatialLocations(gobj, + name = spatloc_unreg, copy_obj = FALSE, output = "spatLocsObj" ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobj <- set_spatial_locations(gobj, + gobj <- setSpatialLocations(gobj, spatlocs = unreg_locs, - spat_loc_name = "unregistered" + name = "unregistered" ) # Assign registered spatial locations from spatloc_list to gobject_list - gobj <- set_spatial_locations(gobj, + gobj <- setSpatialLocations(gobj, spatlocs = spatloc_list[[gobj_i]], - spat_loc_name = spatloc_reg_name + name = spatloc_reg_name ) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -1033,7 +1033,7 @@ interactiveLandmarkSelection <- function(source, target) { GiottoUtils::package_check("shiny") GiottoUtils::package_check("ggplot2") GiottoUtils::package_check("miniUI") - + .create_image_to_plot <- function(x){ if (inherits(x, "gg")){ return(x) @@ -1052,7 +1052,7 @@ interactiveLandmarkSelection <- function(source, target) { } source_image <- .create_image_to_plot(source) target_image <- .create_image_to_plot(target) - + # Function to extract the range of x and y values from a ggplot object .extract_plot_ranges <- function(plot) { data <- ggplot2::ggplot_build(plot)$data[[1]] @@ -1060,11 +1060,11 @@ interactiveLandmarkSelection <- function(source, target) { y_range <- range(data$y, na.rm = TRUE) list(x_range = x_range, y_range = y_range) } - + # Extract ranges for the input plots source_ranges <- .extract_plot_ranges(source_image) target_ranges <- .extract_plot_ranges(target_image) - + ui <- miniUI::miniPage( miniUI::gadgetTitleBar("Select Extents and Points"), miniUI::miniContentPanel( @@ -1073,11 +1073,11 @@ interactiveLandmarkSelection <- function(source, target) { shiny::column(6, shiny::plotOutput("plot2", click = "plot2_click")) ), shiny::fluidRow( - shiny::column(6, + shiny::column(6, shiny::sliderInput("xrange1", "X Range for Plot 1", min = source_ranges$x_range[1], max = source_ranges$x_range[2], value = source_ranges$x_range), shiny::sliderInput("yrange1", "Y Range for Plot 1", min = source_ranges$y_range[1], max = source_ranges$y_range[2], value = source_ranges$y_range) ), - shiny::column(6, + shiny::column(6, shiny::sliderInput("xrange2", "X Range for Plot 2", min = target_ranges$x_range[1], max = target_ranges$x_range[2], value = target_ranges$x_range), shiny::sliderInput("yrange2", "Y Range for Plot 2", min = target_ranges$y_range[1], max = target_ranges$y_range[2], value = target_ranges$y_range) ) @@ -1092,63 +1092,63 @@ interactiveLandmarkSelection <- function(source, target) { ) ) ) - + server <- function(input, output, session) { click_history1 <- shiny::reactiveVal(data.frame(x = numeric(), y = numeric())) click_history2 <- shiny::reactiveVal(data.frame(x = numeric(), y = numeric())) - + output$plot1 <- shiny::renderPlot({ source_image + ggplot2::coord_cartesian(xlim = input$xrange1, ylim = input$yrange1) + ggplot2::geom_point(data = click_history1(), ggplot2::aes(x = x, y = y), color = "red", size = 4.5) }) - + output$plot2 <- shiny::renderPlot({ target_image + ggplot2::coord_cartesian(xlim = input$xrange2, ylim = input$yrange2) + ggplot2::geom_point(data = click_history2(), ggplot2::aes(x = x, y = y), color = "blue",size = 4.5) }) - + shiny::observeEvent(input$plot1_click, { click <- input$plot1_click new_coords <- rbind(click_history1(), data.frame(x = click$x, y = click$y)) click_history1(new_coords) }) - + shiny::observeEvent(input$plot2_click, { click <- input$plot2_click new_coords <- rbind(click_history2(), data.frame(x = click$x, y = click$y)) click_history2(new_coords) }) - + shiny::observeEvent(input$undo1, { if (nrow(click_history1()) > 0) { new_coords <- click_history1()[-nrow(click_history1()), , drop = FALSE] click_history1(new_coords) } }) - + shiny::observeEvent(input$undo2, { if (nrow(click_history2()) > 0) { new_coords <- click_history2()[-nrow(click_history2()), , drop = FALSE] click_history2(new_coords) } }) - + output$click_info1 <- shiny::renderPrint({ click_history1() }) - + output$click_info2 <- shiny::renderPrint({ click_history2() }) - + shiny::observeEvent(input$done, { returnValue <- list(click_history1(),click_history2()) shiny::stopApp(returnValue) }) } - + shiny::runGadget(ui, server) } @@ -1184,32 +1184,32 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ #' @name .sift_detect -#' @title Run SIFT feature detector and descriptor extractor +#' @title Run SIFT feature detector and descriptor extractor #' @description #' Perform feature detector and descriptor extractor on a matrix object or preprocessed image object #' @param x input matrix or preprocessed image to extract feature and descriptor from #' @param ... additional params to pass to `skimage.feature.SIFT()` #' @returns list of keypoints and descriptors -#' +#' .sift_detect <- function(x, ..., pkg_ptr) { - + if (missing(pkg_ptr)) { GiottoUtils::package_check("skimage", repository = "pip:scikit-image") SKI <- reticulate::import("skimage", convert = TRUE, delay_load = TRUE) } else { SKI <- pkg_ptr } - + # sift object SIFT <- SKI$feature$SIFT() - + SIFT$detect_and_extract(x) - + out <- list( keypoints = SIFT$keypoints, descriptors = SIFT$descriptors ) - + return(out) } @@ -1230,7 +1230,7 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ #' Computer Vision, 2004. #' @param ... additional params to pass to `skimage.feature.match_descriptors()` #' @returns list -#' +#' .match_descriptor <- function( descriptor_list, target_idx = 1L, @@ -1239,19 +1239,19 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ ..., pkg_ptr ) { - + checkmate::assert_list(descriptor_list, min.len = 2L) target_idx <- as.integer(target_idx) - + if (missing(pkg_ptr)) { package_check("skimage", repository = "pip:scikit-image") SKI <- reticulate::import("skimage", convert = TRUE, delay_load = TRUE) } else { SKI <- pkg_ptr } - + target <- descriptor_list[[target_idx]] - + out <- lapply( seq_along(descriptor_list), function(moving_idx) { @@ -1263,9 +1263,9 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ )) # directly return all as matches } - + moving <- descriptor_list[[moving_idx]] - + m <- .match_descriptor_single( x = target, y = moving, @@ -1275,7 +1275,7 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ m + 1 # since it is 0 indexed } ) - + return(out) } @@ -1283,17 +1283,17 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ # wrapper for sklearn-image match_descriptors # returns a 2 col matrix of x to y index matches .match_descriptor_single <- function(x, y,max_ratio, ..., pkg_ptr) { - + checkmate::assert_class(x, "matrix") checkmate::assert_class(y, "matrix") - + if (missing(pkg_ptr)) { GiottoUtils::package_check("skimage", repository = "pip:scikit-image") SKI <- reticulate::import("skimage", convert = TRUE, delay_load = TRUE) } else { SKI <- pkg_ptr } - + match_descriptors <- SKI$feature$match_descriptors m <- match_descriptors( descriptors1 = x, @@ -1301,7 +1301,7 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ max_ratio = max_ratio, ... # max_ratio of 0.6 - 0.8 recommended for sift, cross_check = TRUE ) - + return(m) } @@ -1319,7 +1319,7 @@ calculateAffineMatrixFromLandmarks <- function(source_df,target_df){ #' @param use_single_channel If input is a multichannel image, whether or not to extract single channel, default FALSE #' @param single_channel_number Channel number in the multichannel image, required if use_single_channel = TRUE #' @returns a matrix array to input to .sift_detect -#' +#' #' @export preprocessImageToMatrix <- function(x, invert = F, @@ -1330,7 +1330,7 @@ preprocessImageToMatrix <- function(x, use_single_channel = F, single_channel_number = NULL, pkg_ptr) { - + if (missing(pkg_ptr)) { GiottoUtils::package_check("skimage", repository = "pip:scikit-image") SKI <- reticulate::import("skimage", convert = TRUE, delay_load = TRUE) @@ -1339,18 +1339,18 @@ preprocessImageToMatrix <- function(x, } GiottoUtils::package_check("numpy", repository = "pip:scikit-image") np <- reticulate::import("numpy", convert = TRUE, delay_load = TRUE) - + image = SKI$io$imread(x) - + if (length(dim(image)) >2 & use_single_channel == FALSE){ image = SKI$color$rgb2gray(image) - } + } if (use_single_channel == TRUE) { if (is.null(single_channel_number)) {stop("Set use single channel == TRUE, please provide a channel number to continue")} image <- image[,,single_channel_number] } - - + + if (flip_vertical == T){ image = np$flipud(image) } @@ -1390,20 +1390,20 @@ preprocessImageToMatrix <- function(x, } else { SKI <- pkg_ptr } - + # Extract matched keypoints src_pts <- keypoints1[match[, 1] + 1, , drop = FALSE] dst_pts <- keypoints2[match[, 2] + 1, , drop = FALSE] - + estimate_fun <- match.arg(estimate_fun, unique(c('euclidean', 'similarity', 'affine', 'piecewise-affine', 'projective', 'polynomial', estimate_fun))) - - # Estimate homography matrix + + # Estimate homography matrix ransac_result <- SKI$transform$estimate_transform( ttype = estimate_fun, src = src_pts, dst = dst_pts, ) - + return(ransac_result) } @@ -1427,10 +1427,10 @@ preprocessImageToMatrix <- function(x, } else { SKI <- pkg_ptr } - + # Ensure the source image array is writable by making a copy x_copy <- reticulate::r_to_py(x)$copy() - + # Warp the source image to align with the destination image warped_image <- SKI$transform$warp(x_copy, model, output_shape = dim(y)) SKI$io$imsave(outpath,warped_image) @@ -1455,22 +1455,22 @@ preprocessImageToMatrix <- function(x, } else { SKI <- pkg_ptr } - + matplotlib <-reticulate::import("matplotlib", convert = TRUE, delay_load = TRUE) np <- reticulate::import("numpy",convert = T, delay_load = T) plt <- matplotlib$pyplot - + match_py <- reticulate::r_to_py(match) - match_py <- np$array(match_py, dtype = np$int32) - + match_py <- np$array(match_py, dtype = np$int32) + # Create a subplot fig_ax <- plt$subplots(nrows = 1L, ncols = 1L, figsize = c(11, 8)) fig <- fig_ax[[1]] ax <- fig_ax[[2]] - + # Plot the matches SKI$feature$plot_matches(ax, x, y, keypoints1, keypoints2, match_py, only_matches = TRUE) - + ax$axis('off') plt$show() plt$close() @@ -1497,31 +1497,31 @@ estimateAutomatedImageRegistrationWithSIFT <- function(x, estimate_fun = 'affine', save_warp = NULL, verbose = T){ - + GiottoUtils::vmsg(.v = verbose, .is_debug = T,'Detecting features via SIFT... ') x_sift <- .sift_detect(x) y_sift <- .sift_detect(y) - + GiottoUtils::vmsg(.v = verbose, .is_debug = T,'Matching Descriptors via SIFT... ') matched <- .match_descriptor_single(x_sift$descriptor, y_sift$descriptor,max_ratio = max_ratio) - + if (plot_match == TRUE){ .plot_matched_descriptors(x, y, x_sift$keypoints, y_sift$keypoints, matched) } - - + + GiottoUtils::vmsg(.v = verbose, .is_debug = T,'Estimating transformation matrix from matched descriptor... ') - estimation <- .estimate_transform_from_matched_descriptor(x_sift$keypoints, + estimation <- .estimate_transform_from_matched_descriptor(x_sift$keypoints, y_sift$keypoints, matched, estimate_fun = estimate_fun) - + if (!is.null(save_warp)){ .warp_transformed_image(x = x, y = y, model = estimation$inverse, outpath = save_warp) } - + return(estimation) } diff --git a/R/interactivity.R b/R/interactivity.R index 27dc3ad5c..2ce831111 100644 --- a/R/interactivity.R +++ b/R/interactivity.R @@ -380,7 +380,7 @@ comparePolygonExpression <- function( } # get expression - my_expression <- get_expression_values(gobject, + my_expression <- getExpression(gobject, values = expression_values, spat_unit = spat_unit, feat_type = feat_type, @@ -587,7 +587,7 @@ plotPolygons <- function( if (is.null(x)) stop("A plot object must be provided") ## get polygons spatial info - polygon_spatVector <- get_polygon_info( + polygon_spatVector <- getPolygonInfo( gobject = gobject, polygon_name = polygon_name, return_giottoPolygon = FALSE diff --git a/R/python_hmrf.R b/R/python_hmrf.R index 6d1177ed0..a4ac65ed8 100644 --- a/R/python_hmrf.R +++ b/R/python_hmrf.R @@ -1498,7 +1498,7 @@ initHMRF_V2 <- "scaled", "normalized", "custom", expression_values ))) - expr_values <- get_expression_values( + expr_values <- getExpression( gobject = gobject, spat_unit = spat_unit, feat_type = feat_type, @@ -1506,7 +1506,7 @@ initHMRF_V2 <- ) if (zscore != "none") { zscore <- match.arg(zscore, c("none", "colrow", "rowcol")) - expr_values <- get_expression_values( + expr_values <- getExpression( gobject = gobject, spat_unit = spat_unit, feat_type = feat_type, diff --git a/R/spatial_enrichment.R b/R/spatial_enrichment.R index e378fd762..5c92d38a0 100644 --- a/R/spatial_enrichment.R +++ b/R/spatial_enrichment.R @@ -67,7 +67,7 @@ #' ) #' #' g <- runPAGEEnrich(gobject = g, -#' sign_matrix = sign_matrix, +#' sign_matrix = sm, #' min_overlap_genes = 2 #' ) #' @@ -256,7 +256,7 @@ makeSignMatrixDWLS <- function( expression_values, unique(c("normalized", "scaled", "custom", expression_values)) ) - expr_values <- get_expression_values( + expr_values <- getExpression( gobject = gobject, spat_unit = spat_unit, feat_type = feat_type, @@ -828,10 +828,7 @@ runPAGEEnrich <- function( gobject@parameters <- parameters_list ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_spatial_enrichment( - gobject = gobject, - spatenrichment = enrObj - ) + gobject <- setGiotto(gobject, enrObj) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -1132,10 +1129,7 @@ runRankEnrich <- function( gobject@parameters <- parameters_list ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_spatial_enrichment( - gobject = gobject, - spatenrichment = enrObj - ) + gobject <- setGiotto(gobject, enrObj) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### return(gobject) @@ -1351,10 +1345,7 @@ runHyperGeometricEnrich <- function( gobject@parameters <- parameters_list ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_spatial_enrichment( - gobject = gobject, - spatenrichment = enrObj - ) + gobject <- setGiotto(gobject, enrObj) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### return(gobject) @@ -1904,10 +1895,7 @@ spatialAutoCorLocal <- function( ) } ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_spatial_enrichment( - gobject = gobject, - spatenrichment = enr - ) + gobject <- setGiotto(gobject, enr) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### return(gobject) @@ -2928,10 +2916,7 @@ runDWLSDeconv <- function( gobject@parameters <- parameters_list ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### - gobject <- set_spatial_enrichment( - gobject = gobject, - spatenrichment = enrObj - ) + gobject <- setGiotto(gobject, enrObj) ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### return(gobject) diff --git a/R/spatial_interaction_spot.R b/R/spatial_interaction_spot.R index 9fe9f0740..267c426c8 100644 --- a/R/spatial_interaction_spot.R +++ b/R/spatial_interaction_spot.R @@ -2255,6 +2255,8 @@ plotCellProximityFeatSpot <- function( #' @param expression_values (e.g. 'normalized', 'scaled', 'custom') #' @param spatial_network_name spatial network to use for identifying #' interacting cells +#' @param spat_enr_name name of spatial enrichment containing DWLS results. +#' Default = `"DWLS"` #' @param cluster_column cluster column with cell type information #' @param random_iter number of iterations #' @param feature_set_1 first specific feature set from feature pairs @@ -2306,6 +2308,7 @@ plotCellProximityFeatSpot <- function( #' * p.adj: adjusted p-value #' * PI: significanc score: log2fc \* -log10(p.adj) #' } +#' @md #' @export spatCellCellcomSpots <- function( gobject, @@ -2313,6 +2316,7 @@ spatCellCellcomSpots <- function( feat_type = NULL, ave_celltype_exp, spatial_network_name = "Delaunay_network", + spat_enr_name = "DWLS", cluster_column = "cell_ID", random_iter = 1000, feature_set_1, @@ -2381,10 +2385,11 @@ spatCellCellcomSpots <- function( proximityMat <- proximityMat[, intersect_cell_IDs] # exact spatial_enrichment matrix - dwls_values <- get_spatial_enrichment( + dwls_values <- getSpatialEnrichment( gobject = gobject, spat_unit = spat_unit, feat_type = feat_type, + name = spat_enr_name, output = "data.table" ) data.table::setDF(dwls_values) diff --git a/R/wnn.R b/R/wnn.R index 588d11888..25b2cb829 100644 --- a/R/wnn.R +++ b/R/wnn.R @@ -458,7 +458,7 @@ runWNN <- function( matrix_result_name <- "theta_weighted_matrix" } - gobject <- set_multiomics( + gobject <- setMultiomics( gobject = gobject, result = theta_weighted, spat_unit = spat_unit, @@ -476,7 +476,7 @@ runWNN <- function( w_name_modality_1 <- paste0("w_", modality_1) } - gobject <- set_multiomics( + gobject <- setMultiomics( gobject = gobject, result = w_modality1, spat_unit = spat_unit, @@ -491,7 +491,7 @@ runWNN <- function( w_name_modality_2 <- paste0("w_", modality_2) } - gobject <- set_multiomics( + gobject <- setMultiomics( gobject = gobject, result = w_modality2, spat_unit = spat_unit, @@ -539,7 +539,7 @@ runIntegratedUMAP <- function( integrated_feat_type <- paste0(modality1, "_", modality2) } - theta_weighted <- get_multiomics(gobject, + theta_weighted <- getMultiomics(gobject, spat_unit = spat_unit, feat_type = integrated_feat_type, integration_method = integration_method, @@ -594,17 +594,10 @@ runIntegratedUMAP <- function( feat_type = modality1 ) - gobject <- set_NearestNetwork( - gobject = gobject, - nn_network = nnNetObj, - spat_unit = spat_unit, - feat_type = modality1, - nn_network_to_use = "kNN", - network_name = "integrated_kNN" - ) + gobject <- setGiotto(gobject, nnNetObj) ## store nn_network id - gobject <- set_multiomics( + gobject <- setMultiomics( gobject = gobject, result = nn_network$id, spat_unit = spat_unit, @@ -615,7 +608,7 @@ runIntegratedUMAP <- function( ) ## store nn_network dist - gobject <- set_multiomics( + gobject <- setMultiomics( gobject = gobject, result = nn_network$dist, spat_unit = spat_unit, diff --git a/man/enrichment_PAGE.Rd b/man/enrichment_PAGE.Rd index 220a05060..226fcb31a 100644 --- a/man/enrichment_PAGE.Rd +++ b/man/enrichment_PAGE.Rd @@ -114,7 +114,7 @@ sm <- makeSignMatrixPAGE( ) g <- runPAGEEnrich(gobject = g, - sign_matrix = sign_matrix, + sign_matrix = sm, min_overlap_genes = 2 ) diff --git a/man/screePlot.Rd b/man/screePlot.Rd index 2f65fb4f9..a8477d3b1 100644 --- a/man/screePlot.Rd +++ b/man/screePlot.Rd @@ -8,7 +8,8 @@ screePlot( gobject, spat_unit = NULL, feat_type = NULL, - name = NULL, + dim_reduction_name = NULL, + name = deprecated(), expression_values = c("normalized", "scaled", "custom"), reduction = c("cells", "feats"), method = c("irlba", "exact", "random", "factominer"), @@ -34,7 +35,9 @@ screePlot( \item{feat_type}{feature type (e.g. "rna", "dna", "protein")} -\item{name}{name of PCA object if available} +\item{dim_reduction_name}{name of PCA} + +\item{name}{deprecated} \item{expression_values}{expression values to use} diff --git a/man/spatCellCellcomSpots.Rd b/man/spatCellCellcomSpots.Rd index ac6e46389..dee251301 100644 --- a/man/spatCellCellcomSpots.Rd +++ b/man/spatCellCellcomSpots.Rd @@ -10,6 +10,7 @@ spatCellCellcomSpots( feat_type = NULL, ave_celltype_exp, spatial_network_name = "Delaunay_network", + spat_enr_name = "DWLS", cluster_column = "cell_ID", random_iter = 1000, feature_set_1, @@ -39,6 +40,9 @@ spatCellCellcomSpots( \item{spatial_network_name}{spatial network to use for identifying interacting cells} +\item{spat_enr_name}{name of spatial enrichment containing DWLS results. +Default = \code{"DWLS"}} + \item{cluster_column}{cluster column with cell type information} \item{random_iter}{number of iterations} @@ -84,31 +88,33 @@ Statistical framework to identify if pairs of features expected based on a reshuffled null distribution of feature expression values in cells that are spatially in proximity to each other. \itemize{ - * LR_comb:Pair of ligand and receptor - * lig_cell_type: cell type to assess expression level of ligand - * lig_expr: average expression residual(observed - DWLS_predicted) of - ligand in lig_cell_type - * ligand: ligand name - * rec_cell_type: cell type to assess expression level of receptor - * rec_expr: average expression residual(observed - DWLS_predicted) of - receptor in rec_cell_type - * receptor: receptor name - * LR_expr: combined average ligand and receptor expression residual - * lig_nr: total number of cells from lig_cell_type that spatially interact - with cells from rec_cell_type - * rec_nr: total number of cells from rec_cell_type that spatially interact - with cells from lig_cell_type - * rand_expr: average combined ligand and receptor expression residual from - random spatial permutations - * av_diff: average difference between LR_expr and rand_expr over all random - spatial permutations - * sd_diff: (optional) standard deviation of the difference between LR_expr - and rand_expr over all random spatial permutations - * z_score: (optional) z-score - * log2fc: LR_expr - rand_expr - * pvalue: p-value - * LR_cell_comb: cell type pair combination - * p.adj: adjusted p-value - * PI: significanc score: log2fc \* -log10(p.adj) +\itemize{ +\item LR_comb:Pair of ligand and receptor +\item lig_cell_type: cell type to assess expression level of ligand +\item lig_expr: average expression residual(observed - DWLS_predicted) of +ligand in lig_cell_type +\item ligand: ligand name +\item rec_cell_type: cell type to assess expression level of receptor +\item rec_expr: average expression residual(observed - DWLS_predicted) of +receptor in rec_cell_type +\item receptor: receptor name +\item LR_expr: combined average ligand and receptor expression residual +\item lig_nr: total number of cells from lig_cell_type that spatially interact +with cells from rec_cell_type +\item rec_nr: total number of cells from rec_cell_type that spatially interact +with cells from lig_cell_type +\item rand_expr: average combined ligand and receptor expression residual from +random spatial permutations +\item av_diff: average difference between LR_expr and rand_expr over all random +spatial permutations +\item sd_diff: (optional) standard deviation of the difference between LR_expr +and rand_expr over all random spatial permutations +\item z_score: (optional) z-score +\item log2fc: LR_expr - rand_expr +\item pvalue: p-value +\item LR_cell_comb: cell type pair combination +\item p.adj: adjusted p-value +\item PI: significanc score: log2fc \* -log10(p.adj) +} } }