From ad2014f7cdfe7d0f2ba490cad0b0e4e86b828494 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 20 Feb 2017 16:02:03 +0100 Subject: [PATCH] Add tests for morphologies --- Makefile | 6 +- bluepyopt/tests/.gitignore | 1 + bluepyopt/tests/test_ephys/test_morphologies.py | 82 ++++++++++++++++++- bluepyopt/tests/test_ephys/test_protocols.py | 92 ++++++++++++++++++++++ bluepyopt/tests/test_ephys/testdata/simple_ax1.swc | 6 ++ bluepyopt/tests/test_ephys/testdata/simple_ax2.asc | 18 +++++ bluepyopt/tests/test_ephys/testdata/simple_ax2.swc | 7 ++ 7 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 bluepyopt/tests/test_ephys/testdata/simple_ax1.swc create mode 100644 bluepyopt/tests/test_ephys/testdata/simple_ax2.asc create mode 100644 bluepyopt/tests/test_ephys/testdata/simple_ax2.swc diff --git a/Makefile b/Makefile index 315ffa5..c775bbd 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,10 @@ sc_prepare: jupyter jupyter nbconvert --to python simplecell.ipynb && \ sed '/get_ipython/d;/plt\./d;/plot_responses/d;/import matplotlib/d' simplecell.py >simplecell.tmp && \ mv simplecell.tmp simplecell.py +coverage_unit: unit + cd bluepyopt/tests; coverage html -d coverage_html; open coverage_html/index.html +coverage_test: test + cd bluepyopt/tests; coverage html -d coverage_html; open coverage_html/index.html jupyter: pip install -q jupyter install_test_requirements: @@ -37,7 +41,7 @@ install_test_requirements: test: clean unit functional unit: install install_test_requirements cd bluepyopt/tests; nosetests -a 'unit' -s -v -x --with-coverage --cover-xml \ - --cover-package bluepyopt + --cover-package bluepyopt; functional: install install_test_requirements stochkv_prepare l5pc_prepare sc_prepare cd bluepyopt/tests; nosetests -a '!unit' -s -v -x --with-coverage --cover-xml \ --cover-package bluepyopt diff --git a/bluepyopt/tests/.gitignore b/bluepyopt/tests/.gitignore index b53725c..3f413ec 100644 --- a/bluepyopt/tests/.gitignore +++ b/bluepyopt/tests/.gitignore @@ -1,2 +1,3 @@ /.coverage /coverage.xml +/coverage_html/ diff --git a/bluepyopt/tests/test_ephys/test_morphologies.py b/bluepyopt/tests/test_ephys/test_morphologies.py index 8fc588c..785301d 100644 --- a/bluepyopt/tests/test_ephys/test_morphologies.py +++ b/bluepyopt/tests/test_ephys/test_morphologies.py @@ -3,6 +3,7 @@ import json import os + import nose.tools as nt from nose.plugins.attrib import attr @@ -15,6 +16,8 @@ 'testdata') simpleswc_morphpath = os.path.join(testdata_dir, 'simple.swc') +simpleswc_ax1_morphpath = os.path.join(testdata_dir, 'simple_ax1.swc') +simpleswc_ax2_morphpath = os.path.join(testdata_dir, 'simple_ax2.asc') simplewrong_morphpath = os.path.join(testdata_dir, 'simple.wrong') @@ -31,23 +34,96 @@ def test_nrnfilemorphology_init(): """ephys.morphologies: testing NrnFileMorphology constructor""" sim = ephys.simulators.NrnSimulator() - # morph = ephys.morphologies.NrnFileMorphology(simple_morphpath) - # nt.assert_is_instance(morph, ephys.morphologies.NrnFileMorphology) - morph = ephys.morphologies.NrnFileMorphology('wrong.swc') nt.assert_raises(IOError, morph.instantiate, sim=sim) morph = ephys.morphologies.NrnFileMorphology(simplewrong_morphpath) + + nt.assert_equal(str(morph), simplewrong_morphpath) + nt.assert_raises(ValueError, morph.instantiate, sim=sim) morph = ephys.morphologies.NrnFileMorphology( simpleswc_morphpath, do_set_nseg=False) + morph.instantiate(sim=sim) morph.destroy(sim=sim) @attr('unit') +def test_nrnfilemorphology_replace_axon(): + """ephys.morphologies: testing NrnFileMorphology replace_axon""" + sim = ephys.simulators.NrnSimulator() + + morph = ephys.morphologies.NrnFileMorphology( + simpleswc_morphpath, + do_replace_axon=True) + + cell = ephys.models.CellModel(name='cell_replace') + icell = cell.create_empty_cell( + cell.name, + sim=sim, + seclist_names=cell.seclist_names, + secarray_names=cell.secarray_names) + + morph.instantiate(sim=sim, icell=icell) + + nt.assert_equal(len([sec for sec in icell.axon]), 2) + + morph.destroy(sim=sim) + icell.destroy() + + +@attr('unit') +def test_nrnfilemorphology_replace_axon_ax1(): + """ephys.morphologies: testing NrnFileMorphology replace_axon with ax1""" + sim = ephys.simulators.NrnSimulator() + + morph = ephys.morphologies.NrnFileMorphology( + simpleswc_ax1_morphpath, + do_replace_axon=True) + + cell = ephys.models.CellModel(name='cell_ax1') + icell = cell.create_empty_cell( + cell.name, + sim=sim, + seclist_names=cell.seclist_names, + secarray_names=cell.secarray_names) + + morph.instantiate(sim=sim, icell=icell) + + nt.assert_equal(len([sec for sec in icell.axon]), 2) + + morph.destroy(sim=sim) + icell.destroy() + + +@attr('unit') +def test_nrnfilemorphology_replace_axon_ax2(): + """ephys.morphologies: testing NrnFileMorphology replace_axon with ax2""" + sim = ephys.simulators.NrnSimulator() + + morph = ephys.morphologies.NrnFileMorphology( + simpleswc_ax2_morphpath, + do_replace_axon=True) + + cell = ephys.models.CellModel(name='cell_ax2') + icell = cell.create_empty_cell( + cell.name, + sim=sim, + seclist_names=cell.seclist_names, + secarray_names=cell.secarray_names) + + morph.instantiate(sim=sim, icell=icell) + + nt.assert_equal(len([sec for sec in icell.axon]), 2) + + morph.destroy(sim=sim) + icell.destroy() + + +@attr('unit') def test_serialize(): """ephys.morphology: testing serialization""" diff --git a/bluepyopt/tests/test_ephys/test_protocols.py b/bluepyopt/tests/test_ephys/test_protocols.py index de4f6e4..6fe5557 100644 --- a/bluepyopt/tests/test_ephys/test_protocols.py +++ b/bluepyopt/tests/test_ephys/test_protocols.py @@ -133,12 +133,104 @@ def test_sweepprotocol_init(): nt.assert_true(isinstance(protocol, ephys.protocols.SweepProtocol)) nt.assert_equal(protocol.total_duration, 50) + nt.assert_equal( + protocol.subprotocols(), {'prot': protocol}) + + nt.assert_true('somatic[0](0.5)' in str(protocol)) protocol.destroy(sim=nrn_sim) dummy_cell.destroy(sim=nrn_sim) @attr('unit') +def test_sequenceprotocol_init(): + """ephys.protocols: Test SequenceProtocol init""" + + nrn_sim = ephys.simulators.NrnSimulator() + dummy_cell = testmodels.dummycells.DummyCellModel1() + # icell = dummy_cell.instantiate(sim=nrn_sim) + soma_loc = ephys.locations.NrnSeclistCompLocation( + name='soma_loc', + seclist_name='somatic', + sec_index=0, + comp_x=.5) + + rec_soma = ephys.recordings.CompRecording( + name='soma.v', + location=soma_loc, + variable='v') + + stim = ephys.stimuli.NrnSquarePulse( + step_amplitude=0.0, + step_delay=0.0, + step_duration=50, + total_duration=50, + location=soma_loc) + + sweep_protocol = ephys.protocols.SweepProtocol( + name='sweep_prot', + stimuli=[stim], + recordings=[rec_soma]) + + seq_protocol = ephys.protocols.SequenceProtocol( + name='seq_prot', + protocols=[sweep_protocol]) + + nt.assert_true(isinstance(seq_protocol, ephys.protocols.SequenceProtocol)) + nt.assert_equal( + seq_protocol.subprotocols(), { + 'seq_prot': seq_protocol, 'sweep_prot': sweep_protocol}) + + sweep_protocol.destroy(sim=nrn_sim) + dummy_cell.destroy(sim=nrn_sim) + + +@attr('unit') +def test_sequenceprotocol_run(): + """ephys.protocols: Test SequenceProtocol run""" + + nrn_sim = ephys.simulators.NrnSimulator() + dummy_cell = testmodels.dummycells.DummyCellModel1() + # icell = dummy_cell.instantiate(sim=nrn_sim) + soma_loc = ephys.locations.NrnSeclistCompLocation( + name='soma_loc', + seclist_name='somatic', + sec_index=0, + comp_x=.5) + + rec_soma = ephys.recordings.CompRecording( + name='soma.v', + location=soma_loc, + variable='v') + + stim = ephys.stimuli.NrnSquarePulse( + step_amplitude=0.0, + step_delay=0.0, + step_duration=50, + total_duration=50, + location=soma_loc) + + sweep_protocol = ephys.protocols.SweepProtocol( + name='sweep_prot', + stimuli=[stim], + recordings=[rec_soma]) + + seq_protocol = ephys.protocols.SequenceProtocol( + name='seq_prot', + protocols=[sweep_protocol]) + + responses = seq_protocol.run( + cell_model=dummy_cell, + param_values={}, + sim=nrn_sim) + + nt.assert_true(responses is not None) + + sweep_protocol.destroy(sim=nrn_sim) + dummy_cell.destroy(sim=nrn_sim) + + +@attr('unit') def test_sweepprotocol_run_unisolated(): """ephys.protocols: Test SweepProtocol unisolated run""" diff --git a/bluepyopt/tests/test_ephys/testdata/simple_ax1.swc b/bluepyopt/tests/test_ephys/testdata/simple_ax1.swc new file mode 100644 index 0000000..41aece6 --- /dev/null +++ b/bluepyopt/tests/test_ephys/testdata/simple_ax1.swc @@ -0,0 +1,6 @@ +# Dummy granule cell morphology +1 1 -5.0 0.0 0.0 5.0 -1 +2 1 0.0 0.0 0.0 5.0 1 +3 1 5.0 0.0 0.0 5.0 2 +4 2 5.0 0.0 0.0 1.0 3 +5 2 10.0 0.0 0.0 1.0 4 diff --git a/bluepyopt/tests/test_ephys/testdata/simple_ax2.asc b/bluepyopt/tests/test_ephys/testdata/simple_ax2.asc new file mode 100644 index 0000000..b40e4f0 --- /dev/null +++ b/bluepyopt/tests/test_ephys/testdata/simple_ax2.asc @@ -0,0 +1,18 @@ +; V3 text file written for MicroBrightField products. + +("CellBody" + (CellBody) + ( -5 0 0 0) ; 1, 1 + ( 0 -5 0 0) ; 1, 2 + ( 5 0 0 0) ; 1, 3 + ( 0 5 0 0) ; 1, 4 +) + +( (Axon) + ( 5 0 0 .5) ; Root + ( 10 0 0 .5) ; 1, R + ( + ( 20 0 0 .5) ; 1, R-1 + ( 1000 0 0 .5) ; 2 + ) +) diff --git a/bluepyopt/tests/test_ephys/testdata/simple_ax2.swc b/bluepyopt/tests/test_ephys/testdata/simple_ax2.swc new file mode 100644 index 0000000..70ac09c --- /dev/null +++ b/bluepyopt/tests/test_ephys/testdata/simple_ax2.swc @@ -0,0 +1,7 @@ +# Dummy granule cell morphology +1 1 -5.0 0.0 0.0 5.0 -1 +2 1 0.0 0.0 0.0 5.0 1 +3 1 5.0 0.0 0.0 5.0 2 +4 2 5.0 0.0 0.0 1.0 3 +5 2 10.0 0.0 0.0 1.0 4 +6 2 100.0 0.0 0.0 1.0 5