예제 #1
0
def test_has_sequential_ids_bad_data():

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

    ok, ids = check.has_sequential_ids(load_data(f))
    nt.ok_(not ok)
    nt.ok_(ids == [6, 217, 428, 639])
예제 #2
0
def test_has_sequential_ids_bad_data():

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

    ok, ids = check.has_sequential_ids(load_data(f))
    nt.ok_(not ok)
    nt.ok_(ids == [6, 217, 428, 639])
예제 #3
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 = check.has_all_finite_length_segments(load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
예제 #4
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_(check.has_soma_points(load_data(f)))
예제 #5
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 = check.has_all_finite_length_segments(load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
예제 #6
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_(check.has_soma_points(load_data(f)))
예제 #7
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 = check.has_all_finite_radius_neurites(load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
예제 #8
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 = check.has_all_finite_radius_neurites(load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
예제 #9
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 = check.has_all_finite_length_segments(load_data(f))
        nt.ok_(not ok)
        nt.assert_equal(ids, bad_segs[i])
예제 #10
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 = check.has_sequential_ids(load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
예제 #11
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 = check.has_all_finite_length_segments(load_data(f))
        nt.ok_(not ok)
        nt.assert_equal(ids, bad_segs[i])
예제 #12
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 = check.has_sequential_ids(load_data(f))
        nt.ok_(ok)
        nt.ok_(len(ids) == 0)
예제 #13
0
파일: utils.py 프로젝트: wvangeit/NeuroM
def load_neuron(filename, tree_action=None):
    """
    Loads a neuron keeping a record of the filename.
    Args:
        filename: the path of the file storing morphology data
        tree_action: optional function to run on each of the neuron's
        neurite trees.
    Raises: SomaError if no soma points in data.
    Raises: NonConsecutiveIDsError if filename contains non-consecutive
    point IDs
    """

    data = load_data(filename)
    if not has_sequential_ids(data)[0]:
        raise NonConsecutiveIDsError('Non consecutive IDs found in raw data')

    nrn = make_neuron(data, tree_action)
    nrn.name = os.path.splitext(os.path.basename(filename))[0]

    return nrn
예제 #14
0
파일: utils.py 프로젝트: wvangeit/NeuroM
def load_neuron(filename, tree_action=None):
    """
    Loads a neuron keeping a record of the filename.
    Args:
        filename: the path of the file storing morphology data
        tree_action: optional function to run on each of the neuron's
        neurite trees.
    Raises: SomaError if no soma points in data.
    Raises: NonConsecutiveIDsError if filename contains non-consecutive
    point IDs
    """

    data = load_data(filename)
    if not has_sequential_ids(data)[0]:
        raise NonConsecutiveIDsError('Non consecutive IDs found in raw data')

    nrn = make_neuron(data, tree_action)
    nrn.name = os.path.splitext(os.path.basename(filename))[0]

    return nrn
예제 #15
0
def test_has_soma_points_bad_data():
    f = os.path.join(SWC_PATH, 'Single_apical_no_soma.swc')
    nt.ok_(not check.has_soma_points(load_data(f)))
예제 #16
0
def test_has_finite_radius_neurites_bad_data():
    f = os.path.join(SWC_PATH, 'Neuron_zero_radius.swc')
    ok, ids = check.has_all_finite_radius_neurites(load_data(f))
    nt.ok_(not ok)
    nt.ok_(ids == [194, 210, 246, 304, 493])
예제 #17
0
from neurom.analysis.morphtree import n_bifurcations
from neurom.analysis.morphtree import n_terminations
from neurom.analysis.morphtree import trunk_radius
from neurom.analysis.morphtree import trunk_length
from neurom.analysis.morphtree import trunk_direction
from neurom.analysis.morphtree import trunk_elevation
from neurom.analysis.morphtree import trunk_azimuth
from neurom.analysis.morphtree import get_bounding_box
import math
import numpy as np
from itertools import izip

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))
예제 #18
0
def test_has_soma_points_bad_data():
    f = os.path.join(SWC_PATH, 'Single_apical_no_soma.swc')
    nt.ok_(not check.has_soma_points(load_data(f)))
예제 #19
0
'''Calculate inter-segment angles'''

import logging
import numpy as np
from neurom.core.dataformat import COLS
from neurom.io.readers import load_data
from neurom.io.utils import make_neuron
from neurom.analysis.morphtree import i_segment_meander_angle


# root level logger. This would be a top level application logger.
logging.basicConfig()
LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOG.handlers[0].setFormatter(fmt)


if __name__ == '__main__':

    filename = 'test_data/swc/Neuron.swc'
    rd = load_data(filename)
    nrn = make_neuron(rd)

    for tt in nrn.neurites:
        print 'Tree ID: {0}, type: {1}'.format(tt.value[COLS.ID], tt.value[COLS.TYPE])
        for a in i_segment_meander_angle(tt):
            LOG.debug('Angle %f', a)
            if np.isnan(a):
                LOG.warn('Found NaN angle. Check for zero length segments!')
예제 #20
0
def test_has_finite_radius_neurites_bad_data():
    f = os.path.join(SWC_PATH, 'Neuron_zero_radius.swc')
    ok, ids = check.has_all_finite_radius_neurites(load_data(f))
    nt.ok_(not ok)
    nt.ok_(ids == [194, 210, 246, 304, 493])
예제 #21
0
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''Calculate inter-segment angles'''

import logging
import numpy as np
from neurom.core.dataformat import COLS
from neurom.io.readers import load_data
from neurom.io.utils import make_neuron
from neurom.analysis.morphtree import i_segment_meander_angle

# root level logger. This would be a top level application logger.
logging.basicConfig()
LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOG.handlers[0].setFormatter(fmt)

if __name__ == '__main__':

    filename = 'test_data/swc/Neuron.swc'
    rd = load_data(filename)
    nrn = make_neuron(rd)

    for tt in nrn.neurites:
        print 'Tree ID: {0}, type: {1}'.format(tt.value[COLS.ID],
                                               tt.value[COLS.TYPE])
        for a in i_segment_meander_angle(tt):
            LOG.debug('Angle %f', a)
            if np.isnan(a):
                LOG.warn('Found NaN angle. Check for zero length segments!')
예제 #22
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 = [load_data(f) for f in FILES]
NO_SOMA_RAW_DATA = load_data(NO_SOMA_FILE)


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_segment_ids():
    for i, d in enumerate(RAW_DATA):
        nt.ok_(utils.get_initial_segment_ids(d) == INIT_IDS[i])


def _check_trees(trees):
    for t in trees: