Segment tree¶
- class dendrotweaks.morphology.seg_trees.Segment(idx, parent_idx, sim_seg, section)[source]¶
Bases:
Node
A class representing a segment.
A segment is a part of a section used to discretize the section in space for the purpose of numerical simulations.
- Parameters:
idx (int) – The index of the segment.
parent_idx (int) – The index of the parent segment.
sim_seg (h.Segment) – The segment object from a simulator (e.g. NEURON).
section (Section) – The section to which the segment belongs.
- _ref¶
The segment object from a simulator (e.g. NEURON).
- Type:
h.Segment
- property domain¶
The morphological or functional domain of the segment.
- property subtree_size¶
The number of sections in the subtree rooted at the segment.
- property Ra¶
The axial resistance of the segment (from NEURON).
- property distance¶
- property domain_distance¶
- set_param_value(param_name, value)[source]¶
Set the value of a parameter of the segment.
- Parameters:
param_name (str) – The name of the parameter to set.
value (float) – The value to set the parameter to.
- get_param_value(param_name)[source]¶
Get the value of a parameter of the segment.
- Parameters:
param_name (str) – The name of the parameter to get.
- Returns:
The value of the parameter.
- Return type:
float
- connect_to_parent(parent)¶
Attach the node to a parent node.
Warning
This method should not be used directly when working with trees as it doesn’t add the node to the tree’s list of nodes. Use the Tree class to insert nodes into the tree.
- Args:
parent (Node): The parent node to attach the node to.
- property depth¶
Computes the depth of the node in the tree iteratively.
- disconnect_from_parent()¶
Detach the node from its parent.
Examples
for child in node.children: child.disconnect_from_parent()
- property nearest_neighbours¶
Gets the nearest neighbours of the node.
- Returns:
A list of nodes that share the same parent or children as the node.
- Return type:
list
- property parent¶
- property siblings¶
Gets the siblings of the node.
- Returns:
A list of nodes that share the same parent as the node.
- Return type:
list
- property subtree: list¶
Gets the subtree of the node (including the node itself) using an iterative depth-first traversal.
- Returns:
A list of nodes in the subtree.
- Return type:
list
- property topological_type: str¶
The topological type of the node based on the number of children.
- Returns:
The topological type of the node: ‘continuation’, ‘bifurcation’, or ‘termination’.
- Return type:
str
- class dendrotweaks.morphology.seg_trees.SegmentTree(segments: list[Segment])[source]¶
Bases:
Tree
A class representing a tree graph of segments.
- property segments¶
The segments in the segment tree. Alias for self._nodes
- add_subtree(node, parent)¶
Add a subtree to the tree.
- property bifurcations¶
The bifurcation nodes in the tree.
- Returns:
A list of bifurcation nodes in the tree.
- Return type:
list
- property edges: list¶
Returns a list of edges in the tree.
- insert_node_after(new_node, existing_node)¶
Insert a node after a given node in the tree.
- insert_node_before(new_node, existing_node)¶
Insert a node before a given node in the tree.
- property is_connected¶
Whether the tree is connected i.e. each node can be reached from the root.
- Returns:
bool – True if the root node’s subtree contains exactly the same nodes
as the entire tree. False otherwise.
- property is_sorted¶
Whether the nodes in the tree are sorted by index.
- Returns:
True if the nodes are sorted by index. False otherwise.
- Return type:
bool
- remove_node(node)¶
Remove a node from the tree.
- Parameters:
node (Node) – The node to remove.
- Raises:
ValueError – If the tree is not sorted.
- remove_subtree(node)¶
Remove a subtree from the tree.
- Parameters:
node (Node) – The root node of the subtree to remove.
- reposition_subtree(node, new_parent_node, origin=None)¶
Reposition a subtree in the tree.
- Parameters:
Note
Treats differently the children of the root node.
- sort(sort_children=True, force=False)¶
Sort the nodes in the tree using a stack-based depth-first traversal.
- Parameters:
sort_children (bool, optional) – Whether to sort the children of each node based on the number of bifurcations in their subtrees. Defaults to True.
force (bool, optional) – Whether to force the sorting of the tree even if it is already sorted. Defaults to False.
- property terminations¶
- topology()¶
Print the topology of the tree with a visual tree structure.