Repository navigation
Add BidsComponent.get() for runtime file path retrieval with BIDS special wildcard support - #490
Conversation
BidsComponent.get() for runtime file path retrieval with optional entity support
fbaf03b to
e9aa093
Compare
|
@copilot, please try again, going over all currently unresolved comments |
6296463 to
c242819
Compare
|
@copilot, please review the changes and update the PR message as necessary for accuracy |
I've reviewed the current implementation. The code is fully functional and uses Core Implementation:
Key Features:
Testing:
The implementation is complete and all unresolved comment threads from previous reviews have been addressed in commit c242819. |
BidsComponent.get() for runtime file path retrieval with optional entity supportBidsComponent.get() for runtime file path retrieval with BIDS special wildcard support
There was a problem hiding this comment.
Pull request overview
This pull request adds a get() method to the BidsComponent class for retrieving file paths at runtime based on entity values. The method supports optional entities through a combination of regular entities and dummy wildcards, enabling robust support for datasets with optional BIDS entities. The implementation uses Python's Formatter class through the custom SnakemakeFormatter to substitute path templates, and includes comprehensive error handling for various edge cases.
Changes:
- Added
BidsComponent.get()method for file path retrieval with entity matching - Added private
_contains()helper method for efficient entity subset matching - Added
MissingEntityErrorcustom exception for clearer error reporting - Added comprehensive test suite with property-based testing using Hypothesis
- Added benchmark tests for performance validation of the
_containsmethod
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/snakebids/core/datasets.py | Added get() method to BidsComponent and _contains() helper method to BidsPartialComponent for entity matching and path retrieval |
| src/snakebids/utils/snakemake_templates.py | Added MissingEntityError exception class for handling missing entity errors in formatter |
| tests/test_datasets.py | Added comprehensive test suite TestBidsComponentGet with parametrized tests, and benchmark class TestBenchmarkContains for performance testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1e5a604 to
469fed4
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #490 +/- ##
==========================================
+ Coverage 95.26% 95.35% +0.09%
==========================================
Files 56 56
Lines 2492 2543 +51
==========================================
+ Hits 2374 2425 +51
Misses 118 118 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a550e35 to
e42a824
Compare
Returns path associated with the provided query, if found, errors otherwise. Special wildcards given in the query are ignored from querying, but used for formatting the template if a match is found
e42a824 to
cdc0f89
Compare
Adds a
getmethod toBidsComponentfor retrieving file paths at runtime based on entity values, enabling robust support for datasets with optional entities and BIDS special wildcards. This replaces direct path template manipulation in workflows.Changes
Core Method
BidsComponent.get(query=None, /, **entities): Returns single file path matching provided entities"") as blank/absent values in formattingSnakemakeFormatterfor proper wildcard handling and path template substitutionBIDS Special Wildcard Support
___(underscore wildcard): Passes through any value__d__(slash/datatype wildcard): Handles datatype formatting with slash suppression_TAG_(dummy wildcards): Represents optional entity tags (e.g.,_acq_,_run_)_TAG_d_(directory wildcards): Handles directory path components (e.g.,_subject_d_,_session_d_)Implementation Details
SnakemakeFormatterfor proper BIDS wildcard formatting_contains()method for efficient entity matching via set intersectionError Handling
TypeError: Bothqueryand**entitiesprovidedKeyError: Queried entity not in componentValueError: Invalid entity value, unqueried entities, or special wildcard without associated entityPerformance
_containsvsfiltermethods for entity matchingExample
Testing
Comprehensive test suite using property-based testing with Hypothesis:
test_get_returns_str_path: Validates correct path retrieval matches.expand()outputtest_error_when_unknown_special_wildcard: Ensures special wildcards require associated entitiestest_allow_associated_special_wildcards: Confirms special wildcards work when entity existstest_slash_wildcard_when_datatype_present: Tests__d__wildcard handlingtest_underscore_wildcard_permitted: Validates___wildcard supporttest_special_wildcards_passed_through: Verifies special wildcards are properly formattedTestBenchmarkContains) comparing performance of matching methodsOriginal prompt
This section details on the original issue you should resolve
<issue_title>Create method on
BidsComponentfor retrieval of input files with optional entity handling</issue_title><issue_description>Implement a new method on the
BidsComponentclass to retrieve input file paths based on a set of entity values, while handling optional entities. Optional entities shall appear in two manifestations:Nonevalue: This indicates the entity is absent._acq_) represent the tag portion of the path and are ignored when a corresponding entity (e.g. acq) is specified as absent.This new method (
get) will replace direct template usage in workflows, enabling robust support for datasets with optional entities.Details
The
getmethod will allow runtime retrieval of input files by leveraging thewildcardsargument provided by Snakemake. Its behavior must satisfy the following requirements:Requirements
Noneshall be interpreted as absent. Corresponding dummy wildcards (e.g.,_acq_) shall be ignored unless another constraint applies.Noneor a blank string. Otherwise, the method shall trigger an error.Implementation
Add the following method to the
BidsComponentclass:In the initial implementation,
TypeError,ValueError, andKeyErrorwill be used to handle input validation and errors. These will eventually be refactored into custom Snakebids errors alongside thefiltermethod.Tasks
getmethod as outlined above within theBidsComponentclass.queryand**entities).test_error_on_both_query_and_entitiesshould be parameterized to test both thequeryand**entitiesforms of the function call.):test_get_returns_str_path: Ensure a valid string path is returned.test_dummy_wildcards_ignored_if_entity_absent: Check that dummy wildcards are ignored when the corresponding entity is absent.test_error_on_both_query_and_entities: Test that using bothqueryand**entitiesraises aTypeError.test_error_on_missing_entity_in_component: Test that querying an entity not present in the component raises aKeyError.test_error_on_entity_value_absent_in_component: Verify that querying an entity value not present in the component raises aValueError.test_error_on_unqueried_entities_in_component: Test that missing queries for all entities in the component raises a `Value...BidsComponentfor retrieval of input files with optional entity handling #488💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.