Jun 12, 2025

Public workspacePerforming surgeries, Image processing and Analysis on Animals

  • Di Lu1,
  • mj Sheng1
  • 1Stanford University
Icon indicating open access to content
QR code linking to this content
Protocol CitationDi Lu, mj Sheng 2025. Performing surgeries, Image processing and Analysis on Animals. protocols.io https://dx.doi.org/10.17504/protocols.io.yxmvmeyk5g3p/v1
License: This is an open access protocol distributed under the terms of the Creative Commons Attribution License,  which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited
Protocol status: Working
We use this protocol and it's working
Created: June 10, 2024
Last Modified: June 12, 2025
Protocol Integer ID: 102036
Keywords: ASAPCRN, experimental procedures on animal, performing surgery, analysis on animal, experimental procedure, procedure, photon imaging, image processing, surgery, processing, pca, animal, movement behavior analysis, protocol detail, analysis
Funders Acknowledgements:
Aligning Science Against Parkinson’s (ASAP)
Abstract
This protocol details the experimental procedures on animals that includes the surgery, two-photon imaging, cued lever-pushing task and analysis includes movement behavior analysis, and PCA.
Guidelines
Animals:

All experimental procedures were conducted following the protocols approved by the Stanford University Animal Care and Use Committee, in accordance with the National Institutes of Health’s Guide for the Care and Use of Laboratory Animals. All animals were maintained on a normal 12 h:12 h light/dark cycle. WT mice (C57BL/6J, > 7 weeks) of both males and females from The Jackson Laboratory were used in the Present study.

Materials
  • AAV1-CAG-FLEX-GCaMP6s (Catalog # 100842-AAV1, 1:1)
  • AAV5- hSyn-Cre (Catalog # 105553-AAV5)
  • AAV5-CAG-FLEX-EGFP (Catalog # 51502-AAV5, 1:1)
  • Two-photon microscope(Bergamo II, Thorlabs)


Troubleshooting
Surgical Procedure
10m
We performed surgeries on animals under isoflurane anesthesia (1.5% in 0.5 L/min of O2). To drive the expression of GCaMP6s in the motor cortex, we stereotaxically injected a mixture of AAV1-CAG-FLEX-GCaMP6s (Catalog # 100842-AAV1, 1:1) and AAV5- hSyn-Cre (Catalog # 105553-AAV5, 1:200 diluted in saline) into the caudal forelimb area of the motor cortex (from Bregma, anteroposterior (AP): 0.3 mm, mediolateral (ML): 1.5 mm; and from dura, dorsoventral (DV): -0.7 mm) .

Similarly, for structural imaging, we injected a mixture of AAV5-CAG-FLEX-EGFP (Catalog # 51502-AAV5, 1:1) and AAV5- hSyn-Cre (Catalog # 105553-AAV5, 1:1,000 diluted in saline).

A total volume of Amount100 µL - Amount300 µL was injected over Duration00:10:00 , using a micro pump (WPI). To prevent viral backflow, the pipette was left in situ within the brain for 15 minutes post-injection before withdrawal.
10m
Pipetting
Upon completion of the procedure, the incision site was sutured, and the mice were returned to their home cage once they recovered from anesthesia.

For the implantation of the chronic imaging window, 3-30 days after virus injection, we anesthetized the mice with isoflurane (1.5% in 0.5 L/min of O2). Following scalp removal, a titanium head plate was affixed firmly to the skull using super glue and dental cement (Lang Dental).
A circular craniotomy with a diameter of approximately 2.4 mm was performed above the dorsal lateral striatum, centered at the coordinates (AP: 0.3 mm, ML: 4.0 mm).
We aspirated the cortical tissue above the striatum using a 27-gauge needle at a 30-degree angle towards the surface of the corpus callosum [6,56]. Subsequently, a cannula was inserted above DLS.
The cannula consisted of a stainless- steel tube (~2.4 mm diameter, ~1.6 mm length) and a 2.4 mm round coverslip attached to one end of the tube using adhesive (Norland optical adhesive) [1,2].
We then used Kwik-Sil and dental cement to fix the cannula and cover the exposed skull. Mice were returned to their home cage after they recovered from anesthesia.
Two-photon imaging
In vivo imaging experiments were conducted using a commercial two-photon microscope(Bergamo II, Thorlabs), operated with ThorImage software. We used a 16× / 0.8 NA objective (NIKON), covering a field of view (FOV) size ranged from 120 × 120 to 200 ×200 µm (1024 × 1024 pixels) [1].
A mode-locked tunable ultrafast laser provided 925 nm excitation for two-photon imaging (Insight X3 Spectra-physics).

For calcium imaging, we imaged awake mice when they were performing the lever-pushing task.
Imaging data were synchronized and recorded with a PCIe-6321 card (National Instrument) to capture image frame-out timing and behavioral events, encompassing cue responses, rewards, punishments, licking behavior, and lever displacement.
Time-lapse movies were acquired at an approximate frame rate of ~15 Hz. 1 to 3 days were imaged for the early stage, 1-6 days were imaged for the late stage.
For imaging the same population of axons and boutons, same FOVs were imaged between early and late stage. The first 3 days were defined as the early stage, late stage was the days when mice learned the task (>=8 days).

  • For example, one mouse was imaged on days 1-3 and days 9-11, then days 1-3 were defined as early stage, and days 9-11 were defined as the late stage.
13 mice were used in functional calcium imaging, including 8 mice imaged the same axons and boutons at the early and late stage, another 5 mice imaged different FOVs at the early and late stage of learning.
For structural imaging, mice were anesthetized with 1% - 1.5% isoflurane and a heating pad was used to keep normothermia.
Image stacks were acquired via real-time averaging of 20 frames, with a z-step of 1 μm to ensure precise axial resolution.
2-4 regions of interest (ROIs) were imaged per mouse, and these ROIs were repeatedly imaged every other day.
8 mice were used in structural imaging for the training group, and 9 mice were used for the control group.
Cued lever-pushing task
The cued lever-pushing task was conducted as previously described [1].
Briefly, mice were subjected to water restriction at Amount1 mL per day for three days.
The lever-pushing task training started 3 days after water restriction and habituation. During habituation, mice were head fixed and received water from the water tube.
After starting the training, mice remained water restricted but received water during the training.
Lever displacement was continuously monitored using a potentiometer, converting it into voltage signals, and recorded through a PCIe-6321 card (National Instrument).
A custom LabVIEW program governed the training paradigm, precisely controlling cue presentation, reward delivery, punishment, and the determination of lever-pushing threshold crossing.
Each trial was initiated with a 500 ms, 6-kHz pure tone as the cue.
Mice received a water reward (approximately 8 μl) when they pushed the level surpassed the designated threshold (0.5 mm during the initial training on day 1, later increased to 1.5 mm for subsequent sessions) within the allocated task period.
Failure to meet the threshold or absence of lever pushing during the task period resulted in the presentation of white noise.
The inter-trial interval (ITI) was either fixed at 4 seconds or randomly varied between 3 and 6 seconds.
Lever pushing during the ITI incurred an additional time-out equivalent to the ITI duration for that specific trial.
The task period was 30 seconds during the first session and then reduced to 10 seconds for subsequent sessions.
A total of 27 mice were trained, mice learned the task within 3 weeks, including 13 mice for calcium imaging and, 8 mice for structural imaging, and 6 mice used for behavior training.
Movement behavior analysis
To identify movement bouts, we first determined a threshold to separate the resting and movement period.
Movement bouts separated by less than 500 ms were considered continuous and were combined together [5,6].
The start time was identified as the point where the lever position crossed a threshold that exceeded the resting period, while the end time was determined by detecting the moment when the lever position fell below the threshold [1,3].
To ensure the integrity of the baseline before each movement, we adopted a specific criterion. If there were any other movements occurring within a 3- second window before a particular movement, the latter was excluded from further analysis.
This exclusion step was implemented to guarantee the cleanliness and reliability of the baseline period, thus enhancing the accuracy of subsequent analyses.
RM was defined as lever pushes that exceeded the threshold during the task period, while UM was those lever pushes that failed to exceed the threshold during the task period, or ever pushes during ITI.
Activity pattern correlation and its relationship to movement trajectory correlation
Activity pattern correlation and movement trajectory correlation were calculated for each trial pair using MATLAB function ‘corrcoef’.
For all trial pairs in one day, we used bins - 0.2 to 0, 0 to 0.2, 0.2 to 0.4, 0.4 to 0.6, 0.6 to 0.8 and 0.8 to 1 to average all data points based on movement trajectory correlations. Then the activity pattern correlation was plotted against the movement trajectory correlation for each mouse.
Fraction of activated ensemble difference and its relationship to movement trajectory correlation
Percentage of activated ensemble difference was calculated based on each pair of trials, if a is the number of activated bouton ensemble in trial 1, while b is the number of activated bouton ensemble in trial 2, then the fraction of activated ensemble difference for this trial pair is defined as

in which the |a-b| was the number of activated ensemble difference, and 0.5 × (a + b) was the average number of activated ensemble for the trial pair.
Then we calculated correlation of the movement trajectory for each trial pair using MATLAB function ‘corrcoef’.
For all trial pairs in one day, we used bins -0.2 to 0, 0 to 0.2, 0.2 to 0.4, 0.4 to 0.6, 0.6 to 0.8and 0.8 to 1 to average all data points based on movement trajectory correlations. Then the percentage of activated ensemble difference was plotted against the movement trajectory correlation for each mouse.
Image processing and analysis
For Ca2+ image analysis, lateral motion artifacts were corrected using the ImageJ plugin (Turboreg) [4] or the efficient subpixel image registration algorithm [5].
Axons and boutons in FOV were manually drawn using adobe photoshop session-by- session. For the same FOV imaged both in early and late stages, only boutons with clear bouton morphology that could be identified in all sessions by visual inspection were selected and further analyzed.
To extract the calcium signals for each axon or bouton, we averaged the fluorescence intensity of all labeled pixels to obtain the raw fluorescence trace.
To calculate F0, we utilized a 30-second sliding window, where the 30th percentile of raw fluorescence within the window was designated as F0. ΔF/F was computed as (F-F0) / F0 for each individual axon and bouton [6].
For structural imaging, individual boutons were identified as swellings along thinner axon shafts, and were manually identified, marked, and tracked across multiple imaging sessions using the custom written script (MATLAB).
Only high-quality images displaying sparsely labeled axons, with distinct axon and bouton structures, were selected for subsequent quantification.
Analysis of bouton dynamics, including formation and elimination, was performed by comparing boutons between two adjacent imaging sessions.
Boutons were classified as "persistent" if they were present in both images, determined through their positions relative to nearby boutons within the same axon. An eliminated bouton was the one that appeared in the initial image but not the second image.
A newly formed bouton was the one that was absent in the initial image and then appeared in the second image.
The bouton survival rate was calculated as the percentage of boutons formed during day 4 of training that remained present in subsequent training sessions (days 6,8,10).
Identification and classification of RM and UM axon and bouton
The activities of individual axons or boutons in both rewarded movement (RM) trials and unrewarded movement (UM) trials were aligned to the movement onset, spanning a time window from 1 second before movement initiation (served as the baseline) to 3 seconds after the movement onset.
Subsequently, we calculated the average activity across all trials within this aligned time window.
To identify responsive boutons, we examined the peak value of each bouton within the time window (-0.2 to 3 seconds relative to the movement onset).
Boutons were considered responsive if the difference between the peak fluorescence value and the 5th percentile of the averaged activity exceeded 90% of the standard deviation (sd).
For the identification of responsive axons, we plotted histograms of all peak values in RM and UM trials for each mouse.
Utilizing a bin size of 0.1 sd, the peak bin values were determined for both RM and UM distributions, and the threshold was established as the mean of the corresponding peak positions in RM and UM.
If the calculated threshold, based on the histogram distribution, exceeded 1 sd, the final threshold was set at 1 sd.
Responsive axons were identified if the difference surpassed the threshold by comparing each axo 's peak value to the 5th percentile of the averaged activity.
Subsequently, axons or boutons were categorized based on their responsiveness in RM and UM trials.
Those identified as responsive exclusively in RM trials were classified as RM-only axons or boutons, while those responsive only in UM trials were categorized as UM-only axons or boutons.
Axons or boutons showing responsiveness in both RM and UM trials were designated as RM-UM-both axons and boutons.
To simplify, we combined the RM-only and RM-UM-both categories, grouping them as RM, RM-responsive or RM-related axons and boutons.
Ca2+ event detection and identification of same or unique peaks
To detect Ca2+ events, we employed the Matlab findpeaks function with the following criterion:
z-scored ΔF/F0 exceeding 1 standard deviation [7].
To compare events between pairs of boutons, we considered any events occurring within 670 ms of each other as 'matched' and defined them as the same peak [8], while those peaks that cannot find matched peaks were defined as unique peaks.

  • If the same peaks or unique peaks occurred during a time window 330 ms before and 670 ms after the onset of RM or UM, those peaks were classified as RM or UM-related same or unique peaks, respectively.
To calculate the same peak fraction, we divided the number of same peaks with total peaks based on each bouton pair, and averaged the results over all boutons within one axon, then averaged over all axons in one mouse.
Principal component analysis (PCA)
We used PCA to project each trial into a lower-dimensional space to discern the low- dimensional embedding of individual boutons during rewarded movement (RM) and unrewarded movement (UM) trials.
Initially, the activity of each bouton was averaged across all RM or UM trials, and the averaged activities were then concatenated for each bouton.
We recorded the results in a data matrix where each column represented the concatenated trial-averaged RM and UM activity of one bouton.
The size of the matrix was 2M-by-N, with M denoting the number of time points per RM or UM trial (ranging from –1 to 3 seconds relative to movement onset), and N representing the number of boutons.
Subsequently, PCA was conducted across the time points of concatenated RM and UM trials, capturing the first three principal components to represent the RM and UM trials in a visually informative 3-dimensional principal component (PC) space.
Each bouton was depicted as a distinct dot within this space, facilitating clear visualization and discrimination of the bouton responses during both RM and UM trials.
PCA trajectory and calculation of selectivity index
PCA was conducted on each continuous imaged segment (4000 frames by n boutons, frame rate: 15 Hz), utilizing the first three principal components to represent the ensemble activity of boutons. Then we aligned the first three principal components from 1s before to 3 s after each RM and UM onset to generate single RM or UM neural trajectories in the PCA space.
We used activity trajectory selectivity index to measure the selectivity of bouton activity towards RM or UM, a method modified from a previously published paper [20].
The activity trajectory selectivity index for an RM trial was defined as (dto mean UM trajectory – dto mean RM trajectory) / (dto mean RM trajectory + dto mean UM trajectory), where dto mean UM trajectory (dto mean RM trajectory) is the Euclidean distance between the single RM trial trajectory and the mean UM (RM) trajectory, which was computed frame-by-frame.
The mean RM and UM trajectories were the averages of all RM and UM trajectories respectively.

  • For example, the first three PCs of the first frame of a RM trial is (a, b, c), while the first three PCs of the first frame of the mean UM trial is (x, y, z), then the dto mean UM trajectory is


Similarly, Activity trajectory selectivity index for a UM trial was defined based on distances as (dto mean RM trajectory – dto mean UM trajectory) / (dto mean RM trajectory + dto mean UM trajectory).
The trajectory selectivity index essentially measures how closely individual trajectories match the mean trajectories of their respective trial type versus the opposite type.

  • For example, for an RM trial, an index score of 1 means the single trial trajectory was at the same point in PCA space as the mean RM trajectory, and an index score of -1 means the single trial trajectory was at the same point in state space as the mean UM trajectory.
Statistics
Significance testing was performed using the Wilcoxon rank sum test, Pearson correlation coefficient, one-way ANOVA, two-way ANOVA and Kolmogorov–Smirnov test using Matlab.
Two-sided statistical tests were conducted, and data is presented as mean ± SEM (standard error of the mean), with all statistical tests, statistical significance values, and sample sizes described in the figure legends. Statistical thresholds used: * p < 0.05, ** p < 0.01, *** p < 0.001, NS: not significant. All source data are included in the source data table.
Protocol references
1. Sheng, M. J., Lu, D., Shen, Z. M., & Poo, M. M. (2019). Emergence of stable striatal D1R and D2R neuronal ensembles with distinct firing sequence during motor learning. Proceedings of the National Academy of Sciences, 116(22), 11038-11047.
2. Dombeck, Daniel A., et al. "Functional imaging of hippocampal place cells at cellular resolution during virtual navigation." Nature neuroscience 13.11 (2010): 1433-1440.
3. Peters, A. J., Chen, S. X., & Komiyama, T. (2014). Emergence of reproducible spatiotemporal activity during motor learning. Nature, 510(7504), 263-267.
4. Thevenaz, Philippe, Urs E. Ruttimann, and Michael Unser. "A pyramid approach to subpixel registration based on intensity." IEEE transactions on image processing 7.1 (1998): 27-41.
5. Guizar-Sicairos, Manuel, Samuel T. Thurman, and James R. Fienup. "Efficient subpixel image registration algorithms." Optics letters 33.2 (2008): 156-158.
6. Peron, Simon P., et al. "A cellular resolution map of barrel cortex activity during tactile behavior." Neuron 86.3 (2015): 783-799.
7. d’Aquin, Simon, et al. "Compartmentalized dendritic plasticity during associative learning." Science 376.6590 (2022): eabf7052.
8. Wagner, Mark J., et al. "Shared cortex-cerebellum dynamics in the execution and learning of a motor task." Cell 177.3 (2019): 6