Пример #1
0
def test_is_single_tree_bad_data():

    f = os.path.join(SWC_PATH, 'Neuron_disconnected_components.swc')

    ok, ids = io.check.is_single_tree(io.load_data(f))
    nt.ok_(not ok)
    nt.eq_(ids, [6, 217, 428, 639])
Пример #2
0
def test_has_all_points_connected_good_data():

    f = os.path.join(SWC_PATH, 'Neuron.swc')

    ok, ids = io.check.all_points_connected(io.load_data(f))
    nt.ok_(ok)
    nt.eq_(len(ids), 0)
Пример #3
0
def test_has_sequential_ids_bad_data():

    f = os.path.join(SWC_PATH, 'Neuron_missing_ids.swc')

    ok, ids = io.check.has_sequential_ids(io.load_data(f))
    nt.ok_(not ok)
    nt.ok_(ids == [6, 217, 428, 639])
Пример #4
0
    def _check_file(self, f):
        '''Run tests on a morphology file'''

        L.info('File: %s', f)

        result = True

        try:
            data = load_data(f)
        except Exception as e:  # pylint: disable=W0703
            L.error('Failed to load data... skipping tests for this file')
            L.error(e.args)
            return False, {f: OrderedDict([('ALL', False)])}

        try:
            result &= self._check_loop(data, 'structural_checks')
            nrn = fst_core.FstNeuron(data)
            result &= self._check_loop(nrn, 'neuron_checks')
        except Exception as e:  # pylint: disable=W0703
            L.error('Check failed:' + str(type(e)) + str(e.args))
            result = False

        self.summary['ALL'] = result

        for m, s in self.summary.items():
            self._log_msg(m, s)

        return result, {f: self.summary}
Пример #5
0
def test_has_no_missing_parents_bad_data():

    f = os.path.join(SWC_PATH, 'Neuron_missing_parents.swc')

    ok, ids = io.check.no_missing_parents(io.load_data(f))
    nt.ok_(not ok)
    nt.eq_(ids, [6, 217, 428, 639])
Пример #6
0
def test_has_no_missing_parents_good_data():

    f = os.path.join(SWC_PATH, 'Neuron.swc')

    ok, ids = io.check.no_missing_parents(io.load_data(f))
    nt.ok_(ok)
    nt.eq_(len(ids), 0)
Пример #7
0
    def _check_file(self, f):
        '''Run tests on a morphology file'''

        L.info('File: %s', f)

        result = True

        try:
            data = load_data(f)
        except StandardError as e:
            L.error('Failed to load data... skipping tests for this file')
            L.error(e.message)
            return False, {f: OrderedDict([('ALL', False)])}

        try:
            result &= self._check_loop(data, 'structural_checks')
            nrn = fst_core.FstNeuron(data)
            result &= self._check_loop(nrn, 'neuron_checks')
        except StandardError as e:
            L.error('Check failed: %s: %s', type(e), e.message)
            result = False

        self.summary['ALL'] = result

        for m, s in self.summary.iteritems():
            self._log_msg(m, s)

        return result, {f: self.summary}
Пример #8
0
    def _check_file(self, f):
        '''Run tests on a morphology file'''
        L.info('File: %s', f)

        full_result = True
        full_summary = OrderedDict()
        try:
            data = load_data(f)
        except Exception as e:  # pylint: disable=W0703
            L.error('Failed to load data... skipping tests for this file')
            L.error(e.args)
            return False, {f: OrderedDict([('ALL', False)])}

        try:
            result, summary = self._check_loop(data, 'structural_checks')
            full_result &= result
            full_summary.update(summary)

            nrn = fst_core.FstNeuron(data)
            result, summary = self._check_loop(nrn, 'neuron_checks')
            full_result &= result
            full_summary.update(summary)
        except Exception as e:  # pylint: disable=W0703
            L.error('Check failed: %s', str(type(e)) + str(e.args))
            full_result = False

        full_summary['ALL'] = full_result

        for m, s in full_summary.items():
            self._log_msg(m, s)

        return full_result, {f: full_summary}
Пример #9
0
def test_is_single_tree_good_data():

    f = os.path.join(SWC_PATH, 'Neuron.swc')

    ok, ids = io.check.is_single_tree(io.load_data(f))
    nt.ok_(ok)
    nt.eq_(len(ids), 0)
Пример #10
0
def test_has_all_points_connected_bad_data():

    f = os.path.join(SWC_PATH, 'Neuron_disconnected_components.swc')

    ok, ids = io.check.all_points_connected(io.load_data(f))
    nt.ok_(not ok)
    nt.eq_(ids, [6, 217, 428, 639])
Пример #11
0
def test_read():
    rdw = io.load_data(StringIO(MORPH_ASC), reader='asc')
    raw_data = rdw.data_block

    eq_(raw_data.shape, (19, 7))
    ok_(np.allclose(raw_data[:, COLS.ID], np.arange(0, 19)))  # correct ID
    # 3 is ID of end of the soma, 2 sections attach to this
    ok_(np.count_nonzero(raw_data[:, COLS.P] == 3), 2)
Пример #12
0
def test_has_finite_length_segments_good_data():
    files = [os.path.join(SWC_PATH, f)
             for f in ['Neuron.swc',
                       'sequential_trunk_off_0_16pt.swc',
                       'sequential_trunk_off_1_16pt.swc',
                       'sequential_trunk_off_42_16pt.swc']]
    for f in files:
        ok, ids = io.check.has_all_finite_length_segments(io.load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
Пример #13
0
def test_has_soma_points_good_data():
    files = [os.path.join(SWC_PATH, f)
             for f in ['Neuron.swc',
                       'Single_apical.swc',
                       'Single_basal.swc',
                       'Single_axon.swc']]

    files.append(os.path.join(H5V1_PATH, 'Neuron_2_branch.h5'))

    for f in files:
        nt.ok_(io.check.has_soma_points(io.load_data(f)))
Пример #14
0
def test_has_finite_radius_neurites_good_data():
    files = [os.path.join(SWC_PATH, f)
             for f in ['Neuron.swc',
                       'Single_apical.swc',
                       'Single_basal.swc',
                       'Single_axon.swc']]

    files.append(os.path.join(H5V1_PATH, 'Neuron_2_branch.h5'))

    for f in files:
        ok, ids = io.check.has_all_finite_radius_neurites(io.load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
Пример #15
0
def test_read():
    rdw = io.load_data(StringIO(MORPH_ASC), reader='asc')
    raw_data = rdw.data_block

    eq_(raw_data.shape, (19, 7))
    ok_(np.allclose(raw_data[:, COLS.ID], np.arange(0, 19)))  # correct ID
    # 3 is ID of end of the soma, 2 sections attach to this
    ok_(np.count_nonzero(raw_data[:, COLS.P] == 3), 2)

    neuron = load_neuron(StringIO(MORPH_ASC), reader='asc')
    assert_array_equal(neuron.neurites[0].root_node.points[:, COLS.XYZ],
                       [[0., 5., 0.], [2., 9., 0.], [0., 13., 0.],
                        [2., 13., 0.], [4., 13., 0.]])
Пример #16
0
def test_has_finite_length_segments_bad_data():
    files = [os.path.join(SWC_PATH, f)
             for f in ['Neuron_zero_length_segments.swc',
                       'Single_apical.swc',
                       'Single_basal.swc',
                       'Single_axon.swc']]

    bad_segs = [[(4, 5), (215, 216),
                 (426, 427), (637, 638)],
                [(4, 5)],
                [(4, 5)],
                [(4, 5)]]

    for i, f in enumerate(files):
        ok, ids = io.check.has_all_finite_length_segments(io.load_data(f))
        nt.ok_(not ok)
        nt.assert_equal(ids, bad_segs[i])
Пример #17
0
def test_has_sequential_ids_good_data():

    files = [os.path.join(SWC_PATH, f)
             for f in ['Neuron.swc',
                       'Single_apical_no_soma.swc',
                       'Single_apical.swc',
                       'Single_basal.swc',
                       'Single_axon.swc',
                       'Neuron_zero_radius.swc',
                       'sequential_trunk_off_0_16pt.swc',
                       'sequential_trunk_off_1_16pt.swc',
                       'sequential_trunk_off_42_16pt.swc',
                       'Neuron_no_missing_ids_no_zero_segs.swc']
             ]

    for f in files:
        ok, ids = io.check.has_sequential_ids(io.load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
Пример #18
0
INIT_IDS = [[4, 215, 426, 637],
            [],
            [4],
            [4],
            [4],
            [2, 10],
            [3, 11],
            [44, 52],
            [4]]


_path = os.path.dirname(os.path.abspath(__file__))
DATA_PATH = os.path.join(_path, '../../../test_data')
SWC_PATH = os.path.join(DATA_PATH, 'swc')

RAW_DATA = [io.load_data(f) for f in FILES]
NO_SOMA_RAW_DATA = io.load_data(NO_SOMA_FILE)


class MockNeuron(object):
    def __init__(self, trees):
        self.neurites = trees


def test_get_soma_ids():
    for i, d in enumerate(RAW_DATA):
        nt.ok_(utils.get_soma_ids(d) == SOMA_IDS[i])


def test_get_initial_neurite_segment_ids():
    for i, d in enumerate(RAW_DATA):
Пример #19
0
def test_neuron_name():

    d = _io.load_data(FILENAMES[0])
    nrn = _core.FstNeuron(d, '12af3rg')
    nt.eq_(nrn.name, '12af3rg')
Пример #20
0
def test_load_neurolucida_ascii():
    f = os.path.join(NEUROLUCIDA_PATH, 'sample.asc')
    ascii = io.load_data(f)
    ok_(isinstance(ascii, DataWrapper))
    eq_(len(ascii.data_block), 18)
Пример #21
0
from neurom.core.tree import Tree
from neurom import segments as seg
from neurom import iter_neurites

import math
from itertools import izip


class MockNeuron(object):
    pass


DATA_PATH = './test_data'
SWC_PATH = os.path.join(DATA_PATH, 'swc/')

data    = io.load_data(SWC_PATH + 'Neuron.swc')
neuron0 = make_neuron(data)
tree0   = neuron0.neurites[0]

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]))
Пример #22
0
def test_load_neurolucida_ascii():
    f = os.path.join(NEUROLUCIDA_PATH, 'sample.asc')
    with warnings.catch_warnings(record=True):
        ascii = io.load_data(f)
    ok_(isinstance(ascii, DataWrapper))
    eq_(len(ascii.data_block), 18)
Пример #23
0
def test_load_neurolucida_ascii():
    f = os.path.join(NEUROLUCIDA_PATH, 'sample.asc')
    ascii = io.load_data(f)
    ok_(isinstance(ascii, DataWrapper))
    eq_(len(ascii.data_block), 18)
Пример #24
0
def test_neuron_name():

    d = _io.load_data(FILENAMES[0])
    nrn = _core.FstNeuron(d, '12af3rg')
    nt.eq_(nrn.name, '12af3rg')
Пример #25
0
def test_has_soma_points_bad_data():
    f = os.path.join(SWC_PATH, 'Single_apical_no_soma.swc')
    nt.ok_(not io.check.has_soma_points(io.load_data(f)))
Пример #26
0
def test_has_finite_radius_neurites_bad_data():
    f = os.path.join(SWC_PATH, 'Neuron_zero_radius.swc')
    ok, ids = io.check.has_all_finite_radius_neurites(io.load_data(f))
    nt.ok_(not ok)
    nt.ok_(ids == [194, 210, 246, 304, 493])