Skip to content

Commit d691d53

Browse files
committed
Activities in prov/ dir
1 parent 073607c commit d691d53

File tree

7 files changed

+56
-47
lines changed

7 files changed

+56
-47
lines changed

examples/dcm2niix/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ as follows:
3939

4040
## New features for BIDS / BIDS Prov
4141

42-
We introduce the following BIDS suffixes that are currently not existing:
43-
* `soft`: the file describes BIDS Prov `Software` for the provenance traces
44-
* `env`: the file describes BIDS Prov `Environments` for the provenance traces
45-
* `base`: the file describes common BIDS Prov parameters for the provenance traces (version and context for BIDS Prov)
46-
4742
We introduce the following BIDS entity that is currently not existing:
4843
* `prov`
4944
* Full name: Provenance traces
5045
* Format: `prov-<label>`
5146
* Definition: A grouping of provenance traces. Defining multiple provenance traces groups is appropriate when several processings have been performed on data.
5247

53-
We use the `GeneratedBy` field of JSON sidecars to describe `Activities` that created the file the sidecars refers to.
48+
We introduce the following BIDS suffixes that are currently not existing:
49+
* `act`: the file describes BIDS Prov `Activities` for the group of provenance traces
50+
* `soft`: the file describes BIDS Prov `Software` for the group of provenance traces
51+
* `env`: the file describes BIDS Prov `Environments` for the group of provenance traces
52+
* `base`: the file describes common BIDS Prov parameters for the group of provenance traces (version and context for BIDS Prov)
53+
54+
We use the `GeneratedBy` field of JSON sidecars to link to `Activities` that created the file the sidecars refers to.
5455

5556
## Merging JSON in a JSON-LD file and plotting graph
5657

examples/dcm2niix/code/merge_prov.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
prov_env_files = [
1414
'prov/prov-dcm2niix_env.prov.json'
1515
]
16+
prov_act_files = [
17+
'prov/prov-dcm2niix_act.prov.json'
18+
]
1619
sidecar_files = [
1720
'sub_02/ses_20130717141500/anat/sub-02_ses-20130717141500_T1w.json',
1821
'sub_02/ses_20140425155335/func/sub-02_ses-20140425155335_task-oneback_run-1_bold.json'
@@ -49,6 +52,14 @@
4952
# the Environments term is not defined in the BIDS Prov context yet
5053
base_provenance['Records']['Entities'].append(value)
5154

55+
# Parse Activities
56+
for prov_file in prov_act_files:
57+
with open(prov_file, encoding = 'utf-8') as file:
58+
data = json.load(file)
59+
for key, value in data.items():
60+
value['Id'] = key
61+
base_provenance['Records']['Activities'].append(value)
62+
5263
# Parse Sidecar files
5364
for sidecar_file in sidecar_files:
5465
# Identify data file(s) associated with the sidecar
@@ -60,12 +71,11 @@
6071
with open(sidecar_file, encoding = 'utf-8') as file:
6172
data = json.load(file)
6273
if 'GeneratedBy' in data:
63-
activity = data['GeneratedBy']
64-
base_provenance['Records']['Activities'].append(activity)
74+
activity_id = data['GeneratedBy']
6575
for data_file in data_files:
6676
base_provenance['Records']['Entities'].append({
6777
"Id": f"bids::{data_file}",
68-
"GeneratedBy": activity["Id"]
78+
"GeneratedBy": activity_id
6979
})
7080

7181
# Write jsonld

examples/dcm2niix/prov/merged/prov-dcm2niix.prov.jsonld

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
],
1010
"Activities": [
1111
{
12-
"Id": "urn:conversion-00f3a18f",
13-
"Type": "Activity",
1412
"Label": "Conversion",
1513
"Command": "dcm2niix -o . -f sub-%i/ses-%t/anat/sub-%i_ses-%t_T1w sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
1614
"AssociatedWith": "bids::prov/dcm2niix-khhkm7u1",
@@ -21,11 +19,10 @@
2119
"Type": "Entity",
2220
"Label": "dicoms"
2321
}
24-
]
22+
],
23+
"Id": "bids::prov/conversion-00f3a18f"
2524
},
2625
{
27-
"Id": "urn:conversion-5a66f5be",
28-
"Type": "Activity",
2926
"Label": "Conversion",
3027
"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",
3128
"AssociatedWith": "bids::prov/dcm2niix-khhkm7u1",
@@ -36,7 +33,8 @@
3633
"Type": "Entity",
3734
"Label": "dicoms"
3835
}
39-
]
36+
],
37+
"Id": "bids::prov/conversion-5a66f5be"
4038
}
4139
],
4240
"Entities": [
@@ -47,11 +45,11 @@
4745
},
4846
{
4947
"Id": "bids::sub_02/ses_20130717141500/anat/sub-02_ses-20130717141500_T1w.nii",
50-
"GeneratedBy": "urn:conversion-00f3a18f"
48+
"GeneratedBy": "bids::prov/conversion-00f3a18f"
5149
},
5250
{
5351
"Id": "bids::sub_02/ses_20140425155335/func/sub-02_ses-20140425155335_task-oneback_run-1_bold.nii",
54-
"GeneratedBy": "urn:conversion-5a66f5be"
52+
"GeneratedBy": "bids::prov/conversion-5a66f5be"
5553
}
5654
]
5755
},
-18 Bytes
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"bids::prov/conversion-00f3a18f": {
3+
"Label": "Conversion",
4+
"Command": "dcm2niix -o . -f sub-%i/ses-%t/anat/sub-%i_ses-%t_T1w sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
5+
"AssociatedWith": "bids::prov/dcm2niix-khhkm7u1",
6+
"Used": [
7+
"bids::prov/fedora-uldfv058",
8+
{
9+
"Id": "bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
10+
"Type": "Entity",
11+
"Label": "dicoms"
12+
}
13+
]
14+
},
15+
"bids::prov/conversion-5a66f5be": {
16+
"Label": "Conversion",
17+
"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",
18+
"AssociatedWith": "bids::prov/dcm2niix-khhkm7u1",
19+
"Used": [
20+
"bids::prov/fedora-uldfv058",
21+
{
22+
"Id": "bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms",
23+
"Type": "Entity",
24+
"Label": "dicoms"
25+
}
26+
]
27+
}
28+
}

examples/dcm2niix/sub_02/ses_20130717141500/anat/sub-02_ses-20130717141500_T1w.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,5 @@
2020
-0.128044 ],
2121
"ConversionSoftware": "dcm2niix",
2222
"ConversionSoftwareVersion": "v1.0.20220720",
23-
"GeneratedBy": {
24-
"Id": "urn:conversion-00f3a18f",
25-
"Type": "Activity",
26-
"Label": "Conversion",
27-
"Command": "dcm2niix -o . -f sub-%i/ses-%t/anat/sub-%i_ses-%t_T1w sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
28-
"AssociatedWith": "bids::prov/dcm2niix-khhkm7u1",
29-
"Used": [
30-
"bids::prov/fedora-uldfv058",
31-
{
32-
"Id": "bids::sourcedata/hirni-demo/acq1/dicoms/example-dicom-structural-master/dicoms",
33-
"Type": "Entity",
34-
"Label": "dicoms"
35-
}
36-
]
37-
}
23+
"GeneratedBy": "bids::prov/conversion-00f3a18f"
3824
}

examples/dcm2niix/sub_02/ses_20140425155335/func/sub-02_ses-20140425155335_task-oneback_run-1_bold.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,5 @@
5858
"InPlanePhaseEncodingDirectionDICOM": "COL",
5959
"ConversionSoftware": "dcm2niix",
6060
"ConversionSoftwareVersion": "v1.0.20220720",
61-
"GeneratedBy": {
62-
"Id": "urn:conversion-5a66f5be",
63-
"Type": "Activity",
64-
"Label": "Conversion",
65-
"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",
66-
"AssociatedWith": "bids::prov/dcm2niix-khhkm7u1",
67-
"Used": [
68-
"bids::prov/fedora-uldfv058",
69-
{
70-
"Id": "bids::sourcedata/hirni-demo/acq2/dicoms/example-dicom-functional-master/dicoms",
71-
"Type": "Entity",
72-
"Label": "dicoms"
73-
}
74-
]
75-
}
61+
"GeneratedBy": "bids::prov/conversion-5a66f5be"
7662
}

0 commit comments

Comments
 (0)