Skip to content

Commit

Permalink
Merge pull request #187 from josschavezf/dev
Browse files Browse the repository at this point in the history
replace cat and print with wrap_msg
  • Loading branch information
josschavezf authored Apr 12, 2024
2 parents e119ac1 + bb2cebf commit cc3030e
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 283 deletions.
7 changes: 2 additions & 5 deletions R/NN_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]][[
Expand Down
20 changes: 9 additions & 11 deletions R/auxilliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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")
}

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
Expand Down
2 changes: 1 addition & 1 deletion R/combine_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand Down
38 changes: 17 additions & 21 deletions R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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 ##
## ------- ##
Expand All @@ -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 ##
Expand Down Expand Up @@ -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")



Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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.")
}
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/data_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions R/giotto_structures.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand All @@ -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"]

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit cc3030e

Please sign in to comment.