
Import and process antimicrobial phenotype data from WHONET files
Source:R/import_pheno.R
import_whonet_pheno.RdThis function imports antimicrobial susceptibility testing (AST) data from WHONET software output files (wide CSV format) and converts it to the standardised long-format used by AMRgen.
Usage
import_whonet_pheno(
input,
sample_col = NULL,
source = NULL,
species = NULL,
ab = NULL,
interpret_eucast = FALSE,
interpret_clsi = FALSE,
interpret_ecoff = FALSE,
include_patient_info = FALSE
)Arguments
- input
A dataframe or path to a CSV file containing WHONET AST output data
- sample_col
Column name for sample identifiers. If
NULL(default), the function auto-detects from known WHONET column names:"Identification number","Identification","laboratory","patient_id". Supply a column name explicitly to override.- source
Optional string value to record in the
sourcecolumn for all data points (e.g., dataset name or study identifier)- species
Optional string indicating a single species to use for phenotype interpretation (otherwise this is inferred per-sample from the input)
- ab
Optional string indicating a single antibiotic to use for phenotype interpretation (otherwise this is inferred per-sample from the input)
- interpret_eucast
A logical value (default is
FALSE). IfTRUE, the function will re-interpret the susceptibility phenotype (SIR) for each observation based on the MIC or disk diffusion values, against EUCAST human breakpoints. These will be reported in a new columnpheno_eucast, of classsir.- interpret_clsi
A logical value (default is
FALSE). IfTRUE, the function will re-interpret the susceptibility phenotype (SIR) for each observation based on the MIC or disk diffusion values, against CLSI human breakpoints. These will be reported in a new columnpheno_clsi, of classsir.- interpret_ecoff
A logical value (default is
FALSE). IfTRUE, the function will re-interpret the wildtype vs nonwildtype status for each observation based on the MIC or disk diffusion values, against epidemiological cut-off (ECOFF) values. These will be reported in a new columnecoff, of classsirand coded asNWT(nonwildtype) orWT(wildtype).- include_patient_info
Include patient demographic columns in output
Examples
# Built-in AMR package WHONET example dataset (standard uppercase format)
result <- import_whonet_pheno(AMR::WHONET)
#> Warning: There were 2 warnings in `mutate()`.
#> The first warning was:
#> ℹ In argument: `mic = as.mic(...)`.
#> Caused by warning:
#> ! in `as.mic()`: 1311 results in column mic truncated (9%) that were invalid
#> MICs: "S", "I", and "R"
#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
head(result)
#> # A tibble: 6 × 31
#> id drug mic disk guideline method platform disk_potency pheno_provided
#> <chr> <ab> <mic> <dsk> <chr> <chr> <chr> <chr> <sir>
#> 1 fe41d… AMP NA NA CLSI disk d… NA 10 S
#> 2 fe41d… AMC NA NA EUCAST disk d… NA 20 S
#> 3 fe41d… TZP NA NA EUCAST disk d… NA 30 S
#> 4 fe41d… FEP NA NA EUCAST disk d… NA 30 NA
#> 5 fe41d… CTX NA NA EUCAST disk d… NA 5 NA
#> 6 fe41d… FOX NA NA EUCAST disk d… NA 30 NA
#> # ℹ 22 more variables: spp_pheno <mo>, `Specimen number` <int>, Organism <chr>,
#> # Country <chr>, Laboratory <chr>, collection_date <date>,
#> # `Specimen type` <chr>, `Specimen type (Numeric)` <dbl>, Reason <chr>,
#> # `Isolate number` <int>, `Organism type` <chr>, Serotype <chr>,
#> # `Beta-lactamase` <lgl>, ESBL <lgl>, Carbapenemase <lgl>,
#> # `MRSA screening test` <lgl>, `Inducible clindamycin resistance` <lgl>,
#> # Comment <chr>, `Date of data entry` <date>, ab_col <chr>, …
if (FALSE) { # \dontrun{
# WHONET file with lowercase columns and _SIR suffix (e.g. amc_nd20, amc_nd20_SIR)
# import_whonet_pheno("path/to/whonet_export.csv", sample_col = "patient_id")
# Include patient demographics in output
import_whonet_pheno("path/to/whonet_export.csv",
sample_col = "patient_id",
include_patient_info = TRUE
)
# Interpret against EUCAST breakpoints for a specific species
result_interp <- import_whonet_pheno(AMR::WHONET,
interpret_eucast = TRUE,
species = "Escherichia coli"
)
} # }