Code for: Granule cells reorient cortical trajectories to separate contexts
Abstract
# Granule cells reorient cortical trajectories to separate contexts Two codebases Garcia-Garcia et al. (in press, 2026): (1) Python simulations (Fig. 5) [expansion_layer_geom-main.zip] (2) MATLAB data analysis [garciagarcia-2026-main.zip] with documentation for the associated processed behavioral and dual-site two-photon imaging data. ## Data availability The processed data are archived on Dryad and are not stored in this GitHub repository. - **Dryad record:** [url pending] - Download `data1.mat` through `data4.mat` and `optodata.mat`. - Place the downloaded files in a `data/` directory beside the analysis scripts, or select their location when prompted by the setup section. ## Repository contents - `GarciaGarcia2026.m` - principal imaging and behavioral analysis. - `GarciaGarcia2026_gtacr1.m` - GtACR1 optogenetic analysis. - `dependencies/` - helper functions required by the analysis. The study follows the same mice while they learn two skills in parallel: - **Reach:** the mouse pushes a robotic handle with its left forepaw. A successful reach is followed by a 1 s delay and water reward. - **VR:** the mouse runs along a 60 mm virtual linear track. Arrival at the target is followed by the same 1 s delay and water reward. Although the tasks use different movements, sensory environments, and apparatuses, both share the temporal structure **Action -> 1 s Delay -> Reward + ITI**. Premotor layer 5 pyramidal tract neurons (L5PTs) and cerebellar granule cells (GrCs) were imaged simultaneously and tracked across sessions. Most of the paper, including the principal analyses in Figures 1-4, concerns animals after dual-task training. The Novice recordings are used later, primarily in Figure 5 and Extended Data Figure 5, to examine how context separation develops with learning. The workspace is organized as follows: - `crossTask` (`27 x 1` struct) contains paired VR and Reach sessions: - **18 Trained pairs**, represented in the workspace by the `mid` and `expert` learning-stage labels. These are the primary data used to compare cortical generalization with cerebellar context separation. - **9 Novice pairs**, labeled `novice`. These were recorded on consecutive VR and Reach training days immediately after pre-training, before animals had learned predictive timing in both tasks. - `sameTask` (`9 x 1` struct) contains Trained VR-VR or Reach-Reach session pairs. These are cross-day controls used to distinguish genuine context-dependent remapping from tracking noise or ordinary day-to-day variability. - `xlstbl` (`70 x 16` table) is the session manifest and matching table. In the manuscript, **Trained** is the group-level term encompassing the `mid` and `expert` acquisition stages. The public analysis script consistently combines `mid` and `expert` for group-level Trained analyses: Example stage selection: ```matlab stage = lower([crossTask.learningstage]); trainedIdx = ismember(stage, ["mid", "expert"]); noviceIdx = stage == "novice"; trainedCrossTask = crossTask(trainedIdx); % 18 VR-Reach pairs noviceCrossTask = crossTask(noviceIdx); % 9 VR-Reach pairs trainedControls = sameTask; % 9 same-task pairs ``` ## Files in this dataset | File | Approximate size | Saved variables | Contents | |---|---:|---|---| | `data1.mat` | 1.488 GB | `xlstbl1` | First fragment of the session manifest and its nested processed single-session data. | | `data2.mat` | 2.294 GB | `xlstbl2` | Second fragment of the session manifest and its nested processed single-session data. | | `data3.mat` | 3.092 GB | `xlstbl3` | Third fragment of the session manifest and its nested processed single-session data. | | `data4.mat` | 3.760 GB | `crossTask`, `sameTask` | Analysis-ready paired-session imaging and behavioral structures. | | `optodata.mat` | 0.027 GB | `laser_stack`, `lickratestack`, `lickstack`, `tplt_s_tsk` | Processed GtACR1 optogenetic licking data for Extended Data Figure 2. | The five files total approximately 10.662 GB. The MAT-files contain processed data; raw two-photon movies are not included. ## Software and hardware requirements The associated analysis was tested with MATLAB R2025a. Required MathWorks products are: - MATLAB; - Statistics and Machine Learning Toolbox; - Signal Processing Toolbox; and - Image Processing Toolbox. The analysis uses MATLAB R2025a functions including `kde` and `violinplot`. Earlier MATLAB releases are not supported. Because loading the complete manifest and paired structures requires substantially more memory than the compressed files occupy on disk, a computer with at least 32 GB RAM is recommended. The analysis scripts add the bundled `dependencies/` directory automatically during setup. ## Loading the public data The scripts look for the required MAT-files first in a `data` subdirectory beside the scripts and then beside the scripts themselves. If the files are not found, the setup section asks the user to select the Dryad download directory. A recommended local arrangement is: ```text GarciaGarcia2026.m GarciaGarcia2026_gtacr1.m dependencies/ data/ data1.mat data2.mat data3.mat data4.mat optodata.mat ``` Run the first setup section of `GarciaGarcia2026.m` before running later sections. It loads the four imaging files and constructs the combined manifest as: ```matlab xlstbl = vertcat(xlstbl1,xlstbl2,xlstbl3); clear xlstbl1 xlstbl2 xlstbl3 ``` Run the setup section of `GarciaGarcia2026_gtacr1.m` to load `optodata.mat`. Both scripts add the bundled `dependencies` directory using the saved script location, so they remain compatible with section-by-section execution in the MATLAB Editor. The main analysis is implemented as ordered MATLAB sections. Many later figure sections use intermediate variables created by the joint-PCA section, so running isolated later sections in a fresh workspace may fail. ## Optogenetic licking dataset `optodata.mat` contains the processed trial-level data for the GtACR1 experiment in Extended Data Figure 2. The manuscript describes four sessions from four mice. The file contains four saved variables: - `tplt_s_tsk` — `1 x 2` cell array of reward-centered time vectors. Element 1 is Reach (801 samples, `dt = 0.005 s`, -2 to 2 s); element 2 is VR (20,001 samples, `dt = 0.0002 s`, -2 to 2 s). - `lickstack` — `2 x 1` cell array. Each task element contains four binary trial-by-time lick-contact matrices. - `lickratestack` — `2 x 1` cell array with the same organization, containing normalized lick-rate traces. Values were normalized to the peak lick rate in rewarded laser-off trials; filtering/normalization can produce small values below zero. - `laser_stack` — `2 x 1` cell array with the same organization, containing binary laser-state matrices. Within each task, the four groups are ordered: 1. Rewarded, laser-off. 2. Rewarded, laser-on. 3. Reward omitted, laser-off. 4. Reward omitted, laser-on. The trial counts are `[263, 34, 48, 43]` for Reach and `[243, 35, 39, 34]` for VR. The analysis summarizes normalized lick rate from -0.7 to -0.2 s relative to reward. The detected laser epochs are -0.745 to -0.200 s for Reach and -0.7978 to -0.1058 s for VR. The processed file pools trials and does not store mouse or session identifiers aligned to individual rows. The GtACR1 plots andcomparisons use trials as observations. ## Experimental and processing summary - L5PTs in premotor cortex expressed jRGECO1a and were imaged through the cortical arm of a custom dual-site microscope. - GrCs expressed GCaMP6f and were imaged simultaneously in contralateral cerebellar Crus I, Crus II, or simplex. - Imaging frames were acquired at 30 Hz. - Movies were motion-corrected with NoRMCorre, slow fluorescence drift was removed, and sources were extracted with constrained non-negative matrix factorization followed by manual curation. - Extracted fluorescence traces were z-scored. - Cells were registered across the paired imaging sessions. The analysis retained cells with validated activity in both sessions. - Unless a particular analysis states otherwise, paired neural comparisons use cells that were jointly task-locked in both sessions. Reliability was calculated from odd-versus-even trial averages, corrected with the Spearman-Brown formulas, and thresholded at adjusted reliability greater than 0.4 (except Extended Data Fig. 7 which reproduced main results with no threshold). - Stored behavioral and neural trials span `[-3, 2]` s relative to reward. Reward is at `t = 0`, and the end of the reach/run is represented at approximately `t = -1` s. - The principal paired neural analyses generally crop the stored data to `[-2, 2]` s. The movement-stereotypy calculations use task-specific pre-reward windows: `[-2, -1]` s for Reach and `[-3, -1]` s for VR. - Reward omission trials comprised approximately 20% of trials and were randomly interleaved. ## MATLAB structure conventions Call one paired-session structure `curd`: ```matlab curd = crossTask(i); % or curd = sameTask(i); ``` Each `curd` contains two sessions from one mouse. Unless noted otherwise, elements of a `1 x 2` field follow the same ordering as: ```matlab curd.dates curd.task curd.trials curd.rawsigs ``` For `crossTask`, the public script assumes session order `[Reach, VR]`. For `sameTask`, the two sessions are addressed as `[Day1, Day2]`; the task itself is either Reach on both days or VR on both days. Dimension symbols used below are: - `Ntrial`: number of retained trials in one session. - `NGrC`: number of GrCs retained for the paired-session analysis. - `NL5PT`: number of L5PTs retained for the paired-session analysis. - `Nt_beh = 5001`: samples in the `[-3, 2]` s behavioral window, approximately 1 kHz. - `Nt_neural = 151`: samples in the `[-3, 2]` s neural window, approximately 30 Hz. - `Nt_raw`: samples in a session's continuous imaging tr
Publication details
- Journal / source
- Zenodo (CERN European Organization for Nuclear Research)
- Publication date
- 29 July 2026