Skip to content

Commit 6d002b2

Browse files
authored
feat(schema): Add meta.templates and allow for composing multiple references (#2140)
* feat(schema): Add meta.templates * fix(test): Replace removed schema location * feat(schema): Move more imaging data into imaging.yaml * feat(schema): Remove redundant anatomical derivative rules * feat(schema): Expand use of raw templates * rf: Dereference while looking up references * doc: Document null deletion * schema: Factor out common PET and MRS entities
1 parent dd1e5d2 commit 6d002b2

File tree

25 files changed

+709
-917
lines changed

25 files changed

+709
-917
lines changed

src/metaschema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
"additionalProperties": false
7272
}
7373
},
74+
"templates": {
75+
"type": "object"
76+
},
7477
"versions": {
7578
"type": "array",
7679
"items": {

src/schema/README.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,43 @@ references (the cases in which they are used will be presented later):
167167
(which are in turn references to individual values), and the references inside `GeneticLevel.anyOf` indicate that there may be a single
168168
such value or a list of values.
169169

170-
1. In [`rules.files.deriv.preprocessed_data`][preprocessed_data]:
170+
1. In [`rules.files.deriv.imaging`](./rules/files/deriv/imaging.yaml):
171171
```YAML
172-
anat_nonparametric_common:
173-
$ref: rules.files.raw.anat.nonparametric
172+
anat_parametric_volumetric:
173+
$ref: rules.files.raw.anat.parametric
174174
entities:
175-
$ref: rules.files.raw.anat.nonparametric.entities
176-
space: optional
177-
description: optional
175+
$ref:
176+
- meta.templates.deriv.volumetric.entities
177+
- rules.files.raw.anat.parametric.entities
178178
```
179179
Here, the derivative datatype rule starts by copying the raw datatype rule
180180
`rules.files.raw.anat.nonparametric`.
181181
It then *overrides* the `entities` portion of that rule with a new object.
182-
To *extend* the original `entities`, it again begins
183-
by referencing `rules.files.raw.anat.nonparametric.entities`,
184-
and adding the new entities `space` and `description`.
182+
To *extend* the original `entities`, it composes
183+
`meta.templates.deriv.volumetric.entities`
184+
and `rules.files.raw.anat.nonparametric.entities`.
185+
When multiple references are aggregated, the first reference takes
186+
precedence.
187+
188+
Note also that `value: null` can be used to "delete" a key from a template.
189+
For example, in `rules.files.raw.events`:
190+
191+
```YAML
192+
events__pet:
193+
$ref: rules.files.raw.events.events
194+
datatypes:
195+
- pet
196+
entities:
197+
$ref: meta.templates.raw.task.entities
198+
tracer: optional
199+
reconstruction: optional
200+
# Most events allow acquisition, PET doesn't
201+
acquisition: null
202+
```
203+
204+
This technique should be used judiciously, preferring semantic clarity to brevity.
205+
Templates should be expected to grow as BIDS evolves,
206+
and should thus be used only where those changes should propagate.
185207

186208
### Expressions
187209

@@ -1074,5 +1096,4 @@ ensuring consistency across the entire schema directory. Validation of the schem
10741096
incorporated into the CI, so any changes that are inconsistent will be flagged before
10751097
inclusion.
10761098

1077-
[preprocessed_data]: https://github.com/bids-standard/bids-specification/tree/master/src/schema/rules/files/deriv/preprocessed_data.yaml
10781099
[tabular files]: https://bids-specification.readthedocs.io/en/stable/common-principles.html#tabular-files

src/schema/meta/templates.yaml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
# This section is unstructured, for inclusion in rules by reference
3+
4+
# Entities that apply to most raw files
5+
# Include thus:
6+
#
7+
# filerule:
8+
# entities:
9+
# $ref: meta.templates.raw.base.entities
10+
# task: optional
11+
# ...
12+
# datatypes:
13+
# ...
14+
raw:
15+
base:
16+
entities:
17+
subject: required
18+
session: optional
19+
20+
recording:
21+
entities:
22+
$ref: meta.templates.raw.base.entities
23+
acquisition: optional
24+
run: optional
25+
26+
task:
27+
entities:
28+
$ref: meta.templates.raw.recording.entities
29+
task: required
30+
31+
mri:
32+
entities:
33+
$ref: meta.templates.raw.recording.entities
34+
ceagent: optional
35+
reconstruction: optional
36+
chunk: optional
37+
38+
epi:
39+
entities:
40+
$ref: meta.templates.raw.mri.entities
41+
direction: optional
42+
part: optional
43+
44+
pet:
45+
entities:
46+
$ref: meta.templates.raw.base.entities
47+
task: optional
48+
tracer: optional
49+
reconstruction: optional
50+
run: optional
51+
52+
mrs:
53+
entities:
54+
$ref: meta.templates.raw.recording.entities
55+
task: optional
56+
nucleus: optional
57+
volume: optional
58+
reconstruction: optional
59+
60+
# Entities that apply to most derivative files
61+
# Include thus:
62+
#
63+
# filerule:
64+
# entities:
65+
# $ref: meta.templates.deriv.base.entities
66+
# task: optional
67+
# ...
68+
# datatypes:
69+
# ...
70+
deriv:
71+
base:
72+
selectors:
73+
- dataset.dataset_description.DatasetType == 'derivative'
74+
entities:
75+
subject: optional
76+
session: optional
77+
description: optional
78+
79+
spatial:
80+
$ref: meta.templates.deriv.base
81+
entities:
82+
$ref: meta.templates.deriv.base.entities
83+
space: optional
84+
85+
# Imaging derivatives
86+
volumetric:
87+
$ref: meta.templates.deriv.spatial
88+
extensions:
89+
- .nii.gz
90+
- .nii
91+
- .json
92+
entities:
93+
$ref: meta.templates.deriv.spatial.entities
94+
resolution: optional
95+
96+
surface:
97+
$ref: meta.templates.deriv.spatial
98+
entities:
99+
$ref: meta.templates.deriv.spatial.entities
100+
hemisphere: optional
101+
density: optional
102+
103+
mask:
104+
$ref: meta.templates.deriv.volumetric
105+
suffixes:
106+
- mask
107+
entities:
108+
$ref: meta.templates.deriv.volumetric.entities
109+
label: optional
110+
111+
dseg:
112+
$ref: meta.templates.deriv.volumetric
113+
extensions:
114+
- .nii.gz
115+
- .nii
116+
- .tsv
117+
- .json
118+
suffixes:
119+
- dseg
120+
entities:
121+
$ref: meta.templates.deriv.volumetric.entities
122+
segmentation: optional
123+
124+
probseg:
125+
$ref: meta.templates.deriv.volumetric
126+
extensions:
127+
- .nii.gz
128+
- .nii
129+
- .json
130+
suffixes:
131+
- probseg
132+
entities:
133+
$ref: meta.templates.deriv.volumetric.entities
134+
segmentation: optional
135+
label: optional
136+
137+
dseg_surface:
138+
$ref: meta.templates.deriv.surface
139+
extensions:
140+
- .label.gii
141+
- .dlabel.nii
142+
- .tsv
143+
- .json
144+
suffixes:
145+
- dseg
146+
entities:
147+
$ref: meta.templates.deriv.surface.entities
148+
segmentation: optional

0 commit comments

Comments
 (0)