diff --git a/R/NN_network.R b/R/NN_network.R index 45fe8eef..e41c0546 100644 --- a/R/NN_network.R +++ b/R/NN_network.R @@ -805,7 +805,7 @@ createNearestNetwork <- function(gobject, nn_names <- names(gobject@nn_network[[spat_unit]][[type]]) if (name %in% nn_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } nnObj <- create_nn_net_obj( @@ -915,10 +915,7 @@ addNetworkLayout <- function( if (return_gobject == TRUE) { nn_names <- names(gobject@nn_network[[spat_unit]][[nn_network_to_use]]) if (layout_name %in% nn_names) { - cat( - "\n ", layout_name, - " has already been used, will be overwritten \n" - ) + wrap_msg(layout_name," has already been used, will be overwritten") } gobject@nn_network[[spat_unit]][[ diff --git a/R/auxilliary.R b/R/auxilliary.R index 6102105d..09a6f6b7 100644 --- a/R/auxilliary.R +++ b/R/auxilliary.R @@ -197,14 +197,11 @@ annotateGiotto <- function( no_matching_annotations <- uniq_names[!uniq_names %in% uniq_clusters] if (length(missing_annotations) > 0) { - cat( - "Not all clusters have an accompanying annotation in the - annotation_vector: \n", - "These names are missing: ", as.character(missing_annotations), - "\n", - "These annotations have no match: ", - as.character(no_matching_annotations), "\n" - ) + wrap_msg("Not all clusters have an accompanying annotation in the + annotation_vector: \n", "These names are missing: ", + as.character(missing_annotations), "\n", + "These annotations have no match: ", + as.character(no_matching_annotations)) stop("Annotation interrupted \n") } @@ -1186,14 +1183,15 @@ calculateMetaTableCells <- function( if (!all(value_cols %in% cell_metadata_cols)) { missing_value_cols <- value_cols[!value_cols %in% cell_metadata_cols] - cat("These value columns were not found: ", missing_value_cols) + wrap_msg("These value columns were not found: ", missing_value_cols) } value_cols <- value_cols[value_cols %in% cell_metadata_cols] if (!all(metadata_cols %in% cell_metadata_cols)) { missing_metadata_cols <- metadata_cols[!metadata_cols %in% cell_metadata_cols] - cat("These metadata columns were not found: ", missing_metadata_cols) + wrap_msg("These metadata columns were not found: ", + missing_metadata_cols) } metadata_cols <- metadata_cols[metadata_cols %in% cell_metadata_cols] @@ -1340,7 +1338,7 @@ createMetafeats <- function( ) if (name %in% spenr_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### diff --git a/R/combine_metadata.R b/R/combine_metadata.R index 9d5ba472..fd890ff1 100644 --- a/R/combine_metadata.R +++ b/R/combine_metadata.R @@ -703,7 +703,7 @@ calculateSpatCellMetadataProportions <- function( if (name %in% spenr_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } ## update parameters used ## diff --git a/R/create.R b/R/create.R index 62e712a4..3cd3e412 100644 --- a/R/create.R +++ b/R/create.R @@ -761,7 +761,7 @@ createGiottoObjectSubcellular <- function(gpolygons = NULL, polygon_dfr_list_params <- list(calc_centroids = FALSE) } - if (verbose) cat("1. Start extracting polygon information \n") + if (verbose) wrap_msg("1. Start extracting polygon information") polygon_res <- .extract_polygon_list( polygonlist = gpolygons, @@ -770,18 +770,16 @@ createGiottoObjectSubcellular <- function(gpolygons = NULL, ) gobject@spatial_info <- polygon_res - if (verbose) cat("2. Finished extracting polygon information \n") + if (verbose) wrap_msg("2. Finished extracting polygon information") - if (verbose) cat("3. Add centroid / spatial locations if available \n") + if (verbose) wrap_msg("3. Add centroid / spatial locations if available") for (polygon_info in list_spatial_info_names(gobject)) { centroidsDT <- gobject@spatial_info[[polygon_info]]@spatVectorCentroids if (!is.null(centroidsDT)) { if (verbose) { - cat( - " - Add centroid / spatial locations for ", - polygon_info, " \n" - ) + wrap_msg(" - Add centroid / spatial locations for ", + polygon_info) } centroidsDT <- .spatvector_to_dt(centroidsDT) @@ -801,7 +799,7 @@ createGiottoObjectSubcellular <- function(gpolygons = NULL, ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### } } - if (verbose) cat("3. Finish adding centroid / spatial locations \n") + if (verbose) wrap_msg("3. Finish adding centroid / spatial locations") ## cell ID ## ## ------- ## @@ -818,13 +816,13 @@ createGiottoObjectSubcellular <- function(gpolygons = NULL, if (!is.null(gpoints)) { - if (verbose) cat("3. Start extracting spatial feature information \n") + if (verbose) wrap_msg("3. Start extracting spatial feature information") points_res <- .extract_points_list(pointslist = gpoints) gobject@feat_info <- points_res if (verbose) { - cat("4. Finished extracting spatial feature information \n") + wrap_msg("4. Finished extracting spatial feature information") } ## expression features ## @@ -1160,7 +1158,7 @@ createGiottoObjectSubcellular <- function(gpolygons = NULL, ## largeImages ## # expect a list of giotto largeImages or file paths to such images if (!is.null(largeImages)) { - if (verbose) cat("3. Start loading large images \n") + if (verbose) wrap_msg("3. Start loading large images") @@ -1214,7 +1212,7 @@ createGiottoObjectSubcellular <- function(gpolygons = NULL, } } - if (verbose) cat("4. Finished loading large images \n") + if (verbose) wrap_msg("4. Finished loading large images") } return(gobject) @@ -3004,8 +3002,8 @@ createGiottoImage <- function( } else if (transf == "flip_y_axis") { mg_object <- magick::image_flop(mg_object) } else { - cat(transf, " is not a supported transformation, see - details \n") + wrap_msg(transf, " is not a supported transformation, see + details") } } } @@ -3015,11 +3013,8 @@ createGiottoImage <- function( ## 2. spatial minmax and adjustments -- manual OR by image dimensions (auto) if (verbose == TRUE) { if (do_manual_adj == TRUE) { - cat( - "do_manual_adj == TRUE \n", - "Boundaries will be adjusted by given - values.\n" - ) + wrap_msg("do_manual_adj == TRUE \n", + "Boundaries will be adjusted by given values.") } } # If spatlocs or gobject supplied, minmax values will always be generated @@ -3252,7 +3247,7 @@ createGiottoLargeImage <- function( if (use_rast_ext == TRUE) { extent <- terra::ext(raster_object) if (verbose == TRUE) { - cat("use_rast_ext == TRUE, extent from input raster_object will + wrap_msg("use_rast_ext == TRUE, extent from input raster_object will be used.") } } @@ -3341,7 +3336,8 @@ createGiottoLargeImage <- function( if (nrow(sample_values) == 0) { if (verbose == TRUE) { - cat("No values discovered when sampling for image characteristics") + wrap_msg("No values discovered when sampling for image + characteristics") } } else { # find estimated intensity range diff --git a/R/data_input.R b/R/data_input.R index 71cb7d80..e3dc33eb 100644 --- a/R/data_input.R +++ b/R/data_input.R @@ -2201,7 +2201,7 @@ readPolygonData <- function( ), polygon_mask_list_params ) - if (isTRUE(verbose)) print(parameters) + if (isTRUE(verbose)) wrap_msg(parameters) poly_results <- do.call( what = "createGiottoPolygonsFromMask", @@ -2216,7 +2216,7 @@ readPolygonData <- function( ), polygon_dfr_list_params ) - if (isTRUE(verbose)) print(parameters) + if (isTRUE(verbose)) wrap_msg(parameters) poly_results <- do.call( what = "createGiottoPolygonsFromDfr", diff --git a/R/giotto_structures.R b/R/giotto_structures.R index ffd7f827..52ba9889 100644 --- a/R/giotto_structures.R +++ b/R/giotto_structures.R @@ -347,7 +347,7 @@ smoothGiottoPolygons <- function( # adjust k to maximum value max_k <- nrow(polygMat) if (k >= max_k) { - cat("k will be set to ", max_k) + wrap_msg("k will be set to ", max_k) k <- max_k } @@ -578,7 +578,7 @@ createSpatialFeaturesKNNnetwork_dbscan <- function( } ## 2. get spatial feature info and convert to matrix - if (verbose == TRUE) cat("Convert feature spatial info to matrix \n") + if (verbose == TRUE) wrap_msg("Convert feature spatial info to matrix") featDT <- .spatvector_to_dt(gobject@feat_info[[feat_type]]@spatVector) spatial_locations_matrix <- as.matrix( featDT[, c("x", "y", NULL), with = FALSE] @@ -593,7 +593,7 @@ createSpatialFeaturesKNNnetwork_dbscan <- function( ) ## 3. create kNN network - if (verbose == TRUE) cat("Create kNN network with dbscan \n") + if (verbose == TRUE) wrap_msg("Create kNN network with dbscan") knn_spatial <- dbscan::kNN( x = spatial_locations_matrix, k = k, @@ -609,7 +609,7 @@ createSpatialFeaturesKNNnetwork_dbscan <- function( ## 3. keep minimum and filter if (verbose == TRUE) { - cat("Filter output for distance and minimum neighbours \n") + wrap_msg("Filter output for distance and minimum neighbours") } knn_sptial.norm[, rank := seq_len(.N), by = "from"] @@ -632,7 +632,7 @@ createSpatialFeaturesKNNnetwork_dbscan <- function( ## 3. add feature information and sort if (add_feat_ids == TRUE) { - if (verbose == TRUE) cat("Add feat IDs and sort output \n") + if (verbose == TRUE) wrap_msg("Add feat IDs and sort output") featDT_vec <- featDT$feat_ID names(featDT_vec) <- featDT$feat_ID_uniq @@ -731,7 +731,7 @@ createSpatialFeaturesKNNnetwork <- function( network_names <- names(gobject@feat_info[[feat_type]]@networks) if (name %in% network_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } gobject@feat_info[[feat_type]]@networks[[name]] <- knn_feat_network_obj diff --git a/R/images.R b/R/images.R index 9aaf6486..98c31de8 100644 --- a/R/images.R +++ b/R/images.R @@ -61,8 +61,8 @@ estimateImageBg <- function(mg_object, top_color_range = seq_len(50)) { col = names(sort_table[top_color_range]) ) - cat("Most abundant pixel colors: \n") - print(sort_table[top_color_range]) + wrap_msg("Most abundant pixel colors:") + wrap_msg(sort_table[top_color_range]) } @@ -312,7 +312,7 @@ addGiottoImageMG <- function( )[1, ] } else { spat_loc_name <- NULL - cat("No spatial locations have been found \n") + wrap_msg("No spatial locations have been found") } } @@ -324,8 +324,6 @@ addGiottoImageMG <- function( if ((length(scale_factor) == length(images)) || length(scale_factor) == 1) { - # cat('scale_factor(s) external to giottoImage have been given and - # will be used') ext_scale_factor <- TRUE } else { stop("if scale_factor is given, it must be a numeric with either @@ -352,8 +350,7 @@ addGiottoImageMG <- function( all_im_names <- names(gobject@images) if (im_name %in% all_im_names) { - cat("\n ", im_name, " has already been used, will be - overwritten \n") + wrap_msg(im_name, " has already been used, will be overwritten") } # 3. Update boundaries if not already done during @@ -491,7 +488,7 @@ updateGiottoImageMG <- function( OR giottoImage argument(s) \n") } if (verbose == TRUE) { - cat("gobject argument not given \n return_gobject set to FALSE \n") + wrap_msg("gobject argument not given, return_gobject set to FALSE") } return_gobject <- FALSE } @@ -505,8 +502,8 @@ updateGiottoImageMG <- function( stop("giottoImage argument only accepts giottoImage objects \n") } if (verbose == TRUE && !is.null(gobject)) { - cat("giottoImage argument is given and will take priority \n - return_gobject set to FALSE \n") + wrap_msg("giottoImage argument is given and will take priority \n + return_gobject set to FALSE") } return_gobject <- FALSE } @@ -1168,17 +1165,12 @@ stitchGiottoLargeImage <- function( if (file.exists(filename)) { if (verbose == TRUE) { if (overwrite == TRUE) { - cat( - "File at", filename, - "exists.\n (overwrite == TRUE) Image will be overwritten" - ) + wrap_msg("File at", filename, + "exists.\n (overwrite == TRUE) Image will be overwritten") } if (overwrite == FALSE) { - cat( - "File at", filename, - "exists.\n (overwrite == FALSE) Image will not be - overwritten" - ) + wrap_msg("File at", filename, "exists.\n + (overwrite == FALSE) Image will not be overwritten") } } } @@ -1255,8 +1247,8 @@ stitchGiottoLargeImage <- function( # integer extents) if (round_positions == TRUE) { if (verbose == TRUE) { - cat("round_positions == TRUE \n Image spatial positions will be - rounded to integers. \n") + wrap_msg("round_positions == TRUE \n Image spatial positions will be + rounded to integers.") } for (rast_i in seq_len(length(raster_list))) { terra::ext(raster_list[[rast_i]]) <- round( @@ -1564,8 +1556,7 @@ convertGiottoLargeImageToMG <- function( if (return_gobject == TRUE) { if (verbose == TRUE) { if (mg_name %in% names(gobject@images)) { - cat("\n ", mg_name, " has already been used, will be - overwritten \n") + wrap_msg(mg_name, " has already been used, will be overwritten") } } gobject@images[[mg_name]] <- g_image @@ -1697,7 +1688,7 @@ convertGiottoLargeImageToMG <- function( } } else if (!is.null(quick_INTS_maxval)) { if (isTRUE(verbose)) { - cat("Selecting compatible datatype for given maximum value \n") + wrap_msg("Selecting compatible datatype for given maximum value") } bitDepth <- .bitdepth(quick_INTS_maxval) } @@ -1805,11 +1796,11 @@ writeGiottoLargeImage <- function( if (file.exists(filename)) { if (verbose == TRUE) { if (overwrite == TRUE) { - cat("File at", filename, "exists.\n (overwrite == TRUE) + wrap_msg("File at", filename, "exists.\n (overwrite == TRUE) Image will be overwritten") } if (overwrite == FALSE) { - cat("File at", filename, "exists.\n (overwrite == FALSE) + wrap_msg("File at", filename, "exists.\n (overwrite == FALSE) Image will not be overwritten") } } @@ -1860,7 +1851,7 @@ writeGiottoLargeImage <- function( ## 3. Write to disk - if (verbose == TRUE) cat(paste0("Writing image to disk as ", dataType)) + if (verbose == TRUE) wrap_msg("Writing image to disk as ", dataType) terra::writeRaster( x = raster_object, filename = filename, @@ -1919,7 +1910,7 @@ updateGiottoLargeImage <- function( largeImage_name OR giottoLargeImage argument(s) \n") } if (verbose == TRUE) { - cat("gobject argument not given \n return_gobject set to FALSE \n") + wrap_msg("gobject argument not given, return_gobject set to FALSE") } return_gobject <- FALSE } @@ -1934,8 +1925,8 @@ updateGiottoLargeImage <- function( objects \n") } if (verbose == TRUE && !is.null(gobject)) { - cat("giottoLargeImage argument is given and will take priority - \n return_gobject set to FALSE \n") + wrap_msg("giottoLargeImage argument is given and will take priority + \n return_gobject set to FALSE") } return_gobject <- FALSE } @@ -2097,8 +2088,6 @@ addGiottoLargeImage <- function( if ((length(scale_factor) == length(largeImages)) || length(scale_factor) == 1) { - # cat('scale_factor(s) external to giottoImage have been given and - # will be used') ext_scale_factor <- TRUE } else { stop("if scale_factor is given, it must be a numeric with either @@ -2125,10 +2114,8 @@ addGiottoLargeImage <- function( all_im_names <- names(gobject@largeImages) if (im_name %in% all_im_names) { - cat( - "\n ", im_name, - " has already been used, will be overwritten \n" - ) + wrap_msg("\n ", im_name, + " has already been used, will be overwritten") } # Deep copy the raster_object @@ -2314,7 +2301,6 @@ plotGiottoImage <- function( } # Select plotting function - # cat('Plotting ', image_type, ': "', image_name, '" ... \n', sep = '') if (image_type == "image") { .plot_giottoimage_mg(giottoImage = img_obj) @@ -2691,7 +2677,7 @@ reconnectGiottoImage <- function( #### Auto Workflow if (auto_reconnect == TRUE) { - if (verbose == TRUE) cat("Attempting automatic reconnection...\n\n") + if (verbose == TRUE) wrap_msg("Attempting automatic reconnection...") # Find image_types to reconnect image_type_list <- unique(availableImgs$img_type) @@ -2724,36 +2710,32 @@ reconnectGiottoImage <- function( # print discovered images and paths # additionally, set path to NULL if file.exists() == FALSE if (verbose == TRUE) { - cat(image_type, "(s) discovered...\n", sep = "") + wrap_msg(image_type, "(s) discovered...", sep = "") } for (image_i in seq_len(length(img_path[[image_type]]))) { if (!is.null(img_path[[image_type]][[image_i]])) { if (verbose == TRUE) { - cat( - "-->", name_list[[image_type]][[image_i]], - ": filepath found" - ) + wrap_msg("-->", name_list[[image_type]][[image_i]], + ": filepath found") } if (!file.exists(img_path[[image_type]][[image_i]])) { - if (verbose == TRUE) cat("but file is missing\n") + if (verbose == TRUE) wrap_msg("but file is missing") img_path[[image_type]][[image_i]] <- NULL - } else if (verbose == TRUE) cat("\n") + } else if (verbose == TRUE) wrap_msg("\n") } else if (verbose == TRUE) { - cat( - "-->", name_list[[image_type]][[image_i]], - ": filepath NOT found\n" - ) + wrap_msg("-->", name_list[[image_type]][[image_i]], + ": filepath NOT found") } } - if (verbose == TRUE) cat("\n") + if (verbose == TRUE) wrap_msg("\n") } # image_type end loop #### Manual Workflow } else { - if (verbose == TRUE) cat("Reconnecting with manual input...\n\n") + if (verbose == TRUE) wrap_msg("Reconnecting with manual input...") # Check params # filepath list(s) must be given as input @@ -2845,20 +2827,17 @@ reconnectGiottoImage <- function( img_path[[image_type]] )) { if (verbose == TRUE) { - cat(image_type, ": no filepaths found. Skipping. \n") + wrap_msg(image_type, ": no filepaths found. Skipping.") } next } if (verbose == TRUE) { - cat("\n Skipping ", image_type, - "s with missing filepaths: \n", - sep = "" - ) - for (image_NULL_i in seq_len(sum(image_path_NULL[[image_type]]))) { - cat(name_list[[image_type]][[which( - image_path_NULL[[image_type]] - )[[image_NULL_i]]]], "\n") + wrap_msg("Skipping ", image_type, "s with missing filepaths:") + for (image_NULL_i in + seq_len(sum(image_path_NULL[[image_type]]))) { + wrap_msg(name_list[[image_type]][[which( + image_path_NULL[[image_type]])[[image_NULL_i]]]]) } } @@ -2899,7 +2878,7 @@ reconnectGiottoImage <- function( ) } - if (verbose == TRUE) cat("done \n") + if (verbose == TRUE) wrap_msg("done") } # image_type end loop return(gobject) } diff --git a/R/interoperability.R b/R/interoperability.R index f3b679a5..497966a4 100644 --- a/R/interoperability.R +++ b/R/interoperability.R @@ -128,8 +128,8 @@ check_py_for_scanpy <- function() { \n ", errWidth = TRUE)) } else if (module_test == FALSE && genv_in_use) { - cat("Python module scanpy is required for conversion. - Installing scanpy now in the Giotto Miniconda Environment.\n") + wrap_msg("Python module scanpy is required for conversion. + Installing scanpy now in the Giotto Miniconda Environment.") conda_path <- reticulate::miniconda_path() py_ver <- reticulate::py_config()$version_string @@ -147,8 +147,8 @@ check_py_for_scanpy <- function() { python_version = py_ver ) } else { - cat("Required Python module scanpy has been previously installed. - Proceeding with conversion.\n") + wrap_msg("Required Python module scanpy has been previously installed. + Proceeding with conversion.") } } @@ -631,10 +631,10 @@ giottoToAnnData <- function( } else if (!dir.exists(save_directory)) { warning(wrap_msg("Provided save directory not found. Creating save directory at location:")) - cat(save_directory) + wrap_msg(save_directory) dir.create(save_directory, recursive = TRUE) if (dir.exists(save_directory)) { - cat("Created directory", save_directory) + wrap_msg("Created directory", save_directory) } else { stop(wrap_msg("Unable to create directory. Please change the provided path and try again.")) diff --git a/R/join.R b/R/join.R index b118620b..f99ab36c 100644 --- a/R/join.R +++ b/R/join.R @@ -437,14 +437,13 @@ joinGiottoObjects <- function( } if (verbose) { - cat( - "Image: for ", imname, " add_to_x = ", - add_to_x, "\n" - ) + wrap_msg("Image: for ", imname, " add_to_x = ", + add_to_x) } gobj@images[[imname]]@minmax[c("xmax_sloc", "xmin_sloc")] <- - gobj@images[[imname]]@minmax[c("xmax_sloc", "xmin_sloc")] + add_to_x + gobj@images[[imname]]@minmax[c( + "xmax_sloc", "xmin_sloc")] + add_to_x xshift_list[[gobj_i]] <- add_to_x @@ -454,16 +453,14 @@ joinGiottoObjects <- function( add_to_y <- y_shift_i + (y_padding * (gobj_i - 1)) if (verbose) { - cat( - "Image: for ", imname, " add_to_y = ", - add_to_y, "\n" - ) + wrap_msg("Image: for ", imname, " add_to_y = ", + add_to_y) } - gobj@images[[imname]]@minmax[c("ymax_sloc", "ymin_sloc")] <- gobj@images[[imname]]@minmax[c( - "ymax_sloc", - "ymin_sloc" - )] + add_to_y + gobj@images[[imname]]@minmax[ + c("ymax_sloc", "ymin_sloc")] <- gobj@images[[ + imname]]@minmax[c("ymax_sloc","ymin_sloc")] + + add_to_y yshift_list[[gobj_i]] <- add_to_y } } @@ -516,10 +513,8 @@ joinGiottoObjects <- function( if (verbose) { - cat( - "largeImage: for ", imname, " add_to_x = ", - add_to_x, "\n" - ) + wrap_msg("largeImage: for ", imname, " add_to_x = ", + add_to_x) } @@ -542,10 +537,8 @@ joinGiottoObjects <- function( if (verbose) { - cat( - "largeImage: for ", imname, " add_to_y = ", - add_to_y, "\n" - ) + wrap_msg("largeImage: for ", imname, " add_to_y = ", + add_to_y) } @@ -611,10 +604,8 @@ joinGiottoObjects <- function( } if (verbose) { - cat( - "Spatial locations: for ", locs_i, - " add_to_x = ", add_to_x, "\n" - ) + wrap_msg("Spatial locations: for ", locs_i, + " add_to_x = ", add_to_x) } @@ -630,10 +621,8 @@ joinGiottoObjects <- function( add_to_y <- y_shift_i + (y_padding * (gobj_i - 1)) if (verbose) { - cat( - "Spatial locations: for ", locs_i, - " add_to_y = ", add_to_y, "\n" - ) + wrap_msg("Spatial locations: for ", locs_i, + " add_to_y = ", add_to_y) } myspatlocs[, sdimy := sdimy + add_to_y] @@ -721,16 +710,12 @@ joinGiottoObjects <- function( } if (verbose) { - cat( - "Spatial info: for ", spat_info, " add_to_x = ", - add_to_x, "\n" - ) + wrap_msg("Spatial info: for ", spat_info, " add_to_x = ", + add_to_x) } if (verbose) { - cat( - "Spatial info: for ", spat_info, " add_to_y = ", - add_to_y, "\n" - ) + wrap_msg("Spatial info: for ", spat_info, " add_to_y = ", + add_to_y) } gobj@spatial_info[[spat_info]]@spatVector <- terra::shift( @@ -786,16 +771,12 @@ joinGiottoObjects <- function( } if (verbose) { - cat( - "Feature info: for ", feat_info, " add_to_x = ", - add_to_x, "\n" - ) + wrap_msg("Feature info: for ", feat_info, " add_to_x = ", + add_to_x) } if (verbose) { - cat( - "Feature info: for ", feat_info, " add_to_y = ", - add_to_y, "\n" - ) + wrap_msg("Feature info: for ", feat_info, " add_to_y = ", + add_to_y) } gobj@feat_info[[feat_info]]@spatVector <- terra::shift( @@ -1045,7 +1026,7 @@ joinGiottoObjects <- function( if (isTRUE(verbose)) { wrap_msg("available_spat_info: \n") - print(available_spat_info) + wrap_msg(available_spat_info) } for (spat_info in available_spat_info) { diff --git a/R/methods-initialize.R b/R/methods-initialize.R index b3cf385c..780f2d50 100644 --- a/R/methods-initialize.R +++ b/R/methods-initialize.R @@ -207,7 +207,7 @@ setMethod("initialize", signature("giotto"), function(.Object, ...) { exp_list_names <- lapply(exp_list, spatIDs) list_match <- sapply(exp_list_names, setequal, exp_list_names[[1L]]) if (!all(list_match)) { - print(list_match) + wrap_msg(list_match) warning(wrap_txt( "spat_unit:", unique_expr_sets$spat_unit[[set_i]], "/", "feat_type:", unique_expr_sets$feat_type[[set_i]], diff --git a/R/save_load.R b/R/save_load.R index 6c29059e..57c4d366 100644 --- a/R/save_load.R +++ b/R/save_load.R @@ -374,7 +374,7 @@ loadGiotto <- function( ) for (feat_i in seq_len(length(feat_names))) { - if (verbose) print(feat_paths[feat_i]) + if (verbose) wrap_msg(feat_paths[feat_i]) spatVector <- terra::vect(x = feat_paths[feat_i]) # read in original column names and assign to spatVector @@ -385,7 +385,7 @@ loadGiotto <- function( names(spatVector) <- spatVector_names feat_name <- feat_names[feat_i] - if (verbose) print(feat_name) + if (verbose) wrap_msg(feat_name) gobject@feat_info[[feat_name]]@spatVector <- spatVector } } @@ -410,8 +410,8 @@ loadGiotto <- function( if (length(spat_files) != 0) { ## 3.1. shapes if (isTRUE(verbose)) { - wrap_msg("\n3.1 read Giotto spatial shape information \n") - print(spat_files) + wrap_msg("3.1 read Giotto spatial shape information") + wrap_msg(spat_files) } spat_names <- gsub(spat_files, @@ -513,10 +513,10 @@ loadGiotto <- function( if (length(overlap_files) == 0) { if (verbose) { wrap_msg("No overlaps were found, overlap loading will be - skipped \n") + skipped") } } else { - print(overlap_files) + wrap_msg(overlap_files) # find overlaps per spatVector for (sv_i in seq_along(overlap_search_term)) { @@ -544,7 +544,7 @@ loadGiotto <- function( input = overlap_paths_colnames[spat_i], header = FALSE )[["V1"]] - if (verbose) print(spatVector_names) + if (verbose) wrap_msg(spatVector_names) names(spatVector) <- spatVector_names feat_name <- gsub(overlap_filenames[spat_i], diff --git a/R/slot_accessors.R b/R/slot_accessors.R index d87b0cdf..ea6012ae 100644 --- a/R/slot_accessors.R +++ b/R/slot_accessors.R @@ -979,35 +979,6 @@ set_cell_metadata <- function( } - # old_meta = data.table::copy( - # gobject@cell_metadata[[spat_unit]][[feat_type]]) - # - # new_cols = NULL - # if(!is.null(old_meta) && inherits(old_meta, "data.table")){ - # old_cols = colnames(old_meta) - # new_cols = colnames(meta_dt) - # cat("\nWarning: The following columns will be overwritten:", - # old_cols, "\nThey will be replaced with:", new_cols,"\n") - # - # old_meta[, (old_cols) := NULL] - # - # } else { - # new_cols = colnames(meta_dt) - # cat("\nWriting data within columns:", new_cols, - # "\nto cell metadata\n") - # } - - # suppressWarnings({ - # gobject <- removeCellAnnotation(gobject = gobject, - # spat_unit = spat_unit, - # feat_type = feat_type, - # columns = old_cols, - # return_gobject = TRUE) - # gobject@cell_metadata[[spat_unit]][[feat_type]] = meta_dt - # }) - # message("\nCell Metadata slot '",spat_unit, feat_type, "' set.\n") - # - # 6. set and return gobject gobject@cell_metadata[[spat_unit]][[feat_type]] <- metadata @@ -2317,11 +2288,9 @@ get_spatial_locations <- function( spat_loc_name <- names( slot(gobject, "spatial_locs")[[spat_unit]] )[[1]] - # cat('No spatial locations have been selected, the first - # one -',spat_loc_name, '- will be used \n') } else { spat_loc_name <- NULL - cat("No spatial locations have been found \n") + wrap_msg("No spatial locations have been found") return(NULL) } } @@ -5329,11 +5298,9 @@ get_spatial_enrichment <- function( spat_unit = spat_unit, feat_type = feat_type )[[1]] - # cat('No spatial locations have been selected, the first - # one -',spat_loc_name, '- will be used \n') } else { enrichm_name <- NULL - cat("No spatial enrichment results have been found \n") + wrap_msg("No spatial enrichment results have been found") return(NULL) } } diff --git a/R/spatial_structures.R b/R/spatial_structures.R index 271c2fe9..ada67646 100644 --- a/R/spatial_structures.R +++ b/R/spatial_structures.R @@ -824,7 +824,7 @@ spat_net_to_igraph <- function(spatialNetworkObj, attr = NULL) { spat_unit = spat_unit ) if (name %in% spn_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } parameters_list <- slot(gobject, "parameters") number_of_rounds <- length(parameters_list) @@ -997,10 +997,7 @@ spat_net_to_igraph <- function(spatialNetworkObj, attr = NULL) { spat_unit = "cell" ) if (name %in% spn_names) { - cat( - "\n ", name, - " has already been used, will be overwritten \n" - ) + wrap_msg(name, " has already been used, will be overwritten") } parameters_list <- gobject@parameters number_of_rounds <- length(parameters_list) @@ -1508,7 +1505,7 @@ createSpatialKNNnetwork <- function( ) if (name %in% spn_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } parameters_list <- slot(gobject, "parameters") number_of_rounds <- length(parameters_list) @@ -2283,7 +2280,7 @@ createSpatialDefaultGrid <- function( ) if (name %in% spg_names) { - cat("\n ", name, " has already been used, will be overwritten \n") + wrap_msg(name, " has already been used, will be overwritten") } # 2. create spatial grid object @@ -2321,8 +2318,6 @@ createSpatialDefaultGrid <- function( # parent function name cl <- sys.call(-1) - # print('cl = ') - # print(cl) if (is.null(cl)) { gobject <- update_giotto_params(gobject, description = "_grid") @@ -2602,11 +2597,8 @@ annotateSpatialGrid <- function( missing_annotation <- annotation_vector[!annotation_vector %in% possible_annotations] if (length(missing_annotation) > 0) { - cat( - "These annotations were not found back in the cell metadata - (pDataDT): \n", - missing_annotation, "\n" - ) + wrap_msg("These annotations were not found back in the cell metadata + (pDataDT): \n", missing_annotation) } annotation_vector_found <- annotation_vector[annotation_vector %in% diff --git a/R/stitch_coordinates.R b/R/stitch_coordinates.R index 9d8cebd3..5ee4a496 100644 --- a/R/stitch_coordinates.R +++ b/R/stitch_coordinates.R @@ -112,13 +112,13 @@ stitchTileCoordinates <- function( Xcoord <- X.X <- XtileIndex <- Ycoord <- Y.Y <- YtileIndex <- NULL if (is.null(location_file$X.X)) { - print("X coordinates missing in input file.") + wrap_msg("X coordinates missing in input file.") } else if (is.null(location_file$Y.Y)) { - print("Y coordinates missing in input file.") + wrap_msg("Y coordinates missing in input file.") } else if (is.null(location_file$XtileIndex)) { - print("X tile index missing in input file.") + wrap_msg("X tile index missing in input file.") } else if (is.null(location_file$YtileIndex)) { - print("Y tile index missing in input file.") + wrap_msg("Y tile index missing in input file.") } else { copy_loc_file <- data.table::copy(location_file) copy_loc_file[, Xcoord := X.X + Xtilespan * (XtileIndex - 1)] diff --git a/R/subset.R b/R/subset.R index 77c71c0c..cd2a90ae 100644 --- a/R/subset.R +++ b/R/subset.R @@ -566,16 +566,14 @@ res_list <- list() # iterate through all spatial info entries... for (spat_info in names(spatial_info)) { - if (verbose) cat("for ", spat_info, "\n") + if (verbose) wrap_msg("for ", spat_info) si <- spatial_info[[spat_info]] # if the spatial info is one selected in poly_info: if (spat_info %in% poly_info) { if (verbose) { - cat( - "--> ", spat_info, " found back in polygon layer: ", - poly_info, "\n" - ) + wrap_msg("--> ", spat_info, " found back in polygon layer: ", + poly_info) } # # whitelist check @@ -583,14 +581,6 @@ # # that no spatial locations # # or expression info was discovered for the selected # # spat_unit - # if (!is.null(poly_whitelist)) { - # if (!objName(si) %in% poly_whitelist) { - # warning(wrap_txt( - # 'poly', objName(si), 'not in spat_unit or provenance of - # . aggregate spatial locations or expression' - # )) - # } - # } # check if cell_ids to keep and poly_ids of polygon have any overlap # warn if none @@ -669,7 +659,7 @@ res_list <- list() for (feat in names(feat_info)) { if (isTRUE(feat %in% feat_type)) { - if (verbose) cat("subset feature info:", feat) + if (verbose) wrap_msg("subset feature info:", feat) feat_subset <- .subset_giotto_points_object( gpoints = feat_info[[feat]], @@ -801,7 +791,7 @@ - if (verbose) cat("completed 1: preparation \n") + if (verbose) wrap_msg("completed 1: preparation") ## FILTER ## @@ -816,7 +806,7 @@ feat_type_ssub = feat_type_ssub ) - if (verbose) cat("completed 2: subset expression data \n") + if (verbose) wrap_msg("completed 2: subset expression data") # filter spatial locations @@ -827,7 +817,7 @@ spat_unit = spat_unit ) - if (verbose) cat("completed 3: subset spatial locations \n") + if (verbose) wrap_msg("completed 3: subset spatial locations") @@ -840,7 +830,7 @@ cell_ids = cell_ids ) - if (verbose) cat("completed 4: subset cell metadata \n") + if (verbose) wrap_msg("completed 4: subset cell metadata") # feature metadata gobject <- .subset_feature_metadata( @@ -850,7 +840,7 @@ feat_ids = feat_ids ) - if (verbose) cat("completed 5: subset feature metadata \n") + if (verbose) wrap_msg("completed 5: subset feature metadata") ## spatial network & grid ## @@ -862,7 +852,7 @@ ) - if (verbose) cat("completed 6: subset spatial network(s) \n") + if (verbose) wrap_msg("completed 6: subset spatial network(s)") # spatial grid # need to be recomputed @@ -881,7 +871,7 @@ ) # likely also needs to be recomputed - if (verbose) cat("completed 7: subsetted dimension reductions \n") + if (verbose) wrap_msg("completed 7: subsetted dimension reductions") ## nn network ## @@ -892,7 +882,7 @@ cell_ids = cell_ids ) - if (verbose) cat("completed 8: subsetted nearest network(s) \n") + if (verbose) wrap_msg("completed 8: subsetted nearest network(s)") ## spatial enrichment ## @@ -903,7 +893,7 @@ cell_ids = cell_ids ) - if (verbose) cat("completed 9: subsetted spatial enrichment results \n") + if (verbose) wrap_msg("completed 9: subsetted spatial enrichment results") ## spatial info if (!is.null(gobject@spatial_info)) { @@ -912,10 +902,6 @@ # # aggregate spatial locations and expression information # # # # Should only be checked for cell_ids subsets - # poly_whitelist = poly_provenance_whitelist( - # gobject = gobject, - # spat_unit = spat_unit - # ) for (select_poly_info in poly_info) { # For each entry entry in poly_info, subset using cell_ids. @@ -937,7 +923,8 @@ ) } - if (verbose) cat("completed 10: subsetted spatial information data \n") + if (verbose) + wrap_msg("completed 10: subsetted spatial information data") } @@ -954,7 +941,7 @@ verbose = verbose ) - if (verbose) cat("completed 11: subsetted spatial feature data \n") + if (verbose) wrap_msg("completed 11: subsetted spatial feature data") } @@ -1112,8 +1099,6 @@ gobject = gobject, spat_unit = spat_unit )[[1]] - # cat('No spatial locations have been selected, the first - # one -',spat_loc_name, '- will be used \n') # if spatlocs missing, use alternate method with spatial_info } else if (!is.null(slot(gobject, "spatial_info"))) { diff --git a/R/zzz.R b/R/zzz.R index 6e112df4..6217d886 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -2,29 +2,6 @@ .onAttach <- function(libname, pkgname) { - ## Giotto Utils ## - # utils_try = try( - # library(GiottoUtils), - # silent = TRUE - # ) - # - # if(inherits(utils_try, 'try-error')) { - # if (utils::menu(c("Yes", "No"), - # title = "GiottoUtils is required. Proceed with - # installation?") == "1") { - # devtools::install_github('drieslab/GiottoUtils') - # - # } else { - # print("Cancelling installation") - # stop('There is no package called GiottoUtils', call. = FALSE) - # } - # } - - # set GiottoClass options - # options("giotto.use_conda" = FALSE) - - ## print version number ## - check_ver <- getOption("giotto.check_version", TRUE) if (isTRUE(check_ver)) { GiottoUtils::check_github_suite_ver("GiottoClass") diff --git a/man/crop.Rd b/man/crop.Rd index 731a83fd..baa9080e 100644 --- a/man/crop.Rd +++ b/man/crop.Rd @@ -3,12 +3,15 @@ \name{crop} \alias{crop} \alias{crop,giottoLargeImage-method} +\alias{crop,spatLocsObj-method} \alias{crop,giottoPoints-method} \alias{crop,giottoPolygon-method} \title{Crop to a spatial subset} \usage{ \S4method{crop}{giottoLargeImage}(x, y, ...) +\S4method{crop}{spatLocsObj}(x, y, ...) + \S4method{crop}{giottoPoints}(x, y, DT = TRUE, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, ...) \S4method{crop}{giottoPolygon}(x, y, DT = TRUE, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, ...) @@ -40,15 +43,6 @@ the polygon that does fall within the selected crop region. Set \code{DT = FALSE} in order to use the default style of terra::crop behavior that also allows usage of additional params through ... } -\section{Methods (by class)}{ -\itemize{ -\item \code{crop(giottoLargeImage)}: Crop a giottoLargeImage - -\item \code{crop(giottoPoints)}: Crop a giottoPoints - -\item \code{crop(giottoPolygon)}: Crop a giottoPoints - -}} \examples{ g <- GiottoData::loadGiottoMini("visium") g_image <- getGiottoImage(g, image_type = "largeImage")