From 3f825b946f21f2b2ccd2331aaf1672ce6615b778 Mon Sep 17 00:00:00 2001 From: missaroa Date: Thu, 4 Apr 2024 17:54:21 -0700 Subject: [PATCH] add simpler milo check for plotting functions --- DESCRIPTION | 2 +- R/plotting_functions.R | 2 +- R/utils.R | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bb5c257..0f2d923 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: Sensitive DE testing using neighbourhoods instead of discrete clust License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 Imports: dplyr, ggplot2, diff --git a/R/plotting_functions.R b/R/plotting_functions.R index cc67ddf..ace0e41 100644 --- a/R/plotting_functions.R +++ b/R/plotting_functions.R @@ -67,7 +67,7 @@ plot_milo_by_single_metric = function(x, nhood_stat, colour_by = "logFC" , signi # checks out = .check_argument_correct(x, .check_sce, "Check x - something is wrong (gene names unique? reducedDim.name is not present?)") & - .check_sce_milo(x) & + .check_sce_milo_wo_graph(x) & .check_argument_correct(order_direction, .check_boolean, "Check order_direction - should be either TRUE or FALSE") & .check_reducedDim_in_sce(x , layout) & .check_nhood_stat(nhood_stat , x) diff --git a/R/utils.R b/R/utils.R index 5207446..78b3e5d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -28,6 +28,29 @@ } } +# sce-milo check wo/ calculation of the length of graph: that is used in plotting functions +#' @importFrom miloR Milo nhoods graph graph<- nhoods<- nhoodIndex<- buildNhoodGraph +#' @importFrom methods is +.check_sce_milo_wo_graph = function(x){ + if (!is(x , "Milo")){ + stop("x should be a Milo object. Please run `assign_neighbourhoods` first.") + return(FALSE) + } else if (sum(sum(nhoods(x))) == 0){ + stop("x should have calculated nhoods. Please run 'assign_neighbourhoods' first.") + return(FALSE) + } else if ( nrow(nhoods(x)) == 1 & ncol(nhoods(x)) == 1 ){ + stop("x should contain non-trivial nhoods. Please run `assign_neighbourhoods` first.") + return(FALSE) + } else if (isEmpty(nhoodIndex(x))){ + stop("x should have calculated nhoodIndex. Please run 'assign_neighbourhoods' first.") + return(FALSE) + } else { + return(TRUE) + } +} + + + # sce check: that is used in add_embedding #' @importFrom SingleCellExperiment reducedDimNames #' @importFrom SummarizedExperiment assays<- assays