Skip to main content
STAR Protocols logoLink to STAR Protocols
. 2026 Jun 25;7(3):104659. doi: 10.1016/j.xpro.2026.104659

Protocol for simultaneous in vivo two-photon imaging and locomotion quantification during olfactory stimulation and pharmacology in walking Drosophila

Qiantao Lv 1,2,3,4,5,∗, Yunming Gao 2,3,4, Jing Ning 2,3,4, Yi Sun 1,2,3,4,6,∗∗
PMCID: PMC13333336  PMID: 42348421

Summary

To decipher the circuit and molecular mechanisms underlying neural information processing, it is essential to manipulate cellular targets while simultaneously recording neural activity and behavior during sensory stimulation. Here, we present a protocol for Drosophila that temporally synchronizes olfactory stimulation and pharmacological intervention with in vivo recording as well as locomotion measurement. We detail step-by-step workflows for head-fixed walking flies, including fly preparation, surgery, two-photon imaging, and locomotion detection, providing instructions for surgery station, odor stimulator, and perfusion system setup.

Subject areas: Microscopy, Model Organisms, Neuroscience

Graphical abstract

graphic file with name ga1.jpg

Highlights

  • •

    Protocol for synchronized imaging, pharmacology, odor stimulation, and behavior tracking

  • •

    Integrating sensory input and motor output with neural measurement and manipulation

  • •

    Instructions for configuring the surgery station, olfactometer, and perfusion system


Publisher’s note: Undertaking any experimental protocol requires adherence to local institutional guidelines for laboratory safety and ethics.


To decipher the circuit and molecular mechanisms underlying neural information processing, it is essential to manipulate cellular targets while simultaneously recording neural activity and behavior during sensory stimulation. Here, we present a protocol for Drosophila that temporally synchronizes olfactory stimulation and pharmacological intervention with in vivo recording as well as locomotion measurement. We detail step-by-step workflows for head-fixed walking flies, including fly preparation, surgery, two-photon imaging, and locomotion detection, providing instructions for surgery station, odor stimulator, and perfusion system setup.

Before you begin

We describe protocols for in vivo two-photon imaging of head-fixed adult Drosophila, with optional modules for olfactory stimulation setup, locomotive behavior readout, and pharmacological perturbations. To validate the pharmacological perturbation module, we perfused dopamine-containing saline and recorded the responses in neurons expressing the G-protein coupled receptor activation based dopamine indicator in the adult Drosophila brain. We also delivered odor stimulation with behavior detection in walking flies. This protocol offers combined reproducible workflows for in vivo imaging with olfactory stimulation and pharmacological perturbations in adult walking flies.

Innovation

Recent advances in genetically encoded indicators enable optical readouts of calcium activity,1 neurotransmitter release,2 and intracellular dynamics.3 Imaging neural activity in head-fixed flies has been widely used, making critical contributions to our understanding of fly brain function.4,5,6,7,8,9,10 For instance, pairing imaging with sensory stimulation has revealed complex sensory representations,6,7,9 while the use of treadmill-based walking setups has uncovered the neural correlates of locomotion.5,8 Furthermore, combining sensory stimulation with head-fixed walking paradigms has proven instrumental in uncovering the mechanisms of sensorimotor integration.10 Yet transitioning from correlational observations to establishing causal relationships in vivo requires perturbation experiments. While pharmacological manipulations are routinely performed in ex vivo preparations, acute drug delivery is less commonly incorporated during ongoing in vivo imaging. Specifically, detailed protocols that integrate acute pharmacological perturbations with in vivo imaging, sensory stimulation, and treadmill-based walking behavior setup remain limited.

Transgenic fly preparation

Inline graphicTiming: 2–3 weeks

This step describes the preparation of transgenic flies for experiments.

  • 1.
    Select the driver lines required (e.g., GAL4, split-GAL4, or LexA) to label the target neurons and choose the appropriate genetically encoded indicators.
    • a.
      Collect 5–10 virgin females from the driver line and cross them with 3–5 males from the reporter line in each vial.
    • b.
      Maintain the crosses in an incubator at 25°C with 40–60 % humidity and a 12:12 h light/dark cycle.

Note: Do not place more than 15 parental flies in a single vial to avoid overcrowding.

Inline graphicCRITICAL: If one of the parental insertions is located on the X chromosome and male progeny are required, use virgin females carrying the X chromosome insertion for the cross.

  • 2.
    Collect progeny for experiments.
    • a.
      Collect newly eclosed progeny as needed to obtain age-matched flies (we used 7-day-old flies).
    • b.
      Maintain the flies under defined and consistent housing conditions.

Note: Adjust the collection schedule according to the experimental requirements.

Inline graphicCRITICAL: Select balancer-negative progeny.

Adult Drosophila external saline solution preparation

Inline graphicTiming: 1 h

Note: This saline closely follows a previously reported formulation,11 with minor adjustments.

  • 3.
    Base ionic stock solution preparation.
    • a.
      Add approximately 600 mL of deionized water to a beaker with a stir bar.
    • b.
      Add 60.19 g NaCl, 2.24 g KCl, 1.20 g NaH2PO4, 11.46 g TES, 21.84 g NaHCO3.
    • c.
      Add the reagents to the water with stirring.
    • d.
      Adjust the final volume to 1 L with deionized water, mix thoroughly.
    • e.
      Label and store at 4°C (store for no more than 1 month).

Note: NaHCO3 dissolves slowly in water. Allow extra stirring time to ensure complete dissolution.

  • 4.
    Mg2+ stock solution preparation.
    • a.
      Add approximately 600 mL of deionized water to a beaker with a stir bar.
    • b.
      Add 8.13 g MgCl2·6H2O.
    • c.
      Add the reagents to the water with stirring.
    • d.
      Adjust the final volume to 1 L with deionized water, mix thoroughly.
    • e.
      Label and store at 4°C (store for no more than 1 month).

Note: MgCl2·6H2O is highly hygroscopic and should be stored in a dry environment.

  • 5.
    Adult Drosophila external saline solution preparation.
    • a.
      Add approximately 700 mL of deionized water to a beaker with a stir bar.
    • b.
      Add 1.5 mL of 1 M CaCl2 solution.
    • c.
      Add 100 mL Mg2+ stock solution (described in step 4).
    • d.
      Add 100 mL of base ionic stock solution (described in step 3) slowly while stirring, and monitor for precipitation.
    • e.
      Add 3.78 g trehalose and 1.80 g glucose.
    • f.
      Add the reagents to the water while stirring.
    • g.
      Adjust the final volume to 1 L with deionized water, mix thoroughly.

Note: This solution can be stored for no more than one week at 4°C.

Inline graphicCRITICAL: Avoid mixing too quickly, otherwise precipitation may occur. If precipitation occurs, discard the solution and prepare a fresh one.

Pharmacology solution preparation

Inline graphicTiming: 1 h

  • 6.
    Dopamine stock solution preparation.
    • a.
      Add approximately 70 mL of deionized water to a beaker with a stir bar.
    • b.
      Add 1.90 g dopamine hydrochloride.
    • c.
      Add 0.95 g sodium metabisulfite.
      Note: Sodium metabisulfite is included to prevent oxidation of dopamine.
    • d.
      Adjust the final volume to 100 mL with deionized water and mix until fully dissolved.
    • e.
      Aliquot 1.0 mL into 1.5 mL microcentrifuge tubes and store at −20°C.
  • 7.
    Dopamine working solution preparation.
    • a.
      Thaw one 1.0 mL aliquot of 100 mM dopamine stock solution on ice.
    • b.
      Dilute the stock solution in pre-warmed adult fly external saline to the desired final concentration. (For example, add 50 μL of 100 mM stock to 50 mL saline to obtain 100 μM dopamine).

Note: Avoid repeated freeze-thaw cycles.

Note: Keep the dopamine working solution on ice, protected from light, and use it within 2 h of preparation.

Inline graphicCRITICAL: Discard the solution if discoloration is observed.

Surgery station preparation

Inline graphicTiming: Hours to days

This section describes the process for assembling a surgery station used in fly surgery (Figure 1).

  • 8.
    Bond thermoelectric modules (TEMs) to a water-cooled heat sink.
    • a.
      Identify the hot and cold sides of each TEM.
    • b.
      Apply thermally conductive adhesive to the hot side of each TEM.
    • c.
      Place the hot side of each TEM onto the water block (water-cooled heat sink) and press firmly to ensure full, even contact.
    • d.
      Allow the thermal adhesive to cure completely.

Note: We used three pieces of TEMs (XH-C1208S2, SINHE Electronic Technology). Using more modules or higher-power TEMs can improve cooling performance, depending on the station design, material, and ambient temperature. We used a customized water block (120 × 160 × 15 mm) for our setup. Other water block designs with comparable capacity are also suitable.

Note: Avoid introducing air bubbles in the thermally conductive adhesive. Even small air gaps can reduce thermal transfer efficiency.

Inline graphicCRITICAL: Verify the polarity of each TEM carefully before powering the system. Incorrect polarity may damage the module.

  • 9.
    Connect the water loop.
    • a.
      Connect the inlet and outlet of the water block to the recirculating chiller with appropriate tubing.
    • b.
      Turn on the chiller power, set the chiller to the target temperature, and establish a stable water flow.
    • c.
      Allow the chiller to run for 10 minutes.
    • d.
      Verify that the flow rate is stable, and the coolant has reached the target temperature.
  • 10.
    Build the copper stage and bridge assembly.
    • a.
      Cut a 3-5 mm thick copper plate to the required footprint (Figure 1B).
    • b.
      Fasten copper columns to the plate with screws.
    • c.
      Attach the copper bridge to the column’s pre-drilled holes and fasten with screws if necessary.
    • d.
      Place the copper plate on the TEM array. Confirm hole alignments and fasten the copper plate to the breadboard with screws.
  • 11.
    Complete the wiring and verify system operation.
    • a.
      Connect the TEMs to the DC switching power supply.
    • b.
      Connect the temperature sensor to the temperature controller.
    • c.
      Fix the temperature sensor on the copper plate with thermally conductive adhesive.
    • d.
      Set the temperature setpoint of the controller so that power to the TEMs is regulated according to the measured temperature.
    • e.
      Start the chiller and power on the temperature controller. Verify stable temperature control and continuous coolant circulation.

Inline graphicCRITICAL: Do not power the TEMs unless active coolant flow has been established.

Figure 1.

Figure 1

Surgery station assembly

(A) Photo of the surgery station and accessory parts under a stereomicroscope.

The blue box highlights the surgery station.

(B) Three-dimensional rendering of the surgery station, including (1) a fly holder, (2) a bridge with a fly-sized groove, (3) copper columns, (4) the copper plate, (5) thermoelectric module arrays, and (6) a water-cooled heat sink.

Surgery tools preparation

Inline graphicTiming: Hours to days

This section describes the preparation of tools used for fly surgery.

  • 12.
    Prepare a tungsten wire applicator for UV glue.
    • a.
      Cut a tungsten wire to the desired length.
    • b.
      Clean the wire and secure one end in a holder.
    • c.
      Shape and align the wire tip, preferably with a slight bend to facilitate glue application.
  • 13.
    Prepare and mount a fine dissection needle.
    • a.
      Retrieve a fine dissection needle carefully.
    • b.
      Insert the needle shaft into a compatible micro-holder and secure it firmly.
    • c.
      Cover the needle with a 1 mL pipette tip whenever it is not in use.

Inline graphicCRITICAL: The needle tip is extremely sharp and fragile. Avoid applying lateral force, and do not touch the tip directly. Always cover the needle with a 1 mL pipette tip when not in use. Discard damaged needles in a sharps container.

  • 14.
    Prepare fine forceps.
    • a.
      Ensure the tips of the forceps align perfectly.
    • b.
      Attach a tip protector when not in use.

Note: If needed, gently realign with a fine stone. Protect the tip of the forceps carefully.

  • 15.
    Fabricate a fly holder.
    • a.
      Laser-cut the stainless-steel shim (0.02 mm thick, SUS304) according to the template with a central aperture sized for the fly head.
    • b.
      Fold the shim along the designated lines to form a pyramidal structure.
    • c.
      Attach the pyramid to a custom aluminum holder with adhesive.
    • d.
      Allow the adhesive to cure completely.

Inline graphicCRITICAL: Seal all seams to prevent leaks. Allow the adhesive to cure fully before the leaking check.

  • 16.

    Prepare the optical UV glue.

Key resources table

REAGENT or RESOURCE SOURCE IDENTIFIER
Chemicals, peptides, and recombinant proteins

NaCl Aladdin C111538
KCl Aladdin P112144
NaH2PO4 Aladdin S108343
N-tris(hydroxymethyl)methyl-2-aminoethanesulfonic Acid (TES) Aladdin T105114
NaHCO3 Aladdin S118660
MgCl2·6H2O Aladdin M116335
CaCl2·2H2O Aladdin C118444
D-(+)-Trehalose dihydrate Aladdin T100012
D-(+)-Glucose anhydrous Aladdin D274366
Dopamine hydrochloride Sigma-Aldrich H8502
Sodium metabisulfite Sigma-Aldrich S9000

Experimental models: Organisms/strains

MB085C Bloomington Drosophila Stock Center (BDSC) 68288
UAS-gDA3h Li Y, Peking University N/A
UAS-jRGECO1a Bloomington Drosophila Stock Center (BDSC) 63794
UAS-jGCaMP7f Bloomington Drosophila Stock Center (BDSC) 79031

Software and algorithms

Illustrator Adobe RRID: SCR_010279
Python https://www.python.org/ RRID: SCR_008394
ThorImage Thorlabs N/A
ThorSync Thorlabs N/A
FicTrac V2.1.2 https://github.com/rjdmoore/fictrac N/A
CaImAn https://github.com/flatironinstitute/CaImAn N/A

Other

Two-photon microscope Thorlabs N/A
Pockels cells Conoptics N/A
Femtosecond Laser Spectra-Physics InSight X3
Dissecting forceps Dumont 0209-5-PO
Stereomicroscope Leica M80
Motorized micromanipulator Sutter Instrument MPC-325-2
Optical table Jiangxi Liansheng Technology ZDT-P-MOT-F30-15
Dissection needle World Precision Instruments 501317
Norland Optical Adhesive NOA 68 Norland #16-780
Normally-closed valve Fspump 0520D
Normally-open valve Fspump 0520C
Camera Hikvision MV-CA016-10UC
Lens Hikvision MVL-HF2528M-6MP
Dual-channel syringe pump Shanghai Lande Medical Equipment LD-P2020II
Two-position three-way solenoid valve Kamoer KVE23PL24FP3Q201
Thermoelectric modules SINHE Electronic Technology XH-C1208S2
Water-cooling aluminum cold plate Customized N/A
Recirculating chiller Shandong Huanli Electromechanical Equipment CW3000
Digital multimeter Delixi DLX-890C

Materials and equipment

Adult Drosophila external saline solution

Reagent Final concentration Amount
NaCl 103 mM 6019.32 mg
KCl 3 mM 223.65 mg
NaH2PO4 1 mM 119.98 mg
N-tris(hydroxymethyl)methyl-2-aminoethanesulfonic Acid (TES) 5 mM 1146.25 mg
NaHCO3 26 mM 2184.26 mg
MgCl2·6H2O 4 mM 812.8 mg
CaCl2·2H2O 1.5 mM 220.50 mg
D-(+)-Trehalose dihydrate 10 mM 3783.3 mg
D-(+)-Glucose anhydrous 10 mM 1801.6 mg
ddH2O N/A 1000 mL
Total N/A 1000 mL

Note: Store at 4°C for up to 1 week.

Dopamine stock solution

Reagent Final concentration Amount
Dopamine hydrochloride 100 mM 1.90 g
Sodium metabisulfite 50 mM 0.95 g
ddH2O N/A 100 mL
Total N/A 100 mL

Note: Store at −20°C for up to 2 months.

Note: Aliquot to single-use volumes and prevent repeated freeze-thaw cycles.

Dopamine working solution

Reagent Amount
Dopamine stock solution 200 μL
Adult Drosophila external saline solution 100 mL
Total 100 mL

Note: Prepare fresh solution immediately before the experiment. Keep it on ice and use within 2 h.

Step-by-step method details

Surgical preparation of adult flies for imaging

Inline graphicTiming: 10–20 min

This section describes how to tether an adult fly to the shim, expose the brain in extracellular saline, and stabilize the preparation for live imaging (Figure 2).

  • 1.
    Anesthetize and position the fly.
    • a.
      Transfer a single fly into an empty vial and place the vial on ice until the fly is immobile (typically within 20 s).
    • b.
      Gently transfer the fly onto the pre-cooled tethering station (maintained at 4°C) to maintain anesthesia.

Inline graphicCRITICAL: Do not keep the fly on ice for more than 20 s to minimize physiological perturbation.

  • 2.

    Immobilize the proboscis of the fly and secure it with low-melting wax.

  • 3.
    Tether the head of the fly to the holder (Figures 2A and 2B).
    • a.
      Place the surgery station under the stereomicroscope. Adjust the magnification and focus of the stereomicroscope until the preparation is clearly visible.
    • b.
      Mount the shim holder on a micromanipulator attached with manual rotation stage.
    • c.
      Position the fly with the abdomen facing upward. Position the posterior abdomen and most of the thorax within the groove of the copper bridge, leaving the head and a small anterior portion of the thorax beyond the groove edge.
    • d.
      Align the contour of the head precisely with the aperture of the thin stainless-steel shim.
    • e.
      Apply a minimal amount of UV glue along the perimeter of the head. Bond the head to the shim and cure the glue with UV light.

Note: This protocol can be adapted to alternative dissection geometries according to experimental needs.

  • 4.
    Tether the thorax of the fly to the holder (Figure 2C).
    • a.
      Remove the holder carrying the fly and rotate it by 180°. Remount it on the micromanipulator.
    • b.
      Adjust magnification and focus of the stereomicroscope until the field of view is clear with the fly centered.
    • c.
      Apply a small droplet of UV glue to bond the upper anterior thorax to the shim.
    • d.
      Cure the glue with UV light and confirm that the fly is securely tethered.
  • 5.
    Remove the dorsal cuticle of the fly (Figures 2C–2E).
    • a.
      Fill the fly holder with extracellular saline.
    • b.
      Use a sharp needle to gently cut the dorsal cuticle.
    • c.
      Remove the cuticle with fine forceps.
    • d.
      Carefully remove the fat tissue and push the overlying trachea aside to fully expose the brain.
    • e.
      Cut muscle 16 to minimize brain motion along the z axis.

Note: Always keep the brain immersed in adult Drosophila external saline.

  • 6.

    Remove a small section of the glial sheath with fine forceps (Figure 2E).

Note: Incomplete sheath removal may reduce drug access to the neuropil, whereas excessive contact with the underlying neuropil can cause tissue damage. Successful glial sheath removal can be functionally validated by measuring fluorescence changes induced by dopamine perfusion. For beginners, we recommend first practicing this step using flies expressing a gDA indicator, utilizing dopamine perfusion responses as a readout to test drug accessibility. Although the initial success rate depends on the operator’s experience, users typically become proficient in less than a week.

Inline graphicCRITICAL: Avoid contacting the underlying neuropil with the forceps.

  • 7.
    Allow recovery and adaptation after surgery.
    • a.
      After surgery, allow the fly to recover for approximately 10 mins.
    • b.
      Place the fly on an air-supported ball and assess locomotor activity.

Note: Exclude flies that remain inactive before imaging.

Figure 2.

Figure 2

Drosophila surgery procedure

(A) Place the anesthetized fly within the bridge groove and apply a minimal bead of UV glue to quickly tether the head to the shim.

(B) Remove the holder carrying the tethered fly from the stage.

(C) Tether the thorax of the fly to the shim with UV glue and cut the dorsal cuticle with a sharp needle.

(D) Remove the dorsal head cuticle.

(E) Remove the fat tissue and clear the trachea to expose the brain.

Scale bars, 0.5 mm.

Two-photon in vivo imaging

Inline graphicTiming: 20–30 min

This section describes the procedure for recording neural activity in the brain of walking adult fly using a two-photon microscope integrated with olfactory stimulation and pharmacological perturbations (Figure 3).

  • 8.
    Set up the perfusion system.
    • a.
      Prepare two reservoirs (bottle A and bottle B).
    • b.
      Fill bottle A with vehicle saline and bottle B with the drug working solution. Keep the two solutions in separate and clearly labeled containers.
    • c.
      Connect bottle A to a normally-open (NO) solenoid valve and connect bottle B to a normally-closed (NC) solenoid valve, with independent outlet lines for each valve.
    • d.
      Connect both valves to the same TTL output channel of the data acquisition (DAQ) board.
    • e.
      Configure the valve wiring so that a TTL-low signal keeps the NO valve open and the NC valve closed, and a TTL-high signal closes the NO valve and opens the NC valve simultaneously.
    • f.
      Deliver a series of test TTL signals while monitoring the outlet line. Confirm that the two valves switch reliably.
    • g.
      Record the TTL signals on a separate input channel of the DAQ system together with the imaging and behavioral data streams to verify synchronized switching.
  • 9.

    Prepare the dopamine working solution.

  • 10.
    Set up the olfactory stimulation system.
    • a.
      Prepare odor vials and add freshly prepared odor solutions.
      Note: Odorants can be diluted as needed depending on the desired stimulus strength. We used undiluted apple cider vinegar (Haitian) for stimulation.
    • b.
      Connect each odor vial to a solenoid valve.
      Note: We used a two-position three-way solenoid valve (Kamoer, KVE23PL24FP3Q201). Equivalent valves may also be suitable depending on the experimental setup.
    • c.
      Position the odor outlet in front of the fly.
    • d.
      Connect the valves controlling each odor line to TTL output channels on the DAQ board.
    • e.
      Deliver a series of test TTL signals and verify stable odor output.
    • f.
      Record the odor TTL signals along with imaging and behavioral data to enable precise alignment of odor delivery with neural activity and walking behavior.
  • 11.
    Set up the behavior measurement system.
    • a.
      Prepare an 8 mm diameter polyurethane foam ball and verify that the surface is smooth and that the ball is spherical.
    • b.
      Apply high-contrast random patterns to the ball surface.
      Note: Make high-contrast random patterns for computer-vision tracking.12
    • c.
      Fabricate a custom aluminum base with a central opening designed to deliver an upward stream of air.
    • d.
      Connect the base to a regulated air supply and set the airflow to approximately 0.6 L/min.
    • e.
      Place the ball on the base and confirm that the ball can rotate freely around all axes.
    • f.
      Integrate a heating element into the aluminum base and place the temperature sensor near the ball surface and connect the sensor to the temperature controller.
    • g.
      Set the controller to 31°C so that the heating element is switched on or off according to the measured temperature.
      Note: Maintaining the temperature of the ball surface at 31°C during experiments can promote fly walking.
    • h.
      Illuminate the ball with an 850 nm IR LED and adjust the intensity to optimize the image contrast.
    • i.
      Position an IR-sensitive camera to image the ball surface. Set the camera to trigger mode so that image acquisition is synchronized to the TTL signals.
    • j.
      Record the camera trigger TTL signals together with the imaging data and the TTL timing signals for perfusion and odor stimulation.
  • 12.
    Place the fly under the objective.
    • a.
      Transfer the holder carrying the tethered fly to the two-photon microscope and position it directly under the objective.
    • b.
      Position the fly on an air-supported ball. Adjust the holder so that the fly can walk freely on the ball.
    • c.
      Position the two perfusion outlets in the holder chamber. Place a gentle vacuum outlet at the opposite side of the holder chamber to maintain a stable bath level.
    • d.
      Position the odor outlet 5–10 mm in front of the antennae of the fly.
  • 13.
    Imaging parameter configuration.
    • a.
      Launch the imaging acquisition software on the microscope control workstation.
      Note: We used a customized Thorlabs two-photon microscope (Bergamo II, Thorlabs) equipped with an ultrafast laser (InSight X3, Spectra-Physics) modulated by Pockels cells (Conoptics) for image acquisition. We used a 25× water-immersion objective (CFI75 Apochromat 25XC W 1300, Nikon). For the imaging software, we used ThorImage and ThorSync (Thorlabs). Adjust the configuration described here according to the experimental requirements.
    • b.
      Set the excitation wavelength according to the indicator used.
      Note: We tuned the laser to 940 nm for gDA imaging and 1060 nm for jRGECO1a imaging.
    • c.
      Adjust the Pockels cell so that the laser power measured after the objective remains below 10 mW, unless otherwise required by the experiment.
    • d.
      Set the detector gain to obtain sufficient signals without saturation.
      Note: We used two high-sensitivity GaAsP photomultiplier tubes (PMT2100, Thorlabs) to collect the fluorescence signals. We used 525/50 nm and 607/70 nm bandpass filters for green and red fluorescence channels, respectively.
    • e.
      Set the scan to 256 × 256 pixels. Adjust the scan zoom to match the field of view to the region of interest.
      Note: We used single plane for imaging in this protocol. For experiments requiring z-stack acquisition, the z-step size should be adjusted according to the experimental requirements.
    • f.
      Adjust the stage and focal plane to locate the target neurons.
      Note: The microscopy information provided here follows the checklist for reporting multiphoton microscopy as previously described.13
  • 14.
    Capture the image sequence.
    • a.
      Set the total number of frames to acquire and set the frame interval in capture mode in ThorImage.
    • b.
      Enable logging in ThorSync for TTL signals corresponding to perfusion valve control, odor valve control, and behavior camera recording control.
    • c.
      Start image acquisition in ThorImage and record baseline activity for more than 60 s under vehicle perfusion. During this period, verify that fluorescence signals and behavioral readouts are stable.
    • d.
      After the baseline period, deliver a 60 s TTL pulse to switch perfusion from vehicle saline to dopamine solution. Within the same 60 s period, initiate odor stimulation according to the experimental design while continuing to acquire images.
    • e.
      After the stimulation period, switch perfusion back to vehicle saline and continue imaging during the washout phase for approximately 200 s.

Note: We used a dual-channel syringe pump (LD-P2020II) to maintain a constant solution flow (3 mL/min) during experiments.

  • 15.
    Perform end-of-day cleaning.
    • a.
      Remove the saline or pharmacological solution from the containers.
    • b.
      Add deionized water to the containers and perfuse with the water to thoroughly rinse the tubes and the imaging chamber.
    • c.
      Flush the odor line with clean air.

Figure 3.

Figure 3

Schematic of the odor-delivery and pharmacological perturbation system combined with in vivo two-photon imaging and locomotion monitoring in head-fixed walking flies

(A) Schematic of the experimental setup.

A head-fixed fly walks on a patterned treadmill ball while neural activity is recorded by two-photon imaging and behavior is monitored with a camera.

For pharmacological perturbations, drug-containing solution and saline are delivered through independent tubing lines controlled by normally closed (NC) and normally open (NO) valves, respectively. For olfactory stimulation, airflow regulated by a flowmeter enters either an odor vial or a control vial before delivery to the fly.

(B) TTL signals are generated and recorded by independent DAQs to control the timing of stimulation, enabling precise synchronization of odor delivery, pharmacological perturbation, two-photon imaging, and behavioral recording.

Data analysis

Inline graphicTiming: 1 h

This section describes the analysis of imaging and behavior data. For behavior data analysis, we describe how to quantify treadmill ball motion. For imaging analysis, we describe how to convert raw movies into fluorescence traces and align them to stimulation timing.

  • 16.
    Behavior data processing.
    • a.
      Load time series behavior data for each trial.
    • b.
      Open FicTrac configGui to generate ball tracking parameter. Specifically, define the ball position and the ignore regions.
    • c.
      Mount a cube on the treadmill as a visual reference, click the cube corners following the instructions in FicTrac configGui and verify that the axes are correctly aligned relative to the animal.
    • d.
      Define remaining parameters accordingly and run FicTrac. Get the computed ball tracking data file.
      Note: We ran FicTrac 2.1.2 in Windows 10 operating system equipped with an Intel Core i7-9700K 8-core CPU and 16 GB RAM. Other FicTrac versions and operating systems may also be used if they are compatible with the experimental setup.
    • e.
      Export the ball rotation data from the file and convert them to forward, lateral, and angular velocities.
      Note: The FicTrac.dat outputs are in radians. Multiply by the ball radius and account for the frame rate to convert to mm/s. Ensure that all units remain consistent throughout the analysis.
    • f.
      Exclude the trials if the fly raises legs or loses contact with the ball, as this typically produces abnormal rapid ball rotation.
    • g.
      Use the camera trigger signals and imaging frame-out signals recorded via ThorSync to align the behavioral time series with the imaging frames. Map both sets of signals to their corresponding ThorSync timestamps, and resample the imaging signals to match each camera trigger frame.
    • h.
      For repeated trials of the same condition, define t = 0 as the rising edge of the relevant TTL signal recorded in ThorSync. Extract the same pre- and post-event time window for all repeated trials.
  • 17.
    Import and preprocess the raw imaging data.
    • a.
      Load time series imaging data for each trial.
    • b.
      Apply piecewise-rigid registration to the time series imaging stack for motion correction.14,15

Note: Exclude trials with excessive motion artifacts.

  • 18.
    Imaging ROI selection.
    • a.
      Calculate the mean projection of the motion-corrected time-series stack.
    • b.
      Draw ROIs over the target neurons based on the fluorescence patterns.
    • c.
      Draw a background ROI in regions without fluorescence signals.

Note: Automated ROI segmentation can also be performed using CaImAn or other related methods.

  • 19.
    Quantify fluorescence changes.
    • a.
      For each ROI perform background subtraction first.
      F(t)=FROI(t)−FBG(t)
    • b.
      Define the baseline and calculate mean fluorescence of the baseline. n is the number of frames within the pre-stimulus baseline window (we used a 2-s window).
      F0=∑i=1nF(ti)n
    • c.
      Calculate fluorescence changes for each ROI.
      ΔF/F0(t)=F(t)−F0F0
  • 20.
    Align to stimulation or perfusion onset.
    • a.
      Load the timestamps log file for each trial.
    • b.
      Detect the rising edge of stimulation or perfusion TTL signals and map it to the nearest frame onset.
    • c.
      Align the traces for each trial.
  • 21.
    Data visualization.
    • a.
      Import the preprocessed data.
    • b.
      Compute the mean response trace for each fly for repeated trials of the same condition.
    • c.
      Compute the population-averaged traces and plot the mean ± SEM, aligned to the onset of olfactory stimulation or perfusion.
      Note: For visualization purposes, plotted traces may be smoothed using a Savitzky-Golay filter or a sliding window filter.
    • d.
      Calculate response magnitude using the area under the curve (AUC), peak ΔF/F0, or mean ΔF/F0 within a predefined time window as appropriate.
    • e.
      Apply appropriate statistical analysis as required by the experimental design.

Expected outcomes

We integrated four functional modules into one system so that we can deliver olfactory stimulation and drug delivery while recording neural activity and walking behavior simultaneously. This synchronized multi-input, multi-output system configuration enables quantitative analysis of neural dynamics and walking behavior during sensory stimulation and pharmacological perturbation. We validated each of the four modules below.

We first verified the perfusion system and functional imaging module. We used the dopamine indicator gDA3 to optically detect extracellular dopamine dynamics using a two-photon microscope. We diluted the dopamine stock in extracellular saline to a final concentration of 200 μM dopamine solution. We expressed the high-sensitivity dopamine indicator gDA3h in a specific neuron type MBON11 and recorded the fluorescence signals during pharmacological perturbations (Figures 4A and 4B). Upon switching from vehicle control to dopamine-containing saline, the fluorescence signal rose gradually after the switch onset, producing a significant increase in ΔF/F. The averaged time to half-peak was about 45 s after TTL switch onset (Figure 4C). When switched back to the vehicle control solution, the signal decayed toward baseline. Responses were reproducible across trials and across flies, although response magnitude and temporal dynamics may vary between preparations. We also perfused the vehicle control alone, and we found no systematic fluorescence change under these conditions (data not shown). To reliably detect dopamine-induced changes in dopamine indicator fluorescence signals, we found it important to remove the sheath. We barely detected any fluorescence signal change when keeping the sheath intact.

Figure 4.

Figure 4

Two-photon imaging and behavior results

(A) Schematic for in vivo two-photon dopamine imaging in a head-fixed fly walking on an air-supported ball during perfusion. IN and OUT denote inflow and outflow, respectively.

(B) Averaged MBON11 responses during dopamine perfusion across flies. Blue and gray shades at the bottom denote the dopamine and saline perfusion periods, respectively.

Errors are SEM, same as follows. (n = 12 flies).

(C) Quantification of latency to half-peak, calculated for each fly as the time elapsed from the onset of the TTL-controlled dopamine switch until the fluorescence response reaches 50% of its peak amplitude. Each dot denotes an individual fly, and the bar shows the mean ± SEM.

(D) Schematic for in vivo two-photon calcium imaging of a head-fixed fly walking on an air-supported ball during odor stimulation.

(E) Upper, averaged MBON11 calcium response dynamics to ACV odor stimulation.

Lower, forward velocity dynamics on the same timescale. (n = 7 flies).

(F) Schematic for in vivo two-photon calcium imaging of a head-fixed fly walking on an air-supported ball during simultaneous odor stimulation and perfusion.

(G) Upper, averaged MBON11 calcium response dynamics to ACV odor stimulation and dopamine perfusion across flies.

Lower, forward velocity dynamics on the same timescale. (n = 5 flies).

We also verified the sensory stimulation module and the behavior readout module. We expressed the red calcium indicator jRGECO1a in MBON11 and delivered apple cider vinegar (ACV) odor to head-fixed flies walking on an air-supported ball (Figure 4D). This neuron showed robust odor-evoked calcium transients (Figure 4E). We also measured the walking velocity of the fly during odor stimulation. We observed a transient startle in forward velocity at odor onset, followed by a gradual increase in forward velocity during odor stimulation. At the offset of the odor stimulation, the velocity returns to baseline.

We also validated the full integration of these modules. We integrated odor stimulation, dopamine perfusion, two-photon imaging, and walking-behavior recording (Figure 4F). We observed robust MBON11 responses together with clear changes in forward velocity. And the responses decay gradually, likely due to the pharmacological perfusion (Figure 4G).

Limitations

This protocol describes a multi-input, multi-output system setup and procedures for in vivo two-photon imaging, behavior readout, sensory stimulation setup, and pharmacological perturbations in head-fixed adult Drosophila. Although this protocol can be used to test how sensory inputs shape neural activity and locomotion and how pharmacological perturbations affect neural activity and behavior, there are a few limitations. First, head-fixed walking on a treadmill cannot fully recapitulate free movement conditions. Second, surgical access and partial glia sheath removal may induce perturbation to the physiological environment of the brain. Proboscis immobilization and muscle 16 excision, which are performed primarily to minimize brain motion, make it more invasive and may influence behavior, particularly behaviors involving proboscis movement. Third, exogenous application via perfusion does not precisely mimic endogenous release patterns. And the measurement of drug arrival is limited by indicator response time. In addition, compared to more localized approaches such as microinjection that can target localized compartments, whole-brain perfusion lacks spatial precision.

Troubleshooting

Problem 1

No fluorescence signal is detected under the two-photon microscope (related to Step 13).

Potential solution

  • •

    Check the crossing strategy and confirm that the correct driver and indicator lines are used.

  • •

    Confirm that the balancers chromosomes were excluded from the experimental flies.

  • •

    Verify the two-photon microscope parameters, and make sure to use the right excitation wavelength. Confirm that the shutter in the excitation light path is open.

Problem 2

Flies recover from anesthesia on the tethering stage before tethering to the holder (related to Step 1).

Potential solution

  • •

    Verify the surface temperature of the copper stage.

  • •

    Check the thermal-adhesive bonding between the TEMs and the copper plate.

  • •

    Use multiple TEM arrays to increase cooling capacity if necessary. Confirm that the temperature of the copper stage surface is maintained at approximately 4°C.

Problem 3

Leakage is observed from the holder (related to Step 5).

Potential solution

  • •

    This issue is typically caused by incomplete curing or inadequate seals. Reapply adhesive to the leaking region and allow it to cure fully.

Problem 4

The fly detaches from the UV glue during surgery (related to Step 5).

Potential solution

  • •

    Protect the UV glue ed from light and use freshly dispensed UV glue for each preparation.

  • •

    Confirm that the tip of the dissection needle is sharp enough, and replace the needle if the tip is damaged.

Problem 5

Flies show reduced behavioral response after surgery (related to Step 7).

Potential solution

  • •

    Minimize tissue damaging when cutting and removing the cuticle.

  • •

    Gently push the overlying trachea aside with fine forceps.

  • •

    Refresh the saline chamber of the fly holder with oxygenated saline.

Problem 6

Large motion artifacts are observed during imaging (related to Step 2 and Step 5).

Potential solution

  • •

    Cut the muscle 16 of the Drosophila to minimize z axis brain motion.

  • •

    Check the proboscis of the fly. Fully extend the proboscis and secure it with low-melting-point wax to prevent proboscis extension.

Problem 7

The target neuron appears damaged during imaging (related to Step 13).

Potential solution

  • •

    This issue is typically caused by long-term exposure to high laser power. Use the lowest laser power (less than 10 mW) at the specimen that gives adequate SNR.

Problem 8

No fluorescence change is observed during dopamine perfusion (related to Step 6 and Step 9).

Potential solution

  • •

    Verify the correct valve wiring and confirm that solution switching occurs as intended.

  • •

    Confirm correct expression of dopamine sensor in the target neurons.

  • •

    Confirm that a small section of the glial sheath is removed during surgery.

  • •

    Dopamine solution oxidation nay also reduce response. Prepare a fresh dopamine working solution if necessary.

Problem 9

Vehicle-only control trials show fluorescence changes (related to Step 8 and Step 12).

Potential solution

  • •

    Stabilize the bath level by placing a gentle vacuum outlet opposite the perfusion inlet to maintain a constant bath volume in the chamber.

Problem 10

Visible cellular deformation is observed under the microscope (related to Step 6).

Potential solution

  • •

    This issue is likely caused by excessive contact between the forceps and underlying neuropil during desheathing. Discard the preparation and start with a new fly.

Resource availability

Lead contact

Further information and requests for resources and reagents should be directed to and will be fulfilled by the lead contact, Yi Sun (sunyi@westlake.edu.cn).

Technical contact

Further information on executing this protocol should be directed to and will be answered by the technical contact, Yi Sun (sunyi@westlake.edu.cn).

Materials availability

This study did not generate new unique reagents.

Data and code availability

Our pipeline code is available at the following website: https://github.com/SunLabWestlake/cia.

Acknowledgments

We thank Y. Li for sharing gDA3 flies; Y. Wang, Y. Guo, and S. Cao from the Biomedical Research Core Facilities at Westlake University for assistance with fly-food preparation; and members of Sun lab for helpful suggestions. This work was supported by the Research Center for Industries of the Future of Westlake University (WU2022C011), the Westlake Laboratory of Life Sciences and Biomedicine (W101386022101), and Westlake Education Foundation to Y.S.

Author contributions

Q.L. and Y.S. designed the protocol. Q.L. implemented the original protocol. Y.G. and J.N. tested the protocol in various experimental conditions and provided feedback for optimization. Q.L. and Y.S. wrote and revised the manuscript with comments from all authors.

Declaration of interests

The authors declare no competing interests.

Contributor Information

Qiantao Lv, Email: lvqiantao@westlake.edu.cn.

Yi Sun, Email: sunyi@westlake.edu.cn.

References

  • 1.Dana H., Sun Y., Mohar B., Hulse B.K., Kerlin A.M., Hasseman J.P., Tsegaye G., Tsang A., Wong A., Patel R., et al. High-performance calcium sensors for imaging activity in neuronal populations and microcompartments. Nat. Methods. 2019;16:649–657. doi: 10.1038/s41592-019-0435-6. [DOI] [PubMed] [Google Scholar]
  • 2.Zhuo Y., Luo B., Yi X., Dong H., Miao X., Wan J., Williams J.T., Campbell M.G., Cai R., Qian T., et al. Improved green and red GRAB sensors for monitoring dopaminergic activity in vivo. Nat. Methods. 2024;21:680–691. doi: 10.1038/s41592-023-02100-w. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 3.Wang L., Wu C., Peng W., Zhou Z., Zeng J., Li X., Yang Y., Yu S., Zou Y., Huang M., et al. A high-performance genetically encoded fluorescent indicator for in vivo cAMP imaging. Nat. Commun. 2022;13:5363. doi: 10.1038/s41467-022-32994-7. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 4.Mann K., Gallen C.L., Clandinin T.R. Whole-Brain Calcium Imaging Reveals an Intrinsic Functional Network in Drosophila. Curr. Biol. 2017;27:2389–2396.e4. doi: 10.1016/j.cub.2017.06.076. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 5.Brezovec B.E., Berger A.B., Hao Y.A., Chen F., Druckmann S., Clandinin T.R. Mapping the neural dynamics of locomotion across the Drosophila brain. Curr. Biol. 2024;34:710–726.e4. doi: 10.1016/j.cub.2023.12.063. [DOI] [PubMed] [Google Scholar]
  • 6.Someya M., Liu K.Y., Ohta K., Kazama H. Distinct circuit motifs evaluate opposing innate values of odors. Cell. 2025;188:6892–6906.e22. doi: 10.1016/j.cell.2025.08.032. [DOI] [PubMed] [Google Scholar]
  • 7.Pacheco D.A., Thiberge S.Y., Pnevmatikakis E., Murthy M. Auditory activity is diverse and widespread throughout the central brain of Drosophila. Nat. Neurosci. 2021;24:93–104. doi: 10.1038/s41593-020-00743-y. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 8.Schaffer E.S., Mishra N., Whiteway M.R., Li W., Vancura M.B., Freedman J., Patel K.B., Voleti V., Paninski L., Hillman E.M.C., et al. The spatial and temporal structure of neural activity across the fly brain. Nat. Commun. 2023;14 doi: 10.1038/s41467-023-41261-2. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 9.Gauthey W., Lin A., Ahmed O.M., Leifer A.M., Murthy M., Thiberge S.Y. High-speed whole-brain imaging in Drosophila. Nat. Commun. 2026 doi: 10.1038/s41467-026-72437-1. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 10.Turner M.H., Krieger A., Pang M.M., Clandinin T.R. Visual and motor signatures of locomotion dynamically shape a population code for feature detection in Drosophila. eLife. 2022;11 doi: 10.7554/eLife.82587. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 11.Sun Y., Nern A., Franconville R., Dana H., Schreiter E.R., Looger L.L., Svoboda K., Kim D.S., Hermundstad A.M., Jayaraman V. Neural signatures of dynamic stimulus selection in Drosophila. Nat. Neurosci. 2017;20:1104–1113. doi: 10.1038/nn.4581. [DOI] [PubMed] [Google Scholar]
  • 12.Moore R.J.D., Taylor G.J., Paulk A.C., Pearson T., van Swinderen B., Srinivasan M.V. FicTrac: A visual method for tracking spherical motion and generating fictive animal paths. J. Neurosci. Methods. 2014;225:106–119. doi: 10.1016/j.jneumeth.2014.01.010. [DOI] [PubMed] [Google Scholar]
  • 13.Montero Llopis P., Senft R.A., Ross-Elliott T.J., Stephansky R., Keeley D.P., Koshar P., Marqués G., Gao Y.S., Carlson B.R., Pengo T., et al. Best practices and tools for reporting reproducible fluorescence microscopy methods. Nat. Methods. 2021;18:1463–1476. doi: 10.1038/s41592-021-01156-w. [DOI] [PubMed] [Google Scholar]
  • 14.Giovannucci A., Friedrich J., Gunn P., Kalfon J., Brown B.L., Koay S.A., Taxidis J., Najafi F., Gauthier J.L., Zhou P., et al. CaImAn an open source tool for scalable calcium imaging data analysis. eLife. 2019;8 doi: 10.7554/eLife.38173. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 15.Pnevmatikakis E.A., Giovannucci A. NoRMCorre: An online algorithm for piecewise rigid motion correction of calcium imaging data. J. Neurosci. Methods. 2017;291:83–94. doi: 10.1016/j.jneumeth.2017.07.031. [DOI] [PubMed] [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Data Availability Statement

Our pipeline code is available at the following website: https://github.com/SunLabWestlake/cia.


Articles from STAR Protocols are provided here courtesy of Elsevier

RESOURCES