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

Use BIDS schema in CuBIDS #392

Merged
merged 23 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
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
49 changes: 48 additions & 1 deletion cubids/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _parse_validate():
allow_abbrev=False,
)
PathExists = partial(_path_exists, parser=parser)
IsFile = partial(_is_file, parser=parser)

parser.add_argument(
"bids_dir",
Expand Down Expand Up @@ -177,6 +178,17 @@ def _parse_validate():
help="Lets user run a locally installed BIDS validator. Default is set to False ",
required=False,
)
parser.add_argument(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great idea. Note to future self: add section to docs that show where to get these files and suggest that users grab a copy at the start of a project.

"--schema",
type=IsFile,
action="store",
default=None,
help=(
"Path to a BIDS schema JSON file. "
"Default is None, which uses the latest schema available to the validator."
),
required=False,
)
return parser


Expand Down Expand Up @@ -243,6 +255,7 @@ def _parse_bids_version():
allow_abbrev=False,
)
PathExists = partial(_path_exists, parser=parser)
IsFile = partial(_is_file, parser=parser)

parser.add_argument(
"bids_dir",
Expand All @@ -263,6 +276,17 @@ def _parse_bids_version():
"By default, `cubids bids-version /bids/path` prints to the terminal."
),
)
parser.add_argument(
"--schema",
type=IsFile,
action="store",
default=None,
help=(
"Path to a BIDS schema JSON file. "
"Default is None, which uses the latest schema available to the validator."
),
required=False,
)
return parser


Expand Down Expand Up @@ -412,6 +436,7 @@ def _parse_group():
allow_abbrev=False,
)
PathExists = partial(_path_exists, parser=parser)
IsFile = partial(_is_file, parser=parser)

parser.add_argument(
"bids_dir",
Expand Down Expand Up @@ -446,13 +471,24 @@ def _parse_group():
parser.add_argument(
"--config",
action="store",
type=PathExists,
type=IsFile,
default=None,
help=(
"Path to a config file for grouping. "
"If not provided, then the default config file from CuBIDS will be used."
),
)
parser.add_argument(
"--schema",
type=IsFile,
action="store",
default=None,
help=(
"Path to a BIDS schema JSON file. "
"Default is None, which uses the latest schema available to the validator."
),
required=False,
)
return parser


Expand Down Expand Up @@ -601,6 +637,17 @@ def _parse_apply():
"If not provided, then the default config file from CuBIDS will be used."
),
)
parser.add_argument(
"--schema",
type=IsFile,
action="store",
default=None,
help=(
"Path to a BIDS schema JSON file. "
"Default is None, which uses the latest schema available to the validator."
),
required=False,
)

return parser

Expand Down
29 changes: 29 additions & 0 deletions cubids/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,32 @@ def load_config(config_file):
config = yaml.safe_load(f)

return config


def load_schema(schema_file):
"""Load a JSON file containing the BIDS schema.

Parameters
----------
schema_file : str or pathlib.Path, optional
The path to the schema file. If None, the default schema file is used.

Returns
-------
dict
The schema loaded from the YAML file.
"""
import json

if schema_file is None:
schema_file = Path(importlib.resources.files("cubids") / "data/schema.json")

with schema_file.open() as f:
schema = json.load(f)

print(
f"Loading BIDS schema version: {schema['schema_version']}. "
f"BIDS version: {schema['bids_version']}"
)

return schema
Loading