Skip to content

Commit 4b47320

Browse files
committed
Documentation of the nipype example
1 parent 804298b commit 4b47320

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

examples/nipype/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# BIDS-Prov example for nipype
2+
3+
This example aims at showing provenance traces from a simple [nipype](https://nipype.readthedocs.io/en/latest/) workflow, performed on a container-based software environment.
4+
5+
## Workflow
6+
7+
The workflow code is inside `code/normalize.py` and performs:
8+
1. a brain extraction of a T1w anatomical file `sub-001/anat/sub-001_Tw.nii.gz`, using BET;
9+
2. a normalisation to MNI152 of the resulting file, using FLIRT;
10+
3. exporting relevant output files to a BIDS compliant name space.
11+
12+
See [hereafter](#running-the-workflow) for more details on how to run the workflow.
13+
14+
## Overview
15+
16+
In order to describe provenance records using BIDS Prov, we use:
17+
18+
* the `GeneratedBy` field of JSON sidecar files, already existing in the BIDS specification;
19+
* modality agnostic files inside the `prov/` directory
20+
* a modality agnostic file inside the `derivatives/normalize/sub-001/anat/` directory
21+
22+
After running the workflow and adding provenance traces, the resulting directory tree looks like this:
23+
24+
```
25+
.
26+
├── code
27+
│ └── normalize.py
28+
├── derivatives
29+
│ ├── bids_prov_workflow
30+
│ └── normalize
31+
│ └── sub-001
32+
│ └── anat
33+
│ ├── sub-001_prov-normalize_act.prov.json
34+
│ ├── sub-001_space-mni152nlin2009casym_T1w_brain.json
35+
│ ├── sub-001_space-mni152nlin2009casym_T1w_brain.nii.gz
36+
│ ├── sub-001_T1w_brain.json
37+
│ └── sub-001_T1w_brain.nii.gz
38+
├── prov
39+
│ ├── prov-normalize_base.prov.json
40+
│ ├── prov-normalize_ent.prov.json
41+
│ ├── prov-normalize_env.prov.json
42+
│ └── prov-normalize_soft.prov.json
43+
├── README.md
44+
└── sub-001
45+
└── anat
46+
└── sub-001_T1w.nii.gz
47+
48+
```
49+
50+
Note that the `derivatives/bids_prov_workflow/` directory is nipype's working directory for the workflow. Its contents are not exhaustively described by the provenance traces.
51+
52+
## Provenance merge
53+
54+
The python script `code/merge_prov.py` aims at merging all provenance records into one JSON-LD graph.
55+
56+
```shell
57+
pip install bids-prov==0.1.0
58+
mkdir prov/merged/
59+
python code/merge_prov.py
60+
```
61+
62+
The `code/merge_prov.py` code is responsible for:
63+
* merging the JSON provenance traces into the base JSON-LD graph;
64+
* create an `Entity` and linking it to the `Activity` described by the `GeneratedBy` field in the case of JSON sidecars.
65+
66+
## Provenance visualization
67+
68+
We are then able to visualize these provenance files using the following commands (current directory is `examples/nipype/`):
69+
70+
```shell
71+
pip install bids-prov==0.1.0
72+
bids_prov_visualizer --input_file prov/merged/prov-normalize.prov.jsonld --output_file prov/merged/prov-normalize.prov.png
73+
```
74+
75+
![](/examples/nipype/prov/merged/prov-normalize.prov.png)
76+
77+
## Running the workflow
78+
79+
We use of the `nipype/nipype:py38` docker image that contains both nipype and FSL.
80+
81+
Assuming we are inside the nipype example directory (`examples/nipype`)
82+
83+
```bash
84+
# Get the container and run the workflow
85+
docker pull nipype/nipype:py38
86+
docker run -u root -it --rm -v .:/work nipype/nipype:py38 python code/normalize.py
87+
```
88+
89+
## Limitations
File renamed without changes.

0 commit comments

Comments
 (0)