def test_add_child(): t = Tree(0) t.add_child(Tree(11)) t.add_child(Tree(22)) nt.ok_(t.value == 0) nt.ok_(len(t.children) == 2) nt.ok_([i.value for i in t.children] == [11, 22])
def test_is_forking_point(): t = Tree() t.add_child(Tree()) t.add_child(Tree()) nt.ok_(t.is_forking_point()) t.add_child(Tree()) nt.ok_(t.is_forking_point())
def test_is_forking_point(): t = Tree(0) t.add_child(Tree(1)) t.add_child(Tree(2)) nt.ok_(is_forking_point(t)) t.add_child(Tree(3)) nt.ok_(is_forking_point(t))
def test_is_bifurcation_point_false(): t = Tree(0) nt.ok_(not is_bifurcation_point(t)) t.add_child(Tree(1)) nt.ok_(not is_bifurcation_point(t)) t.add_child(Tree(2)) t.add_child(Tree(3)) nt.ok_(not is_bifurcation_point(t))
def test_is_bifurcation_point_false(): t = Tree() nt.ok_(not t.is_bifurcation_point()) t.add_child(Tree()) nt.ok_(not t.is_bifurcation_point()) t.add_child(Tree()) t.add_child(Tree()) nt.ok_(not t.is_bifurcation_point())
def test_parent(): t = Tree(0) for i in xrange(10): t.add_child(Tree(i)) nt.ok_(len(t.children) == 10) for c in t.children: nt.ok_(c.parent is t)
def _create_root_soma_tree(neuron): ''' soma segment to represent the soma as a square of radius equal to the soma one ''' soma_radius = neuron.get_soma_radius() soma_node0 = Tree((0., 0., 0., soma_radius, 1.)) soma_node1 = Tree((soma_radius, 0., 0., soma_radius, 1.)) soma_node0.add_child(soma_node1) return soma_node0
def _make_simple_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 1] T = Tree(p) T1 = T.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 1])) T2 = T1.add_child(Tree([2.0, 2.0, 0.0, 1.0, 1, 1, 1])) T3 = T2.add_child(Tree([2.0, 6.0, 0.0, 1.0, 1, 1, 1])) T5 = T.add_child(Tree([0.0, 0.0, 2.0, 1.0, 1, 1, 1])) T6 = T5.add_child(Tree([2.0, 0.0, 2.0, 1.0, 1, 1, 1])) T7 = T6.add_child(Tree([6.0, 0.0, 2.0, 1.0, 1, 1, 1])) return T
def _form_simple_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 1] T = Tree(p) T1 = T.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 1])) T2 = T1.add_child(Tree([0.0, 4.0, 0.0, 1.0, 1, 1, 1])) T3 = T2.add_child(Tree([0.0, 6.0, 0.0, 1.0, 1, 1, 1])) T4 = T3.add_child(Tree([0.0, 8.0, 0.0, 1.0, 1, 1, 1])) T5 = T.add_child(Tree([0.0, 0.0, 2.0, 1.0, 1, 1, 1])) T6 = T5.add_child(Tree([0.0, 0.0, 4.0, 1.0, 1, 1, 1])) T7 = T6.add_child(Tree([0.0, 0.0, 6.0, 1.0, 1, 1, 1])) T8 = T7.add_child(Tree([0.0, 0.0, 8.0, 1.0, 1, 1, 1])) return T
def test_principal_direction_extent(): points = np.array([[-10., 0., 0.], [-9., 0., 0.], [9., 0., 0.], [10., 0., 0.]]) tree = Tree(np.array([points[0][0], points[0][1], points[0][2], 1., 0., 0.])) tree.add_child(Tree(np.array([points[1][0], points[1][1], points[1][2], 1., 0., 0.]))) tree.children[0].add_child(Tree(np.array([points[2][0], points[2][1], points[2][2], 1., 0., 0.]))) tree.children[0].add_child(Tree(np.array([points[3][0], points[3][1], points[3][2], 1., 0., 0.]))) extent = mtr.principal_direction_extent(tree) nt.assert_true(np.allclose(extent, [20., 0., 0.]))
def _create_root_soma_tree(neuron): ''' soma segment to represent the soma as a square of radius equal to the soma one ''' soma_radius = neuron.get_soma_radius() soma_center = neuron.soma.center soma_node0 = Tree((soma_center[0] - soma_radius, soma_center[1], soma_center[2], soma_radius, 1.)) soma_node1 = Tree( (soma_center[0], soma_center[1], soma_center[2], soma_radius, 1.)) soma_node0.add_child(soma_node1) return soma_node0
def _make_tree(): '''This tree has 3 branching points''' p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = Tree(p) T1 = T.add_child(Tree([0.0, 1.0, 0.0, 2.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 3.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 4.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 5.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 6.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 7.0, 1, 1, 2])) return T
def _form_neuron_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = Tree(p) T1 = T.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) return T
def _make_neuron_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = Tree(p) T1 = T.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) return T
def _form_branching_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = Tree(p) T1 = T.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) T11 = T9.add_child(Tree([0.0, 6.0, 4.0, 0.75, 1, 1, 2])) T33 = T3.add_child(Tree([1.0, 5.0, 0.0, 2.0, 1, 1, 2])) T331 = T33.add_child(Tree([15.0, 15.0, 0.0, 2.0, 1, 1, 2])) return T
def _make_branching_tree(): '''This tree has 3 branching points''' p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = Tree(p) T1 = T.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) T11 = T9.add_child(Tree([0.0, 6.0, 4.0, 0.75, 1, 1, 2])) T33 = T3.add_child(Tree([1.0, 5.0, 0.0, 2.0, 1, 1, 2])) T331 = T33.add_child(Tree([15.0, 15.0, 0.0, 2.0, 1, 1, 2])) return T
def test_add_child(): t = Tree() ch11 = t.add_child(Tree()) ch22 = t.add_child(Tree()) nt.ok_(len(t.children) == 2) nt.ok_(t.children == [ch11, ch22])
def test_is_root_false(): t = Tree(0) t.add_child(Tree(1)) nt.ok_(not is_root(t.children[0]))
def test_is_leaf_false(): t = Tree(0) t.add_child(Tree(1)) nt.ok_(not is_leaf(t))
def test_is_root_false(): t = Tree() t.add_child(Tree()) nt.ok_(not t.children[0].is_root())
def test_is_bifurcation_point(): t = Tree() t.add_child(Tree()) t.add_child(Tree()) nt.ok_(t.is_bifurcation_point())
def test_is_forking_point_false(): t = Tree() nt.ok_(not t.is_forking_point()) t.add_child(Tree()) nt.ok_(not t.is_forking_point())
DATA_PATH = './test_data' SWC_PATH = os.path.join(DATA_PATH, 'swc/') data = load_data(SWC_PATH + 'Neuron.swc') neuron0 = make_neuron(data) tree0 = neuron0.neurites[0] tree_types = [TreeType.axon, TreeType.basal_dendrite, TreeType.basal_dendrite, TreeType.apical_dendrite] # Mock tree holding integers, not points MOCK_TREE = Tree(0) MOCK_TREE.add_child(Tree(11)) MOCK_TREE.add_child(Tree(12)) MOCK_TREE.children[0].add_child(Tree(111)) MOCK_TREE.children[0].add_child(Tree(112)) MOCK_TREE.children[1].add_child(Tree(121)) MOCK_TREE.children[1].add_child(Tree(122)) MOCK_TREE.children[1].children[0].add_child(Tree(1211)) MOCK_TREE.children[1].children[0].children[0].add_child(Tree(12111)) MOCK_TREE.children[1].children[0].children[0].add_child(Tree(12112)) T1111 = MOCK_TREE.children[0].children[0].add_child(Tree(1111)) T11111 = T1111.add_child(Tree(11111)) T11112 = T1111.add_child(Tree(11112)) T11113 = T1111.add_child(Tree(11113)) def _form_neuron_tree():
[11, 22, 33, 44, 4, 1, 3], [11, 22, 33, 44, 5, 1, 4], [11, 22, 33, 44, 6, 1, 5] ] INVALID_PTS_0 = [] INVALID_PTS_2 = [ [11, 22, 33, 44, 1, 1, -1], [11, 22, 33, 44, 2, 1, 1] ] TREE = Tree([0.0, 0.0, 0.0, 1.0, 1, 1, 2] ) T1 = TREE.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) def test_make_SomaA(): soma = neuron.make_soma(SOMA_A_PTS) nt.ok_('SomaA' in str(soma)) nt.ok_(isinstance(soma, neuron.SomaA)) nt.assert_equal(soma.center, (11, 22, 33))
def test_is_bifurcation_point(): t = Tree(0) t.add_child(Tree(1)) t.add_child(Tree(2)) nt.ok_(is_bifurcation_point(t))
def test_is_leaf_false(): t = Tree() t.add_child(Tree()) nt.ok_(not t.is_leaf())
[11, 22, 33, 44, 4, 1, 3], [11, 22, 33, 44, 5, 1, 4], [11, 22, 33, 44, 6, 1, 5] ] INVALID_PTS_0 = [] INVALID_PTS_2 = [ [11, 22, 33, 44, 1, 1, -1], [11, 22, 33, 44, 2, 1, 1] ] TREE = Tree([0.0, 0.0, 0.0, 1.0, 1, 1, 2] ) T1 = TREE.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) def test_make_SomaA(): soma = neuron.make_soma(SOMA_A_PTS) nt.ok_('SomaA' in str(soma)) nt.ok_(isinstance(soma, neuron.SomaA)) nt.assert_items_equal(soma.center, (11, 22, 33))
def test_is_forking_point_false(): t = Tree(0) nt.ok_(not is_forking_point(t)) t.add_child(Tree(1)) nt.ok_(not is_forking_point(t))
def test_trunk_length(): t = Tree((0, 0, 0, 42)) tt = t.add_child(Tree((10, 0, 0, 4))) tt.add_child(Tree((10, 15, 0, 4))) nt.assert_almost_equal(trunk_length(t), 25.0)
from neurom.core.tree import is_bifurcation_point from neurom.core.tree import ipreorder from neurom.core.tree import ipostorder from neurom.core.tree import iupstream from neurom.core.tree import isegment from neurom.core.tree import ileaf from neurom.core.tree import itriplet from neurom.core.tree import iforking_point from neurom.core.tree import ibifurcation_point from neurom.core.tree import isection from neurom.core.tree import val_iter from neurom.core.tree import i_branch_end_points from copy import deepcopy REF_TREE = Tree(0) REF_TREE.add_child(Tree(11)) REF_TREE.add_child(Tree(12)) REF_TREE.children[0].add_child(Tree(111)) REF_TREE.children[0].add_child(Tree(112)) REF_TREE.children[1].add_child(Tree(121)) REF_TREE.children[1].add_child(Tree(122)) REF_TREE.children[1].children[0].add_child(Tree(1211)) REF_TREE.children[1].children[0].children[0].add_child(Tree(12111)) REF_TREE.children[1].children[0].children[0].add_child(Tree(12112)) REF_TREE2 = deepcopy(REF_TREE) T1111 = REF_TREE2.children[0].children[0].add_child(Tree(1111)) T11111 = T1111.add_child(Tree(11111)) T11112 = T1111.add_child(Tree(11112)) T11113 = T1111.add_child(Tree(11113))
def test_trunk_radius(): t = Tree((0, 0, 0, 42)) t.add_child(Tree((1, 0, 0, 4))) nt.assert_equal(trunk_radius(t), 42.0)
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys from nose import tools as nt from neurom.core.tree import Tree REF_TREE = Tree() T11 = REF_TREE.add_child(Tree()) T12 = REF_TREE.add_child(Tree()) T111 = REF_TREE.children[0].add_child(Tree()) T112 = REF_TREE.children[0].add_child(Tree()) T121 = REF_TREE.children[1].add_child(Tree()) T122 = REF_TREE.children[1].add_child(Tree()) T1211 = REF_TREE.children[1].children[0].add_child(Tree()) T12111 = REF_TREE.children[1].children[0].children[0].add_child(Tree()) T12112 = REF_TREE.children[1].children[0].children[0].add_child(Tree()) REF_TREE2 = Tree() T11_ = REF_TREE2.add_child(Tree()) T12_ = REF_TREE2.add_child(Tree()) T111_ = REF_TREE2.children[0].add_child(Tree()) T112_ = REF_TREE2.children[0].add_child(Tree()) T121_ = REF_TREE2.children[1].add_child(Tree())
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys from nose import tools as nt from neurom.core.tree import Tree REF_TREE = Tree() T11 = REF_TREE.add_child(Tree()) T12 = REF_TREE.add_child(Tree()) T111 = REF_TREE.children[0].add_child(Tree()) T112 = REF_TREE.children[0].add_child(Tree()) T121 = REF_TREE.children[1].add_child(Tree()) T122 = REF_TREE.children[1].add_child(Tree()) T1211 = REF_TREE.children[1].children[0].add_child(Tree()) T12111 = REF_TREE.children[1].children[0].children[0].add_child(Tree()) T12112 = REF_TREE.children[1].children[0].children[0].add_child(Tree()) REF_TREE2 = Tree() T11_ = REF_TREE2.add_child(Tree()) T12_ = REF_TREE2.add_child(Tree()) T111_ = REF_TREE2.children[0].add_child(Tree()) T112_ = REF_TREE2.children[0].add_child(Tree()) T121_ = REF_TREE2.children[1].add_child(Tree())