Skip to content

Commit 88aac30

Browse files
committed
Cleaning example
1 parent ca081c8 commit 88aac30

File tree

13 files changed

+120
-109
lines changed

13 files changed

+120
-109
lines changed

examples/dcm2niix/README.md

Lines changed: 17 additions & 15 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,9 +12,10 @@ 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 inside several files. Here we use sidecars and modality agnostic files inside the `prov/` directory, as follows:
1518

16-
The aim of the experiment is to describe the provenance records inside several files. Here we use sidecars and modality agnostic files inside the `prov/` directory, as follows:
1719
```
1820
.
1921
├── prov
@@ -28,38 +30,38 @@ The aim of the experiment is to describe the provenance records inside several f
2830
└── sub-02_ses-20140425155335_task-oneback_run-1_bold.prov.jsonld
2931
```
3032

31-
* `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.
33+
* `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.
3234
* `environments.prov.jsonld` mutualises the declaration of software environments objects for lower level prov files
3335
* `software.prov.jsonld` mutualises the declaration of software pieces objects for lower level prov files
3436

35-
The python script `code/exp1_merge_prov.py` aims at merging all these provenance records into one RFD graph.
37+
The python script `code/merge_prov.py` aims at merging all these provenance records into one JSON-LD graph.
3638

3739
```shell
38-
pip install -r code/requirements.txt
39-
mkdir prov/experiment_1/
40-
python code/exp1_merge_prov.py
40+
pip install bids-prov==0.1.0
41+
mkdir prov/merged/
42+
python code/merge_prov.py
4143
```
4244

43-
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:
45+
From that, we generate the graph `prov/merged/dcm2niix.prov.jsonld`. Then we were able to plot the graph as a png file. We used this command:
4446

4547
```shell
46-
python code/plot_graph.py -i prov/experiment_1/merged_provenance_2.ttl -o prov/experiment_1/merged_provenance_2.png
48+
bids_prov_visualizer --input_file prov/merged/dcm2niix.prov.jsonld --output_file prov/merged/dcm2niix.prov.png
4749
```
4850

49-
![](/examples/dcm2niix/prov/experiment_1/merged_provenance.png)
51+
![](/examples/dcm2niix/prov/merged/dicom2niix.prov.png)
5052

5153
### Notes
5254

5355
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:
54-
* `bids::prov/dcm2niix`
55-
* `bids::prov/fedora`
56+
* `bids::prov/dcm2niix-xce5m9z3`
57+
* `bids::prov/fedora-b7hmkmqd`
5658

5759
### Limitations
5860

59-
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.
61+
The `bids::prov/fedora-b7hmkmqd` node defined in `prov/environments.prov.jsonld` is defined as an `Entity` as the current context (commit [ce0eb77](https://github.com/bids-standard/BEP028_BIDSprov/commit/ce0eb774abd9527e594bd69212a87d5047864678)) does not define the `Environments` term.
6062

6163
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`:
62-
* `bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms/`
63-
* `bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms/`
64+
* `bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms`
65+
* `bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms`
6466

6567
although it is not allowed by the current version of the BIDS Prov specification to have directories as `Entities`.

examples/dcm2niix/code/exp1_merge_prov.py

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/python
2+
# coding: utf-8
3+
4+
""" Merge available prov JSON-LD files into one JSON-LD graph """
5+
6+
import json
7+
from bids_prov.visualize import join_jsonld
8+
9+
# List of available prov files
10+
prov_files = [
11+
'prov/software.prov.jsonld',
12+
'prov/environments.prov.jsonld',
13+
'sub_02/ses_20130717141500/anat/sub-02_ses-20130717141500_T1w.prov.jsonld',
14+
'sub_02/ses_20140425155335/func/sub-02_ses-20140425155335_task-oneback_run-1_bold.prov.jsonld'
15+
]
16+
17+
# Generate JSON-LD graph of each file using pyld
18+
graphs = list()
19+
for prov_file in prov_files:
20+
with open(prov_file, encoding = 'utf-8') as file:
21+
graphs.append(json.load(file))
22+
23+
# Merge graphs & Write JSON-LD graph
24+
with open('prov/merged/dcm2niix.prov.jsonld', 'w' , encoding = 'utf-8') as file:
25+
file.write(json.dumps(join_jsonld(graphs, omit_details = False), 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.

examples/dcm2niix/prov/environments.prov.jsonld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"@context": "https://purl.org/nidash/bidsprov/context.json",
33
"BIDSProvVersion": "0.0.1",
44
"Records": {
5-
"Environments": [
5+
"Entities": [
66
{
7-
"Id": "bids::prov/fedora",
7+
"Id": "bids::prov/fedora-b7hmkmqd",
88
"Label": "Fedora release 36 (Thirty Six)",
99
"OperatingSystem": " GNU/Linux 6.2.15-100.fc36.x86_64"
1010
}
-114 KB
Binary file not shown.

examples/dcm2niix/prov/experiment_1/merged_provenance.ttl

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"@context": "https://purl.org/nidash/bidsprov/context.json",
3+
"Records": {
4+
"Software": [
5+
{
6+
"Id": "bids::prov/dcm2niix-xce5m9z3",
7+
"Label": "dcm2niix",
8+
"Version": "v1.0.20220720"
9+
}
10+
],
11+
"Entities": [
12+
{
13+
"Id": "bids::prov/fedora-b7hmkmqd",
14+
"Label": "Fedora release 36 (Thirty Six)",
15+
"OperatingSystem": " GNU/Linux 6.2.15-100.fc36.x86_64"
16+
},
17+
{
18+
"Id": "bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
19+
"Label": "dicoms"
20+
},
21+
{
22+
"Id": "bids::sub-02/ses-20130717141500/anat/sub-02_ses-20130717141500_T1w.nii",
23+
"Label": "sub-02_ses-20130717141500_T1w.nii",
24+
"GeneratedBy": "urn:conversion-00f3a18f"
25+
},
26+
{
27+
"Id": "bids::sub-02/ses-20130717141500/anat/sub-02_ses-20130717141500_T1w.json",
28+
"Label": "sub-02_ses-20130717141500_T1w.json",
29+
"GeneratedBy": "urn:conversion-00f3a18f"
30+
},
31+
{
32+
"Id": "bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms",
33+
"Label": "dicoms"
34+
},
35+
{
36+
"Id": "bids::sub-02/ses-20140425155335/func/sub-02_ses-20140425155335_task-oneback_run-1_bold.nii",
37+
"Label": "sub-02_ses-20140425155335_task-oneback_run-1_bold.nii",
38+
"GeneratedBy": "urn:conversion-5a66f5be"
39+
},
40+
{
41+
"Id": "bids::sub-02/ses-20140425155335/func/sub-02_ses-20140425155335_task-oneback_run-1_bold.json",
42+
"Label": "sub-02_ses-20140425155335_task-oneback_run-1_bold.json",
43+
"GeneratedBy": "urn:conversion-5a66f5be"
44+
}
45+
],
46+
"Activities": [
47+
{
48+
"Id": "urn:conversion-00f3a18f",
49+
"Label": "Conversion",
50+
"Command": "dcm2niix -o . -f sub-%i/ses-%t/anat/sub-%i_ses-%t_T1w sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
51+
"AssociatedWith": "bids::prov/dcm2niix-xce5m9z3",
52+
"Used": [
53+
"bids::prov/fedora-b7hmkmqd",
54+
"bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms"
55+
]
56+
},
57+
{
58+
"Id": "urn:conversion-5a66f5be",
59+
"Label": "Conversion",
60+
"Command": "dcm2niix -o . -f sub-%i/ses-%t/func/sub-%i_ses-%t_task-oneback_run-1_bold sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms",
61+
"AssociatedWith": "bids::prov/dcm2niix-xce5m9z3",
62+
"Used": [
63+
"bids::prov/fedora-b7hmkmqd",
64+
"bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms"
65+
]
66+
}
67+
]
68+
}
69+
}
107 KB
Loading

0 commit comments

Comments
 (0)