Skip to content

Commit d856b1b

Browse files
committed
First version of heudiconv prov example
1 parent 1202d77 commit d856b1b

File tree

10 files changed

+249
-0
lines changed

10 files changed

+249
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "examples/heudiconv/examples/heudiconv/sourcedata/hirni-demo"]
2+
path = examples/heudiconv/examples/heudiconv/sourcedata/hirni-demo
3+
url = https://github.com/psychoinformatics-de/hirni-demo.git

examples/heudiconv/.bidsignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.duecredit.p

examples/heudiconv/CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0.0.1 Initial data acquired
2+
TODOs:
3+
- verify and possibly extend information in participants.tsv (see for example http://datasets.datalad.org/?dir=/openfmri/ds000208)
4+
- fill out dataset_description.json, README, sourcedata/README (if present)
5+
- provide _events.tsv file for each _bold.nii.gz with onsets of events (see '8.5 Task events' of BIDS specification)

examples/heudiconv/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Provide description for the dataset -- basic details about the study, possibly pointing to pre-registration (if public or embargoed)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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-heudiconv_soft.prov.json'
12+
]
13+
prov_env_files = [
14+
'prov/prov-heudiconv_env.prov.json'
15+
]
16+
prov_act_files = [
17+
'prov/prov-heudiconv_act.prov.json'
18+
]
19+
prov_ent_files = [
20+
'prov/prov-heudiconv_ent.prov.json'
21+
]
22+
sidecar_files = [
23+
'sub-None/func/sub-None_task-oneback_run-01_bold.json',
24+
'sub-None/anat/sub-None_run-1_T1w.json'
25+
]
26+
27+
# Base jsonld
28+
base_provenance = {
29+
"Records": {
30+
"Software": [],
31+
"Activities": [],
32+
"Entities": []
33+
}
34+
}
35+
36+
# Add context and version
37+
with open('prov/prov-heudiconv_base.prov.json', encoding = 'utf-8') as file:
38+
base_provenance.update(json.load(file))
39+
40+
# Parse Software
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+
for prov_file in prov_env_files:
50+
with open(prov_file, encoding = 'utf-8') as file:
51+
data = json.load(file)
52+
for key, value in data.items():
53+
value['Id'] = key
54+
# /!\ Workaround: environments are added in the Entities list because
55+
# the Environments term is not defined in the BIDS Prov context yet
56+
base_provenance['Records']['Entities'].append(value)
57+
58+
# Parse Activities
59+
for prov_file in prov_act_files:
60+
with open(prov_file, encoding = 'utf-8') as file:
61+
data = json.load(file)
62+
for key, value in data.items():
63+
value['Id'] = key
64+
base_provenance['Records']['Activities'].append(value)
65+
66+
# Parse Entities
67+
for prov_file in prov_ent_files:
68+
with open(prov_file, encoding = 'utf-8') as file:
69+
data = json.load(file)
70+
for key, value in data.items():
71+
value['Id'] = key
72+
base_provenance['Records']['Entities'].append(value)
73+
74+
# Parse Sidecar files
75+
for sidecar_file in sidecar_files:
76+
# Identify data file(s) associated with the sidecar
77+
sidecar_filename = Path(sidecar_file)
78+
data_files = Path('').glob(f'{sidecar_filename.with_suffix("")}.*')
79+
data_files = [str(f) for f in list(data_files) if str(sidecar_filename) not in str(f)]
80+
81+
# Write provenance
82+
with open(sidecar_file, encoding = 'utf-8') as file:
83+
data = json.load(file)
84+
if 'GeneratedBy' in data:
85+
activity_id = data['GeneratedBy']
86+
for data_file in data_files:
87+
base_provenance['Records']['Entities'].append({
88+
"Id": f"bids::{data_file}",
89+
"GeneratedBy": activity_id
90+
})
91+
92+
# Write jsonld
93+
with open('prov/merged/prov-heudiconv.prov.jsonld', 'w', encoding = 'utf-8') as file:
94+
file.write(json.dumps(base_provenance, indent = 2))
Submodule hirni-demo added at f5aa766
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"Records": {
3+
"Software": [
4+
{
5+
"Label": "Heudiconv",
6+
"Version": "v1.3.2",
7+
"Id": "bids::prov/heudiconv-a9x5yd3j"
8+
}
9+
],
10+
"Activities": [
11+
{
12+
"Label": "Conversion",
13+
"Command": "heudiconv --files sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms/*.dcm -o . -f sourcedata/hirni-demo/code/hirni-toolbox/converters/heudiconv/hirni_heuristic.py -s 01 -ss acq1 -c dcm2niix -b --minmeta --overwrite",
14+
"AssociatedWith": "bids::prov/heudiconv-a9x5yd3j",
15+
"Used": [
16+
"bids::prov/fedora-1cu6r6ou",
17+
"bids::sourcedata/hirni-demo/acq1/studyspec.json",
18+
"bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
19+
"bids::sourcedata/hirni-demo/code/hirni-toolbox/converters/heudiconv/hirni_heuristic.py"
20+
],
21+
"Id": "bids::prov/conversion-00f3a18f"
22+
},
23+
{
24+
"Label": "Conversion",
25+
"Command": "heudiconv --files sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms/* -o . -f sourcedata/hirni-demo/code/hirni-toolbox/converters/heudiconv/hirni_heuristic.py -s 01 -ss acq2 -c dcm2niix -b --minmeta --overwrite",
26+
"AssociatedWith": "bids::prov/heudiconv-a9x5yd3j",
27+
"Used": [
28+
"bids::prov/fedora-pgrzf567",
29+
"bids::sourcedata/hirni-demo/acq2/studyspec.json",
30+
"bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms",
31+
"bids::sourcedata/hirni-demo/code/hirni-toolbox/converters/heudiconv/hirni_heuristic.py"
32+
],
33+
"Id": "bids::prov/conversion-5a66f5be"
34+
}
35+
],
36+
"Entities": [
37+
{
38+
"Label": "Fedora release 36 (Thirty Six)",
39+
"OperatingSystem": "GNU/Linux 6.2.15-100.fc36.x86_64",
40+
"EnvVars": {
41+
"HIRNI_STUDY_SPEC": "sourcedata/hirni-demo/acq1/studyspec.json"
42+
},
43+
"Id": "bids::prov/fedora-1cu6r6ou"
44+
},
45+
{
46+
"Label": "Fedora release 36 (Thirty Six)",
47+
"OperatingSystem": "GNU/Linux 6.2.15-100.fc36.x86_64",
48+
"EnvVars": {
49+
"HIRNI_STUDY_SPEC": "sourcedata/hirni-demo/acq2/studyspec.json"
50+
},
51+
"Id": "bids::prov/fedora-pgrzf567"
52+
},
53+
{
54+
"Label": "heuristics",
55+
"Id": "bids::sourcedata/hirni-demo/code/hirni-toolbox/converters/heudiconv/hirni_heuristic.py"
56+
},
57+
{
58+
"Label": "studyspec",
59+
"Id": "bids::sourcedata/hirni-demo/acq1/studyspec.json"
60+
},
61+
{
62+
"Label": "studyspec",
63+
"Id": "bids::sourcedata/hirni-demo/acq2/studyspec.json"
64+
},
65+
{
66+
"Label": "dicoms",
67+
"Id": "bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms"
68+
},
69+
{
70+
"Label": "dicoms",
71+
"Id": "bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms"
72+
},
73+
{
74+
"Label": "CHANGES",
75+
"GeneratedBy": [
76+
"bids::prov/conversion-00f3a18f",
77+
"bids::prov/conversion-5a66f5be"
78+
],
79+
"Id": "bids::CHANGES"
80+
},
81+
{
82+
"Label": "README",
83+
"GeneratedBy": [
84+
"bids::prov/conversion-00f3a18f",
85+
"bids::prov/conversion-5a66f5be"
86+
],
87+
"Id": "bids::README"
88+
},
89+
{
90+
"Label": "dataset_description.json",
91+
"GeneratedBy": [
92+
"bids::prov/conversion-00f3a18f",
93+
"bids::prov/conversion-5a66f5be"
94+
],
95+
"Id": "bids::dataset_description.json"
96+
},
97+
{
98+
"Label": "participants.json",
99+
"GeneratedBy": [
100+
"bids::prov/conversion-00f3a18f",
101+
"bids::prov/conversion-5a66f5be"
102+
],
103+
"Id": "bids::participants.json"
104+
},
105+
{
106+
"Label": "participants.tsv",
107+
"GeneratedBy": [
108+
"bids::prov/conversion-00f3a18f",
109+
"bids::prov/conversion-5a66f5be"
110+
],
111+
"Id": "bids::participants.tsv"
112+
},
113+
{
114+
"Label": "scans.json",
115+
"GeneratedBy": [
116+
"bids::prov/conversion-00f3a18f",
117+
"bids::prov/conversion-5a66f5be"
118+
],
119+
"Id": "bids::scans.json"
120+
},
121+
{
122+
"Label": "task-oneback_bold.json",
123+
"GeneratedBy": [
124+
"bids::prov/conversion-00f3a18f",
125+
"bids::prov/conversion-5a66f5be"
126+
],
127+
"Id": "bids::task-oneback_bold.json"
128+
},
129+
{
130+
"Id": "bids::sub-None/func/sub-None_task-oneback_run-01_bold.nii.gz",
131+
"GeneratedBy": "bids::prov/conversion-5a66f5be"
132+
},
133+
{
134+
"Id": "bids::sub-None/anat/sub-None_run-1_T1w.nii.gz",
135+
"GeneratedBy": "bids::prov/conversion-00f3a18f"
136+
}
137+
]
138+
},
139+
"@context": "https://purl.org/nidash/bidsprov/context.json",
140+
"BIDSProvVersion": "0.0.1"
141+
}
227 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TODO: Provide description about source data, e.g.
2+
Directory below contains DICOMS compressed into tarballs per each sequence, replicating directory hierarchy of the BIDS dataset itself.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit f5aa766d900037d97c82329e7dfc94ee80086b92

0 commit comments

Comments
 (0)