Пример #1
0
def test_intact_branching_angles():
    obj = Repair(SIMPLE_PATH)
    obj._fill_repair_type_map()
    branches = [neurite.root_node for neurite in obj.neuron.neurites]
    angles = obj._intact_branching_angles(branches)
    assert_array_almost_equal(angles[test_module.RepairType.basal][0],
                              [1.5707963267948966, 1.5707963267948966])
Пример #2
0
def test__compute_sholl_data():
    obj = Repair(SIMPLE_PATH)
    obj._fill_repair_type_map()
    branches = [neurite.root_node for neurite in obj.neuron.neurites]
    sholl_data = obj._compute_sholl_data(branches)
    assert_dict_equal(sholl_data[RepairType.basal][0][0], {
        Action.TERMINATION: 0,
        Action.CONTINUATION: 0,
        Action.BIFURCATION: 1
    })
    assert_dict_equal(sholl_data[RepairType.basal][0][1], {
        Action.TERMINATION: 2,
        Action.CONTINUATION: 0,
        Action.BIFURCATION: 0
    })
    assert_dict_equal(sholl_data[RepairType.oblique], {})
    assert_dict_equal(
        sholl_data[RepairType.axon], {
            0: {
                0: {
                    Action.BIFURCATION: 1,
                    Action.CONTINUATION: 0,
                    Action.TERMINATION: 0
                },
                1: {
                    Action.BIFURCATION: 0,
                    Action.CONTINUATION: 0,
                    Action.TERMINATION: 2
                }
            }
        })
Пример #3
0
def test__grow():
    obj = Repair(SIMPLE_PATH, seed=1)
    leaf = obj.neuron.sections[2]
    obj.repair_type_map = {
        section: RepairType.basal
        for section in obj.neuron.sections
    }
    obj.info = {
        'sholl': {
            RepairType.basal: {
                0: {
                    1: {
                        Action.BIFURCATION: 0.5,
                        Action.TERMINATION: 0,
                        Action.CONTINUATION: 0.5
                    }
                }
            }
        },
        'dendritic_sections': obj.neuron.sections,
        'intact_branching_angles': {
            RepairType.basal: {
                1: [0.2]
            }
        }
    }
    obj.current_trunk_radius = 1.0
    obj._grow(leaf, 0, obj.neuron.soma.center)
    assert_equal(len(obj.neuron.sections), 8)
Пример #4
0
def test_best_case_angle_data():
    obj = Repair(SIMPLE_PATH)
    obj.info = {
        'intact_branching_angles': {
            SectionType.axon: {
                0: [1, 2, 3],
                1: [2, 2],
                2: []
            }
        }
    }

    # Use exact data for this specific branching angle
    assert_array_equal(obj._best_case_angle_data(SectionType.axon, 0),
                       [1, 2, 3])

    # No info for this branching angle, use aggregate data
    assert_array_equal(obj._best_case_angle_data(SectionType.axon, 2),
                       [1, 2, 3, 2, 2])
Пример #5
0
def test__fill_repair_type_map():
    obj = Repair(DATA_PATH / 'repair_type.asc')
    obj.apical_section = obj.neuron.sections[3]
    # Pre check to be sure that the apical point is the one it should be
    assert_array_almost_equal(
        obj.apical_section.points,
        np.array([[0., 0., 4., 1.], [0., 0., 0., 0.5], [1., 0., 0., 0.5]],
                 dtype=np.float32))

    obj._fill_repair_type_map()
    assert_dict_equal({sec.id: v
                       for sec, v in obj.repair_type_map.items()}, {
                           0: test_module.RepairType.axon,
                           1: test_module.RepairType.trunk,
                           2: test_module.RepairType.oblique,
                           3: test_module.RepairType.trunk,
                           4: test_module.RepairType.tuft,
                           5: test_module.RepairType.tuft,
                           6: test_module.RepairType.basal,
                       })
Пример #6
0
def test_get_order_offset():
    obj = Repair(SIMPLE_PATH)
    section = obj.neuron.neurites[0].root_node.children[0]
    obj.repair_type_map = {section: RepairType.basal}
    assert_equal(obj._get_order_offset(section), 0)

    obj.repair_type_map = {section: RepairType.oblique}
    assert_equal(obj._get_order_offset(section), 1)
Пример #7
0
def test_get_origin():
    obj = Repair(SIMPLE)
    section = obj.neuron.section(1)
    obj.repair_type_map = {section: RepairType.basal}
    assert_array_equal(obj._get_origin(section), [0, 0, 0])

    obj.repair_type_map = {section: RepairType.oblique}
    assert_array_equal(obj._get_origin(section), [0, 5, 0])
Пример #8
0
def test__compute_statistics_for_intact_subtrees():
    input_file = DATA_PATH / 'neuron-slice.h5'
    points = test_module.CutPlane.find(input_file,
                                       bin_width=15).cut_leaves_coordinates
    obj = Repair(input_file, cut_leaves_coordinates=points)
    obj._fill_repair_type_map()
    obj._fill_statistics_for_intact_subtrees()

    with open(DATA_PATH / 'neuron-slice-sholl-data.json') as f:
        expected = json.load(f)

    basal_data = expected['SectionType.basal_dendrite']

    actual = json_compatible_dict(obj.info['sholl'][RepairType.basal])
    for layer in basal_data:
        for order in basal_data[layer]:
            for action in basal_data[layer][order]:
                assert_equal(basal_data[layer][order][action],
                             actual[layer][order][action])
Пример #9
0
def test__find_intact_sub_trees():
    obj = Repair(SIMPLE_PATH)
    obj.cut_leaves = np.array([[2, 2, 2]])
    obj._fill_repair_type_map()

    assert_equal(len(obj._find_intact_sub_trees()), 2)

    points = test_module.CutPlane.find(SLICE,
                                       bin_width=15).cut_leaves_coordinates
    obj = Repair(SLICE_PATH, cut_leaves_coordinates=points)
    obj._fill_repair_type_map()
    intact_sub_trees = obj._find_intact_sub_trees()
    assert_array_equal([section.id for section in intact_sub_trees], [0, 34])

    obj = Repair(DATA_PATH / 'test-cut-apical' / 'simple-apical-cut.swc',
                 cut_leaves_coordinates=[[1.0, 30.0, 0.0]])
    obj._fill_repair_type_map()
    intact_sub_trees = obj._find_intact_sub_trees()
    assert_array_equal([section.id for section in intact_sub_trees], [1, 0, 3])
    assert_array_equal(
        [obj.repair_type_map[section] for section in intact_sub_trees],
        [RepairType.basal, RepairType.axon, RepairType.tuft])

    filename = DATA_PATH / 'no-intact-basals.h5'
    points = test_module.CutPlane.find(filename,
                                       bin_width=15).cut_leaves_coordinates
    obj = Repair(filename, cut_leaves_coordinates=points)
    obj._fill_repair_type_map()
    intact_sub_trees = obj._find_intact_sub_trees()
    basals = [
        section for section in intact_sub_trees
        if section.type == NeuriteType.basal_dendrite
    ]
    assert_equal(len(basals), 78)
Пример #10
0
def test__external_apical_point():
    obj = Repair(DATA_PATH / 'repair_type.asc', apical_point=[1.0, 0.0, 0.0])
    assert_array_almost_equal(
        obj.apical_section.points,
        np.array([[0., 0., 4., 1.], [0., 0., 0., 0.5], [1., 0., 0., 0.5]],
                 dtype=np.float32))