Skip to content

Commit

Permalink
Fix: tax_fix no longer allows min_length of 0, as empty strings are (…
Browse files Browse the repository at this point in the history
…and were) always replaced. #97
  • Loading branch information
david-barnett committed Sep 14, 2024
1 parent 739f388 commit 4ad67d9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# microViz 0.12.5

- Fix: tax_fix no longer allows min_length of 0, as empty strings are (and were) always replaced

# microViz 0.12.4

- Fix: no more cowplot legend extraction warnings in `ord_explore`
Expand Down
31 changes: 22 additions & 9 deletions R/tax_fix.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@
#' 'G__unknown' 'G__Unknown' 'G__NA' 'F__unknown' 'F__Unknown' 'F__NA' 'O__unknown' 'O__Unknown' 'O__NA'
#' 'C__unknown' 'C__Unknown' 'C__NA' 'P__unknown' 'P__Unknown' 'P__NA' 'K__unknown' 'K__Unknown' 'K__NA'
#'
#' @param ps phyloseq or tax_table (taxonomyTable)
#' @param min_length replace strings shorter than this
#' @param unknowns also replace strings matching any in this vector, NA default vector shown in details!
#'
#' @param ps
#' phyloseq or tax_table (taxonomyTable)
#' @param min_length
#' replace strings shorter than this, must be integer > 0
#' @param unknowns
#' also replace strings matching any in this vector,
#' NA default vector shown in details!
#' @param suffix_rank
#' "classified" (default) or "current", when replacing an entry, should the suffix be taken from the lowest classified rank
#' for that taxon, "classified", or the "current" unclassified rank?
#' @param sep character(s) separating new name and taxonomic rank level suffix (see suffix_rank)
#' @param anon_unique make anonymous taxa unique by replacing unknowns with taxa_name?
#' "classified" (default) or "current", when replacing an entry,
#' should the suffix be taken from the lowest classified rank
#' for that taxon, "classified", or the "current" unclassified rank?
#' @param sep
#' character(s) separating new name and taxonomic rank level suffix (see suffix_rank)
#' @param anon_unique
#' make anonymous taxa unique by replacing unknowns with taxa_name?
#' otherwise they are replaced with paste("unknown", first_rank_name),
#' which is therefore the same for every anonymous taxon, meaning they will be merged if tax_agg is used.
#' (anonymous taxa are taxa with all unknown values in their tax_table row, i.e. cannot be classified even at highest rank available)
#' @param verbose emit warnings when cannot replace with informative name?
#' (anonymous taxa are taxa with all unknown values in their tax_table row,
#' i.e. cannot be classified even at highest rank available)
#' @param verbose
#' emit warnings when cannot replace with informative name?
#'
#' @return object same class as ps
#' @export
Expand Down Expand Up @@ -105,6 +115,9 @@ tax_fix <- function(ps,
sep = " ",
anon_unique = TRUE,
verbose = TRUE) {
if (!rlang::is_scalar_integerish(min_length) || min_length < 1L) {
stop("min_length must be an integer greater than 0")
}
if (is(ps, "psExtra")) stop("ps is a psExtra, run tax_fix BEFORE tax_agg etc")
if (methods::is(ps, "phyloseq")) {
tt <- unclass(phyloseq::tax_table(ps))
Expand Down
2 changes: 1 addition & 1 deletion R/tax_fix_interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ tax_fix_interactive <- function(data,
shiny::h5("Min length:"),
shiny::sliderInput(
inputId = "min_char", label = NULL,
min = 0, max = 10, value = 4,
min = 1, max = 10, value = 4,
step = 1, round = TRUE, ticks = FALSE
)
),
Expand Down
11 changes: 7 additions & 4 deletions man/tax_fix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ad67d9

Please sign in to comment.