Mercurial > repos > ufz > dfpl_train
annotate json_flatten.py @ 0:e0bb949eac45 draft default tip
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
author | ufz |
---|---|
date | Thu, 19 Dec 2024 12:51:21 +0000 |
parents | |
children |
rev | line source |
---|---|
0
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
1 import json |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
2 from sys import stdin |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
3 |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
4 d = json.load(stdin) |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
5 |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
6 |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
7 def flatten(o: dict): |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
8 d_flat = {} |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
9 for key, value in o.items(): |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
10 if type(value) is dict: |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
11 value = flatten(value) |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
12 for k, v in value.items(): |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
13 d_flat[k] = v |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
14 else: |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
15 d_flat[key] = value |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
16 return d_flat |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
17 |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
18 |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
19 d = flatten(d) |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
20 |
e0bb949eac45
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
ufz
parents:
diff
changeset
|
21 print(json.dumps(d)) |