3131# ' @param overwrite Logical; overwrite an existing file? Default `FALSE`.
3232# ' @param pheno_col Character string naming the column that contains
3333# ' SIR interpretations (class `sir`). Default `"pheno_provided"`.
34+ # ' @param guideline Optional single value to record in `testing_standard` field in the output (default `NULL`, in which case `testing_standard` will be populated from the `guideline` field in the input file).
35+ # ' @param vendor Optional single value to record in `vendor` field in the output (default `NULL`).
36+ # ' @param version Optional single value to record in `laboratory_typing_method_version_or_reagent` field in the output (default `NULL`).
3437# '
3538# ' @details
3639# ' When both `mic` and `disk` columns are present, MIC values are
7174# ' export_ncbi_ast(ebi_kq, "Kq_NCBI.tsv")
7275# ' }
7376export_ncbi_ast <- function (data , file = NULL , overwrite = FALSE ,
74- pheno_col = " pheno_provided" ) {
77+ pheno_col = " pheno_provided" , guideline = NULL ,
78+ vendor = NULL , version = NULL ) {
7579 # --- input validation ---
7680 if (! is.null(file )) {
7781 if (file.exists(file ) && ! overwrite ) {
@@ -172,7 +176,9 @@ export_ncbi_ast <- function(data, file = NULL, overwrite = FALSE,
172176 measurement = m_value ,
173177 measurement_units = m_units ,
174178 laboratory_typing_method = ncbi_method ,
175- testing_standard = if (" guideline" %in% colnames(data )) {
179+ testing_standard = if (! is.null(guideline )) {
180+ as.character(guideline )
181+ } else if (" guideline" %in% colnames(data )) {
176182 as.character(data $ guideline )
177183 } else {
178184 NA_character_
@@ -182,8 +188,14 @@ export_ncbi_ast <- function(data, file = NULL, overwrite = FALSE,
182188 } else {
183189 NA_character_
184190 },
185- vendor = NA_character_ ,
186- laboratory_typing_method_version_or_reagent = NA_character_ ,
191+ vendor = if (! is.null(vendor )) {
192+ as.character(vendor )
193+ } else {NA_character_
194+ },
195+ laboratory_typing_method_version_or_reagent = if (! is.null(version )) {
196+ as.character(version )
197+ } else {NA_character_
198+ },
187199 stringsAsFactors = FALSE
188200 )
189201
@@ -220,8 +232,11 @@ export_ncbi_ast <- function(data, file = NULL, overwrite = FALSE,
220232# ' `disk`, `method`, `platform`.
221233# ' @param pheno_col Character string naming the column that contains
222234# ' SIR interpretations (class `sir`). Default `"pheno_provided"`.
223- # ' @param breakpoint_version Character string specifying the breakpoint
224- # ' version used for interpretation (e.g. `"EUCAST 2024"`).
235+ # ' @param guideline Optional character string to record in `ast_standard`
236+ # ' field in the output (default `NULL`, in which case `ast_standard` will be
237+ # ' populated from the `guideline` field in the input file).
238+ # ' @param breakpoint_version Character string specifying the breakpoint version used for
239+ # ' interpretation (e.g. `"EUCAST 2024"`).
225240# ' @param submission_account Character string specifying the EBI Webin
226241# ' submission account identifier (e.g. `"Webin-###"`). If not provided,
227242# ' JSON output files will not be generated and the function will return
@@ -269,6 +284,7 @@ export_ncbi_ast <- function(data, file = NULL, overwrite = FALSE,
269284# ' }
270285export_ebi_ast <- function (data ,
271286 pheno_col = " pheno_provided" ,
287+ guideline = NULL ,
272288 breakpoint_version ,
273289 submission_account ,
274290 domain = " self.ExampleDomain" ,
@@ -370,12 +386,16 @@ export_ebi_ast <- function(data,
370386 biosample_id = data $ id ,
371387 species = species ,
372388 antibiotic_name = antibiotic_name ,
373- ast_standard = if (" guideline" %in% colnames(data )) {
389+ ast_standard = if (! is.null(guideline )) {
390+ as.character(guideline )
391+ } else if (" guideline" %in% colnames(data )) {
374392 as.character(data $ guideline )
375393 } else {
376394 NA_character_
377395 },
378- breakpoint_version = NA_character_ ,
396+ breakpoint_version = if (! is.null(breakpoint_version )) {
397+ as.character(breakpoint_version )
398+ } else {NA_character_ },
379399 laboratory_typing_method = ebi_method ,
380400 measurement = m_value ,
381401 measurement_units = m_units ,
@@ -393,7 +413,6 @@ export_ebi_ast <- function(data,
393413 if (! is.null(output_dir )) {
394414 safe_execute(format_ebi_json(out_df ,
395415 output_dir = output_dir ,
396- breakpoint_version = breakpoint_version ,
397416 submission_account = submission_account ,
398417 domain = domain
399418 ))
@@ -413,8 +432,6 @@ export_ebi_ast <- function(data,
413432# '
414433# ' @param ebi_antibiogram_table A data frame in the format output by
415434# ' [export_ebi_ast()].
416- # ' @param breakpoint_version Character string specifying the
417- # ' breakpoint version used for interpretation (e.g. `"EUCAST 2024"`).
418435# ' @param submission_account Character string specifying the Webin
419436# ' submission account identifier (e.g. `"Webin-###"`).
420437# ' @param output_dir Character string specifying the directory where JSON
@@ -438,7 +455,6 @@ export_ebi_ast <- function(data,
438455# ' \dontrun{
439456# ' format_ebi_json(
440457# ' ast_dataset,
441- # ' breakpoint_version = "EUCAST 2015",
442458# ' submission_account = "Webin-###",
443459# ' output_dir = "/path/to/output/"
444460# ' )
@@ -447,7 +463,6 @@ export_ebi_ast <- function(data,
447463# ' @importFrom jsonlite write_json
448464# ' @export
449465format_ebi_json <- function (ebi_antibiogram_table ,
450- breakpoint_version ,
451466 submission_account ,
452467 output_dir ,
453468 domain = NULL ) {
@@ -472,7 +487,7 @@ format_ebi_json <- function(ebi_antibiogram_table,
472487 iri = NULL
473488 ),
474489 " breakpointVersion" = list (
475- value = breakpoint_version ,
490+ value = records_by_sample [[ biosample ]] $ breakpoint_version [ entry ] ,
476491 iri = NULL
477492 ),
478493 " laboratoryTypingMethod" = list (
0 commit comments