SWC specification
The SWC data format specification used by the treem package.
Format
Plain-text file with 7-column tabular data (one node per line).
Lines starting with
#are comments (ignored).Structure:
<I> <T> <X> <Y> <Z> <R> <P>
Field |
Column |
Description |
Values |
|---|---|---|---|
I |
0 |
Node ID |
int: 1 (root), 2, 3, … |
T |
1 |
Point type |
int: 1 (soma), 2 (axon), 3 (dend), 4 (apic) |
X/Y/Z |
2/3/4 |
Coordinates |
float (micrometers) |
R |
5 |
Radius |
float (micrometers) |
P |
6 |
Parent node ID |
int: -1 (parent of root), 1, 2, … |
Rules
Node IDs:
Start at 1, increment sequentially by 1.
Unique, positive integers.
Root:
Exactly one root:
I=1,T=1,P=-1.
Parent-child:
All non-root nodes have only one parent and
P < I(no loops).Parent IDs must exist in the file (except
P=-1for root).
Soma (type 1):
Must be represented as one of the following:
Single node (root only).
Single section starting from the root.
Two sections from root (e.g., 3-point soma).
Non-somatic nodes (types 2/3/4):
Each non-soma branch (neurite) originates in root.
Non-soma branches must maintain consistent type
Pwithin a branch. First node of a neurite (stem) has parent root.
Validity:
File must have >=1 data rows.
T in {1, 2, 3, 4}(other types invalidate the file).
Terminology
Term |
Definition |
|---|---|
Tree |
Hierarchical structure with no loops. Each node has <=1 parent. |
Branch |
A maximal sub-tree of the same type |
Node |
Single SWC line (point in 3D). |
Root |
Node with no parent ( |
Child |
Node with a parent. |
Parent |
Node with >=1 child. |
Leaf |
Node with no children (degree=0). |
Fork |
Non-root node with >1 child (degree>1). Bifurcation if degree=2. |
Depth |
Ancestor count from root (root depth=0). |
Height |
Max edges from node to any leaf in its sub-tree. |
Size |
Total nodes in (sub-)tree. |
Breadth |
Total leaves in (sub-)tree. |
Width |
Nodes at same depth as current node. |
Segment |
Line connecting two nodes (parent and child). |
Section |
Continuous chain of segments between fork/root/leaf nodes. |
Stem |
First node of non-somatic branch. |