Skip to content

Commit

Permalink
Merge pull request #1015 from dandi/regexfix
Browse files Browse the repository at this point in the history
Corrected regex label string
  • Loading branch information
yarikoptic authored May 18, 2022
2 parents e7784a8 + bd6ea64 commit 9ddba4c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions dandi/bids_validator_xs.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _add_subdirs(
):
"""Add appropriate subdirectories as required by entities present."""

label = "([a-z,A-Z,0-9]*?)"
label = "([a-zA-Z0-9]*?)"

regex_dirs = "/"
for dir_entity in DIR_ENTITIES:
Expand Down Expand Up @@ -247,7 +247,7 @@ def load_entities(
-----
* Couldn't find where the `label` type is defined as alphanumeric, hard-coding
`entity_definitions["subject"]["format"]`-type entries as`[a-z,A-Z,0-9]*?` for the time
`entity_definitions["subject"]["format"]`-type entries as`[a-zA-Z0-9]*?` for the time
being.
Apparently there is a `label` (alphanumeric) versus `index` (integer) specification:
https://github.com/bids-standard/bids-specification/issues/956#issuecomment-992967479
Expand All @@ -266,7 +266,7 @@ def load_entities(
A list of dictionaries, with keys including 'regex' and 'mandatory'.
"""

label = "([a-z,A-Z,0-9]*?)"
label = "([a-zA-Z0-9]*?)"

# Parsing tabular_metadata as a datatype, might be done automatically if the YAML is moved
# to the same subdirectory
Expand Down
2 changes: 1 addition & 1 deletion dandi/tests/data/expected_bids_validator_xs_write.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

SUMMARY:
0 out of 1 files were successfully validated, using the following regular expressions:
- `.*?/sub-(?P<subject>([a-z,A-Z,0-9]*?))/(|ses-(?P<session>([a-z,A-Z,0-9]*?))/)anat/sub-(?P=subject)(|_ses-(?P=session))(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))(|_ce-(?P<ceagent>([a-z,A-Z,0-9]*?)))(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))(|_run-(?P<run>([a-z,A-Z,0-9]*?)))(|_part-(?P<part>(mag|phase|real|imag)))_(T1w|T2w|PDw|T2starw|FLAIR|inplaneT1|inplaneT2|PDT2|angio|T2star)\.(nii.gz|nii|json)$`
- `.*?/sub-(?P<subject>([a-zA-Z0-9]*?))/(|ses-(?P<session>([a-zA-Z0-9]*?))/)anat/sub-(?P=subject)(|_ses-(?P=session))(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))(|_ce-(?P<ceagent>([a-zA-Z0-9]*?)))(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))(|_run-(?P<run>([a-zA-Z0-9]*?)))(|_part-(?P<part>(mag|phase|real|imag)))_(T1w|T2w|PDw|T2starw|FLAIR|inplaneT1|inplaneT2|PDT2|angio|T2star)\.(nii.gz|nii|json)$`
The following files were not matched by any regex schema entry:
* `/home/chymera/.data2/datalad/000026/rawdata/sub-EXC022/anat/sub-EXC022_ses-MRI_flip-1_VFA.nii.gz
The following mandatory regex schema entries did not match any files:
76 changes: 38 additions & 38 deletions dandi/tests/test_bids_validator_xs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test__add_entity():
regex_entities = ""
entity = "subject"
entity_shorthand = "sub"
variable_field = "([a-z,A-Z,0-9]*?)"
variable_field = "([a-zA-Z0-9]*?)"
requirement_level = "required"

_regex_entities = _add_entity(
Expand All @@ -42,13 +42,13 @@ def test__add_entity():
# Test append input and optional entity
regex_entities = (
"sub-(?P=subject)(|_ses-(?P=session))"
"(|_task-(?P<task>([a-z,A-Z,0-9]*?)))(|_trc-(?P<tracer>([a-z,A-Z,0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))"
"(|_run-(?P<run>([a-z,A-Z,0-9]*?)))"
"(|_task-(?P<task>([a-zA-Z0-9]*?)))(|_trc-(?P<tracer>([a-zA-Z0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))"
"(|_run-(?P<run>([a-zA-Z0-9]*?)))"
)
entity = "recording"
entity_shorthand = "recording"
variable_field = "([a-z,A-Z,0-9]*?)"
variable_field = "([a-zA-Z0-9]*?)"
requirement_level = "optional"

_regex_entities = _add_entity(
Expand All @@ -61,10 +61,10 @@ def test__add_entity():

assert (
_regex_entities == "sub-(?P=subject)(|_ses-(?P=session))"
"(|_task-(?P<task>([a-z,A-Z,0-9]*?)))(|_trc-(?P<tracer>([a-z,A-Z,0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))"
"(|_run-(?P<run>([a-z,A-Z,0-9]*?)))"
"(|_recording-(?P<recording>([a-z,A-Z,0-9]*?)))"
"(|_task-(?P<task>([a-zA-Z0-9]*?)))(|_trc-(?P<tracer>([a-zA-Z0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))"
"(|_run-(?P<run>([a-zA-Z0-9]*?)))"
"(|_recording-(?P<recording>([a-zA-Z0-9]*?)))"
)


Expand All @@ -74,8 +74,8 @@ def test__add_extensions():
# Test single extension
regex_string = (
"sub-(?P=subject)(|_ses-(?P=session))"
"_sample-(?P<sample>([a-z,A-Z,0-9]*?))"
"(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))_photo"
"_sample-(?P<sample>([a-zA-Z0-9]*?))"
"(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))_photo"
)
variant = {
"suffixes": ["photo"],
Expand All @@ -91,15 +91,15 @@ def test__add_extensions():

assert (
_regex_string == "sub-(?P=subject)(|_ses-(?P=session))"
"_sample-(?P<sample>([a-z,A-Z,0-9]*?))"
"(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))_photo\\.jpg"
"_sample-(?P<sample>([a-zA-Z0-9]*?))"
"(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))_photo\\.jpg"
)

# Test multiple extensions
regex_string = (
"sub-(?P=subject)(|_ses-(?P=session))"
"_sample-(?P<sample>([a-z,A-Z,0-9]*?))"
"(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))_photo"
"_sample-(?P<sample>([a-zA-Z0-9]*?))"
"(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))_photo"
)
variant = {
"suffixes": ["photo"],
Expand All @@ -115,8 +115,8 @@ def test__add_extensions():

assert (
_regex_string == "sub-(?P=subject)(|_ses-(?P=session))"
"_sample-(?P<sample>([a-z,A-Z,0-9]*?))"
"(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))"
"_sample-(?P<sample>([a-zA-Z0-9]*?))"
"(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))"
"_photo(\\.jpg|\\.png|\\.tif)"
)

Expand Down Expand Up @@ -169,7 +169,7 @@ def test__add_subdirs():
)

assert (
_regex_string == "/sub-(?P<subject>([a-z,A-Z,0-9]*?))/sub-(?P=subject)"
_regex_string == "/sub-(?P<subject>([a-zA-Z0-9]*?))/sub-(?P=subject)"
"_sessions\\.(tsv|json)"
)

Expand All @@ -196,10 +196,10 @@ def test__add_suffixes():
# Test multiple expansions
regex_entities = (
"sub-(?P=subject)(|_ses-(?P=session))"
"(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))"
"(|_dir-(?P<direction>([a-z,A-Z,0-9]*?)))(|_run-(?P<run>([a-z,A-Z,0-9]*?)))"
"(|_recording-(?P<recording>([a-z,A-Z,0-9]*?)))"
"(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))"
"(|_dir-(?P<direction>([a-zA-Z0-9]*?)))(|_run-(?P<run>([a-zA-Z0-9]*?)))"
"(|_recording-(?P<recording>([a-zA-Z0-9]*?)))"
)
variant = {
"suffixes": [
Expand All @@ -222,10 +222,10 @@ def test__add_suffixes():
}
regex_string = (
"sub-(?P=subject)(|_ses-(?P=session))"
"(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))"
"(|_dir-(?P<direction>([a-z,A-Z,0-9]*?)))(|_run-(?P<run>([a-z,A-Z,0-9]*?)))"
"(|_recording-(?P<recording>([a-z,A-Z,0-9]*?)))"
"(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))"
"(|_dir-(?P<direction>([a-zA-Z0-9]*?)))(|_run-(?P<run>([a-zA-Z0-9]*?)))"
"(|_recording-(?P<recording>([a-zA-Z0-9]*?)))"
"_(physio|stim)"
)

Expand Down Expand Up @@ -256,12 +256,12 @@ def test_write_report(tmp_path):

validation_result["schema_tracking"] = [
{
"regex": ".*?/sub-(?P<subject>([a-z,A-Z,0-9]*?))/"
"(|ses-(?P<session>([a-z,A-Z,0-9]*?))/)anat/sub-(?P=subject)"
"(|_ses-(?P=session))(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))"
"(|_ce-(?P<ceagent>([a-z,A-Z,0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))"
"(|_run-(?P<run>([a-z,A-Z,0-9]*?)))"
"regex": ".*?/sub-(?P<subject>([a-zA-Z0-9]*?))/"
"(|ses-(?P<session>([a-zA-Z0-9]*?))/)anat/sub-(?P=subject)"
"(|_ses-(?P=session))(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))"
"(|_ce-(?P<ceagent>([a-zA-Z0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))"
"(|_run-(?P<run>([a-zA-Z0-9]*?)))"
"(|_part-(?P<part>(mag|phase|real|imag)))"
"_(T1w|T2w|PDw|T2starw|FLAIR|inplaneT1|inplaneT2|PDT2|angio|T2star)"
"\\.(nii.gz|nii|json)$",
Expand All @@ -270,12 +270,12 @@ def test_write_report(tmp_path):
]
validation_result["schema_listing"] = [
{
"regex": ".*?/sub-(?P<subject>([a-z,A-Z,0-9]*?))/"
"(|ses-(?P<session>([a-z,A-Z,0-9]*?))/)anat/sub-(?P=subject)"
"(|_ses-(?P=session))(|_acq-(?P<acquisition>([a-z,A-Z,0-9]*?)))"
"(|_ce-(?P<ceagent>([a-z,A-Z,0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-z,A-Z,0-9]*?)))"
"(|_run-(?P<run>([a-z,A-Z,0-9]*?)))"
"regex": ".*?/sub-(?P<subject>([a-zA-Z0-9]*?))/"
"(|ses-(?P<session>([a-zA-Z0-9]*?))/)anat/sub-(?P=subject)"
"(|_ses-(?P=session))(|_acq-(?P<acquisition>([a-zA-Z0-9]*?)))"
"(|_ce-(?P<ceagent>([a-zA-Z0-9]*?)))"
"(|_rec-(?P<reconstruction>([a-zA-Z0-9]*?)))"
"(|_run-(?P<run>([a-zA-Z0-9]*?)))"
"(|_part-(?P<part>(mag|phase|real|imag)))"
"_(T1w|T2w|PDw|T2starw|FLAIR|inplaneT1|inplaneT2|PDT2|angio|T2star)"
"\\.(nii.gz|nii|json)$",
Expand Down

0 comments on commit 9ddba4c

Please sign in to comment.