Strains used in this study

AZS163 (gpa-6::GCaMP3, pha-1::PHA-1; lite-1;pha-1) was generated by crossing PS6390 with AZS43 (lite-1(ce314); pha-1(e2123)).

AZS164 (gpa-6::GCaMP3, pha-1::PHA-1; lite-1; pha-1; unc-13(s69)) was generated by crossing BC168 with AZS163.

AZS165 (gpa-6::GCaMP3, pha-1::PHA-1; lite-1; pha-1; unc-31(e928)) was generated by crossing AZS163 with AZS68 (unc-31(e928); pha-1(e2123)).

AZS281 (gpa-6::GCaMP3, str-2::GCaMP3,;str-2::dsRed; pha-1::PHA-1; pha-1; lite-1), where GCaMP is expressed in AWA neurons and in AWCON. We first generated AZS162 (str-2::GCaMP3, str-2::dsRed pha-1::PHA-1; pha-1; lite-1) and then crossed with AZS163.

AZS256 (gpa-6::GCaMP3, mod-1::GCaMP3; pha-1::PHA-1; pha-1; lite-1) was generated by injecting both constructs into the double mutant.

CX16573 (ky5662[odr-7::Chrimson::SL2::mCherry,elt-2::mCherry]; kyIs587[gpa-6::G-CaMP2.2b, coel::dsRed])39.

All strains were grown on NGM plates seeded with overnight culture of OP 50 according to Brenner53. L4 worms were picked aside the day before the experiment so that all experiments were performed on young adult animals at 20 °C.

Microfluidic-based system for generating smooth gradients

We developed a microfluidic-based system that allows generating a large variety of smooth temporal gradients (Fig. 1a). In this system, we control two syringe pumps (Chemyx fusion 400) using custom-made MATLAB code (Mathworks © Inc.). One pump holds a syringe with the chemical cue mixed with Rhodamine. The second pump holds a syringe filled with the diluting buffer (chemotaxis buffer (CTX)8). Importantly, Rhodamine alone did not elicit neural responses (Supplementary Fig. 14). Moreover, minute worm movements inside the microfluidic channel did not affect the observed neural responses as these displacements were uncorrelated to the pulsatile activity (\(\bar \rho = 0.05\), Wilcoxon signed-rank test, p = 0.15, Supplementary Fig. 15). To verify accurate continuous flow of the gradient, and to avoid possible pressure buildup in the system, we used glass syringes (1000 series GASTIGHT, Hamilton).

Of note, diffusion, and possibly other fluid-flow processes in the tubing, causes a minute amount of the cue to arrive before its expected time based on calculation. This results in a neural response which may be observed up to 1 min ahead of its expected time. An example of such a case can be seen in Fig. 1d. Importantly, this is only a start-of-the-experiment effect, which does not affect the gradients to follow during the experiment. As soon as detectable levels of rhodamine enter the field of view, we can reliably quantitate them and accurately infer diacetyl concentrations at any given second (Fig. 1a).

Both syringes flow through Tygon tubing (0.02' ID, Qosina Crop.) into a mixing chamber (of either 50 or 200 µL volume) with a small magnetic pole inside. The chamber is placed on a magnetic stirrer which ensures thorough mixing inside the chamber. The chamber output flows into a simple microfluidic device where the worm is restrained with its nose protruding to the flow channel (Fig. 1a). The microfluidic device is placed under the microscope for continuous imaging of the target neurons. Supplementary Note 1 includes a detailed description of the parameters used to generate each of the gradients presented in this study, along with the mathematical dynamical modeling of the system. In addition, the online information provides guidelines for the possible gradients one can generate using this system.

Preparing worms and media

Prior to imaging experiments, worms were placed on empty NGM plates (w/o OP 50) for a short starvation period (30–60 min). Following a wash in CTX, we inserted the worm into the microfluidic device designed with a short and wide flowing channel (L = 5 mm, W = 0.5 mm, h = 35 μm) to flow the gradients through the tip of the nose of a constrained worm. The wide channel reduces flow resistance and thereby increases gradient accuracy.

We used two syringes as the input to the mixing chamber, a ‘Buffer’ syringe and a ‘Stimulus’ syringe (Fig. 1a). The ‘Buffer’ syringe contained CTX buffer with 0.12 µM diacetyl. The purpose of this initial basal concentration in the buffer syringe was to increase accuracy of the flowing gradients by reducing possible noise and variability due to minute flow fluctuations.

The ‘Stimulus’ syringe contained diacetyl (1.15 or 0.115 mM) diluted in the CTX buffer. To verify the accuracy of stimulus gradients we added to the ‘Stimulus’ syringe a Rhodamine dye (0.2–1 μM). Sequential imaging in the red channel (for Rhodamine) and the green channel (for GCaMP signal) provided high-temporal resolution measurements of the gradient throughout the experiment.

To further increase measurement accuracy we reduced the effect of worm movement by adding 10 mM Levamisole (Sigma, CAS Number: 16595-80-5), similarly to previous reports54. Importantly, the addition of levamisole did not affect the pulsatile activity as similar results were obtained when using un-anesthetized worms (Supplementary Fig. 16 and Supplementary Movie 7).

Imaging single neurons

Imaging one of the pair of AWA neurons was done using an Olympus IX-83 inverted microscope equipped with a Photometrics EMCCD camera and a 40× magnification (0.95 NA) Olympus objective. A dual band filter (Chroma 59012) and a 2-leds illumination source (X-cite, Lumen Dynamics) were used to allow fast iterative imaging of both green and red channels sequentially. Hardware was controlled using Micro-Manager55. AWA activation (green) and the Rhodamine concentration (red) were each imaged at a rate of 1.4 frames/s. We then developed in-house MATLAB scripts to analyze the movies and to extract neural activity. Notably, imaging at 1.4 Hz was indeed sufficient to reliably capture the pulsatile calcium dynamics (Supplementary Fig. 17).

Imaging several neurons simultaneously

Imaging of several neurons simultaneously was done using a Nikon AR1 + fast-scanning confocal system controlled by the Nikon NIS-elements software. We used a water-immersed 40× Nikon objective (1.15 NA) for imaging at a frame rate of 1.4 volumes/s. Pinhole opening was 1.2 Airy units and z slice jumps were ~0.7 µm. We then developed in-house MATLAB scripts to analyze the movies and to extract neural activity.

Imaging freely behaving worms during chemotaxis

For these experiments, we developed a software package based on the Micromanager55 software suite for tracking and fluorescence imaging using a commercially available microscope setup. The code utilizes a motorized stage and a light source to track the worm while exciting and imaging its calcium sensor in 10× magnification. The code for this system, together with a detailed description of the entire system, can be found in our lab’s github repository: https://github.com/zaslab/FreelyMovingNeuronTracker. In this study, we used an Olympus IX-83 inverted microscope, with a 10× UPLASAPO objective, Lumen-Dynamics’ X-Cite light source, Prior H117 motorized stage and Photometrics Evolve 512 camera.

We always assayed young adult animals following a short starvation period (30–60 min). A single worm was placed in a 5 µL CTX drop on an NGM agar plate at a distance of 30 mm from a 1 µL drop of diacetyl (1.2 Molar). To prevent external perturbations to the gradient, we concealed the experimental arena: we first placed 1 mm PDMS spacers on two opposing edges of the agar arena, along the formed gradient, and then placed on them a 43 × 50 mm glass coverslip. The coverslip did not come in contact with the agar but was 1 mm above it and the imaged worm. Given that the diffusion constant of diacetyl is \(D \approx 9\, {\rm{mm}}^2/{\rm{s}}\) (calculated based on its molecular mass), it should take roughly \(t = \frac{{L^2}}{D} = 30\,{\rm{s}}\) for the gradient to stabilize once the coverslip is placed. The worm was kept in the 5 µL droplet for approximately 3 min before the droplet evaporated, giving the diacetyl gradient enough time to stabilize.

Once the CTX drop evaporated and the worm emerged out of it, we started imaging (frame rate of 2 Hz). We then analyzed the movies using custom-made MATLAB software to extract neuron activity together with the worm position in relation to the chemical source. For accurate determination of worm trajectories, and to compensate for the wide-angle head swings during movement, we smoothed worm tracks (Supplementary Fig. 18) with a smoothing spline, that uses a least-squares approach with penalization for roughness56,57.

Analyses of high-throughput behavioral chemotaxis data

We used previously published data9 to analyze the turning rate of worms given their bearing in relation to the chemical source. In each of those experiments, approximately 100 worms were placed on one vertex of equilateral triangle with edge lengths of 4 cm, while diacetyl and dilution buffer were placed on the other two vertices. Tracking was done using the Multi Animal Tracker software suite9.

Light-activating AWA neurons in freely moving animals

Worms expressing the Chrimson channel in the AWA neurons39 were picked at the L4 larval stage and separated into two groups. One group was picked into an NGM plate supplemented with 1 mM all trans-retinal (ATR, 100 mM stock was diluted 1:100 into E. coli OP50 prior to plate seeding). The second control group was picked to a NGM plate seeded with E. coli OP50 only. The following day, worms were randomly picked from either plate and subjected to three trials of behavioral analyses. During each trial we waited until the worm started a run and then exposed it for 10 s of green light (wavelength 545 nm, Bandwidth 25 nm, Intensity 14 mW/cm2). During these 10 s, we inspected whether the worm performed a reversal. Interval between consecutive trials for the same worm was at least 15 s. Importantly, the experimenter was blind to the worm’s group.

Simulating chemotaxis performance

We contrasted the performance of two chemotaxis strategies: The first obeys the sign of the first derivative only, and hence follows the classical biased-random walk strategy. The second strategy implements on top of the first strategy the ability to adapt to the first derivative of the gradient. These simulations were intended to examine the possible benefits that arise from adapting to the magnitude of the experienced first derivative, rather than simulating a fully-detailed model in attempt to fit the experimental observations. We therefore simplified our model as much as possible, and included only the parameters necessary to contrast between the two strategies. Supplementary Note 2 provides a detailed description of the simulation, including an analytical solution for the case of linear gradients.

Variability and individuality in neural responses

To analyze the variability of the pulsatile responses, a total of 92 discrete pulses were compiled from 10 different worms responding to a linear gradient (Fig. 1g depicts responses from 6 of the worms). To test whether each worm is characterized by significantly different pulse properties, we first calculated the standard deviations of different pulse parameters (namely amplitude, and pulse decay time) for each worm. We then shuffled all 92 pulses between the 10 worms, thus assigning each worm a random set of pulses, but each worm consisted with the same number of pulses it originally had. For this random set, we calculated the mean standard deviations for each of the pulse parameters and compared it to the mean standard deviations obtained for the original data. The results of this bootstrap analysis showed that the standard deviations of the random shuffles (N =1 06 in total) are significantly higher than those of the original data (p ≤ 10e−6). This analysis demonstrates that each worm responds with a characteristic pulsatile activity (which may suggest worm individuality) that is significantly different from pulses observed in other worms (population variability). Similar analysis was used to compare pulses amplitude and peak to peak time (p ≤ 10e-6, Supplementary Fig. 1).

Plotting neural activity

Raster plots of neural activity are presented as heat maps (Figs. 1c, e, 2c, 3a, 4b, c, Supplementary Figs. 2a, b, 8a, 16). The values were normalized per each neuron (row) to range between 0–1: \([{\rm{val}} - \min \left( {{\rm{val}}} \right)]/[\max \left( {{\rm{val}}} \right) - \min \left( {{\rm{val}}} \right)]\)

First derivative adaptation

Neural activity within each worm was first normalized as described above. We then calculated the mean activity in each worm during the 2.5 min before and after the point of maximal first derivative. A non-parametric Wilcoxon signed rank test was used to compare the mean values of these two time periods (results are shown in Fig. 3).

Pulse analyses

To extract the parameters of individual pulses, (Figs. 1f, g, 4e, Supplementary Figs. 1, 3, 7, 16), we marked them manually. When pulse amplitude normalization was required (Supplementary Fig. 7), it was done for each pulse in respect to the other pulses observed in the same worm according to\({\mathrm{normalized}}\,{\mathrm{amplitude}} = \left. {\left[ {{\mathrm{amplitude}} - \min \left( {{\mathrm{amplitude}}} \right)} \right]{\mathrm{/max}}\left( {{\mathrm{amplitude}}} \right)} \right]\)Peak to peak time was similarly normalized.

Code availability

The code for imaging freely moving animals as well as the code for the simulations can be found in the github repository: https://github.com/zaslab/. Any additional data information is available upon request.

Data availability

The mean fluorescence values of the AWA neuron and the measured gradients throughout the experiments are available under the Open Science Framework.