def test_cell_class_init(): with raises(AssertionError): CellClass(asdf=1) with raises(AssertionError): CellClass(db.Pair.n_ex_test_spikes < 10) with raises(AssertionError): CellClass([]) with raises(AssertionError): CellClass(name=1)
def test_cell_class_contains(): cell = db.Cell() morpho = db.Morphology() loc = db.CorticalCellLocation() cell.morphology = morpho cell.cortical_location = loc cls = CellClass(cre_type=('sst', 'pvalb')) cell.cre_type = 'sst' assert cell in cls cell.cre_type = 'sim1' assert cell not in cls cls = CellClass(cre_type='sim1', dendrite_type='spiny') morpho.dendrite_type = 'spiny' assert cell in cls morpho.dendrite_type = 'aspiny' assert cell not in cls cls = CellClass(cre_type='sim1', dendrite_type='spiny', cortical_layer='2/3') morpho.dendrite_type = 'spiny' loc.cortical_layer = '2/3' assert cell in cls loc.cortical_layer = '2' assert cell not in cls cls = CellClass(cre_type='sim1', dendrite_type='spiny', cortical_layer='2/3', cell_class='ex') cell.cell_class = 'ex' loc.cortical_layer = '2/3' assert cell in cls cell.cell_class = 'mixed' assert cell not in cls cls = CellClass(input_resistance=0) # no intrinsic added to this cell assert cell not in cls
def ei_hist_plot(ax, metric, bin_edges, db, pair_query_args): ei_classes = {'ex': CellClass(cell_class='ex'), 'in': CellClass(cell_class='in')} pairs_has_metric, metric_name, units, scale, _, _, log_scale, _, _ = get_metric_data(metric, db, ei_classes, ei_classes, pair_query_args=pair_query_args) ex_pairs = pairs_has_metric[pairs_has_metric['pre_class']=='ex'] in_pairs = pairs_has_metric[pairs_has_metric['pre_class']=='in'] if 'amp' in metric: ax[0].hist(ex_pairs[metric]*scale, bins=bin_edges, color=(0.8, 0.8, 0.8), label='All Excitatory Synapses') ax[1].hist(in_pairs[metric]*scale, bins=bin_edges, color=(0.8, 0.8, 0.8), label='All Inhibitory Synapses') else: ax[0].hist(pairs_has_metric[metric]*scale, bins=bin_edges, color=(0.8, 0.8, 0.8), label='All Synapses') ax[1].hist(pairs_has_metric[metric]*scale, bins=bin_edges, color=(0.8, 0.8, 0.8), label='All Synapses') ee_pairs = ex_pairs[ex_pairs['post_class']=='ex'] ei_pairs = ex_pairs[ex_pairs['post_class']=='in'] ax[0].hist(ee_pairs[metric]*scale, bins=bin_edges, color='red', alpha=0.6, label='E->E Synapses') ax[0].hist(ei_pairs[metric]*scale, bins=bin_edges, color='pink', alpha=0.8, label='E->I Synapses') ax[0].legend(frameon=False) ii_pairs = in_pairs[in_pairs['post_class']=='in'] ie_pairs = in_pairs[in_pairs['post_class']=='ex'] ax[1].hist(ii_pairs[metric]*scale, bins=bin_edges, color='blue', alpha=0.4, label='I->I Synapses') ax[1].hist(ie_pairs[metric]*scale, bins=bin_edges, color='purple', alpha=0.4, label='I->E Synapses') ax[1].legend(frameon=False) ax[0].spines['right'].set_visible(False) ax[0].spines['top'].set_visible(False) ax[1].spines['right'].set_visible(False) ax[1].spines['top'].set_visible(False) ax[1].set_xlabel('%s (%s)' % (metric_name, units)) ax[1].set_ylabel('Number of Synapses', fontsize=12) #KS test excitatory = stats.ks_2samp(ee_pairs[metric], ei_pairs[metric]) inhibitory = stats.ks_2samp(ii_pairs[metric], ie_pairs[metric]) print('Two-sample KS test for %s' % metric) print('Excitatory: p = %0.3e' % excitatory[1]) print('Inhibitory: p = %0.3e' % inhibitory[1]) return ex_pairs, in_pairs
def get_pre_or_post_classes(self, key): """Return a list of postsynaptic cell_classes. This will be a subset of self.cell_classes.""" # if self.cell_classes is None: # return [] ccg = copy.deepcopy(self.cell_class_groups) classes = [] for group in self.params.children(): if group.value() is True: if group['pre/post'] in ['both', key]: classes.extend(ccg[group.name()]) classes = self.layer_call(classes) classes = [CellClass(**c) for c in classes] return classes
def get_cell_groups(self, pairs): """Given a list of cell pairs, return a dict indicating which cells are members of each user selected cell class. This internally calls cell_class.classify_cells """ ccg = copy.deepcopy(self.cell_class_groups) if self.cell_groups is None: self.cell_classes = [] for group in self.params.children()[1:]: if group.value() is True: self.cell_classes.extend(ccg[group.name()]) self.cell_classes = self.layer_call(self.cell_classes) self.cell_classes = [CellClass(**c) for c in self.cell_classes] self.cell_groups = classify_cells(self.cell_classes, pairs=pairs) return self.cell_groups, self.cell_classes
def _make_cell_class(self, spec): spec = spec.copy() dnames = spec.pop('display_names') cell_cls = CellClass(**spec, name=' '.join(dnames).strip()) cell_cls.display_names = dnames return cell_cls
def _make_cell_class(self, spec): spec = spec.copy() dnames = spec.pop('display_names') cell_cls = CellClass(**spec) cell_cls.display_names = dnames return cell_cls
def test_correction_model(): # test preparations ei_classes = { 'excit': CellClass(cell_class_nonsynaptic='ex', name='ex'), 'inhib': CellClass(cell_class_nonsynaptic='in', name='in') } correction_metrics = { 'lateral_distance': { 'model': GaussianModel, 'init': (0.1, 100e-6), 'bounds': ((0.001, 1), (100e-6, 100e-6)) }, 'pre_axon_length': { 'model': BinaryModel, 'init': (0.1, 200e-6, 0.5), 'bounds': ((0.001, 1), (200e-6, 200e-6), (0.1, 0.9)) }, 'avg_pair_depth': { 'model': ErfModel, 'init': (0.1, 30e-6, 30e-6), 'bounds': ((0.01, 1), (10e-6, 200e-6), (-100e-6, 100e-6)) }, 'detection_power': { 'init': (0.1, 1.0, 3.0), 'model': ErfModel, 'bounds': ((0.001, 1), (0.1, 5), (2, 5)), 'constraint': (0.6745, 4.6613) }, } # test finite connection cases pairs, variables, conn = data_snippets() corr_model = ei_correct_connectivity(ei_classes, correction_metrics, pairs) # fixing the correction parameters from a larger pool of data correction_parameters = [ [ np.array([0.1, 100e-6]), # lateral_distance (Gaussian) np.array([6.939e-2, 2.000e-4, 6.003e-1]), # pre_axon_length (Binary) np.array([6.893e-2, 4.021e-5, 2.848e-5]), # avg_pair_depth (Erf) np.array([9.847e-2, 6.845e-1, 4.200]) ], # detection_power (Erf) [ np.array([0.1, 100e-6]), np.array([1.227e-1, 2.000e-4, 3.634e-1]), np.array([1.095e-1, 4.130e-5, 2.700e-5]), np.array([1.967e-1, 4.396e-1, 4.365]) ] ] corr_model.correction_parameters = correction_parameters assert corr_model.pmax == 0.1 fit = corr_model.fit(variables, conn, excinh=1) assert corr_model.pmax == pytest.approx(0.74590, 1e-4) assert fit.x == pytest.approx(0.74590, 1e-4) assert corr_model.likelihood(variables, conn) == pytest.approx(-1.95075, 1e-4) assert fit.fun == pytest.approx(1.95075, 1e-4) assert fit.cp_ci[0] == corr_model.pmax assert fit.cp_ci[1] == pytest.approx(0.0478545, 1e-4) # lower MINOS value assert fit.cp_ci[2] == pytest.approx(2.17707, 1e-4) # upper MINOS value # test zero-connection cases pairs, variables, conn = data_snippets('zero') fit = CorrectionModel.fit(corr_model, variables, conn, excinh=1) assert fit.cp_ci[0] == pytest.approx(0, abs=1e-6) assert fit.cp_ci[1] == pytest.approx(0, abs=1e-6) # lower MINOS value assert fit.cp_ci[2] == pytest.approx(1.03155, 1e-4) # upper MINOS value # test full-cnnection cases pairs, variables, conn = data_snippets('full') fit = CorrectionModel.fit(corr_model, variables, conn, excinh=1) assert fit.cp_ci[0] == pytest.approx(3, 1e-4) # maxed out assert fit.cp_ci[1] == pytest.approx(1.87319, 1e-4) # lower MINOS value assert fit.cp_ci[2] == pytest.approx(3, 1e-4) # upper MINOS value return
app.processEvents() mouse_dist_plots[0].setXRange(20e-6, 180e-6, padding=0) mouse_dist_plots[0].setYRange(0, 0.4, padding=0) human_dist_plots[0].setYRange(0, 0.4, padding=0) mouse_hist_plots[0].setYRange(0, 200) human_hist_plots[0].setYRange(0, 50) app.processEvents() # define CellClass, short name, and color for each class mouse_classes = [ (CellClass(target_layer='2/3', pyramidal=True), 'L2/3', (249, 144, 92)), (CellClass(cre_type='rorb'), 'Rorb', (100, 202, 103)), (CellClass(cre_type='tlx3'), 'Tlx3', (81, 221, 209)), (CellClass(cre_type='sim1'), 'Sim1', (45, 77, 247)), (CellClass(cre_type='ntsr1'), 'Ntsr1', (153, 51, 255)), ] human_classes = [ (CellClass(target_layer='2', pyramidal=True), 'L2', (247, 118, 118)), (CellClass(target_layer='3', pyramidal=True), 'L3', (246, 197, 97)), (CellClass(target_layer='4', pyramidal=True), 'L4', (100, 202, 103)), (CellClass(target_layer='5', pyramidal=True), 'L5', (107, 155, 250)), (CellClass(target_layer='6', pyramidal=True), 'L6', (153, 51, 255)), ]
def test_cell_class_is_excitatory(): cls = CellClass(cre_type='sst') assert cls.is_excitatory is False assert cls.output_synapse_type == 'in' cls = CellClass(cre_type='sim1') assert cls.is_excitatory is True assert cls.output_synapse_type == 'ex' cls = CellClass(cre_type=['sst', 'pvalb']) assert cls.is_excitatory is False assert cls.output_synapse_type == 'in' cls = CellClass(cre_type=['sst', 'tlx3']) assert cls.is_excitatory is None assert cls.output_synapse_type is None cls = CellClass(cre_type=['sst'], dendrite_type='spiny') assert cls.is_excitatory is None assert cls.output_synapse_type is None cls = CellClass(cre_type='rorb', dendrite_type='spiny') assert cls.is_excitatory is True assert cls.output_synapse_type == 'ex' cls = CellClass(cre_type='rorb', dendrite_type='sparsely spiny') assert cls.is_excitatory is None assert cls.output_synapse_type is None cls = CellClass(cre_type=['sst', 'vip'], dendrite_type='sparsely spiny') assert cls.is_excitatory is False assert cls.output_synapse_type == 'in' cls = CellClass(cell_class='in') assert cls.is_excitatory is False assert cls.output_synapse_type == 'in' cls = CellClass(cell_class_nonsynaptic='in') assert cls.is_excitatory is False assert cls.output_synapse_type == 'in' cls = CellClass(cell_class='ex') assert cls.is_excitatory is True assert cls.output_synapse_type == 'ex' cls = CellClass(cell_class_nonsynaptic='ex') assert cls.is_excitatory is True assert cls.output_synapse_type == 'ex' cls = CellClass(cell_class='in', cell_class_nonsynaptic='ex') assert cls.is_excitatory is None assert cls.output_synapse_type is None cls = CellClass(target_layer='2/3') assert cls.is_excitatory is None assert cls.output_synapse_type is None cls = CellClass(target_layer='2/3', cell_class='ex') assert cls.is_excitatory is True assert cls.output_synapse_type == 'ex'