Skip to content

Console method files: load the RT correction library once from the final path; make duplicated keys last-wins everywhere - #817

Merged
htsugawa merged 3 commits into
masterfrom
claude/rt-library-and-duplicate-keys
Sep 29, 2026
Merged

htsugawa merged 3 commits into
masterfrom
claude/rt-library-and-duplicate-keys

Conversation

@YukiMatsuzawa

@YukiMatsuzawa YukiMatsuzawa commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two fixes to the MS-DIAL 5 console's method-file reader (tests/MSDIAL5/MsdialCoreTestApp/Parser/ConfigParser.cs).

1. The RT correction library is no longer loaded while the file is being read

ReadCommonParameter used to call TextLibraryParser.StandardTextLibraryReader as soon as it read Compounds library file path for RT correction, using the value exactly as written, and stored the result in RetentionTimeCorrectionCommon.StandardLibrary. That caused three problems:

  • a relative value was opened from the working directory;
  • GC-MS resolves the path against the method file's folder afterwards (ResolveGcmsFilePaths), and the rt-correction command swaps in its own library argument after parsing. In both cases the stored library and the stored path could refer to different files;
  • when the library had errors the reader returned null, so StandardLibrary became null.

Who reads StandardLibrary: in the console and the core code it calls, only RetentionTimeCorrectionProcess.Prepare. It sets StandardLibrary, and MsdialCore's RetentionTimeCorrection.Execute then reads it. Execute is reached only from Prepare. ParameterBase.ParametersAsText reads it too, but the console never calls that. Prepare already reloaded the library from CompoundListForRtCorrectionPath whenever Execute RT correction: True.

Change: the parser now records only the path. RetentionTimeCorrectionProcess.LoadStandards is the one place the library is loaded, and it is called from the final path after every rewrite, so it stays compatible with a separate change that rewrites relative paths after reading. The load is still an early format check: the library is small and its format is easy to get wrong, so LcmsProcess loads it right after the method file is read, before the analysis files are imported and before the annotation libraries and raw data. A malformed library stops the run there with RT correction library could not be used: <parser message>. The loaded anchors are passed to Prepare (new standardLibrary argument), which no longer reads the file again. The rt-correction command uses the same loader for its library argument, before it reads any raw data, and passes its anchors to Prepare too, so that command also reads the file once. LoadStandards is internal so tests can call it.

2. Duplicated keys now resolve the same way for every key

ReadCommonParameter and the mode readers keep the last line of a key. The six separate LC-MS passes kept the first usable line: ReadAlignmentLightMode, ReadLbmAnnotatorPriority, ReadDetailedAlignmentProvenance, ReadAnnotationCandidateExport, and the MSP and Text annotator settings-file-path readers. ReadFirst is replaced by ReadLast. It keeps the last line the line reader accepts and skips blank and unusable values, which is how the main readers already behave.

Key report: MethodFileKeys now lists each key written on more than one line (compared ignoring letter case) and the value the run used, meaning the last line a reader accepted. This goes in a new repeated array in <method>.keys.json ({"key", "lines", "used"}, with used: null when no line applied) and in a console line:
Method file 'x.txt': the parameter 'Minimum peak height' is written on 2 lines; the last line applied was used: '200'.
The addition is additive, so the schema stays msdial-method-file-keys.v1.

Left out of scope:

  • Aliases of one setting (e.g. LBM annotator priority / LBM annotation priority) are not matched as the same key, because only the readers know which spellings belong together.
  • A few legacy arms (e.g. Ion mode, MS1 data type) still return "applied" for a value they ignore. For those, used can name a value that was never assigned. That is an existing inaccuracy of those arms and is not new here.

Behaviour changes for existing method files

  • Execute RT correction: False. The RT library is no longer read or checked (not even for existence), so StandardLibrary stays empty and a project saved by the console no longer carries standards for a correction that was not run. If the path is set anyway, LC-MS prints Warning: 'Compounds library file path for RT correction' is set (…) but 'Execute RT correction' is False, so the library is not used. in place of the old parser error print.
  • Execute RT correction: True. The same anchors are used. A malformed or missing library is still reported, now as RT correction library could not be used: … before the analysis files are loaded, instead of a parse-time print followed by RT correction failed after the import.
  • Non-LC-MS modes (GC-MS, DIMS, IMMS, LC-IM-MS) no longer fill StandardLibrary at all. None of them runs RT correction in the console, so only a saved project's contents change.
  • A key written twice among the six LC-MS side settings now takes the later value instead of the earlier one.
  • A blank settings-file path (MSP/Text annotator settings file path:) no longer ends the search. A real path on a later line now applies, and a blank line after a real path no longer hides it. The old code stopped at the blank line, so before this change a blank line followed by a real path gave no settings file.
  • The key record and console report gain the repeated entries and lines described above.

Tests

New tests in ConfigParserTests:

  • the side readers take the last line of a key written twice, for all six settings, and agree with the main reader;

  • a blank or unusable later line leaves the earlier value, and a blank first line no longer blocks a later path;

  • the key record and console report name repeated keys and the value used, including cases where no line applied;

  • LC-MS parsing records the RT library path without loading it;

  • for GC-MS, a relative RT library path is resolved against the method file's folder and LoadStandards loads it from there;

  • a malformed library is refused with the parser's message;

  • an LC-MS run with a malformed library stops before Loading analysis files..;

  • with RT correction off, a set library path is warned about and not read, and nothing is said when no path is set.

  • dotnet test tests/MSDIAL5/MsdialCoreTestAppTests/MsdialCoreTestAppTests.csproj: 77 passed, 0 failed

  • dotnet build tests/MSDIAL5/MsdialCoreTestApp/MsdialCoreTestApp.csproj (net472, net48, net8): succeeded, 0 errors

🤖 Generated with Claude Code

YukiMatsuzawa and others added 3 commits September 29, 2026 14:19
…ery method-file key last-wins

The console method-file reader loaded "Compounds library file path for RT
correction" the moment it read the key, from the value as written: a relative
value was opened from the working directory, and GC-MS path resolution (or the
rt-correction command's own library argument) could leave the stored library
and the stored path naming different files. The reader now records only the
path; RetentionTimeCorrectionProcess.LoadStandards is the single load, after
every rewrite.

The six settings LcmsProcess reads for itself took the FIRST usable line while
every other key takes the last. They now take the last usable line, skipping
blank and unusable values the way the main readers do. The key record gains a
"repeated" list naming each key written on more than one line and the value
the run used, and the console says the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parse-time load also served as an early format check: the library is small
and easy to get wrong, so it should fail before the raw data and annotation
libraries are read. LcmsProcess now loads it with LoadStandards right after the
method file is read, before the analysis files are imported, and hands the
anchors to Prepare, which no longer reads the file again. The rt-correction
command uses the same loader for its library argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With Execute RT correction: False the library has no effect, so LcmsProcess
neither reads nor checks it, but a path left in the method file usually means
the switch was meant to be on, so the run says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@htsugawa
htsugawa merged commit 04ef1c5 into master Sep 29, 2026
1 check passed
@htsugawa
htsugawa deleted the claude/rt-library-and-duplicate-keys branch September 29, 2026 08:26
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