|
47 | 47 |
|
48 | 48 |
|
49 | 49 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
50 | | -#################### Object Checks #################### |
| 50 | +#################### Object/Feature Checks #################### |
51 | 51 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
52 | 52 |
|
53 | 53 |
|
@@ -188,8 +188,68 @@ Assay5_Check <- function( |
188 | 188 | } |
189 | 189 |
|
190 | 190 |
|
| 191 | +#' Perform Feature and Meta Checks before plotting |
| 192 | +#' |
| 193 | +#' Wraps the `Feature_Present`, `Meta_Present`, `Reduction_Loading_Present`, and `Case_Check` into |
| 194 | +#' single function to perform feature checks before plotting. |
| 195 | +#' |
| 196 | +#' @param object Seurat object |
| 197 | +#' @param features vector of features and/or meta data variables to plot. |
| 198 | +#' @param assay Assay to use (default all assays present). |
| 199 | +#' |
| 200 | +#' @return vector of features and/or meta data that were found in object. |
| 201 | +#' |
| 202 | +#' @noRd |
| 203 | +#' |
| 204 | +#' @keywords internal |
| 205 | +#' |
| 206 | + |
| 207 | +Feature_PreCheck <- function( |
| 208 | + object, |
| 209 | + features, |
| 210 | + assay = NULL |
| 211 | +) { |
| 212 | + # set assay (if null set to active assay) |
| 213 | + assay <- assay %||% Assays(object = object) |
| 214 | + |
| 215 | + # Check features and meta to determine which features present |
| 216 | + features_list <- Feature_Present(data = object, features = features, omit_warn = FALSE, print_msg = FALSE, case_check_msg = FALSE, return_none = TRUE, seurat_assay = assay) |
| 217 | + |
| 218 | + meta_list <- Meta_Present(object = object, meta_col_names = features_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE) |
| 219 | + |
| 220 | + reduction_list <- Reduction_Loading_Present(seurat_object = object, reduction_names = meta_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE) |
| 221 | + |
| 222 | + all_not_found_features <- reduction_list[[2]] |
| 223 | + |
| 224 | + all_found_features <- c(features_list[[1]], meta_list[[1]], reduction_list[[1]]) |
| 225 | + |
| 226 | + # Stop if no features found |
| 227 | + if (length(x = all_found_features) < 1) { |
| 228 | + cli_abort(message = c("No features were found.", |
| 229 | + "*" = "The following are not present in object:", |
| 230 | + "i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}") |
| 231 | + ) |
| 232 | + } |
| 233 | + |
| 234 | + # Return message of features not found |
| 235 | + if (length(x = all_not_found_features) > 0) { |
| 236 | + op <- options(warn = 1) |
| 237 | + on.exit(options(op)) |
| 238 | + cli_warn(message = c("The following features were omitted as they were not found:", |
| 239 | + "i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}") |
| 240 | + ) |
| 241 | + } |
| 242 | + |
| 243 | + # Check feature case and message if found |
| 244 | + Case_Check(seurat_object = object, gene_list = all_not_found_features, case_check_msg = TRUE, return_features = FALSE) |
| 245 | + |
| 246 | + # return all found features |
| 247 | + return(all_found_features) |
| 248 | +} |
| 249 | + |
| 250 | + |
191 | 251 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
192 | | -#################### WARN/ERROR MESSAGING #################### |
| 252 | +#################### FUNCTION HELPERS #################### |
193 | 253 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
194 | 254 |
|
195 | 255 |
|
@@ -250,66 +310,6 @@ glue_collapse_scCustom <- function( |
250 | 310 | } |
251 | 311 |
|
252 | 312 |
|
253 | | -#' Perform Feature and Meta Checks before plotting |
254 | | -#' |
255 | | -#' Wraps the `Feature_Present`, `Meta_Present`, `Reduction_Loading_Present`, and `Case_Check` into |
256 | | -#' single function to perform feature checks before plotting. |
257 | | -#' |
258 | | -#' @param object Seurat object |
259 | | -#' @param features vector of features and/or meta data variables to plot. |
260 | | -#' @param assay Assay to use (default all assays present). |
261 | | -#' |
262 | | -#' @return vector of features and/or meta data that were found in object. |
263 | | -#' |
264 | | -#' @noRd |
265 | | -#' |
266 | | -#' @keywords internal |
267 | | -#' |
268 | | - |
269 | | -Feature_PreCheck <- function( |
270 | | - object, |
271 | | - features, |
272 | | - assay = NULL |
273 | | -) { |
274 | | - # set assay (if null set to active assay) |
275 | | - assay <- assay %||% Assays(object = object) |
276 | | - |
277 | | - # Check features and meta to determine which features present |
278 | | - features_list <- Feature_Present(data = object, features = features, omit_warn = FALSE, print_msg = FALSE, case_check_msg = FALSE, return_none = TRUE, seurat_assay = assay) |
279 | | - |
280 | | - meta_list <- Meta_Present(object = object, meta_col_names = features_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE) |
281 | | - |
282 | | - reduction_list <- Reduction_Loading_Present(seurat_object = object, reduction_names = meta_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE) |
283 | | - |
284 | | - all_not_found_features <- reduction_list[[2]] |
285 | | - |
286 | | - all_found_features <- c(features_list[[1]], meta_list[[1]], reduction_list[[1]]) |
287 | | - |
288 | | - # Stop if no features found |
289 | | - if (length(x = all_found_features) < 1) { |
290 | | - cli_abort(message = c("No features were found.", |
291 | | - "*" = "The following are not present in object:", |
292 | | - "i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}") |
293 | | - ) |
294 | | - } |
295 | | - |
296 | | - # Return message of features not found |
297 | | - if (length(x = all_not_found_features) > 0) { |
298 | | - op <- options(warn = 1) |
299 | | - on.exit(options(op)) |
300 | | - cli_warn(message = c("The following features were omitted as they were not found:", |
301 | | - "i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}") |
302 | | - ) |
303 | | - } |
304 | | - |
305 | | - # Check feature case and message if found |
306 | | - Case_Check(seurat_object = object, gene_list = all_not_found_features, case_check_msg = TRUE, return_features = FALSE) |
307 | | - |
308 | | - # return all found features |
309 | | - return(all_found_features) |
310 | | -} |
311 | | - |
312 | | - |
313 | 313 | #' Ask yes/no question to proceed |
314 | 314 | #' |
315 | 315 | #' Asks the user to answer yes/no question and returns logical value depending on |
@@ -337,6 +337,37 @@ yesno <- function(msg, .envir = parent.frame()) { |
337 | 337 | } |
338 | 338 |
|
339 | 339 |
|
| 340 | +#' Change function parameter value from NULL to NA |
| 341 | +#' |
| 342 | +#' Provides method to change parameter value dynamically within function to suit defaults of other functions. |
| 343 | +#' Used in iterative plotting functions. |
| 344 | +#' |
| 345 | +#' @param parameter the parameter to check for NULL |
| 346 | +#' |
| 347 | +#' @return if NULL returns NA otherwise returns input value. |
| 348 | +#' |
| 349 | +#' |
| 350 | +#' @import cli |
| 351 | +#' |
| 352 | +#' @noRd |
| 353 | +#' |
| 354 | + |
| 355 | +replace_null <- function( |
| 356 | + parameter |
| 357 | +) { |
| 358 | + # check length |
| 359 | + if (length(x = parameter) > 1) { |
| 360 | + cli_abort(message = "{.code parameter} must be single value.") |
| 361 | + } |
| 362 | + |
| 363 | + # check NULL and swap NA |
| 364 | + if (is.null(x = parameter)) { |
| 365 | + parameter <- NA |
| 366 | + } |
| 367 | + return(parameter) |
| 368 | +} |
| 369 | + |
| 370 | + |
340 | 371 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
341 | 372 | #################### QC HELPERS #################### |
342 | 373 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
@@ -827,7 +858,7 @@ Retrieve_IEG_Ensembl_Lists <- function( |
827 | 858 |
|
828 | 859 | # pull lists |
829 | 860 | qc_gene_list <- list( |
830 | | - ieg = ieg_gene_list[[ieg]] |
| 861 | + ieg = ensembl_ieg_list[[ieg]] |
831 | 862 | ) |
832 | 863 |
|
833 | 864 | return(qc_gene_list) |
|
0 commit comments