code: def parse_structure(node):
      """Turn a collapsed node in an OverlayGraph into a heirchaical grpah structure."""
      if node is None:
          return None
  
      structure = node.sub_structure
  
      if structure is None:
          return {"type": "Node", "name": node.name}
      elif structure.structure_type == "Sequence":
          return {
              "type": "Sequence",
              "children": [
                  parse_structure(n)
                  for n in structure.structure["sequence"]
              ],
          }
      elif structure.structure_type == "HeadBranch":
          return {
              "type": "Sequence",
              "children": [
                  {
                      "type": "Branch",
                      "children": [
                          parse_structure(n)
                          for n in structure.structure["branches"]
                      ],
                  },
                  parse_structure(structure.structure["head"]),
              ],
          }
      elif structure.structure_type == "TailBranch":
          return {
              "type": "Sequence",
              "children": [
                  parse_structure(structure.structure["tail"]),
                  {
                      "type": "Branch",
                      "subtype": "AuxilliaryHeadBranch",
                      "children": [
                          parse_structure(n)
                          for n in structure.structure["branches"]
                      ],
                  },
              ],
          }
      else:
          data = {}
          for k in structure.structure:
              if isinstance(structure.structure[k], list):
                  data[k] = [
                      parse_structure(n) for n in structure.structure[k]
                  ]
              else:
                  data[k] = parse_structure(structure.structure[k])
  
          data["type"] = structure.structure_type
          return data
  
file_path: lucid/lucid/misc/graph_analysis/parse_overlay.py
imports: from lucid.misc.graph_analysis.overlay_graph import OverlayGraph, OverlayNode, OverlayStructure
label_desc: Use image node_id 3 for calling a global function with example usage: parse_structure(node) and returns: None, dict, dict, dict, dict, data