Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pass
not_same_same = list()
def walk(folder):
import os
for root, _, files in os.walk(folder):
for file in files:
yield os.path.join(root, file)
# for i, f in enumerate(filter(_is_good_file, walk('MorphologyRepository'))):
for i, f in enumerate(not_same_same_list):
print(i)
print(f)
m = MutMorphology(f)
immut = Morphology(f)
try:
m.write_h5('morph.h5')
except MorphioError:
continue
m.write_swc('morph.swc')
m.write_asc('morph.asc')
same_same = ((immut == Morphology("morph.h5")) and
(immut == Morphology("morph.swc")) and
(immut == Morphology("morph.asc")))
if not same_same:
not_same_same.append(f)
print(not_same_same)
# soma point
1 1 1 0 1 4.0 -1
# root section
2 3 0 0 2 0.5 1
3 3 0 0 3 0.5 2
# first child: real duplicate
4 3 0 0 3 0.5 3
5 3 0 0 7 0.5 4
# second child: duplicate with different diameter
6 3 0 0 3 2.3 3
7 3 0 0 8 3.5 6
# third child: no duplicate
8 3 1 0 0 2.3 3
9 3 1 1 0 3.5 8''') as tmp_file:
n = Morphology(tmp_file.name)
nt.eq_(len(n.root_sections), 1)
nt.eq_(len(n.root_sections[0].children), 3)
child1, child2, child3 = n.root_sections[0].children
assert_array_equal(n.root_sections[0].points, np.array([[0, 0, 2], [0, 0, 3]]))
assert_array_equal(child1.points, np.array([[0, 0, 3], [0, 0, 7]]))
assert_array_equal(child2.points, np.array([[0, 0, 3], [0, 0, 8]]))
assert_array_equal(child3.points, np.array([[0, 0, 3],
[1, 0, 0],
[1, 1, 0]]))
assert_array_equal(child1.diameters, np.array([1, 1]))
assert_array_equal(child2.diameters, np.array([4.6, 7], dtype=np.float32))
assert_array_equal(child3.diameters, np.array([1, 4.6, 7], dtype=np.float32))
(
(3 -10 0 2) ; merged with parent section
(0 -10 0 2) ; merged with parent section
(-3 -10 0 2) ; merged with parent section
(
(-5 -5 5 5)
|
(-6 -6 6 6)
)
)
)
''') as tmp_file:
with captured_output() as (_, err):
with ostream_redirect(stdout=True, stderr=True):
n = Morphology(tmp_file.name)
assert_substring('is the only child of section: 0 starting at:',
err.getvalue().strip())
assert_substring('It will be merged with the parent section',
err.getvalue().strip())
nt.assert_equal(len(n.soma.points), 0)
nt.assert_equal(len(n.soma.points), 0)
assert_equal(len(n.root_sections), 1)
assert_array_equal(n.root_sections[0].points,
np.array([[3, -4, 0],
[3, -6, 0],
[3, -8, 0],
[3, -10, 0],
[0, -10, 0],
[-3, -10, 0]],
dtype=np.float32))
def test_doc_exists():
cls = morphio.Morphology
classes = [morphio.Morphology,
morphio.mut.Morphology,
morphio.Section,
morphio.mut.Section,
morphio.Soma,
morphio.mut.Soma,
morphio.MitoSection,
morphio.mut.MitoSection,
morphio.Mitochondria,
morphio.mut.Mitochondria
]
for cls in classes:
public_methods = (method for method in dir(cls) if not method[:2] == '__')
for method in public_methods:
ok_(getattr(cls, method).__doc__,
'Public method {} of class {} is not documented !'.format(method, cls))
def test_soma_no_neurite():
n = Morphology(os.path.join(H5V1_PATH, 'soma_no_neurites.h5'))
assert_array_equal(n.soma.points,
[[ 0., 0., 0.],
[ 1., 0., 0.],
[ 0., 25., 0.]])
assert_array_equal(n.soma.diameters,
[6,6,15])
assert_equal(len(n.root_sections), 0)
(Name "Marker 3")
( -223.67 -157.92 -42.45 0.69) ; 1
( -222.76 -154.18 -39.90 0.69) ; 2
) ; End of markers
Incomplete
|
( -269.77 -129.47 -22.57 0.92) ; R-2-2, 1
( -268.17 -130.62 -24.75 0.92) ; R-2-2, 2
( -266.79 -131.77 -26.13 0.92) ; R-2-2, 3
Incomplete
) ; End of split
) ; End of split
)
''') as tmp_file:
n = Morphology(tmp_file.name)
nt.assert_equal(len(n.root_sections), 1)
assert_array_equal(n.root_sections[0].points,
np.array([[-290.87, -113.09, -16.32],
[-290.87, -113.09, -16.32],
],
dtype=np.float32))
assert_array_equal(n.root_sections[0].children[0].points,
np.array([[-290.87, -113.09, -16.32],
[-277.14, -119.13, -18.02],
[-275.54, -119.99, -16.67]],
dtype=np.float32))
assert_array_equal(n.root_sections[0].children[1].points,
def test_v1():
n = Morphology(os.path.join(H5V1_PATH, 'simple.h5'))
assert_equal(len(n.root_sections), 2)
assert_equal(n.root_sections[0].type, 3)
assert_equal(n.root_sections[1].type, 2)
n = Morphology(os.path.join(H5V1_PATH, 'Neuron.h5'))
assert_equal(n.version, MORPHOLOGY_VERSION_H5_1)
assert_equal(len(n.sections), 84)
assert_equal(len(n.soma.points), 3)
assert_equal(len(list(n.iter())), 84)
assert_equal(len(n.points), 924)
section_types = list(s.type for s in n.iter())
assert_equal(len(section_types), 84)
real_section_types = list(chain(repeat(SectionType.apical_dendrite, 21),
repeat(SectionType.basal_dendrite, 42),
repeat(SectionType.axon, 21)))
assert_equal(section_types, real_section_types)
assert_array_equal(n.points[:7],
yield os.path.join(root, file)
# for i, f in enumerate(filter(_is_good_file, walk('MorphologyRepository'))):
for i, f in enumerate(not_same_same_list):
print(i)
print(f)
m = MutMorphology(f)
immut = Morphology(f)
try:
m.write_h5('morph.h5')
except MorphioError:
continue
m.write_swc('morph.swc')
m.write_asc('morph.asc')
same_same = ((immut == Morphology("morph.h5")) and
(immut == Morphology("morph.swc")) and
(immut == Morphology("morph.asc")))
if not same_same:
not_same_same.append(f)
print(not_same_same)
# for i, f in enumerate(filter(_is_good_file, walk('MorphologyRepository'))):
for i, f in enumerate(not_same_same_list):
print(i)
print(f)
m = MutMorphology(f)
immut = Morphology(f)
try:
m.write_h5('morph.h5')
except MorphioError:
continue
m.write_swc('morph.swc')
m.write_asc('morph.asc')
same_same = ((immut == Morphology("morph.h5")) and
(immut == Morphology("morph.swc")) and
(immut == Morphology("morph.asc")))
if not same_same:
not_same_same.append(f)
print(not_same_same)
def test_read_weird_ids():
'''The ordering of IDs is not required'''
with tmp_swc_file('''10000 3 0 0 5 0.5 100 # neurite 4th point
3 3 0 0 3 0.5 47 # neurite 2nd point
10 1 0 0 0 3.0 -1 # soma
47 3 0 0 2 0.5 10 # neurite 1st point
100 3 0 0 4 0.5 3 # neurite 3rd point
''') as tmp_file:
neuron = Morphology(tmp_file.name)
assert_array_equal(neuron.soma.points, [[0, 0, 0]])
assert_array_equal(neuron.root_sections[0].points, [[0., 0., 2.],
[0., 0., 3.],
[0., 0., 4.],
[0., 0., 5.]])