diff --git a/R/amRdataPlots.R b/R/amRdataPlots.R index 7cf3f63..18c35a3 100644 --- a/R/amRdataPlots.R +++ b/R/amRdataPlots.R @@ -4,17 +4,21 @@ #' 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". +#' @return Invisibly returns the path to the written Markdown summary report +#' ("/amr_metadata_summary.md"). #' #' @examples +#' \dontrun{ #' generateSummary( -#' metadata_parquet = "results/metadata.parquet", -#' out_path = "results/" +#' metadata_parquet = "data/metadata.parquet", +#' out_path = "data/" #' ) +#' } #' #' @export -generateSummary <- function(metadata_parquet, out_path) { +generateSummary <- function(metadata_parquet, + out_path +) { # Little helper to apply distinct + non-empty + sorted vector clean_distinct <- function(df, col) { df |> @@ -60,7 +64,9 @@ generateSummary <- function(metadata_parquet, out_path) { dplyr::pull() # Core summaries - TotalEntryCount <- metadata |> dplyr::count() + TotalEntryCount <- metadata |> + dplyr::count() + CleanEntryCount <- metadata |> dplyr::distinct(genome.genome_id) |> dplyr::count() @@ -172,7 +178,7 @@ ResPropbyDrugClass <- drug_class_calls |> # Header write_new( md_path, - sprintf("# AMR summary report for *%s*", Species_name) + sprintf("# AMR summary report for *%s*", paste(Species_name, collapse = ", ")) ) # Basic stats @@ -218,18 +224,14 @@ ResPropbyDrugClass <- drug_class_calls |> 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), "", "")) - # } +invisible(md_path) } #' 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 +#' Expects `metadata_parquet` to be the output of +#' `cleanMetaData()` 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. #' @@ -238,9 +240,18 @@ ResPropbyDrugClass <- drug_class_calls |> #' #' @return Invisibly returns the path to the written PDF (all plots as #' separate pages of one multi-page file). +#' +#' @examples +#' \dontrun{ +#' generatePlots( +#' metadata_parquet = "data/metadata.parquet", +#' out_path = "data/" +#' ) +#' } #' @export generatePlots <- function(metadata_parquet, - out_path) { + out_path + ) { if (!dir.exists(out_path)) { dir.create(out_path, showWarnings = FALSE, recursive = TRUE) } diff --git a/R/utils_colors.R b/R/utils_colors.R index 7c4a25e..4ec3fce 100644 --- a/R/utils_colors.R +++ b/R/utils_colors.R @@ -3,7 +3,7 @@ # 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. +# a muted blue 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", diff --git a/data/amRdata_exploratory_plots.pdf b/data/amRdata_exploratory_plots.pdf index f54769b..6066afd 100644 Binary files a/data/amRdata_exploratory_plots.pdf and b/data/amRdata_exploratory_plots.pdf differ diff --git a/man/generatePlots.Rd b/man/generatePlots.Rd index 82845a2..2ba6636 100644 --- a/man/generatePlots.Rd +++ b/man/generatePlots.Rd @@ -16,8 +16,16 @@ 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 +Expects \code{metadata_parquet} to be the output of +\code{cleanMetaData()} 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. } +\examples{ +\dontrun{ +generatePlots( + metadata_parquet = "data/metadata.parquet", + out_path = "data/" +) +} +} diff --git a/man/generateSummary.Rd b/man/generateSummary.Rd index bbe49ef..246a824 100644 --- a/man/generateSummary.Rd +++ b/man/generateSummary.Rd @@ -13,16 +13,18 @@ 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". +Invisibly returns the path to the written Markdown summary report +("/amr_metadata_summary.md"). } \description{ Generate a summary report for AMR metadata } \examples{ +\dontrun{ generateSummary( - metadata_parquet = "results/metadata.parquet", - out_path = "results/" + metadata_parquet = "data/metadata.parquet", + out_path = "data/" ) +} }