Skip to content

Commit

Permalink
Extracted functions what_antibiotic and what_phenotype
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebittinger committed Jun 26, 2024
1 parent 4809763 commit 581b120
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions R/match.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
antibiotic_susceptibility <- function (lineage,
antibiotic,
db = mirixdb::taxon_susceptibility) {
what_antibiotic(lineage, antibiotic, db)
}

what_antibiotic <- function (lineage,
antibiotic,
db = mirixdb::taxon_susceptibility) {
is_relevant <- db$antibiotic %in% antibiotic
db <- db[is_relevant, c("taxon", "rank", "value")]

Expand Down Expand Up @@ -75,18 +81,21 @@ phenotype_susceptibility <- function (lineage,
phenotype,
susceptibility,
db = mirixdb::taxon_phenotypes) {
is_relevant <- db[[phenotype]] %in% names(susceptibility)
db <- db[is_relevant, c("taxon", "rank", phenotype)]
# match_annotation() requires a column named "value"
colnames(db)[3] <- "value"

phenotype_values <- match_annotation(lineage, db)

phenotype_values <- what_phenotype(lineage, phenotype, db)
susceptibility_values <- susceptibility[phenotype_values]
susceptibility_values <- unname(susceptibility_values)
susceptibility_values
}

what_phenotype <- function (lineage,
phenotype,
db = mirixdb::taxon_phenotypes) {
db <- db[, c("taxon", "rank", phenotype)]
# match_annotation() requires a column named "value"
colnames(db)[3] <- "value"
match_annotation(lineage, db)
}

# Determine the annotation values for each lineage
#
# @param lineage A vector of taxonomic assignments or lineages
Expand Down

0 comments on commit 581b120

Please sign in to comment.