Animals

Flies (Drosophila melanogaster) were reared on standard yeast-based Drosophila medium under a 12-h light and 12-h dark cycle (lights on at 8 A.M.). Three experimental setups were used: overnight brain recording setup (Fig. 1a), multichannel brain recording setup (Fig. 2a), and exposed-brain recording setup (Fig. 3a). Flies used for overnight brain recording experiments were kept in the same room to allow exposure to the same daily fluctuations in temperature (22–24 °C) and humidity (40–60%) as during the experiments. All other flies were raised at 25 °C with 50–60% humidity. Adult female flies (<7 days post-eclosion) were used for all experiments. Wild-type Canton-S (CS) flies were used for overnight recording experiments. UAS-TrpA1 and UAS-2xEGFP were acquired from the Bloomington Drosophila stock center. The Gal4 drivers used for driving expression in the dFB neurons were C5-Gal4, 104y-Gal4 and 23E10-Gal4, also from the Bloomington Drosophila stock center. UAS-CsChrimson was kindly provided by Vivek Jarayaman (Janelia Research Campus).

For all experiments, flies were anesthetized on a thermoelectric-cooled block (1–2 °C). To prepare the fly for both the overnight and multichannel recording experiments, the dorsal surfaces of the fly head and thorax were secured to a tungsten rod11, 21 using dental cement (Coltene Whaledent Synergy D6 Flow A3.5/B3) and cured by 30–40 s exposure to high intensity blue light (Radii Plus, Henry Scheinn Dental).

Two channel differential LFP

As described previously11, to perform the overnight recordings (Fig. 1a), we used pulled borosilicate micropipettes (World Precision Instruments TW100F-4, pulled using a Sutter P-97 micropipette puller), which were cut, leaving only the 6 mm length of the tip (~3MΩ resistance), and subsequently filled with extracellular fluid (ECF) containing (in mM): 103 NaCl, 10.5 trehalose, 10 glucose, 26 NaHCO 3 , 5 C 6 H 15 NO 6 S, 5 MgCl 2 (hexa-hydrate), 2 sucrose, 3 KCl, 1.5 CaCl (dihydrate), and 1 NaH 2 PO 4 . The cut micropipettes were then carefully inserted ~100 μm into each brain hemisphere through the dorsal eye rim using a mechanical micromanipulator, with each micropipette permanently held in place using dental cement. Fine tungsten wire electrodes (25 μm; A-M Systems) were inserted into the solution-filled micropipettes and sealed within the micropipette using electrical insulating compound (Dow Corning 4). The prepared fly was then placed onto an air-supported polystyrene foam ball that served as a walking/resting platform (Fig. 1a). Local field potentials (LFPs) were recorded, 1–2 h after implanting the micropipette electrodes11, using field-effect transistors (FETs) (NB Labs, Denison, TX). Recordings were performed at a sampling rate of 291 Hz and amplified (×10,000 gain) with a differential amplifier, signal bandpass filtered (low: 1 Hz, high: 100 Hz) (Warner Instruments DP-304), digitized (National Instruments BNC-2090), and the data acquired with a custom-built software on a LabVIEW platform11. The electrophysiology setup was housed within a light-shielded box to allow a controlled environment of 12-h light and 12-h dark cycle. Infrared LEDs illuminated the fly for movement monitoring via an infrared-enabled webcam (Logitech Pro 9000, with modification described below), producing monochromatic low-resolution images (27 × 34 pixels) with a frame rate of 3 frames per second, well-suited for a continuous long recording session. Movement data were quantified offline using a custom script in MATLAB (The Mathworks, Natick, MA) and subsequently time-matched with the LFP data.

Most readily available webcams have an infrared filter, which was removed in order to film under infrared lighting conditions. This first involved accessing the camera’s circuit board by unscrewing the outer case, then removing the screws holding the lens in place, followed by de-soldering the 2 connectors between the lens assembly (auto focus unit) and the circuit board, to allow access to the rear of the lens. The thin glass disc (the IR filter) was removed by breaking the glass with a pair of forceps, ensuring that none of the glass pieces fell into the photo sensor underneath. Once the IR filter was removed, the webcam was reassembled to its original state. A visible light filter was fitted to the front to complete the modification.

Multichannel LFP

Methods for performing multichannel fly brain recording have been described previously21. Briefly, to record from multiple channels in the fly brain we used a 16-electrode linear silicon probe (model no. A1 × 16-3 mm50-177; NeuroNexus Technologies). The probe was inserted into the flies’ eyes laterally, perpendicular to the curvature of the eye, with the aid of a micromanipulator (Merzhauser, Wetzlar, Germany) (Fig. 2a, middle panel). We inserted the probe such that the electrode sites faced posteriorly within the brain. A sharpened, fine tungsten wire (0.25 mm; A-M Systems) served as a reference electrode and placed superficially in the thorax. Recordings were made using the Tucker–Davis Technologies (Tucker-Davis Technologies, US) multichannel data acquisition system at 25 kHz coupled with a RZ5 Bioamp processor and RP2.1 enhanced real-time processor.

Exposed-brain targeted single channel LFP

For experiments on the exposed-brain assay (Fig. 3a), the two forelegs were cut in the femur segment and the proboscis restrained with dental cement to the ventral thorax. This was done to provide access to the posterior surface of the head and to eliminate proboscis or foreleg movement from disrupting the brain visualization and electrical recording. The flies were then mounted and sealed with dental cement onto a custom fly plate51, 52 that provided electrode access to the posterior head (Fig. 3b). The bath chamber of the fly plate was filled with oxygenated ECF (95% O 2 , 5% CO 2 ), immersing the brain, while keeping the rest of the fly dry. With the use of a pair of forceps and 30½ gauge syringe needle, the head was dissected, with the perineural sheath removed either mechanically with forceps or chemically using protease (0.5% collagenase type IV solution). Similar to the overnight setup, the fly in this preparation was also positioned on an air-supported ball. The fly brain was kept healthy with a continuous delivery of oxygenated ECF at a flow rate of about 2 ml/min. LFP recordings were performed with a glass electrode amplified (via FETs) and filtered (low: 0.1 Hz, high: 1 kHz) (A-M Systems Model 1700), digitized (Axon Digidata 1440 A Digitizer) and sampled at 1000 Hz using the data acquisition software AxoGraph × 1.4.4 (Axon Instrument) on a computer running Windows XP. A fixed-stage upright fluorescence microscope (Olympus BX51WI, U-RFL-T, Olympus, Berlin, Germany) was used to visualize the fly brain, and a motorized micromanipulator system (Sutter MP-285) was used for guiding electrode insertion. The fly was illuminated using a 3 mm white LED (PN: 5219901802 F, Dialight, South Farmingdale, NJ) placed at a distance of 6–8 cm from the fly for behavioral monitoring using a camera (Point Grey GRAS-14S3C-C) at a resolution of 480 × 640 pixels and 30 frames per second. For optogenetic experiments, illumination of the fly was achieved using an infrared LED (Osram SFH 4232) instead of a white LED, coupled with a custom lens filter fitted to the camera that specifically blocks out red light. Behavioral data were acquired and stored on a computer running Linux OS. For optimal visualization of the targeted neurons, a second high-powered infrared LED (Osram SFH 4232) was used with its light path redirected to the fly’s right eye via an optic fiber (1 mm diameter), positioned about 2–3 mm from the eye (Fig. 3a). A microscope camera (DAGE-MTI IR-1000) connected to an LCD TV unit (Samsung SyncMaster 940MG) provided live imaging of the fly brain and neurons. Visualization of the GFP-labeled neurons was achieved using a mercury short-arc lamp (HBO 103 W/2). No GFP-labeling was used to target specific sites in the optic lobes recording and were therefore only approximated. The recording site was confirmed by releasing dye in a subset of flies (Fig. 3c, and see immunolabeling, below).

Arousal-testing stimulus for tethered flies

Methods describing the use of a vibration stimulus for testing behavioral responsiveness of tethered flies in the overnight recording setup was previously described11. Briefly, a vibration stimulus generated by a 12 mm shaft-less vibrating motor (Pico Vibe 312-101; Precision Microdrives) was delivered to a subset of flies in the overnight recording preparation. We then examined the flies’ behavioral responsiveness, from the movie images, to determine whether flies in the brain-recording setup were sleeping as defined by an increased arousal threshold. The motor was glued to the top end of the brass tether rod (Fig. 1a), delivering a vibratory stimulus of 1 V intensity to the fly through the length of the rod lasting < 1 s at 15 min intervals throughout the recording session. Stimulus delivery was automated and set using a custom MATLAB script11.

Thermogenetic and optogenetic sleep induction

Thermogenetic sleep induction in the multichannel brain recording setup was achieved by heating the suspended fly from below, using a 100-W halogen lamp (Zeiss) equipped with an infrared long pass filter21. For the exposed-brain recording setup, the fly brain was heated directly by modulating the temperature of the ECF bath solution. This was achieved by using an in-line heater/cooler (Warner Instruments Model SC-20), driven by a temperature controller (Warner Instruments Model CL-100), and cooled by a liquid cooling system (Warner Instruments Model LCS-1). With the aid of a thermistor, the temperature of the bath was kept at room temperature in the range of 22–23 °C. During the stimulation period, temperature was ramped up to >29 °C after 2 min of room temperature recording (baseline), and lasted for 5 min before returning to <23 °C for 5 min of recovery (see Fig. 3d, bottom plot). Temperature throughout each experiment was handled by AxoGraph.

For optogenetic experiments, dietary supplements of ATR were needed for the transgenic channelrhodopsin to function. Therefore, all flies used for optogenetic experiments were transferred to food vials containing 1 mM ATR supplementation53 at least 2 days prior to experimentation. The activation stimulus consisted an ultra-bright red LED (617 nm Luxeon Rebel LED, Luxeon Star LEDs, Ontario, Canada) directed to the opened section of the fly head (Fig. 5a, bottom panel), producing 0.1–0.2 mW/mm2 at a distance of 4–5 cm with the aid of concentrator optics (Polymer Optics 6° 15 mm Circular Beam Optic, Luxeon Star LEDs). To prevent overheating the fly and the immediate environment, the LED was mounted onto a sink pad (SinkPAD-II 20 mm Star Base), which was attached to a small heat sink. The temperature of the solution bath was also kept constant by the temperature controller system (see above). Continuous light exposure was administered after 1 min of baseline recording and lasted for 2 min (Fig. 5b). Timing of the light switch was controlled by AxoGraph, which also measured the timing of light exposure from a photodiode (Fig. 5a, bottom panel).

Pharmacologically induced sleep

The GABA A agonist, Gaboxadol, also known as 4,5,6,7-tetrahydroisoxazolopyridin-3-ol (THIP), was used to induce sleep in flies16. Instead of feeding, as in previous studies16, 28, Gaboxadol was delivered directly to the fly brain by dissolving it into the ECF28. Three concentrations were used (in mg/ml): 0.05, 0.1, and 0.2. The Gaboxadol-containing ECF was delivered to the bath chamber at the rate of 2 ml/min for a total of 5 min, after 5 min of recording with standard ECF, and immediately washed out by switching back to standard ECF thereafter. The drug delivery setup consisted of two 50 ml reservoirs, one with Gaboxadol-containing solution and the other standard ECF, both connected to a 3-way solenoid valve with the outlet leading to the fly plate bath chamber (Fig. 4a). The timing for the switching of the solenoid valve was controlled by AxoGraph. The effect of optogenetic activation on Gaboxadol-induced sleep flies was examined by first running the optogenetic activation protocol (see above, with a baseline recording of 5 instead of 2 min), followed by a 5-min delivery of Gaboxadol solution, and subsequently running the optogenetic activation protocol for the second time (5 min baseline, 5 min activation, and 10 min of recovery; see Fig. 5d, top panel).

Immunolabeling

The electrode positions in the fly brain were labeled with Texas Red fluorescent dye (Invitrogen) via iontophoresis to confirm the recording location in the dFB (Fig. 3c). Fly brains were dissected and fixed in 4% paraformaldehyde in a phosphate buffer solution (PBS). After a minimum of 1 h in fixative, the brains were washed with 0.2% Triton X-100 in PBS (PBST) with 0.01% sodium azide (Sigma), blocked in 5% normal goat serum in PBST, and let incubate overnight in a primary antibody solution (1:10 mouse anti-nc82 + 1:1000 rabbit anti-GFP + block solution). The next day, the brains were washed in PBST and let incubate overnight in a secondary antibody solution (1:250 goat anti-rabbit Alexa Fluor 488 and 1:250 goat anti-mouse Alexa Fluor 633). The brains were washed in PBST for the final time and embedded in Vectashield and imaged using a confocal microscope (Zeiss).

Behavioral analyses of tethered flies

Movie images of the flies acquired from the overnight and exposed-brain recordings were analyzed and quantified in MATLAB using a pixel subtraction method11, generating the pixel change value (Δ pixels), which quantifies the fly’s behavioral activity. Image noise level varies with each movie recording and was therefore determined for each recording by visually inspecting the activity trace and assigning a threshold value. The fly was considered active during the times when the measured activity exceeded this threshold11.

For each stimulus trial in the arousal-testing experiments (see Arousal-testing stimulus for tethered flies), the average Δ pixels in the 15 s post-stimulus were calculated, and if exceeded the threshold (see above), the fly was regarded to respond to the stimulus (respond group), while for trials with values below threshold, regarded unresponsive (did not respond group; Fig. 1b, top). Response rate was thus calculated as the averaged percentage of trials when the flies responded (Fig. 1b, bottom). Visual inspection on an overnight fly movie recording revealed a range of non-locomotion micro-behaviors, which we classified into one of three groups: posterior groom, anterior groom, and proboscis extension. Times of occurrence for each of the micro-behavior in one fly recording were determined manually, and subsequently time matched to the LFP recording (Supplementary Fig. 2). Behavioral activity was not monitored for flies in the multichannel recording setup.

For comparing fly activity in the exposed-brain recording setup, Δ pixels were reduced to a binary format such that behavioral activity was quantified as the percentage of frames where Δ pixels exceeded the threshold in a specified time range (Figs 3f and 4c). For Gaboxadol-induced sleep experiments, we observed a rapid decline in behavioral activity following drug perfusion, which we defined as the onset of the drug’s effect. We observed some variability in the latency period of the drug effect onset across flies, and therefore the drug onset time was determined for each fly by examining the movie recordings. Comparison between the percentage movement in the period within 5 min prior and 5 min after drug onset were made to confirm the cessation of movement that occured as a result of Gaboxadol exposure (Fig. 4c–e). Latency periods were defined as the time it takes since the commencement of drug perfusion to the onset of behavioral effect of the drug.

Overnight recordings

Analyses on the LFP data obtained from the overnight recording setup were performed offline on custom scripts in MATLAB (2014a, 2015a). Analyses were restricted to frequencies between 0 and 100 Hz as activity above 100 Hz in the fly brain is unlikely biological. For comparing the LFP activity across different arousal states sorted into day and night (Fig. 1d), the raw LFP were split and grouped based on the recorded movement data (see Behavioral analyses of tethered flies) and time-of-day during the recordings. The raw LFP for each condition were then transformed into power using the Morlet wavelet transformation function “ft_specest_wavelet” in the Fieldtrip MATLAB toolbox54. The width setting of the wavelet used was set at 30 with 3 standard deviation (gwidth). Power differ in magnitudes across fly recordings, and were therefore normalized for each fly prior to averaging. Normalization involved obtaining the mean values for the power in the Wake day condition, and used as the reference (denominator of a ratio calculation) to compare with the individual power values of the other 3 conditions (numerator). The resulting values used for statistical analyses were therefore ratio values of power in each group relative to those for Wake day. For the 0–100 Hz analysis, this normalization process was performed separately in binned groups of 2 Hz prior to averaging.

Similarly, for sleep bout LFP analysis, the mid-sleep section was used as the reference with ratio of power in each sleep segment within a sleep bout obtained prior to averaging the ratio values across all sleep bouts (separated into day and night) in a fly, and subsequently averaged across all flies. This process of normalization was applied in the 7–10 Hz analysis (see Fig. 1g), where the ratio calculation was performed first in binned groups of 0.1 Hz for each sleep bout prior to subsequent averaging. Additionally, we examined the LFP power in a series of broader frequency domains (Supplementary Fig. 3a–e), identified previously in a k-means cluster analysis of Drosophila brain activity (2–6 Hz, 6–15 Hz, 15–30 Hz, 30–50 Hz, 50–100 Hz)21 excluding 0–2 Hz due to potential heartbeat artifacts.

Power spectra were generated by performing discrete Fourier transform on the raw LFP data (fft function from MATLAB Signal Processing Toolbox) (Supplementary Fig. 1b). To prepare the time-frequency spectrograms, the data were first lowpass filtered at a cutoff of 100 Hz and then highpass filtered at a cutoff of 0.2 Hz by using a second-order Butterworth filter, with further processing (tapers [3 5], moving window [1 0.05]). The time-frequency spectrogram was generated by the mtspecgramc function in the Chronux MATLAB toolbox55. For the analysis of the frequency domain, Letswave 5 (http://nocions.webnode.com/letswave) was used, which runs on MATLAB 2015a. As before, the data were first lowpass filtered at a cutoff of 100 Hz and the highpass filtered at a cutoff of 0.2 Hz by using a second-order Butterworth filter. Furthermore, the data were cropped and divided into 4 categories (day wake, day sleep, night wake, night sleep). The Data were first averaged in the time domain for each category and each animal, then a discrete Fourier transform was performed on the averaged data and the data were normalized. The signal to noise ratio (SNR) was calculated as the ratio between the amplitude for each frequency and the mean amplitude of 15 neighboring frequency bins (0.1 Hz) on each side. Z-scores for the frequency peaks were calculated in a similar way as the SNR. Z-score values above 1.64 indicated a significant (p < 0.05) difference between peak and baseline.

For determining whether sleep-related oscillations were homeostatically regulated in overnight experiments, we divided all nighttime sleep bouts (>5 min) into three equal-sized epochs per fly: early sleep, mid sleep, and late sleep. Normalized LFP power for the 7–10 Hz domain of the first night epoch was compared to the last epoch, and any differences were tested by a Wilcoxon matched-pairs signed rank two-tailed test. We further analyzed whether 7–10 Hz oscillations during spontaneous sleep is associated with increased responsiveness following a vibration stimulus. For that purpose, we performed a Morlet wavelet transformation (2–15 Hz), as described earlier. We normalized all the data ([0 1]) for every fly separately and extracted the average sleep LFP power for the 7–10 Hz frequency range. We then separated our data into low 7–10 Hz LFP power and high 7–10 Hz LFP power based on a set threshold defined by the average LFP power of the neighboring frequencies (2–7 Hz and 10–15 Hz). Vibration stimuli occurred every 15 min throughout the night, as described above. All vibration stimuli that coincided with ‘high’ 7–10 Hz LFP power during a sleep epoch were noted, and a behavioral response rate was calculated as before (see Behavioral analyses of tethered flies). Response rates were compared for trials when the stimulus coincided with ‘low’ 7–10 Hz LFP power during sleep epoch. For all trials, 7–10 Hz LFP power was determined for the 10 s preceding the vibration stimulus.

Multichannel recordings

All LFP data were analyzed offline in MATLAB (2015a). Raw LFP data were down sampled to 1000 Hz, filtered between 0.5 Hz and 200 Hz using a fourth-order Butterworth filter. Bipolar-referencing to the most lateral channel (1, in the optic lobe) was used to create 15 differentiated channels. From this, independent components analysis (ICA) was conducted to reduce spontaneous artifacts in the data using the FastICA function56, 57. From the data set, 3 s epochs were extracted for each condition prior to the heating condition as baseline, the ‘Heat ON’ condition, as well as a post heat condition.

Drosophila heart beat has been shown to change frequency during heating58 which could be a confounding factor in our experiments. Thus, channels containing clear heartbeat artifacts, at any stage of the experiment (baseline, heat on, heat off) were removed from subsequent analysis. For this reason, a multi-tapered Fourier transform was performed using the mtspectrumc.m Chronux function55 to improve resolution in order to visually identify channels contaminated with a heartbeat around 2–4 Hz and its harmonics21.

We converted LFP into power as described above (see Overnight recordings). For this, we used a wavelet resolution of 3 s corresponding to the length of each epoch, and a wavelet width of 3 s.d. This was done twice, once to look at the 2–40 Hz frequency band across channels, and again to examine differences in the 5 frequency bands described above (2–6 Hz, 6–15 Hz, 15–30 Hz, 30–50 Hz, 50–100 Hz; see Supplementary Note 1 for analysis).

For normalization of the power values, we divided each channel by the median of the baseline activity, followed by the median by channel groups for every fly. The bipolar-referencing scheme allowed the orthogonal selection of channels by grouping them in 3 groups of up to 5 channels (optic lobe 1, center, optic lobe 2). The resulting data were organized in factor coded columns and exported to R version 3.3.259 for further statistical analysis.

A non-parametric multi-factor ANOVA was used to assess statistical significance on the mean LFP power, with post hoc contrasts on a three-way interaction term between brain regions, fly line, and heat condition. Significant effects were determined at a Bonferroni corrected alpha value of 0.0125.

Exposed-brain recordings

All analyses on the LFP data obtained from the exposed-brain recording setup were performed offline on custom scripts in MATLAB (2014a, 2015a). The time-frequency spectrograms were generated in the same way as described for the overnight recordings. To obtain the averaged spectrogram across multiple flies (Figs 3e, i and 5b, bottom), the data were first normalized for every animal by dividing the amplitudes of frequencies over time by the mean amplitude of the baseline for all frequencies. Then, the ratio was calculated by dividing all values by the maximum amplitude of the baseline. Subsequently, data of all experimental animals was averaged.

For quantifying the LFP signal, wavelet transformation was first applied to the raw LFP data prior to splitting into 3 groups: baseline, stimulus on, and stimulus off. The power values for the stimulus on and stimulus off groups were divided by the mean of the baseline power within the corresponding frequency bins (same frequency domains and bins as the analysis for the overnight recordings). Additionally, the ratio power values were zeroed such that any negative power value indicates a decrease of LFP activity in relation to baseline. For thermogenetic experiments, segments of data where the temperature transitions between the two stable states (24 °C and 29 °C) were excluded from analysis. LFP recordings from the optogenetic experiments contain obvious artifacts during the brief period when the light was switched on and off; therefore, a short data segment (from 5 s prior to 5 s after the light switching) were excluded from analysis. To examine the LFP effect of Gaboxadol-induced sleep, we compared the LFP power between the 5 min prior and the 5 min after the drug effect onset (see Behavioral analyses). Likewise, the power used for this comparison were first normalized to baseline values which was the first 5 min of each recording.

Similar to the multichannel brain recording, we detected oscillatory activity surrounding 2 Hz that likely originated from the heartbeat. The intensity of the heartbeat can often be observed visually under the light microscope during cuticle dissection. We first attempted to stop these muscle contractions by mechanically damaging the relevant muscle58 with a pair of forceps. We then also excluded any observed LFP effect in the 0–2 Hz domain as it is likely contaminated by the movement artifacts. In some flies, however, the harmonics of the heartbeat artifact were also present, clouding any signal that manifests in frequencies above 2 Hz. We excluded these recordings entirely, based on the interpretation of heartbeat artifacts by two experimenters (M.H.W.Y. and M.J.G.) independently.

Statistical analyses

All statistical analyses for data gathered from the overnight and exposed-brain recording setup were performed using Prism 7 for Windows (GraphPad). A subset of behavioral and LFP power data set did not pass the Shapiro–Wilk normality test (p < 0.05). Depending on the outcome of the Shapiro–Wilk normality test, a Wilcoxon signed rank test or a t test was used to test for significant effects between two matched conditions. The appropriate tests used are mentioned in the figure legends. Friedman test with Dunn’s post hoc multiple comparisons test were used to compare three or more matched conditions, and Kruskal–Wallis test with Dunn’s post hoc for unmatched data. All the data presented in figures are as means ± S.E.M. for bar and line graphs while box and whiskers plot presents median and 10–90 percentiles as whiskers. All tests for significance were two-tailed and confidence levels set at α = 0.05.

For the multichannel statistical analysis, the following R packages were used: ARTool60, 61, car62, dplyr63, influence.ME64, lattice65, lme466, magrittr67, MASS68, Matrix69, nortest70, phia71, and plyr72. The data.frame was organized by splitting the data set into 104 y and C5 groups to be analyzed separately. In the case of the frequency cluster analysis, the data were further divided into individual frequency bands. The data for the 2–40 Hz band were not normally distributed (Lilliefors (Kolomogorv–Smirnov) Test p < 0.001). Therefore, a non-parametric test was used for the log transformed data, which allowed the test of multiple factors and their interactions called the Aligned-Rank ANOVA from the R ARTool package61. The Aligned-Rank ANOVA allows multi-factor or mixed model regression to be performed on a non-parametric dataset or one that violates the normal assumptions of parametric models61. For the 2–40 Hz and frequency cluster analysis, Aligned-Ranks were constructed using the art function from ARTool. The ARTool package makes use of the lmer function for testing mixed models from the lme4 package and thus uses its syntax.

To perform contrasts on significant higher-order interactions, the testInteractions function from the phia package was used to test post hoc contrasts between categorical variables, employing a scheme called Helmert coding73. Unlike other types of factor level coding, Helmert contrasts allows flexibility in the equivalence assigned to factor levels73. In this instance, it allows the mean across both optic lobes to be compared to the center for the Region factor (e.g., −1/2 for each optic lobe and 1 for the center, summing to zero). The contrasts also compared the TRP-lines to GAL4 or UAS controls (TRP = 1, GAL4 = −1), Heat On to Baseline (Baseline = −1, Heat On = 1, Heat Off = 0) or Heat Off to Baseline (Baseline = −1, Heat On = 0, Heat Off = 1), unless otherwise specified. The testInteractions function takes the model output provided by ARTool. The Aligned-Rank ANOVA has two diagnostic tests associated with it which tests whether the aligned-rank transformation was performed successfully61. For the first test, the columns of aligned-rank responses should all sum to zero. All analyses performed passed this test. The second test checks whether a full-factorial ANOVA on ranked (but not aligned) responses has all main effects stripped out as indicated by an F value of 0 (Pr = 1).

Arousal testing in freely walking flies

Sleep-related metrics (sleep intensity, arousal thresholds, sleep duration) for freely walking flies (Fig. 6a) were determined using the Drosophila ARousal Tracking system (DART) as previously described16, 31. Twenty-four hours prior to experiments, 3- to 5-day-old adults were collected and loaded individually into 65 mm glass tubes (Trikinetics) that were plugged at one end with standard yeast-based fly food, containing either 0.1 mg/ml Gaboxadol or 0.5 mg/ml ATR. Controls were placed onto normal food and housed under the same conditions as the experimental groups. The tubes were aligned on platforms (6 total platforms, 17 tubes per platform) for filming. Flies were exposed to ultra-bright red LED (617 nm Luxeon Rebel LED, Luxeon Star LEDs, Ontario, Canada) for the duration of the experiment for optogenetic activation of flies fed with ATR. For determining arousal thresholds, flies were probed once every hour for 48 h, with a succession of vibrational stimuli of increasing strength, from 0 to 1.2 g. Each stimulus consisted of 5 pulses of 200 ms, and was delivered in 0.2 g increments 15 s apart. To investigate behavioral responsiveness, flies were stimulated every hour with 5 succesive vibrations of equal strength (1.2 g), 200 ms apart. Sleep intensity was measured as the proportion of immobile (sleeping, as per >5 min criteria) flies that responded (at any level) to these stimuli. Flies were determined to have responded if they moved by a threshold of at least 3 mm (~3 body lengths) within the minute following the stimulus, as reported previously16, 31. To determine awake responsiveness, we excluded sleeping flies (i.e., flies immobile for five minutes or greater prior to the stimulus) and only flies that had moved within the four minutes prior to the stimulus (i.e. awake flies) were included in the analysis. Awake responsiveness was measured as the proportion of awake flies responding (Fig. 6f), as well as their response magnitude (Supplementary Fig. 8c). To determine response magnitude, fly activity was averaged for two minutes prior to and 15 min after each stimulus. This average activity was fitted with a single-inactivation exponential equation and the peak amplitude of activity following the stimulus was measured. For experiments testing the effect of different sleep induction methods on subsequent behavior, flies were placed on either 0.1 mg/ml Gaboxadol, 0.5 mg/ml ATR, or drug-free food in vials for 12 h (8 P.M.–8 A.M.) while exposed to red light, and then transferred to DART for 12 h (8 A.M.–8 P.M.) for arousal probing. Sleep deprivation was performed using SNAP devices as described previously16, 31.

Code availability

The code used to generate the results that are reported in this study are available from the corresponding author upon reasonable request.

Data availability

The data that support the findings of this study are available from the corresponding author upon reasonable request.