From 3375c9c549543a43be58f4294a688806db006de8 Mon Sep 17 00:00:00 2001 From: Insaynoah <74536546+Insaynoah@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:10:48 +0300 Subject: [PATCH] fix issue 88 plotAbundance rank --- R/plotAbundance.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/R/plotAbundance.R b/R/plotAbundance.R index 29f2adad..52dc85e3 100644 --- a/R/plotAbundance.R +++ b/R/plotAbundance.R @@ -140,6 +140,18 @@ setGeneric("plotAbundance", signature = c("x"), } } +.find_lowest_taxonomy_level<- function(x){ + levels <- taxonomyRanks(x) + for(tax_index in 1:length(levels)){ + if(anyNA(rowData(x)[,levels[tax_index]])){ + return(levels[tax_index-1]) + } + + } + return(levels[length(levels)]) +} + + #' @rdname plotAbundance #' @importFrom scater plotExpression @@ -147,7 +159,7 @@ setGeneric("plotAbundance", signature = c("x"), #' @export setMethod("plotAbundance", signature = c("SummarizedExperiment"), function(x, - rank = taxonomyRanks(x)[1], + rank = .find_lowest_taxonomy_level(x), features = NULL, order_rank_by = c("name","abund","revabund"), order_sample_by = NULL,