code: def flatten_sequences(structure):
      """Flatten nested sequences into a single sequence."""
      if (
          isinstance(structure, str)
          or (
              isinstance(structure, dict)
              and structure["type"] == "Node"
          )
          or structure is None
      ):
          return structure
      else:
          structure = structure.copy()
          if "children" in structure:
              structure["children"] = [
                  flatten_sequences(sub)
                  for sub in structure["children"]
              ]
  
      if structure["type"] == "Sequence":
          new_seq = []
          for sub in structure["children"]:
              if isinstance(sub, dict) and sub["type"] == "Sequence":
                  new_seq += sub["children"]
              else:
                  new_seq.append(sub)
          structure["children"] = new_seq
      return structure
  
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 4 for calling a global function with example usage: flatten_sequences(structure) and returns: structure, structure