Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCHEMA: Add index_columns metadata, render in tables #1306

Merged
merged 2 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ rule is applied.
| `selectors` | List of expressions; any evaluating false indicate rule does not apply |
| `columns` | Object with keys that may be found in `objects.columns`, values either a requirement level or an object |
| `initial_columns` | An optional list of columns that must be the first N columns of a file |
| `index_columns` | An optional list of columns that uniquely identify a row. |
| `additional_columns` | Indicates whether additional columns may be defined. One of `allowed`, `allowed_if_defined` and `not_allowed`. |

The following tables demonstrate how mutual exclusive, required fields, may be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ SegmentationLookup:
abbreviation: optional
color: optional
mapping: optional
index_columns: [index]
2 changes: 2 additions & 0 deletions src/schema/rules/tabular_data/eeg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ EEGChannels:
notch: optional
status: optional
status_description: optional
index_columns: [name__channels]
additional_columns: allowed_if_defined

EEGElectrodes:
Expand All @@ -40,4 +41,5 @@ EEGElectrodes:
type__electrodes: recommended
material: recommended
impedance: recommended
index_columns: [name__electrodes]
additional_columns: allowed_if_defined
2 changes: 2 additions & 0 deletions src/schema/rules/tabular_data/ieeg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ iEEGChannels:
notch: optional
status: optional
status_description: optional
index_columns: [name__channels]
additional_columns: allowed_if_defined

iEEGElectrodes:
Expand Down Expand Up @@ -60,4 +61,5 @@ iEEGElectrodes:
type__electrodes: optional
impedance: optional
dimension: optional
index_columns: [name__electrodes]
additional_columns: allowed_if_defined
1 change: 1 addition & 0 deletions src/schema/rules/tabular_data/meg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ MEGChannels:
software_filters: optional
status: optional
status_description: optional
index_columns: [name__channels]
additional_columns: allowed_if_defined
14 changes: 6 additions & 8 deletions src/schema/rules/tabular_data/modality_agnostic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ Participants:
handedness: recommended
strain: recommended
strain_rrid: recommended
index_columns: [participant_id]
additional_columns: allowed

Samples:
selectors:
- path == "samples.tsv"
columns:
sample_id:
level: required
description_addendum: |
The combination of `sample_id` and `participant_id` MUST be unique.
participant_id:
level: required
description_addendum: |
The combination of `sample_id` and `participant_id` MUST be unique.
sample_id: required
participant_id: required
sample_type: required
pathology: recommended
derived_from: recommended
index_columns: [sample_id, participant_id]
additional_columns: allowed

Scans:
Expand All @@ -46,6 +42,7 @@ Scans:
description_addendum: |
There MUST be exactly one row for each file.
acq_time__scans: optional
index_columns: [filename]
additional_columns: allowed

Sessions:
Expand All @@ -61,4 +58,5 @@ Sessions:
There MUST be exactly one row for each session.
acq_time__sessions: optional
pathology: recommended
index_columns: [session_id]
additional_columns: allowed
9 changes: 9 additions & 0 deletions tools/schemacode/bidsschematools/render/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def _make_table_from_rule(
# Since only one table may be provided for columns, we can just use this directly.
additional_columns = table_schema.get("additional_columns", "not_allowed")
initial_columns = table_schema.get("initial_columns", [])
index_columns = table_schema.get("index_columns", [])
else:
raise ValueError(f"Unsupported 'table_type': '{table_type}'")

Expand Down Expand Up @@ -214,6 +215,14 @@ def _make_table_from_rule(
# Typically begins with "if"
level = f"{level} {level_addendum}"

if table_type == "columns" and element in index_columns:
if len(index_columns) == 1:
msg = f"Values in `{schema.objects.columns[element].name}`"
else:
cols = [f"`{schema.objects.columns[col].name}`" for col in index_columns]
msg = f"The combination of {', '.join(cols[:-1])} and {cols[-1]}"
description_addendum += f"\n\n\n\n{msg} MUST be unique."

if table_type == "columns" and initial_columns:
if element in initial_columns:
order = initial_columns.index(element) + 1
Expand Down