Preprocessing script - #1
Conversation
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
weshinsley
left a comment
There was a problem hiding this comment.
Looks fine to me! A very optional suggestion about the cli package for messages...
| args <- commandArgs(trailingOnly = TRUE) | ||
| if (length(args) == 0) { | ||
| stop("Usage: Rscript process_stave.R <stave_release>\nExample: Rscript process_stave.R 2026.03.17") | ||
| } |
There was a problem hiding this comment.
This is fine - we've generally been using the cli package and cli_abort instead of stop - it looks a little nicer and can do some clever message construction (which you don't really need here in this example - but perhaps later!)
eg
cli_abort(c(
"Usage: {.code Rscript process_stave.R <stave_release>}",
"i" = "Example: {.code Rscript process_stave.R 2026.03.17}"
))
| stop(sprintf( | ||
| "Expected each variant to parse to exactly 1 row via variant_to_long(), but got unexpected row counts for: %s.\n The variant string might not be single-locus. Did you call $get_variants(report_haplo=TRUE)?", | ||
| paste(unique(bad), collapse = ", ") | ||
| )) |
There was a problem hiding this comment.
So with cli - see if you like the below (both code and the appearance of the error...?)
cli_abort(c(
"Expected each variant to parse to exactly 1 row via {.fn variant_to_long}, but got unexpected row counts for: {.val {unique(bad)}}.",
"x" = "The variant string might not be single-locus.",
"i" = "Did you call {.code $get_variants(report_haplo = TRUE)}?"
))
|
|
||
| write_parquet(prevalence_tbl, file.path(output_dir, output_filename)) | ||
|
|
||
| print(sprintf("Wrote %s with %d rows to %s", output_filename, nrow(prevalence_tbl), output_dir)) |
There was a problem hiding this comment.
Wonder if this looks nicer...
cli::cli_inform(c(
"v" = "Wrote {.file {output_filename}} with {nrow(prevalence_tbl)} rows to {.path {output_dir}}."
))
| input_dir <- here("scripts", "input", "stave", current_stave_release) | ||
| output_dir <- here("data", "stave", current_stave_release) | ||
|
|
||
| stave_obj <- readRDS(file.path(input_dir, "stave_data.rds")) |
There was a problem hiding this comment.
Line 27, if you like:
cli_abort("Input file not found: {.file {input_file}}.")
|
@copilot Add the cli package and apply weshinsley's suggestions. |
Co-authored-by: david-mears-2 <60350599+david-mears-2@users.noreply.github.com>
Done — |
This is a script that takes in an .rds file of data in the schema defined by STAVE and outputs a parquet file to be queried by the app. The parquet file contains one row per genetic variant per survey (the domain is surveys of malaria genetics). The script will be run whenever a new dataset is released, which may be a few times a year.
Extra data is appended to the table during the process: the prevalence of the variant in its survey (as calculated by a function from the STAVE package) and a little parsing of the variant into its composite gene and “mutation”.
Please let me know if anything is unclear or if it needs commenting to explain the reason for it; and whether the script produces the expected product.
ignore linting errors from main branch
AI usage
Script was written by AI with extensive hand-holding. Comments are human-written.