Skip to content

Commit ea4d844

Browse files
Refactor resistance summary calculation
Updated resistance summary calculation to read from the database and include a count of resistant classes.
1 parent 577b251 commit ea4d844

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

R/data_processing.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,15 +1370,18 @@ cleanMetaData <- function(duckdb_path, path, ref_file_path = "data_raw/") {
13701370
dplyr::filter(genome_drug.resistant_phenotype %in% c("Resistant", "Susceptible")) |>
13711371
DBI::dbWriteTable(conn = con, name = "filtered_metadata", overwrite = TRUE)
13721372

1373-
resistance_summary <- dplyr::tbl(con, "filtered_metadata") |>
1374-
tibble::as_tibble() |>
1375-
dplyr::filter(genome_drug.resistant_phenotype == "Resistant") |>
1376-
dplyr::group_by(genome.genome_id) |>
1377-
dplyr::summarise(
1378-
num_resistant_classes = dplyr::n_distinct(drug_class),
1379-
resistant_classes = paste(unique(class_abbr), collapse = "_")
1380-
)
1381-
1373+
resistance_summary <- DBI::dbReadTable(con, "filtered_metadata") |>
1374+
dplyr::filter(genome_drug.resistant_phenotype == "Resistant") |>
1375+
dplyr::group_by(genome.genome_id) |>
1376+
dplyr::summarise(
1377+
resistant_classes = paste(sort(unique(class_abbr)), collapse = "_"),
1378+
.groups = "drop"
1379+
) |>
1380+
dplyr::collect() |>
1381+
dplyr::mutate(
1382+
num_resistant_classes = stringr::str_count(resistant_classes, "_") + 1
1383+
)
1384+
13821385
year_breaks <- seq(1980, 2026, by = 5)
13831386
dplyr::tbl(con, "filtered_metadata") |>
13841387
tibble::as_tibble() |>

0 commit comments

Comments
 (0)