Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/nwb2bids/_command_line_interface/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import rich_click

from .._core._convert_nwb_dataset import convert_nwb_dataset
from .._inspection._inspection_result import Severity
from .._tools._pluralize import _pluralize


# nwb2bids
Expand Down Expand Up @@ -71,11 +73,16 @@ def _run_convert_nwb_dataset(
additional_metadata_file_path=additional_metadata_file_path,
)

if messages is not None and not silent:
if messages and not silent:
text = (
f"{len(messages)} suggestion for improvement was found during conversion."
if len(messages) == 1
else f"{len(messages)} suggestions for improvement were found during conversion."
f'\n{(n := len(messages))} {_pluralize(n=n, word="suggestion")} for improvement '
f'{_pluralize(n=n, word="was", plural="were")} found during conversion.'
)
console_notification = rich_click.style(text=text, fg="yellow")
rich_click.echo(message=console_notification)

not_any_failures = not messages or not any(message.severity == Severity.ERROR for message in messages)
if not_any_failures and not silent:
text = "BIDS dataset was successfully created!"
console_notification = rich_click.style(text=text, fg="green")
rich_click.echo(message=console_notification)
7 changes: 7 additions & 0 deletions src/nwb2bids/_tools/_pluralize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def _pluralize(n: int, word: str, plural: str | None = None) -> str:
if n == 1:
return word
else:
if plural is None:
plural = word + "s"
return plural
13 changes: 7 additions & 6 deletions src/nwb2bids/bids_models/_bids_session_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ def _check_fields(self, file_paths: list[pathlib.Path] | list[pydantic.HttpUrl])
title="Invalid session ID",
reason=(
"The session ID contains invalid characters. "
"BIDS allows only dashes to be used as separators in session entity label. "
"Underscores, spaces, slashes, and special characters (including #) are expressly forbidden."
"BIDS allows only the plus sign to be used as a separator in the subject entity label. "
"Underscores, dashes, spaces, slashes, and other special characters (including #) are "
"expressly forbidden."
),
solution="Rename the session without using spaces or underscores.",
solution="Rename the session without using any special characters except for `+`.",
examples=[
"`ses_01` -> `ses-01`",
"`session #2` -> `session-2`",
"`id 2 from 9/1/25` -> `id-2-9-1-25`",
"`ses_01` -> `ses+01`",
"`session #2` -> `session+2`",
"`id 2 from 9/1/25` -> `id+2+9+1+25`",
],
field="nwbfile.session_id",
source_file_paths=file_paths,
Expand Down
2 changes: 1 addition & 1 deletion src/nwb2bids/bids_models/_model_globals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_VALID_ID_REGEX = r"^[A-Za-z0-9]+$"
_VALID_ID_REGEX = r"^[A-Za-z0-9+]+$"
_VALID_SPECIES_REGEX = r"([A-Z][a-z]* [a-z]+)|(http://purl.obolibrary.org/obo/NCBITaxon_\d+)"
_VALID_BIDS_SEXES = {
value: True
Expand Down
13 changes: 7 additions & 6 deletions src/nwb2bids/bids_models/_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ def _check_fields(self, file_paths: list[pathlib.Path] | list[pydantic.HttpUrl])
title="Invalid participant ID",
reason=(
"The participant ID contains invalid characters. "
"BIDS allows only dashes to be used as separators in subject entity label. "
"Underscores, spaces, slashes, and special characters (including #) are expressly forbidden."
"BIDS allows only the plus sign to be used as a separator in the subject entity label. "
"Underscores, dashes, spaces, slashes, and other special characters (including #) are "
"expressly forbidden."
),
solution="Rename the subject without using spaces or underscores.",
solution="Rename the subject without using any special characters except for `+`.",
examples=[
"`ab_01` -> `ab-01`",
"`subject #2` -> `subject-2`",
"`id 2 from 9/1/25` -> `id-2-9-1-25`",
"`ab_01` -> `ab+01`",
"`subject #2` -> `subject+2`",
"`id 2 from 9/1/25` -> `id+2+9+1+25`",
],
field="nwbfile.subject.subject_id",
source_file_paths=file_paths,
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def test_messages_1(problematic_nwbfile_path_1: pathlib.Path, temporary_bids_dir
nwb2bids.InspectionResult(
title="Invalid participant ID",
reason=(
"The participant ID contains invalid characters. BIDS allows only dashes to be used as separators in "
"subject entity label. Underscores, spaces, slashes, and special characters (including #) are "
"expressly forbidden."
"The participant ID contains invalid characters. BIDS allows only the plus sign to be used as a "
"separator in the subject entity label. Underscores, dashes, spaces, slashes, and other special "
"characters (including #) are expressly forbidden."
),
solution="Rename the subject without using spaces or underscores.",
examples=["`ab_01` -> `ab-01`", "`subject #2` -> `subject-2`", "`id 2 from 9/1/25` -> `id-2-9-1-25`"],
solution="Rename the subject without using any special characters except for `+`.",
examples=["`ab_01` -> `ab+01`", "`subject #2` -> `subject+2`", "`id 2 from 9/1/25` -> `id+2+9+1+25`"],
Comment on lines +41 to +46
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A follow-up PR will add a common registry for notifications to avoid the need for this ctrl+r duplication (as discussed in #103)

field="nwbfile.subject.subject_id",
source_file_paths=nwb_paths,
data_standards=[nwb2bids.DataStandard.BIDS, nwb2bids.DataStandard.DANDI],
Expand Down Expand Up @@ -112,12 +112,12 @@ def test_messages_2(problematic_nwbfile_path_2: pathlib.Path, temporary_bids_dir
nwb2bids.InspectionResult(
title="Invalid participant ID",
reason=(
"The participant ID contains invalid characters. BIDS allows only dashes to be used as separators in "
"subject entity label. Underscores, spaces, slashes, and special characters (including #) are "
"expressly forbidden."
"The participant ID contains invalid characters. BIDS allows only the plus sign to be used as a "
"separator in the subject entity label. Underscores, dashes, spaces, slashes, and other special "
"characters (including #) are expressly forbidden."
),
solution="Rename the subject without using spaces or underscores.",
examples=["`ab_01` -> `ab-01`", "`subject #2` -> `subject-2`", "`id 2 from 9/1/25` -> `id-2-9-1-25`"],
solution="Rename the subject without using any special characters except for `+`.",
examples=["`ab_01` -> `ab+01`", "`subject #2` -> `subject+2`", "`id 2 from 9/1/25` -> `id+2+9+1+25`"],
field="nwbfile.subject.subject_id",
source_file_paths=nwb_paths,
target_file_paths=None,
Expand Down