in lucid/misc/graph_analysis/parse_overlay.py [0:0]
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