Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2022 May 9:16:779106.
doi: 10.3389/fnins.2022.779106. eCollection 2022.

PyRAT: An Open-Source Python Library for Animal Behavior Analysis

Affiliations

PyRAT: An Open-Source Python Library for Animal Behavior Analysis

Tulio Fernandes De Almeida et al. Front Neurosci. .

Abstract

Here we developed an open-source Python-based library called Python rodent Analysis and Tracking (PyRAT). Our library analyzes tracking data to classify distinct behaviors, estimate traveled distance, speed and area occupancy. To classify and cluster behaviors, we used two unsupervised algorithms: hierarchical agglomerative clustering and t-distributed stochastic neighbor embedding (t-SNE). Finally, we built algorithms that associate the detected behaviors with synchronized neural data and facilitate the visualization of this association in the pixel space. PyRAT is fully available on GitHub: https://github.com/pyratlib/pyrat.

Keywords: animal tracking; behavioral analysis; deep learning; electrophysiology; neuroscience method; unsupervised learning.

PubMed Disclaimer

Conflict of interest statement

The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.

Figures

Figure 1
Figure 1
(A) Representative image showing the marks of body parts used to train the network and the rat skeleton generated based on these marks. (B) Representative trajectory plots of a rat during the exploration sessions of an open field arena carried out on 3 consecutive days. Color variation indicates the moment in time at the rat's location. (C) Heatmaps of average trajectories during each exploration session. (D) Average distance traveled during each exploration session. (E) Average distance traveled during each exploration session is shown in blocks of 5 min per day. Data are expressed as mean ± SD.
Figure 2
Figure 2
(A) Image showing the trajectory of one rat for 120 s based on the snout coordinates. (B) Image showing rat body orientation during the entire object exploration session. (C) Average heatmap during the entire object exploration session. (D) Top: Object interaction across the entire object exploration session; Bottom left: Bar plot showing interaction time with objects A and A'; Bottom right: Bar plot showing the number of interactions with object A and A'. Data are expressed as mean ± SD.
Figure 3
Figure 3
(A) Bidimensional projection representing each cluster found by the unsupervised algorithm of behavior classification. (B) Histogram showing the number of frames in each cluster. (C) Top left: Dendrogram presenting the proximity of the clusters. Clusters with similar behaviors were grouped after visual inspection. We identified five behavioral clusters: immobility, sniffing, locomotion, rearing, and nesting/sleeping. The other images are representative frames showing some of the behavioral clusters identified.
Figure 4
Figure 4
(A) Overview of SignalSubset function. Left column: The SignalSubset function receives as input neural data (e.g., raw LFP) and the clustermap produced by ClassifyBehavior. Right column: SignalSubset function returns a list of extracted neural data corresponding to time windows of a determined behavior (e.g., Cluster 11). We also show a representative spectrogram of extracted data. (B) Overview of SpatialNeuralActivity function. Left column: The SpatialNeuralActivity function receives as input the neural data (e.g., single unit spike rasterplot) to be shown in pixel space, and the tracking as spatial data. Right column: The SpatialNeuralActivity function returns the quantification of neural activity (spike firing) in each part of the pixel space.

References

    1. Aonuma H., Mezheritskiy M., Boldyshev B., Totani Y., Vorontsov D., Zakharov I., et al. . (2020). The role of serotonin in the influence of intense locomotion on the behavior under uncertainty in the mollusk lymnaea stagnalis. Front. Physiol. 11, 221. 10.3389/fphys.2020.00221 - DOI - PMC - PubMed
    1. Dunn T. W., Marshall J. D., Severson K. S., Aldarondo D. E., Hildebrand D. G., Chettih S. N., et al. . (2021). Geometric deep learning enables 3d kinematic profiling across species and environments. Nat. Methods 18, 564–573. 10.1038/s41592-021-01106-6 - DOI - PMC - PubMed
    1. Fujisawa S., Amarasingham A., Harrison M. T., Buzsáki G. (2008). Behavior-dependent short-term assembly dynamics in the medial prefrontal cortex. Nat. Neurosci. 11, 823–833. 10.1038/nn.2134 - DOI - PMC - PubMed
    1. Fujisawa S., Amarasingham A., Harrison M. T., Buzsáki G. (2015). Simultaneous electrophysiological recordings of ensembles of isolated neurons in rat medial prefrontal cortex and intermediate ca1 area of the hippocampus during a working memory task. Dataset 1, 1–6. 10.6080/K01V5BWK - DOI
    1. Geuther B. Q., Deats S. P., Fox K. J., Murray S. A., Braun R. E., White J. K., et al. . (2019). Robust mouse tracking in complex environments using neural networks. Commun. Biol. 2, 1–11. 10.1038/s42003-019-0362-1 - DOI - PMC - PubMed