Analysis scripts for rat behavioural experiments. These scripts were applied following body part tracking in DeepLabCut and behavioural classification in SimBA.
The scripts in this repository were run on R (version 4.3.3) through RStudio (Posit Software PBC, 2026), with the following packages:
| Package | Version tested | Citation |
|---|---|---|
| here | 1.0.1 | Müller K (2020) |
| tidyverse | 2.0.0 | Wickham et al. (2019) |
| ggpattern | 1.1.4 | Mike FC & Davis (2025) |
| ggpubr | 0.6.1 | Kassambara (2025) |
| ggnewscale | 0.5.2 | Campitelli (2025) |
To install the latest version of all packages, run install.packages(c('here', 'tidyverse', 'ggpattern', 'ggpubr', 'ggnewscale'))
Body part tracking in DeepLabCut
To track rat body parts in open field, novel object recognition (NOR), object location task (OLT), Barnes maze and fear conditioning experiments, DeepLabCut (version 3.0.0rc9) was run using the UNSW Katana computational cluster. The labelling scheme is shown in Figure 1. A ResNet-50-based neural network was trained, with 95% train-test split, a batch size of 8 and all other default parameters. This model was trained on 1525 labelled frames across 77 videos (25 frames per second). After 400 epochs, the test root mean square error (RMSE) was 10.9 mm for predictions with greater than 60% confidence.
Figure 1: Labelling scheme for DeepLabCut body part tracking.
Analysis in Simple Behavioral Analysis (SimBA) and R
Following body part tracking, the rats' movement and behaviours were analysed using Simple Behavioral Analysis (SimBA) (versions 4.1.6–5.1.1), with scaling factors determined in ImageJ. Any videos that ended significantly prematurely, commenced significantly late, or had other notable disruptions were excluded from the analysis. Test scores were determined in R (version 4.3.3) using the tidyverse package collection (version 2.0.0), prior to further statistical analysis and graphing in GraphPad Prism (versions 10.6.1–11.0.0). An explanation of each experiment's analysis is provided below.
For the open field test, the arena's centre zone was defined as its four inner squares, constituting a quarter of its area. After defining a region of interest (ROI) in SimBA (Figure 2), smoothing pose prediction (500 ms, Gaussian) and filtering for points with likelihood ≥ 0.6, the duration for which the rats' centres were within this boundary was determined. In R, this value was divided by the total duration of the experiment to calculate the percentage of time in the inner zone.
The path length was also calculated, defined as the total distance travelled by the 'centre' body part in metres, regardless of ROI. Data were analysed by two-way ANOVA (α = 0.05).
Figure 2: Open field test. On left, illustration of inner zone definition. On right, example path plot of centre point (taken from rat08 open field test), with gradient from purple to yellow illustrating position from start to end of the 10 min test.
To analyse NOR and OLT, ROIs were declared around the objects, feature subsets were calculated (listed here), and machine models were trained to classify object-directed interaction. Interaction was defined as the rat being within 2 cm of an object with its nose oriented toward it. Frames in which rats were resting on or rearing against the object were excluded from the positive class. A total of 21 videos were manually annotated for model training (315,000 frames total, with ~11,000 frames in the positive class for each behaviour), and 20% of frames were held out as a test set. A Random Forest classifier (2,000 estimators) was trained using SimBA’s default feature extraction pipeline. After classification, a minimum bout length of 250 ms was applied to reduce spurious detections. Automated predictions were verified by both comparison of numerical output to a manually scored subset of videos, and inspection of machine-labelled videos.
Exploration was calculated as the total time a rat spent interacting with either object, and any rats with less than 10 s of exploration were excluded from the analysis. Discrimination indices were calculated as follows:
Thus, in phase 2, positive values indicate greater proportion of time interacting with the novel object/location (See Figure 3), whereas negative values show more time spent with the familiar object/location. In phase 1, DI quantifies inherent bias towards objects placed on either the left (positive) or right (negative) side. GraphPad Prism was then used to conduct two-way ANOVAs (α = 0.05), assess normality, exclude outliers (ROUT method, Q = 1%), determine statistical significance (Šídák's multiple comparisons, α = 0.05), and graph the results.
Figure 3: Experimental set-up for NOR and OLT. Note, both the object types and the novel sides were counterbalanced to account for any intrinsic object or location preferences.
To analyse the Barnes maze, ROIs were drawn around each of its 18 holes in SimBA. The aggregate ROI data, detailed sequences, and path lengths were outputted for analysis. Desciptions of each of the seven measures used for Barnes Maze analysis are shown in Table 1. To reduce inaccuracies due to occasional body part tracking errors in DeepLabCut, each ROI-based measure was calculated separately with tracking for nose, left ear, and right ear (referred to below as 'head'). For search strategy, the maximum score was awarded, whereas for all other measures, the median of the three values was awarded. These approaches were validated on a subset of 32 videos, and were seen to achieve more accurate results than tracking the nose alone or averaging between body parts.
Table 1: Scoring schemes for the Barnes Maze. Note, 'head' refers to a summary of the nose point and both ear points. For further detail of how scores were generated, see here.
| Measure | Definition |
|---|---|
| Search strategy | Score out of 11, based on the sequence of holes the rat's head enters, concluding with its first entry into the EB ROI. Based on Rodríguez Peris et al. (2024), adapted for use with a 18-hole Barnes maze. A detailed description is shown in Figure 4. |
| Primary errors | Number of hole ROIs that the rat's head passed through before it first entered the EB ROI. |
| Primary latency | Time (in seconds) elapsed before the rat's head first entered the EB ROI. |
| Primary path length | Distance (in metres) travelled by the rat's centre point, before its head first entered the EB ROI. |
| Total errors | Number of hole ROIs that the rat's head passed through before the rat fully climbed into the EB. Excludes the EB ROI. |
| Total latency | Time (in seconds) elapsed before the rat fully climbed into the EB. |
| Total path length | Distance (in metres) travelled by the rat's centre point, before the rat fully climbed into the EB. |
Figure 4: Barnes maze search strategy scoring scheme. Pink arrow indicates the sequence of holes visited by a rat, with the corresponding scores shown in green circles. Serial searches are defined as searches with fewer than two holes skipped at a time that maintain a consistent direction, save for permission of searching one hole in the reverse direction if the rat then immediately returns to the original direction.
The results for the Barnes maze were determined in R, then imported to GraphPad Prism, analysed by three-way repeated measure ANOVA (α = 0.05, Geisser Greenhouse corrected) and visualised.
To analyse the contextual and cued fear conditioning (CFC) experiments, a new SimBA machine model was trained to classify freezing. This was defined as a rat exhibiting an absence of any movement except for breathing. Feature subsets were calculated (listed here). The model was trained on frames across 19 videos (85,000 total frames, with ~18,000 freezing frames), and 20% of frames were reserved as a test set. A random Forest classifer (2,000 estimators) was trained using SimBA's default feature extraction pipeline. For classification, the discrimination threshold was set to 0.5 and the minimum bout length was set to 600 ms. The quality of automated predictions was verified by inspection of machine-labelled videos.
The percentage of time spent freezing was calculated in each experiment for various time bins. For the conditioning and testing phases, freezing within 'event bins' were calculated (Figure 4), such as freezing prior to the first tone (2 min duration), within each tone (10 s duration), or within each intertrial interval (typically 2 min duration, but shorter for final intervals in both experiments). As no dedicated 'events' occur within the extinction phase, freezing was presented in 1 min time bins (although shorter time bin durations, as low as 10 s, were also inspected) where bins are named as the time they commenced, (e.g. 0 corresponds to freezing within the 0–1 min bin). In addition, percent time freezing within the 2–5 min window was calculated, as this corresponds to the time between the first tone and end of the conditioning experiment, where rats would be most likely to expect a shock.
After initial analysis, all outliers were thoroughly checked by inspection of their SimBA validation video. Of 25 videos with an outlier datapoint, 2 were partially rescored and 2 were fully rescored using RodentManualScorer (version 2.0.0). See here for the full list of outlier videos and explanation of why datapoints were manually corrected.
Figure 4: Fear conditioning experiment. On left, see an example of the body part tracking from DeepLabCut for fear conditioning footage. On right, see timing of 'events' in all phases of experiment to scale. Note, the values provided in blue are for when a tone commenced. Grey areas represent periods where no tone or shock is occurring. Times beside bars were when each experiment was terminated.