allensdk.core.swc module¶
-
class
allensdk.core.swc.
Compartment
(*args, **kwargs)[source]¶ Bases:
dict
A dictionary class storing information about a single morphology node
-
class
allensdk.core.swc.
Marker
(*args, **kwargs)[source]¶ Bases:
dict
Simple dictionary class for handling reconstruction marker objects.
-
CUT_DENDRITE
= 10¶
-
NO_RECONSTRUCTION
= 20¶
-
SPACING
= [0.1144, 0.1144, 0.28]¶
-
-
class
allensdk.core.swc.
Morphology
(compartment_list=None, compartment_index=None)[source]¶ Bases:
object
Keep track of the list of compartments in a morphology and provide a few helper methods (soma, tree information, pruning, etc).
-
APICAL_DENDRITE
= 4¶
-
AXON
= 2¶
-
BASAL_DENDRITE
= 3¶
-
DENDRITE
= 3¶
-
NODE_TYPES
= [1, 2, 3, 3, 4]¶
-
SOMA
= 1¶
-
append
(node_list)[source]¶ Add additional nodes to this Morphology. Those nodes must originate from another morphology object.
Parameters: - node_list: list of Morphology nodes
-
apply_affine
(aff, scale=None)[source]¶ Apply an affine transform to all compartments in this morphology. Node 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
-
change_parent
(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
(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_index
¶ Return the compartment index. This is a property to ensure that the compartment list and compartment index are in sync.
-
compartment_index_by_type
(compartment_type)[source]¶ Return an dictionary of compartments indexed by id that all have a particular compartment type.
Parameters: - compartment_type: int
Desired compartment type
Returns: - A dictionary of Morphology Objects, indexed by ID
-
compartment_list
¶ Return the compartment list. This is a property to ensure that the compartment list and compartment index are in sync.
-
compartment_list_by_type
(compartment_type)[source]¶ Return an list of all compartments having the specified compartment type.
Parameters: - compartment_type: int
Desired compartment type
Returns: - A list of of Morphology Objects
-
convert_type
(old_type, new_type)[source]¶ Converts all compartments from one type to another. Nodes of the original type are not affected so this procedure can also be used as a merge procedure.
Parameters: - old_type: enum
The compartment type to be changed. Use one of the following constants: SOMA, AXON, DENDRITE, BASAL_DENDRITE, or APICAL_DENDRITE
- new_type: enum
The target compartment type. Use one of the following constants: SOMA, AXON, DENDRITE, BASAL_DENDRITE, or APICAL_DENDRITE
-
delete_tree
(n)[source]¶ Delete tree, and all of its compartments, from the morphology.
Parameters: - n: Integer
The tree number to delete
-
find
(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, DENDRITE, BASAL_DENDRITE or APICAL_DENDRITE
Returns: - A list of all Morphology Objects matching the search criteria
-
node
(n)[source]¶ Returns the morphology node having the specified ID.
Parameters: - n: integer
ID of desired node
Returns: - A morphology object having the specified ID, or None if such a
- node doesn’t exist
-
num_nodes
¶ Return the number of compartments in the morphology.
-
num_trees
¶ Return the number of trees in the morphology. A tree is defined as everything following from a single root compartment.
-
parent_of
(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
-
root
¶ [deprecated] Returns root node of soma, if present. Use ‘soma’ instead of ‘root’
-
save
(file_name)[source]¶ Write this morphology out to an SWC file
Parameters: - file_name: string
desired name of your SWC file
-
soma
¶ Returns root node of soma, if present
-
sparsify
(modulo, compress_ids=False)[source]¶ Return a new Morphology object that has a given number of non-leaf, non-root nodes removed. IDs can be reassigned so as to be continuous.
Parameters: - modulo: int
keep 1 out of every modulo nodes.
- compress_ids: boolean
Reassign ids so that ids are continuous (no missing id numbers).
Returns: - Morphology
A new morphology instance
-
strip_all_other_types
(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 compartment type to keep in the morphology. Use one of the following constants: SOMA, AXON, DENDRITE, 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
(node_type)[source]¶ Strips all compartments of the specified type from the morphology. Parent and child relationships are updated accordingly, creating new roots when necessary.
Parameters: - node_type: enum
The compartment type to strip from the morphology. Use one of the following constants: SOMA, AXON, DENDRITE, BASAL_DENDRITE, or APICAL_DENDRITE
-
stumpify_axon
(count=10)[source]¶ Remove all axon compartments except the first ‘count’ nodes, as counted from the connected axon root.
Parameters: - count: Integer
The length of the axon ‘stump’, in number of compartments
-
tree
(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
-