Skip to content

Preprocessing script - #1

Open
david-mears-2 wants to merge 12 commits into
mainfrom
preprocessing-script
Open

Preprocessing script#1
david-mears-2 wants to merge 12 commits into
mainfrom
preprocessing-script

Conversation

@david-mears-2

@david-mears-2 david-mears-2 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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.

@david-mears-2
david-mears-2 marked this pull request as ready for review August 5, 2026 14:31
@david-mears-2
david-mears-2 requested a lite review from Copilot August 5, 2026 14:33

This comment was marked as outdated.

david-mears-2 and others added 4 commits August 5, 2026 16:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@weshinsley weshinsley left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me! A very optional suggestion about the cli package for messages...

Comment thread scripts/process_stave.R
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
stop("Usage: Rscript process_stave.R <stave_release>\nExample: Rscript process_stave.R 2026.03.17")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}"
))

Comment thread scripts/process_stave.R
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 = ", ")
))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)}?"
))

Comment thread scripts/process_stave.R Outdated

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if this looks nicer...

cli::cli_inform(c(
  "v" = "Wrote {.file {output_filename}} with {nrow(prevalence_tbl)} rows to {.path {output_dir}}."
))

Comment thread scripts/process_stave.R Outdated
Comment on lines +22 to +25
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"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 27, if you like:
cli_abort("Input file not found: {.file {input_file}}.")

@david-mears-2

Copy link
Copy Markdown
Contributor Author

@copilot Add the cli package and apply weshinsley's suggestions.

Co-authored-by: david-mears-2 <60350599+david-mears-2@users.noreply.github.com>

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown

@copilot Add the cli package and apply weshinsley's suggestions.

Done — cli is now imported and all stop()/print(sprintf(...)) calls have been replaced with cli_abort()/cli_inform() following weshinsley's suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants