Repository navigation
BugFix : Fixed Targetedfileconverter crash - #7924
Conversation
WalkthroughThe pull request adjusts the header validation in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TransitionTSVFile
Client->>TransitionTSVFile: Call getTSVHeader_(TSV input)
TransitionTSVFile->>TransitionTSVFile: Parse header fields
alt Header field count >= 4
TransitionTSVFile->>Client: Return parsed header
else
TransitionTSVFile->>Client: Trigger error handling
end
Assessment against linked issues
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
cbielow
left a comment
There was a problem hiding this comment.
you found the correct place.
But the fix needs more thought
| std::vector<std::string> header; | ||
| int nr_delimiters = 3; | ||
| Size min_header_size = 8; | ||
| Size min_header_size = 1; |
There was a problem hiding this comment.
not ideal IMHO.
If you have a header which contains commata in a column name, then comma will be preferred.
If the min_header_size is large, this is somewhat robust, but using 1, this cries for errors,
Think of a more robust strategy, also look at the header, what is minimally expected. Its more than 1 column!
There was a problem hiding this comment.
Right, I'm looking into this
There was a problem hiding this comment.
@cbielow So I read the documentation and these are columns that are required (at minimum). So I can:
- Set the
min_header_sizeto 4 - Reverse the possible delimiters order from
const char possibleDelimiters[3] = {',', ';', '\t'};toconst char possibleDelimiters[3] = {'\t', ';', ','};so that tabs get preference and even if headers have,inside their name the headers will get parsed on the basis oftabs. - And since these header names are
*required.... I can also put in a check that after parsing these 4 should be found individually
Do you think the approach looks good? Then I can make the relevant change
| Header Name | Type | Description |
|---|---|---|
| PrecursorMz* | float | This describes the precursor ion m/z |
| ProductMz* | float; synonyms: FragmentMz | This specifies the product ion m/z |
| LibraryIntensity* | float; synonyms: RelativeFragmentIntensity | This specifies the relative intensity of the fragment ion |
| NormalizedRetentionTime* | float; synonyms: RetentionTime, Tr_recalibrated, iRT, RetentionTimeCalculatorScore | This specifies the expected retention time (normalized retention time) |
There was a problem hiding this comment.
yes, good strat!
Go for it.
There was a problem hiding this comment.
if you want, also replace const char possibleDelimiters[3] with const std::array<char, 3> possible_delimiters;, which would enable easier iteration and avoid repeating '3' etc.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp (1)
171-190: Header validation is comprehensive but might be too strictThe new validation ensures required headers are present, which is good. However, the current implementation marks
valid_headersas false if ANY header doesn't match the predefined list. This could reject files with valid custom columns that aren't in the standard list.Looking at the code in lines 282-317, the system already handles column synonyms (e.g., "ProductMz" or "FragmentMz"). Consider only validating the presence of the four required columns mentioned in the error message rather than all columns.
-bool valid_headers = true; -for (Size i = 0; i < header.size(); i++) -{ - header_dict[header[i]] = i; - bool valid_header = false; - for (auto header_name : header_names_) { - if (header_name == header[i]) { - valid_header = true; - } - } - - if (!valid_header) { - valid_headers = false; - } -} - -if (!valid_headers) { +// Add columns to header dictionary +for (Size i = 0; i < header.size(); i++) +{ + header_dict[header[i]] = i; +} + +// Check if required columns are present +bool has_precursor_mz = header_dict.find("PrecursorMz") != header_dict.end(); +bool has_product_mz = header_dict.find("ProductMz") != header_dict.end() || + header_dict.find("FragmentMz") != header_dict.end(); +bool has_library_intensity = header_dict.find("LibraryIntensity") != header_dict.end() || + header_dict.find("RelativeIntensity") != header_dict.end() || + header_dict.find("RelativeFragmentIntensity") != header_dict.end(); +bool has_retention_time = header_dict.find("RetentionTimeCalculatorScore") != header_dict.end() || + header_dict.find("iRT") != header_dict.end() || + header_dict.find("NormalizedRetentionTime") != header_dict.end() || + header_dict.find("RetentionTime") != header_dict.end() || + header_dict.find("Tr_recalibrated") != header_dict.end() || + header_dict.find("SpectraSTRetentionTime") != header_dict.end(); + +if (!has_precursor_mz || !has_product_mz || !has_library_intensity || !has_retention_time) { throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "The provided TSV/CSV file is missing one or more required header columns. Please ensure it includes: PrecursorMz, ProductMz (or FragmentMz), LibraryIntensity (or RelativeFragmentIntensity), and NormalizedRetentionTime (or its synonyms)."); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp(2 hunks)
🔇 Additional comments (2)
src/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp (2)
149-150: Good improvements to header parsing configuration!The changes to reduce
min_header_sizefrom 8 to 4 columns and switch tostd::arraywith tab-first delimiter preference address the crash in TargetedFileConverter, following the agreed approach in previous discussions. This improvement makes the code more resilient when handling files with fewer columns.
152-157: Improved code readability with modern C++ constructsThe range-based for loop replacing the index-based iteration is more readable and less error-prone.
|
@cbielow, kindly check if the PR is good to go |
| bool valid_headers = true; | ||
| for (Size i = 0; i < header.size(); i++) | ||
| { | ||
| header_dict[header[i]] = i; | ||
| bool valid_header = false; | ||
| for (auto header_name : header_names_) { | ||
| if (header_name == header[i]) { | ||
| valid_header = true; | ||
| } | ||
| } | ||
|
|
||
| if (!valid_header) { | ||
| valid_headers = false; | ||
| } | ||
| } | ||
|
|
||
| if (!valid_headers) { | ||
| throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, | ||
| "The provided TSV/CSV file is missing one or more required header columns. Please ensure it includes: PrecursorMz, ProductMz (or FragmentMz), LibraryIntensity (or RelativeFragmentIntensity), and NormalizedRetentionTime (or its synonyms)."); | ||
| } | ||
|
|
There was a problem hiding this comment.
looking at the code, this is not needed after all, since this is checked here
for the four required headers.
There was a problem hiding this comment.
I've dropped this additional check
cbielow
left a comment
There was a problem hiding this comment.
good to go,
Please remove the second part of the new code which deals with headers (its duplicating functionality already present)
| int nr_delimiters = 3; | ||
| Size min_header_size = 8; | ||
| const char possibleDelimiters[3] = {',', ';', '\t'}; | ||
| Size min_header_size = 4; | ||
| const std::array<char, 3> possible_delimiters = {'\t', ';', ','}; | ||
|
|
||
| for (int i = 0; i < nr_delimiters; i++) | ||
| for (auto possible_delimiter : possible_delimiters) | ||
| { | ||
| header.clear(); | ||
| std::stringstream lineStream(line); | ||
| delimiter = possibleDelimiters[i]; | ||
| delimiter = possible_delimiter; |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp (1)
175-175: Why is this line change necessary?This empty line change appears to be unrelated to the PR's objective. If it was added unintentionally, consider removing it to maintain a cleaner diff.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp(2 hunks)
🔇 Additional comments (2)
src/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp (2)
149-151: Improved header parsing robustnessThe code now requires a minimum of 4 header fields (matching the documented requirements) instead of 8, and uses a properly ordered array of delimiters that prioritizes tabs. This will fix the
TargetedFileConvertercrash when processing TSV files with fewer than 8 columns, while still ensuring the minimum required fields are present.
152-157: Good C++ modernizationThe switch to range-based for loop with
std::arrayimproves code readability and follows modern C++ best practices, as suggested in the review comments.
I've removed, thanks for the review |
|
@cbielow can you re-run the checks for this PR, they got stopped after the merge of branch |


User description
Description
fixes #7923
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsPR Type
Bug fix
Description
Fixed crash in
TargetedFileConverterwhen input TSV has fewer than 8 columns.Adjusted minimum header size requirement from 8 to 1 in
TransitionTSVFile.Changes walkthrough 📝
TransitionTSVFile.cpp
Adjusted minimum header size in TransitionTSVFilesrc/openms/source/ANALYSIS/OPENSWATH/TransitionTSVFile.cpp
Summary by CodeRabbit