Repository navigation
(feat,pyopenms): add XIMParquetFile pyopenms bindings - #8894
Conversation
📝 WalkthroughWalkthroughAdds Python bindings and a high-level addon for OpenMS::XIMParquetFile: C++ bindings exposing file/column/run/analyte/mobilogram access and a Python addon with DataFrame/Arrow/dict conversions, a chainable mobilogram query builder, and unit tests. Changes
Sequence DiagramsequenceDiagram
actor User
participant PyAddon as XIMParquetFile<br/>(Python addon)
participant CppBind as XIMParquetFile<br/>(C++ binding)
participant Parquet as Parquet Data<br/>Layer
participant Output as Formatter<br/>(DF/Dict/Arrow)
User->>PyAddon: query_mobilograms() / build filters
activate PyAddon
PyAddon-->>CppBind: getMobilograms(filters..., explode)
activate CppBind
CppBind->>Parquet: read/scan Parquet files
activate Parquet
Parquet-->>CppBind: mobilogram records (dict)
deactivate Parquet
CppBind-->>PyAddon: mobilogram dict/result
deactivate CppBind
PyAddon->>Output: convert to DataFrame/Arrow/dict
activate Output
Output-->>PyAddon: formatted result
deactivate Output
PyAddon-->>User: return result
deactivate PyAddon
Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pyOpenMS/bindings/bind_format.cpp`:
- Around line 2181-2201: The loop currently iterates using c.mobility.size() but
then accesses c.intensity[j], risking OOB if the vectors differ; change the
iteration to use a safe size (e.g., size_t n = std::min(c.mobility.size(),
c.intensity.size())) and loop j from 0 to n, or explicitly check that
c.mobility.size() == c.intensity.size() before the loop and handle the mismatch
(skip, truncate, or log/error) so accesses to c.mobility[j] and c.intensity[j]
are always in-bounds; update the loop around the block that appends into
run_id_list, mobility_list, intensity_list accordingly (referencing c.mobility,
c.intensity and the for loop using j).
In `@src/pyOpenMS/pyopenms/addons/ximparquetfile.py`:
- Around line 20-25: The _add_filter function currently builds IN-list filters
by joining raw str(v) which breaks for string elements and doesn't escape
quotes; update _add_filter to detect string elements and wrap them in quoted,
escaped form (e.g., replace any internal quote characters or use a safe quoting
routine) before joining so the produced "column IN ('a','b')" is valid; apply
the same quoting/escaping logic to the other filter-construction code referenced
around the same region (the similar filter-building block at lines 46-59) so all
list/tuple values are consistently quoted and escaped.
- Around line 81-84: The __len__ implementation currently swallows all
exceptions by using a bare "except Exception:" around self.getFilenames(), which
hides real errors; update the __len__ method in ximparquetfile.py (and mirror
change in xicparquetfile.py) to either remove the try/except so exceptions
propagate, or catch only the expected exceptions (e.g., AttributeError,
TypeError, or the library-specific exception raised by getFilenames()) and
re-raise or return 0 only for those specific cases; ensure you reference the
method name __len__ and the call self.getFilenames() when making the change so
the behavior is explicit and unexpected errors are not silently swallowed.
- Around line 101-103: The parameter name "filter" in get_data_dict shadows a
Python builtin; rename it to "filter_expr" in the function signature of
get_data_dict, update every reference inside the function body (including any
use in conditionals or variable access), update the docstring parameter
description to use "filter_expr", and update any calls to get_data_dict within
this module that pass the old "filter" keyword to use "filter_expr" instead so
all references to the old name are replaced consistently.
In `@src/pyOpenMS/tests/unittests/test_XIMParquetFile.py`:
- Around line 93-109: The test assumes the first precursor_id from
xim.get_analyte_dict(columns=["PRECURSOR_ID"], nest_transitions=False) is
non-null; change the test_xim_query_builder (and the earlier test usage) to
select the first non-null precursor_id instead of blindly using
analytes["precursor_id"][0] so the test isn't flaky. Locate usages of
get_analyte_dict and replace the direct index access with logic that filters out
None/NaN values (e.g., iterate or use a comprehension to find the first valid
value) before passing it into xim.query_mobilograms().filter_precursor_id(...).
Ensure the same change is applied in both the initial assertions block and
test_xim_query_builder referencing precursor_id.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: baa1c58d-949e-44c6-95dc-489552631f60
📒 Files selected for processing (3)
src/pyOpenMS/bindings/bind_format.cppsrc/pyOpenMS/pyopenms/addons/ximparquetfile.pysrc/pyOpenMS/tests/unittests/test_XIMParquetFile.py
…am data from Parquet files
…ting and consistency
…nd improve readability
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pyOpenMS/pyopenms/addons/ximparquetfile.py`:
- Around line 117-171: The get_data_dict function accepts **kwargs but silently
ignores them; update get_data_dict to handle legacy/alias kwargs (e.g.,
'filter') or fail loudly: check if 'filter' is present in kwargs and, if so, pop
it and assign to filter_expr before calling self.getMobilograms; after handling
known aliases, if kwargs is not empty raise a TypeError listing unexpected
kwargs so callers are not silently ignored. Ensure you reference get_data_dict,
the filter_expr variable, and the call to
self.getMobilograms(filter=filter_expr, ...) when making the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2ad38fed-acc1-442c-937b-91ba1a35178e
📒 Files selected for processing (4)
CHANGELOGsrc/pyOpenMS/bindings/bind_format.cppsrc/pyOpenMS/pyopenms/addons/ximparquetfile.pysrc/pyOpenMS/tests/unittests/test_XIMParquetFile.py
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG
| filter_expr="", | ||
| **kwargs, | ||
| ): | ||
| """ | ||
| Return mobilogram data as a dict. | ||
|
|
||
| If explode=True, returns long format with mobility/intensity rows. | ||
| Otherwise, mobility and intensity are stored as lists. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| explode : bool | ||
| If True, return long format with one row per mobility/intensity. | ||
| precursor_id : int | ||
| Optional precursor id (-1 to ignore). | ||
| transition_id : int | ||
| Optional transition id (-1 to ignore). | ||
| modified_sequence : str | ||
| Optional modified sequence filter (empty to ignore). | ||
| precursor_charge : int | ||
| Optional precursor charge filter (-1 to ignore). | ||
| product_charge : int | ||
| Optional product charge filter (-1 to ignore). | ||
| ms_level : int | ||
| Optional MS level filter (-1 to ignore). | ||
| run_id : int | ||
| Optional run id filter (-1 to ignore). | ||
| mobilogram_type : str | ||
| Optional mobilogram type filter (empty to ignore). | ||
| feature_id : int | ||
| Optional feature id filter (-1 to ignore). | ||
| feature_rt : float | ||
| Optional feature RT filter (<0 to ignore). | ||
| filter_expr : str | ||
| Optional filter expression string. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| Dict of lists keyed by column name. | ||
| """ | ||
| return self.getMobilograms( | ||
| precursor_id=precursor_id, | ||
| transition_id=transition_id, | ||
| modified_sequence=modified_sequence, | ||
| precursor_charge=precursor_charge, | ||
| product_charge=product_charge, | ||
| ms_level=ms_level, | ||
| run_id=run_id, | ||
| mobilogram_type=mobilogram_type, | ||
| feature_id=feature_id, | ||
| feature_rt=feature_rt, | ||
| filter=filter_expr, | ||
| explode=explode, | ||
| ) |
There was a problem hiding this comment.
Handle legacy/unknown kwargs explicitly in get_data_dict.
At Line 118, **kwargs is accepted but never used. Calls like get_data_dict(filter="...") will silently drop the filter and return unfiltered results.
🔧 Proposed fix
def get_data_dict(
@@
feature_rt=-1.0,
filter_expr="",
**kwargs,
):
@@
+ # Backward compatibility with older keyword name used in related APIs.
+ if "filter" in kwargs:
+ if filter_expr:
+ raise TypeError("Use only one of 'filter_expr' or 'filter'.")
+ filter_expr = kwargs.pop("filter")
+
+ if kwargs:
+ unexpected = ", ".join(sorted(kwargs.keys()))
+ raise TypeError(f"Unexpected keyword argument(s): {unexpected}")
+
return self.getMobilograms(
@@
filter=filter_expr,
explode=explode,
)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/pyOpenMS/pyopenms/addons/ximparquetfile.py` around lines 117 - 171, The
get_data_dict function accepts **kwargs but silently ignores them; update
get_data_dict to handle legacy/alias kwargs (e.g., 'filter') or fail loudly:
check if 'filter' is present in kwargs and, if so, pop it and assign to
filter_expr before calling self.getMobilograms; after handling known aliases, if
kwargs is not empty raise a TypeError listing unexpected kwargs so callers are
not silently ignored. Ensure you reference get_data_dict, the filter_expr
variable, and the call to self.getMobilograms(filter=filter_expr, ...) when
making the change.
Description
Added python bindings fir the extracted ion mobilogram parquet files introduced in PR #8871. The bindings are pretty much the same as the XIC parquet fles python bindings.
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 buildsSummary by CodeRabbit
New Features
Tests