-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from FZJ-INM1-BDA/test_addNameDuplCheck
Check duplicate names and IDs in parcellations
- Loading branch information
Showing
9 changed files
with
510 additions
and
943 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.