Main

Many animals, including birds1, mammals1,2,3,4 and insects5,6,7, navigate to specific locations in their environment, such as their home or a source of food. To do so, they often use an internal sense of heading, which can persist even without visual landmarks3,4,5,6. Neurons that keep track of heading or head-direction were first discovered in rodents8,9 and have more recently been found in other animals10,11,12,13, including Drosophila14. Whereas elegant computational models have been proposed to account for the firing properties of such neurons15,16,17,18,19,20, a biological circuit that computes an animal’s heading remains unknown in any species. Here we describe a neural shifting mechanism in the Drosophila central complex, akin to models proposed for rodent head direction cells15,16,17,18,19, which allows flies to integrate their turning velocity quantitatively in order to update an internal heading estimate over time.

Heading signals in the central complex

We focus on two cell types that make direct connections between the protocerebral bridge and the ellipsoid body in the fly central complex: E-PGs (ellipsoid body-protocerebral bridge-gall neurons, also PBG1–8.b-EBw.s-D/Vgall.b21 or EIP22; Fig. 1a, b) and P-ENs (protocerebral bridge-ellipsoid body-noduli neurons, also PBG2–9.s-EBt.b-NO1.b21, PEN22, or ‘shifting neurons’ in this paper; Fig. 1a, b). Each cell type tiles both the protocerebral bridge and the ellipsoid body. To assess the role of E-PGs and P-ENs in building an internal heading signal, we first measured calcium levels in each cell type separately using the genetically encoded calcium indicator GCaMP6m23 under two-photon excitation. We imaged P-ENs expressing Gal4 under two independent drivers (VT032906–Gal4, which we call P-EN1, and VT020739–Gal4, which we call P-EN2) because we observed differences in their physiology in later experiments (see below). In all figures, the fly brain is viewed from the posterior side, such that the left bridge is displayed on the left and the right bridge on the right (except Supplementary Videos; see Video Legends). In all experiments, the fly was tethered24 and walking on an air-cushioned ball25,26 at the centre of a cylindrical LED arena27 (Fig. 1c, see Methods). The fly viewed either a dark screen or a bright vertical bar that rotated in closed loop with the fly’s behaviour, simulating a fixed, distant landmark (Fig. 1c).

Figure 1: The activity of three cell types in the protocerebral bridge tracks the fly’s heading.
figure 1

a, Protocerebral bridge and ellipsoid body in the fly brain. b, Example E-PG and P-EN neurons. Each cell type tiles the bridge and ellipsoid body. c, Imaging neural activity in a fly walking on a ball with an LED arena. df, Z-projected bridge volumes of GCaMP6m over time for each cell type. Scale bars, 20 μm. gi, Left, bridge activity as the fly walks with a bar in closed-loop; right, phase of the bridge activity and bar position. The 90° gap in the back of the arena is highlighted in grey. jl, Correlations between phase position and ball position as well as phase velocity and ball velocity. Each circle represents one fly. The mean and s.d. across flies are shown. P-ENs are in orange and E-PGs in blue throughout.

PowerPoint slide

In both conditions, we observed two or three periodic peaks of activity in the bridge for each cell type (Fig. 1d–i and Extended Data Figs 1a–l, 2). In all cell types, these peaks moved in unison to the left or right along the bridge as the fly turned right or left, respectively. The position of these peaks in the bridge—which we will call the E-PG or P-EN ‘phase’—quantitatively tracks the virtual heading of the fly (Fig. 1g–l, Supplementary Videos 1–7). Given a bar in closed loop, the phase tracks the bar’s position with an offset that is typically constant for many minutes, but differs from fly to fly (Extended Data Fig. 1m–o). In the dark, however, the phase tracks the fly’s heading with an error that accumulates over time, consistent with a system that integrates self-motion inputs (Extended Data Fig. 2). These properties, measured for three cell types in the bridge, are very similar to those previously observed for rodent head-direction cells8,9,41,42 (Extended Data Fig. 3) and E-PGs in the ellipsoid body14.

A model for angular integration

Do P-ENs and E-PGs interact in a circuit to track the fly’s heading? Our first clue came from examining a previous anatomical study21 that characterized how each cell type projects between the bridge, a linear array of 18 glomeruli, and the ellipsoid body, a circular array of 8 tiles21 (Fig. 2a). In linking this anatomical work to our physiological observations, we noticed that left- and right-bridge P-ENs project clockwise and anticlockwise, respectively, to the ellipsoid body (Fig. 2a (orange arrows), Extended Data Fig. 4 and Supplementary Table 1). E-PGs, on the other hand, project without shifting from the ellipsoid body to the bridge (Fig. 2a, blue arrows). Although the full connectome for this circuit will surely reveal more complexity, this coarse level of description already suggests a path by which an activity peak could propagate clockwise or anticlockwise around this circuit when the fly turns. For example, assuming that there are reciprocally excitatory interactions between E-PGs and P-ENs, E-PG activity in tile 5 of the ellipsoid body would activate P-EN cells in glomerulus 5 in both the left and right bridge (Fig. 2a, using a modified numbering scheme for functional clarity; see Extended Data Fig. 4a–d). If, when the fly turns right, the right-bridge P-ENs become more active than their left-bridge counterparts (Fig. 2b), these right-bridge P-ENs would drive the E-PGs in tile 4 in the ellipsoid body, shifting the E-PG activity peak anticlockwise by one tile (Fig. 2c). The E-PG activity in tile 4 in the ellipsoid body would then reverberate back to activate P-ENs in glomeruli 4 of the left and right bridge, shifting P-ENs to the left in the bridge in unison with E-PGs (Fig. 2d). If the fly continued to turn right, the E-PG and P-EN activities would continue to propagate leftward in the bridge and anticlockwise in the ellipsoid body, with stronger turning driving larger asymmetries in P-EN activity and faster propagation of the E-PG peak. The opposite sequence of events would cause the E-PG peak to rotate clockwise in the ellipsoid body if the fly turned left. In this way, an asymmetry in the activity of the right versus left P-ENs could cause the E-PG signal to rotate in one direction or the other in response to the fly turning.

Figure 2: P-EN neurons in the left and right bridge are asymmetrically active when the fly turns, consistent with an anatomically inspired model for neural integration.
figure 2

ad, How an asymmetry in left and right P-EN neurons could rotate the E-PG phase (see text). eg, Bridge activity and accumulated phase in constant darkness for each cell type. Arrows highlight right–left asymmetries when the fly turns. hj, Right–left bridge activity (bottom) triggered on the onset of left or right turns (top). The mean and s.e.m. across turns are shown. km, Right–left bridge activity versus turning velocity. Thin lines represent single flies. Thick lines represent the mean across flies. hm, Averaged over bar and dark conditions.

PowerPoint slide

Turning velocity signals in P-ENs

Consistent with this model, in addition to the GCaMP peaks shifting along the bridge (Fig. 1), we observed an asymmetry in the amplitude of the left and right P-EN peaks, but not of the E-PG peaks, when the fly turned (Fig. 2e–g, white arrows). To quantify this asymmetry, we subtracted the GCaMP signal averaged across all glomeruli in the left bridge from that averaged across the right bridge, and computed the time course of this right–left GCaMP signal triggered on the start of left and right turns (Fig. 2h–j, see Methods). When the fly turned right, we observed a transient increase in activity on the right bridge relative to the left (hereafter referred to as the ‘bridge asymmetry’) for both P-EN lines, and vice versa when the fly turned left (Fig. 2h, i). We observed this asymmetry when the fly turned—both in the dark and with a closed-loop bar (Extended Data Fig. 5)—as well as when the fly was not turning, but was viewing panoramic visual motion (that is, optic flow) that it would normally experience during turning (Extended Data Fig. 6). These results indicate that both visual optic-flow inputs and non-visual inputs (such as proprioceptive or efference copy signals) that carry information about the fly’s angular velocity contribute to the bridge asymmetry. Moreover, we found a quantitative, positive relationship between right–left GCaMP and the fly’s turning velocity for both P-EN lines (Fig. 2k, l), but not for E-PGs (Fig. 2m). This bridge asymmetry between left and right P-ENs could provide the quantitative signal necessary for integrating the fly’s turns over time.

Spatiotemporal relationships across cells

A second prediction of the anatomical model in Fig. 2a–d is that E-PG and P-EN activity peaks should occupy similar positions in the bridge. We therefore imaged E-PGs simultaneously with either P-EN1s or P-EN2s, with E-PGs expressing GCaMP6f23 and P-ENs expressing jRGECO1a, a red-shifted calcium indicator28 (Fig. 3). In the bridge, the calcium peaks from both P-EN lines shifted in unison with those of E-PGs (Fig. 3a–d). However, the two P-EN lines differed greatly in that P-EN1 and E-PG peaks were in phase with each other (Fig. 3a, c), whereas the P-EN2 and E-PG peaks were nearly in antiphase (Fig. 3b, d). Anatomical experiments suggested that we imaged genuine P-ENs in both Gal4 lines (Extended Data Fig. 4g–l, Supplementary Information Table 1), but that our P-EN1 and P-EN2 Gal4 lines target different subsets of P-ENs (Extended Data Fig. 7). Owing to these physiological and anatomical differences, we operationally defined two P-EN subtypes: P-EN1 and P-EN2.

Figure 3: The P-EN1 activity peak leads, and the P-EN2 peak trails, a rotating E-PG peak in the ellipsoid body, as predicted by their activity in the bridge.
figure 3

a, b, Co-imaging of E-PGs (GCaMP6f) with P-EN1s (jRGECO1a) (a) or P-EN2s (jRGECO1a) (b) in the bridge in constant darkness. c, d, Phase-nulled signals in the bridge, averaged over time. e, f, Bridge data from c, d replotted onto the ellipsoid body using each cell type’s anatomical projection pattern21. g, h, Sum of the left- and right-bridge curves in e, f (scales adjusted). i, j, Co-imaging of E-PGs with P-EN1s or P-EN2s in the ellipsoid body. kp, Phase-nulled signals in the ellipsoid body averaged over time when the fly was walking straight (k, l), turning left (m, n) or turning right (o, p). Arrows indicate the velocity of the peaks. The P-EN ellipsoid body asymmetries were significantly different during turning and walking straight (P < 0.02), and during turning left and right (P < 0.01) (Wilcoxon rank-sum test). The mean and s.e.m. across flies are shown. ch, kp, Averaged over bar and dark conditions.

PowerPoint slide

What are the implications of these in-phase and nearly antiphase activity peaks in the bridge on the interactions between P-ENs and E-PGs? As P-ENs are likely to output (directly or indirectly) onto E-PGs in the ellipsoid body21,22 (Extended Data Fig. 4e, f), we replotted the mean GCaMP signal measured from each bridge glomerulus (Fig. 3c, d) over the appropriate tile in the ellipsoid body (Fig. 3e, f), using the anatomical mappings described above21 (Extended Data Fig. 4a–d). For E-PGs, the two peaks in the bridge map to a single peak in the ellipsoid body (Fig. 3e, f, blue curves), as expected14. However, the two P-EN peaks in the bridge map to either side of the single E-PG peak in the ellipsoid body (Fig. 3e, f, orange curves) because of their offset anatomy (Fig. 2a). Furthermore, the positions of these P-EN peaks are inverted across the two P-EN subtypes: the right bridge peak maps to the anticlockwise flank of the E-PG ellipsoid body-peak for P-EN1 (Fig. 3e, dashed orange curve) but to the clockwise flank for P-EN2 (Fig. 3f, dashed orange curve). The reverse is true for the left bridge peak in each cell type.

To evaluate whether these projected activity patterns match the actual patterns in the ellipsoid body, we performed dual imaging from E-PGs and either P-EN1s or P-EN2s in the ellipsoid body. With E-PGs, we observed a single, sharp peak in the ellipsoid body (Fig. 3i–l), as expected14. With P-ENs, we had the null expectation, based on summing the left and right bridge signals after projecting to the ellipsoid body, that we would observe a broad GCaMP peak for P-EN1 and a broad valley for P-EN2 at the position of the E-PG peak (Fig. 3g, h). Unexpectedly, however, P-ENs in both lines also showed a single, sharp peak in the ellipsoid body, which overlapped with the E-PG peak (Fig. 3i–l). These data suggest that the broad P-EN1 and P-EN2 calcium signals are reshaped by presynaptic modulation in the ellipsoid body, the mechanism for which should be investigated in future work. Despite this reshaping, we nevertheless observed an asymmetry in P-EN activity relative to the E-PG peak in the ellipsoid body (hereafter referred to as the ellipsoid body asymmetry) when the fly turned (Fig. 3m–p). Specifically, P-EN1 activity increased on the leading edge of the moving E-PG peak (Fig. 3m, o) and P-EN2 activity increased on the trailing edge (Fig. 3n, p), consistent with the sign of the bridge asymmetry during turns (Fig. 2h–i, k, l), the relative phase of P-EN1 and P-EN2 to E-PG activity in the bridge (Fig. 3c, d), and the known anatomical mappings of P-ENs and E-PGs between the bridge and ellipsoid body (Fig. 3e, f). Control experiments and analyses indicate that these results were not due to bleed-through between indicator channels, differences in indicator kinetics, or the specific lag times chosen (Extended Data Figs 8, 9).

Given that P-EN1 and P-EN2 have inverted spatial activity patterns, how are they coordinated in time? When the activity peaks moved in the bridge, the P-EN1 bridge asymmetry was evident early, before the onset of the movement of the peaks, whereas the P-EN2 bridge asymmetry came on late, after the peaks had begun to move, as measured by averaging these signals triggered on movements of the peaks (Fig. 4a–c). A cross-correlation analysis also showed this timing difference between P-EN1s and P-EN2s in the bridge (Fig. 4d) and the ellipsoid body (Extended Data Fig. 9c, d).

Figure 4: P-EN1 and P-EN2 bridge asymmetries respectively lead and lag phase shifts in time, and impairing P-ENs impairs E-PG phase updating in the dark.
figure 4

a, b, Bridge activity during phase shifts in constant darkness for P-EN1 (a) and P-EN2 (b). White arrows highlight right–left asymmetries. c, Right–left bridge activity (bottom) triggered on phase changes (top). The mean and s.e.m. across phase shifts are shown. d, Correlation between right–left bridge activity and phase velocity versus time lag between the two signals. Thin lines represent single flies. Thick lines represent the mean across flies. c, d, Traces are averaged over bar and dark conditions. e, f, E-PG activity in the bridge with P-EN1 cells expressing shibirets at 22 °C (e) or 32 °C (f). Arrows highlight atypical deviations in the E-PG phase from the ball’s heading at 32 °C. g, E-PG phase velocity versus ball velocity in a control fly and a P-EN1>shibirets fly (same as in e, f) in constant darkness. R, Pearson correlation coefficient. h, Phase velocity versus ball velocity correlations for three P-EN-Gal4 lines. Each circle represents one fly. The mean and s.e.m. across flies are shown. The cold-to-hot changes in correlation are significantly different between P-EN>shibirets and control groups (P < 0.01) (Wilcoxon rank-sum test). Note the different rotation scales in a, b and e, f.

PowerPoint slide

Blocking P-ENs impairs integration

If P-EN neurons serve an important role in moving the E-PG peak, then impeding P-EN synaptic output should impair the ability of the E-PG peak to properly update its position when the fly turns. We expressed shibirets, which prevents synaptic vesicle recycling in a temperature-dependent manner29, in each P-EN line, and measured E-PG activity in the bridge using GCaMP6f (Fig. 4e–h). When we impeded P-EN synaptic output at 32 °C, the E-PG signal failed to consistently track the dynamics of the fly’s heading in the dark (Fig. 4f (black arrows), g, h). We note that at 34 °C, the E-PG signal appeared dim or blurred, indicating a stronger effect (and suggesting that P-ENs contribute to the overall magnitude, or general stability, of the E-PG peak), but this made it difficult to properly estimate the E-PG phase. We therefore performed our experiments at 32 °C, expecting that P-ENs would be only partially impaired. Moreover, we did not observe a consistent impairment in the ability of the E-PG phase to track a closed-loop bar in the same flies (Extended Data Fig. 10a–d). These experiments argue that proper synaptic transmission in P-ENs is necessary for this circuit to integrate the fly’s heading without a visual landmark.

Activating P-ENs shifts E-PG activity

If P-ENs contribute to the rotation of the E-PG activity peaks, then experimental stimulation of P-ENs should drive specific changes in E-PG activity. We stimulated P-ENs, with 1–2-glomeruli resolution, on the left or right bridge by expressing the ATP-gated cation channel P2X230 and locally releasing ATP from a pipette (see Methods), while measuring E-PG activity in the bridge using GCaMP6f (Fig. 5a). When we locally excited P-ENs in the left bridge, the E-PG peaks appeared (on both sides of the bridge) to the right of the stimulated glomerulus, and vice versa when P-ENs were excited on the right bridge (Fig. 5b–g), for both P-EN1 and P-EN2 Gal4 lines. These data are consistent with an excitatory relationship (direct or indirect) between P-ENs and E-PGs. Control experiments without ATP and without Gal4 indicate that we specifically stimulated P-ENs (Extended Data Fig. 10e–j). Notably, the flies occasionally performed a behavioural turn immediately after the local release of ATP, in a direction that would return the E-PG peaks to their position just before stimulation (for example, Fig. 5b–e, asterisks)—an effect that we do not pursue further here. At the neural level, these experiments demonstrate that experimentally activating P-ENs induces the E-PG activity peaks to relocate to the expected positions in the bridge relative to the stimulated glomerulus. We note that the effects we observed in our perturbation experiments across P-EN1 and P-EN2 Gal4 lines could, formally, have been due to perturbing one P-EN subtype alone since all of our Gal4 lines contain a mixture of both subtypes but with different ratios (Extended Data Fig. 7). Regardless, these data support a role for P-ENs of at least one subtype in the shift-circuit hypothesis for angular integration.

Figure 5: P-EN neurons medially excite E-PG neurons in the bridge, consistent with a model of neural integration.
figure 5

a, Stimulating P2X2-expressing P-ENs in the bridge with ATP is expected to excite E-PGs in the medial neighbouring glomerulus. b, Left, ATP (Alexa594) signal in the bridge; right, E-PG bridge activity while stimulating P-EN1 neurons in the left bridge. c, Same as b, except for stimulating P-EN1s in the right bridge. d, e, Same as b, c but for stimulating P-EN2 neurons. Asterisks highlight events when the fly turned following stimulation in a direction that would return the E-PG phase to its pre-stimulus position. f, g, Phase-nulled E-PG activity and ATP (Alexa594) signal after P-EN1 (f) or P-EN2 (g) stimulation. Thin lines represent the mean response in each fly. Thick lines represent the mean across flies. h, Summary model. P-EN and E-PG interactions projected onto a single ring. Only ellipsoid body tiles are represented for clarity. i, Model proposed in ref. 15 for rat head-direction cells.

PowerPoint slide

Discussion

These anatomical and physiological data support a model in which an asymmetry in P-EN activity rotates the E-PG activity peak in response to the fly turning (Figs 2a–d, 5h). This model also requires additional inhibitory circuitry to maintain the width of the E-PG peak in the face of spreading P-EN excitation. A second, parallel study employing electrophysiological measurements and calcium imaging provides further evidence that P-ENs serve a role in angular integration31.

Whereas previous models of angular integration15,16,17,18,19 have required only P-EN1-like neurons, we observe a second set of asymmetrically active neurons (P-EN2) whose activity is biased to the trailing edge of the ellipsoid body E-PG peak and whose asymmetry arises later during tethered-walking turns. One interpretation of this discovery is that, given their relative timing, the early P-EN1 cells start the movement of the E-PG peak, and the late P-EN2 cells stop its movement. This model implies that a moving E-PG peak would otherwise continue rotating—a property not featured to date in models of head direction15,16,17,18,19. Another interpretation is that P-EN1s are the main drivers of angular integration, whereas P-EN2s serve a different role (see Supplementary Discussion). Further work will be needed to rigorously test such functional hypotheses.

The physiology of E-PGs and P-ENs resembles that of rodent head-direction cells in the presubiculum (and other areas)8,32 and the lateral mammillary nucleus33,34, respectively. Moreover, the models proposed to account for these physiological properties in Drosophila (here) and rodents15,16,17,18,19 are remarkably similar (Fig. 5h, i), suggesting that insects and mammals may use common circuit architectures to update their sense of heading. Although apparently hard-wired to integrate turning velocities, the essential features of this circuit are general enough to integrate other variables (including variables in two or more dimensions19) over time, and may also therefore appear in other integrating neural systems, such as the mammalian grid cell system19,35,36, among others37,38,39,40.

Methods

Fly stocks

Flies were raised with a 12-h light, 12-h dark cycle at 25 °C. All physiological experiments were performed with 1–3-day-old females with at least one wild-type white allele. Flies were selected randomly for all experiments. We were not blinded to the flies’ genotypes. For experiments imaging one cell type (Figs 1, 2, 4a–d; Extended Data Figs 1, 2, 3, 5, 6, 8a–f), we used + (Canton S, Heisenberg Laboratory)/w; UAS-GCaMP6m (Bloomington Drosophila Stock Center, BDSC #42748); VT032906–Gal4 (Vienna Drosophila Resource Center, VDRC #202537) flies for P-EN1; +/w; 60D05-LexA (BDSC #52867)/LexAop-tdTomato (Ruta Laboratory); VT020739–Gal4 (VDRC #201501)/UAS–GCaMP6m (BDSC #42750) flies for P-EN2; and +/w; +; 60D05–Gal4 (BDSC #39247)/UAS–GCaMP6m flies for E-PG. The same flies were analysed in Figs 1, 2, 4a–d, Extended Data Figs 1, 2, 3, 5. For imaging P-EN1 or P-EN2 simultaneously with E-PGs (Fig. 3, Extended Data Fig. 9), we used +/w; 60D05-LexA/LexAop–GCaMP6f (BDSC #44277); VT032906–Gal4/UAS–jRGECO1a (BDSC #63794), and +/w; 60D05-LexA/LexAop–GCaMP6f; VT020739–Gal4/UAS–jRGECO1a flies, respectively. As a control for differences in calcium indicator kinetics, we imaged GCaMP6f and jRGECO1a in the same cell type (Extended Data Fig. 8g–j), E-PGs, using +/w; UAS–GCaMP6f (BDSC #42747)/+; 60D05–Gal4/UAS–jRGECO1a flies. For the shibirets experiments (Fig. 4e–h, Extended Data Fig. 10a–d), we used three Gal4 lines to drive shibirets in P-ENs: VT032906–Gal4 (P-EN1), VT020739–Gal4 (P-EN2), and 12D09–Gal4 (P-EN2, BDSC #48503). We used pJFRC99-20XUAS-IVS-Syn21-Shibire-ts1-p10 inserted at VK00005 (referred to here as UAS-shibirets) to drive shibirets (Rubin Laboratory). For each X-Gal4 line, we used +/w; 60D05-LexA/LexAop–GCaMP6f; X-Gal4/UAS-shibirets flies with +/w; 60D05-LexA/LexAop–GC6aMPf; X-Gal4/+ flies as a control. We also used +/w; 60D05-LexA/LexAop–GCaMP6f; +/UAS-shibirets flies as a control without Gal4. For P-EN stimulation (Fig. 5, Extended Data Fig. 10e–j), we used +/w; 60D05-LexA/LexAop–GCaMP6f; X-Gal4/UAS–P2X2 flies (Ruta Laboratory), where X was either VT032906 (P-EN1) or VT020739 (P-EN2). We used +/w; 60D05-LexA/LexAop–GCaMP6f; +/UAS–P2X2 flies as a control without Gal4. For multicolour flip-out experiments (Supplementary Information Table 1, Extended Data Fig. 4g–l), we used 57C10-FLP/+; +; 10×UAS–FRT.stop-myr::smGdP–HA, UAS–FRT.stop-myr::smGdP–V5-THS-10×UAS–FRT.stop-myr::smGdP–FLAG/X-Gal4 flies, where X was VT032906, VT020739 or 12D09. We used either 57C10-FLPL (BDSC #64087) or 57C10-FLPG5 (BDSC #64088) to label more or fewer neurons, respectively. To label putative axon terminals with synaptotagmin–GFP (Extended Data Fig. 4e, f), we used +/w; +/UAS-syt–GFP (BDSC #6925); X-Gal4/UAS–tdTomato (BDSC #32221) flies, where X was VT032906 or VT020739. To co-label different P-EN driver lines (Extended Data Fig. 7), we used +/w; 12D09-LexA (BDSC #54419)/LexAop–myrGFP (BDSC #32210);X-Gal4/UAS–tdTomato flies, where X was VT032906 or VT020739.

Immunohistochemistry

We dissected fly brains in S2 medium at room temperature and fixed them in 1% paraformaldehyde at 4 °C overnight. Fixed brains were washed 3 times for 30–60 min with PAT3 (0.5% Triton X-100 and 0.5% bovine serum albumin in phosphate buffered saline), then blocked with 3% NGS in PAT3 for 1.5 h at room temperature. We incubated brains with primary and secondary antibodies as previously described43, and mounted them in VectaShield (Vector Labs). For co-labelling tdTomato with GFP (Extended Data Figs 4e, f, 7), we used anti-DsRed antibody (Clontech) at 1:1,000. For the multicolour flip-out experiments (Extended Data Fig. 4g–l, Supplementary Information Table 1), we used antibodies as previously described43. We imaged the central complex using a 40 × 1.20 NA objective on a Zeiss LSM780 confocal microscope with 0.58 or 1.0 μm separating each optical slice.

Tethered walking setup

We shaped 6.35 mm (1/4 inch) diameter balls from Last-A-Foam FR-4618 (General Plastics)25. The balls had a mass ranging from 42 to 46 mg. To shape the ball from raw foam, we machined a steel concave file with the same diameter as the ball, with sharp edges to cut the foam25. The ball rested in an aluminium base with a concave hemisphere 6.75 mm (17/64 inch) in diameter. A 1-mm channel was drilled through the bottom of the hemisphere and connected to air flowing at approximately 260 ml per min.

Behavioural imaging

For all experiments, we imaged the fly and ball from the front under 850-nm illumination with a Prosilica GE680 camera (Allied Vision Technologies) externally triggered at 50 Hz, with a zoom lens (MLM3X-MP, Computar) set at 0.3×. The lens also held an OD4 875-nm shortpass filter (Edmund Optics) to block the two-photon excitation laser (925 nm or 1,035–1,040 nm). This camera was used both to position the fly and to track the ball.

Ball tracking and closed-loop experiments

We tracked the ball using FicTrac software26. FicTrac calculates the angular position of the ball for each frame, rather than integrating rotational velocities, which ensures no drift in the estimated ball position over time. The ball was marked with irregular black spots, which allowed a single camera (see Behavioural Imaging) facing the fly to track all three rotational axes of the ball in real time at 50 Hz. We verified the accuracy of the FicTrac software using a servo motor rotating a ball at known velocities. A plastic square was laser-cut with a hole at the centre so that it fit as a sleeve on the ball holder, under the ball. The plastic square was aligned to the fly, such that its side edges were parallel to the fly’s body axis. This plastic square was then used to calibrate the FicTrac tracking system to the fly’s frame of reference (in other words, to determine which rotational axes represented forward, heading, and sideways walking). We modified FicTrac to output analogue voltages corresponding to the angular position of the ball along each axis through a digital-to-analogue converter (USB-3101, Measurement Computing). In closed loop experiments, we used the heading axis voltage output to control the azimuthal position of a bar displayed on the LED arena. That is, when the fly turned left, the bar rotated right, and vice versa, simulating the natural visual input a turning fly would experience from a prominent, stationary, visual landmark at infinity.

LED arena and visual stimuli

We used a cylindrical LED arena27, spanning 270° in azimuth and 81° in height. Pixels were spaced by 1.875°. We positioned the empty quadrant of the arena directly behind the fly. We used blue LEDs (BM-10B88MD, Betlux Electronics), covered by five sheets of blue filter (Tokyo Blue, Rosco) to reduce detection of the blue LEDs by the two-photon’s photomultiplier tubes. For all experiments, the microscope was surrounded by a black shroud to block light from the monitors, and all light-emitting sources inside the shroud other than the LED arena were covered with black tape. For the bar stimulus, we presented a single bright bar, 6 pixels wide (11°) and spanning the height of the arena. The bar did not jump across the 90° gap in the arena behind the fly; rather, we kept track of the bar position behind the fly without displaying it. For the dark stimulus, all LEDs were turned off. For the moving dots stimulus (Extended Data Fig. 6), we generated a series of frames—one for each azimuthal pixel (spaced by 1.875°)—in which single-pixel (1.875° pitch) dots appeared at random locations, travelled for four pixels, and then reappeared at a new random location. We chose this stimulus to separate the contributions of position and velocity of a moving object (like a bar), because with this stimulus the fly cannot track the position of any single dot for more than 7.5° (four frames). We designed the stimulus such that the optic flow could proceed with the same number of dots disappearing and reappearing on each frame, uninterrupted, for an infinite number of rotations. The total number of dots (including those not visible, behind the fly) was kept constant on all frames. In Extended Data Fig. 6, we presented this stimulus in closed loop with the fly's rotational walking behaviour, which we interrupted with 1-s open-loop rotations of the moving dots stimulus (45°/s and 90°/s to the left or right) every 6 s.

Fly tethering and preparation

Flies were anaesthetized at 4 °C, and were tethered to a custom holder that was similar to that used in previous studies24, except that the back wall was pitched to 45° instead of 90°, allowing more light from the brain to reach the objective (Fig. 1c). We also modified the rear of the holders to ensure that the flies could see 280° around them. Flies were fixed to the holder by gluing the thorax and the front of the head between the eyes with glue cured by blue light (Bondic). Additional glue was applied to the posterior side of the head to stabilize the head for dissection. The head was pitched forward during tethering to provide a posterior view of the central complex. We cut a window in the cuticle immersed in saline at the centre of the posterior side of the head to gain optical and pipette access to the central complex. The holder to which each fly was tethered was placed in a base at the centre of the LED arena, under the objective. The holder was stabilized by magnets in the holder and the base. The ball holder was mounted on a manipulator to adjust the position of the ball under each fly.

Calcium imaging

We used a two-photon microscope with a movable objective (Bruker) and custom stage (ThorLabs, Siskiyou). For two-photon excitation we used a Chameleon Ultra II Ti:Sapphire femtosecond pulsed laser (Coherent). To image GCaMP6m or GCaMP6f alone, we tuned the laser to 925 nm, whereas to image GCaMP6f and jRGECO1a together, we used 1,035–1,040-nm light, to excite both fluorophores simultaneously. The emitted light was split by a 575-nm dichroic mirror. We used a 490–560-nm bandpass filter (Chroma) for the green channel in single indicator experiments (Figs 1, 2, 4; Extended Data Figs 13, 5, 6, 8a–f, 10a–d). For dual imaging of GCaMP6f and jRGECO1a (Fig. 3, Extended Data Figs 8g–j, 9) we used a 500–550-nm bandpass filter for the green channel and a 585–635-nm bandpass filter for the red channel, except during dual imaging of E-PGs and P-EN2 in the bridge (Fig. 3b, d), where we used a 490–560-nm bandpass filter for the green channel. We detected light signals with GaAsP detectors (Hamamatsu). We used a 40× 0.8 NA objective (Olympus) to image the brain. We perfused the brain with extracellular saline composed of, in mM: 103 NaCl, 3 KCl, 5 N-Tris(hydroxymethyl) methyl-2-aminoethanesulfonic acid (TES), 10 trehalose, 10 glucose, 2 sucrose, 26 NaHCO3, 1 NaH2PO4, 1.5 CaCl2, 4 MgCl2, and bubbled with 95% O2/5% CO2. The saline had a pH of 7.3–7.4, and an osmolarity of 280 ± 5 mOsm. The temperature of the bath was controlled by flowing the saline through a Peltier device, with feedback from a thermistor in the bath (Warner Instruments). This thermistor measurement was used to set the bath to 22 °C or 32 °C for the shibirets experiments. To image the protocerebral bridge, we selected a region framing the bridge, about 140 × 50 pixels in size, and scanned through 2 or 3 z-planes separated by 7–9 μm using a Piezo motor to achieve a volumetric scanning rate of 5–7 Hz. To image the ellipsoid body, we selected a region 64 × 64 pixels in size and scanned through 3 z-planes separated by 7–9 μm at 5–7 Hz.

Trial structure

For all experiments, unless noted, we interleaved two visual conditions: closed-loop bar (1.0× gain between angular rotations of the ball and bar) and dark screen. For GCaMP6m imaging of single cell types in the bridge (Figs 1, 2, 4a–d; Extended Data Figs 13, 5), we presented each fly with six 50-s trials of each visual condition. For GCaMP6m imaging of single cell types in the bridge and ellipsoid body (Extended Data Fig. 8a–f), we presented each fly with two 50-s trials of each visual condition. For GCaMP6f and jRGECO1a imaging (Fig. 3, Extended Data Figs 8g–j, 9), we presented each fly with one or two 20–30 s trials of each visual condition. For imaging E-PGs with P-EN-shibirets (Fig. 4e–h; Extended Data Fig. 10a–d), we presented each fly with two 50-s trials each of closed-loop bar and a dark screen (and additional stimuli not analysed here) for each temperature. For the optic flow stimuli (Extended Data Fig. 6), we presented 16 blocks of the four stimuli (−45°/s, +45°/s, −90°/s, +90°/s open loop optic flow) to each fly. The order of the four open loop stimuli was randomized within each block. Half of the 1-s open loop stimuli were separated by 5 s of 0.5× gain closed loop optic flow, and half by 5 s of 1.0× gain closed loop optic flow. The P2X2 experiments (Fig. 5; Extended Data Fig. 10e–j) were performed in constant darkness.

Data acquisition and alignment

All data were digitized at 10 kHz using a Digidata 1440 (Axon Instruments), except for the two-photon scanning images, which were acquired using PrairieView (Bruker). Behavioural, stimulus and two-photon scanning data were aligned using triggers acquired on the same Digidata 1440.

Comparing data acquired at different sampling rates

When comparing two-photon imaging (~5–7 Hz) and behavioural data (50 Hz) within a fly on a time-point-by-time-point basis (Figs 1j–l, 2k–m, 4g, h; Extended Data Figs 1m–o, 3, 9e, f, 10c, d), we subsampled behavioural data to the imaging frame rate by computing its mean during each volumetric imaging time point. Because different flies were imaged at slightly different frame rates depending on the size of the region of interest, when averaging across flies or across turns (Fig. 2h–j, bottom row, 4c, d, thick lines; Extended Data Figs 5, 6, 9a–d), we linearly interpolated each time series to a common time base of 10 Hz, and then averaged over these interpolated time series. Our conclusions are not altered if we interpolate to slower time bases.

Data analysis

Two photon images were first registered using Python 2.7 (see Image registration). These images were then manually parsed in Fiji44 (see Processing imaging data). All subsequent data analysis was performed in Python 2.7. We did not exclude flies from any analysis, except for the jRGECO1a experiments, where a few recordings were excluded because the red signal was too weak (0/20 flies for Figs 3c, 1/12 flies for Fig. 3d, 8/22 flies for Fig. 3k, m, o, 0/11 flies for Fig. 3l). In analysed jRGECO1a flies, we also sometimes excluded the second of two sets of stimuli because of jRGECO1a bleaching. If we do not exclude these data, our conclusions are unaltered. No statistical method was used to choose the sample size.

Image registration

Two-photon imaging frames were computationally registered by translating each frame in x and y to best match the time-averaged frame for each z-plane. We registered multiple recordings from the same fly to the same time-averaged template for each z-plane, unless a significant shift was introduced between recordings. Rarely, time points were discarded from analysis if the registration failed because the signal in a particular frame was too weak. We did not register dual cell type imaging data from the ellipsoid body, but rather analysed the raw data directly.

Processing imaging data

Regions of interest were manually defined in Fiji44. For the protocerebral bridge, we manually defined regions delineating each glomerulus from the registered time-average of each z-plane (Extended Data Fig. 1a). Note that E-PGs do not innervate the outer two glomeruli of the bridge, and P-ENs do not innervate the inner two glomeruli21, and thus no region was defined for these glomeruli for the respective cell type. In P-EN2 GCaMP experiments, tdTomato was expressed in E-PGs, which helped us to parse glomeruli. For P-EN1 GCaMP experiments, two copies of UAS-GCaMP and VT032906-Gal4 were required to produce enough signal, and therefore tdTomato was not used for parsing glomeruli. For the ellipsoid body recordings, we first smoothed the imaging data with a 2-pixel (~ 2-μm) Gaussian. We manually defined an ellipsoid body region of interest from the time-average of each z-plane. We then subdivided these regions into 16 equal wedges radiating from a manually selected centre, as described previously14. Note that while E-PGs tile the ellipsoid body in 16 wedges, and P-ENs tile the ellipsoid body in half the number of tiles21, we used the same 16-wedge analysis for both as an equal means of comparing the two signals. We calculated the mean pixel value for each glomerulus or wedge across z-planes for each time point, producing a matrix of raw mean intensity values for each region over time. We then calculated ∆F/F values for each glomerulus or wedge independently, by defining F as the mean of the lower 5% of raw values in a given glomerulus or wedge over time. We also normalized each glomerulus or wedge independently with a z-score, which measures how many standard deviations each imaging data point is from the mean. We used this metric to estimate bridge asymmetries (Figs 2, 4a–d; Extended Data Figs 5, 6), because it tended to normalize constant, absolute differences in intensity across glomeruli better than the ∆F/F approach. Constant, absolute differences in fluorescence across glomeruli might reflect functional differences among glomeruli or simply result from differences in the number of cells per glomerulus targeted by each Gal4 line, or the amount of GCaMP in each cell. We observed the same asymmetries in the bridge using the ∆F/F normalization approach, but with more variability (Extended Data Fig. 5).

Analysis of periodicity and phase

To analyse the protocerebral bridge signal, we started with a matrix of ∆F/F values, in which each row represents a time point, and each column represents a glomerulus. We took the Fourier transform of each row or time point independently, and observed a consistent peak at a periodicity of about eight glomeruli for each cell type (the peak periodicity of the power spectrum averaged over time is shown in Extended Data Fig. 1j–l for closed-loop bar and Extended Data Fig. 2g–i for dark conditions). Given that this periodicity was relatively constant over time (Extended Data Figs 1a–i, 2a–f), we extracted the phase from the Fourier component with a period of eight glomeruli for each time point independently. When overlaid on the protocerebral bridge GCaMP time series, this phase accurately tracked the shift in the protocerebral bridge over time (Extended Data Figs 1a–i, 2a–f). For the ellipsoid body, we computed the population vector average, as previously described14. For summary analyses, and for the dual-imaging sample traces (Fig. 3a, b, i, j), the phase was filtered with a three-point moving average. To calculate the offset between the phase and bar position (Extended Data Fig. 1m–o), we computed the circular mean of the difference between the phase and bar position during time points when the bar was visible to the fly. We shifted the phase by this constant offset in Fig. 1g–i and Extended Data Figs 1c, f, i and 10a, b. In Figs 2e–g and 4a, b, we nulled the accumulated phase and ball position at time zero, and applied a gain to the ball heading to best match the phase: 1.0 for Fig. 2e (P-EN1), 1.40 for Fig. 2f (P-EN2), 0.75 for Fig. 2g (E-PG), 1.0 for Fig. 4a (P-EN1) and 0.89 for Fig. 4b (P-EN2). We do not interpret these different gains measured in different flies to mean that the three cell types have phase signals that drift relative to each other; indeed, when we imaged E-PGs and P-ENs simultaneously in the same fly (Fig. 3), their peaks moved in unison (that is, with the same gain) along the bridge and ellipsoid body. The different gains measured in separate flies could be due to fly-to-fly or tethering variability14.

Correlation analysis

For closed-loop bar experiments, we computed the circular correlation45 between GCaMP phase and bar position (Fig. 1j–l, ‘position’). For experiments in the dark, we computed the Pearson correlation between GCaMP phase velocity and ball velocity (Fig. 1j–l, ‘velocity’ and Fig. 4g, h). We correlated velocities instead of position for dark screen data because the phase tended to drift away from the ball’s heading without a visual landmark. We calculated these correlations for different time lags between the phase and ball signals, and in each figure we report the correlation at the time lag for which the correlation was highest. Specifically, the phase was delayed by 300 ms relative to the ball for E-PG and P-EN2 neurons in Fig. 1j, l, and by 600 ms for P-EN1 neurons in Fig. 1k. The sign of these delays suggests that the heading system updates in response to the fly turning, not vice versa, although more experiments are needed (see Supplementary Discussion). The longer delay for P-EN1 compared to P-EN2 and E-PG was likely to be an artefact of overexpressing GCaMP6m in P-EN1 rather than to reflect a genuine biological difference among cell types (see Supplementary Discussion). For example, in other imaging experiments in which we measured P-EN1 activity side-by-side with E-PG activity, we observed that the P-EN1 peak actually led the E-PG peak (Fig. 3m, o). In Fig. 4g, h, the time lag for which the correlation was highest between E-PG GCaMP phase and ball velocity was 200 ms (rather than 300 ms), which was the time lag used for the correlation values reported in this Figure; this shorter delay was probably due to the fact that in Fig. 1 we used GCaMP6m, and in Fig. 4e–h we used GCaMP6f. For the P-EN>shibirets experiments (Fig. 4e–h), we computed the difference between the velocity correlations at 22 °C and 32 °C for each fly. We then used a two-sided Wilcoxon rank-sum test to reject the null hypothesis that this difference was the same in each of the three P-EN-Gal4, UAS-shibirets fly populations and in the respective P-EN-Gal4- or UAS-shibirets-only populations (P < 0.01 for all individual comparisons). For all phase correlations, we included only data during which the fly was walking with a speed of at least 1 mm/s. We also required the peak activity (the mean of the top two values in the bridge) to be greater than 0.8 ∆F/F, to ensure the phase was properly estimated.

Computing the bridge asymmetry as a function of turning velocity

For each time point, we subtracted the mean z-score-normalized signal in the left bridge from that in the right bridge (referred to as the bridge asymmetry). We binned these bridge asymmetries based on the turning velocity of the fly in 30°/s bins, and computed the mean asymmetry in each bin (Fig. 2k–m). We repeated this process for different time lags between the bridge asymmetry and the fly’s turning behaviour, to find the lag at which the slope (measured between −200°/s and +200°/s) was the steepest. The curve computed at this time lag (bridge asymmetry lagging by +400 ms with respect to behaviour for P-EN1 and P-EN2) is shown in Fig. 2k, l. (Many other lags, before and after +400 ms, also show a significant positive slope for P-EN1 and P-EN2.) The time lag chosen does not affect the E-PG curve, whose slope is always near zero.

Culling individual turns or phase shifts

To isolate individual turns (Fig. 2h–j) or phase shifts in the bridge (Fig. 4c), we detected peaks in the turning velocity or phase velocity signal, respectively. In both cases, we first smoothed the velocity signal by convolving it with a Gaussian (300 ms s.d.). From this smoothed velocity signal, we isolated peaks with a minimum peak height of 30°/s and a minimum peak width of 0.5 s for the turns and the phase shifts. We further required that each peak be isolated from other peaks by a minimum distance of 1.5 s. We aligned the turning velocity or phase velocity and bridge asymmetry signals to the start of each turn or phase shift.

Phase nulling

To compute the average GCaMP signal in the bridge or ellipsoid body independent of phase (Fig. 3c, d, k–p; Extended Data Figs 8, 9a, b), we computationally shifted the GCaMP signals at each time point so that the phase was the same across all time points. To achieve this phase nulling, we first interpolated the GCaMP signal at each time point to 1/10 of a glomerulus or wedge with a cubic spline. We then shifted this interpolated signal by the phase estimate at that time point. In the ellipsoid body, this shift is naturally circular. In the protocerebral bridge, we wrapped the signal around the same side of the bridge, such that values shifted past the left edge of the left bridge would return on the right edge of the left bridge, and so on, in order to preserve left and right asymmetries. This was possible because each side of the bridge innervated by a given cell type consisted of eight glomeruli, which matched the period of the signals. Once we nulled the phase, we computed the mean signal over time when the fly was walking straight (Fig. 3c, d, k, l, computed for 0 ± 30°/s). For the ellipsoid body, we also averaged the phase-nulled signal over times when the fly turned at 300 ± 30°/s to the left (negative) or right (positive). In Fig. 3k–p, we show these phase nulled plots at the time lag for which the P-EN1 or P-EN2 ellipsoid body asymmetry (see below) and the fly’s turning velocity showed a maximum correlation (Extended Data Fig. 9e, f, black arrows). In Fig. 3 we nulled both the P-EN and E-PG signals using the E-PG phase. In Extended Data Fig. 8a–f, we nulled both the bridge and ellipsoid body signals using the ellipsoid body phase. In Extended Data Fig. 8g–j, we nulled both the GCaMP6f and jRGECO1a signals using the GCaMP6f phase (analogous to Fig. 3). In Fig. 5f, g, and Extended Data Fig. 10e–j, we nulled both the GCaMP6f and Alexa594 signals using the position of the pipette.

Computing the ellipsoid body asymmetry in P-ENs

To compute the ellipsoid body asymmetry in P-ENs (Extended Data Fig. 9c–f), we integrated the P-EN signal 180° clockwise and anticlockwise from the E-PG phase, and subtracted the integrated anticlockwise (left on the linearized plots) signal from the integrated clockwise (right on the linearized plots) signal. We used a two-sided Wilcoxon rank-sum test to reject the null hypothesis that the ellipsoid body asymmetry in P-ENs was the same when the fly was turning to the left at –300°/s (Fig. 3m, n) as when it was walking straight (Fig. 3k, l), and the same when turning to the right at +300°/s (Fig. 3o, p) as when it was walking straight (Fig. 3k, l). All P values were <0.02 when analysing either z-score normalized data (not shown) or ∆F/F normalized data (Fig. 3k–p). The null hypothesis that the ellipsoid body asymmetry in P-ENs was the same when the fly turned left (Fig. 3m, n) as when it turned right (Fig. 3o, p) was rejected for both P-EN1 and P-EN2 (P < 0.01), using a two-sided Wilcoxon rank-sum test with either z-score or ∆F/F normalized data.

P-EN stimulation

To measure the effect of stimulation of P-ENs on E-PGs, we expressed GCaMP6f in E-PGs and the ATP-gated cation channel P2X2 in either P-EN1 or P-EN2 cells (see Fly stocks). Na2ATP (A7699, Sigma) was dissolved in extracellular solution (see Calcium imaging) at 1 mM, and stored in aliquots at −80 °C. Working solutions of 0.5 mM ATP for VT032906-Gal4 or 0.1 mM ATP for VT020739-Gal4 with 20 μM Alexa594 were prepared on the same day as the experiment and loaded into a pipette with a bore <1 μm in diameter. We adjusted the concentration of ATP to provide as gentle a perturbation as possible, as measured by the E-PG signal shapes remaining the same, and the E-PG phase returning to following the fly’s movements a few seconds after the stimulation. 0.5 mM ATP was used for controls without Gal4. The pressure in the pipette was controlled using a Pneumatic PicoPump (PV820, World Precision Instruments), and the pressure recorded using a Pressure Monitor (PM 015R, World Precision Instruments). We applied pressure pulses ranging from 5 to 20 psi with a 20-ms duration. The pipette was controlled using a PatchStar micromanipulator (Scientifica). To access the bridge, we locally applied 0.5 mg/ml collagenase type 4 (Worthington) through a pipette, while keeping the bath at ~30 °C, to breach the sheath above the bridge. For dual imaging of GCaMP6f and Alexa594, we used a 500–550-nm bandpass filter for the green channel, and a 585–635-nm bandpass filter for the red channel. We computed ∆F/F values for Alexa594 by defining the baseline, F0, as the mean of the lowest 5% of values in the entire bridge, rather than independently for each glomerulus, because the glomerulus-independent normalization is meant to compensate for varying GCaMP baselines across glomeruli, presumably owing to varying levels of GCaMP expression, or the amount of innervation within each glomerulus. In Fig. 5f, g and Extended Data Fig. 10e–j, both channels were nulled using the position of the pipette, which differed from fly to fly. In Fig. 5f, g, we averaged the E-PG signal 0.7–1.0 s after stimulation, and the Alexa594 (ATP) signal during the first frame after stimulation. In Extended Data Fig. 10e–j, we computed the change in each phase-nulled signal by subtracting the average over 0.3 s before stimulation from the averages in Fig. 5f, g for each channel. The four examples in Fig. 5b–e highlight trials in which we happened to stimulate P-ENs at roughly the glomeruli where we expected P-EN1 or P-EN2 activity peaks to already have been residing immediately before stimulation based on the measured E-PG phase (see Fig. 3) (that is, approximately in phase with E-PGs for P-EN1 and approximately anti-phase with E-PGs for P-EN2). All stimulation trials are included in the phase-nulled averages in Fig. 5f, g. All stimulation experiments were performed in the dark.

Data and code availability

All data and code are available on request from the authors.