jaxley.io.graph.build_compartment_graph#
- build_compartment_graph(swc_graph, ncomp, root=None, min_radius=None, max_len=None, ignore_swc_tracing_interruptions=True, relevant_type_ids=None)[source]#
Return a networkX graph that indicates the compartment structure.
Build a new graph made up of compartments in every branch. These compartments are spaced at equidistant points along the branch. Node attributes, like radius are linearly interpolated along its length.
Example: 4 compartments | edges = - | nodes = o | comp_nodes = x o———–o———-o—o—o—o——–o o——-x—o—-x—–o–xo—o—ox——-o
This function returns a _directed_ graph. The graph is directed only because every compartment tracks the xyzr coordinates of the associated SWC file. These xyzr coordinates are ordered by the order of the traversal of the swc_graph. In later methods (e.g. build_solve_graph), we traverse the comp_graph and mostly ignore the directionality of the edges, but we only use the directionality to reverse the xyzr coordinates if necessary.
- Parameters:
swc_graph (DiGraph) – Graph generated by to_swc_graph().
ncomp (int) – How many compartments per branch to insert.
root (int | None) – The root branch from which to start tracing the nodes. This defines the branch indices.
min_radius (float | None) – Minimal radius for each compartment.
max_len – Maximal length for each branch. Longer branches are split into separate branches.
ignore_swc_tracing_interruptions – If False, it this function automatically starts a new branch when a section is traced with interruptions.
relevant_type_ids (List[int] | None) – All type ids that are not in this list will be ignored for tracing the morphology. This means that branches which have multiple type ids (which are not in relevant_type_ids) will be considered as one branch. If None, we default to [1, 2, 3, 4].
- Returns:
Directed graph made up of compartments.
Compartment nodes have attributes (example): {‘x’: 2.0, ‘y’: 0.0, ‘z’: 0.0, ‘branch_index’: 2, ‘comp_index’: 2, ‘type’: ‘comp’, ‘xyzr’: array([[0., 0., 0., 1.], [1., 0., 0., 1.]]), ‘groups’: [‘soma’], ‘radius’: 1.0, ‘length’: 4.0, ‘cell_index’: 0}
Between-compartment nodes have attributes: {‘x’: 0.0, ‘y’: 0.0, ‘z’: 0.0, ‘p’: -1, ‘type’: ‘branchpoint’, ‘groups’: [‘soma’], ‘radius’: 1.0, ‘length’: 0.0, ‘cell_index’: 0}
Edges have attributes: {}
- Return type:
DiGraph
Example usage#
from jaxley.io.graph to_swc_graph, build_compartment_graph swc_graph = to_swc_graph("path_to_swc.swc") comp_graph = build_compartment_graph(swc_graph, ncomp=1)