Browse Source

modify parseilf file

Xiao Gui 3 years ago
parent
commit
28f14a89ec
1 changed files with 15 additions and 8 deletions
  1. 15 8
      code/parse-ilf.py

+ 15 - 8
code/parse-ilf.py

@@ -1,13 +1,12 @@
 import xml.etree.ElementTree as ET
 import os
+import re
 
-path_to_metadata='./output/metadata/'
+path_to_input_meta='./neuroglancer-scripts-input/metadata'
+path_to_metadata='./output/metadata'
 
 os.makedirs(path_to_metadata,exist_ok=True)
 
-path_to_ifl="./neuroglancer-scripts-input/metadata/ilf.ilf"
-path_to_region=f"{path_to_metadata}regions.json"
-
 def get_rgb_from_hex(hex=None):
   if hex is None:
     return None
@@ -35,13 +34,14 @@ def process_label(label, parent=None):
   
   for l in label:
     process_label(l, node)
-  
 
-def main():
+def process_ilf_file(filename):
+  stripped_name=re.sub(r'.ilf$', '', filename)
+  path_to_ifl=f'{path_to_input_meta}/{filename}'
   ilf=ET.parse(path_to_ifl)
 
   root_node={
-    'name': 'Whole brain',
+    'name': 'Root',
     'rgb': None,
     'labelIndex': None,
     'children': []
@@ -50,10 +50,17 @@ def main():
   structure=ilf.find('structure')
   for label in structure:
     process_label(label, root_node)
-  
+
+  path_to_region=f"{path_to_metadata}/{stripped_name}.regions.json"
   with open(path_to_region, 'w') as fp:
     import json
     json.dump(root_node, fp, indent=2)
+  pass  
+
+def main():
+  is_ilf = re.compile(r'.ilf$')
+  for f in [f for f in os.listdir(path_to_input_meta) if is_ilf.search(f)]:
+    process_ilf_file(f)
 
 if __name__ == '__main__':
   main()