Skip to content

Commit

Permalink
Merge pull request #13 from FZJ-INM1-BDA/test_addNameDuplCheck
Browse files Browse the repository at this point in the history
Check duplicate names and IDs in parcellations
  • Loading branch information
AhmetNSimsek authored Dec 13, 2024
2 parents 5391498 + 8e1c70c commit d869287
Show file tree
Hide file tree
Showing 9 changed files with 510 additions and 943 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/check-region-id-uniqueness.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: '[test] check region id uniqueness'

on:
push:
paths:
- 'parcellations/**.json'

jobs:
check_region_id_uniqueness:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: checkout siibra-python
uses: actions/checkout@v4
with:
repository: FZJ-INM1-BDA/siibra-python
path: siibra-python-${{ github.run_id }}-${{ github.run_number }}
fetch-depth: 1
clean: True
ref: 'main'

- name: move siibra-python one up from workspace
run: mv siibra-python-${{ github.run_id }}-${{ github.run_number }} ../siibra-python

- name: Install siibra-python testing requirements
run: |
pip install -r ../siibra-python/requirements-test.txt
pip install -r ../siibra-python/requirements.txt
- name: region id uniqueness test
run: |
export SIIBRA_USE_CONFIGURATION='./'
pytest ../siibra-python/e2e/core/test_parcellation.py::test_parc_id_uniqueness
pytest ../siibra-python/e2e/core/test_parcellation.py::test_region_id_uniqueness
15 changes: 15 additions & 0 deletions .github/workflows/test-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,18 @@ jobs:
pip install -r _ci/requirements.txt
- name: Verify neuroglancer urls
run: python _ci/verify_neuroglancer_urls.py

ensure_no_duplicated_region_name:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install requirements
run: |
pip install -U pip
pip install -r _ci/requirements.txt
- name: Verify no duplicated region name
run: python _ci/ensure_no_duplicated_region_name.py
77 changes: 77 additions & 0 deletions _ci/ensure_no_duplicated_region_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from pathlib import Path
import json
from dataclasses import dataclass

@dataclass
class DuplicatedErr:
filename: str
key: str

def __eq__(self, other: "DuplicatedErr"):
return self.filename == other.filename and self.key == other.key


class DuplicatedRegionName(Exception):
pass


FAIL_FAST = False

# There is no solution for the following
XFAIL_LIST = [
DuplicatedErr(filename='parcellations\\rat_waxholmv1_01.json', key='corticofugal pathways'),
DuplicatedErr(filename='parcellations\\rat_waxholmv1_01.json', key='medial lemniscus'),
DuplicatedErr(filename='parcellations\\rat_waxholmv1_01.json', key='facial nerve'),
DuplicatedErr(filename='parcellations\\rat_waxholmv1_01.json', key='spinal cord'),
DuplicatedErr(filename='parcellations\\rat_waxholmv2.json', key='corticofugal pathways'),
DuplicatedErr(filename='parcellations\\rat_waxholmv2.json', key='medial lemniscus'),
DuplicatedErr(filename='parcellations\\rat_waxholmv2.json', key='facial nerve'),
DuplicatedErr(filename='parcellations\\rat_waxholmv2.json', key='spinal cord'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='anterior commissure'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='medial lemniscus'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='facial nerve'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='lateral lemniscus'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='neocortex'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='thalamus'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='brainstem'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='ventricular system'),
DuplicatedErr(filename='parcellations\\rat_waxholmv3.json', key='spinal cord'),
]

def iterate_over_children(r):
yield r
for c in r.get("children", []):
for cc in iterate_over_children(c):
yield cc


def main():
errors = []
_dir = Path("parcellations")
for _file in _dir.glob("*.json"):
reg_name_set = set()
with open(_file, "r", encoding="utf-8") as fp:
parc_json = json.load(fp)
all_regions = [
rc for r in parc_json.get("regions") for rc in iterate_over_children(r)
]
for reg in all_regions:
reg_name = reg.get("name")
if reg_name.lower() in reg_name_set:
error = DuplicatedErr(filename=str(_file), key=reg_name)
if error in XFAIL_LIST:
print(f"xfail: {error}")
continue
errors.append(error)
if FAIL_FAST:
raise DuplicatedRegionName(
"\n".join([str(err) for err in errors])
)
reg_name_set.add(reg_name.lower())

if len(errors) > 0:
raise DuplicatedRegionName("\n".join([str(err) for err in errors]))


if __name__ == "__main__":
main()
Loading

0 comments on commit d869287

Please sign in to comment.