def analysis_synapse_count(self, pre_synaptic_cell_type_specifiers, post_synaptic_cell_type_specifiers): """ Analysis of number of synapses in pathways specified by values of pre and post synaptic cell properties. Arguments ---------------- pre_synaptic_cell_type_specifiers :: cell properties post_synaptic_cell_type_specifiers :: cell properties """ return BrainCircuitAnalysis( introduction=""" Not provided. """, methods=""" Not provided. """, phenomenon=Phenomenon( "Sysapse count", """ Number of synapses in a pathway. """), AdapterInterface=self.AdapterInterface, measurement_parameters=self.pathways( pre_synaptic_cell_type_specifiers, post_synaptic_cell_type_specifiers), sample_measurement=self.synapse_count, measurement_collection=measurement.collection.primitive_type, plotter=HeatMap())
def get_phenomenon(cls): """ Get phenomenon form a class' attributes """ name = cls.__name__ description = cls.__doc__ return\ Phenomenon(name, description=description, group=NA)
class LayerCellDensityMeasurement(SampleMeasurement): """ Measurement of layer cell densities. """ phenomenon = Phenomenon("Cell Density", description="Counts of cells per unit volume", group="Composition") parameters = OrderedDict( layer="Layer where the cells density was measured.")
class RegionCellDensityMeasurement(SampleMeasurement): """ Measurement of cell density in a brain region. """ phenomenon = Phenomenon("Cell Density", description="Counts of cells per unit volume", group="Composition") parameters = OrderedDict( region="Region where the cells density was measured.")
class ByLayerCellDensityMeasurement(SampleMeasurement): """ Measurement of cell density, by cortical layer. """ phenomenon = Phenomenon("Cell Density", description="Count of cells per unit volume.", group="Composition") parameters = OrderedDict( layer="Cortical layer where to count the cells in.")
class RegionInhibitoryFractionMeasurement(SampleMeasurement): """ Measurement of the fraction of inhibitory cells. """ phenomenon = Phenomenon( "Inhibitory Fraction", description="Fraction of cells that are inhibitory", group="Composition") parameters = OrderedDict( region="Region where the inhibitory fraction was measured.")
class ByRegionLayerCellDensityMeasurement(SampleMeasurement): """ Measurement of layer cell densities, for regions in a brain. """ phenomenon = Phenomenon("Cell Density", description="Counts of cells per unit volume", group="Composition") parameters = OrderedDict( layer="Layer where the cells were counted", region="Name of the brain region where cell density was measured.")
class CorticalThicknessMeasurement(SampleMeasurement): """ Measurement of total thickness of cortical layers. """ phenomenon = Phenomenon( "cortical_thickness", description="Total cortical thickness.", group="Composition") parameters = OrderedDict( region="Labels for the (sub-)brain regions where layer thickness was measured.")
class LayerThicknessMeasurement(SampleMeasurement): """ Measurement of layer thicknesses. """ phenomenon = Phenomenon( "thickness", description="Thickness of layers", group="Composition") parameters = OrderedDict( layer="Labels for layers where thickness was measured.")
class ByLayerInhibitoryCellFractionMeasurement(SampleMeasurement): """ Measurement of inhibitory cell fraction, by cortical layer. """ phenomenon = Phenomenon( "Inhibitory Cell Fraction", description="Fraction of inhibitory cells in a population.", group="Composition") parameters = OrderedDict( layer="Cortical layer where the inhibitory cell fraction was measured." )
class ByRegionLayerInhibitoryFractionMeasurement(SampleMeasurement): """ Measurement of the fraction of inhibitory cells. """ phenomenon = Phenomenon( "Inhibitory Fraction", description="Fraction of cells that are inhibitory", group="Composition") parameters = OrderedDict( layer="Layer where the cells were counted", region="Name of the brain region where the inhibitory fraction was measured.")
class ByRegionRelativeLayerThicknessMeasurement(SampleMeasurement): """ Measurement of layer thicknesses divided by total cortical thickness. """ phenomenon = Phenomenon( "relative_thickness", description="Thickness of layers", group="Composition") parameters = OrderedDict( layer="Labels for layers where thickness was measured.", region="Labels for the (sub-)brain regions where layer thickness was measured.")
def analysis_number_connections_afferent(self): """ Analyze number of incoming connections. """ return BrainCircuitAnalysis( introduction=""" A circuit model should reproduce experimentally measured number of incoming connections of a cell. Here we analyze number of afferent connections to cells of a given (post-synaptic) cell-type, grouped by the cell-types of the post-synaptic cells. For example, if cell-type is defined by a cell's mtype, then given a pre-synaptic-mtype-->post-synaptic-mtype pathway, we analyze number of afferent connections incident upon the group of cells with the given post-synaptic mtype that originate from the group of all cells with the given pre-synaptic mtype. """, methods=""" For each of pre-synaptic and post-synaptic cell type in the given pathway {}, cells were sampled. Connection probability was computed as the number of cell pairs that were connected to the total number of pairs.""".format(self.sample_size), phenomenon=Phenomenon( "Number Afferent Connections", """ Probability that two neurons in a pathway are connected. While most of the interest will be in `mtype-->mtype` pathways, we can define a pathway as a any two group of cells, one on the afferent side, the other on the efferent side of a (possible) synapse. Given the pre-synaptic and post-synaptic cell types (groups), connection probability counts the fraction of connected pre-synaptic, post-synaptic pairs. Connection probability may be calculated as a function of the soma-distance between the cells in a pair, in which case the measured quantity will be vector-valued data such as a `pandas.Series`. """), AdapterInterface=self.AdapterInterface, measurement_parameters=self.parameters_post_synaptic_cell_mtypes, sample_measurement=self.number_connections_afferent( terminology.sampling_methodology.random, by_soma_distance=True).sample_one, measurement_collection=measurement.collection.series_type, plotter=MultiPlot(mvar=("post_synaptic_cell", "mtype"), plotter=LinePlot( xvar="soma_distance", xlabel="Soma Distance", yvar="number_afferent_connections", ylabel="Mean number of afferent connections", gvar=("pre_synaptic_cell", "mtype"), drawstyle="steps-mid")), report=CircuitAnalysisReport)
def test_adapter_resolution(): """ `BrainCircuitAnalysis` should be able to resolve which adapter to use. """ cell_density_phenomenon =\ Phenomenon( "Cell Density", "Count of cells in a unit volume.", group="composition") model = mock.cortical.get_circuit_model() adapter = mock.cortical.get_circuit_adapter(model) analysis =\ BrainCircuitAnalysis( phenomenon=cell_density_phenomenon, AdapterInterface=CellDensityAdapterInterface, measurement_parameters=Parameters( pd.DataFrame({"layer": range(1, 7)})), plotter=Bars( xvar="layer", xlabel="Layer", yvar=cell_density_phenomenon.label, ylabel=cell_density_phenomenon.name, gvar="dataset")) with pyt.raises(TypeError): analysis(model) with pyt.raises(TypeError): analysis._resolve_adapter_and_model(model) analysis.adapter = adapter assert analysis._resolve_adapter_and_model(model)\ == (adapter, model) assert analysis._resolve_adapter_and_model(model, adapter)\ == (adapter, model) for a, m in 10 * [(adapter, model)]: assert analysis._resolve_adapter_and_model(model) == (a, m)
def suite(cls, adapter): """ A suit of analyses. """ cell_density_phenomenon =\ Phenomenon( "Cell Density", "Count of cells in a unit volume", group="Composition") return AnalysisSuite( *(BrainCircuitAnalysis(phenomenon=phenomenon, AdapterInterface=AdapterInterface, measurement_parameters=Parameters( pd.DataFrame({"layer": range(1, 7)})), plotter=Bars(xvar="layer", xlabel="Layer", yvar=phenomenon.label, ylabel=phenomenon.name, gvar="dataset"), adapter=adapter) for phenomenon, AdapterInterface in (( cell_density_phenomenon, CellDensityAdapterInterface), )))
class LayerThicknessAnalysis(Adapted, BrainCircuitAnalysis): """ Analyze layer thickness of a brain-circuit """ phenomenon = Phenomenon("thickness", description="Thickness of a brain region", group="Composition") regions = Field(""" Brain sub-regions to analyze layer thicknesses in. """) measurement_collection = Field( """ A method to collect measurements for individual parameter set values. """, __default_value__=measurement.collection.series_type) sample_size = Field(""" Number of samples to make. For the peculiar case of this class, this value should be 1. """, __default_value__=1) figures = Field(""" A callable on plotting data that produces figures... """, __default_value__=Bars(xvar="layer", xlabel="Layer", yvar="thickness", ylabel="Thickness", gvar="region")) report = Field(""" An callable that can create a report. """, __default_value__=CircuitAnalysisReport) # class introduction(self): # """ # The cortex consists of layers of cells. Here we analyze how layer # thicknesses vary over a brain region. # """ # pass # @section # def methods(self): # """ # Thickness of layers were measured as the shortest top-bottom line # passing through each voxel in the circuit's physical space. # """ @lazyfield def introduction(self): return Section.introduction(""" The cortex consists of layers of cells. Here we analyze how layer thicknesses vary over a brain region. """) @lazyfield def methods(self): return Section.methods(""" Thickness of layers were measured as the shortest top-bottom line passing through each voxel in the circuit's physical space. """) def get_parameter_sets(self, *args, **kwargs): """ Parameters to compute this analysis for. """ return [{"region": r} for r in self.regions] def get_figures(self, measurement_data, caption=None, **kwargs): """...""" plot_type =\ Bars( xvar="layer", xlabel="Layer", yvar="thickness", ylabel="Thickness", gvar="region") return plot_type.get_figures(measurement_data, caption=caption) @interfacemethod def get_layer_thickness_values(self, circuit_model, region=None, **kwargs): """ Get a sample of values for layer thickness in a named region of the circuit. Arguments -------------- relative : Boolean indicating return of relative layer thickness region : name of the region where the layer thickness must be computed. Notes -------------- For brain regions with arbitrary shape, their thickness can be hard to define. The exact definition is left to the implementation. What this analysis expects is a collection (`pandas.Series`) that may contain a sample of values for each layer in the named region. """ def get_measurement(self, circuit_model, **parameters): """ Measurement to be made on `circuit_model` for given `parameters` """ wide = self.get_layer_thickness_values(circuit_model, **parameters) wide.columns.name = "layer" return pd.concat([wide.iloc[i] for i in range(wide.shape[0])])\ .rename("thickness")
Common attributes of all by layer `CompositionAnalysis` types. """ measurement_parameters = Parameters( pandas.DataFrame({"layer": [1, 2, 3, 4, 5, 6]})) @lazyproperty def plotter(self): return Bars( xvar="layer", xlabel="Layer", yvar=self.phenomenon.label, ylabel=self.phenomenon.name) cell_density_phenomenon = Phenomenon( "Cell Density", "Count of cells in a unit volume.", group="composition") class ByLayerCellDensityAnalysis( ByLayerCompositionAnalysis): """ Analysis of cell density by layer. The `Field` values assigned below are the simplest applicable values. You may customize them. """ phenomenon = cell_density_phenomenon AdapterInterface =\ CellDensityAdapterInterface