Skip to main content
Dryad logo

Dorsal Periaqueductal gray ensembles represent approach and avoidance states


Reis, Fernando et al. (2021), Dorsal Periaqueductal gray ensembles represent approach and avoidance states, Dryad, Dataset,


Animals must balance needs to approach threats for risk-assessment and to avoid danger. The dorsal periaqueductal gray (dPAG) controls defensive behaviors, but it is unknown how it represents states associated with threat approach and avoidance. We identified a dPAG threat-avoidance ensemble in mice (Mus musculus) that showed higher activity far from threats such as the open arms of the elevated plus maze and a live predator. These cells were also more active during threat-avoidance behaviors such as escape and freezing, even though these behaviors have antagonistic motor output. Conversely, the threat-approach ensemble was more active during risk-assessment behaviors and near threats. Furthermore, unsupervised methods showed approach/avoidance states were encoded with shared activity patterns across threats. Lastly, the relative number of cells in each ensemble predicted threat-avoidance across mice. Thus, dPAG ensembles dynamically encode threat approach and avoidance states, providing a flexible mechanism to balance risk-assessment and danger avoidance.


Mice. Mice (Mus musculus) of the C57BL/6J strain (Jackson Laboratory stock No. 000664) were used for all experiments. Male mice between 2 and 5 months of age were used in all experiments. Mice were maintained on a 12-hour reverse light-dark cycle with food and water ad libitum. Sample sizes were chosen based on previous behavioral studies with miniaturized microscope recordings on defensive behaviors, which typically use 6-10 mice per group. All mice were handled for a minimum of 5 days prior to any behavioral task. In this work, analyses of the EPM environment used 8 mice, while any analyses involving rat exposure used 7 mice. All procedures conformed to guidelines established by the National Institutes of Health and have been approved by the University of California, Los Angeles Institutional Animal Care and Use Committee.

Rats. Male Long-Evans rats (250-400 grams) were obtained from Charles River and were individually housed on a standard 12-hour light-dark cycle and given food and water ad libitum. Rats were only used as a predatory stimulus. Rats were handled for several weeks prior to being used and were screened for low aggression to avoid attacks on mice. No attacks on mice were observed in this experiment.

Surgeries. Eight-week-old mice were anaesthetized with 1.5-3.0% isoflurane and placed in a stereotaxic apparatus (Kopf Instruments). AAV9.Syn.GCaMP6s.WPRE.SV40 were packaged and supplied by UPenn Vector Core at titers 7.5 x 103 viral particles per ml and viral aliquots were diluted prior to use with artificial cortex buffer to a final titer of 5 x 1012 viral particles per ml. After performing a craniotomy, 100nl of virus was injected into the dPAG (coordinates in mm, from skull surface): -4.20 anteromedial, -0.85 lateral, -2.3 depth, 15-degree angle. Five days after virus injection, the animals underwent a second surgery in which two skull screws were inserted and a microendoscope was implanted above the injection site. A 0.5 mm diameter, ~4 mm long gradient refractive index (GRIN) lens (Inscopix, Palo Alto, CA) was implanted above the dPAG (-2.0 mm ventral to the skull surface) (Resendez et al., 2016). The lens was fixed to the skull with cyanoacrylate glue and adhesive cement (Metabond; Parkell). The exposed end of the GRIN lens was protected with transparent Kwik-seal glue and animals were returned to a clean cage. Two weeks later, a small aluminum base plate was cemented onto the animal’s head on top of the previously formed dental cement. Animals were provided with analgesic and anti-inflammatory (carprofen). 

Behavioral timeline. Behavioral tests were combined in the following manner across days: EPM test, habituation 1, habituation 2, rat exposure. Three days after, the fear conditioning test was conducted in the following manner: habituation 1, habituation 2, fear conditioning and retrieval.

Elevated Plus Maze (EPM) test. Mice were placed in the center of the EPM facing one of the closed arms and were allowed to freely explore the environment for 20 minutes. The length of each arm was 30 cm, the width was 7 cm and the height of the closed arm walls was 20 cm. The maze was 65 cm elevated from the floor by a camera stand. A total of 8 mice were analyzed.

Rat Exposure Assay. Mice were habituated to a white rectangular box (70 cm length, 26 cm width, 44 cm height) for two consecutive days during 20-minute sessions. Mice were then exposed to an adult rat in this environment on the following day. The rat was secured by a harness tied to one of the walls and could freely ambulate only within a short perimeter. The mouse was placed near the wall opposite to the rat and freely explored the context for 20 minutes. No separating barrier was placed between the mouse and the rat, allowing for close naturalistic encounters that can induce a variety of robust defensive behaviors. A total of 7 mice were analyzed.

Behavior and miniscope video capture. All videos were recorded at 30 frames/sec using a Logitech HD C310 webcam and custom-built head-mounted UCLA miniscope (Aharoni and Hoogland, 2019). Open-source UCLA Miniscope software and hardware ( were used to capture and synchronize neural and behavioral video (Cai et al., 2016, Schuette et. al, 2020).

Perfusion and histological verification. Mice were anesthetized with Fatal-Plus and transcardially perfused with phosphate buffered saline followed by a solution of 4% paraformaldehyde. Extracted brains were stored for 12 hours at 4°C in 4% paraformaldehyde. Brains were then placed in sucrose solution for a minimum of 24 hours. Brains were sectioned in the coronal plane in a cryostat, washed in phosphate buffered saline and mounted on glass slides using PVA-DABCO. Images were acquired using a Keyence BZ-X fluorescence microscope with a 10 or 20X air objective.

Data Analysis was performed using custom-written code in MATLAB and Python.

Miniscope postprocessing and co-registration. Miniscope videos were motion-corrected using the open-source UCLA miniscope analysis package ( (Aharoni and Hoogland, 2019). They were spatially downsampled by a factor of two and temporally downsampled by a factor of four, and the cell footprints and activity were extracted using the open-source package Constrained Nonnegative Matrix Factorization for microEndoscopic data (CNMF-E; (Zhou et al., 2018). Neurons were co-registered across sessions using the open-source probabilistic modeling package CellReg ( (Sheintuch et al., 2017).

Artifact suppression. For suppression of long timescale artifacts, e.g. long-time scale fluctuations in calcium fluorescence shared across many neurons due to bleaching or other factors, we used PCA to identify large variance PCs (≥ 5% total variance) reflecting these artifacts. Cell activity was then reconstructed using these PCs excluded from reconstruction (O'Shea and Shenoy, 2018). This method was applied only to data for mouse 1 in the rat exposure assay.

Variance thresholding. A minority of recorded cells had very small variance over the course of an experimental session. To exclude these cells from analysis, we identified a representative cell for each trial. Cells with less than 10% of the representative cell’s variance were discarded. The remaining cells were used for further analysis.

Behavior detection. To extract the pose of freely-behaving mice in the described assays, we implemented DeepLabCut (Mathis et al., 2018), an open-source convolutional neural network-based toolbox, to identify mouse nose, ear and tail base xy-coordinates in each recorded video frame. These coordinates were then used to calculate velocity and position at each time point, as well as classify defensive behaviors in an automated manner using custom Matlab scripts. Freezing was defined as epochs of cessation of all movement except for breathing. Approach and escape were defined as epochs when the mouse moved, respectively towards or away from the rat at a velocity exceeding a minimum threshold.

Usage Notes

Each numbered folder corresponds to a mouse.  Within each folder:

'neural_data.mat' is a struct containing 'C_raw', the raw CNMF-E output neural data.


'BehaviorMS.mat' contains a series of vectors or matrices.  Pertinent to this study are:

Rat sessions-
-approachFrameMS and approachIndicesMS
-stretchFrameMS and stretchIndicesMS
-escapeFrameMS and escapeIndicesMS
-freezeFrameMS and freezeIndicesMS

EPM sessions-
-openArmFrameMS and openArmIndicesMS
-closedArmFrameMS and closedArmIndicesMS
Additionally, the separate file 'headDip.mat' gives the headDipFrameMS and headDipIndicesMS for all 
head dips over the edge of the open arms of the EPM.

All '*FrameMS' files give in/out points, aligned to the neural data, for each behavior. 'In' is
column 1 and 'Out' is column 2. All '*IndicesMS' files give logical '0' or '1' values for whether a 
behavior is happening during a frame of neural data.


'Tracking.mat' is a struct containing the pertinent fields:
FOR EPM, RAT, and TOY RAT, for each frame of neural data:
'mouse_positionMS', which provides the xy coordinates of the point between the mouse ears.
'mouseAngleMS' provides the angle in radians of mouse head direction.
'mouseVelMS' provides the frame-by-frame velocity of the mouse, in pixels per frame.

FOR RAT and TOY RAT only, for each frame of neural data:
'rat_positionMS' provides the xy coordinates of the point between the rat ears.
'angleDiffMouseHeadDirRatMS' provides the difference in radians between the head direction of the mouse
and the rat position.
'ratVelMS' provides the frame-by-frame velocity of the rat, in pixels per frame.
'distanceMouseRatMS' or 'distanceMouseToyRatMS' provides the distance in pixels between the mouse and rat.


National Institute for Mental Health, Award: R00 MH106649

National Institute for Mental Health, Award: R01 MH119089

Brain and Behavior Research Foundation, Award: 22663

Brain and Behavior Research Foundation, Award: 27654

National Science Foundation, Award: NSF-GRFP DGE-1650604

University of California, Los Angeles, Award: Affiliates fellowship

Hellman Foundation

Fundação de Amparo à Pesquisa do Estado de São Paulo, Award: #2014/05432-9

Fundação de Amparo à Pesquisa do Estado de São Paulo, Award: #2015/23092-3

Fundação de Amparo à Pesquisa do Estado de São Paulo, Award: #2017/08668-1