|
| 1 | +Architecture |
| 2 | +============ |
| 3 | + |
| 4 | +bids2openminds converts `BIDS <https://bids.neuroimaging.io/>`_ neuroimaging datasets into |
| 5 | +`openMINDS <https://openminds-documentation.readthedocs.io/>`_ metadata collections |
| 6 | +serialised as JSON-LD. |
| 7 | + |
| 8 | +Conversion pipeline |
| 9 | +------------------- |
| 10 | + |
| 11 | +The top-level entry point is :func:`bids2openminds.converter.convert`. |
| 12 | +It orchestrates the following steps: |
| 13 | + |
| 14 | +1. Validate that the input path is a directory and load a BIDS layout via |
| 15 | + `ancpBIDS <https://github.com/ANCPLabOldenburg/ancp-bids>`_. |
| 16 | +2. Flatten the layout into a Pandas ``DataFrame`` (one row per file) via the |
| 17 | + ``layout_to_df()`` shim in ``converter.py``. |
| 18 | +3. Call functions in ``main.py`` to create typed openMINDS objects: |
| 19 | + |
| 20 | + * Subjects and their biological states |
| 21 | + * Persons (authors / contributors) |
| 22 | + * Behavioural protocols (tasks) |
| 23 | + * File bundles and individual files |
| 24 | + * A ``DatasetVersion`` and its parent ``Dataset`` |
| 25 | + |
| 26 | +4. Validate the resulting ``openminds.Collection`` against the openMINDS schema. |
| 27 | +5. Optionally serialise to JSON-LD (single file or one file per object). |
| 28 | +6. Print a human-readable conversion report. |
| 29 | + |
| 30 | +Module descriptions |
| 31 | +------------------- |
| 32 | + |
| 33 | +``converter.py`` |
| 34 | +~~~~~~~~~~~~~~~~ |
| 35 | + |
| 36 | +CLI entry point (Click command) and the ``convert()`` function that orchestrates |
| 37 | +the pipeline. Also contains ``layout_to_df()``, a shim that translates the |
| 38 | +ancpBIDS object model into a flat Pandas DataFrame so the rest of the code can |
| 39 | +query files without depending directly on the ancpBIDS API. |
| 40 | + |
| 41 | +``main.py`` |
| 42 | +~~~~~~~~~~~ |
| 43 | + |
| 44 | +All object-creation functions that map BIDS concepts to openMINDS schema objects: |
| 45 | +``create_subjects()``, ``create_persons()``, ``create_behavioral_protocol()``, |
| 46 | +``create_file()``, ``create_dataset_version()``, and ``create_dataset()``. |
| 47 | + |
| 48 | +``mapping.py`` |
| 49 | +~~~~~~~~~~~~~~ |
| 50 | + |
| 51 | +Controlled-vocabulary dictionaries that translate BIDS terms (file suffixes, |
| 52 | +acquisition labels, species identifiers, sex codes, handedness codes) into |
| 53 | +openMINDS ``ControlledTerm`` instances. Entries that do not yet have a |
| 54 | +corresponding openMINDS instance are marked ``None`` with a ``# TODO`` comment. |
| 55 | + |
| 56 | +``utility.py`` |
| 57 | +~~~~~~~~~~~~~~ |
| 58 | + |
| 59 | +Helper functions: JSON reading, Pandas DataFrame filtering and value extraction, |
| 60 | +file hashing (returns an openMINDS ``Hash`` object), file size (returns an |
| 61 | +openMINDS ``QuantitativeValue`` object), and NIfTI version detection. |
| 62 | + |
| 63 | +``report.py`` |
| 64 | +~~~~~~~~~~~~~ |
| 65 | + |
| 66 | +Generates a human-readable conversion summary printed after a successful run, |
| 67 | +showing counts of subjects, files, persons, and protocols. |
| 68 | + |
| 69 | +openMINDS object model |
| 70 | +---------------------- |
| 71 | + |
| 72 | +All metadata objects are instances from the ``openminds.v4`` package: |
| 73 | + |
| 74 | +* ``openminds.v4.core`` — ``Dataset``, ``DatasetVersion``, ``SubjectGroup``, |
| 75 | + ``Subject``, ``SubjectState``, ``Person``, ``File``, ``FileBundle``, etc. |
| 76 | +* ``openminds.v4.controlled_terms`` — ``Species``, ``BiologicalSex``, |
| 77 | + ``Handedness``, ``Technique``, ``ExperimentalApproach``, ``UnitOfMeasurement``, etc. |
| 78 | + |
| 79 | +Objects are added to an ``openminds.Collection``, which enforces the schema and |
| 80 | +handles JSON-LD serialisation. |
| 81 | + |
| 82 | +Test structure |
| 83 | +-------------- |
| 84 | + |
| 85 | +``test/test_bids_examples.py`` |
| 86 | + End-to-end conversion of datasets from the `bids-examples |
| 87 | + <https://github.com/bids-standard/bids-examples>`_ corpus (checked out as a |
| 88 | + git submodule at ``bids-examples/``). Each test asserts on the counts of |
| 89 | + openMINDS objects produced. |
| 90 | + |
| 91 | +``test/test_thorough_bids_example.py`` |
| 92 | + Deep validation on a more complex BIDS dataset. |
| 93 | + |
| 94 | +``test_dataset_version.py``, ``test_example_datasets_click.py``, ``test/test_person.py``, ``test/test_task.py``, ``test/test_subject_age.py``, ``test/test_file_bundle.py``, ``test/test_mapping_completeness.py`` |
| 95 | + Unit tests for individual mapping and utility functions. |
| 96 | + |
| 97 | +The ``bids-examples`` submodule must be initialised before running the full test suite:: |
| 98 | + |
| 99 | + git submodule update --init |
0 commit comments