diff --git a/DESCRIPTION b/DESCRIPTION index 784b8f4..f3ec63d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,11 @@ Imports: data.table, dplyr, duckdb, + ggplot2, glue, + grid, + gridExtra, + knitr, purrr, readr, reshape2, @@ -44,7 +48,6 @@ Imports: biocViews: GenomeAssembly, Annotation, Sequencing VignetteBuilder: knitr Suggests: - knitr, rmarkdown, testthat (>= 3.0.0) Config/roxygen2/version: 8.0.0 diff --git a/NAMESPACE b/NAMESPACE index ff6d425..69af5ae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,8 @@ export(CDHIT2duckdb) export(buildClusterFeatureMap) export(cleanData) export(cleanMetaData) +export(generatePlots) +export(generateSummary) export(prepareGenomes) export(proteinAnnotations2Duckdb) export(retrieveGenomes) diff --git a/R/amRdataPlots.R b/R/amRdataPlots.R new file mode 100644 index 0000000..7cf3f63 --- /dev/null +++ b/R/amRdataPlots.R @@ -0,0 +1,491 @@ +#' Generate a summary report for AMR metadata +#' +#' @param metadata_parquet Character string. Path to a Parquet file containing +#' standardized AMR metadata. +#' @param out_path Character string. Directory where the Markdown report is written. +#' +#' @return Writes a structured, human‑readable summary report to +#' "/amr_metadata_summary.md". +#' +#' @examples +#' generateSummary( +#' metadata_parquet = "results/metadata.parquet", +#' out_path = "results/" +#' ) +#' +#' @export +generateSummary <- function(metadata_parquet, out_path) { + # Little helper to apply distinct + non-empty + sorted vector + clean_distinct <- function(df, col) { + df |> + dplyr::distinct({{ col }}) |> + dplyr::filter(!is.na({{ col }}), {{ col }} != "") |> + dplyr::arrange({{ col }}) |> + dplyr::pull({{ col }}) + } + + # Format for Markdown + md_tbl <- function(df) { + knitr::kable(df, format = "pipe") + } + + # Create a file + write_new <- function(path, lines) { + con <- file(path, open = "w", encoding = "UTF-8") + on.exit(close(con), add = TRUE) + writeLines(lines, con = con, sep = "\n", useBytes = TRUE) + } + + # Add lines to file + append_lines <- function(path, lines) { + con <- file(path, open = "a", encoding = "UTF-8") + on.exit(close(con), add = TRUE) + writeLines(lines, con = con, sep = "\n", useBytes = TRUE) + } + + # Setting paths + if (!dir.exists(out_path)) dir.create(out_path, recursive = TRUE, showWarnings = FALSE) + metadata_parquet <- normalizePath(metadata_parquet) + metadata <- arrow::read_parquet(metadata_parquet) + md_path <- file.path(out_path, "amr_metadata_summary.md") + + # Validation (got any data?) + if (nrow(metadata) == 0) { + stop("The output table is empty. Please check your query or input data.") + } + + # get Species name + Species_name <- metadata |> + dplyr::distinct(genome.species) |> + dplyr::pull() + + # Core summaries + TotalEntryCount <- metadata |> dplyr::count() + CleanEntryCount <- metadata |> + dplyr::distinct(genome.genome_id) |> + dplyr::count() + + Antibiotics <- clean_distinct(metadata, genome_drug.antibiotic) + AntibioticClasses <- clean_distinct(metadata, drug_class) + + LabMethods <- metadata |> + dplyr::mutate( + genome_drug.laboratory_typing_method = dplyr::case_when( + is.na(genome_drug.laboratory_typing_method) ~ "Not defined", + genome_drug.laboratory_typing_method == "" ~ "Not defined", + TRUE ~ genome_drug.laboratory_typing_method + ) + ) |> + dplyr::count(genome_drug.laboratory_typing_method) + + PubMed_ids <- clean_distinct(metadata, genome_drug.pmid) + + PhenotypeCount <- metadata |> + dplyr::group_by(genome_drug.resistant_phenotype) |> + dplyr::count() |> + dplyr::arrange(-n) |> + dplyr::ungroup() + + ## Stats by drugs + PhenotypebyDrugCount <- metadata |> + dplyr::group_by(genome_drug.resistant_phenotype, genome_drug.antibiotic) |> + dplyr::count() |> + dplyr::arrange(-n) |> + dplyr::ungroup() + + ResPropbyDrug <- metadata |> + dplyr::group_by(genome_drug.antibiotic) |> + dplyr::count(genome_drug.resistant_phenotype) |> + dplyr::mutate(prop = n / sum(n)) |> + dplyr::filter(genome_drug.resistant_phenotype == "Resistant") |> + dplyr::transmute(genome_drug.antibiotic, res_prop = round(prop, 3)) |> + dplyr::arrange(-res_prop) |> + dplyr::ungroup() + + # Collapse to one phenotype per genome x drug_class +drug_class_calls <- metadata |> + dplyr::group_by(genome.genome_id, drug_class) |> + dplyr::summarise( + genome_drug.resistant_phenotype = dplyr::case_when( + any(genome_drug.resistant_phenotype == "Resistant", na.rm = TRUE) ~ "Resistant", + any(genome_drug.resistant_phenotype == "Intermediate", na.rm = TRUE) ~ "Intermediate", + any(genome_drug.resistant_phenotype == "Susceptible", na.rm = TRUE) ~ "Susceptible", + TRUE ~ NA_character_ + ), + .groups = "drop" + ) + +# Stats by drug class +PhenotypebyDrugClassCount <- drug_class_calls |> + dplyr::count(genome_drug.resistant_phenotype, drug_class) |> + dplyr::arrange(dplyr::desc(n)) + +ResPropbyDrugClass <- drug_class_calls |> + dplyr::group_by(drug_class) |> + dplyr::count(genome_drug.resistant_phenotype) |> + dplyr::mutate(prop = n / sum(n)) |> + dplyr::filter(genome_drug.resistant_phenotype == "Resistant") |> + dplyr::transmute(drug_class, res_prop = round(prop, 3)) |> + dplyr::arrange(dplyr::desc(res_prop)) |> + dplyr::ungroup() + + ## Collection years + Year <- metadata |> + dplyr::distinct(genome.collection_year) |> + dplyr::filter(!is.na(genome.collection_year)) |> + dplyr::pull() |> + sort() + + YearCount <- metadata |> + dplyr::group_by(genome.collection_year) |> + dplyr::filter(!is.na(genome.collection_year)) |> + dplyr::count() |> + dplyr::arrange(-n) |> + dplyr::ungroup() + + ## Geographical regions (countries) + Country <- clean_distinct(metadata, genome.isolation_country) + CountryCount <- metadata |> + dplyr::group_by(genome.isolation_country) |> + dplyr::filter(!is.na(genome.isolation_country), genome.isolation_country != "") |> + dplyr::count() |> + dplyr::arrange(-n) |> + dplyr::ungroup() + + ## Isolation sources + Source <- clean_distinct(metadata, genome.isolation_source) + SourceCount <- metadata |> + dplyr::group_by(genome.isolation_source) |> + dplyr::filter(!is.na(genome.isolation_source), genome.isolation_source != "") |> + dplyr::count() |> + dplyr::arrange(-n) |> + dplyr::ungroup() + + Host <- clean_distinct(metadata, genome.host_common_name) + HostCount <- metadata |> + dplyr::group_by(genome.host_common_name) |> + dplyr::filter(!is.na(genome.host_common_name), genome.host_common_name != "") |> + dplyr::count() |> + dplyr::arrange(-n) |> + dplyr::ungroup() + + # Header + write_new( + md_path, + sprintf("# AMR summary report for *%s*", Species_name) + ) + + # Basic stats + append_lines( + md_path, + c( + sprintf("- **Total no. of observations**: %s", TotalEntryCount[[1]]), + sprintf("- **Unique genome IDs**: %s", CleanEntryCount[[1]]), + "", + sprintf( + "- **Associated publications** (%d): %s", + length(PubMed_ids), + if (length(PubMed_ids)) paste(PubMed_ids, collapse = ", ") else "None" + ), + "" + ) + ) + + # Lists + append_lines( + md_path, + c( + sprintf("## Antibiotics (%d)", length(Antibiotics)), + "", + paste(Antibiotics, collapse = ", "), + "", + sprintf("## Antibiotic classes (%d)", length(AntibioticClasses)), + "", + paste(AntibioticClasses, collapse = ", "), + "" + ) + ) + + # Tables! + append_lines(md_path, c("## Phenotype counts", "", md_tbl(PhenotypeCount), "", "")) + append_lines(md_path, c("## Phenotypes x antibiotic(s)", "", md_tbl(PhenotypebyDrugCount), "", "")) + append_lines(md_path, c("## Resistant proportions per antibiotic", "", md_tbl(ResPropbyDrug), "", "")) + append_lines(md_path, c("## Phenotypes x antibiotic class(es)", "", md_tbl(PhenotypebyDrugClassCount), "", "")) + append_lines(md_path, c("## Resistant proportion per antibiotic class", "", md_tbl(ResPropbyDrugClass), "", "")) + append_lines(md_path, c("## Laboratory methods", "", md_tbl(LabMethods), "", "")) + append_lines(md_path, c("## Collection years", "", md_tbl(YearCount), "", "")) + append_lines(md_path, c("## Isolation countries", "", md_tbl(CountryCount), "", "")) + append_lines(md_path, c("## Isolation sources", "", md_tbl(SourceCount), "", "")) + append_lines(md_path, c("## Hosts", "", md_tbl(HostCount), "", "")) + + + # Hosts as a simple list + # if (length(Host)) { + # append_lines(md_path, c("## Hosts", "", paste0("- ", Host), "", "")) + # } +} + + +#' Write all summary plots to file(s) +#' +#' Expects `metadata_parquet` to be the output of `runDataProcessing()`'s +#' `cleanData()` step (or an export of the resulting `metadata` table), since +#' `drug_abbr`, `drug_class`, and `num_resistant_classes` are only populated +#' after that step joins in the reference drug tables. +#' +#' @param metadata_parquet Character. Path to the Parquet metadata file. +#' @param out_path Character. Output directory for plot files. +#' +#' @return Invisibly returns the path to the written PDF (all plots as +#' separate pages of one multi-page file). +#' @export +generatePlots <- function(metadata_parquet, + out_path) { + if (!dir.exists(out_path)) { + dir.create(out_path, showWarnings = FALSE, recursive = TRUE) + } + + metadata <- arrow::read_parquet(normalizePath(metadata_parquet)) + + if (nrow(metadata) == 0) { + stop("The input metadata table is empty. Please check your query or input data.") + } + + ## Generate plots + # 1) Phenotypes across antibiotics and time + df_year <- metadata |> + dplyr::filter(!is.na(genome.collection_year)) |> + dplyr::select( + genome.genome_id, + drug_abbr, + genome_drug.resistant_phenotype, + genome.isolation_country, + genome.collection_year + ) + + summary_year <- df_year |> + dplyr::group_by( + drug_abbr, + genome_drug.resistant_phenotype, + genome.collection_year + ) |> + dplyr::summarise(count = dplyr::n(), .groups = "drop") + + p1 <- ggplot2::ggplot( + summary_year, + ggplot2::aes( + x = genome.collection_year, + y = count, + colour = genome_drug.resistant_phenotype + ) + ) + + ggplot2::geom_line() + + ggplot2::geom_point() + + ggplot2::facet_wrap(~drug_abbr, scales = "free_y") + + ggplot2::labs( + title = "Distribution of AMR phenotypes across antibiotics by year", + x = "Year", y = "Number of isolates", + colour = "Phenotype" + ) + + ggplot2::scale_color_manual(values = PHENOTYPE_COLORS, na.value = "gray70") + + ggplot2::theme_minimal(base_size = 12) + + ggplot2::theme( + text = ggplot2::element_text(colour = "black"), + legend.position = "bottom", + axis.text.x = ggplot2::element_text(angle = 45, hjust = 1, colour = "black"), + axis.text.y = ggplot2::element_text(colour = "black"), + axis.title = ggplot2::element_text(colour = "black"), + panel.grid.minor = ggplot2::element_blank() + ) + + # 2) Resistance only over time, colored by antibiotic (named palette aligned + # to factor levels via meta_palette() so colors stay consistent across runs) + abx_levels <- summary_year |> + dplyr::filter(genome_drug.resistant_phenotype == "Resistant") |> + dplyr::distinct(drug_abbr) |> + dplyr::arrange(drug_abbr) |> + dplyr::pull(drug_abbr) + + pal_named <- stats::setNames(meta_palette(length(abx_levels)), abx_levels) + + p2 <- ggplot2::ggplot( + summary_year |> + dplyr::filter(genome_drug.resistant_phenotype == "Resistant") |> + dplyr::mutate( + antibiotic_fac = factor(drug_abbr, levels = abx_levels) + ), + ggplot2::aes( + x = genome.collection_year, y = count, + colour = antibiotic_fac + ) + ) + + ggplot2::geom_line() + + ggplot2::geom_point() + + ggplot2::labs( + title = "Distribution of resistant isolates by year", + x = "Year", + y = "Number of AMR isolates", + colour = "Antibiotic" + ) + + ggplot2::scale_color_manual(values = pal_named, drop = TRUE) + # <- named palette + ggplot2::theme_minimal(base_size = 12) + + ggplot2::theme( + text = ggplot2::element_text(colour = "#2D2D2D"), + legend.position = "bottom" + ) + + # 3) Time × geography × phenotype + df_country <- metadata |> + dplyr::filter(genome.isolation_country != "") |> + dplyr::select( + genome.genome_id, + drug_abbr, + genome_drug.resistant_phenotype, + genome.isolation_country, + genome.collection_year + ) + + summary_country_year <- df_country |> + dplyr::group_by( + genome.collection_year, + genome_drug.resistant_phenotype, + genome.isolation_country + ) |> + dplyr::summarise(count = dplyr::n(), .groups = "drop") + + p3 <- ggplot2::ggplot( + summary_country_year, + ggplot2::aes( + x = genome.collection_year, + y = genome.isolation_country, + size = count, + color = genome_drug.resistant_phenotype + ) + ) + + ggplot2::geom_point(alpha = 0.75) + + ggplot2::scale_size(range = c(3, 15)) + + ggplot2::scale_color_manual(values = PHENOTYPE_COLORS, na.value = "gray70") + + ggplot2::labs( + title = "Distribution of AMR phenotype by year and geography", + x = "Year", y = "Country", + size = "Count", color = "Phenotype" + ) + + ggplot2::theme_minimal(base_size = 12) + + ggplot2::theme( + text = ggplot2::element_text(colour = "black"), + legend.position = "right" + ) + + # 4) Phenotype proportion per antibiotic (stacked, normalized) + p4 <- ggplot2::ggplot( + metadata, + ggplot2::aes( + x = drug_abbr, + fill = genome_drug.resistant_phenotype + ) + ) + + ggplot2::geom_bar(position = "fill") + + ggplot2::coord_flip() + + ggplot2::labs( + title = "Distribution of AMR phenotypes", + x = "Antibiotic", y = "Proportion", fill = "Phenotype" + ) + + ggplot2::scale_fill_manual(values = PHENOTYPE_COLORS, na.value = "gray70") + + ggplot2::theme_minimal(base_size = 12) + + ggplot2::theme( + text = ggplot2::element_text(colour = "black"), + legend.position = "bottom", + axis.text.x = ggplot2::element_text(angle = 45, hjust = 1) + ) + + # 5) Resistant isolates by isolation source (top 10 sources + Other, same + # convention as amRviz's makeIsolationSourcesPlot) + summary_isolation_source <- metadata |> + dplyr::filter(genome.isolation_source != "") |> + dplyr::group_by(genome.isolation_source, genome_drug.resistant_phenotype) |> + dplyr::summarise(count = dplyr::n(), .groups = "drop") |> + dplyr::filter(genome_drug.resistant_phenotype == "Resistant") + + top_isolation_sources <- summary_isolation_source |> + dplyr::slice_max(order_by = count, n = 10) |> + dplyr::pull(genome.isolation_source) + + summary_isolation_source <- summary_isolation_source |> + dplyr::mutate( + isolation_source_grp = ifelse( + genome.isolation_source %in% top_isolation_sources, + genome.isolation_source, + "Other" + ) + ) + + n_sources <- dplyr::n_distinct(summary_isolation_source$isolation_source_grp) + + p5 <- ggplot2::ggplot( + summary_isolation_source, + ggplot2::aes( + x = stats::reorder(isolation_source_grp, count), + y = count, fill = isolation_source_grp + ) + ) + + ggplot2::geom_col() + + ggplot2::coord_flip() + + ggplot2::labs( + title = "Distribution of AMR isolates by isolation source", + x = "Isolation source", y = "Number of AMR isolates" + ) + + ggplot2::scale_fill_manual(values = meta_palette(n_sources)) + + ggplot2::theme_minimal(base_size = 12) + + ggplot2::theme( + text = ggplot2::element_text(colour = "black"), + legend.position = "none" + ) + + # 6) Histogram of resistant classes per genome + p6 <- ggplot2::ggplot(metadata, ggplot2::aes(num_resistant_classes)) + + ggplot2::geom_histogram(binwidth = 1, fill = META_COLORS[[1]]) + + ggplot2::labs( + title = "Distribution of AMR classes per isolate", + x = "# Resistant Classes", y = "Count" + ) + + ggplot2::theme_minimal(base_size = 12) + + ggplot2::theme( + text = ggplot2::element_text(colour = "black"), + legend.position = "bottom", + axis.text = ggplot2::element_text(colour = "black"), + axis.title = ggplot2::element_text(colour = "black"), + panel.grid.minor = ggplot2::element_blank() + ) + + plots <- list(p1 = p1, p2 = p2, p3 = p3, p4 = p4, p5 = p5, p6 = p6) + + # Table for drug name - abbreviation mapping + drug_table <- metadata |> + dplyr::distinct(genome_drug.antibiotic, drug_abbr) |> + dplyr::rename( + "Abbreviation" = "drug_abbr", + "Antibiotic" = "genome_drug.antibiotic" + ) |> + dplyr::arrange(Antibiotic) + + ## Write to device + pdf_path <- file.path(out_path, "amRdata_exploratory_plots.pdf") + grDevices::pdf(pdf_path, onefile = TRUE) + on.exit(grDevices::dev.off(), add = TRUE) + for (nm in names(plots)) { + print(plots[[nm]]) + } + # grid::grid.newpage() + + gridExtra::grid.arrange( + grid::textGrob( + "Antibiotic name abbreviations", + gp = grid::gpar(fontsize = 16, fontface = "bold") + ), + gridExtra::tableGrob(drug_table, rows = NULL), + ncol = 1, + heights = c(0.08, 0.92) + ) + + invisible(pdf_path) +} diff --git a/R/utils_colors.R b/R/utils_colors.R new file mode 100644 index 0000000..7c4a25e --- /dev/null +++ b/R/utils_colors.R @@ -0,0 +1,41 @@ +# Colour palettes shared across the amR suite's plots (kept in sync with +# amRviz's R/utils_colors.R so reports and the dashboard read as one system). + +# AMR phenotype palette (R/S/I plus full-word + lowercase variants so it works +# regardless of how the column is encoded). Susceptible is intentionally +# neutral grey so Resistant amber stands out as the signal of interest. +PHENOTYPE_COLORS <- c( + R = "#d4872a", Resistant = "#d4872a", resistant = "#d4872a", + S = "#5b8db8", Susceptible = "#5b8db8", susceptible = "#5b8db8", + I = "#e6ab80", Intermediate = "#e6ab80", intermediate = "#e6ab80" +) + +# Categorical palette for metadata plots (hosts, isolation sources, etc.). +# Use `meta_palette(n)` at call sites rather than referencing META_COLORS +# directly, so plots handle more categories than length(META_COLORS) without +# falling back to NA / gray70. +META_COLORS <- c( + "#4a6b8a", "#87ceeb", "#e6ab80", "#8b6b7a", + "#4e9a9a", "#c4a35a", "#9b7fba", "#5b8db8", + "#d4735e", "#d4872a", "#b5b5b5" +) + +#' Categorical palette of `n` muted colors +#' +#' For `n <= length(META_COLORS)` returns the first `n` curated colors verbatim; +#' above that, interpolates via `grDevices::colorRampPalette()` so callers get a +#' full palette regardless of how many unique values their data has. +#' +#' @param n Number of colors to return. +#' @return A character vector of `n` hex colors (empty when `n <= 0`). +#' @keywords internal +#' @noRd +meta_palette <- function(n = length(META_COLORS)) { + if (n <= 0) { + return(character(0)) + } + if (n <= length(META_COLORS)) { + return(META_COLORS[seq_len(n)]) + } + grDevices::colorRampPalette(META_COLORS)(n) +} diff --git a/data/amRdata_exploratory_plots.pdf b/data/amRdata_exploratory_plots.pdf new file mode 100644 index 0000000..f54769b Binary files /dev/null and b/data/amRdata_exploratory_plots.pdf differ diff --git a/data/amr_metadata_summary.md b/data/amr_metadata_summary.md new file mode 100644 index 0000000..b280f57 --- /dev/null +++ b/data/amr_metadata_summary.md @@ -0,0 +1,150 @@ +# AMR summary report for *Staphylococcus argenteus* +- **Total no. of observations**: 723 +- **Unique genome IDs**: 73 + +- **Associated publications** (2): 26806258, 34100643 + +## Antibiotics (16) + +cefoxitin, chloramphenicol, ciprofloxacin, clindamycin, daptomycin, erythromycin, fosfomycin, fusidic_acid, gentamicin, levofloxacin, linezolid, oxacillin, penicillin, tetracycline, trimethoprim-sulfamethoxazole, vancomycin + +## Antibiotic classes (14) + +aminoglycosides, amphenicols, cephalosporins, fluoroquinolones, fusidane, glycopeptides, lincosamides, lipopeptides, macrolides, oxazolidinones, penicillins, phosphonics, tetracyclines, trimethoprim-sulfonamides + +## Phenotype counts + +|genome_drug.resistant_phenotype | n| +|:-------------------------------|---:| +|Susceptible | 633| +|Resistant | 90| + + +## Phenotypes x antibiotic(s) + +|genome_drug.resistant_phenotype |genome_drug.antibiotic | n| +|:-------------------------------|:-----------------------------|--:| +|Susceptible |gentamicin | 73| +|Susceptible |cefoxitin | 72| +|Susceptible |oxacillin | 72| +|Susceptible |trimethoprim-sulfamethoxazole | 72| +|Resistant |penicillin | 69| +|Susceptible |clindamycin | 68| +|Susceptible |fusidic_acid | 68| +|Susceptible |erythromycin | 67| +|Susceptible |fosfomycin | 58| +|Susceptible |levofloxacin | 58| +|Resistant |erythromycin | 5| +|Susceptible |daptomycin | 5| +|Susceptible |linezolid | 5| +|Susceptible |vancomycin | 5| +|Resistant |clindamycin | 4| +|Susceptible |penicillin | 4| +|Resistant |chloramphenicol | 3| +|Resistant |ciprofloxacin | 3| +|Resistant |tetracycline | 3| +|Susceptible |chloramphenicol | 2| +|Susceptible |ciprofloxacin | 2| +|Susceptible |tetracycline | 2| +|Resistant |cefoxitin | 1| +|Resistant |oxacillin | 1| +|Resistant |trimethoprim-sulfamethoxazole | 1| + + +## Resistant proportions per antibiotic + +|genome_drug.antibiotic | res_prop| +|:-----------------------------|--------:| +|penicillin | 0.945| +|chloramphenicol | 0.600| +|ciprofloxacin | 0.600| +|tetracycline | 0.600| +|erythromycin | 0.069| +|clindamycin | 0.056| +|cefoxitin | 0.014| +|oxacillin | 0.014| +|trimethoprim-sulfamethoxazole | 0.014| + + +## Phenotypes x antibiotic class(es) + +|genome_drug.resistant_phenotype |drug_class | n| +|:-------------------------------|:-------------------------|--:| +|Susceptible |aminoglycosides | 73| +|Susceptible |cephalosporins | 72| +|Susceptible |trimethoprim-sulfonamides | 72| +|Resistant |penicillins | 69| +|Susceptible |fusidane | 68| +|Susceptible |lincosamides | 68| +|Susceptible |macrolides | 67| +|Susceptible |fluoroquinolones | 60| +|Susceptible |phosphonics | 58| +|Resistant |macrolides | 5| +|Susceptible |glycopeptides | 5| +|Susceptible |lipopeptides | 5| +|Susceptible |oxazolidinones | 5| +|Resistant |lincosamides | 4| +|Susceptible |penicillins | 4| +|Resistant |amphenicols | 3| +|Resistant |fluoroquinolones | 3| +|Resistant |tetracyclines | 3| +|Susceptible |amphenicols | 2| +|Susceptible |tetracyclines | 2| +|Resistant |cephalosporins | 1| +|Resistant |trimethoprim-sulfonamides | 1| + + +## Resistant proportion per antibiotic class + +|drug_class | res_prop| +|:-------------------------|--------:| +|penicillins | 0.945| +|amphenicols | 0.600| +|tetracyclines | 0.600| +|macrolides | 0.069| +|lincosamides | 0.056| +|fluoroquinolones | 0.048| +|cephalosporins | 0.014| +|trimethoprim-sulfonamides | 0.014| + + +## Laboratory methods + +|genome_drug.laboratory_typing_method | n| +|:--------------------------------------------|---:| +|Biofosun Gram-positive panels broth dilution | 65| +|Not defined | 658| + + +## Collection years + +| genome.collection_year| n| +|----------------------:|---:| +| 2015| 671| +| 2017| 39| +| 2018| 13| + + +## Isolation countries + +|genome.isolation_country | n| +|:------------------------|---:| +|Thailand | 658| + + +## Isolation sources + +|genome.isolation_source | n| +|:-----------------------|--:| +|pork | 39| +|duck | 26| + + +## Hosts + +|genome.host_common_name | n| +|:-----------------------|---:| +|Human | 658| +|Duck | 26| + + diff --git a/data/metadata.parquet b/data/metadata.parquet new file mode 100644 index 0000000..ff600a0 Binary files /dev/null and b/data/metadata.parquet differ diff --git a/man/generatePlots.Rd b/man/generatePlots.Rd new file mode 100644 index 0000000..82845a2 --- /dev/null +++ b/man/generatePlots.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/amRdataPlots.R +\name{generatePlots} +\alias{generatePlots} +\title{Write all summary plots to file(s)} +\usage{ +generatePlots(metadata_parquet, out_path) +} +\arguments{ +\item{metadata_parquet}{Character. Path to the Parquet metadata file.} + +\item{out_path}{Character. Output directory for plot files.} +} +\value{ +Invisibly returns the path to the written PDF (all plots as +separate pages of one multi-page file). +} +\description{ +Expects \code{metadata_parquet} to be the output of \code{runDataProcessing()}'s +\code{cleanData()} step (or an export of the resulting \code{metadata} table), since +\code{drug_abbr}, \code{drug_class}, and \code{num_resistant_classes} are only populated +after that step joins in the reference drug tables. +} diff --git a/man/generateSummary.Rd b/man/generateSummary.Rd new file mode 100644 index 0000000..bbe49ef --- /dev/null +++ b/man/generateSummary.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/amRdataPlots.R +\name{generateSummary} +\alias{generateSummary} +\title{Generate a summary report for AMR metadata} +\usage{ +generateSummary(metadata_parquet, out_path) +} +\arguments{ +\item{metadata_parquet}{Character string. Path to a Parquet file containing +standardized AMR metadata.} + +\item{out_path}{Character string. Directory where the Markdown report is written.} +} +\value{ +Writes a structured, human‑readable summary report to +"/amr_metadata_summary.md". +} +\description{ +Generate a summary report for AMR metadata +} +\examples{ +generateSummary( + metadata_parquet = "results/metadata.parquet", + out_path = "results/" +) + +}