SWC Export and Cycles¶
SWC is inherently a tree format, but MASCAF can handle morphologies with topological cycles.
MASCAF keeps arbitrary graph topology in memory via
MorphologyGraph and only enforces a tree when
writing SWC, by duplicating nodes where necessary.
For each broken cycle a directive is written to the SWC file header:
# CYCLE_BREAK <node_id> <parent_id>
When you later reload the file with
from_swc_file(), MASCAF reads
these annotations and reconnects the duplicated nodes to restore the original
cycle topology.
Example¶
from mascaf import MorphologyGraph
# Save — cycles are broken, CYCLE_BREAK annotations written
morphology.to_swc_file("neuron.swc")
# Reload — cycles are automatically restored from annotations
restored = MorphologyGraph.from_swc_file("neuron.swc")