Skip to content

feat(dsstox): add ignore_case, fields and best_match options to dss_resolve() - #400

Merged
seanthimons merged 2 commits into
mainfrom
feat/dss-resolve-rank-and-match-options
Nov 24, 2026
Merged

seanthimons merged 2 commits into
mainfrom
feat/dss-resolve-rank-and-match-options

Conversation

@seanthimons

@seanthimons seanthimons commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

What

dss_resolve() gains three options. The defaults return the same rows and columns as before.

  • ignore_case = TRUE matches preferred names, IUPAC names and synonyms without regard to case.
    • Synonyms use the stored ident_upper rows. Preferred and IUPAC names have no upper-cased copy, so those two fields (2.5M of 15.3M rows) are folded at query time with DuckDB upper(), the same function that built ident_upper. No rebuild is needed.
    • A synonym match is reported as matched_on = "IDENTIFIER" in this mode, never "ident_upper".
    • CAS numbers, formulas, InChIKeys, SMILES and DTXSIDs stay exact, because case carries meaning in SMILES (c/C) and formulas (Co/CO).
  • fields limits which fields may match (any matched_on value). An input that matches only other fields comes back as the usual NA row. With ignore_case = TRUE, "ident_upper" means "IDENTIFIER".
  • best_match = TRUE returns one row per input and DTXSID when an input matches the same substance under several fields. It keeps the first field in the build's sort order: DTXSID, preferred name, CAS number, formula, InChIKey, IUPAC name, SMILES, upper-cased synonym, synonym. fields is applied first. An input that matches several substances still returns one row for each.
dss_resolve(
  c("formaldehyde", "CO"),
  ignore_case = TRUE,
  fields = c("PREFERRED_NAME", "IUPAC_NAME", "IDENTIFIER", "CASRN"),
  best_match = TRUE
)

The file-header comment on SQL interpolation is also corrected: field names are interpolated, after an allowlist check.

Not in this PR: synonym quality in the build

The build source has no synonym quality or type field, so nothing was added to data-raw/dsstox.R and no rebuild was run.

  • What the source holds. DSSTox_CCD_dump_12092025_CSVs.zip (Clowder 69529775e4b0731a616efc4b, the latest DSSTox zip on Clowder) has 13 columns: DTXSID, PREFERRED_NAME, CASRN, DTXCID, INCHIKEY, IUPAC_NAME, SMILES, MOLECULAR_FORMULA, AVERAGE_MASS, MONOISOTOPIC_MASS, QSAR_READY_SMILES, MS_READY_SMILES, IDENTIFIER. IDENTIFIER is one |-separated string of synonyms with no label per synonym.
  • Sources that do carry it.
    • CTX POST chemical/synonym/search/by-dtxsid/ groups synonyms as valid / good / other / beilstein / alternate / pcCode / deleted. Per the probe in DSSTox: decide synonym source now that the export has no IDENTIFIER column #349 it returns records for about 32% of DTXSIDs.
    • Clowder DSSTox_Synonyms.csv (April 2023, 643d71e1e4b08a6b393ff1b7) has a Synonym Type column parallel to Synonyms. It has two values only: Expert Validated Synonym (170,462 rows) and Synonym (415,962). 170,054 of its 1,210,230 substances have any synonyms. Joined to the installed build it would label 580,641 of 3,964,504 IDENTIFIER rows (14.6%), on 169,627 of 1,246,396 substances.
  • Neither covers most substances, and the 2023 file is three years older than the dump. This ties into the open synonym-source decision in DSSTox: decide synonym source now that the export has no IDENTIFIER column #349.

Checks

  • New fixture tests (in-memory DuckDB passed as con =, no network) cover the unchanged default, ignore_case, fields, best_match, combinations and bad arguments.
  • Default output on the installed 15.3M-row build for 4,997 names is row-for-row identical before and after (9,398 rows).
  • best_match on the installed build, 4,997 names, in four modes (default, ignore_case, ignore_case + name fields, default + name fields): one row per input and DTXSID, the same input/DTXSID pairs as without it, and the same field as a best-field pick computed separately in R. Rows drop from 9,398 to 5,034 (default) and from 9,081 to 5,043 (ignore_case).
  • DSSTox test file with NOT_CRAN=true against the installed build: 19 tests, 57 expectations, 0 fail, 0 skip.
  • Full suite (run before best_match was added; not re-run after): 11,514 pass, 0 fail, 3 skip, and 1 file-level error in test-generate_tests_pipeline.R. That file skips cleanly when run alone ("{specmill} is not installed" in this machine's default library) and does not touch this code.
  • Timing on the installed build, median of 5 runs, 4,997 names:
Call Before After
default 0.6–1.1 s 0.61 s
each name as written + upper-cased (concert's workaround) 0.62 s 0.65 s
ignore_case = TRUE n/a 1.19 s
ignore_case = TRUE + name fields n/a 1.18 s
default + best_match n/a 0.58 s
ignore_case + name fields + best_match n/a 1.53 s

The table has no indexes, so every call is already a scan plus hash join. ignore_case adds two scans; its time is flat in the number of inputs (0.99 s for 50 names, 1.60 s for 50,000; default 0.45 s and 0.71 s).

  • No CTX calls were made.

- ignore_case = TRUE matches preferred names, IUPAC names and synonyms
  without regard to case. Synonyms use the stored ident_upper rows; the two
  name fields are folded at query time with DuckDB upper(). CAS numbers,
  formulas, InChIKeys, SMILES and DTXSIDs stay exact.
- fields limits which fields may match, so a name lookup can leave out
  formulas and SMILES.
- Defaults return the same rows and columns as before.
@github-actions

Copy link
Copy Markdown
Contributor

📊 Test Coverage Report

Current Coverage: 90.97%

Threshold Target Status
Target 75% ✅

Note: Coverage is informational only and does not block merges. The 75% target is a guideline.

View detailed coverage report

Run covr::report(covr::package_coverage()) locally for detailed analysis.

Coverage excludes: R/data.R (documentation-only file)

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

One row per input and DTXSID, keeping the first matching field in the
build's sort order. Defaults unchanged. Also corrects the file-header
comment on SQL interpolation.
@seanthimons seanthimons changed the title feat(dsstox): add ignore_case and fields options to dss_resolve() feat(dsstox): add ignore_case, fields and best_match options to dss_resolve() Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📊 Test Coverage Report

Current Coverage: 90.97%

Threshold Target Status
Target 75% ✅

Note: Coverage is informational only and does not block merges. The 75% target is a guideline.

View detailed coverage report

Run covr::report(covr::package_coverage()) locally for detailed analysis.

Coverage excludes: R/data.R (documentation-only file)

@seanthimons
seanthimons merged commit 2dea292 into main Nov 24, 2026
13 checks passed
@seanthimons
seanthimons deleted the feat/dss-resolve-rank-and-match-options branch November 24, 2026 21:48
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