Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions R/amRdataPlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#' "<out_path>/amr_metadata_summary.md".
#' @return Invisibly returns the path to the written Markdown summary report
#' ("<out_path>/amr_metadata_summary.md").
#'
#' @examples
#' \dontrun{
#' generateSummary(
#' metadata_parquet = "results/metadata.parquet",
#' out_path = "results/"
#' metadata_parquet = "data/metadata.parquet",
#' out_path = "data/"
Comment thread
AbhirupaGhosh marked this conversation as resolved.
#' )
#' }
#'
#' @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 |>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Comment thread
AbhirupaGhosh marked this conversation as resolved.
}


#' 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
Comment thread
AbhirupaGhosh marked this conversation as resolved.
#' `drug_abbr`, `drug_class`, and `num_resistant_classes` are only populated
#' after that step joins in the reference drug tables.
#'
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion R/utils_colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file modified data/amRdata_exploratory_plots.pdf
Binary file not shown.
12 changes: 10 additions & 2 deletions man/generatePlots.Rd

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

10 changes: 6 additions & 4 deletions man/generateSummary.Rd

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