Skip to content

Commit

Permalink
update docs, rename validation fn
Browse files Browse the repository at this point in the history
- update docs to include information about skipping bids validation
- renamed function from validate_input_dir -> validate_bids_dir
- added exception to skipping bids-validation with node if all paths
  provided are custom
- quality fixes
  • Loading branch information
kaitj committed Mar 10, 2023
1 parent 9ccfd1a commit 430f28a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/bids_app/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ To get access to these additions, the base Snakefile for a snakebids workflow sh
inputs = snakebids.generate_inputs(
bids_dir=config["bids_dir"],
pybids_inputs=config["pybids_inputs"],
skip_bids_validation=config["skip_bids_validation"],
derivatives=config.get("derivatives", None),
participant_label=config.get("participant_label", None),
exclude_participant_label=config.get("exclude_participant_label", None)

)

#this adds constraints to the bids naming
Expand Down
2 changes: 2 additions & 0 deletions docs/running_snakebids/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Indexing of large datasets can be a time-consuming process. Snakebids, through `
1. Uncomment the lines in `snakebids.yml` containing `pybids_db_dir` and `pybids_db_reset`.
1. The variables can be updated directly in this file or through the CLI by using `-pybidsdb-dir {dir}` to specify the database path and `--reset-db` to indicate that the database should be updated. _Note: CLI arguments take precendence if both CLI and config variables are set._

Input BIDS datasets are also validated via the bids-validator. By default, this feature uses the command-line (node.js) version of the [validator](https://www.npmjs.com/package/bids-validator). If this is not found to be installed on the system, the `pybids` version of validation will be performed instead. To opt-out validation, one can invoke `--skip-bids-validation`.

Workflow mode
=============

Expand Down
19 changes: 11 additions & 8 deletions snakebids/core/input_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def generate_inputs(
be specified if participant_label is specified
skip_bids_validation : bool, optional
If True, will not perform validation of the input dataset. Otherwise,
If True, will not perform validation of the input dataset. Otherwise,
validation is first attempted by performing a system call to `bids-validator`
(e.g. node version), which is has more comprehensive coverage, before falling
back on the python version of the validator.
(e.g. node version), which is has more comprehensive coverage, before falling
back on the python version of the validator.
use_bids_inputs : bool, optional
If True, opts in to the new :class:`BidsDataset` output, otherwise returns the
Expand Down Expand Up @@ -268,12 +268,15 @@ def generate_inputs(
participant_label, exclude_participant_label
)

# Attempt to validate with node bids-validator, if needed
validated = _validate_input_dir if not skip_bids_validation else None
# Attempt to validate with node bids-validator
validated = (
_validate_bids_dir
if not skip_bids_validation and not _all_custom_paths(pybids_inputs)
else None
)

# Generates a BIDSLayout
# If not skipping validation, set validate indicator to opposite of output
# from _validate_input_dir, otherwise do not validate
# from _validate_bids_dir, otherwise do not validate
layout = (
_gen_bids_layout(
bids_dir=bids_dir,
Expand Down Expand Up @@ -390,7 +393,7 @@ def _gen_bids_layout(
)


def _validate_input_dir(
def _validate_bids_dir(
bids_dir: Union[Path, str],
) -> bool:
"""Perform validation of dataset. Initial attempt at validation performed
Expand Down
4 changes: 2 additions & 2 deletions snakebids/tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
_generate_filters,
_get_lists_from_bids,
_parse_custom_path,
_validate_input_dir,
_validate_bids_dir,
generate_inputs,
)
from snakebids.exceptions import ConfigError, PybidsError
Expand Down Expand Up @@ -1004,7 +1004,7 @@ def start(self, tmpdir):

def test_check_validator(self):
"""Test validator defaults to pybids (i.e. False)"""
assert _validate_input_dir(self.bids_dir) == False
assert _validate_bids_dir(self.bids_dir) == False

def test_pybids_validation_fail(self):
with pytest.raises(BIDSValidationError):
Expand Down

0 comments on commit 430f28a

Please sign in to comment.