Skip to content

Commit fff9fa5

Browse files
oestebaneffigies
andcommitted
enh: use macro for the physio template
The physio template has an optional entity `recording-`. With the previous version of the macro, all entities are nested in the placeholder (`<matches>`). This commit adds a ``show_entities`` argument so that entities that should be displayed despite the placeholder are taken out and written in the name. Co-Authored-By: Chris Markiewicz <[email protected]>
1 parent 7a9f680 commit fff9fa5

File tree

2 files changed

+53
-56
lines changed

2 files changed

+53
-56
lines changed

src/modality-specific-files/physiological-recordings.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,13 @@ JSON file for storing metadata fields (see below).
1414
- [`7t_trt`](https://github.com/bids-standard/bids-examples/tree/master/7t_trt)
1515
- [`ds210`](https://github.com/bids-standard/bids-examples/tree/master/ds210)
1616

17-
Template:
18-
19-
```Text
20-
sub-<label>/[ses-<label>/]
21-
<datatype>/
22-
<matches>[_recording-<label>]_physio.tsv.gz
23-
<matches>[_recording-<label>]_physio.json
24-
```
25-
26-
For the template directory name, `<datatype>` can correspond to any data
27-
recording modality, for example `func`, `anat`, `dwi`, `meg`, `eeg`, `ieeg`,
28-
or `beh`.
29-
30-
In the template filenames, the `<matches>` part corresponds to task filename
31-
before the suffix.
32-
For example for the file `sub-control01_task-nback_run-1_bold.nii.gz`,
33-
`<matches>` would correspond to `sub-control01_task-nback_run-1`.
17+
{{ MACROS___make_filename_template(
18+
"raw",
19+
placeholders=True,
20+
show_entities=["recording"],
21+
suffixes=["physio"]
22+
)
23+
}}
3424

3525
!!! warning "Caution"
3626

tools/schemacode/src/bidsschematools/render/text.py

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def make_filename_template(
234234
pdf_format=False,
235235
placeholders=False,
236236
empty_dirs=None,
237+
show_entities=tuple(),
237238
**kwargs,
238239
):
239240
"""Create codeblocks containing example filename patterns for a given datatype.
@@ -271,6 +272,10 @@ def make_filename_template(
271272
If False, empty datatype directories are not included. If ``placeholders`` is True,
272273
this option is set False.
273274
Default is True.
275+
show_entities: tuple, optional
276+
If ``placeholders`` is ``False`` this argument is ignored.
277+
When using placeholders, this argument can be set to a list or tuple of entity
278+
names that will be "extracted" out of the placeholder.
274279
275280
Other Parameters
276281
----------------
@@ -325,9 +330,11 @@ def make_filename_template(
325330
if empty_dirs is None:
326331
empty_dirs = not placeholders
327332

333+
entity_list = schema.rules.entities
334+
start_string = ""
328335
if placeholders:
329336
metaentity_name = "matches" if dstype == "raw" else "source_entities"
330-
ent_string = (
337+
start_string = (
331338
lt
332339
+ utils._link_with_html(
333340
metaentity_name,
@@ -337,6 +344,7 @@ def make_filename_template(
337344
)
338345
+ gt
339346
)
347+
entity_list = show_entities
340348

341349
for datatype in sorted(file_groups):
342350
group_lines = []
@@ -350,44 +358,43 @@ def make_filename_template(
350358

351359
# Unique filename patterns
352360
for group in file_groups[datatype]:
353-
if not placeholders:
354-
ent_string = ""
355-
for ent in schema.rules.entities:
356-
if ent not in group.entities:
357-
continue
358-
359-
# Add level and any overrides to entity
360-
ent_obj = group.entities[ent]
361-
if isinstance(ent_obj, str):
362-
ent_obj = {"level": ent_obj}
363-
entity = {**schema.objects.entities[ent], **ent_obj}
364-
365-
if "enum" in entity:
366-
# Link full entity
367-
pattern = utils._link_with_html(
368-
_format_entity(entity, lt, gt),
369-
html_path=f"{ENTITIES_PATH}.html",
370-
heading=entity["name"],
371-
pdf_format=pdf_format,
372-
)
373-
else:
374-
# Link entity and format separately
375-
entity["name"] = utils._link_with_html(
376-
entity["name"],
377-
html_path=f"{ENTITIES_PATH}.html",
378-
heading=entity["name"],
379-
pdf_format=pdf_format,
380-
)
381-
fmt = entity.get("format", "label")
382-
entity["format"] = utils._link_with_html(
383-
entity.get("format", "label"),
384-
html_path=f"{GLOSSARY_PATH}.html",
385-
heading=f"{fmt}-common_principles",
386-
pdf_format=pdf_format,
387-
)
388-
pattern = _format_entity(entity, lt, gt)
389-
390-
ent_string = _add_entity(ent_string, pattern, entity["level"])
361+
ent_string = start_string
362+
for ent in entity_list:
363+
if ent not in group.entities:
364+
continue
365+
366+
# Add level and any overrides to entity
367+
ent_obj = group.entities[ent]
368+
if isinstance(ent_obj, str):
369+
ent_obj = {"level": ent_obj}
370+
entity = {**schema.objects.entities[ent], **ent_obj}
371+
372+
if "enum" in entity:
373+
# Link full entity
374+
pattern = utils._link_with_html(
375+
_format_entity(entity, lt, gt),
376+
html_path=f"{ENTITIES_PATH}.html",
377+
heading=entity["name"],
378+
pdf_format=pdf_format,
379+
)
380+
else:
381+
# Link entity and format separately
382+
entity["name"] = utils._link_with_html(
383+
entity["name"],
384+
html_path=f"{ENTITIES_PATH}.html",
385+
heading=entity["name"],
386+
pdf_format=pdf_format,
387+
)
388+
fmt = entity.get("format", "label")
389+
entity["format"] = utils._link_with_html(
390+
entity.get("format", "label"),
391+
html_path=f"{GLOSSARY_PATH}.html",
392+
heading=f"{fmt}-common_principles",
393+
pdf_format=pdf_format,
394+
)
395+
pattern = _format_entity(entity, lt, gt)
396+
397+
ent_string = _add_entity(ent_string, pattern, entity["level"])
391398

392399
# In cases of large numbers of suffixes,
393400
# we use the "suffix" variable and expect a table later in the spec

0 commit comments

Comments
 (0)