allensdk.internal.morphology.morphology module¶
-
class
allensdk.internal.morphology.morphology.
Morphology
(node_list=None)[source]¶ Bases:
object
Keep track of the list of nodes in a morphology and provide a few helper methods (soma, tree information, pruning, etc).
-
APICAL_DENDRITE
= 4¶
-
AXON
= 2¶
-
BASAL_DENDRITE
= 3¶
-
NODE_TYPES
= [1, 2, 3, 4]¶
-
SOMA
= 1¶
-
append
(self, nodes)[source]¶ Add additional nodes to this Morphology. Those nodes must originate from another morphology object.
Parameters: - nodes: list of Morphology nodes
-
apply_affine
(self, aff, scale=None)[source]¶ Apply an affine transform to all nodes in this morphology. Compartment radius is adjusted as well.
Format of the affine matrix is:
[x0 y0 z0] [tx] [x1 y1 z1] [ty] [x2 y2 z2] [tz]
where the left 3x3 the matrix defines the affine rotation and scaling, and the right column is the translation vector.
The matrix must be collapsed and stored in a list as follows:
[x0 y0, z0, x1, y1, z1, x2, y2, z2, tx, ty, tz]
Parameters: - aff: 3x4 array of floats (python 2D list, or numpy 2D array)
the transformation matrix
-
apply_affine_only_rotation
(self, aff)[source]¶ Apply an affine transform to all nodes in this morphology. Only the rotation element of the transform is performed (i.e., although the entire transformation and translation matrix is supplied, only the rotation element is used). The morphology is translated to the point where the soma root is at 0,0,0.
Format of the affine matrix is:
[x0 y0 z0] [tx] [x1 y1 z1] [ty] [x2 y2 z2] [tz]
where the left 3x3 the matrix defines the affine rotation and scaling, and the right column is the translation vector.
The matrix must be collapsed and stored in a list as follows:
[x0 y0, z0, x1, y1, z1, x2, y2, z2, tx, ty, tz]
Parameters: - aff: 3x4 array of floats (python 2D list, or numpy 2D array)
the transformation matrix
-
change_parent
(self, child, parent)[source]¶ Change the parent of a node. The child node is adjusted to point to the new parent, the child is taken off of the previous parent’s child list, and it is added to the new parent’s child list.
Parameters: - child: integer or Morphology Object
The ID of the child node, or the child node itself
- parent: integer or Morphology Object
The ID of the parent node, or the parent node itself
Returns: - Nothing
-
children_of
(self, seg)[source]¶ Returns a list of the children of the specified node
Parameters: - seg: integer or Morphology Object
The ID of the parent node, or the parent node itself
Returns: - A list of the child morphology objects. If the ID of the parent
- node is invalid, None is returned.
-
compartment
(self, n)[source]¶ Returns the morphology Compartment having the specified ID.
Parameters: - n: integer
ID of desired compartment
Returns: - A morphology object having the specified ID, or None if such a
- node doesn’t exist
-
compartment_list
¶
-
convert_type
(self, from_type, to_type)[source]¶ Convert all nodes in morphology from one type to another
Parameters: - from_type: enum
The node type that will be eliminated and replaced. Use one of the following constants: SOMA, AXON, BASAL_DENDRITE, or APICAL_DENDRITE
- to_type: enum
The new type that will replace it. Use one of the following constants: SOMA, AXON, BASAL_DENDRITE, or APICAL_DENDRITE
-
delete_tree
(self, n)[source]¶ Delete tree, and all of its nodes, from the morphology.
Parameters: - n: Integer
The tree number to delete
-
find
(self, x, y, z, dist, node_type=None)[source]¶ Returns a list of Morphology Objects located within ‘dist’ of coordinate (x,y,z). If node_type is specified, the search will be constrained to return only nodes of that type.
Parameters: - x, y, z: float
The x,y,z coordinates from which to search around
- dist: float
The search radius
- node_type: enum (optional)
One of the following constants: SOMA, AXON, BASAL_DENDRITE or APICAL_DENDRITE
Returns: - A list of all Morphology Objects matching the search criteria
-
get_dimensions
(self)[source]¶ Returns tuple of overall width, height and depth of morphology. WARNING: if locations of nodes in morphology are manipulated then this value can become incorrect. It can be reset and recalculated by programmitcally setting self.dims to None.
Returns: - 3 real arrays: [width, height, depth], [min_x, min_y, min_z],
- [max_x, max_y, max_z]
-
node
(self, n)[source]¶ Returns the morphology node having the specified ID.
Parameters: - n: integer
ID of desired node
Returns: - A morphology node having the specified ID, or None if such a
- node doesn’t exist
-
node_list
¶ Return the node list. This is a property to ensure that the node list and node index are in sync.
-
node_list_by_type
(self, node_type)[source]¶ Return an list of all nodes having the specified node type.
Parameters: - node_type: int
Desired node type
Returns: - A list of of Morphology Objects
-
num_nodes
¶ Return the number of nodes in the morphology.
-
num_trees
¶ Return the number of trees in the morphology. A tree is defined as everything following from a single root node.
-
parent_of
(self, seg)[source]¶ Returns parent of the specified node.
Parameters: - seg: integer or Morphology Object
The ID of the child node, or the child node itself
Returns: - A morphology object, or None if no parent exists or if the
- specified node ID doesn’t exist
-
save
(self, file_name)[source]¶ Write this morphology out to an SWC file
Parameters: - file_name: string
desired name of your SWC file
-
sparsify
(self, modulo)[source]¶ Return a new Morphology object that has a given number of non-leaf, non-root nodes removed.
Parameters: - modulo: int
keep 1 out of every modulo nodes.
Returns: - Morphology
A new morphology instance
-
strip_all_other_types
(self, node_type, keep_soma=True)[source]¶ Strips everything from the morphology except for the specified type. Parent and child relationships are updated accordingly, creating new roots when necessary.
Parameters: - node_type: enum
The node type to keep in the morphology. Use one of the following constants: SOMA, AXON, BASAL_DENDRITE, or APICAL_DENDRITE
- keep_soma: Boolean (optional)
True (default) if soma nodes should remain in the morpyhology, and False if the soma should also be stripped
-
strip_type
(self, node_type)[source]¶ Strips all nodes of the specified type from the morphology. Parent and child relationships are updated accordingly, creating new roots when necessary.
Parameters: - node_type: enum
The node type to strip from the morphology. Use one of the following constants: SOMA, AXON, BASAL_DENDRITE, or APICAL_DENDRITE
-
stumpify_axon
(self, count=10)[source]¶ Remove all axon nodes except the first ‘count’ nodes, as counted from the connected axon root.
Parameters: - count: Integer
The length of the axon ‘stump’, in number of nodes
-
to_dict
(self)[source]¶ Returns a dictionary of Node objects. These Nodes are a copy of the Morphology. Modifying them will not modify anything in the Morphology itself.
-
tree
(self, n)[source]¶ Returns a list of all Morphology nodes within the specified tree. A tree is defined as a fully connected graph of nodes. Each tree has exactly one root.
Parameters: - n: integer
ID of desired tree
Returns: - A list of all morphology objects in the specified tree, or None
- if the tree doesn’t exist
-