Skip to content

Fix parse_ml_filename() misparsing year/country-stratified filenames - #34

Merged
eboyer221 merged 15 commits into
mainfrom
dev-parse-ml-filename-stratified
Sep 3, 2026
Merged

eboyer221 merged 15 commits into
mainfrom
dev-parse-ml-filename-stratified

Conversation

@eboyer221

Copy link
Copy Markdown
Contributor

##Description
parse_ml_filename() in R/merge_ml_results.R expected the stratification token (year/country) to appear after the drug value in a filename, but the actual filenames written by the matrix-generation code place it before the drug value (e.g. Csp_drug_year_AMX_2010-2015_genes_binary_year_42_performance.tsv). This caused stratified filenames to be parsed with the wrong drug and a missing seed, with no error.

Why it matters

parse_ml_filename() is exported and documented as supporting stratified filenames, so any code parsing a stratified result filename with it gets silently wrong metadata.

Fix

Reordered the token-parsing logic so the strat label is read immediately after drug/drug_class, before the drug value, matching the grammar already used by buildPerfPqYearCountry().

Testing

Added tests/testthat/test-merge-ml-results.R covering: unstratified drug, unstratified drug_class, shuffled, year-stratified drug, and country-stratified drug_class filenames. Full suite passes (230/230).

Found while reviewing #32. Resolves PR1) of Issue #33.

…t filenames, not after the drug value so there was mislabeling. Corrected the token order to match was regex expects, and added regression tests for the stratified and unstratified cases.
AbhirupaGhosh
AbhirupaGhosh previously approved these changes Sep 2, 2026

@AbhirupaGhosh AbhirupaGhosh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. I made a few changes to remove the existing confusion with parse_ml_filename() using stratified filenames. I removed those steps so that it is only used by buildPerfPq() and buildTopFeatsPq().
  2. I also did a comparative major change; the performance and top features were saved as TSVs previously, which I changed to PARQUET. To adapt the parquets, I updated the merge_ml_results.
  3. Added a function to call all the merge functions.

parse_ml_filename() no longer carries stratification tokens, so a
year/country stratified filename was silently mislabelled (drug and
seed came out wrong). Detect the strat label after drug/drug_class and
stop() with a message pointing at buildPerfPqYearCountry().

Rewrite the regression tests to match the current design: .parquet
fixtures, no strat_label/strat_value fields, and explicit expect_error
coverage for stratified names and a bad drug token.
The path argument was renamed to perf_dir_path without updating the
roxygen block, leaving all four arguments undocumented (R CMD check
WARNING).
@eboyer221

eboyer221 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

My most recent commits made parse_ml_filename() throw a clear error when handed a year/country-stratified filename (instead of silently mis-parsing it), rewrote its tests to match the branch's current unstratified-only design, and added the missing docs for buildPerfPq(). Then merged current main into the branch and resolved the NAMESPACE conflict by regenerating the docs, so PR #34 is now conflict-free with all 231 tests passing.

Question I have for @AbhirupaGhosh :

  1. Did you mean to stop putting year / country in the result filenames? Your commit "remove stratification type twice" took the _year / _country tag out of the names that run_ML.R writes for stratified runs. Was that on purpose for this PR, or should that be a separate change? (If it's intended, then buildPerfPqYearCountry() — which still reads year / country names — needs a look, because it may no longer match anything.)

@AbhirupaGhosh

Copy link
Copy Markdown
Contributor
  1. The filenames had year/country word twice, so I removed one that was in the suffix and left only one in the prefix. I edited buildPerfPqYearCountry() and the topFeat one too.
  2. There will be a next PR where all the build functions will be converted to internal and not user-facing, and the function called mergeMLresults() will be used to build the merged result files.

Cover filename parsing for the single-token stratified format: year and
country stratification, drug and drug_class, plus the Importance
numeric coercion in the top-features aggregator.
@eboyer221
eboyer221 merged commit 48148ec into main Sep 3, 2026
@eboyer221
eboyer221 deleted the dev-parse-ml-filename-stratified branch September 3, 2026 20:55
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.

2 participants