Exemplo n.º 1
0
def test_neurite_wrong_root_point():
    '''Test that for 3 points soma, the neurites are attached to first soma point'''

    # Not 3-points soma --> OK
    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):
            n = Morphology(os.path.join(_path, 'soma_cylinders.swc'))
            assert_equal('', err.getvalue().strip())
        assert_equal(len(n.root_sections), 1)

    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):
            n = Morphology(os.path.join(_path, 'neurite_wrong_root_point.swc'))
            assert_string_equal(
                '''Warning: with a 3 points soma, neurites must be connected to the first soma point:
{}/neurite_wrong_root_point.swc:4:warning

{}/neurite_wrong_root_point.swc:6:warning'''.format(_path, _path),
                err.getvalue())
    assert_equal(len(n.root_sections), 2)
    assert_array_equal(n.root_sections[0].points, [[0, 0, 0], [0, 0, 1]])

    with ignored_warning(Warning.wrong_root_point):
        with captured_output() as (_, err):
            with ostream_redirect(stdout=True, stderr=True):
                n = Morphology(
                    os.path.join(_path, 'neurite_wrong_root_point.swc'))
                assert_equal('', err.getvalue().strip())
Exemplo n.º 2
0
def test_mitochondria():
    morpho = Morphology()
    morpho.soma.points = [[0, 0, 0], [1, 1, 1]]
    morpho.soma.diameters = [1, 1]

    neuronal_section_ids = [0, 0]
    relative_pathlengths = np.array([0.5, 0.6], dtype=np.float32)
    diameters = [10, 20]
    mito_id = morpho.mitochondria.append_root_section(
        MitochondriaPointLevel(neuronal_section_ids, relative_pathlengths,
                               diameters))

    mito_id.append_section(
        MitochondriaPointLevel([0, 0, 0, 0], [0.6, 0.7, 0.8, 0.9],
                               [20, 30, 40, 50]))
    with setup_tempdir('test_mitochondria') as tmp_folder:
        morpho.write(os.path.join(tmp_folder, "test.h5"))

        with captured_output() as (_, err):
            with ostream_redirect(stdout=True, stderr=True):
                morpho.write(os.path.join(tmp_folder, "test.swc"))
                assert_string_equal(
                    err.getvalue(),
                    "Warning: this cell has mitochondria, they cannot be saved in "
                    " ASC or SWC format. Please use H5 if you want to save them."
                )

        with captured_output() as (_, err):
            with ostream_redirect(stdout=True, stderr=True):
                morpho.write(os.path.join(tmp_folder, "test.asc"))
                assert_string_equal(
                    err.getvalue(),
                    "Warning: this cell has mitochondria, they cannot be saved in "
                    " ASC or SWC format. Please use H5 if you want to save them."
                )

        mito = ImmutMorphology(os.path.join(tmp_folder,
                                            'test.h5')).mitochondria
        assert_array_equal(mito.root_sections[0].diameters, diameters)
        assert_array_equal(mito.root_sections[0].neurite_section_ids,
                           neuronal_section_ids)
        assert_array_equal(mito.root_sections[0].relative_path_lengths,
                           relative_pathlengths)

        assert_equal(len(mito.root_sections), 1)

        mito = Morphology(os.path.join(tmp_folder, 'test.h5')).mitochondria
        assert_equal(len(mito.root_sections), 1)
        assert_equal(mito.root_sections[0].neurite_section_ids,
                     neuronal_section_ids)
        assert_array_equal(mito.section(0).diameters, diameters)

        assert_array_equal(
            mito.section(0).neurite_section_ids, neuronal_section_ids)
Exemplo n.º 3
0
def test_zero_diameter():
    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True),\
                tmp_swc_file('''1 1 1 0 0 3.0 -1
                                2 1 2 0 0 3.0  1
                                3 1 3 0 0 3.0  2
                                4 3 4 0 0 0.0  1
                                5 3 5 0 0 3.0  4
                         ''') as tmp_file:
            Morphology(tmp_file.name)
            assert_string_equal(
                f'{tmp_file.name}:4:warning\nWarning: zero diameter in file\n',
                err.getvalue())
Exemplo n.º 4
0
def test_soma_type():
    '''The ordering of IDs is not required'''
    # 1 point soma
    with tmp_swc_file('''1 1 0 0 0 3.0 -1''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_SINGLE_POINT)

    # 2 point soma
    with tmp_swc_file('''1 1 0 0 0 3.0 -1
                         2 1 0 0 0 3.0  1''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_UNDEFINED)

    # > 3 points soma
    with tmp_swc_file('''1 1 0 0 0 3.0 -1
                         2 1 0 0 0 3.0  1
                         3 1 0 0 0 3.0  2
                         4 1 0 0 0 3.0  3
                         5 1 0 0 0 3.0  4''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_CYLINDERS)

    # 3 points soma can be of type SOMA_CYLINDERS or SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS
    # depending on the point layout

    # SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS are characterized by
    # one soma point with 2 children
    with tmp_swc_file('''1 1 0  0 0 3.0 -1
    2 1 0 -3 0 3.0  1
    3 1 0  3 0 3.0  1 # PID is 1''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type,
            SomaType.SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS)

    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):

            with tmp_swc_file('''1 1 0  0 0 3.0 -1
                                 2 1 1 -3 0 3.0  1
                                 3 1 0  0 0 3.0  1 # PID is 1''') as tmp_file:
                assert_equal(
                    Morphology(tmp_file.name).soma_type,
                    SomaType.SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS)
                assert_string_equal(
                    '''{}:0:warning
                       Warning: the soma does not conform the three point soma spec
                       The only valid neuro-morpho soma is:
                       1 1 x   y   z r -1
                       2 1 x (y-r) z r  1
                       3 1 x (y+r) z r  1

                       Got:
                       1 1 0 0 0 3 -1
                       2 1 1.000000 (exp. 0.000000) -3.000000 0.000000 3.000000 1
                       3 1 0.000000 0.000000 (exp. 3.000000) 0.000000 3.000000 1'''
                    .format(tmp_file.name),
                    err.getvalue(),
                )


# If this configuration is not respected -> SOMA_CYLINDERS
    with tmp_swc_file('''1 1 0 0 0 3.0 -1
                         2 1 0 0 0 3.0  1
                         3 1 0 0 0 3.0  2 # PID is 2''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_CYLINDERS)