Skip to content

Commit 8002280

Browse files
committed
Doc and cleaning the dcm2niix json example
1 parent bef9dbe commit 8002280

File tree

6 files changed

+55
-47
lines changed

6 files changed

+55
-47
lines changed

examples/dcm2niix/README.md

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
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.
44

55
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+
67
```shell
78
mkdir sourcedata
89
cd sourcedata
@@ -11,67 +12,95 @@ datalad install --recursive https://github.com/psychoinformatics-de/hirni-demo.g
1112

1213
> [!NOTE] Note that the dataset must be added inside the `sourcedata/` directory.
1314
14-
## Experiment #1
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:
1524

16-
The aim of the experiment is to describe the provenance records inside several files.
17-
Here we use sidecars and modality agnostic files inside the `prov/` directory, as follows:
1825
```
1926
.
2027
├── prov
21-
│ ├── prov-dcm2niix_.prov.json
22-
│ ├── prov-dcm2niix_env.prov.json
23-
│ └── prov-dcm2niix_soft.prov.json
28+
│ ├── base.prov.json
29+
│ ├── prov-dcm2niix_ses-01_env.prov.json
30+
│ ├── prov-dcm2niix_ses-01_soft.prov.json
31+
│ ├── prov-dcm2niix_ses-02_env.prov.json
32+
│ └── prov-dcm2niix_ses-02_soft.prov.json
2433
└── sub_02
2534
├── ses_20130717141500
2635
│ └── anat
27-
│ └── sub-02_ses-20130717141500_T1w.prov.jsonld
36+
│ └── sub-02_ses-20130717141500_T1w.json
2837
└── ses_20140425155335
2938
└── func
30-
└── sub-02_ses-20140425155335_task-oneback_run-1_bold.prov.jsonld
39+
└── sub-02_ses-20140425155335_task-oneback_run-1_bold.json
3140
```
3241

42+
## New features for BIDS / BIDS Prov
43+
3344
We introduce the following BIDS suffixes that are currently not existing:
34-
* `soft`:
35-
* `env`:
45+
* `soft`: the file describes BIDS Prov `Software` for the provenance traces
46+
* `env`: the file describes BIDS Prov `Environments` for the provenance traces
3647

3748
We introduce the following BIDS entity that is currently not existing:
3849
* `prov`
3950
* Full name: Provenance traces
4051
* Format: `prov-<label>`
4152
* Definition: A grouping of provenance traces. Defining multiple provenance traces groups is appropriate when several processings have been performed on data.
4253

43-
* `sub-02_ses-20130717141500_T1w.prov.jsonld` and `sub-02_ses-20140425155335_task-oneback_run-1_bold.prov.jsonld` are sidecars defining provenance for the corresponding `.nii` files.
44-
* `environments.prov.jsonld` mutualises the declaration of software environments objects for lower level prov files
45-
* `software.prov.jsonld` mutualises the declaration of software pieces objects for lower level prov files
54+
We also use the `ses` entity for provenance files, in order to identify several groups of processes that happened at different times. In the example, `ses-01` and `ses-02` represent two different dcm2niix conversion sessions, with different versions of dcm2niix and environments.
55+
56+
We use the `GeneratedBy` field of JSON sidecars to describe `Activities` that created the file the sidecars refers to.
57+
58+
The `prov/base.prov.jsonld` contains an empty BIDS Prov JSON-LD graph as follows:
59+
```JSON-LD
60+
{
61+
"@context": "https://purl.org/nidash/bidsprov/context.json",
62+
"BIDSProvVersion": "0.0.1",
63+
"Records": {
64+
"Software": [],
65+
"Activities": [],
66+
"Entities": []
67+
}
68+
}
69+
```
70+
71+
## Merging JSON in a JSON-LD file and plotting graph
4672

47-
The python script `code/exp1_merge_prov.py` aims at merging all these provenance records into one RFD graph.
73+
The python script `code/merge_prov.py` aims at merging all these provenance records into one RFD graph.
4874

4975
```shell
50-
pip install -r code/requirements.txt
51-
mkdir prov/experiment_1/
52-
python code/exp1_merge_prov.py
76+
mkdir prov/merged/
77+
python code/merge_prov.py
5378
```
5479

55-
From that, we generate the RDF graph `prov/experiment_1/merged_provenance.ttl`. Then we were able to plot the graph as a png file. We used this command:
80+
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:
5681

5782
```shell
58-
python code/plot_graph.py -i prov/experiment_1/merged_provenance_2.ttl -o prov/experiment_1/merged_provenance_2.png
83+
python ../../bids_prov/visualize.py --input_file prov/merged/prov-dcm2niix.prov.jsonld --output_file prov/merged/prov-dcm2niix.prov.png
5984
```
6085

61-
![](/examples/dcm2niix/prov/experiment_1/merged_provenance.png)
86+
![](/examples/dcm2niix/prov/merged/prov-dcm2niix.prov.png)
6287

6388
### Notes
6489

65-
In this example, we rely on the fact that nodes defined in the `prov/*.prov.jsonld` files have `bids::prov/` as base IRIs. Here are the involved nodes:
66-
* `bids::prov/dcm2niix`
67-
* `bids::prov/fedora`
90+
In this example, we rely on the fact that nodes defined in the `prov/*.prov.jsonld` files have `bids::prov/` as base IRIs.
91+
92+
The `code/merge_prov.py` code is responsible for:
93+
* merging the JSON provenance traces into the base JSON-LD graph;
94+
* create an `Entity` and linking it to the `Activity` described by the `GeneratedBy` field in the case of JSON sidecars.
6895

6996
### Limitations
7097

71-
The `bids::prov/fedora` node defined in `prov/environments.prov.jsonld` (see grey node in the above graph plot) is not recognized as a `prov:Entity` as the current context (commit [ce0eb77](https://github.com/bids-standard/BEP028_BIDSprov/commit/ce0eb774abd9527e594bd69212a87d5047864678)) does not define the `Environments` term.
98+
1. The `Environments` term is not defined in the current BIDS Prov context, hence we define environments as `Entities`.
7299

73-
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`:
100+
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`:
74101
* `bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms/`
75102
* `bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms/`
76103

77104
although it is not allowed by the current version of the BIDS Prov specification to have directories as `Entities`.
105+
106+
3. In this example, the provenance for the JSON sidecar files is not described.

examples/dcm2niix/code/exp1_merge_prov.py renamed to examples/dcm2niix/code/merge_prov.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
""" Merge available prov JSON files into one RDF graph """
55

66
import json
7-
from pyld import jsonld
87

98
# List of available prov files
109
prov_soft_files = [
@@ -55,5 +54,5 @@
5554
})
5655

5756
# Write jsonld
58-
with open('prov/experiment_1/merged_provenance.prov.jsonld', 'w', encoding = 'utf-8') as file:
57+
with open('prov/merged/prov-dcm2niix.prov.jsonld', 'w', encoding = 'utf-8') as file:
5958
file.write(json.dumps(base_provenance, indent = 2))

examples/dcm2niix/code/plot_graph.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/dcm2niix/code/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)