Package: bids-validator
BIDS-ValidatorBIDS-ValidatorQuickstartSupportMaintainers and ContributorsUseAPI.bidsignoreConfigurationIn the BrowserOn the ServerThrough Command LineDocker imagePython LibraryExampleDevelopmentRunning Locally in a BrowserTestingPublishingAcknowledgmentsQuickstartWeb version:OpenGoogle ChromeorMozilla Firefox(currently the only
supported browsers)Go tohttps://bids-standard.github.io/bids-validator/and select a folder
with your BIDS dataset. If the validator seems to be working longer than
couple of minutes please opendeveloper toolsand report the error athttps://github.com/bids-standard/bids-validator/issues.Command line version:InstallNode.js(at least version 18.0.0)Updatenpmto be at least version 7 (npm install --global npm@^7)From a terminal runnpm install -g bids-validatorRunbids-validatorto start validating datasets.DockerInstall DockerFrom a terminal rundocker run -ti --rm -v /path/to/data:/data:ro bids/validator /databut replace the/path/to/datapart of the command with your own path on your machine.Python Library:InstallPythonInstallPippackage manager for Python, if
not already installed.From a terminal runpip install bids_validatorto acquire theBIDS Validator PyPI packageorconda install bids-validatorfor theConda package.Open a Python terminal and type:pythonImport the BIDS Validator packagefrom bids_validator import BIDSValidatorCheck if a file is BIDS compatibleBIDSValidator().is_bids('/relative/path/to/a/bids/file')Note, the file path must be relative to the root of the BIDS dataset, and
a leading forward slash/must be added to the file path.SupportThe BIDS Validator is designed to work in both the browser and in Node.js. We
target support for the latest long term stable (LTS) release of Node.js and the
latest version of Chrome.There is also a library of helper functions written in Python, for use with BIDS
compliant applications written in this language.Please report any issues you experience while using these support targets via
theGitHub issue tracker.
If you experience issues outside of these supported environments and believe we
should extend our targeted support feel free to open a new issue describing the
issue, your support target and why you require extended support and we will
address these issues on a case by case basis.Maintainers and ContributorsThis project follows theall-contributorsspecification.
Contributions of any kind are welcome!The project is maintained by@rwblairwith the help of many contributors listed below.
(Theemoji keyis indicating the kind of contribution)Please also seeAcknowledgments.Adam Li💻⚠️📓🐛Adam Thomas📖Alexander Jones💻⚠️🤔Ben Beasley📦Chris Gorgolewski🐛💻🔣📖💡🤔🚇🚧🧑‍🏫💬👀⚠️✅📢📓Chris Holdgraf💻Chris Markiewicz💻⚠️🤔🐛💬🔧🚧David Nishikawa💻⚠️Dimitri Papadopoulos Orfanos💻Duncan Macleod🚇Franklin Feingold📖Gregory noack💻⚠️Horea Christian💻Jakub Kaczmarzyk🚇Joke Durnez💻Mainak Jas💻⚠️🤔👀📓Marco Castellaro💻⚠️Max💻🐛Michael Hanke📖Mikael Naveau💻Nell Hardcastle💻🤔🚇💬👀Nicolas Traut💻Parul Sethi💻⚠️Patricia Clement💻Remi Gau💻📖📓Richard Höchenberger💻📓⚠️🐛Robert Oostenveld💻🤔🐛⚠️Rohan Goyal💻Ross Blair🚧🤔💻🐛🚇📆💬👀🔧⚠️Russ Poldrack💻💵🔍Soichi Hayashi🐛Stefan Appelhoff🐛💻🔣📖💡🤔🚇🚧🧑‍🏫💬👀⚠️✅📢📓Suyash💻Taylor Salo💻Teal Hobson-Lowther💻⚠️Travis Riddle🐛VisLab🤔💻Wazeer Zulfikar📖Yaroslav Halchenko🤔💻📖📓constellates💻⚠️dewarrn1💻dkp💻goldmund💻⚠️UseAPIThe BIDS Validator has one primary method that takes a directory as either a
path to the directory (node) or the object given by selecting a directory with a
file input (browser), an options object, and a callback.Available options include:ignoreWarnings - (boolean - defaults to false)ignoreNiftiHeaders - (boolean - defaults to false)For example:validate.BIDS(directory, {ignoreWarnings: true}, function (issues, summary) {console.log(issues.errors, issues.warnings);});If you would like to test individual files you can use the file specific checks
that we expose.validate.BIDS()validate.JSON()validate.TSV()validate.NIFTI()Additionally you can reformat stored errors against a new config usingvalidate.reformat().bidsignoreOptionally one can include a.bidsignorefile in the root of the dataset. This
file lists patterns (compatible with the.gitignore syntax)
defining files that should be ignored by the validator. This option is useful
when the validated dataset includes file types not yet supported by BIDS
specification.*_not_bids.txt
extra_data/ConfigurationYou can configure the severity of errors by passing a json configuration file
with a-cor--configflag to the command line interface or by defining a
config object on the options object passed during javascript usage.If no path is specified a default path of.bids-validator-config.jsonwill be used. You can add this file to your dataset to share dataset specific validation configuration. To disable this behavior use--no-configand the default configuration will be used.The basic configuration format is outlined below. All configuration is optional.{"ignore":[],"warn":[],"error":[],"ignoredFiles":[]}ignoredFilestakes a list of file paths or glob patterns you'd like to ignore.
Lets say we want to ignore all files and sub-directory under/derivatives/.This is not the same syntax as used in the .bidsignore file{"ignoredFiles":["/derivatives/**"]}Note that adding two stars**in path makes validator recognize all files and
sub-dir to be ignored.ignore,warn, anderrortake lists of issue codes or issue keys and change
the severity of those issues so they are either ignored or reported as warnings
or errors. You can find a list of all available issues atutils/issues/list.Some issues may be ignored by default, but can be elevated to warnings or errors.
These provide a way to check for common things that are more specific than BIDS
compatibility. An example is a check for the presence of a T1w modality. The
following would raise an error if no T1W image was found in a dataset.{"error":["NO_T1W"]}In addition to issue codes and keys these lists can also contain objects with
and "and" or "or" properties set to arrays of codes or keys. These allow some
level of conditional logic when configuring issues. For example:{"ignore":[{"and":["ECHO_TIME_GREATER_THAN","ECHO_TIME_NOT_DEFINED"]}]}In the above example the two issues will only be ignored if both of them are
triggered during validation.{"ignore":[{"and":["ECHO_TIME_GREATER_THAN","ECHO_TIME_NOT_DEFINED"{"or":["ECHO_TIME1-2_NOT_DEFINED","ECHO_TIME_MUST_DEFINE"]}]}]}And in this example the listed issues will only be ignored ifECHO_TIME_GREATER_THAN,ECHO_TIME_NOT_DEFINEDand eitherECHO_TIME1-2_NOT_DEFINEDorECHO_TIME_MUST_DEFINEare triggered during
validation."or" arrays are not supported at the lowest level because it wouldn't add any
functionality. For example the following is not supported.{"ignore":[{"or":["ECHO_TIME_GREATER_THAN","ECHO_TIME_NOT_DEFINED"]}]}because it would be functionally the same as this:{"ignore":["ECHO_TIME_GREATER_THAN","ECHO_TIME_NOT_DEFINED"]}For passing a configuration while using the bids-validator on the command line,
you can use the following style to for example ignore empty
file errors (99) and files that cannot be read (44):bids-validator --config.ignore=99 --config.ignore=44 path/to/bids/dirThis style of use puts limits on what configuration you can require, so for
complex scenarios, we advise users to create a dedicated configuration file with
contents as described above.In the BrowserThe BIDS Validator currently works in the browser withbrowserifyorwebpack. You can add it to a project by cloning
the validator and requiring it with browserify syntaxconst validate = require('bids-validator');or an ES2015 webpack importimport validate from 'bids-validator'.On the ServerThe BIDS validator works like most npm packages. You can install it by runningnpm install bids-validator.Through Command LineIf you install the bids validator globally by usingnpm install -g bids-validatoryou will be able to use it as a command line tool. Once installed you should be
able to runbids-validator /path/to/your/bids/directoryand see any validation
issues logged to the terminal. Runbids-validatorwithout a directory path to
see available options.Docker imageTo use bids validator withdocker, you simply need toinstall dockeron your system.And then from a terminal run:docker run -ti --rm bids/validator --versionto print the version of the
docker imagedocker run -ti --rm bids/validator --helpto print the helpdocker run -ti --rm -v /path/to/data:/data:ro bids/validator /datato validate the dataset/path/to/dataon your host machineSee here for a brief explanation of the commands:docker runis the command to tell docker to run a certain docker image,
usually taking the formdocker run <IMAGENAME> <COMMAND>the-tiflag means the inputs are accepted and outputs are printed to the
terminalthe--rmflag means that the state of the docker container is not saved
after it has runthe-vflag is adding your local data to the docker container
(bind-mounts). Importantly,
the input after the-vflag consists of three fields separated colons::the first field is the path to the directory on the host machine:/path/to/datathe second field is the path where the directory is mounted in the
containerthe third field is optional. In our case, we useroto specify that the
mounted data isread onlyPython LibraryThere are is a limited library of helper functions written in Python. The main function
determines if a file extension is compliant with the BIDS specification. You can find
the available functions in the library, as well as their descriptions,here.
To install, runpip install -U bids_validator(requires python and pip) orconda install bids-validator(requires a Conda environment).Examplefrombids_validatorimportBIDSValidatorvalidator=BIDSValidator()filepaths=["/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz","/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe"]forfilepathinfilepaths:print(validator.is_bids(filepath))# will print True, and then FalseNote, the file path must be relative to the root of the BIDS dataset, and a
leading forward slash/must be added to the file path.DevelopmentTo develop locally, clone the project and runnpm installfrom the project
root. This will install external dependencies. If you wish to installbids-validatorglobally (so that you can run it in other folders), use the
following command to install it globally:cd bids-validator && npm install -g(for windows users, if in a different drive add /d, e.g.cd /d F:\bids-validator && npm install -g)Please see theCONTRIBUTING.mdfor additional details.Bundlingbids-validator is bundled with esbuild. While developing, the scriptbids-validator/bin/bids-validatorwill automatically bundle the project each time it is run. To test a build without publishing itnpm -w bids-validator run build. This will generate a bids-validator/dist directory containing the local build andbids-validator/bin/bids-validatorwill use this build. To return to automatic bundling on each run, remove the dist directory.Running Locally in a BrowserA note about OS X, the dependencies for the browser require a npm package called
node-gyp which needs xcode to be installed in order to be compiled.The browser version ofbids-validatorlives in the repo subdirectory/bids-validator-web. It is aReact.jsapplication
that uses thenext.jsframework.To developbids-validatorand see how it will act in the browser, simply runnpm run web-devin the project root and navigate tolocalhost:3000.In development mode, changes to the codebase will trigger rebuilds of the application
automatically.Changes to the/bids-validatorin the codebase will also be reflected in the
web application.Tests use theJesttesting library and should be developed in/bids-validator-web/tests.
We can always use more tests, so please feel free to contribute a test that reduces the chance
of any bugs you fix!To ensure that the web application compiles successfully in production, runnpm run web-exportTestingIf it's your first time running tests, first use the commandgit submodule update --init --depth 1to pull the test example data. This repo contains thebids-examples github repositoryas asubmodule.To start the test suite runnpm run testfrom the project root.npm run test -- --watchis useful to run tests while making changes. A coverage report is available withnpm run coverage.To run the linter which checks code conventions runnpm run lint.Install globally from a development branchGlobal installs are not recommended for development because of the possibility of package conflicts with other Node.js projects. If you do need to test with a global install from a development tree, follow these steps to generate the NPM package without publishing it and install the package locally.npm -w bids-validator run buildnpm -w bids-validator packnpm install -g bids-validator-*.tgzPublishingPublishing is done withLerna. Use the commandnpx lerna publishand follow instructions to set a new version.Using lerna publish will create a git commit with updated version information and create a version number tag for it, push the tag to GitHub, then publish to NPM and PyPI. The GitHub release is manual following that.AcknowledgmentsMany contributions to thebids-validatorwere done by members of the
BIDS community. See thelist of contributors.A large part of the development ofbids-validatoris currently done bySquishymedia, who are in turn financed through
different grants offered for the general development of BIDS. See the list
below.Development and contributions were supported through the following federally
funded projects/grants:BIDS Derivatives (NIMH: R24MH114705, PI: Poldrack)OpenNeuro (NIMH: R24MH117179, PI: Poldrack)Spokes: MEDIUM: WEST (NSF: 1760950, PI: Poldrack & Gorgolewski)ReproNim(NIH-NIBIB P41 EB019936, PI: Kennedy)