Skip to content

Commit

Permalink
Remove unnecessary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulthran committed Jun 26, 2024
1 parent 62887e7 commit 6c5c997
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 257 deletions.
52 changes: 0 additions & 52 deletions R/match.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,55 +76,3 @@ phenotype_susceptibility <- function (lineage,
susceptibility_values <- unname(susceptibility_values)
susceptibility_values
}

# The 'official' taxonomic ranks supported by this package
taxonomic_ranks <- c(
"Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")

# Return the first value that is not NA. If all values are NA, return NA. The
# resultant vector will not have names.
first_non_na_value <- function (x) {
unname(x[whatbacteria::first_true_idx(!is.na(x))])
}

# For each lineage, return the index of the taxon that is found within the
# lineage. If no taxa are found, return NA for that element. If multiple taxa
# are found, we issue a warning and return the index of the first taxon in the
# vector of taxa.
match_taxa <- function (lineages, taxa) {
n_lineages <- length(lineages)
if (length(taxa) == 0) {
return(rep_len(NA_character_, length(lineages)))
}

taxa_patterns <- paste0("(?<=__|\\b)(?:", taxa, ")\\b")
lineage_matches <- vapply(
X = taxa_patterns,
FUN = grepl,
FUN.VALUE = rep_len(TRUE, n_lineages),
x = lineages,
perl = TRUE,
USE.NAMES = TRUE)

# If the user passes only one lineage, lineage_matches will be a vector
# rather than an array. After some trial and error, I found that it's better
# to deal with this at each stage of the computation, rather than trying to
# coerce the vector to an array up front.
if (n_lineages == 1) {
multi_matches <- sum(lineage_matches) > 1
} else {
multi_matches <- rowSums(lineage_matches) > 1
}
if (any(multi_matches)) {
warning(
"The following lineages match more than one taxon:\n",
paste(lineages[multi_matches], collapse = "\n"), "\n")
}

if (n_lineages == 1) {
taxon_idx <- whatbacteria::first_true_idx(lineage_matches)
} else {
taxon_idx <- apply(lineage_matches, 1, whatbacteria::first_true_idx)
}
taxon_idx
}
2 changes: 1 addition & 1 deletion man/antibiotic_susceptibility.Rd

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

2 changes: 1 addition & 1 deletion man/phenotype_susceptibility.Rd

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

203 changes: 0 additions & 203 deletions tests/testthat/test-match.R

This file was deleted.

0 comments on commit 6c5c997

Please sign in to comment.