|
| 1 | +# BIDS Prov example for `dcm2niix` |
| 2 | + |
| 3 | +This example aims at showing the capture of provenance for a [`dcm2niix`](https://github.com/rordenlab/dcm2niix) usecase: converting DICOM data to Nifti files within a BIDS dataset. |
| 4 | + |
| 5 | +Source data for this example can be found here: https://github.com/psychoinformatics-de/hirni-demo. This is a datalad dataset containing anatomical and functional MRI acquisitions. The contents of this dataset can be downloaded using: |
| 6 | + |
| 7 | +```shell |
| 8 | +mkdir sourcedata |
| 9 | +cd sourcedata |
| 10 | +datalad install --recursive https://github.com/psychoinformatics-de/hirni-demo.git |
| 11 | +``` |
| 12 | + |
| 13 | +> [!NOTE] Note that the dataset must be added inside the `sourcedata/` directory. |
| 14 | +
|
| 15 | +## Purpose |
| 16 | + |
| 17 | +The aim of the example is to describe the provenance records using BIDS Prov, but inside several *JSON* files. |
| 18 | +We use: |
| 19 | + |
| 20 | +* the `GeneratedBy` field of JSON sidecars, already existing in the BIDS specification |
| 21 | +* modality agnostic files inside the `prov/` directory |
| 22 | + |
| 23 | +as follows: |
| 24 | + |
| 25 | +``` |
| 26 | +. |
| 27 | +├── prov |
| 28 | +│ ├── prov-dcm2niix_act.prov.json |
| 29 | +│ ├── prov-dcm2niix_base.prov.json |
| 30 | +│ ├── prov-dcm2niix_env.prov.json |
| 31 | +│ └── prov-dcm2niix_soft.prov.json |
| 32 | +└── sub-02 |
| 33 | + ├── ses-20130717141500 |
| 34 | + │ └── anat |
| 35 | + │ └── sub-02_ses-20130717141500_T1w.json |
| 36 | + └── ses-20140425155335 |
| 37 | + └── func |
| 38 | + └── sub-02_ses-20140425155335_task-oneback_run-1_bold.json |
| 39 | +``` |
| 40 | + |
| 41 | +## New features for BIDS / BIDS Prov |
| 42 | + |
| 43 | +We introduce the following BIDS entity that is currently not existing: |
| 44 | +* `prov` |
| 45 | + * Full name: Provenance traces |
| 46 | + * Format: `prov-<label>` |
| 47 | + * Definition: A grouping of provenance traces. Defining multiple provenance traces groups is appropriate when several processings have been performed on data. |
| 48 | + |
| 49 | +We introduce the following BIDS suffixes that are currently not existing: |
| 50 | +* `act`: the file describes BIDS Prov `Activities` for the group of provenance traces |
| 51 | +* `soft`: the file describes BIDS Prov `Software` for the group of provenance traces |
| 52 | +* `env`: the file describes BIDS Prov `Environments` for the group of provenance traces |
| 53 | +* `base`: the file describes common BIDS Prov parameters for the group of provenance traces (version and context for BIDS Prov) |
| 54 | + |
| 55 | +We use the `GeneratedBy` field of JSON sidecars to link to `Activities` that created the file the sidecars refers to. |
| 56 | + |
| 57 | +## Merging JSON in a JSON-LD file and plotting graph |
| 58 | + |
| 59 | +The python script `code/merge_prov.py` aims at merging all these provenance records into one JSON-LD graph. |
| 60 | + |
| 61 | +```shell |
| 62 | +mkdir prov/merged/ |
| 63 | +python code/merge_prov.py |
| 64 | +``` |
| 65 | + |
| 66 | +From that, we generate the JSON-LD graph `prov/merge/prov-dcm2niix.prov.jsonld`. Then we were able to plot the graph as a png file. We used this command: |
| 67 | + |
| 68 | +```shell |
| 69 | +pip install bids-prov==0.1.0 |
| 70 | +bids_prov_visualizer --input_file prov/merged/prov-dcm2niix.prov.jsonld --output_file prov/merged/prov-dcm2niix.prov.png |
| 71 | +``` |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +### Notes |
| 76 | + |
| 77 | +In this example, we rely on the fact that nodes defined in the `prov/*.prov.jsonld` files have `bids::prov/` as base IRIs. |
| 78 | + |
| 79 | +The `code/merge_prov.py` code is responsible for: |
| 80 | +* merging the JSON provenance traces into the base JSON-LD graph; |
| 81 | +* create an `Entity` and linking it to the `Activity` described by the `GeneratedBy` field in the case of JSON sidecars. |
| 82 | + |
| 83 | +### Limitations |
| 84 | + |
| 85 | +1. The `Environments` term is not defined in the current BIDS Prov context, hence we define environments as `Entities`. |
| 86 | + |
| 87 | +2. Listing all the DICOM files used by the dcm2niix conversion steps would lower readability of the JSON-LD provenance files. Therefore we only listed the following directories as `Entities`: |
| 88 | +* `bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms` |
| 89 | +* `bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms` |
| 90 | + |
| 91 | +although it is not allowed by the current version of the BIDS Prov specification to have directories as `Entities`. |
| 92 | + |
| 93 | +3. In this example, the provenance for JSON sidecars files is not described. |
0 commit comments