From 7529d69c99c2125491c00ee8580ec1e342200489 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 15 May 2024 12:09:57 -0400 Subject: [PATCH 1/3] RF: adjust common-principles to state that columns RECOMMENDED to be in single not plural --- src/common-principles.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common-principles.md b/src/common-principles.md index 3d9bc233af..eb8012fd7f 100644 --- a/src/common-principles.md +++ b/src/common-principles.md @@ -481,6 +481,7 @@ with two exceptions: It is RECOMMENDED that the column names in the header of the TSV file are written in [`snake_case`](https://en.wikipedia.org/wiki/Snake_case) with the first letter in lower case (for example, `variable_name`, not `Variable_name`). +It is RECOMMENDED that the column names are singular (for example, `variable_name`, not `variable_names`). Column names defined in the header MUST be separated with tabs as for the data contents. Furthermore, column names MUST NOT be blank (that is, an empty string) and MUST NOT be duplicated within a single TSV file. From 0f7b5bf5f36532a9193d2a541995c4fca89a0707 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 15 May 2024 12:11:29 -0400 Subject: [PATCH 2/3] Initial stab for migrations code... want to see if there more cases first --- .../schemacode/bidsschematools/migrations.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/schemacode/bidsschematools/migrations.py b/tools/schemacode/bidsschematools/migrations.py index 1cf0441cf1..eae92b1e87 100644 --- a/tools/schemacode/bidsschematools/migrations.py +++ b/tools/schemacode/bidsschematools/migrations.py @@ -58,6 +58,25 @@ def migrate_participants(dataset_path: Path): lgr.info(f" - migrated content in {new_file}") +def migrate_tsv_columns(dataset_path: Path): + """ + Rename some columns in .tsv (and corresponding sidecar .json) + """ + # TODO: ideally here we would not provide file_glob + # but rather take schema and deduce which files could have + # the column... alternatively - consider all .tsv files and + # their .json files (note -- could be above and multiple given + # inheritance principle) + for col_from, col_to, file_glob in ( + # https://github.com/bids-standard/bids-2-devel/issues/78 + ("hplc_recovery_fractions", "hplc_recovery_fraction", "*_blood.*"), + # https://github.com/bids-standard/bids-2-devel/issues/15 + ("units", "unit", "_channels.*"), # dependency on migrate_participants + # ??? Any other columns to rename for some reason? + ): + raise NotImplementedError() + + def migrate_dataset(dataset_path): lgr.info(f"Migrating dataset at {dataset_path}") dataset_path = Path(dataset_path) @@ -74,6 +93,7 @@ def migrate_dataset(dataset_path): for migration in [ migrate_participants, migrate_version, + migrate_tsv_columns, # depends on migrate_participants ]: lgr.info(f" - applying migration {migration.__name__}") migration(dataset_path) From f9a2ae3cba6d353e1798894c8d6b8526a844e6b1 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 15 May 2024 12:20:33 -0400 Subject: [PATCH 3/3] [DATALAD RUNCMD] Rename hplc_recovery_fractions to hplc_recovery_fraction === Do not change lines below === { "chain": [], "cmd": "git-sedi hplc_recovery_fractions hplc_recovery_fraction", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ --- src/schema/objects/columns.yaml | 4 ++-- src/schema/objects/metadata.yaml | 2 +- src/schema/rules/tabular_data/pet.yaml | 4 ++-- tools/schemacode/bidsschematools/migrations.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/schema/objects/columns.yaml b/src/schema/objects/columns.yaml index 3ccb32d324..4217752c10 100644 --- a/src/schema/objects/columns.yaml +++ b/src/schema/objects/columns.yaml @@ -237,8 +237,8 @@ high_cutoff: - type: string enum: - n/a -hplc_recovery_fractions: - name: hplc_recovery_fractions +hplc_recovery_fraction: + name: hplc_recovery_fraction display_name: HPLC recovery fractions description: | HPLC recovery fractions (the fraction of activity that gets loaded onto the HPLC). diff --git a/src/schema/objects/metadata.yaml b/src/schema/objects/metadata.yaml index 57515dd6f0..5f13c42553 100644 --- a/src/schema/objects/metadata.yaml +++ b/src/schema/objects/metadata.yaml @@ -2023,7 +2023,7 @@ MetaboliteRecoveryCorrectionApplied: description: | Metabolite recovery correction from the HPLC, for tracers where it changes with time postinjection. - If `true`, the `hplc_recovery_fractions` column MUST be present in the + If `true`, the `hplc_recovery_fraction` column MUST be present in the corresponding `*_blood.tsv` file. type: boolean MiscChannelCount: diff --git a/src/schema/rules/tabular_data/pet.yaml b/src/schema/rules/tabular_data/pet.yaml index 8410ee8481..529aa24959 100644 --- a/src/schema/rules/tabular_data/pet.yaml +++ b/src/schema/rules/tabular_data/pet.yaml @@ -15,7 +15,7 @@ Blood: metabolite_polar_fraction: level: optional level_addendum: recommended if `MetaboliteAvail` is `true` - hplc_recovery_fractions: + hplc_recovery_fraction: level: optional level_addendum: required if `MetaboliteRecoveryCorrectionApplied` is `true` whole_blood_radioactivity: @@ -48,7 +48,7 @@ BloodMetaboliteCorrection: - extension == ".tsv" - sidecar.MetaboliteRecoveryCorrectionApplied == true columns: - hplc_recovery_fractions: required + hplc_recovery_fraction: required BloodWholeBlood: selectors: diff --git a/tools/schemacode/bidsschematools/migrations.py b/tools/schemacode/bidsschematools/migrations.py index eae92b1e87..22cac11afb 100644 --- a/tools/schemacode/bidsschematools/migrations.py +++ b/tools/schemacode/bidsschematools/migrations.py @@ -69,7 +69,7 @@ def migrate_tsv_columns(dataset_path: Path): # inheritance principle) for col_from, col_to, file_glob in ( # https://github.com/bids-standard/bids-2-devel/issues/78 - ("hplc_recovery_fractions", "hplc_recovery_fraction", "*_blood.*"), + ("hplc_recovery_fraction", "hplc_recovery_fraction", "*_blood.*"), # https://github.com/bids-standard/bids-2-devel/issues/15 ("units", "unit", "_channels.*"), # dependency on migrate_participants # ??? Any other columns to rename for some reason?