Fly stocks and husbandry

Flies were housed at 25 °C and 50–65% relative humidity on a 12 h light/12 h dark cycle, except for animals used in optogenetics experiments, which were reared in darkness. Stocks used for behavioural experiments were reared on standard molasses food, 2P imaging lines were reared on Würzburg food for at least five generations to increase animal robustness, and flies expressing optogenetic actuators were kept on sugar-yeast food to prevent intake of the cofactor retinal. Fly stocks used were as follows: D. melanogaster stocks 71G01-Gal4 (39599) and UAS-GCaMP6s (42746) were obtained from Bloomington Stock Center. Canton-S (G. Maimon, Rockefeller University), CO4n and RG11n (J. Pool, University of Wisconsin-Madison), UAS-CsChrimson (V. Jayaraman, Janelia Research Campus) and VT029314 (LC10a)-LexA, LexAop-GCaMP6s (I. Ribeiro and B. Dickson, Janelia Research Campus) were generously shared by the indicated colleagues. Wild-type D. erecta (14021-0224.01), w− D. erecta (14021-0224.07) and D. yakuba (14021-0261.00) were obtained from the Cornell Stock Center. Ruta lab D. simulans, D. orena (D. Stern, Janelia Research Campus), D. erecta 71G01-Gal4, UAS-GCaMP6s, UAS-CsChrimson, ppk23-mutant and D. erecta as well as D. yakuba Dsx-Gal4 (Y. Ding, University of Pennsylvania) were previously generated36 or shared by the indicated colleagues. D. erecta VT029314 (LC10a)-Gal4, Fru-Gal4, Orco-Gal4 (for labelling, see Extended Data Fig. 10), ∆Orco and ∆Ir8a were generated in this study. The 71G01-Gal4 driver labels a subset of approximately 1052 out of 78 highly interconnected P1 neurons described in D. melanogaster34 and a similar number of neurons in D. erecta36.

Transgene generation

Vector backbone pRC12B36 with ie1.mCherry minigene reporter was used to clone the synthesized VT029314 enhancer fragment gBlock (IDT) upstream of Gal4 by means of Gibson assembly (NEB). The construct was co-injected with hyTsps mRNA into embryos for transposase-mediated genome integration. Chemosensory coreceptor knockouts were generated by targeted excision of the first three exons (Orco) or the entire coding region (Ir8a) using CRISPR–Cas9-mediated homology-directed repair inserting a fluorescent marker gene cassette encoding mCherry under the viral ie1 promoter (Orco) or RFP under control of D. melanogaster 3xP3 (Ir8a). The Orco-Gal4 line in D. erecta was generated by cloning 5,496 bp upstream of the Orco translation start site upstream of the Gal4 sequence into the pCaSpeR backbone and a gateway cassette (pCaSpeR-DEST3 (DGRC, 1029; Research Resource Identifier: DGRC_1029)). The Fru-Gal4 line was generated by first establishing an attP landing site in the D. erecta fruitless locus and subsequently inserting a splice acceptor-Gal4 element. The landing site was created using CRISPR–Cas9-mediated cleavage to the intron 5′ of the exon containing the ATG start codon (as previously described)53 with homology-directed repair inserting the attP sequence. The resulting validated fruattP line was used as a target for site-specific integration of a splice acceptor-Gal4 element, which contained an ie1.mCherry transformation marker.

All transgenic lines in D. erecta were made in a wild-type genetic background except the Orco-Gal4 line, which was constructed in a w− background. For experiments, all constructs were crossed into a wild-type (w+) background to exclude potential behavioural effects of the w− mutation.

Immunohistochemistry

Adult brains were dissected in Schneider’s media (Sigma) and immediately transferred to cold 1% paraformaldehyde (Electron Microscopy Sciences) for overnight fixation at 4 °C. Samples were then washed three times in PAT3 buffer (0.5% bovine serum albumin, 0.5% Triton, phosphate-buffered saline pH 7.4). Brains were blocked in 3% Normal Goat Serum for 90 min at room temperature and incubated in primary antibodies (1:1,000 chicken anti-GFP (Abcam, ab13970), 1:50 mouse anti-brp (Developmental Studies Hybridoma Bank nc82)) for 3 h at room temperature followed by an overnight incubation step at 4 °C. Brains were then washed three times in PAT3 buffer and once in phosphate-buffered saline. Brains were mounted in Vectashield (Vector Laboratories). Images were captured on a Zeiss LSM 880 using a Plan-Apochromat ×20 (0.8 numerical aperture) objective.

Free-behaviour assays

All free-walking behavioural assays were conducted at 25 °C and 50–65% relative humidity between 0 and 3 h after lights on. Virgin males and females were collected after eclosion and group-housed separated by sex for 4–7 days before the assay. Flies were aspirated without anaesthesia, females first followed by males. All free-behaviour videos were recorded with FlyCapture 2 (v.2.13.3.61) at 30 or 42 frames per second (fps) in back light from a white light pad (Logan Electric) using a Point Grey FLIR Grasshopper camera (GS3-U3-32S4M-C 3MP) fitted with a HF12.5SA-1 lens (Fujinon). Central food patches of varying sizes (see below) were formed either from agar (2% w/v) perfumed with ACV (20% v/v), agar (2% w/v) with P. candelabrum fruit pulp (20%) or a 2% agar-only control.

Large arena

Assays were performed in 190-mm-diameter, 3-mm-high circular slope-walled Delrin chambers with a central food patch of 21.5 mm diameter. Five females were transferred to the chamber by mouth aspiration followed by five males. Once the males were loaded, the assay commenced, and groups were recorded for 40 min. Single-individual assays lasted 20 min. The centroid position of each fly was tracked in every frame, and identity swaps were manually corrected using the Caltech FlyTracker (v.1.0.5)54. The positional data were then used to infer individual trajectories, relative distributions and the distance of flies to the central food patch in MATLAB (v.2023b, MathWorks). A clustering fly was defined as within 3 fly lengths of at least one other fly, whereas a solitary individual was defined as being at a distance of at least 3 fly lengths from all other flies in the arena. The timing and position of copulations were manually scored.

Grid arena

Grid assays were conducted in modified large 190-mm-diameter arenas with a large 145-mm-diameter central food patch. A grid forming a lattice of 13 black, fly-sized (3 mm diameter) hemispherical plastic beads (Etsy) arranged in a regular square array was placed on the patch. The grid consisted of five equidistant beads along the horizontal midline with a distance of 30 mm along the edge, three equidistant beads 30 mm above and below and one more bead 30 mm above and below the three beads, all aligned along the midline. Assays with either five males or a single solitary male were recorded for 20 min. For ‘social foraging’ assays, one randomly chosen bead of the grid was exchanged with an immobilized decapitated female. Recording commenced after aspiration of all males. The centroid position and speed of each fly was tracked in every frame using AnimalTA (v.3.2.2)55. If necessary, identity swaps were corrected manually in the software. Exact bead positions were extracted for each assay using the same software. Distances of males to beads or the immobilized female and visits to visual targets were calculated from the positional data and used to infer individual trajectories and relative distributions. Summary statistics including the number of beads visited per male, bead approaches over time, the number of times a male switched between any two different beads, and the fraction of time spent per bead or with the female were calculated from positional data in MATLAB. A visit was defined as an individual spending at least 30 s within 3 fly lengths (approximately 9 mm) of a bead or the female. The timing of an approach was defined as the first frame of a visit bout. Bead switches were defined as the visit of any bead different than the previous one. Male unilateral wing extensions (singing) during the approach of a bead or a female were tracked manually using BORIS (v.7.13.9)56.

Small arena

Assays were performed in 38-mm-diameter, 3-mm-high circular slope-walled Delrin chambers with a central food patch of 21.5 mm diameter. Videos were recorded in 2 × 2 grids using the same recording setup as above. Females were aspirated first, followed by males, and assays commenced after the last fly was loaded for a 40-min recording. Strain-variation assays were restricted to D. melanogaster because of a lack of availability of further D. erecta strains. For heterospecific group assays, four pairs of D. simulans females and males were transferred to the assay chamber first, followed by one D. erecta female and one male. Ppk23-knockout assays were performed by first transferring a D. melanogaster female target to the arena, followed by mouth aspiration of either a wild-type or a D. erecta ppk23-mutant tester male on ACV. In single-bead assays, a hemispherical black plastic bead of approximately 3 mm diameter (Etsy) was placed on the food patch at the centre of the assay chamber first, followed by aspiration of a single fly, after which the assay commenced. Bead assays were recorded for 20 min. The centroid position and orientation of all flies were tracked and manually corrected for identity swaps in FlyTracker. Reproductive behaviours of males were then inferred in MATLAB from their orientation, heading direction and position relative to visual stimuli and other flies in the arena. Specifically, we extracted male approach and tracking of other flies, close-range courtship and copulations. Approach was defined as the directed movement (greater than or equal to 0.8 mm s−1) towards a sedentary object, such as another fly or a plastic bead from within a distance of maximally 4 fly lengths (approximately 12 mm). We scored approach when the male’s orientation was within 60° of the line connecting his and the target’s centre of area, up to a distance of 1.5 fly lengths (4.5 mm), where it had to be within 45°. Courtship was defined as periods during which males were approaching or tracking another fly or were within 1.5 fly lengths (approximately 4.5 mm) of a female with an angle of at least 45° subtending the line connecting the male’s and female’s centroids. We calculated the courtship index as the fraction of time a male was engaged in courtship for the duration of the assay (Courtship index = Time spent courting/Assay length). If a male copulated, courtship index indicates the fraction of time a male was engaged in courtship until copulation. To calculate the visual experience of males in groups in different chemosensory environments, the angular position and width of other flies in the arena on the focal fly’s visual field were calculated in MATLAB on a frame-by-frame basis as previously described57.

Free-behaviour visual virtual reality projector assays

All free-behaviour visual virtual reality assays were performed in 38-mm-diameter, 3-mm-high slope-walled chambers made of Delrin, coated with white self-adhesive vinyl paper (Livelynine) to enhance reflectance and increase the contrast of projected shapes. Visual stimuli were directly projected onto the assay chamber surface28 using a DLP LightCrafter 4500 mini projector (Texas Instruments). Tester males were aspirated into the assay chamber and allowed to acclimate for 5 min before visual stimulus projection started, and recording commenced for 5 min using a Basler acA3088-57uc camera with a 8 mm/f 1.8 lens (Edmund Optics) in pylon Viewer (v.6.3.0). If pairs of flies were used, the female was aspirated first, followed by the male, after which the assay commenced and was recorded for 40 min. All videos were recorded at 30 fps. For all but the visual environment replay assays, either 30 μl 2% (w/v) agar perfumed with ACV (20% v/v) or a 30 μl 2% agar-only control was pipetted into the centre of the assay chamber and allowed to solidify before flies were aspirated. To avoid obstructing the visual environment replay, four equidistant 30-µl dots were placed in a square formation at the periphery of the assay chamber.

Constant angular velocity stimulus assays

Males were presented with either a slow dot rotating clockwise at 16 mm s−1 with a 7.5-mm radius from the centre of the assay chamber, a fast dot rotating counterclockwise at 32 mm s−1 with a 15.5-mm radius from the centre of the assay chamber or both simultaneously. Each dot had a diameter of 3 mm. For mating assays, a female target was added and both visual stimuli were presented after the aspiration of the male. The assay commenced for 40 min or until copulation, whichever was first. The positions of the visual stimuli, female and male were tracked using flyTracker, and male visual object tracking behaviour was inferred in MATLAB on the basis of his orientation, heading direction and position relative to the visual stimuli and female. Tracking was defined as the directed movement towards a moving object within the orientation criteria described for approach in free-behaviour small-arena assays above. The data were then used to calculate the tracking index for each male. The tracking index was defined as the fraction of time a male tracked a visual stimulus during the course of an assay (Tracking index = Time spent tracking/Assay length).

Visual environment replay assays

The visual environment replay videos were prepared as follows. Individual trajectories tracked and manually corrected with FlyTracker were extracted from one representative recording of a D. erecta group of five males and five females on ACV and one recorded on agar in a small 38-mm arena. The positional centroid information as well as the orientation of each individual were then used to place a black ellipse at each fly’s position with the long axis (length 3 mm) aligned to the orientation for each frame for a total of 5 min recorded at 30 fps. The 5 min were then looped to create a 40-min video for each chemosensory condition. This was done because on ACV, the accumulation of copulating pairs over time changes the visual environment of a group from one dominated by dynamic movement during courtship to a more sedentary one. We thus extracted a representative 5-min block of a group dominated by courtship on ACV. For the agar video, we extracted the 5-min block beginning at the same time point. For the assay, replay of either the agar or ACV visual environment was paired with agar (2% w/v) or agar perfumed with ACV (20% v/v). A female fly and a male fly were aspirated into the arena, and the recording started together with video replay. Male behaviour towards the female was scored manually using BORIS for 40 min or until copulation, whichever came first. Manual tracking was necessary because flies were obscured by the ellipse projections at low contrast at times, which was not detectable by automated software. The behavioural data were then used to calculate the tracking index for each male.

Tethered virtual reality assaysTethering

Males (4–5 days old) were briefly (less than 30 s) anaesthetized on CO2 and subsequently tethered to a custom-milled plastic head plate similar to those used in previous studies38,58. Flies were held in place by a string across the cervical connective and fixed to the head plate by both eyes and the back of the thorax using UV-curable glue (Loctite 3106 and Bondic). The string was subsequently removed, and flies were left to recover in a warm, humidified chamber (25 °C, 50–70% humidity) in the dark. Flies were transferred to an air-supported ball of 5 mm (D. erecta) or 6.35 mm (D. melanogaster) diameter after 30 min and left to acclimatize for 45 min.

Virtual reality system

We adapted a previous hardware design for presenting tethered males with visual stimuli38,59 and extended it to provide odours with temporal precision. The system, described in detail in ref. 38, consists of an aluminium base keeping an air-supplied Styrofoam ball afloat, held in place by a custom 3D-printed holder adapted to fit either the original 6.35-mm ball used for D. melanogaster males or a 5-mm ball for D. erecta males. The conical screen surrounding the ball was kept at the original dimensions (large diameter: approximately 220 mm, small diameter: approximately 40 mm, height: approximately 60 mm) but was cut from holographic rear projection film (Megicolim). The visual stimulus was rear-projected around the male using a DLP 3010 Light Control Evaluation Module (Texas Instruments). A high-contrast circular visual stimulus of approximately 28° diameter mimicking the angular size of a female fly 2 mm from the male was rear-projected onto the screen, moving in a symmetric 150° arc at constant angular velocity (50° sec−1). For odour delivery, we fit Teflon tubing to the setup providing a constant stream of humidified air with low flow volume (0.5 l min−1) towards the male’s head from the front at a 45° angle and approximately 2 mm from the fly to not obstruct the view on the screen. The tubing was 1 cm in diameter, making sure the entire male was engulfed by the stream of air. Pure ACV odour was mixed with water vapour to a concentration of 50% by two digital mass flow controllers and fed into the outlet tubing by switching from pure air using solenoid valves controlled by means of a data acquisition device (MMC 1408 FS). This ensured the air-flow rate was constant throughout the experiment. Acquisition of the male’s positional readout was based on positional tracking of the spherical treadmill using FicTrac (v.2.0), which was combined with the regulation of visual stimulus generation and odour delivery in MATLAB on a single computer.

Experimental parameters

Each assay lasted 210 s, beginning with a 30-s baseline period followed by the projection of the oscillating visual stimulus for the remaining 180 s. ACV odour was delivered for 60 s beginning 90 s after assay start, exposing the male to 60 s of visual stimulus only before and after odour delivery.

Anosmic mutant assays

To assess the role of olfaction in the ACV-dependent visual tracking of D. erecta males in the tethered virtual reality assay, we produced a transgenic line mutant for the chemosensory coreceptors Orco and Ir8a deficient in the principal olfactory pathways previously implicated in the detection of ACV volatiles60,61. Double mutants were tethered and assayed as described above.

Tracking index

The tracking index was defined as previously described36 to reflect the fidelity and vigour of the male’s pursuit of the visual target.

Optogenetic assays

Optogenetics experiments were performed by expressing the light activated cation channel CsChrimson in olfactory sensory neurons (Orco-Gal4) or P1 neurons (71G01-Gal4) with flies reared on sugar-yeast food lacking retinal, a cofactor required for channelrhodopsin function. After 5 to 6 days, tester flies were transferred to food containing 400 μM all-trans-retinal for two days before the experiment. Controls were transferred either to a new sugar-yeast food vial or alternatively to food containing retinal when using a genetic control. Genetic control males carried CsChrimson without a Gal4 driver. For optogenetic activation, flies were exposed to light at a wavelength of 625 nm emitted by red LEDs (Cree Xlamp XP-E2). We used three different experimental configurations.

Free-behaviour optogenetic assay

Small 38-mm assay chambers with a central 21.5-mm food patch formed from agar (2% w/v) perfumed with ACV (20% v/v) or an agar control were backlit with blue light. A female, immobilized by decapitation or an inanimate hemispherical bead (diameter 3 mm), was placed at the centre of the arena. After aspiration of the male, assays were run for 6 min, with two 2-min blocks of baseline background illumination interleaved with the delivery of red light pulsing at 5 Hz with a pulse length of 0.1 s for 2 min. For assays with a decapitated female, red light for optogenetic activation was delivered from below the assay chambers using an array of nine high-power LEDs emitting red light at high intensity to penetrate the Delrin resulting in a power of approximately 7 µW mm−2 at the surface. For bead assays, red light was delivered from above using five high-power LEDs. Male behaviour was tracked using FlyTracker. His position, orientation relative to the female and heading direction were used to track courtship behaviour and to calculate the courtship index as described above.

Free-behaviour projector optogenetic assay

Small 38-mm assay chambers were coated with a white adhesive film to increase reflectance and illuminated from above using a LightCrafter 4500 mini projector (Texas Instruments) set to emit light exclusively through its blue LED channel by switching off the red and green LEDs for background lighting. P1 neurons labelled with 71G01-Gal4 were activated by red light delivered from above using five high-power LEDs. Assays were run for 6 min, with two 2-min blocks of baseline background illumination interleaved with a 2-min delivery of constant red light in addition to the background light. Male behaviour was tracked using flyTracker. His position, orientation relative to the female and heading direction were used to calculate the tracking index. Tracking was defined as the directed movement towards a moving object within the orientation criteria described for approach in free-behaviour small-arena assays above. The data were then used to calculate the tracking index for each male. The tracking index was defined as the fraction of time a male tracked a visual stimulus during the course of an assay (Tracking index = Time spent tracking/Assay length). Population behaviour was summarized by the fraction of males courting across assays over time.

Tethered optogenetics assay

Males used for optogenetics assays were tethered as described above in ‘Tethered virtual reality assays’. Assays lasted 210 s beginning with a 30-s baseline followed by visual stimulus delivery for the remaining 180 s. One 1.5-mm optic fibre (Edmund Optics) was coupled to a high-power red LED (650 nm, LED Engin) mounted on a heat sink (Ohmite) and placed directly above the head of the fly. Orco+ olfactory sensory neurons were activated by pulsing light at 5 Hz with a pulse length of 0.1 s for 60 s after 90 s. Tracking index was calculated as described above.

Two-photon functional imagingFly preparation

Males were tethered as described above. After recovery, the plate was filled with saline (108 mM NaCl, 5 mM KCl, 2 mM CaCl2, 8.2 mM MgCl2, 4 mM NaHCO3, 1 mM NaH2PO4, 5 mM trehalose, 10 mM sucrose, 5 mM HEPES, pH 7.5 with osmolarity adjusted to 265 mOsm) covering the fly’s head. The cuticula above the antenna and between the eyes was cut with a 30-gauge needle and removed with forceps without anaesthesia to provide optical access to the central brain. The tracheae covering the top of the brain were removed using forceps, after which flies were transferred to the ball to recover in darkness for 45 min.

Functional imaging

Experiments were performed with an Ultima two-photon laser scanning microscope (Bruker Nanosystems) with a Chameleon Ultra II Ti:Sapphire laser. Samples were excited at a wavelength of 920 nm, and emitted fluorescence was detected with a GaAsP photomultiplier tube (Hamamatsu). Images were acquired in Prairie View (v.5.6; Bruker) with a ×40 Olympus water-immersion objective with 0.8 NA. To reduce noise caused by light emitted by the projector during imaging, the red and green LED channels were switched off. In addition, a piece of blue-light filter paper (Rosco) was placed in front of the projector lens. After the male’s resting period on the ball, the objective was lowered over the brain to identify the brain region of interest (ROI). We centred a small ROI yielding an imaging rate of 4–8 Hz. Laser power was kept low to reduce stress on the fly. ROIs were drawn in a single hemisphere, depending on the neural population imaged. For P1 and LC10a imaging, an ROI was drawn in the LPC and AOTu neuropil, respectively, where axonal projections were densest. For fru and dsx imaging, a larger ROI was drawn, encompassing neurites in both the LPC and adjacent AOTu to capture neural activity simultaneously.

For experiments with a moving visual stimulus, experimental parameters and calculation of the tracking index were as described in ‘Tethered virtual reality assays’. For pheromone tapping experiments, a virgin conspecific female (4–8 days old) was mounted on a micromanipulator serving as pheromone stimulus and presented in sets of six touch bouts 30 s apart to allow neural activity to return to baseline between taps. Pheromone and ACV responses in dsx+ neurons in the LPC were assessed in the same ROI for each animal, where the order of presentation of odour and pheromone stimuli was randomized.

Imaging analysis

Imaging data were postprocessed and analysed using Fiji (v.2.14.0, NIH). For each experimental recording, frames were motion corrected and aligned along the x and y axes by the Template Matching plugin. Residual background noise from the projector was reduced from raw time series using the Despeckle function. Finally, an ROI was drawn across the entire population of interest containing neuropil to extract the average fluorescence. Fluorescence was normalized in MATLAB for each recording using the average fluorescence over the first 30 s of an experiment as baseline (F0). ∆F/F was defined as ∆Fi/F0 = (Fi − F0)/F0, where i denotes the current frame. Because imaging data were collected at a lower frame rate than behavioural data, behavioural data were downsampled using linear interpolation at the imaging time points. Data from pheromone and ACV imaging of Dsx+ neurons were normalized by matching ∆F/F of pheromone responses across species and adjusting odour responses accordingly.

Statistical analysis

MATLAB was used for statistical analyses and plotting. The Shapiro–Wilk method was used to test normality, and the appropriate parametric/non-parametric statistical test was used. In cases for which several comparisons were made, appropriate post hoc tests were conducted as indicated in Supplementary Table 1. All statistical tests used were two-tailed.

Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.