Skip to content

Commit c6bc23c

Browse files
authored
Merge pull request #163 from bclenet/merge
Module to merge provenance
2 parents fb8b6c5 + e584867 commit c6bc23c

File tree

84 files changed

+2267
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2267
-16
lines changed

bids_prov/README.md

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@ python launch_parser_on_nidm.py --input_dir input_examples --output_dir output_r
1515
Your `output_results` directory tree will be generated by itself. A folder is created for each parser and each example contains the input file, the jsonld and the associated png.
1616

1717

18-
### Notes
19-
All scripts provide a `--help` flag, to get an overview of possible parameters and default values
20-
Here is an example
21-
```bash
22-
>> python -m bids_prov.visualize --help
23-
Usage: visualize.py [OPTIONS] [FILENAMES]...
18+
### Parser entry points
2419

25-
Options:
26-
-o, --output_file TEXT
27-
--omit-details omit the following low level details : {'Activity':
28-
('startedAtTime', 'endedAtTime'), 'Entity':
29-
('atLocation', 'generatedAt')}
20+
The following parser python modules provide entry points for direct use in a terminal:
3021

31-
--help Show this message and exit.
32-
```
22+
* `bids_prov.afni_parser`
23+
* `bids_prov.fsl_parser`
24+
* `bids_prov.spm_parser`
25+
26+
> [!NOTE]
27+
> All scripts provide a `--help` flag, to get an overview of possible parameters and default values.
28+
29+
Here are examples:
3330

3431
```bash
3532
>> python -m bids_prov.spm_parser --help
@@ -39,4 +36,99 @@ Options:
3936
-o, --output-file TEXT [required]
4037
-c, --context-url TEXT
4138
--help Show this message and exit.
42-
```
39+
```
40+
41+
### Visualize provenance as a graph
42+
43+
The `bids_prov.visualize` module allows to generate an image showing provenance contained in a JSON-LD file as a graph.
44+
45+
```bash
46+
>> python -m bids_prov.visualize --help
47+
usage: visualize.py [-h] --input_file INPUT_FILE [--output_file OUTPUT_FILE]
48+
49+
options:
50+
-h, --help show this help message and exit
51+
--input_file INPUT_FILE
52+
input BIDSprov data as a .jsonld file
53+
--output_file OUTPUT_FILE
54+
output .png file showing BIDSprov graph
55+
```
56+
57+
This is a generated graph, form the spm_default_batch example.
58+
59+
![](examples/from_parsers/spm/spm_default_batch.png)
60+
61+
### Merge provenance provenance records
62+
63+
The `bids_prov.merge` module allows to merge provenance records contained in a BIDS dataset into a single JSON-LD file.
64+
65+
```bash
66+
>> python -m bids_prov.merge --help
67+
usage: merge.py [-h] [--dataset DATASET] [--derivative] --output_file
68+
OUTPUT_FILE [--group GROUP]
69+
70+
options:
71+
-h, --help show this help message and exit
72+
--dataset DATASET, -d DATASET
73+
The path to the input BIDS dataset.
74+
--derivative Set this option to specify the dataset is a BIDS
75+
derivative dataset.
76+
--output_file OUTPUT_FILE, -o OUTPUT_FILE
77+
Output JSON-LD file containing the provenance graph
78+
for the input dataset.
79+
--group GROUP, -g GROUP
80+
Provenance group for which to extract the metadata.
81+
```
82+
83+
In the example of the following BIDS dataset:
84+
85+
```
86+
.
87+
├── dataset_description.json
88+
├── prov/
89+
│ ├── prov-fmriprep_act.json
90+
│ ├── prov-fmriprep_ent.json
91+
│ ├── prov-fmriprep_env.json
92+
│ └── prov-fmriprep_soft.json
93+
├── README.md
94+
└── sub-001/
95+
├── anat
96+
│ ├── sub-001_T1w_brainmask.nii.gz
97+
│ ├── sub-001_T1w_dtissue.nii.gz
98+
│ ├── sub-001_T1w_label-aparcaseg_roi.nii.gz
99+
│ ├── sub-001_T1w_label-aseg_roi.nii.gz
100+
│ ├── sub-001_T1w_preproc.nii.gz
101+
│ ├── sub-001_T1w_space-MNI152NLin2009cAsym_brainmask.nii.gz
102+
│ ├── sub-001_T1w_space-MNI152NLin2009cAsym_dtissue.nii.gz
103+
│ └── sub-001_T1w_space-MNI152NLin2009cAsym_preproc.nii.gz
104+
└── func
105+
├── sub-001_task-MGT_run-01_bold_confounds.tsv
106+
├── sub-001_task-MGT_run-01_bold_space-MNI152NLin2009cAsym_brainmask.nii.gz
107+
├── sub-001_task-MGT_run-01_bold_space-MNI152NLin2009cAsym_preproc.nii.gz
108+
├── sub-001_task-MGT_run-01_bold_space-T1w_label-aparcaseg_roi.nii.gz
109+
├── sub-001_task-MGT_run-01_bold_space-T1w_label-aseg_roi.nii.gz
110+
├── sub-001_task-MGT_run-02_bold_confounds.tsv
111+
├── sub-001_task-MGT_run-02_bold_space-MNI152NLin2009cAsym_brainmask.nii.gz
112+
├── sub-001_task-MGT_run-02_bold_space-MNI152NLin2009cAsym_preproc.nii.gz
113+
├── sub-001_task-MGT_run-02_bold_space-T1w_label-aparcaseg_roi.nii.gz
114+
├── sub-001_task-MGT_run-02_bold_space-T1w_label-aseg_roi.nii.gz
115+
├── sub-001_task-MGT_run-03_bold_confounds.tsv
116+
├── sub-001_task-MGT_run-03_bold_space-MNI152NLin2009cAsym_brainmask.nii.gz
117+
├── sub-001_task-MGT_run-03_bold_space-MNI152NLin2009cAsym_preproc.nii.gz
118+
├── sub-001_task-MGT_run-03_bold_space-T1w_label-aparcaseg_roi.nii.gz
119+
├── sub-001_task-MGT_run-03_bold_space-T1w_label-aseg_roi.nii.gz
120+
├── sub-001_task-MGT_run-04_bold_confounds.tsv
121+
├── sub-001_task-MGT_run-04_bold_space-MNI152NLin2009cAsym_brainmask.nii.gz
122+
├── sub-001_task-MGT_run-04_bold_space-MNI152NLin2009cAsym_preproc.nii.gz
123+
├── sub-001_task-MGT_run-04_bold_space-T1w_label-aparcaseg_roi.nii.gz
124+
└── sub-001_task-MGT_run-04_bold_space-T1w_label-aseg_roi.nii.gz
125+
```
126+
127+
Launching this command from the root dir of the dataset:
128+
```shell
129+
python -m bids_prov.merge -d . -o prov/prov-fmriprep_all.jsonld
130+
```
131+
132+
will look through all the sidecar JSON files, the `dataset_description.json`, and the `prov/*` files to extract provenance metadata, and merge it into the `prov/prov-fmriprep_all.jsonld` file as a JSON-LD RDF graph.
133+
134+
Note that it is possible to extract provenance metadata for all provenance groups or for one provenance group only. Also note that it is important to set the `--derivative` option to parse BIDS derivative datasets.

0 commit comments

Comments
 (0)