Skip to content

Compare Neural State Data Across Epochs

Compute Credits

This tool uses 1.0 compute credits per hour.

Overview

The Compare Neural State Data Across Epochs tool performs comprehensive analysis of neural activity patterns across behavioral states and time epochs, calculating activity measures, correlation metrics, and modulation indices relative to a user-specified baseline state-epoch combination. This tool integrates correlation analysis and population activity analysis into a unified workflow, enabling researchers to understand how neural dynamics change across experimental conditions.

Comparison Method: State vs Baseline Only

Unlike the Compare Neural Activity Across States tool which supports multiple comparison methods (state vs not state, pairwise, state vs baseline, state vs not defined), this tool currently only supports the "state vs baseline" comparison method.

Design Rationale:
This focused approach prevents combinatorial explosion when analyzing state-epoch combinations. For example, with 4 behavioral states and 4 time epochs, pairwise comparisons would generate 120 unique combinations ((16 × 15) / 2), making results difficult to interpret and computationally expensive.

By requiring a single baseline state-epoch reference, the tool produces a manageable number of comparisons (one per non-baseline state-epoch combination) while maintaining clear biological interpretation relative to a control condition.

Potential Future Expansion:
Support for "state-epoch vs not state-epoch" comparison may be added in future versions to enable comparisons of each state-epoch combination against all other time periods, similar to the "state vs not state" method in the Population Activity tool. If you’d like this feature, please reach out to inscopix.support@bruker.com.

Input Data

This tool requires synchronized neural activity data, behavioral annotations, and epoch definitions. It can analyze calcium trace data and optionally calcium event data.

Valid Inputs

File Type Required? Description
Cell Set File(s) (.isxd) Yes One or more cell set files containing calcium traces and cell spatial footprints. If multiple are provided, they can be concatenated.
Event Set File(s) (.isxd) No Optional. One or more event set files containing detected calcium events. Must correspond to the cell set files.
Annotations File (.parquet or .csv) Yes¹ A synchronized annotations file containing behavioral state labels aligned with the neural data.

Note

  1. The analysis defaults to requiring an annotations file. It can only be omitted when the internal allow_epoch_only_mode feature flag is enabled (restricted to development workflows).

Generating synchronized annotation files

You can generate the synchronized annotation file by running one of these synchronization tools:

Parameters

Parameter Required? Default Description
Cell Set File(s) True N/A ISXD cell set file(s) containing neural activity data
Event Set File(s) False N/A ISXD event set file(s) containing neural events data
Annotations File False N/A Optional experiment annotations file with state and epoch information. If not provided, uses epoch-only analysis mode.
Define Epochs By True N/A Method to define epochs. If 'files', one epoch per input cell set will be automatically defined, for the whole duration of each cell set. If 'global file time', you can define as many epochs as you want, with 0 corresponding to start time of the first cell set. If 'local file time', you can define as many epochs as you want per input cell set, with 0 corresponding to start time of each cell set.
Epochs False N/A Tuples of the start and end times (in seconds) for each epoch (e.g., if 'Define Epochs by' is set to 'Global file time', (0, 600), (650, 950), (950, 1250)). If 'Define Epochs by' is set to 'Local file time', provide one list of tuple per input cell set file (e.g., [(0, 600)], [(0, 300), (300, 600)]). If 'Define Epochs by' is set to 'Files', you can leave this parameter empty.
Epoch Names True N/A Comma-separated list of time epoch names (e.g., 'baseline, training, test')
Epoch Colors False N/A Comma-separated list of colors for epochs (e.g., 'lightgray, lightblue, lightgreen')
State Column Name False N/A Name of the column in annotations file containing state information
State Names True N/A Comma-separated list of behavioral state names (e.g., 'rest, active, exploration')
State Colors False N/A Comma-separated list of colors for states (e.g., 'gray, blue, green')
Baseline State True N/A State to use as baseline for modulation calculations
Baseline Epoch True N/A Epoch to use as baseline for modulation calculations
Correlation Statistic False N/A Per-cell correlation statistic to summarize in distribution previews (max, min, or mean).
Method to Compare States True state vs baseline Specifies how states are compared; this tool currently supports only state vs baseline comparisons.
Concatenate Files False N/A Whether to concatenate multiple input files
Trace Scaling Method False N/A Method for scaling trace data. Baseline methods require baseline_state to be specified.
Event Scaling Method False N/A Method for scaling event data. Baseline methods require baseline_state to be specified.
Event Correlation Previews False N/A Attach event-based correlation previews to the outputs when event data and correlations are available.
Tolerance False N/A Tolerance for temporal alignment and file concatenation
Sort by Time False N/A Whether to sort cellsets by time when concatenating
Significance Level False N/A Significance level for statistical tests
Number of Shuffles False N/A Number of shuffles for permutation tests

Algorithm Details

The following diagram demonstrates the steps of the tool algorithm.

graph TD Start[Start Workflow] --> LoadData[Load Input Data
Cell Sets, Annotations, Events]; LoadData --> DefineEpochs[Define Time Epochs
Based on Epoch Parameters]; DefineEpochs --> AnalyzeLoop{For Each State-Epoch Combination}; AnalyzeLoop --> PopActivity[Calculate Population Activity
Mean Traces & Event Rates]; AnalyzeLoop --> Correlations[Calculate Pairwise Correlations
Pearson Correlation Matrices]; PopActivity --> StoreResults[Store Combination Results]; Correlations --> StoreResults; StoreResults --> MoreCombos{More Combinations?}; MoreCombos -- Yes --> AnalyzeLoop; MoreCombos -- No --> ValidateBaseline[Validate Baseline Availability]; ValidateBaseline --> CalcModulation[Calculate Modulation Indices
Relative to Baseline]; CalcModulation --> GenOutputs[Generate Output Files
& Visualizations]; GenOutputs --> End[Complete];

The following sections describe the metrics and procedures performed by the algorithm.

Epoch Definition

Time epochs are defined using one of three methods specified by the Define Epochs By parameter:

  • global file time: Epochs are defined relative to the start of the entire recording session. For concatenated files, time continues across file boundaries.
  • files: Each input file is treated as a separate epoch automatically, ignoring the Epochs parameter.
  • local file time: Epochs are defined relative to the start of each individual file. The same epoch time ranges are applied to each file independently.

The Epochs parameter specifies time ranges as comma-separated tuples: "(start1, end1), (start2, end2), ..." in seconds.

Activity Measures

  • Trace Activity: The mean of the calcium trace signal during a given state-epoch combination. Traces can be optionally rescaled using several methods:

    • none: Original raw calcium trace values are preserved without any transformation
    • normalize: Scales all trace values to the range [0, 1] by applying min-max normalization across the entire recording period
    • standardize: Converts traces to z-scores by subtracting the mean and dividing by the standard deviation across the entire recording
    • fractional_change: Calculates the ratio of activity to baseline state mean after ensuring non-negative values
    • standardize_baseline: Computes z-scores relative to the baseline state
  • Event Rate: If event sets are provided, the tool calculates the event rate (events per second) for each cell. These rates can be rescaled using the same methods as trace activity.

Correlation Analysis

For each state-epoch combination, the tool computes:

  1. Pairwise Pearson correlation between all neuron pairs using the Pearson correlation coefficient:
\[ \begin{aligned} r = \frac{\sum_{i=1}^{n}(X_i - \bar{X})(Y_i - \bar{Y})}{\sqrt{\sum_{i=1}^{n}(X_i - \bar{X})^2 \sum_{i=1}^{n}(Y_i - \bar{Y})^2}} \end{aligned} \]

where \(X_i\) and \(Y_i\) are individual trace values, and \(\bar{X}\) and \(\bar{Y}\) are the means.

  1. Per-cell correlation statistics: For each cell, one of the following statistics is computed across its correlations with other cells:
  2. Maximum correlation: Highest correlation value with any other cell
  3. Mean correlation: Average correlation across all other cells
  4. Minimum correlation: Lowest correlation value with any other cell

  5. Population correlation metrics: Average positive and negative correlation values across all cell pairs

Modulation Score

The modulation score quantifies the change in activity between each state-epoch combination and the baseline state-epoch combination. This tool exclusively uses the "state vs baseline" comparison method to avoid combinatorial complexity (see note in Overview section):

\[ \text{Modulation} = \frac{ \text{mean activity in state-epoch} - \text{mean activity in baseline} }{ \text{mean activity in state-epoch} + \text{mean activity in baseline} } \]

Before calculation, a minimum value subtraction is applied to ensure activity values are non-negative, bounding the score between -1 and 1.

Significance Level (p-value)

Trace modulation significance is determined using a circular permutation test:

  1. The time labels corresponding to the state-epoch combinations being compared are randomly shifted (rolled) for the specified number of shuffles.
  2. For each shuffle, a surrogate modulation score is calculated.
  3. Two one-tailed probabilities are computed:
  4. \(p_\text{high}\): fraction of shuffled scores greater than the observed score
  5. \(p_\text{low}\): fraction of shuffled scores less than the observed score
  6. The reported trace_p_values column stores \(\min(p_\text{high}, p_\text{low})\), which lies in \([0, 0.5]\) and reflects the stronger tail.

Directional classifications (up- vs down-modulated) apply the original tail probabilities with a Bonferroni-style split:
- up-modulated if the observed modulation score is positive and \(p_\text{high} < \alpha / 2\)
- down-modulated if the observed modulation score is negative and \(p_\text{low} < \alpha / 2\)
- otherwise non-significant

This matches the permutation procedure used in the standard Python population-activity workflow and maintains an overall Type I error rate of α. The resolution of the probabilities depends on the number of shuffles (e.g., 1000 shuffles give a resolution of 0.001).

Event modulation uses the same permutation workflow whenever raw event traces are available (i.e., when Event Set File(s) are supplied). In that case, event_p_values follow the same interpretation as trace p-values and directional classifications use the identical α/2 thresholds. If only aggregated event rates are present (no time-resolved event traces), the tool falls back to an effect-size heuristic: event_p_values are set to 1.0 and modulation labels rely on |score| > 0.1.

Cell Selection Criteria

The tool uses cell status information from the input cell set(s) to determine which cells to include in the analysis:

  • Accepted cells: When present, only accepted cells are analyzed
  • Undecided cells: Used when no accepted cells are available
  • Rejected cells: If all cells are rejected, the tool terminates with an error
  • Automatic rejection: Cells whose traces contain only NaN values are automatically marked as rejected

Outputs

The tool generates four main CSV files containing detailed analysis results and comprehensive visualization previews.

Data Files

  • activity_per_state_epoch_data.csv: Contains mean activity, standard deviation, median, and coefficient of variation for trace and event data (if available) for each cell in each state-epoch combination.
  • correlations_per_state_epoch_data.csv: Contains all correlation statistics (max, mean, and min) for each cell in each state-epoch combination, plus population-level positive and negative correlation averages.
  • average_correlations.csv: Contains the average positive and average negative correlation values for each state-epoch combination.
  • modulation_vs_baseline_data.csv: Contains modulation scores, p-values, and modulation classifications for each cell across all state-epoch combinations relative to the baseline.

Activity Per State Epoch Data

Each row corresponds to a single cell in a specific state-epoch combination (long format). Columns include:

  • name: Cell identifier
  • cell_index: Numeric cell index
  • state: Behavioral state name
  • epoch: Time epoch name
  • mean_trace_activity: Mean calcium trace activity for the cell during that state-epoch combination
  • std_trace_activity: Standard deviation of trace activity
  • median_trace_activity: Median trace activity
  • trace_activity_cv: Coefficient of variation for trace activity
  • mean_event_rate: Mean event rate for the cell (if event data provided)
  • std_event_rate: Standard deviation of event rate (if event data provided)
  • median_event_rate: Median event rate (if event data provided)
  • event_rate_cv: Coefficient of variation for event rate (if event data provided)

Example activity_per_state_epoch_data.csv:

name cell_index state epoch mean_trace_activity mean_event_rate
C000 0 rest baseline 8.013 0.125
C000 0 rest training 7.542 0.098
C001 1 rest baseline 14.862 0.342
C001 1 rest training 16.204 0.401

Correlations Per State Epoch Data

Each row corresponds to a single cell in a specific state-epoch combination (long format). Columns include:

  • name: Cell identifier
  • cell_index: Numeric cell index
  • state: Behavioral state name
  • epoch: Time epoch name
  • max_trace_correlation: Maximum correlation with any other cell for traces
  • min_trace_correlation: Minimum correlation with any other cell for traces
  • mean_trace_correlation: Mean correlation across all other cells for traces
  • max_event_correlation: Maximum correlation with any other cell for events (if event data provided)
  • min_event_correlation: Minimum correlation with any other cell for events (if event data provided)
  • mean_event_correlation: Mean correlation across all other cells for events (if event data provided)
  • positive_trace_correlation: Population-level average of positive correlations for traces (same value for all cells in this state-epoch)
  • negative_trace_correlation: Population-level average of negative correlations for traces (same value for all cells in this state-epoch)
  • positive_event_correlation: Population-level average of positive correlations for events (if event data provided)
  • negative_event_correlation: Population-level average of negative correlations for events (if event data provided)

Note

The Correlation Statistic parameter (max, mean, or min) controls which per-cell statistic is used for visualization previews, but the CSV file always contains all three statistics (max, min, and mean).

Example correlations_per_state_epoch_data.csv:

name cell_index state epoch max_trace_correlation min_trace_correlation mean_trace_correlation
C000 0 rest baseline 0.85 -0.12 0.31
C000 0 rest training 0.78 -0.18 0.28
C001 1 rest baseline 0.73 -0.09 0.35
C001 1 rest training 0.81 -0.15 0.39

Average Correlations

Each row corresponds to a state-epoch combination. This file provides a summary of population-level correlation patterns. Columns include:

  • state: State-epoch combination identifier in format "{state}-{epoch}" (e.g., "rest-baseline")
  • positive_trace_correlation: Average positive correlation value for traces
  • negative_trace_correlation: Average negative correlation value for traces
  • positive_event_correlation: Average positive correlation value for events (if event data provided)
  • negative_event_correlation: Average negative correlation value for events (if event data provided)

Example average_correlations.csv:

state positive_trace_correlation negative_trace_correlation
rest-baseline 0.42 -0.15
rest-training 0.38 -0.18
explore-baseline 0.51 -0.12

Modulation vs Baseline Data

Each row corresponds to a single cell. Columns include:

  • name: Cell identifier
  • cell_index: Numeric cell index
  • state: State name for this modulation comparison
  • epoch: Epoch name for this modulation comparison
  • baseline_state: Baseline state name
  • baseline_epoch: Baseline epoch name
  • trace_modulation_scores in {state}-{epoch}: Modulation score for trace activity relative to baseline
  • trace_p_values in {state}-{epoch}: P-value from permutation test for trace modulation
  • trace_modulation in {state}-{epoch}: Modulation classification (-1 for significantly down-modulated, 1 for significantly up-modulated, 0 for non-significant)
  • event_modulation_scores in {state}-{epoch}: Modulation score for event rate relative to baseline (if event data provided)
  • event_p_values in {state}-{epoch}: P-value from the event permutation test (or 1.0 when only aggregate event rates are available)
  • event_modulation in {state}-{epoch}: Modulation classification for events (permutation-based when event traces exist, or |score| > 0.1 when falling back to rate-only data)

Note

Column names use spaces and hyphens (e.g., trace_modulation_scores in rest-training) rather than underscores.

Example modulation_vs_baseline_data.csv:

name trace_modulation_scores in rest-training trace_p_values in rest-training trace_modulation in rest-training
C000 -0.0575 0.256 0
C001 0.3215 0.006 1
C002 -0.2183 0.002 -1

Additional Output Files

The tool also generates binary files containing raw correlation data:

  • pairwise_correlation_heatmaps.h5: HDF5 file containing raw correlation matrices for each state-epoch combination. Each dataset corresponds to a state-epoch combination and contains a 2D NumPy array of cell-cell Pearson correlations.
  • spatial_analysis_pairwise_correlations.zip: ZIP archive containing detailed correlation data in CSV format, including full correlation matrices, upper triangle matrices with cell pairs and spatial information (centroid coordinates and distances between cell pairs), and a README file explaining the contents.

Previews

The tool generates comprehensive SVG visualizations for data interpretation:

State-Epoch Time Analysis

Displays the duration spent in each state-epoch combination, organized by state with epoch breakdowns.

Time spent in each state-epoch combination

Population Activity Summary

Bar plots displaying mean population activity (calcium traces) for each state-epoch combination with error bars showing standard error.

Average trace activity across state-epoch combinations

Neural Trace Preview

Shows calcium traces for a subset of neurons over time, with traces colored by behavioral state to visualize state-dependent activity patterns.

Calcium traces colored by behavioral state

Event Rate Summary

Box plots showing mean population event rates for each state-epoch combination with individual cell data points. Generated only when event data is provided.

Average event rates across state-epoch combinations

Event Raster Display

Raster plot visualizing detected calcium events across cells over time, with events colored by behavioral state. Generated only when event data is provided.

Event raster plot colored by behavioral state

Spatial Modulation Map

Spatial footprint visualization showing significantly up-modulated (red outline) and down-modulated (blue outline) cells relative to baseline for each state-epoch combination.

Spatial distribution of modulated neurons relative to baseline

Modulation Distribution

Histograms showing modulation score distributions for each state-epoch combination, with color-coded regions indicating significantly up-modulated (red) and down-modulated (blue) cells.

Distribution of modulation scores relative to baseline

Event-Based Spatial Modulation

Spatial footprint maps showing cells with significant event rate modulation using color-coded outlines. Generated only when event data is provided.

Spatial distribution of event-modulated neurons

Event Modulation Distribution

Histograms displaying event rate modulation score distributions with color-coded regions. Generated only when event data is provided.

Distribution of event modulation scores

Correlation Statistic Distributions

Compares the distribution of the selected correlation statistic across state-epoch combinations through cumulative distribution functions (CDFs) and box plots.

Distribution of per-cell correlation statistics

Average Correlations

Bar plots comparing the mean positive and negative correlation values across all state-epoch combinations.

Average positive and negative correlations

Correlation Heat Maps

Displays correlation matrices as heat maps for each state-epoch combination. Matrices are reorganized using hierarchical clustering to group highly correlated cell pairs.

Pairwise correlation matrices

Spatial Correlation Analysis

Examines the relationship between spatial proximity and neural correlation strength through scatter plots with regression lines and density visualizations for each state-epoch combination.

Correlation versus spatial distance

Spatial Correlation Map

Visualizes the spatial organization of neural correlations by displaying cell positions with connecting lines between highly correlated pairs for each state-epoch combination. Line colors represent correlation polarity (positive/negative), while line presence indicates correlations above a predefined threshold.

Spatial map of neural correlations

Note

Event-based visualizations (event rates, event modulation, and event correlations) are generated only when Event Set File(s) are provided in the analysis