def test_segment_path_length(): leaves = [l for l in tr.ileaf(NEURON_TREE)] for l in leaves: nt.ok_(path_length(l) == 9) leaves = [l for l in tr.ileaf(SIMPLE_TREE)] for l in leaves: nt.ok_(path_length(l) == 8)
def _check_trees(trees): for t in trees: nt.ok_(len(list(tree.ileaf(t))) == 11) nt.ok_(len(list(tree.iforking_point(t))) == 10) nt.ok_(len(list(tree.ipreorder(t))) == 211) nt.ok_(len(list(tree.ipostorder(t))) == 211) nt.ok_(len(list(tree.isegment(t))) == 210) leaves = [l for l in tree.ileaf(t)] # path length from each leaf to root node. branch_order = [21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 111] for i, l in enumerate(leaves): nt.ok_(len(list(tree.iupstream(l))) == branch_order[i])
def test_ibifurcation_point_upstream(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [[11, 0], [11, 0], [11, 0], [11, 0], [1211, 12, 0], [1211, 12, 0], [12, 0]] for l, ref in zip(leaves, ref_paths): nt.assert_equal( [s for s in val_iter(ibifurcation_point(l, iupstream))], ref)
def test_ibifurcation_point_upstream(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [ [11, 0], [11, 0], [11, 0], [11, 0], [1211, 12, 0], [1211, 12, 0], [12, 0] ] for l, ref in zip(leaves, ref_paths): nt.assert_equal([s for s in val_iter(ibifurcation_point(l, iupstream))], ref)
def test_leaf_iteration(): nt.ok_(list(val_iter(ileaf(REF_TREE))) == [111, 112, 12111, 12112, 122]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[0]))) == [111, 112]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[1]))) == [12111, 12112, 122]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[0].children[0]))) == [111]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[0].children[1]))) == [112]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[1].children[0]))) == [12111, 12112]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[1].children[1]))) == [122])
def test_section_upstream_iteration(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [[(1111, 11111), (11, 111, 1111), (0, 11)], [(1111, 11112), (11, 111, 1111), (0, 11)], [(1111, 11113), (11, 111, 1111), (0, 11)], [(11, 112), (0, 11)], [(1211, 12111), (12, 121, 1211), (0, 12)], [(1211, 12112), (12, 121, 1211), (0, 12)], [(12, 122), (0, 12)]] for l, ref in zip(leaves, ref_paths): nt.assert_equal([s for s in val_iter(isection(l, iupstream))], ref)
def test_leaf_iteration(): nt.ok_(list(val_iter(ileaf(REF_TREE))) == [111, 112, 12111, 12112, 122]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[0]))) == [111, 112]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[1]))) == [12111, 12112, 122]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[0].children[0]))) == [111]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[0].children[1]))) == [112]) nt.ok_( list(val_iter(ileaf(REF_TREE.children[1].children[0]))) == [12111, 12112]) nt.ok_(list(val_iter(ileaf(REF_TREE.children[1].children[1]))) == [122])
def test_section_upstream_iteration(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [ [(1111, 11111), (11, 111, 1111), (0, 11)], [(1111, 11112), (11, 111, 1111), (0, 11)], [(1111, 11113), (11, 111, 1111), (0, 11)], [(11, 112), (0, 11)], [(1211, 12111), (12, 121, 1211), (0, 12)], [(1211, 12112), (12, 121, 1211), (0, 12)], [(12, 122), (0, 12)]] for l, ref in zip(leaves, ref_paths): nt.assert_equal([s for s in val_iter(isection(l, iupstream))], ref)
def compare_trees(tree1, tree2): ''' Comparison between all the nodes and their respective radii between two trees. Ids are do not have to be identical between the trees, and swapping is allowed Returns: False if the trees are not identical. True otherwise. ''' leaves1 = list(tr.ileaf(tree1)) leaves2 = list(tr.ileaf(tree2)) if len(leaves1) != len(leaves2): return False else: nleaves = len(leaves1) for leaf1, leaf2 in product(leaves1, leaves2): is_equal = True for node1, node2 in izip(tr.val_iter(tr.iupstream(leaf1)), tr.val_iter(tr.iupstream(leaf2))): if any(node1[0:5] != node2[0:5]): is_equal = False continue if is_equal: nleaves -= 1 return nleaves == 0
def n_terminations(tree): """ Return number of terminations in tree """ return sum(1 for _ in tr.ileaf(tree))
soma = neuron.make_soma([rd.get_row(si) for si in get_soma_ids(rd)]) for tr in trees: for p in point_iter(tree.ipreorder(tr)): print p print 'Initial segment IDs:', init_seg_ids nrn = neuron.Neuron(soma, trees) print 'Neuron soma raw data', [r for r in nrn.soma.iter()] print 'Neuron soma points', [as_point(p) for p in nrn.soma.iter()] print 'Neuron tree init points, types' for tt in nrn.neurites: print tt.value[COLS.ID], tt.value[COLS.TYPE] print 'Making neuron 2' nrn2 = make_neuron(rd) print 'Neuron 2 soma points', [r for r in nrn2.soma.iter()] print 'Neuron 2 soma points', [as_point(p) for p in nrn2.soma.iter()] print 'Neuron 2 tree init points, types' for tt in nrn2.neurites: print tt.value[COLS.ID], tt.value[COLS.TYPE] print 'Print neuron leaves as points' for tt in nrn2.neurites: for p in point_iter(tree.ileaf(tt)): print p
for tr in trees: for p in point_iter(tree.ipreorder(tr)): LOG.debug(p) LOG.info('Initial segment IDs: %s', init_seg_ids) nrn = neuron.Neuron(soma, trees) LOG.info('Neuron soma raw data % s', [r for r in nrn.soma.iter()]) LOG.info('Neuron soma points %s', [as_point(p) for p in nrn.soma.iter()]) LOG.info('Neuron tree init points, types') for tt in nrn.neurites: LOG.info('%s, %s', tt.value[COLS.ID], tt.value[COLS.TYPE]) LOG.info('Making neuron 2') nrn2 = make_neuron(rd) LOG.debug('Neuron 2 soma points %s', [r for r in nrn2.soma.iter()]) LOG.debug('Neuron 2 soma points %s', [as_point(p) for p in nrn2.soma.iter()]) LOG.info('Neuron 2 tree init points, types') for tt in nrn2.neurites: LOG.info('%s %s', tt.value[COLS.ID], tt.value[COLS.TYPE]) LOG.debug('Print neuron leaves as points') for tt in nrn2.neurites: for p in point_iter(tree.ileaf(tt)): LOG.debug(p)
def path_end_to_end_distance(path): '''Calculate and return end-to-end-distance of a given path.''' trunk = path.value return max(morphmath.point_dist(l, trunk) for l in tree.val_iter(tree.ileaf(path)))