# Imaging neural activity in the ventral nerve cord of behaving adult Drosophila

Chin-Lin Chen, Laura Hermans, Meera C Viswanathan, Denis Fortun, Florian Aymanns, Michael Unser, Anthony Camarrato, Michael H. Dickinson, Pavan Ramdya

<figure><img src="image_1.png" /></figure>

## To cite this version:

Chin-Lin Chen, Laura Hermans, Meera C Viswanathan, Denis Fortun, Florian Aymanns, et al., Imag-
ing neural activity in the ventral nerve cord of behaving adult Drosophila. Nature Communications,
2018, 9, 10.1038/s41467-018-06857-z. [This article is licensed under the Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/). This license permits unrestricted use, provided the source is indicated how. For the images and videos, please reference the original author(s) and the Creative Commons license.

HAL Id: hal-03469822

https://hal.science/hal-03469822

Submitted on 7 Dec 2021

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>
# Imaging neural activity in the ventral nerve cord of behaving adult *Drosophila*

Chin-Lin Chen<sup>1,2</sup>, Laura Hermans<sup>1,2</sup>, Meera C. Viswanathan<sup>3</sup>, Denis Fortun<sup>4,5,8</sup>, Florian Aymanns<sup>1,2</sup>, Michael Unser<sup>4</sup>, Anthony Cammarato<sup>3,6</sup>, Michael H. Dickinson<sup>7</sup> & Pavan Ramdya<sup>1,2</sup>

To understand neural circuits that control limbs, one must measure their activity during behavior. Until now this goal has been challenging, because limb premotor and motor circuits have been largely inaccessible for large-scale recordings in intact, moving animals—a constraint that is true for both vertebrate and invertebrate models. Here, we introduce a method for 2-photon functional imaging from the ventral nerve cord (VNC) of behaving adult *Drosophila melanogaster*. We use this method to reveal patterns of activity across nerve cord populations during grooming and walking and to uncover the functional encoding of moonwalker ascending neurons (MANs), moonwalker descending neurons (MDNs), and a previously uncharacterized class of locomotion-associated A1 descending neurons. Finally, we develop a genetic reagent to destroy the indirect flight muscles and to facilitate experimental access to the VNC. Taken together, these approaches enable the direct investigation of circuits associated with complex limb movements.

<footnote n="1"><sup>1</sup>Brain Mind Institute, École Polytechnique Fédérale de Lausanne, CH-1015 Lausanne, Switzerland. <sup>2</sup>Interfaculty Institute of Bioengineering, École Polytechnique Fédérale de Lausanne, CH-1015 Lausanne, Switzerland. <sup>3</sup>Department of Medicine, Johns Hopkins University, Baltimore, MD 21205, USA.</footnote>

<footnote n="4"><sup>4</sup>Biomedical Imaging Group, École Polytechnique Fédérale de Lausanne, CH-1015 Lausanne, Switzerland. <sup>5</sup>Signal Processing core of the Center for Biomedical Imaging (CIBM-SP), École Polytechnique Fédérale de Lausanne, CH-1015 Lausanne, Switzerland. <sup>6</sup>Department of Physiology, Johns Hopkins University, Baltimore, MD 21205, USA. <sup>7</sup>Biology and Biological Engineering, California Institute of Technology, Pasadena, CA 91125, USA. <sup>8</sup>Present address: ICube, CNRS, University of Strasbourg, CS 10413 - F-67412 Illkirch Cedex, France. These authors contributed equally: Chin-Lin Chen, Laura Hermans. Correspondence and requests for materials should be addressed to P.R. (email: Pavan.Ramdya@epfl.ch)</footnote>
Limbs allow animals to rapidly navigate complex terrain, groom, manipulate objects, and communicate. In vertebrates, neural circuits in the spinal cord coordinate the actions of each arm or leg. Thoracic circuits perform comparable tasks in insects¹. The thoracic segments of the fruit fly, *Drosophila melanogaster*, house the ventral nerve cord (VNC) which is a fusion of three thoracic and eight abdominal ganglia. The VNC contains six spherical neuromeres, each controlling one leg, a flat dorsal neuropil associated with the neck, wing, and halteres, and a set of intermediate neuropils including the tectulum that may coordinate the action of the legs and wings². Also within the thoracic VNC are descending³ and ascending⁴ axons that connect the VNC and the brain. These tracts run through the neck or cervical connective, which—like the VNC—is inaccessible in most preparations.

The VNC of adult *Drosophila* is the site where some higher-order decisions are transformed into actions. Adult flies engage in complex limbed behaviors including walking⁵,⁶, reaching⁷, escape jumping⁸, courtship tapping⁹, aggressive boxing¹⁰, and grooming¹¹. Our current understanding of how thoracic circuits coordinate these actions is entirely based on behavioral genetics or recordings from a few neurons in tissue explants¹², immobilized animals¹³⁻¹⁵, or sharp electrode studies in larger insects¹⁶,¹⁷.

To fully understand how thoracic circuits orchestrate limb movements, it is necessary to record the activity of individual cells and populations of neurons during behavior. To date, these experiments have not been performed in *Drosophila* due to the difficulty of accessing the VNC in intact, behaving animals. Here we describe a preparation that overcomes this obstacle and makes it possible to record the dynamic activity of populations and sparse sets of individual neurons within adult thoracic circuits during walking, grooming, and other actions involving limb movement.

## Results

**A dissection for accessing the ventral nerve cord.** The VNC lies on the thoracic sternum—a cuticular structure that anchors the leg muscles and the proximal leg segments to the thorax (Fig. 1a). Consequently, it is difficult to access the VNC by removing ventral thoracic cuticle without destroying musculoskeletal elements required for limb movement. We chose instead to access the VNC dorsally at the expense of flight-related behaviors¹⁸. This approach requires removing the prescutum and scutum of the dorsal thoracic cuticle, the indirect flight muscles (IFMs), and transecting the proventriculus, crop, and salivary glands of the gut (Fig. 1a, Supplementary Fig. 1, see Methods).

Using this technique, it is possible to perform functional imaging in flies that are still capable of exhibiting robust behavior, such as walking and grooming, for up to at least 4 h. In one round of studies (n = 46 flies) by a newly trained experimenter 46% of animals produced behaviors, 26% had limb movement deficiencies, and 28% were incapacitated. When comparing walking behaviors between flies with or without a thoracic dissection, we found that dissected flies generate locomotor bouts with likelihoods and velocities within the range of those observed in non-dissected animals (Supplementary Fig. 2; n = 20 dissected and 20 non-dissected flies). We note, however, that there are more examples of highly active non-dissected animals. We also found that, on average, dissected animals generate longer bouts (Supplementary Fig. 2b; *P* < 0.05 Mann-Whitney *U*-test). This may be due to the fact that we only recorded from dissected animals that produced limb movements in response to touch or puffs of air. Therefore, they may also have been in a higher state of arousal.

Next, to illustrate the extent of optical access, we drove expression of the genetically encoded calcium indicator,

GCaMP6s¹⁹, together with tdTomato²⁰—a fluorophore that serves as an anatomical fiduciary—throughout the entire nervous system (GMR57C10 > GCaMP6s; tdTomato)²¹, (Fig. 1b, d–g and Supplementary Movie 1). To perform 2-photon microscopy in semi-intact, behaving animals, we constructed a customized fly holder and spherical treadmill (Supplementary Fig. 3) that, in contrast to previous methods used to record neural activity in the brain¹⁸,²²,²³, permits optical access to the VNC along with unobstructed videography of limb movements.

**Imaging the activity of populations of neurons in the VNC.** By scanning horizontal x-y image planes in animals expressing GCaMP6s and tdTomato pan-neuronally (GMR57C10 > GCaMP6s; tdTomato), we could record the detailed time course of neural activity in the prothoracic neuromere during walking and grooming (Fig. 1c, e and Supplementary Movie 2). Alternatively, we could use a piezo-driven objective to scan coronal x-z image planes. These coronal sections allowed us to simultaneously record neural activity across different depths of the VNC corresponding to distinct layers housing sensory neuron axons⁴, interneurons¹⁵, and motor neuron dendrites²⁴ (Fig. 1c, f; Supplementary Movie 3), or to monitor activity patterns across populations of descending³,²⁵ and ascending fibers⁴,¹²,²⁵ within the thoracic cervical connective (Fig. 1c, g and Supplementary Movie 4). Thus, we confirmed that our preparation provides optical access to previously inaccessible thoracic neural populations in behaving adult flies.

During behavior, the VNC moves and deforms. To overcome these image analysis obstacles, we used a non-parametric, variational image registration approach, designed to model arbitrarily complex deformations (Supplementary Fig. 4 and Supplementary Movie 5, see Methods). After successful image registration, we used a semi-automated approach to annotate walking and grooming behaviors (Supplementary Movie 6, see Methods) and regressed these two datasets to identify VNC regions whose activity patterns correlated with walking and grooming (Fig. 2). We anticipate that further improvements in image registration will make it possible to build similar behavior-function maps from dense neural population imaging data in which the activity patterns of individual neurons can be identified.

**Imaging the activity of sparse sets of neurons in the VNC.** Using *Drosophila*, it is possible to repeatedly and systematically investigate the functional properties of sparse sets of genetically identifiable neurons. In a recent study, a thermogenetic activation screen was used to identify a pair of descending neurons—Moonwalker Descending Neurons (MDNs)—that cause flies to walk backwards²⁵. Additionally, concurrent thermogenetic activation of ascending neurons that project from the VNC to the brain—Moonwalker Ascending Neurons (MANs)—resulted in even more sustained backwards walking, perhaps by arresting forward walking²⁵. Although these activation experiments show that MDNs and MANs play an important role in the control of backwards walking, their native activity patterns and the means by which they regulate or encode limb movements remain unknown.

Because MAN and MDN axons terminate in the gnathal ganglia (GNG) and the VNC—both relatively inaccessible regions of the nervous system—it is difficult to record the activity of these cells during behavior. We used our functional imaging approach to overcome this challenge and recorded the activity of ascending and descending neurons within the VNC. To overcome vertical movement artifacts associated with walking, we performed
<figure><img src="image_3.png" /><figcaption>**Fig. 1** Dissection for imaging the adult *Drosophila* ventral nerve cord (VNC). **a** Schematic of the dorsal thoracic dissection. **b** Overview of newly accessible nervous tissue following thoracic dissection. **c** Confocal image of pan-neuronal driver line expression in the brain and VNC. Scale bar is 90 µm. GFP (yellow) and neuropil (nc82, blue) are labeled. Dashed lines highlight the horizontal and coronal imaging modalities used in this study. **d** Horizontal sections of the VNC imaged at different depths in an animal expressing GCaMP6s (cyan) and tdTomato (red) throughout the nervous system (GMR57C10 > GCaMP6s; tdTomato). Motor neuron (MNs) cell bodies and prothoracic femoral chordotonal organ (pFChO) axon terminals are indicated (white arrowheads). Scale bar is 30 µm. **e** Horizontal section imaging of the VNC. Scale bar is 35 µm. **f** Coronal section imaging of the prothoracic neuromere. Scale bar is 50 µm. **g** Coronal section imaging of the cervical connective. Scale bar is 35 µm. Images in **e–g** were taken from flies expressing GCaMP6s and tdTomato throughout the nervous system (GMR57C10 > GCaMP6s; tdTomato)</figcaption></figure>

coronal section imaging of their axons within the cervical connective (e.g., Fig. 3a).

**Activity patterns of moonwalker ascending neurons.** Using this approach, MAN axons are visible as small ellipses (Fig. 3b). The MAN split-GAL4 line we used drives expression of GCaMP6s and tdTomato (MAN > GCaMP6s; tdTomato) in a pair of dorsal and a pair of ventral neurons. We focused our analysis on the dorsal pair of neurons—hereafter referred to as dMANs—because they showed conspicuous changes in activity (Fig. 3c). The activity of left and right dMANs were strongly correlated (Supplementary Fig. 5a; Pearson's *r* = 0.96 ± 0.01, *n* = 5 flies), allowing us to study their collective response properties. Specifically, we automatically identified the occurrence of transient increases in dMAN fluorescence—referred to as ‘events’—and examined corresponding behaviors reflected by rotations of the spherical

treadmill (see Methods). Our analysis revealed that dMAN events were associated with rapid bimodal anterior-posterior rotations of the spherical treadmill (Fig. 3d, *n* = 748 left and 746 right dMAN events from 9773 s of data from 5 flies). Through close inspection of the video data, we observed that these rotations occur when flies extend all six legs to push down on the spherical treadmill (Supplementary Movies 7 and 8).

**Activity patterns of moonwalker descending neurons.** Next, we asked to what extent MDNs are active during periods of backwards walking, a possibility suggested by behavioral responses to thermogenetic²⁵ and optogenetic²⁶ MDN stimulation. To address this question, we performed coronal section imaging of the thoracic cervical connective in flies expressing GCaMP6s and tdTomato in MDNs (MDN-1 > GCaMP6s; tdTomato) (Fig. 4a, b). As for dMANs, left and right MDN activity patterns were
<figure><img src="image_4.png" /><figcaption>**Fig. 2** Recording populations of neurons in the VNC during behavior. **a** Standard deviation time projection for an experiment performing horizontal section imaging of the VNC. Scale bar is 35 µm. **b**, **c** Heat maps of linear regression weights $w_g$ and $w_w$ showing the pixel-wise relationships between fluorescence traces and **b** grooming or **c** walking, respectively. Weights are normalized to the maximum for each image. Data are from the experiment shown in panel **a**. **d** ROI-associated fluorescence traces (red from panel **b**, black from panel **c**) (top). Shaded regions indicate semi-automatically detected bouts of grooming (pink) or walking (gray). Corresponding forward, sideways, and rotational velocities of the fly (bottom)</figcaption></figure>

<figure><img src="image_5.png" /><figcaption>**Fig. 3** Neural activity of dMANs in the thoracic cervical connective during behavior. **a** Confocal image of MAN-Gal4 driver line expression in the brain and VNC. Scale bar is 40 µm. Neuronal GFP (yellow) and neuropil (nc82, blue) are labeled. A dashed white line highlights the thoracic x-z plane imaged. **b** Coronal section of the thoracic cervical connective in an animal expressing GCaMP6s (cyan) and tdTomato (red) in MANs (MAN > GCaMP6s; tdTomato). Scale bar is 3.5 µm. **c** Separated ROIs (top-left) and associated fluorescence signals from right and left dMANs (top-right). Corresponding forward, sideways, and rotational velocities of the fly (bottom-right). Events are indicated as dashed gray lines. **d** Summary of dMAN activity and spherical treadmill rotations with respect to fluorescence events (748 left neuron and 746 right neuron events) aligned to 0 s (dashed gray line). Control data in which events are time-shuffled are overlaid in gray. Shown are the means (solid line) and bootstrapped 95% confidence intervals (transparencies)</figcaption></figure>
<figure><img src="image_6.png" /><figcaption>**Fig. 4** Neural activity of MDNs in the thoracic cervical connective during behavior. **a** Confocal image of *MDN-1-Gal4* driver line expression in the brain and VNC. Scale bar is 40 µm. Neuronal GFP (yellow) and neuropil (nc82, blue) are labeled. A dashed white line highlights the thoracic x-z plane imaged. **b** Coronal section of the thoracic cervical connective in an animal expressing GCaMP6s (cyan) and tdTomato (red) in Moonwalker Descending Neurons (*MDN-1* > *GCaMP6s*; *tdTomato*). Scale bar is 6 µm. **c** Separated ROIs (top-left) and associated fluorescence signals from right and left MDNs (top-right). Corresponding forward, sideways, and rotational velocities of the fly (bottom-right). Events are indicated as dashed gray lines. **d** Summary of MDN activity and spherical treadmill rotations with respect to fluorescence events (900 left neuron and 900 right neuron events) aligned to 0 s (dashed gray line). Control data in which events are time-shuffled are overlaid in gray. Shown are the means (solid line) and bootstrapped 95% confidence intervals (transparencies).</figcaption></figure>

strongly correlated (Supplementary Fig. 5b; Pearson's *r* = 0.93 ± 0.001, *n* = 3 flies), allowing us to study their collective response properties. As predicted, MDNs became active prior to anterior rotations of the spherical treadmill, corresponding to brief episodes of backward walking (Fig. 4c, d, *n* = 900 left and 900 right MDN events from 3 flies and 7790 s of data; Supplementary Movies 9 and 10).

**Activity patterns of previously uncharacterized descending neurons.** In addition to resolving the functional properties of previously identified neurons, our method can facilitate the discovery of novel cell classes that are active during walking, grooming, and other behaviors involving the limbs or abdomen. As a proof-of-concept, we selected four split-GAL4 lines²⁷ that drive sparse expression in pairs of descending neurons³ whose axons project to leg neuromeres in the VNC (classes DNa01, DNb06, DNg10, and DNg13). We did not observe fluorescence responses during grooming or locomotion in DNg10, or DNg13 cells. DNb06 activity appeared to be only partially correlated with locomotion. By contrast, we observed that DNa01 neurons—hereon referred to as A1 cells—had activity patterns that were clearly linked to locomotor behaviors (*A1* > *GCaMP6s*; *tdTomato*) (Fig. 5a, b and Supplementary Movie 11). The activity of left and right A1 neurons were not highly correlated (Fig. 5c and Supplementary Fig. 5c; Pearson's *r* = 0.53 ± 0.17, *n* = 4 flies). Therefore, we investigated the response properties of the left and right cells separately. We found that although the activities of both cells are linked to forward walking, events associated only with left A1 activity were correlated with negative medial-lateral and yaw rotations, or leftward turning by the fly (Fig. 5d and Supplementary Movie 12; *n* = 1644 events from 4 flies and 8784 s of data). As predicted from the bilateral symmetry of these cells, activity in the right A1 neuron coincided with positive

medial-lateral and yaw rotations, or rightward turning (Fig. 5e and Supplementary Movie 13; *n* = 1651 events from 4 flies and 8784 s of data).

**Facilitating access to the VNC by inducing IFM cell death.** Our approach for recording neural activity in the VNC of behaving *Drosophila* opens up many new avenues for studying premotor and motor circuits. Nevertheless, we can envision further improvements that will accelerate the study of the thoracic nervous system. For example, in our preparation we found it challenging and time-consuming to remove indirect flight muscles (IFMs) that fill most of the thorax. Although large, these muscles are quite fragile and tend to disintegrate over several hours after the cuticle of the notum is removed. However, to increase the speed and efficiency of our dissection, we devised a transgenic strategy to selectively ablate IFMs. We drove the expression of Reaper—a protein involved in apoptosis²⁸—in IFMs using a 5' *Act88F* promoter sequence²⁹. This loss results in highly elevated or slightly depressed wings—phenotypes seen in IFM developmental mutants³⁰. *Act88F:Rpr* animals show a nearly complete loss of IFMs after 7 days post-eclosion (dpe) when raised at 25 °C (Fig. 6a, b). The heterozygous *Act88F:Rpr* transgenic background greatly accelerated the dorsal thoracic dissection. Immediately following eclosion (0 dpe), we observed prominent degradation of IFMs (Fig. 6c). For imaging, *Act88F:Rpr* was most effective at up to 3 dpe: after this stage, the abdominal gut often entered the thoracic cavity. *Act88F:Rpr* also increased the success of dissections: in one round of studies (*n* = 15 flies) 73% of animals produced behaviors, only 13% had limb movement deficiencies, and only 13% were incapacitated.

We next assessed the degree to which *Act88F:Rpr* might negatively impact tissues beyond the IFMs, including neurons and muscles. Due to the difficulty of identifying regions with
<figure><img src="image_7.png" /><figcaption>**Fig. 5** Neural activity of A1 neurons in the thoracic cervical connective during behavior. **a** Confocal image of *DNa01-Gal4* driver line expression in the brain and VNC. Scale bar is 40 µm. Neuronal GFP (yellow) and neuropil (nc82, blue) are labeled. A dashed white line highlights the thoracic x-z plane imaged. **b** Coronal section of the thoracic cervical connective in an animal expressing GCaMP6s (cyan) and tdTomato (red) in A1 neurons (*A1 > GCaMP6s; tdTomato*). Scale bar is 5 µm. **c** Separated ROIs (top-left) and associated fluorescence signals from right and left A1 neurons (top-right). Corresponding forward, sideways, and rotational velocities of the fly (bottom-right). Events are indicated as dashed red and orange lines for right and left A1 neuron events, respectively. **d, e** Summary of A1 neural activity and spherical treadmill rotations with respect to **d** left (1644 events) or **e** right (1651 events) A1 neuron fluorescence events aligned to 0 s (dashed gray line). Control data in which events are time-shuffled are overlaid in gray. Shown are the means (solid line) and bootstrapped 95% confidence intervals (transparencies)</figcaption></figure>

Rpr-driven cell death, we instead measured fluorescence in transgenic animals expressing GFP driven by the same promoter sequence (*Act88F:eGFP*)²⁹. We observed green fluorescence very rarely and at very low levels outside—but not within—the central nervous system (Supplementary Fig. 6). Unlike a previous report³¹, we also did not observe any fluorescence in the leg muscles of *Act88F:eGFP* animals (Supplementary Fig. 7). This difference may be due to the use of different insertion sites. These anatomical observations were further supported by behavioral responses to antennal infrared laser stimulation: *Act88F:Rpr* (*Act88F:Rpr*; UAS-GCaMP6s-p2A-*tdTomato*; GMR57C10-*GAL4*) and control (+; UAS-GCaMP6s-p2A-*tdTomato*; GMR57C10-*GAL4*) animals exhibited qualitatively indistinguishable walking behaviors at 7 dpe. However, we did observe very small, quantitative differences in walking speed near the end of the stimulation pulse (Supplementary Fig. 8, *n* = 15 *Act88F:Rpr* animals and *n* = 15 control animals; *n* = 10 responses per animal; *P* < 0.001 Friedman test, then *P* < 0.05 Mann–Whitney *U*-test with Holm-Bonferroni correction). Finally, we recorded neural activity in *Act88F:Rpr* flies and observed no qualitative differences between these animals (*Act88F:Rpr*; *elav-GAL4*/+; UAS-GCaMP6s/+*) and their control counterparts (*elav-GAL4*/+; UAS-GCaMP6s/+*) (Supplementary Movie 14).

## Discussion

Several additional modifications might increase the power of our VNC imaging approach. First, we used coronal section imaging to record from sparse sets of descending and ascending neurons. This strategy was chosen to overcome movement issues observed during horizontal section imaging (Supplementary Movie 15). Technologies for reducing axial resolution to achieve video-rate 2-photon imaging could be used to overcome this problem³². Second, we currently resect the gut to gain access to the VNC.

This intervention does not profoundly impact limb movements— we demonstrate robust locomotor behaviors across 40 minutes (Supplementary Movies 16–18)—but we predict that efforts to leave the gut intact will permit even longer recordings.

We have shown that we can record the activity of large VNC neural populations (Fig. 2), as well as sparse cell classes with known (Figs. 3 and 4), or unexplored functional properties (Fig. 5). Our findings have been confirmatory—MDN activity correlates with backward walking—as well as unexpected— dMAN activity correlates with limb pushdown behaviors. With fluorescence decay transients (*t*₁/₂) on the order of 1s¹⁹, we cannot currently establish whether these signals precede these behaviors. However, based on previous observations²⁵, MDNs and perhaps A1 descending neurons likely drive locomotor behaviors. By contrast, MAN activity may report behavioral sig- nals to higher-order decision-making centers in the brain. These first results suggest that our recording method, in conjunction with genetic behavioral screens²⁵,³³,³⁴, will become an indis- pensable tool for unraveling how signaling from the brain and neural dynamics within the VNC give rise to complex motor actions.

## Methods

**Drosophila lines.** Several lines (GMR57C10-*Gal4*, *elav-Gal4*, UAS-GCaMP6s, UAS-GCaMP6f, UAS-CD4:*tdGFP, and UAS-*tdTomato*) were obtained from the Bloomington Stock Center. MAN-*Gal4* (*VT50660-AD; VT14014-DBD*) and MDN-1-*Gal4* (*VT44845-DBD; VT50660-AD*) were provided by B. Dickson (Janelia Research Campus). *DNA01-*Gal4 (*SS00731; GMR22C05-AD; GMR56G08-DBD*), *DNb06-*Gal4 (*SS02631; GMR20C04-AD; BJD113E03-DBD*), *DNg13-*Gal4 (*SS02538; BJD118A10-AD; BJD123E03-DBD*), and *DNg16-*Gal4 (*SS01543; BJD104A07-AD; BJD107F12-DBD*) were provided by G. Rubin (Janelia Research Campus).

**Generation of Act88F:Rpr construct and flies.** *Actin88F:Rpr* strains (*Act88F:Rpr* flies) were generated using an *Actin88F:eGFP* construct²⁹. The *Act88F:GFP* line, which houses an *eGFP* construct driven by a 2053 bp region of the *actin88F*
<figure><img src="image_8.png" /><figcaption>**Fig. 6** Indirect flight muscle degradation in *Act88F:*Rpr animals. Confocal images of dorsal longitudinal IFMs (DLMs) stained with TRITC-Phalloidin at 1 dpe (left), 7 dpe (right), or whole-mount confocal micrographs of myofibrillar structure (middle) for **a** wild-type, or **b** *Act88F:*Rpr heterozygous flies. Scale bars are 5 µm. **c** IFM degradation over time in heterozygous *Act88F:*Rpr animals (*Act88F:*Rpr/elav-Gal4; UAS-GCaMP6s/+). IFMs are already absent at 1 dpe, revealing the underlying proventriculus (Pv). At 4 dpe and later, abdominal gut (Ab) invades the thoracic cavity</figcaption></figure>

promoter, was obtained from R. Benton (University of Lausanne). An *Act88F:*Rpr construct was generated by first using the following primer pair, to add a KpnI restriction site to the 5' end of a *rpr* cDNA clone (IP02530, *Drosophila* Genomics Resource Center, Bloomington, IN) and an XbaI site to the 3' end of the open reading frame, via a QuikChange Site-directed mutagenesis kit (Agilent Technologies):

Forward primer 5' AGACGGTACCATGGCAGTGGCATTC 3'

Reverse primer 5' GCCGCGTCTAGATCATTGCGATGGCTT 3'

The *Rpr* construct was then spliced into the *Act88F:*eGFP construct behind the *Act88F* promoter in place of the *eGFP* sequence. The *Act88F:*Rpr construct was injected into attp18 *Drosophila* embryos for PhiC31 integrase-mediated site-specific transgenesis³⁵ (transgene landing site cytotlocation 6C12) by BestGene Inc. (Chino Hills, CA). For some experiments, this transgene was combined with *UAS-GCaMP6s*-p2A-tdTomato (generated in the laboratory of M.H.D.).

**Fluorescence imaging of indirect flight muscles.** Fluorescent microscopy of hemi-thoraces was performed³⁶,³⁷. Briefly, flies were anesthetized and their heads and abdomens were then removed. Thoraces were fixed overnight in 4% paraformaldehyde at 4 °C and rinsed in 1× phosphate buffered saline (PBS) the following day. The specimens were arranged on a glass slide, snap frozen in liquid nitrogen and bisected down the midsagittal plane using a razor blade. IFMs were stained with Alexa-Fluor 568 Phalloidin (1:100 in PBS with 0.1% Triton-X (PBST)) overnight at 4 °C, rinsed with PBS and visualized using EVOS® FL Cell Imaging System (Life Technologies) at ×4 magnification. For whole-mount imaging of IFM myofibrils, flies were prepared and thoraces bisected as described above. Hemithoraces were stained with Alexa-Fluor 568 Phalloidin (1:100 in PBST) overnight at 4 °C. Samples were rinsed in PBS, mounted with Vectashield (Vector Laboratories)

and visualized using a Leica TCS SPE RGBV confocal microscope (Leica Microsystems) at 100x magnification.

**Immunofluorescence imaging of brains and ventral nerve cords.** Brains and VNCs were dissected out of 2–3 dpe female flies in PBS. Tissues were then fixed for 20 min in 4% paraformaldehyde in PBS at room temperature. After fixation, brains and VNCs were washed 2–3 times in PBS with 1% Triton-X-100 (PBST) for 10 min each and then incubated at 4 °C overnight in PBST. Samples were then placed in PBST with 5% normal goat serum (PBSTS) for 20 min at room temperature. They were then incubated with primary antibodies (rabbit anti-GFP at 1:500, Thermofisher RRID: AB_2536526; mouse anti-Bruchpilot/nc82 at 1:20, Developmental Studies Hybridoma Bank RRID: AB_2314866) diluted in PBSTS for 48 h at 4 °C. Brains and VNCs were rinsed 2–3 times in PBST for 10 min each before incubation with secondary antibodies (goat anti-rabbit secondary antibody conjugated with Alexa 488 at 1:500; Thermofisher; goat anti-mouse secondary antibody conjugated with Alexa 633 at 1:500; Thermofisher) diluted in PBSTS for 48 h at 4 °C. Finally, brains and VNCs were rinsed 2–3 times for 10 min each in PBST and mounted onto slides with bridge coverslips in Slowfade mounting-media (Thermofisher).

Samples were imaged using a Carl Zeiss LSM 700 Laser Scanning Confocal Microscope with the following settings: ×20 magnification, 8-bit dynamic range, 2× image averaging, 0.52 × 0.52 µm pixel size, 0.57 µm z-step interval. Standard deviation z-projections of imaging volumes were made using Fiji³⁸. To compare GFP expression in the central nervous system, laser intensity and PMT gains for the green channel were kept constant across wild-type, *A1 > GFP*, and *Act88F:*GFP samples.

**Imaging GFP expression in leg muscles.** Legs were manually dissected at the body-coxa joint and mounted onto glass slides using double-sided tape. Slowfade mounting-media (Thermofisher) was then added to the space between the cover slip and the slide. We then recorded GFP fluorescence in the green channel using an LSM 700 Laser Scanning Confocal Microscope (Zeiss). Laser intensity, PMT gains, and scanning parameters were kept constant across wild-type, *MHC > GFP* and *Act88F:*GFP animals: ×20 magnification, 8-bit dynamic range, ×8 image averaging, 0.63 × 0.63 µm pixel size, and 10 µm z-step interval. Cuticular autofluorescence was also recorded in the red channel.

**Thoracic dissection for VNC imaging.** Custom holders used to mount flies during imaging were fabricated as described previously³⁹. For VNC imaging, these stages were modified to have (i) flat rather than folded steel shims, and (ii) chamfered vertices to make the spherical treadmill visible to optic flow sensors (Shapeways, 'file'). Steel shims were fabricated from 0.001" Stainless Steel, type 316 soft annealed (McMaster-Carr, part #2317K11). Shims were etched (Etchit, Buffalo, MN) to generate rectangular holes as explained 'here'. The shim design file can be found 'here'.

All experiments were performed on 1–3 dpe female flies raised at 25 °C on standard cornmeal food on a 12 h light:12 h dark cycle. Flies were anesthetized at 4 °C. A female fly was selected and, in some cases, its wings were clipped to simplify the mounting process. The fly's dorsal thorax was then pushed through a hole in the steel shim of the imaging stage. The stage was then flipped over, UV-curing glue (Bondic, Aurora, ON Canada) was carefully applied around the perimeter of the thorax and cured by UV illumination (LED-200, Electro-Lite Co. Bethel, CT USA). UV glue was then used to fix the head and abdomen to the underside of the stage. The stage was then filled with extracellular saline¹⁸. Under a high-magnification dissection microscope (Leica M165C), a hypodermic needle (30 G, BD PrecisionGlide, Franklin Lakes, NJ USA) was used to slice and lift the cuticle off the dorsal thorax⁴⁰, being careful not to sever the neck connective. Subsequently, in non-*Act88F:*Rpr animals, a pair of dull forceps was used to remove IFMs, predominantly from the anterior-medial region of the thorax overlying the gut (this step is unnecessary in *Act88F:*Rpr animals). This process exposes the dorsal surface of the proventriculus—a large bulbous gut structure. With great care, a pair of super-fine forceps was then used to grasp and lift the proventriculus to displace much of the gut (including the crop and salivary glands) from the more ventrally located nervous tissue. With the gut thus elevated, ultra-fine clipper scissors (Fine Science Tools, Foster City, CA USA) were used to transact it at its anterior-most section. The proventriculus was then peeled back and a posterior incision was made to completely remove these portions of the gut, revealing the underlying nervous tissue. Notably, this dissection also removes the aorta, restricting hemolymph flow from the abdominal dorsal vessel. Nevertheless, we found that flies were viable and behaved for up to 4 h. In some cases, we observed that gut or muscle tissue would begin to obscure the VNC during imaging. Therefore, loose tissue should be removed at this stage while taking great care not to sever the VNC. After each dissection, we examined the extent to which the animal moved its legs in response to a puff of air or grabbed an object with each of its legs. This proved to be an accurate predictor of the success of the preparation. To evaluate the quality of a dissection, we examined the movements of each leg on the spherical treadmill. If a fly could walk in a coordinated manner, the dissection was considered successful. Otherwise, the animal was categorized as having a limb movement deficiency. Animals with multiple dysfunctional legs were categorized as incapacitated.
**2-photon microscopy during behavior.** Experiments were performed in the evening Zeitgeber time (Z.T.) and animals were typically imaged 30–60 min following dissection. Fly holders were secured to a raised platform over the spherical treadmill (Supplementary Fig. 3a). The VNC was then located using microscope oculars and positioned in the center of the field-of-view by 2-photon imaging.

The spherical treadmill is an aluminum rod with a ball-shaped hole milled at one end<sup>22</sup>. We fabricated 10 mm diameter foam balls (Last-A-Foam FR-7106, General Plastics, Burlington Way, WA USA) and manually spotted them using a Rapidograph pen (Koh-I-Noor, Leeds, MA USA) to provide high-contrast features for optic flow measurements. A 500–600 mL min<sup>-1</sup> stream of filtered and humidified air was passed through the holder using a digital flow controller (Sierra Instruments, Monterey, CA USA). Movements of the ball were measured using two optical flow sensors (ADNS3080) outfitted with zoom lenses (Computar MLM3X-MP, Cary, NC USA). The ball and fly were illuminated using a pair of IR LEDs (850-nm peak wavelength) coupled to optic fibers and collimator lenses (ThorLabs, Newton, NJ USA). Optic flow measurements were passed to a microcontroller board (Arduino Mega2560) to be recorded using custom Python code. Simultaneously, video recordings of animals behaving on the ball were made using an IR-sensitive firewire camera (Basler, Ahrensburg, Germany) at approximately 30 fps.

We performed 2-photon microscopy using a Bergamo II microscope (ThorLabs) outfitted with two GaAsP PMT detectors for GCaMP6 and tdTomato imaging and coupled to a Ti:Sapphire laser (MaiTai DeepSee, Newport Spectra-Physics, Santa Clara, CA USA) tuned to 930 nm. We used an Olympus 20× water-m immersion objective lens with 1.0 NA (Olympus, Center Valley, PA USA). The microscope was controlled using ThorImage software (ThorLabs). Coronal section imaging experiments were performed in Galvo-Galvo imaging mode at 6–9 Hz. This framerate varied with image size which ranged between 26.58 × 26.58 µm and 53.15 × 53.15 µm. Laser power ranged between 3 mW and 5.7 mW. Volumetric imaging is also possible with appropriate hardware (e.g., Galvo-Resonance scanner and Piezo-driven objective collar).

Occasionally, a puff of air was used to elicit walking behaviors. These puffs were digitally encoded (Honeywell AWM 3300 V, Morris Plains, NJ USA). Custom ROS software interfaced through an analog output device (Phidgets, Calgary, Canada) to ThorSync software (ThorLabs) was used to synchronize optic flow measurements, behavior videography, air puff measurements, and 2-photon image acquisition. For coronal section imaging, a Piezo collar (Physik Instrumente, Karlsruhe, Germany) was used to control rapid z-axis movements of the microscope objective lens.

To compare neural activity between control and Act88F:Rpr animals, we acquired 512 × 512 pixel images at 1.7 fps using a constant laser intensity and PMT gain. Selected imaging regions were empirically chosen as horizontal sections consisting of landmarks observed at ~61–65 µm depth in Supplementary Movie 1.

**Comparing walking with or without dissection.** To evaluate the effects of dissection on locomotion, wild-type animals were subjected to the following procedure. Animals were mounted onto imaging stages and saline was added to each stage. Only a random subset of animals was dissected. Each mounted fly was then placed onto the spherical treadmill and its walking behaviors were recorded for 30 min. Optic flow was recorded as described above. To increase the likelihood of locomotion, a 500 ms pulse of 100% CO₂ was directed at the fly’s antennae with a one min inter-pulse interval (0.05 lₙ min<sup>-1</sup> using a mass flow controller; Vögtlin Instruments, Switzerland).

**Infrared laser antennal stimulation.** To compare walking behaviors between Act88F:Rpr and control animals, we stimulated their antennae with an 830 nm near infrared laser (Schäfter + Kirchhoff, Germany). We first anesthetized 7–8 dpe female animals at 4 °C and mounted them on imaging stages. Flies were then acclimated for 10 min. For each experiment, an animal received ten 2 s laser stimulation pulses (18.1 mW) to its right antenna at a 60 s inter-pulse interval. Control and Act88F:Rpr animals were tested in alternation to minimize the effects of circadian time on behavioral comparisons.

**Statistics.** Sample sizes for animal experiments were chosen as follows: we performed at least three experiments to illustrate population and sparse neural recordings and performed more than ten experiments per group when performing statistical comparisons. A pre-established criteria of low signal-to-noise fluorescence signals resulted in the removal of two MDN experiments from our dataset. No randomization or blinding was used. For antennal laser stimulation, data were not normally distributed, thus Friedman and Mann–Whitney U-tests were performed. Estimates of variation are presented as mean and bootstrapped 95% confidence intervals.

**Data analysis.** We analyzed all data using custom Python scripts. Because the data acquisition frequency differed for optic flow, behavior videography, and 2-photon imaging we interpolated signals to match those of the highest frequency. Subsequently, optic flow data were smoothed using a running average (window = 200 ms) and then translated into rotations s<sup>-1</sup> for anterior-posterior, medial-lateral, and yaw axes<sup>22</sup>. To make these measurements more intuitive, rotations s<sup>-1</sup> were then converted into mm s<sup>-1</sup> (1 rot s<sup>-1</sup> = 31.42 mm s<sup>-1</sup>) for anterior-posterior (v<sub>forward</sub>) and

medial-lateral (v<sub>side</sub>) movements and into degrees s<sup>-1</sup> (1 rot s<sup>-1</sup> = 360° s<sup>-1</sup>) for yaw (v<sub>rotation</sub>) movements<sup>22</sup>.

The analysis of locomotion in dissected animals (Supplementary Fig. 2) was performed as follows. V<sub>forward</sub> optic flow data for 20 dissected and 20 non-dissected flies were downsampled to 1500 points s<sup>-1</sup> and smoothed using a running average of duration 0.2 s. To compute the percentage of time walking forward/backward, or walking sideways two thresholds, −0.31 mm s<sup>-1</sup> and +0.31 mm s<sup>-1</sup>, were empirically defined to differentiate between standing still and forward (rightward) or backward (leftward) walking, respectively. Values above 0.31 mm s<sup>-1</sup> were considered moments of forward (rightward) walking and values below −0.31 mm s<sup>-1</sup> were considered moments of backward (leftward) walking. Optic flow values between these thresholds were considered moments of standing still. The percentage of time walking was calculated as the proportion of data points in which an animal was not considered standing still. Similarly, thresholds of 10.8 and −10.8 degree s<sup>-1</sup> were used to defined moments of turning. A bout was defined as a continuous period of walking or turning.

Large tissue deformations could occur during behavior. Therefore, we performed post-hoc pan-neuronal image registration (Fig. 2). We registered all frames of an imaging experiment to one reference image. Because the complexity of deformations could not be captured using simple parametric motion models (e.g., affine transformations), we used a non-parametric, variational approach, designed to model arbitrarily complex deformations. We computed the motion field w between the reference image, denoted I<sub>r</sub>, and the image at time t, denoted I<sub>t</sub>, by solving the minimization problem

$$ \hat{\mathbf{w}} = \arg \min_{\mathbf{w}} D(\mathbf{w}) + \lambda \sum_{\mathbf{x} \in \Omega} \|\nabla \mathbf{w}(\mathbf{x})\|_2^2, \quad (1) $$

where D(w) is a data fitting term, the second term is a regularization promoting smoothness of w by penalizing its gradient Vw<sup>41</sup>, Ω is the discrete image domain, and the parameter λ balances the contributions of the two terms.

GCaMP6s images present a challenge for motion estimation because neural activity produces large local intensity changes. Therefore, we used an additional activity independent fluorophore, tdTomato, and defined a data term of the form

$$ D(\mathbf{w}) = \rho(\mathbf{w}, I_r, I_t) + \gamma \phi(\mathbf{w}, I_r, I_t). \quad (2) $$

The first term models the standard assumption of conservation of intensity along the trajectory of each pixel. It is defined by

$$ \rho(\mathbf{w}, I_r, I_t) = \sum_{\mathbf{x} \in \Omega} |I_r(\mathbf{x}) + \mathbf{w}(\mathbf{x})) - I_t(\mathbf{x})|, \quad (3) $$

where we use an l₁ norm to gain partial robustness to intensity changes<sup>42</sup>. The second term in Eq. (2) is a feature matching constraint inspired by Revaud and co-workers<sup>43</sup>, written as

$$ \phi(\mathbf{w}, I_r, I_t) = \sum_{\mathbf{x} \in \Omega} \|\mathbf{w}(\mathbf{x}) - \mathbf{m}(\mathbf{x}, I_r, I_t)\|_1. \quad (4) $$

In Eqs. (2)–(4), I<sub>r</sub> and I<sub>t</sub> are from the tdTomato channel. Minimizing the function φ favors motion vectors w(x) to be close to feature correspondences m(x, I<sub>r</sub>, I<sub>t</sub>), computed on a sparse set of relevant keypoints. We obtain m with the feature matching algorithm proposed by Revaud and co-workers<sup>43</sup>, which is specifically designed to handle large image deformations. We compute m using the tdTomato imaging channel, such that the correspondences are also insensitive to the intensity changes between I<sub>r</sub> and I<sub>t</sub>. As a result, the estimation is guided by reliable feature matches. The parameter γ balances the two terms in Eq. (2).

For each experiment, we optimized the values for λ and γ using a grid search to register horizontal section images of the VNC (Supplementary Fig. 4). As an objective function for optimization, we used the gradient of the temporal mean image<sup>44</sup>. Small values of λ (i.e., λ < 1000), occasionally led to artifacts in the registered images. These artifacts were associated with strong convergence in the vector field w(x) (Supplementary Fig. 4c). Therefore, we empirically defined artifacts as clusters of pixels with div w(x) < −1.2 and cardinality >20 (we obtained similar results with cardinality >5). Finally, we selected λ and γ values as those with no artifacts and the highest gradient of the mean image. Sample unregistered images, transformation vector fields, and registered images of the three optimized examples are shown in Supplementary Movie 5.

We solved the optimization problem in Eq. (1) with an alternated direction method of multiplier (ADMM) algorithm<sup>45</sup>. We introduced two splitting variables, associated with the regularization and the feature matching terms, respectively. Each sub-problem of the algorithm was solved analytically. We used parts of the inverse problems library described in ref. 46. A post processing based on weighted median filtering was applied using the method from<sup>47</sup>.

In Fig. 2, behaviors were semi-automatically annotated, using a custom Python module. This module allows the user to select two regions-of-interest (ROIs) on the video’s first frame. The first ROI is used to detect walking and must be positioned over the metathoracic and mesothoracic legs. The second ROI is responsible for detecting prothoracic leg grooming and must be positioned in front of the fly. To
detect motion in those regions, consecutive frames are subtracted. Resulting differential images are then median blurred (radius = 5 pixels), to reduce noise. Based on this blurred image, a threshold on the number of non-zeros pixels in each of the two ROIs is applied to extract binary sequences of grooming and walking bouts. Note that prothoric leg movements observed during walking are ignored (i.e., grooming classification is subservient to walking classification). A hysteresis filter was then applied to low-pass filter binary behavioral sequences and to remove transitions that occur over too few frames to be biologically plausible. Example ROIs and behavioral annotations are illustrated in Supplementary Movie 6. This behavior data was used in Fig. 2 as shown in Supplementary Movie 2. It was annotated using the following parameters: threshold for walking = 400, threshold for grooming = 5, hysteresis length for walking = 8, hysteresis length for grooming = 10.

For Fig. 2b, c, we used linear regression to find regions in the VNC associated with either walking or grooming. Regressors $X_w$ and $X_g$ (for walking and grooming, respectively) were constructed from the two behavioral sequences, $S_w$ and $S_g$ using Eq. (5) by convolution with an exponentially decaying Calcium signal Impulse Response (CIR) derived from the time constant measured for GCaMP6s ($t_{v5} = 1.1448$ s)$^{19}$.

$$ 
\begin{aligned}
X_w &= S_w \otimes \text{CIR} \\
X_g &= S_g \otimes \text{CIR}
\end{aligned}
\qquad (5) $$

Target functions were pixel-wise $\Delta F/F$ traces, where $\Delta F = F_t - F$. $F_t$ is the fluorescence at time, $t$. $F$ is a baseline fluorescence signal measured as the average pixel value for the first ten sequential GCaMP6s images in which no cellular activity was observed (i.e., minimal and unchanging GCaMP6s fluorescence).

The regressor weights were calculated using Eq. (6).

$$ 
\begin{aligned}
w_w &= (X_w^T X_w)^{-1} X_w^T y \\
w_g &= (X_g^T X_g)^{-1} X_g^T y,
\end{aligned}
\qquad (6) $$

where $y$ is the pixel-wise $\Delta F/F$ trace.

Figure 2b, c shows heat maps of the regressor weights, $w_w$ for walking and $w_g$ for grooming, normalized to their respective maxima. ROI 1 was chosen as a region of the heat map with a high weight for grooming but a low weight for walking. ROI 2 was chosen as the spatial location with the highest value of $w_w$. Each ROI encompasses a region with a 15 pixel radius.

To identify process sparse neural imaging data (Figs. 3–5), ROIs were first selected using custom Python scripts that depended on OpenCV and Numpy libraries. To do this, a reference frame was selected for which the software identified all potential ROIs. To do this, the GCaMP6s image was smoothed to reduce background noise and then an Otsu filter threshold was applied to the image. An erosion factor was then applied on all objects detected within the image. Contours of all detected objects were then presented to the user for manual selection. Once these reference ROIs were selected for left and right neurons, we used a cross-correlation-based image registration algorithm$^{48}$ to identify the most likely left and right ROIs for each image frame based on those manually selected on the reference frame. A second script was used to manually verify automatically selected ROIs and, if incorrect, to display all potential ROIs within the frame for manual selection. If erosion values yielded malformed ROIs, another script was used to manually position elliptical ROIs of arbitrary orientation on any given frame. Finally, binary ROI images were used as an image mask to extract mean fluorescence signals from the original GCaMP6s or tdTomato images. These signals were reported as $\%\Delta R/R$ as in ref. 49 to reduce the effects of motion on our measurements. Due to the absence of stimuli, the baseline $R$ was calculated as the minimum ratio of GCaMP6s/tdTomato within a 2.5 s bin.

To detect transient increases in activity, we developed an algorithm based partly on ref. 50. We first determined when the first derivative of the $\%\Delta R/R$ signal crossed a threshold, which was determined by examining all derivative values for a given neuron class (MDN, MAN, or A1). We reasoned that threshold values should be characteristic and potentially different for each type of neuron because fluorescence dynamics are related to intrinsic physiological properties that can differ across neuron classes but not across experiments for a single class. We set this threshold as the 97.5th percentile for MDNs and dMANs and the 90th percentile for A1 neurons. A lower threshold value was selected for A1 neurons because many more fluorescence transients were observed in A1 traces. These transients would have been overlooked using a 97.5th percentile threshold. To identify the onset of fluorescence increases we found the nearest preceding time point where the derivative crossed zero. This zero-crossing is considered the time-point of an 'event' associated with the identified fluorescence increase. Events detected close to one another with no intervening derivative zero-crossing were compressed into one event associated with the first time-point. There were ~10 separate experiments per animal. Events in the first and last 10 s of each experiment were not considered since the data presentation window encompassed 10 s before and 10 s after each event.

Because left and right MDN and dMAN activities strongly covaried (Supplementary Fig. 5), an additional step was performed for event detection: if events were detected in both left and right neurons within 2 s of one another, both

events were retained; otherwise, an event identified for neuron A (e.g., left MDN) and not neuron B (e.g., right MDN) was also added to neuron B's event library.

By contrast, left and right A1 activities did not strongly covary. Therefore, events were associated with one and not the other neuron. To accomplish this, if an event was detected for both left and right A1 neurons within a time window of 0.25 s, neither of the events were used for analysis.

$\%\Delta R/R$ and optic flow traces linked to each event were aligned by setting the event time points to 0 s. We then computed the mean and bootstrapped 95% confidence intervals for these aligned traces using the Python Seaborn library. Optic flow and $\%\Delta R/R$ measurements were downsampled to 500 values $s^{-1}$ for this analysis. To increase clarity, $\%\Delta R/R$ traces were baseline-subtracted to make them zero at the time of the event in the summary panels (Figs. 3d, 4d and 5d, e). Control, shuffled data (gray traces) were computed by instead assigning random time-points in place of real, identified events. These random time points were treated as real events and their mean and bootstrapped 95% confidence intervals were computed and plotted for comparison.

Covariance analysis (Supplementary Fig. 5) was performed using a custom Python script that depended on the Matplotlib and Numpy libraries. Scatter plots were computed to compare left and right neuron $\%\Delta R/R$ values from all experiments for each fly separately. Pearson's $r$ values are reported as mean ± standard deviation.

Event-related behaviors (Supplementary Movies 8, 10, 12 and 13) were manually selected from automatically detected events as described above. For dMANs, events were selected from among those that maximized the difference in anterior-posterior ball rotations between 1 s before and 2 s after the event. For MDNs, events were selected from among those that minimized anterior-posterior ball rotations up to 2 s after the event. For A1 neurons, events were selected from among those that maximized the average yaw ball rotations (positive for left A1 neuron examples and negative for right A1 neuron examples) for up to 2 s after the events.

In Supplementary Fig. 8, responses to near-infrared laser stimulation were averaged across 10 trials for each animal. Optic flow was downsampled to 500 values $s^{-1}$. Mean and 95% bootstrapped confidence intervals for optic flow traces were measured and plotted using the Python Seaborn library. The Python Scipy library was used to perform Friedman and Mann-Whitney U-tests.

## Data availability

The source data used for the analyses in this study are available on the Harvard Dataverse on a 'public repository'. Analysis code and sample datasets can be found 'here'.

Received: 13 March 2018 Accepted: 2 October 2018

Published online: 22 October 2018

## References

1. Bidaye, S. S., Bockemühl, T. & Büschges, A. Six-legged walking in insects: how CPGs, peripheral feedback, and descending signals generate coordinated and adaptive motor rhythms. *J. Neurophysiol.* **119**, 459–475 (2018).

2. Court, R. C. et al. A systematic nomenclature for the *Drosophila* ventral nervous system. Preprint at https://www.biorxiv.org/content/early/2017/04/ 26/122952.

3. Namiki, S., Dickinson, M. H., Wong, A. M., Korff, W. & Card, G. M. The functional organization of descending sensory-motor pathways in *Drosophila*. *eLife* 7, e34272 (2018).

4. Tsubouchi, A. et al. Topological and modality-specific representation of somatosensory information in the fly brain. *Science* **358**, 615–623 (2017).

5. Wosnitza, A., Bockemühl, T., Dübbert, M., Scholz, H. & Büschges, A. Inter-leg coordination in the control of walking speed in *Drosophila*. *J. Exp. Biol.* **216**, 480–491 (2013).

6. Mendes, C. S., Bartos, I., Akay, T., Márka, S. & Mann, R. S. Quantification of gait parameters in freely walking wild type and sensory deprived *Drosophila melanogaster*. *eLife* 2, e00231 (2013).

7. Niven, J. E. Visuomotor control: *Drosophila* bridges the gap. *Curr. Biol.* **20**, R309–R311 (2010).

8. Card, G. M. & Dickinson, M. H. Visually mediated motor planning in the escape response of *Drosophila*. *Curr. Biol.* **18**, 1300–1307 (2008).

9. Pavlov, H. J. & Goodwin, S. F. Courtship behavior in *Drosophila melanogaster*: towards a 'courtship connectome'. *Curr. Opin. Neurobiol.* **23**, 76–83 (2013).

10. Zwarts, L., Versteven, M. & Callaerts, P. Genetics and neurobiology of aggression in *Drosophila*. *Fly* **6**, 35–48 (2012).

11. Seeds, A. M. et al. A suppression hierarchy among competing motor programs drives sequential grooming in *Drosophila*. *eLife* 3, e02951 (2014).

12. Mann, K. J., Gordon, M. D. & Scott, K. A pair of interneurons influences the choice between feeding and locomotion in *Drosophila*. *Neuron* **79**, 754–765 (2013).
13. Trimarchi, J. R. & Murphey, R. K. The shaking-B-2 mutation disrupts electrical synapses in a flight circuit in adult *Drosophila*. *J. Neurosci.* **17**, 4700–4710 (1997).

14. Ikeda, K. & Kaplan, W. D. Neurophysiological Genetics in *Drosophila melanogaster*. *Am. Zool.* **14**, 1055–1066 (1974).

15. Tuthill, J. C. & Wilson, R. I. Parallel Transformation of Tactile Signals in Central Circuits of *Drosophila*. *Cell* **164**, 1046–1059 (2016).

16. Hedwig, B. & Burrows, M. Presynaptic inhibition of sensory neurons during kicking movements in the locust. *J. Neurophysiol.* **75**, 1221–1232 (1996).

17. Bässler, U. & Büschges, A. Pattern generation for stick insect walking movements—multisensory control of a locomotor program. *Brain. Res. Rev.* **27**, 65–88 (1998).

18. Maimon, G., Straw, A. D. & Dickinson, M. H. Active flight increases the gain of visual motion processing in *Drosophila*. *Nat. Neurosci.* **13**, 393–399 (2010).

19. Chen, T.-W. et al. Ultrasensitive fluorescent proteins for imaging neuronal activity. *Nature* **499**, 295–300 (2013).

20. Shaner, N. et al. Improved monomeric red, orange and yellow fluorescent proteins derived from *Discosoma* sp. red fluorescent protein. *Nat. Biotechnol.* **22**, 1567–1572 (2004).

21. Jenett, A. et al. A GAL4-Driver Line Resource for *Drosophila* Neurobiology. *Cell Rep.* **2**, 991–1001 (2012).

22. Seelig, J. D. et al. Two-photon calcium imaging from head-fixed *Drosophila* during optomotor walking behavior. *Nat. Methods* **7**, 535–540 (2010).

23. Hedwig, B. & Poulet, J. Complex auditory behaviour emerges from simple reactive steering. *Nature* **430**, 781–785 (2004).

24. Enriquez, J. et al. Specification of Individual Adult Motor Neuron Morphologies by Combinatorial Transcription Factor Codes. *Neuron* **86**, 955–970 (2015).

25. Bidaye, S. S., Machacek, C., Wu, Y. & Dickson, B. J. Neuronal control of *Drosophila* walking direction. *Science* **344**, 97–101 (2014).

26. Sen, R. et al. Moonwalker descending neurons mediate visually evoked retreat in *Drosophila*. *Curr. Biol.* **27**, 766–771 (2017).

27. Luan, H., Peabody, N. C., Vinson, C. R. & White, B. H. Refined spatial manipulation of neuronal function by combinatorial restriction of transgene expression. *Neuron* **52**, 425–436 (2006).

28. White, K. et al. Genetic control of programmed cell death in *Drosophila*. *Science* **264**, 677–683 (1994).

29. Ramdya, P., Schaffter, T., Floreano, D. & Benton, R. Fluorescence Behavioral Imaging (FBI) tracks identity in heterogeneous groups of *Drosophila*. *PLoS One* **7**, e48381 (2012).

30. Reedy, M. C., Bullard, B. & Vigoreaux, J. O. Flightin is essential for thick filament assembly and sarcomere stability in *Drosophila* flight muscles. *J. Cell Biol.* **151**, 1483–1499 (2000).

31. Nongthomba, U., Pasalodos-Sanchez, S., Clark, S., Clayton, J. D. & Sparrow, J. C. Expression and function of the *Drosophila* ACT88F actin isoform is not restricted to the indirect flight muscles. *J. Muscle Res. Cell Motil.* **22**, 111–119 (2001).

32. Lu, R. et al. Video-rate volumetric functional imaging of the brain at synaptic resolution. *Nat. Neurosci.* **20**, 620–628 (2017).

33. Robie, A. A. et al. Mapping the neural substrates of behavior. *Cell* **170**, 393–406 (2017).

34. Harris, R. M., Pfeiffer, B. D., Rubin, G. M. & Truman, J. W. Neuron hemilineages provide the functional ground plan for the *Drosophila* ventral nervous system. *eLife* **4**, e04493 (2015).

35. Markstein, M., Mitsouli, C., Villalta, C., Celniker, S. E. & Perrimon, N. Exploiting position effects and the gypsy retrovirus insulator to engineer precisely expressed transgenes. *Nat. Genet.* **40**, 476–483 (2008).

36. Nongthomba, U. & Ramachandra, N. B. A direct screen identifies new flight muscle mutants on the *Drosophila* second chromosome. *Genetics* **153**, 261–274 (1999).

37. Viswanathan, M. C., Blice-Baum, A. C., Schmidt, W., Foster, D. B. & Cammarato, A. Pseudo-acetylation of K326 and K328 of actin disrupts *Drosophila melanogaster* indirect flight muscle structure and performance. *Front. Physiol.* **6**, 116 (2015).

38. Schindelin, J. et al. Fiji: An open-source platform for biological-image analysis. *Nat. Methods* **9**, 676–682 (2012).

39. Weir, P. T. et al. Anatomical Reconstruction and Functional Imaging Reveal an Ordered Array of Skylight Polarization Detectors in *Drosophila*. *J. Neurosci.* **36**, 5397–5404 (2016).

40. Fayyazuddin, A. & Dickinson, M. H. Haltere afferents provide direct, electrotonic input to a steering motor neuron in the blowfly. *Calliphora*. *J. Neurosci.* **16**, 5225–5232 (1996).

41. Horn, B. & Schunck, B. G. Determining optical-flow. *Artif. Intell.* **17**, 185–203 (1981).

42. Brox, T., Bruhn, A., Papenberg, N. & Weickert, J. High accuracy optical flow estimation based on a theory for warping. *Comput. Vision* **2034**, 25–36 (2004).

43. Revaud, J., Weinzaepfel, P., Harchaoui, Z. & Schmid, C. DeepMatching: hierarchical deformable dense matching. *Int. J. Comput. Vision* **120**, 300–323 (2016).

44. Pneumatikakis, E. A. & Giovannucci, A. NoRMCorre: an online algorithm for piecewise rigid motion correction of calcium imaging data. *J. Neurosci.* Methods **291**, 83–94 (2017).

45. Boyd, S., Parikh, N., Chu, E., Peleato, B. & Eckstein, J. Distributed optimization and statistical learning via the alternating direction method of multipliers. *Found. Trends Mach. Learn.* **3**, 1–122 (2010).

46. Unser, M., Soubies, E., Soulez, F., McCann, M. & Donati, L. GlobalBioIm: a unifying computational framework for solving inverse problems. In: *Proceedings of the OSA Imaging and Applied Optics Congress on Computational Optical Sensing and Imaging (COSI'17)*, San Francisco CA, USA, June 26–29, paper CTu1B (2017).

47. Sun, D., Roth, S. & Black, M. J. A quantitative analysis of current practices in optical flow estimation and the principles behind them. *Int. J. Comput. Vision.* **106**, 115–137 (2014).

48. Guizar-Sicairos, M., Thurman, S. T. & Fienup, J. R. Efficient pixel image registration algorithms. *Opt. Lett.* **33**, 156–158 (2008).

49. Weir, P. T. & Dickinson, M. H. Functional divisions for visual processing in the central brain of flying. *Drosoph. Proc. Natl Acad. Sci. USA* **112**, E5523–E5532 (2015).

50. Ikegaya, Y. et al. Synfire chains and cortical songs: temporal modules of cortical activity. *Science* **304**, 559–564 (2004).

## Acknowledgements

We thank B.J. Dickson (Janelia Research Campus, VA) for MDN-1-Gal4 and MAN-Gal4 fly strains. We thank G. Rubin (Janelia Research Campus, VA) for DNA01-Gal4, DNb06-Gal4, DNg13-Gal4, and DNg16-Gal4 fly strains. A.C. acknowledges support from the National Institutes of Health (R01HL124091). M.H.D. acknowledges support from the National Institute of Neurological Disorders and Stroke of the National Institutes of Health (U01NS090514). P.R. acknowledges support from the Swiss National Science Foundation (31003A_175667).

## Author contributions

C.L.C. generated strains; performed experiments; analyzed data, L.H. performed experiments; analyzed data, M.C.V. generated strains; performed experiments; analyzed data, D.F. designed and implemented the motion-compensation algorithm F.A. analyzed data, M.U. designed the motion-compensation algorithm, A.C. designed and supervised the project, M.H.D. designed and supervised the project, P.R. conceived of, designed, and supervised the project; performed experiments; analyzed data, All authors contributed to writing the paper.

## Additional information

Supplementary Information accompanies this paper at https://doi.org/10.1038/s41467-018-06857-z.

**Competing interests:** The authors declare no competing interests.

**Reprints and permission** information is available online at http://npg.nature.com/reprintsandpermissions/

**Publisher's note:** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

<figure><img src="image_9.png" /></figure>

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

© The Author(s) 2018