Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(regex): Construct backreferences to ensure entity consistency #1889

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

effigies
Copy link
Collaborator

The regexes currently generated by bidsschematools were overly permissive, allowing mismatches between the entities in the directory and the entities in the filename. This was caught because the Python validator moved to depending on bidsschematools, and pybids has an additional battery of checks. (See bids-standard/pybids#1080.)

I've copied the failing checks in here as well as run pybids' test using this branch of bidsschematools.

Really, we shouldn't be using regexes, but doing it right is its own challenge and this fixes a known issue. Further, this does not handle the case where you might have, e.g., ses-siteA_dwi.json that applies to one session across all subjects.

For my future reference, to properly implement inheritance in regexes, we would need:
(?:sub-(?P<subject>[0-9a-zA-Z]+)/)? # Match subject dir
(?(subject)  # If subject dir
    (?:ses-(?P<sessiondirlabel>[0-9a-zA-Z]+)/)?  # Permit session dir
    (?:(?P<datatype>dwi)/)?  # Permit datatype dir
    sub-(?P=subject)_  # Require subject entity
    (?(sessiondirlabel)  # If session dir
        ses-  # Require start of session entity
    )
| # Else
    (?P<root>ses-)?  # Permit subject entity in root directory
)
(?P<session>  # Capture session label
    (?(sessiondirlabel)  # If session directory was matched
        (?P=sessiondirlabel)  # Match session directory label
    |
        (?(root)[0-9a-zA-Z]+)  # Otherwise match any session label
    )
)
(?(sessiondirlabel)_)(?(root)_)  # Match _ if session entity
(?:acq-(?P<acquisition>[0-9a-zA-Z]+)_)?  # Match acquisition entity
# and so on
(?P<suffix>dwi)
(?P<extension>\.bvec|\.bvec|\.json)

Figuring this out was enough of a task. Programmatically generating it doesn't seem worth it right now.

@effigies effigies added schema-code Updates or changes to the code used to parse, filter, and render the schema. exclude-from-changelog This item will not feature in the automatically generated changelog labels Aug 14, 2024
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.22%. Comparing base (0e506f0) to head (e31e32a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1889      +/-   ##
==========================================
+ Coverage   88.06%   88.22%   +0.16%     
==========================================
  Files          16       16              
  Lines        1391     1393       +2     
==========================================
+ Hits         1225     1229       +4     
+ Misses        166      164       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@effigies effigies merged commit 58e236e into bids-standard:master Aug 14, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude-from-changelog This item will not feature in the automatically generated changelog schema-code Updates or changes to the code used to parse, filter, and render the schema.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants