# eabhorrocks/horrocksetal24_temporaldynamics architecture

> Architecture diagram of the GitHub repository eabhorrocks/horrocksetal24_temporaldynamics, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eabhorrocks/horrocksetal24_temporaldynamics
- Repository: https://github.com/eabhorrocks/horrocksetal24_temporaldynamics

## Overview

1. **Repository purpose and runtime**
   - This is a MATLAB 2022a analysis repo for the paper on mouse visual cortex population dynamics.
   - The code is organized around per-session processing of pre-extracted `*_basic.mat` files, followed by downstream group-level analyses, plotting, and statistics.

2. **Primary data boundary**
   - The input boundary is session-level data files from the external dataset download.
   - A separate metadata spreadsheet in `AllenDataAnalysis/AllenSessionInfo.xlsx` and the paper’s supplementary tables support session selection and labeling.
   - The output boundary is a set of processed session files and derived metrics consumed by analysis scripts.

3. **Session preprocessing layer**
   - The `processSession_XXX` scripts are the main ingestion/normalization layer.
   - They convert raw session data into analysis-ready structures and intermediate results for:
     - PSTHs
     - decoding
     - factor analysis
     - correlations
     - tuning-over-time
   - These scripts are long-running and intended to be batch-executed, often in parallel.

4. **Allen-specific preprocessing path**
   - `AllenDataAnalysis` contains a dedicated pipeline for Allen dataset processing.
   - `preprocessAllenData.m` and the helper functions in `processingFuns/` build trial, unit, and behavior-aligned structures from raw Allen-format data.
   - `analyseAllenPSTHs.m` and `processSession_allenPSTH.m` operate on those processed Allen structures to generate PSTH summaries and figures.

5. **PSTH and response-shape analysis**
   - The `PSTHs` folder focuses on peri-stimulus time histogram analysis at the cell and population level.
   - It includes scripts for cell-type and speed-dependent stratification, response sorting, and PSTH metric extraction.
   - This subsystem produces figures and response summaries that feed later comparisons.

6. **Correlation and stability analyses**
   - The `Correlations` folder contains temporal, signal, and noise correlation analyses.
   - These scripts quantify response stability and correlation structure across time and conditions.
   - Outputs include precomputed `.mat` intermediates and figure files used in the paper’s correlation results.

7. **Decoding subsystem**
   - The `Decoding` folder contains classifiers and cross-time decoding analyses.
   - It includes discriminant analysis, train/test decoding, multi-population-size decoding, and cross-time decoding scripts.
   - The flow here is: processed spike counts or population responses in, decoding performance matrices and summary statistics out.

8. **Factor analysis and latent-dynamics subsystem**
   - `FactorAnalysis` is the main dimensionality-reduction and latent-dynamics layer.
   - It uses DataHigh/GPFA-style tooling to study low-dimensional structure, angles, fit separation, neural tangling, and single-trial latent trajectories.
   - This subsystem is central for linking population geometry to sensory encoding speed/stability.

9. **Tuning-over-time and longitudinal metrics**
   - `TuningOverTime` tracks how tuning quality changes across time windows within a session.
   - It computes R²-over-time and related timing metrics used for “start,” “finish,” and duration summaries.
   - This layer converts session-level dynamics into compact temporal statistics for paper figures.

10. **Reusable analysis primitives**
   - `NeuralDataAnalysis` provides the shared computational core: spike binning, PSTH construction, responsive-cell tests, pairwise/noise correlations, d-prime, mutual information, decoder helpers, and population geometry metrics.
   - These functions are the common dependency layer used by the higher-level analysis folders.

11. **Shared utility and visualization infrastructure**
   - `GenericFunctions` is a large support library of general MATLAB utilities for statistics, signal handling, file/table helpers, and plotting.
   - `GenericFunctions/Plotting` includes custom plotting primitives, colormaps, and figure-export utilities.
   - The repo also bundles third-party helpers such as CircStat, DABEST-Matlab, npy-matlab, and export_fig.

12. **External custom toolboxes**
   - `Toolboxes_customised` contains vendored copies of the main external dependencies:
     - DataHigh / GPFA for latent trajectory and factor-analysis work
     - CellExplorer CCG utilities for autocorrelogram/cross-correlogram style analyses
     - Umakantha et al. population-metric helpers
   - These toolboxes are integrated into the analysis code rather than treated as separate services.

13. **Review and supplementary analysis layer**
   - `ReviewAnalyses` contains comparison and robustness analyses, likely used for reviewer-facing extensions or alternate criteria.
   - It reuses the same processed session outputs but recomputes selected metrics under different assumptions.

14. **Figure artifacts and static outputs**
   - The repository includes many saved `.fig` files representing publication figures or intermediate visualizations.
   - These are generated outputs, not primary inputs, and show that the analysis pipeline is meant to reproduce both numeric results and manuscript-quality graphics.

Main entry points: [`NeuralDataAnalysis`](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/NeuralDataAnalysis) (Neural core), [`FactorAnalysis`](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/FactorAnalysis) (Factor analysis), [`PSTHs`](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/PSTHs) (PSTHs), [`GenericFunctions/Plotting`](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/GenericFunctions/Plotting) (Plotting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_sessions["Session pipeline"]
  node_n_allen_meta["Allen metadata<br/>session catalog"]
  node_n_allen_pre["Allen preprocess<br/>ingestion pipeline"]
  node_n_allen_psth["Allen PSTH<br/>Allen analysis"]
  node_n_session_psth["PSTH sessions<br/>session processor"]
  node_n_session_decode["Decode sessions<br/>session processor"]
  node_n_session_fa["FA sessions<br/>session processor"]
  node_n_session_corr["Corr sessions<br/>session processor"]
  node_n_session_r2["R2 sessions<br/>session processor"]
end

subgraph group_grp_domain["Analysis subsystems"]
  node_n_decoding["Decoding<br/>analysis subsystem"]
  node_n_fa["Factor analysis<br/>analysis subsystem"]
  node_n_corr["Correlations<br/>analysis subsystem"]
  node_n_psth["PSTHs<br/>analysis subsystem"]
  node_n_tuning["Tuning over time<br/>longitudinal metrics"]
  node_n_review["Review analyses<br/>robustness analyses"]
end

subgraph group_grp_shared["Shared core"]
  node_n_neural_core["Neural core<br/>shared computation"]
  node_n_generic["Generic utils<br/>support library"]
  node_n_plotting["Plotting<br/>visualization support"]
end

subgraph group_grp_toolboxes["Bundled toolboxes"]
  node_n_datahigh["DataHigh/GPFA<br/>latent dynamics toolbox"]
  node_n_ce_ccg["CCG tools<br/>correlogram toolbox"]
  node_n_umakantha["Umakantha metrics<br/>population metrics"]
end

subgraph group_grp_artifacts["Artifacts"]
  node_n_fig_allen["Allen figs<br/>saved figures"]
  node_n_fig_corr["Corr figs<br/>saved figures"]
  node_n_fig_tuning["Tuning figs<br/>saved figures"]
  node_n_sup_info["Supp info<br/>spreadsheet artifact"]
end

node_n_allen_meta -->|"selects sessions"| node_n_allen_pre
node_n_allen_pre -->|"feeds"| node_n_allen_psth
node_n_allen_psth -->|"writes"| node_n_fig_allen
node_n_neural_core -->|"supports"| node_n_session_psth
node_n_neural_core -->|"supports"| node_n_session_decode
node_n_neural_core -->|"supports"| node_n_session_fa
node_n_neural_core -->|"supports"| node_n_session_corr
node_n_neural_core -->|"supports"| node_n_session_r2
node_n_session_psth -->|"feeds"| node_n_psth
node_n_session_decode -->|"feeds"| node_n_decoding
node_n_session_fa -->|"feeds"| node_n_fa
node_n_session_corr -->|"feeds"| node_n_corr
node_n_session_r2 -->|"feeds"| node_n_tuning
node_n_psth -->|"writes"| node_n_fig_allen
node_n_corr -->|"writes"| node_n_fig_corr
node_n_tuning -->|"writes"| node_n_fig_tuning
node_n_decoding -->|"summarizes"| node_n_sup_info
node_n_fa -->|"uses"| node_n_datahigh
node_n_fa -->|"uses"| node_n_umakantha
node_n_corr -->|"uses"| node_n_ce_ccg
node_n_psth -->|"uses"| node_n_plotting
node_n_decoding -->|"uses"| node_n_plotting
node_n_fa -->|"uses"| node_n_plotting
node_n_review -->|"reuses"| node_n_psth
node_n_review -->|"reuses"| node_n_fa
node_n_generic -->|"supports"| node_n_neural_core
node_n_generic -->|"supports"| node_n_plotting

click node_n_allen_meta "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/AllenDataAnalysis/AllenSessionInfo.xlsx"
click node_n_allen_pre "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/AllenDataAnalysis/processingFuns/preprocessAllenData.m"
click node_n_allen_psth "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/AllenDataAnalysis/analyseAllenPSTHs.m"
click node_n_session_psth "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/PSTHs/processSession_PSTH.m"
click node_n_session_decode "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/Decoding/processSession_decoding.m"
click node_n_session_fa "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/FactorAnalysis/processSession_popAnalysis.m"
click node_n_session_corr "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/Correlations/processSession_correlationAnalysis_v2.m"
click node_n_session_r2 "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/TuningOverTime/getTuningTimeInfo_paper.m"
click node_n_neural_core "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/NeuralDataAnalysis"
click node_n_generic "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/GenericFunctions"
click node_n_plotting "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/GenericFunctions/Plotting"
click node_n_decoding "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Decoding"
click node_n_fa "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/FactorAnalysis"
click node_n_corr "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Correlations"
click node_n_psth "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/PSTHs"
click node_n_tuning "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/TuningOverTime"
click node_n_review "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/ReviewAnalyses"
click node_n_datahigh "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Toolboxes_customised/DataHigh-master"
click node_n_ce_ccg "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Toolboxes_customised/CellExplorer_CCG"
click node_n_umakantha "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Toolboxes_customised/UmakanthaMetrics"
click node_n_fig_allen "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/AllenDataAnalysis/figures"
click node_n_fig_corr "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/Correlations/noiseStabiity_longAxis.fig"
click node_n_fig_tuning "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/TuningOverTime/tuningStart_scatter_sameScale.fig"
click node_n_sup_info "https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/SupplementaryInfo/V1 Dynamics Stats And Info Table.xlsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_allen_meta,node_n_allen_pre,node_n_allen_psth,node_n_session_psth,node_n_session_decode,node_n_session_fa,node_n_session_corr,node_n_session_r2 toneBlue
class node_n_decoding,node_n_fa,node_n_corr,node_n_psth,node_n_tuning,node_n_review toneAmber
class node_n_neural_core,node_n_generic,node_n_plotting toneMint
class node_n_datahigh,node_n_ce_ccg,node_n_umakantha toneRose
class node_n_fig_allen,node_n_fig_corr,node_n_fig_tuning,node_n_sup_info toneIndigo
```

## Components

### Session pipeline

Per-session ingestion, normalization, and batch analyses built around processed session inputs.

- [Allen metadata](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/AllenDataAnalysis/AllenSessionInfo.xlsx): session catalog · Spreadsheet and helpers for Allen session selection and labeling. · `AllenDataAnalysis/AllenSessionInfo.xlsx`
- [Allen preprocess](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/AllenDataAnalysis/processingFuns/preprocessAllenData.m): ingestion pipeline · Builds Allen-format trial, unit, and behavior-aligned structures. · `AllenDataAnalysis/processingFuns/preprocessAllenData.m`
- [Allen PSTH](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/AllenDataAnalysis/analyseAllenPSTHs.m): Allen analysis · Runs PSTH summaries and figures for Allen sessions. · `AllenDataAnalysis/analyseAllenPSTHs.m`
- [PSTH sessions](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/PSTHs/processSession_PSTH.m): session processor · Per-session PSTH processing entry point for the main dataset. · `PSTHs/processSession_PSTH.m`
- [Decode sessions](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/Decoding/processSession_decoding.m): session processor · Per-session decoding pipeline for population responses. · `Decoding/processSession_decoding.m`
- [FA sessions](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/FactorAnalysis/processSession_popAnalysis.m): session processor · Per-session factor-analysis and population-geometry entry point. · `FactorAnalysis/processSession_popAnalysis.m`
- [Corr sessions](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/Correlations/processSession_correlationAnalysis_v2.m): session processor · Per-session correlation analysis entry point. · `Correlations/processSession_correlationAnalysis_v2.m`
- [R2 sessions](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/TuningOverTime/getTuningTimeInfo_paper.m): session processor · Per-session tuning-over-time processing. · `TuningOverTime/getTuningTimeInfo_paper.m`

### Analysis subsystems

Major scientific analysis branches used in the paper.

- [Decoding](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Decoding): analysis subsystem · Classifiers and cross-time decoding analyses. · `Decoding`
- [Factor analysis](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/FactorAnalysis): analysis subsystem · Latent-dynamics, GPFA/DataHigh, fit separation, tangling, and trajectory analysis. · `FactorAnalysis`
- [Correlations](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Correlations): analysis subsystem · Temporal, signal, and noise correlation analyses. · `Correlations`
- [PSTHs](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/PSTHs): analysis subsystem · Cell- and population-level PSTH stratification and metric extraction. · `PSTHs`
- [Tuning over time](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/TuningOverTime): longitudinal metrics · Computes R2-over-time and timing summaries. · `TuningOverTime`
- [Review analyses](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/ReviewAnalyses): robustness analyses · Alternate criteria and comparison analyses reusing processed outputs. · `ReviewAnalyses`

### Shared core

Reusable analysis primitives and infrastructure.

- [Neural core](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/NeuralDataAnalysis): shared computation · Spike binning, PSTHs, response tests, correlations, decoding helpers, and geometry metrics. · `NeuralDataAnalysis`
- [Generic utils](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/GenericFunctions): support library · Common MATLAB utilities for statistics, tables, signals, and general helpers. · `GenericFunctions`
- [Plotting](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/GenericFunctions/Plotting): visualization support · Custom plotting primitives, colormaps, and figure export utilities. · `GenericFunctions/Plotting`

### Bundled toolboxes

Vendored external dependencies integrated into the MATLAB analysis code.

- [DataHigh/GPFA](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Toolboxes_customised/DataHigh-master): latent dynamics toolbox · Vendored DataHigh and GPFA tooling for dimensionality reduction and latent trajectories. · `Toolboxes_customised/DataHigh-master`
- [CCG tools](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Toolboxes_customised/CellExplorer_CCG): correlogram toolbox · CellExplorer cross-correlogram utilities and compiled helpers. · `Toolboxes_customised/CellExplorer_CCG`
- [Umakantha metrics](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/Toolboxes_customised/UmakanthaMetrics): population metrics · Vendored population-metric helpers used by the analysis code. · `Toolboxes_customised/UmakanthaMetrics`

### Artifacts

Static figures and spreadsheet inputs bundled with the repo.

- [Allen figs](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/tree/main/AllenDataAnalysis/figures): saved figures · Pre-rendered PSTH and response summary figures for Allen analyses. · `AllenDataAnalysis/figures`
- [Corr figs](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/Correlations/noiseStabiity_longAxis.fig): saved figures · Saved correlation result figures. · `Correlations/noiseStabiity_longAxis.fig`
- [Tuning figs](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/main/TuningOverTime/tuningStart_scatter_sameScale.fig): saved figures · Saved longitudinal tuning figures. · `TuningOverTime/tuningStart_scatter_sameScale.fig`
- [Supp info](https://github.com/eabhorrocks/horrocksetal24_temporaldynamics/blob/HEAD/SupplementaryInfo/V1%20Dynamics%20Stats%20And%20Info%20Table.xlsx): spreadsheet artifact · Supplementary statistics and information table. · `SupplementaryInfo/V1 Dynamics Stats And Info Table.xlsx`

## Connections

- Allen metadata → Allen preprocess: selects sessions · Metadata guides Allen session preprocessing.
- Allen preprocess → Allen PSTH: feeds · Preprocessed Allen structures are analyzed for PSTHs.
- Allen PSTH → Allen figs: writes · Allen analysis produces saved figures.
- Neural core → PSTH sessions: supports · Shared PSTH and response routines power per-session processing.
- Neural core → Decode sessions: supports · Shared decoding helpers power per-session decoding.
- Neural core → FA sessions: supports · Shared geometry and latent-dynamics metrics support factor analysis.
- Neural core → Corr sessions: supports · Shared correlation routines support per-session correlation analysis.
- Neural core → R2 sessions: supports · Shared R2-over-time computation supports tuning analysis.
- PSTH sessions → PSTHs: feeds · Session outputs are consumed by PSTH analyses.
- Decode sessions → Decoding: feeds · Session outputs are consumed by decoding analyses.
- FA sessions → Factor analysis: feeds · Session outputs are consumed by factor-analysis analyses.
- Corr sessions → Correlations: feeds · Session outputs are consumed by correlation analyses.
- R2 sessions → Tuning over time: feeds · Session outputs are consumed by tuning-over-time analyses.
- PSTHs → Allen figs: writes · PSTH work also produces publication-style figures.
- Correlations → Corr figs: writes · Correlation analyses emit saved figures.
- Tuning over time → Tuning figs: writes · Longitudinal tuning analyses emit saved figures.
- Decoding → Supp info: summarizes · Decoding and analysis summaries contribute to supplementary tables.
- Factor analysis → DataHigh/GPFA: uses · Latent-dynamics analyses depend on DataHigh/GPFA tooling.
- Factor analysis → Umakantha metrics: uses · Factor-analysis metrics reuse shared population-metric helpers.
- Correlations → CCG tools: uses · Correlation analyses rely on correlogram tooling where needed.
- PSTHs → Plotting: uses · PSTH figures rely on shared plotting infrastructure.
- Decoding → Plotting: uses · Decoding plots rely on shared plotting infrastructure.
- Factor analysis → Plotting: uses · Factor-analysis visualizations rely on shared plotting infrastructure.
- Review analyses → PSTHs: reuses · Review analyses recompute selected PSTH metrics under alternate criteria.
- Review analyses → Factor analysis: reuses · Review analyses recompute selected factor-analysis metrics under alternate criteria.
- Generic utils → Neural core: supports · Generic utilities underpin the shared computational core.
- Generic utils → Plotting: supports · Generic utilities include plotting helpers and export tooling.
