Skip to content

Commit b21843f

Browse files
committed
First provenance traces of anat preprocessing
1 parent ef797f5 commit b21843f

File tree

9 files changed

+550
-0
lines changed

9 files changed

+550
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/python
2+
# coding: utf-8
3+
4+
""" Merge available prov JSON files into one JSON-LD graph """
5+
6+
import json
7+
from pathlib import Path
8+
9+
# List of available prov files
10+
prov_soft_files = [
11+
'prov/prov-fmriprep_soft.prov.json'
12+
]
13+
prov_env_files = [
14+
'prov/prov-fmriprep_env.prov.json'
15+
]
16+
prov_act_files = [
17+
'sub-001/anat/sub-001_prov-fmriprep_act.prov.json'
18+
]
19+
prov_ent_files = [
20+
'prov/prov-fmriprep_ent.prov.json',
21+
'sub-001/anat/sub-001_prov-fmriprep_ent.prov.json'
22+
]
23+
sidecar_files = [
24+
]
25+
26+
# Base jsonld
27+
base_provenance = {
28+
"Records": {
29+
"Software": [],
30+
"Activities": [],
31+
"Entities": []
32+
}
33+
}
34+
35+
# Add context and version
36+
with open('prov/prov-fmriprep_base.prov.json', encoding = 'utf-8') as file:
37+
base_provenance.update(json.load(file))
38+
39+
# Parse Software
40+
print("Parsing soft files")
41+
for prov_file in prov_soft_files:
42+
with open(prov_file, encoding = 'utf-8') as file:
43+
data = json.load(file)
44+
for key, value in data.items():
45+
value['Id'] = key
46+
base_provenance['Records']['Software'].append(value)
47+
48+
# Parse Environments
49+
print("Parsing env files")
50+
for prov_file in prov_env_files:
51+
with open(prov_file, encoding = 'utf-8') as file:
52+
data = json.load(file)
53+
for key, value in data.items():
54+
value['Id'] = key
55+
# /!\ Workaround: environments are added in the Entities list because
56+
# the Environments term is not defined in the BIDS Prov context yet
57+
base_provenance['Records']['Entities'].append(value)
58+
59+
# Parse Activities
60+
print("Parsing act files")
61+
for prov_file in prov_act_files:
62+
with open(prov_file, encoding = 'utf-8') as file:
63+
data = json.load(file)
64+
for key, value in data.items():
65+
value['Id'] = key
66+
base_provenance['Records']['Activities'].append(value)
67+
68+
# Parse Entities
69+
print("Parsing ent files")
70+
for prov_file in prov_ent_files:
71+
with open(prov_file, encoding = 'utf-8') as file:
72+
data = json.load(file)
73+
for key, value in data.items():
74+
value['Id'] = key
75+
base_provenance['Records']['Entities'].append(value)
76+
77+
# Parse Sidecar files
78+
for sidecar_file in sidecar_files:
79+
# Identify data file(s) associated with the sidecar
80+
sidecar_filename = Path(sidecar_file)
81+
data_files = Path('').glob(f'{sidecar_filename.with_suffix("")}.*')
82+
data_files = [str(f) for f in list(data_files) if str(sidecar_filename) not in str(f)]
83+
84+
# Write provenance
85+
with open(sidecar_file, encoding = 'utf-8') as file:
86+
data = json.load(file)
87+
if 'GeneratedBy' in data:
88+
activity_id = data['GeneratedBy']
89+
for data_file in data_files:
90+
base_provenance['Records']['Entities'].append({
91+
"Id": f"bids::{data_file}",
92+
"GeneratedBy": activity_id
93+
})
94+
95+
# Write jsonld
96+
with open('prov/merged/prov-fmriprep.prov.jsonld', 'w', encoding = 'utf-8') as file:
97+
file.write(json.dumps(base_provenance, indent = 2))
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
{
2+
"Records": {
3+
"Software": [
4+
{
5+
"Label": "fmriprep",
6+
"Version": "v1.1.6",
7+
"AltIdentifier": "RRID:SCR_016216",
8+
"Id": "bids::prov/fmriprep-ughfyb4k"
9+
},
10+
{
11+
"Label": "ANTs",
12+
"Version": "2.2.0",
13+
"AltIdentifier": "RRID:SCR_004757",
14+
"Id": "urn:ants-bagzrxi0"
15+
},
16+
{
17+
"Label": "FreeSurfer",
18+
"Version": "6.0.1",
19+
"AltIdentifier": "RRID:SCR_001847",
20+
"Id": "urn:freesurfer-bqv4h9k2"
21+
},
22+
{
23+
"Label": "FSL",
24+
"Version": "5.0.9",
25+
"AltIdentifier": "RRID:SCR_002823",
26+
"Id": "urn:fsl-e1oq534p"
27+
}
28+
],
29+
"Activities": [
30+
{
31+
"Label": "Correction for intensity non-uniformity (INU)",
32+
"Command": "N4BiasFieldCorrection",
33+
"AssociatedWith": [
34+
"urn:ants-bagzrxi0",
35+
"bids::prov/fmriprep-ughfyb4k"
36+
],
37+
"Used": [
38+
{
39+
"Id": "bids:ds001734:sub-001/anat/sub-001_T1w.nii.gz",
40+
"Type": "Entity",
41+
"Label": "sub-001_T1w.nii.gz"
42+
}
43+
],
44+
"Id": "bids::prov/inu-correction-ue9qstw1"
45+
},
46+
{
47+
"Label": "Skull stripping",
48+
"Command": "antsBrainExtraction.sh",
49+
"AssociatedWith": [
50+
"urn:ants-bagzrxi0",
51+
"bids::prov/fmriprep-ughfyb4k"
52+
],
53+
"Used": [
54+
"https://github.com/brainspaces/OASIS/blob/master/OASIS-2x2x2.nii.gz",
55+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_preproc.nii.gz"
56+
],
57+
"Id": "bids::prov/skull-stripping-ics87cwt"
58+
},
59+
{
60+
"Label": "Brain surface reconstruction",
61+
"Command": "recon-all",
62+
"AssociatedWith": [
63+
"urn:freesurfer-bqv4h9k2",
64+
"bids::prov/fmriprep-ughfyb4k"
65+
],
66+
"Used": [],
67+
"Id": "bids::prov/brain-surface-reconstruction-uac8ysmu"
68+
},
69+
{
70+
"Label": "Spatial normalization to the ICBM 152",
71+
"Command": "antsRegistration",
72+
"AssociatedWith": [
73+
"urn:ants-bagzrxi0",
74+
"bids::prov/fmriprep-ughfyb4k"
75+
],
76+
"Used": [
77+
"http://www.bic.mni.mcgill.ca/~vfonov/icbm/2009/mni_icbm152_nlin_sym_09c_nifti.zip",
78+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_brainmask.nii.gz",
79+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_class-CSF_probtissue.nii.gz",
80+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_class-GM_probtissue.nii.gz",
81+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_class-WM_probtissue.nii.gz",
82+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_dtissue.nii.gz",
83+
"bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_preproc.nii.gz"
84+
],
85+
"Id": "bids::prov/spatial-normalisation-uuwz1aep"
86+
},
87+
{
88+
"Label": "Brain tissue segmentation",
89+
"Command": "feat",
90+
"AssociatedWith": [
91+
"urn:fsl-e1oq534p",
92+
"bids::prov/fmriprep-ughfyb4k"
93+
],
94+
"Used": [],
95+
"Id": "bids::prov/brain-segmentation-egbeiwg9"
96+
}
97+
],
98+
"Entities": [
99+
{
100+
"Label": "Fedora release 36 (Thirty Six)",
101+
"OperatingSystem": "GNU/Linux 6.2.15-100.fc36.x86_64",
102+
"Id": "bids::prov/fedora-6qmhtq53"
103+
},
104+
{
105+
"Label": "poldracklab/fmriprep:1.1.4",
106+
"Id": "bids::prov/fmriprep-container-hzlji7es"
107+
},
108+
{
109+
"Label": "OASIS template",
110+
"Id": "https://github.com/brainspaces/OASIS/blob/master/OASIS-2x2x2.nii.gz"
111+
},
112+
{
113+
"Label": "ICBM 152 Nonlinear Asymmetrical template version 2009c",
114+
"Id": "http://www.bic.mni.mcgill.ca/~vfonov/icbm/2009/mni_icbm152_nlin_sym_09c_nifti.zip"
115+
},
116+
{
117+
"Label": "T1w-brainmask.nii.gz",
118+
"GeneratedBy": "bids::prov/skull-stripping-ics87cwt",
119+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_brainmask.nii.gz"
120+
},
121+
{
122+
"Label": "T1w_class-CSF_probtissue.nii.gz",
123+
"GeneratedBy": "bids::prov/brain-segmentation-egbeiwg9",
124+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_class-CSF_probtissue.nii.gz"
125+
},
126+
{
127+
"Label": "T1w_class-GM_probtissue.nii.gz",
128+
"GeneratedBy": "bids::prov/brain-segmentation-egbeiwg9",
129+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_class-GM_probtissue.nii.gz"
130+
},
131+
{
132+
"Label": "T1w_class-WM_probtissue.nii.gz",
133+
"GeneratedBy": "bids::prov/brain-segmentation-egbeiwg9",
134+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_class-WM_probtissue.nii.gz"
135+
},
136+
{
137+
"Label": "T1w_dtissue.nii.gz",
138+
"GeneratedBy": "bids::prov/brain-segmentation-egbeiwg9",
139+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_dtissue.nii.gz"
140+
},
141+
{
142+
"Label": "T1w_inflated.L.surf.gii",
143+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
144+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_inflated.L.surf.gii"
145+
},
146+
{
147+
"Label": "T1w_inflated.R.surf.gii",
148+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
149+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_inflated.R.surf.gii"
150+
},
151+
{
152+
"Label": "T1w_label-aparcaseg_roi.nii.gz",
153+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_label-aparcaseg_roi.nii.gz"
154+
},
155+
{
156+
"Label": "T1w_label-aseg_roi.nii.gz",
157+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_label-aseg_roi.nii.gz"
158+
},
159+
{
160+
"Label": "T1w_midthickness.L.surf.gii",
161+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
162+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_midthickness.L.surf.gii"
163+
},
164+
{
165+
"Label": "T1w_midthickness.R.surf.gii",
166+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
167+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_midthickness.R.surf.gii"
168+
},
169+
{
170+
"Label": "T1w_pial.L.surf.gii",
171+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
172+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_pial.L.surf.gii"
173+
},
174+
{
175+
"Label": "T1w_pial.R.surf.gii",
176+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
177+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_pial.R.surf.gii"
178+
},
179+
{
180+
"Label": "T1w_preproc.nii.gz",
181+
"GeneratedBy": "bids::prov/inu-correction-ue9qstw1",
182+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_preproc.nii.gz"
183+
},
184+
{
185+
"Label": "T1w_smoothwm.L.surf.gii",
186+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
187+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_smoothwm.L.surf.gii"
188+
},
189+
{
190+
"Label": "T1w_smoothwm.R.surf.gii",
191+
"GeneratedBy": "bids::prov/brain-surface-reconstruction-uac8ysmu",
192+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_smoothwm.R.surf.gii"
193+
},
194+
{
195+
"Label": "T1w_space-MNI152NLin2009cAsym_brainmask.nii.gz",
196+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
197+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_brainmask.nii.gz"
198+
},
199+
{
200+
"Label": "T1w_space-MNI152NLin2009cAsym_class-CSF_probtissue.nii.gz",
201+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
202+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_class-CSF_probtissue.nii.gz"
203+
},
204+
{
205+
"Label": "T1w_space-MNI152NLin2009cAsym_class-GM_probtissue.nii.gz",
206+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
207+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_class-GM_probtissue.nii.gz"
208+
},
209+
{
210+
"Label": "T1w_space-MNI152NLin2009cAsym_class-WM_probtissue.nii.gz",
211+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
212+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_class-WM_probtissue.nii.gz"
213+
},
214+
{
215+
"Label": "T1w_space-MNI152NLin2009cAsym_dtissue.nii.gz",
216+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
217+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_dtissue.nii.gz"
218+
},
219+
{
220+
"Label": "T1w_space-MNI152NLin2009cAsym_preproc.nii.gz",
221+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
222+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_preproc.nii.gz"
223+
},
224+
{
225+
"Label": "T1w_space-MNI152NLin2009cAsym_target-T1w_warp.h5",
226+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
227+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-MNI152NLin2009cAsym_target-T1w_warp.h5"
228+
},
229+
{
230+
"Label": "T1w_space-orig_target-T1w_affine.txt",
231+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_space-orig_target-T1w_affine.txt"
232+
},
233+
{
234+
"Label": "T1w_target-fsnative_affine.txt",
235+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_target-fsnative_affine.txt"
236+
},
237+
{
238+
"Label": "T1w_target-MNI152NLin2009cAsym_warp.h5",
239+
"GeneratedBy": "bids::prov/spatial-normalisation-uuwz1aep",
240+
"Id": "bids:ds001734:derivatives/fmriprep/sub-001/anat/sub-001_T1w_target-MNI152NLin2009cAsym_warp.h5"
241+
}
242+
]
243+
},
244+
"@context": "https://purl.org/nidash/bidsprov/context.json",
245+
"BIDSProvVersion": "0.0.1"
246+
}
525 KB
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"https://github.com/brainspaces/OASIS/blob/master/OASIS-2x2x2.nii.gz": {
3+
"Label": "OASIS template"
4+
},
5+
"http://www.bic.mni.mcgill.ca/~vfonov/icbm/2009/mni_icbm152_nlin_sym_09c_nifti.zip": {
6+
"Label": "ICBM 152 Nonlinear Asymmetrical template version 2009c"
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bids::prov/fedora-6qmhtq53": {
3+
"Label": "Fedora release 36 (Thirty Six)",
4+
"OperatingSystem": "GNU/Linux 6.2.15-100.fc36.x86_64"
5+
},
6+
"bids::prov/fmriprep-container-hzlji7es": {
7+
"Label": "poldracklab/fmriprep:1.1.4"
8+
}
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bids::prov/fmriprep-ughfyb4k": {
3+
"Label": "fmriprep",
4+
"Version": "v1.1.6",
5+
"AltIdentifier": "RRID:SCR_016216"
6+
},
7+
"urn:ants-bagzrxi0": {
8+
"Label": "ANTs",
9+
"Version": "2.2.0",
10+
"AltIdentifier": "RRID:SCR_004757"
11+
},
12+
"urn:freesurfer-bqv4h9k2": {
13+
"Label": "FreeSurfer",
14+
"Version": "6.0.1",
15+
"AltIdentifier": "RRID:SCR_001847"
16+
},
17+
"urn:fsl-e1oq534p": {
18+
"Label": "FSL",
19+
"Version": "5.0.9",
20+
"AltIdentifier": "RRID:SCR_002823"
21+
}
22+
}

0 commit comments

Comments
 (0)