## Abstract

Behavioral strategies employed for chemotaxis have been described across phyla, but the sensorimotor basis of this phenomenon has seldom been studied in naturalistic contexts. Here, we examine how signals experienced during free olfactory behaviors are processed by first-order olfactory sensory neurons (OSNs) of the *Drosophila* larva. We find that OSNs can act as differentiators that transiently normalize stimulus intensity—a property potentially derived from a combination of integral feedback and feed-forward regulation of olfactory transduction. In olfactory virtual reality experiments, we report that high activity levels of the OSN suppress turning, whereas low activity levels facilitate turning. Using a generalized linear model, we explain how peripheral encoding of olfactory stimuli modulates the probability of switching from a run to a turn. Our work clarifies the link between computations carried out at the sensory periphery and action selection underlying navigation in odor gradients.

## eLife digest

Fruit flies are attracted to the smell of rotting fruit, and use it to guide them to nearby food sources. However, this task is made more challenging by the fact that the distribution of scent or odor molecules in the air is constantly changing. Fruit flies therefore need to cope with, and exploit, this variation if they are to use odors as cues.

Odor molecules bind to receptors on the surface of nerve cells called olfactory sensory neurons, and trigger nerve impulses that travel along these cells. While many studies have investigated how fruit flies can distinguish between different odors, less is known about how animals can use variation in the strength of an odor to guide them towards its source.

Optogenetics is a technique that allows neuroscientists to control the activities of individual nerve cells, simply by shining light on to them. Because fruit fly larvae are almost transparent, optogenetics can be used on freely moving animals. Now, Schulze, Gomez-Marin et al. have used optogenetics in these larvae to trigger patterns of activity in individual olfactory sensory neurons that mimic the activity patterns elicited by real odors. These virtual realities were then used to study, in detail, some of the principles that control the sensory navigation of a larva—as it moves using a series of forward ‘runs’ and direction-changing ‘turns’.

Olfactory sensory neurons responded most strongly whenever light levels changed rapidly in strength (which simulated a rapid change in odor concentration). On the other hand, these neurons showed relatively little response to constant light levels (i.e., constant odors). This indicates that the activity of olfactory sensory neurons typically represents the rate of change in the concentration of an odor. An independent study by Kim et al. found that olfactory sensory neurons in adult fruit flies also respond in a similar way.

Schulze, Gomez-Marin et al. went on to show that the signals processed by a single type of olfactory sensory neuron could be used to predict a larva's behavior. Larvae tended to turn less when their olfactory sensory neurons were highly active. Low levels and inhibition of activity in the olfactory sensory neurons had the opposite effect; this promoted turning. It remains to be determined how this relatively simple control principle is implemented by the neural circuits that connect sensory neurons to the parts of a larva's nervous system that are involved with movement.

## Main text

### Introduction

Chemosensation is an evolutionarily ancient sense found in nearly every living organism. In bacteria, chemotaxis allows individual cells to detect the presence of food and to accumulate in its vicinity. Multicellular organisms have evolved complex sensory systems to track temporal changes in the concentration of volatile odorant molecules relevant to their survival—food odors, pheromones associated with the presence of conspecifics and substances signaling danger. In turn, sensory perception drives behavioral strategies to forage, locate a mating partner and actively avoid danger (Fraenkel and Gunn, 1961; Schöne, 1984). Bacterial chemotaxis represents the archetype of orientation behavior in unicellular organisms: phases of relatively straight motion—called *runs*—alternate with changes in orientation—called *tumbles*—that randomize the direction of the next run (Berg, 2004). Accumulation near the source of an attractive chemical results from the elongation of runs in the direction of the gradient. In multicellular organisms, olfactory behaviors have been investigated in detail in the nematode *Caenorhabditis elegans* (Bargmann, 2006a), which uses a combination of undirected turns (‘pirouettes’) and continuous correction of the orientation of individual runs (‘weathervaning’) (Iino and Yoshida, 2009; Lockery, 2011). The neural computations enabling animals with a central nervous system to orient in odor gradients, however, remain poorly understood.

The *Drosophila* larva has the smallest known olfactory system analogous to that of vertebrates (Cobb, 1999; Bargmann, 2006b; Gerber and Stocker, 2007; Vosshall and Stocker, 2007). The larva achieves robust odor gradient ascents through an alternation of approximately straight runs and turning events (Gomez-Marin et al., 2011; Gershow et al., 2012). The duration of runs is modulated by the sensory input: runs up the gradient are elongated while runs away from it are shortened (Gomez-Marin et al., 2011; Gershow et al., 2012). Although published results hint at how larval chemotaxis may be achieved (Gomez-Marin and Louis, 2012, 2014), a quantitative model of the underlying sensorimotor integration is still missing. Here, we focus on the primary task of the orientation algorithm common to bacteria, *C. elegans*, and *Drosophila*: the control of run duration (Bargmann, 2006a; Lockery, 2011; Gomez-Marin and Louis, 2012). It is known that turns are preceded by stereotyped decreases in odor concentration (Gomez-Marin et al., 2011; Gomez-Marin and Louis, 2012), but the key question of how concentration differences are computed is unresolved.

In both insects and vertebrates, odor concentrations are represented by time-varying patterns of activity distributed across the olfactory sensory neuron (OSN) population (Wilson and Mainen, 2006; Wilson, 2013; Masse et al., 2009; Mainland et al., 2014; Uchida et al., 2014). Nonetheless, animals with an olfactory system genetically reduced to a single functional OSN are still capable of robust chemotaxis (Fishilevich et al., 2005; Louis et al., 2008), implying that the mechanisms of odor concentration detection can be understood at the level of single OSNs. Here, we rely on this simplification to develop a novel larval preparation in which the neural computations underlying odor gradient ascent can be understood in unprecedented detail. We used optogenetics in larvae with a single type of functional OSNs to substitute turbulent olfactory signals with well-controlled light stimulations (Suh et al., 2007; Bellmann et al., 2010; Smear et al., 2011; Gaudry et al., 2013). This allowed us to characterize the modulatory effects of OSN firing patterns on the probability of switching from a run to a turn. Toward this goal, we developed a novel tracker to create virtual olfactory realities (Kocabas et al., 2012) in which optogenetic stimulations of genetically targeted OSNs are defined based on the behavioral history of the larva. We used this technology to derive a phenomenological model of the OSN transfer function. The model was validated on free behavior in sensory landscapes designed to produce predictable sensorimotor responses, and ultimately, it was found to be applicable to real odor gradients. We found that for positive gradients, the OSN operates as a slope detector: its activity increases with the stimulus derivative, which suppresses the probability of turning. For strongly negative gradients, the OSN acts like an OFF detector: the inhibition of the neural activity facilitates turning in a nearly deterministic manner. Altogether, our results advance our understanding of how peripheral odor encoding guides action selection during chemotaxis.

### Results

#### Run-to-turn transitions as a paradigm for action selection

Odors are generally attractive to *Drosophila* larvae (Cobb, 1999). Exposure to an odor produces gradient ascent even in larvae with a genetically manipulated olfactory system reduced to a single OSN (Fishilevich et al., 2005; Louis et al., 2008). We examined the behavior of larvae with a single functional OSN expressing Or42a, an odorant receptor with a well-characterized tuning profile that includes the odorant isoamyl acetate (IAA) (Fishilevich et al., 2005; Kreher et al., 2008; Asahina et al., 2009). Behavior was studied in a closed environment with a single source of IAA suspended from the ‘ceiling’ of the arena (Figure 1 and ‘Materials and methods’). For large odor droplets, diffusion from the source creates a radially symmetric gradient that can be approximated by a stationary Gaussian distribution (Louis et al., 2008). For smaller odor droplets such as those used in the present study, the temporal evolution of the odor gradient cannot be neglected. We therefore combined infrared spectroscopy (IR) and a partial differential equation (PDE) model to experimentally reconstruct the two-dimensional geometry of the odor gradient over time (see Figure 1B and ‘Materials and methods’). The simulated odor gradient served as a template to reconstruct the average stimulus time course experienced by the larva during real trajectories (Figure 1C).

Figure 1A presents a trajectory consisting of approximately straight segments (‘runs’) punctuated by large changes in orientation (‘turns’). Where to turn to is determined through lateral exploratory head movements, ‘head casts’, during which the larva scans the local odor gradient (Gomez-Marin et al., 2011; Gershow et al., 2012). On average, larvae terminate their runs when motion is directed down the gradient where the odor concentration is decreasing (Gomez-Marin et al., 2011; Gershow et al., 2012). In contrast, turns are suppressed when the direction of motion is along the gradient and the odor concentration is increasing. We sought to define the neural computations underlying this behavior by characterizing the neural activity of the *Or42a*-expressing OSN in response to changes in odor concentration experienced during chemotactic behavior (Figure 1C).

#### Peripheral representation of naturalistic olfactory stimuli in a single larval OSN

To probe the input–output transfer function of the *Or42a* OSN, we devised an extracellular recording technique based on the suction of the antennal nerve into a glass pipette downstream from the dorsal organ (DO) ganglion (Figure 2A and ‘Materials and methods’). With the use of an optogenetic spike-sorting strategy we identified the spikes originating from the *Or42a* OSN expressing channelrhodopsin (ChR2) (denoted as ‘*Or42a*>ChR2 OSN’) (Figure 2B,C and ‘Material and methods’). We devised a customized olfactometer to produce odor stimuli with controlled temporal profiles (Figure 2A) with which we examined the response of the *Or42a*>ChR2 OSN to a concentration replay defined by the stimulus time course associated with the trajectory shown in Figure 1A. Recordings from this 3-min stimulation led to consistent patterns of neural activity in different preparations (Figure 2D). Although the OSN activity appeared to follow the envelope of the stimulus time course, a closer examination revealed greater complexity in the neural response. The OSN firing rate displayed a clear amplification of changes in stimulus intensity, as illustrated by the activity associated with the replay of two consecutive runs, R1 and R2 (Figure 2F). Run R2 brought the larva close to and then beyond the peak of the gradient. When stimulated by the corresponding time course of the odor concentration, OSN activity peaked several seconds before the stimulus intensity (Figure 2F, arrows). Minute fluctuations in odor concentration were strongly amplified in the OSN spiking dynamics (bursts marked by a sharp # symbol in Figure 2F).

#### Characterization of the features encoded by a single larval OSN stimulated by controlled olfactory signals

To tease apart the sensory features encoded by the *Or42a*>ChR2 OSN, we examined the OSN response induced by a set of controlled odor ramps with a temporal profile analogous to the run sequence described in Figure 2F. As a first approximation, we used linear ramps with symmetrical 8-s rising and falling phases. During the rising phase of the ramp, the neural activity increased in proportion with the derivative of the odor concentration (Figure 3A). During the falling phase of the ramp, the firing rate appeared to be driven by the stimulus intensity rather than the stimulus derivative (Figure 3B), suggesting that the response properties of the OSN differed for positive and negative gradients.

To assess the slope sensitivity of the OSN, we compared the neural activity elicited by nonlinear ramps in which the first derivative of the stimulus changed over time (Figure 3C). In an exponential ramp, the stimulus derivative increased throughout the rising phase of the ramp. This acceleration correlated with a continuous increase in spiking activity. To further test the hypothesis that the OSN encodes features related to the slope of the stimulus, we examined a sigmoid ramp (Figure 3C, right panel) for which the first derivative of the stimulus reached its maximum (gray arrow) prior to the stimulus intensity (magenta arrow). Consistent with the slope-sensitivity hypothesis, the OSN spiking activity peaked with the first derivative and not the absolute intensity of the stimulus. During the falling phase of the ramps, the OSN firing rate behaved in a way that could not be predicted from the slope sensitivity observed during the rising phase. At the end of the falling phase, OSN activity decreased below baseline (star signs * in Figure 3C), suggesting offset inhibition similar to that observed in OSNs of adult flies (Hallem et al., 2004; Nagel and Wilson, 2011). Our findings on the features encoded by the OSN were corroborated by responses elicited by other odor ramps (Figure 4—figure supplement 1).

We attempted to model the input–output relationship of the OSN by following a linear system-identification approach (Chichilnisky, 2001). To this end, we applied an M-sequence (pseudorandom binary sequence with nearly flat frequency spectrum) and reverse-correlation (Geffen et al., 2009), but discovered that the resulting linear filter was insufficient to account for the firing patterns elicited by naturalistic stimuli (‘Materials and methods’). We thus turned to dynamical systems theory to capture the nonlinear characteristics of the OSN response. We developed a biophysical model that accounts for the slope-sensitivity of the OSN during stimulus upslopes, proportionality response and offset inhibition during downslopes (Figure 4).

#### Phenomenological model of the olfactory transduction cascade

Negative feedback is known to play an important regulatory function in sensory transduction. Integral feedback control underlies perfect adaption in bacterial chemotaxis (Yi et al., 2000). In vertebrates, the olfactory transduction cascade involves a metabotropic pathway downstream from a G-protein coupled receptor (GPCR) that features negative regulatory feedback (Kaupp, 2010; Pifferi et al., 2010). As with phototransduction, adaptive features of the olfactory transduction cascade in vertebrate can be accounted for by integral feedback (De Palo et al., 2012; De Palo et al., 2013). Even though invertebrate olfaction does not rely on GPCR signaling (Kaupp, 2010), the existence of negative feedback on the odorant receptor has been postulated for olfactory transduction in adult-fly OSNs (Nagel and Wilson, 2011). This conclusion was drawn from a biophysical model that combined a linear filter accounting for the OSN spiking dynamics with a kinetic formalism to describe ligand–receptor interactions. Research in the moth has revealed a different regulatory mechanism that constitutes an ‘incoherent feed-forward’ loop (Alon, 2007) in which the activity of the odorant receptor has a dual effect on the OSN spike rate (Gu et al., 2009): (1) on a short timescale, the inflow of cations increases the firing rate; (2) on a longer timescale increasing concentration of intracellular calcium ions inhibits the OSN firing rate through a pathway that involves the binding of calcium to calmodulin.

Combining the previous ideas, we hypothesized that the OSN spiking activity is regulated by a negative feedback loop (or integral feedback, IFB) coupled with an incoherent feed-forward loop (IFF) (Figure 4A and ‘Materials and methods’). In what follows, this composite model will be denoted as IFB+IFF (Figure 4Bi). Using a mass-action-kinetics formalism originally developed for genetic networks (Ackers et al., 1982; Bintu et al., 2005), each of the two regulatory motifs was described by a system of two ordinary differential equations (ODEs) with three variables (Figure 4Bii): *x*, the stimulus strength (input: odor concentration or light intensity), *y* the instantaneous firing rate of the OSN (output), and *u*, a phenomenological variable that might represent the intracellular concentration of calcium. The free parameters of the model were determined through a simplex algorithm which optimized the fit between the experimental spiking activity of the *Or42a*>ChR2 OSN and that produced by the ODE model. The optimization was achieved on a set of 10 linear and nonlinear ramps listed in Figure 4—figure supplement 1 together with the naturalistic stimulus presented in Figure 2D. The parameter set derived from the 10 odor ramps and naturalistic stimulus (Table 1) led to a remarkably good fit between the output of the ODE model and the experimentally measured spiking activity (experimental peristimulus time histogram PSTH—black line, results of the IFF+IFB model—blue line; Figure 4C,E,F, Figure 4—figure supplement 1). Throughout the study, this parameter set was used to reproduce and predict the OSN spiking activity elicited by olfactory stimuli. To rule out over-fitting, we trained the IFF+IFB model on a partial dataset containing the linear ramps alone and validated its response against other stimuli not present in the training dataset (Figure 4—figure supplement 2).

Light: IFF motif | Odor: pure IFF motif | Odor: IFF+IFB motifs | |
---|---|---|---|

α_{1} | 0.1 (W m^{−2})^{−1} s^{−1} | 0.1 μM^{−1} s^{−1} | 0.13 μM^{−1} s^{−1} |

α_{2} | 0.88 s^{−1} | 0.6 s^{−1} | 0.26 s^{−1} |

α_{3} | 10^{−6} Hz^{−1} s^{−1} | 0* Hz^{−1} s^{−1} | 1.1 Hz^{−1} s^{−1} |

β_{1} | 1731.41 Hz s^{−1} | 1002.25 μM s^{−1} | 2903.36 μM s^{−1} |

β_{2} | 1.27 W m^{−2} | 8.63 μM | 0.01 μM |

β_{3} | 2.48 W m^{−2} | 2.39 μM | 2.65 μM |

β_{4} | 1214.08 Hz s^{−1} | 624.69 μM s^{−1} | 795.62 μM s^{−1} |

β_{5} | 13.03 s^{−1} | 6.44 s^{−1} | 23.79 s^{−1} |

θ | 0.3 Hz | 1.01 Hz | 1.88 Hz |

n | 2 | 2 | 2 |

Parameters were obtained upon training of the model on 10 stereotyped stimulus ramps (see Figure 4—figure supplement 1) together with the naturalistic stimulation patterns shown in Figure 2D (odor) or Figure 6B (light). For light stimulation, the parameter of the IFB pathway (

*α*_{3}) was negligible and considered equal to 0 in the rest of the study. For odor stimulation, parameter*α*_{3}was artificially set to 0 in the case of the pure IFF motif. Note that the units of the intermediate variable*u*are undefined. We empirically found that the goodness of fit improved when the value of the offset*β*undergoes a small correction over time. In all numerical simulations of this study, we used_{4}*β*(t) = (1.023_{4}*t*/(^{4}*t*+ 30^{4}^{4})) ×*β*. The Hill coefficient_{4}*n*was set equal to 2. In this table, all concentrations are given for odor stimulation in liquid phase. As described in the ‘Materials and methods’ section, the concentration equivalence in gaseous phase can be approximated by multiplying the liquid phase concentration by a factor*ρ*^{liquid → gas}= 26.73. The parameters listed in this table are used in all numerical simulations of the study, except the validation controls described in Figure 4—figure supplement 2.parameter set artificially to 0.

Next, we examined the individual contribution of the IFF and IFB pathways to the response dynamics of the OSN. In Figure 4D, the activity of each pathway was separately computed in response to stimulation by a linear odor ramp. The contribution of the IFB motif to the dynamics of variable *u* is approximately 30% that of the IFF (cyan vs magenta curves, Figure 4D). This led us to conclude that the IFF pathway dominates the control of OSN spiking activity. The IFB pathway has nonetheless a non-negligible impact on the dynamics. Using the parameter optimization procedure, the pure IFF model was trained on the full set of odor ramps (Table 1, middle column). At a qualitative level, both the pure IFF and the composite IFF+IFB models reproduced the OSN spiking dynamics (Figure 4 and Figure 4—figure supplement 1), but a quantification of the goodness of fit established the superiority of the IFF+IFB model (Table 2 and inset of Figure 4F). In addition, none of the other standard 3-element circuit motifs we tested produced a reasonable fit of the OSN spiking activity (data not shown), arguing that the composite IFF+IFB model comprises essential regulatory features of the olfactory transduction cascade.

Odor, IFF | Odor, IFF+IFB | Light, IFF | |
---|---|---|---|

A Correlation coefficient (ρ) | |||

Linear (4 s), low | 0.982 | 0.985 | 0.954 |

Linear (4 s), med | 0.994 | 0.994 | 0.980 |

Linear (4 s), high | 0.986 | 0.995 | 0.983 |

Linear (4 s), slow | 0.993 | 0.994 | 0.980 |

Linear (4 s), fast | 0.983 | 0.979 | 0.970 |

Linear (8 s) | 0.983 | 0.994 | 0.982 |

Quadratic | 0.993 | 0.993 | 0.988 |

Exponential | 0.990 | 0.984 | 0.965 |

Sigmoid | 0.985 | 0.994 | 0.990 |

Asymptotic | 0.990 | 0.994 | 0.972 |

B CV(RMSE) | |||

Linear (4 s), low | 0.143 | 0.121 | 0.225 |

Linear (4 s), med | 0.112 | 0.097 | 0.174 |

Linear (4 s), high | 0.159 | 0.093 | 0.184 |

Linear (4 s), slow | 0.111 | 0.091 | 0.167 |

Linear (4 s), fast | 0.173 | 0.179 | 0.229 |

Linear (8 s) | 0.185 | 0.106 | 0.153 |

Quadratic | 0.131 | 0.111 | 0.150 |

Exponential | 0.155 | 0.226 | 0.237 |

Sigmoid | 0.175 | 0.102 | 0.131 |

Asymptotic | 0.124 | 0.080 | 0.193 |

**(A)**Pearson's correlation coefficient (*ρ*) computed for stimulus ramps listed in Figure 4—figure supplement 1.**(B)**Coefficient of variation (CV) of the root-mean-square error (RMSE).

The response properties of the OSN were then studied for a family of stimulus ramps induced by light instead of odor. The temporal profiles of the light ramps were identical to the odor ramps; the intensity range was fixed to coarsely match the low firing rate of the OSN activity observed for the odor stimulations. In this regime, the temporal pattern of the OSN activity elicited by the light ramps was comparable to that elicited by the odor ramps (experimental PSTH—black lines, Figure 4E,F and Figure 4—figure supplement 1). This close similarity in the input–output relationships permitted us to substitute the odor stimulus with light. Using the full set of linear and nonlinear light ramps together with a naturalistic pattern of light stimulation (Figure 6B), optimization of the parameters of the ODE system showed that the IFB pathway does not contribute to the light-evoked response dynamics of the OSN, suggesting that the integral feedback motif is specific to the odor-evoked activity (Table 1). The results of the pure IFF model are in good agreement with the experimental observations (Figure 4E,F and Figure 4—figure supplement 1). Notably, the goodness of fit of the pure IFF motif, when applied to both light and odor stimulations, was comparable (Table 2). In conclusion, the nonlinear-dynamical response properties of the OSN stimulated by odor and light ramps can be well approximated by the IFF motif, even though the IFB motif brings a non-negligible contribution to the modeling of odor-evoked response dynamics.

#### Peripheral encoding of the olfactory stimulus produces transient normalization

To clarify the sensory computation achieved by the *Or42a* OSN, we sought to derive an analytical solution of the ODE system. We restricted this analysis to the pure IFF motif, which provides a good approximation of the dynamics of the composite IFF+IFB motif. The general solution of the IFF motif required solving the ODE system shown in Figure 4Bii. Since the OSN spiking activity evolves on a different timescale than the other two variables, the solution of the ODEs could be simplified through a quasi-steady-state approximation (QSSA, see ‘Materials and methods’). The mathematical expression of the QSSA solution reveals that the OSN spiking activity (*y*) is determined by a hyperbolic ratio function of the stimulus intensity *x*:${y}^{\mathrm{QSSA}}={\delta}_{1}\frac{x}{x+{\delta}_{2}-S\left(x,t\right)}-{\delta}_{4},$(1)where *δ*_{1}, *δ*_{2}, and *δ*_{4} are constants (‘Materials and methods’). The denominator of this hyperbolic relationship contains a scaling term S(*x*, *t*) that normalizes the spiking activity by the short-term history of changes in the stimulus intensity d*x*/d*t*:$S\left(x,t\right)\propto \underset{0}{\overset{t}{{\displaystyle \int}}}{e}^{-{\alpha}_{2}\left(t-t\prime \right)}\frac{dx}{dt\prime}\hspace{0.17em}dt\prime .$

The integration-differentiation scaling function S(*x*, *t*) plays a role similar to the ‘input gain control’ resulting from lateral inhibition of the local interneuron on the projection neurons in the adult antennal lobe (Olsen et al., 2010) with the notable difference that the rescaling takes place within the primary OSN and that it is driven by the temporal integration of changes in the stimulus intensity. In analogy to the divisive normalization reported in the visual system (Carandini and Heeger, 2012), we termed the rescaling operation described in Equation 1 as ‘transient normalization’. This operation appears related to the adaptive rescaling of the spike dynamics observed in adult-fly OSNs (Kim et al., 2011; Nagel and Wilson, 2011).

#### Behavioral relevance of the dynamical features encoded in the OSN activity

By examining the analytical solution of the IFF motif under the quasi-steady-state approximation (Equation 1), we discovered that the most salient features encoded in the activity pattern of the *Or42a*>ChR2 OSN are: (1) rapid increases in firing rate triggered by abrupt positive changes in the stimulus intensity (accelerations); (2) a relaxation of the firing rate toward stationary activity when the first derivative of the stimulus is null or constant (no acceleration or deceleration); (3) decreases in firing rate in response to stimulus decelerations. In addition, we experimentally observed that (4) the spiking activity of the neuron is strongly inhibited upon abrupt return to the stimulus baseline. We asked whether these features bore any relevance to the control of run-to-turn transitions during odor gradient ascent. We hypothesized that sustained spiking activity of the OSN would suppress turning while inhibition of the OSN would facilitate turning. To test this hypothesis, we built a tracker to monitor the position and behavioral state of a single larva in real-time at a rate of 30 Hz (Figure 5A and detailed description in ‘Materials and methods’). Equipped with blue LEDs, the tracker was designed to evoke controlled patterns of spiking activity in the *Or42a*>ChR2 OSN by means of optogenetics. To avoid innate photophobic behavior (Sawin-McCormack et al., 1995; Kane et al., 2013), experiments were conducted on blind larvae (‘Materials and methods’).

We took advantage of our ability to use stereotyped light ramps to elicit predictable and reproducible patterns of firing activity in the *Or42a*>ChR2 OSN (Figure 4, light-evoked activity patterns). In a series of experiments, we associated individual runs with a predefined light ramp and correlated the simulated OSN firing rate with the onset of run-to-turn transitions. In the example shown in Figure 5B, we began each run with either an exponential ramp or a constant basal light intensity (internal control). When an exponential ramp was played to the larva, the pattern of light stimulation was executed as long as the larva remained in a run state. Upon interruption of the run, the light intensity was reset to baseline. As the motion of the larva had no influence on the stimulation pattern it experienced, this experimental protocol featured a sensorimotor loop that is essentially ‘open’.

When the behavior was modulated by changes in light intensity, the majority of the runs associated with an exponential ramp did not terminate before the falling phase of the ramp. This trend was quantified through the probability of turning (or turn rate) defined as the relative number of runs that switched to a turn during a given time window of 1 s (‘Materials and methods’). The turn probability was estimated at every time point by using a sliding window. Upon constant light stimulation, we found that the instantaneous turn probability was largely independent of the duration of the ongoing run (light gray line, Figure 5C). In contrast, the turn probability was strongly modulated by the exponential light ramp (black line, Figure 5C). During the rising phase of the ramp (0–8 s), turning was suppressed below the value corresponding to basal stimulation. Conversely, a sharp increase in turn probability was observed during the falling phase of the ramp. The modulation of the turn probability by the light-evoked spiking activity corroborated the idea that strong activation of the OSN efficiently suppresses turning, whereas inhibition promotes turning.

We set out to develop a quantitative model for the control of run-to-turn transitions by the neural activity. As the probability of turning remained approximately constant when the OSN activity was stationary, we hypothesized that the relationship between the OSN spiking activity and the control of run-to-turn transitions could be captured by a simple model where the time-varying probability of turning was described by the combination of a constant term (*λ*_{0}) and a term proportional to the current OSN firing rate: *λ*_{0}+ *λ*_{1}*y*(*t*)*.* To map this linear combination (which can be positive or negative) onto the definition domain of a probability (which varies between 0 and 1), we applied a standard logit transformation and described the turn probability as a generalized linear model (GLM) (Myers et al., 2002):$\lambda \left(t\right)=\frac{1}{1+{e}^{-\left({\gamma}_{0}+{\gamma}_{1}y\left(t\right)\right)}}.$

To define the parameters of the GLM (*λ*_{0} and *λ*_{1}), we transformed the previous relationship as shown in Figure 5D, and we carried out a linear regression on the open-loop behavior elicited by 10 light ramps identical to those used to characterize the OSN response dynamics (Figure 5—figure supplement 1). The parameter set obtained through this procedure is reported in Table 3. It was used to reproduce or predict behavioral transitions throughout the study. From here on, the GLM (Figure 5D) was fed with the OSN firing rate predicted from the neural model (Figure 4B). This model will be referred to as the integrated *stimulus-to-behavior GLM*.

γ_{0} (constant) | −0.8156 | −0.8200 | −0.3534 |

γ_{1} (input variable) | −0.0114 (W/m^{2})^{−1} | −0.0013 (W/m^{2})^{−1} | −0.1523 Hz^{−1} |

γ_{2} (derivative of input variable) | – | −0.0214 (W/m^{2})^{−1} s | – |

The first two columns of the table report the value of the stimulus-to-behavior control model without (left) and with (center) the contribution of the first derivative of the stimulus. The last column reports the value of the integrated stimulus-to-behavior model fed with the predicted firing rate of the OSN. The parameters listed in this table are used in all numerical simulations of the study, except for the validation controls described in Figure 5—figure supplement 2.

For the linear and nonlinear ramps, the stimulus-to-behavior GLM accurately reproduces the time courses of the experimental turn probability (blue lines, Figures 5E,F). The performance of the test model was compared to a control GLM in which the turn probability was directly predicted from the stimulus intensity without any sensory processing from the OSN (dashed magenta lines, Figure 5E,F). For this control model, we independently fitted the same GLM with the simulated OSN firing rate replaced by the stimulus intensity (‘Materials and methods’). The values of the parameters of the control model are reported in Table 3. The goodness of fit of the GLM was clearly contingent on the nonlinear transformation achieved by the OSN (Table 4). To rule out that the test GLM was overfitted, we trained the model on a subset of linear light ramps and validated the model on a set of nonlinear light ramps (Figure 5—figure supplement 2).

A Correlation coefficient (ρ) | |||

Linear (4 s), low | 0.69 | 0.75 | 0.89 |

Linear (4 s), med | 0.62 | 0.90 | 0.90 |

Linear (4 s), high | 0.67 | 0.96 | 0.95 |

Linear (4 s), slow | 0.54 | 0.92 | 0.91 |

Linear (4 s), fast | 0.65 | 0.76 | 0.90 |

Linear (8 s) | −0.05 | 0.66 | 0.78 |

Quadratic | 0.11 | 0.70 | 0.88 |

Exponential | 0.29 | 0.43 | 0.92 |

Sigmoid | 0.13 | 0.61 | 0.60 |

Asymptotic | −0.10 | 0.25 | 0.03 |

All conditions (all time points included) | 0.53 | 0.74 | 0.86 |

B CV(RMSE) | |||

Linear (4 s), low | 0.59 | 0.54 | 0.33 |

Linear (4 s), med | 0.60 | 0.41 | 0.32 |

Linear (4 s), high | 0.75 | 0.41 | 0.33 |

Linear (4 s), slow | 0.56 | 0.34 | 0.27 |

Linear (4 s), fast | 0.53 | 0.45 | 0.31 |

Linear (8 s) | 1.06 | 0.71 | 0.59 |

Quadratic | 1.06 | 0.73 | 0.55 |

Exponential | 0.84 | 0.85 | 0.39 |

Sigmoid | 0.95 | 0.65 | 0.58 |

Asymptotic | 0.85 | 0.52 | 0.97 |

All conditions (all time points included) | 0.65 | 0.51 | 0.39 |

Comparison of the performances of the integrated stimulus-to-behavior GLM and the control model bypassing the OSN processing. The outputs of the test and control GLMs are obtained based on the parameter sets listed in Table 3.

**(A)**Application of Pearson's correlation coefficient (*ρ*) on the time course of the experimental turn probability and the simulated turn probability. Restriction of the quantification to the first 12 s of the ramp where the experimental estimate of the turn probability is reliable.**(B)**Same as panel**A**for the coefficient of variation of the RMSE. The goodness of fit computed for the entire set of ramps is reported at the bottom of the table for both metrics.

The successful application of the stimulus-to-behavior GLM led us to conclude that: (1) stationary levels of OSN firing rate lead to probabilistic transitions from run to turn. When the OSN spiking activity remains constant, the probability of turning at a given time is largely independent of the duration of the run; (2) excitation of the OSN suppresses turning (evident during rising phase of all ramps); (3) inhibition of the OSN facilitates turning (most evident during falling phase of the exponential ramp). Consistent with our finding that the OSN activity is sensitive to the slope of the ramp, we found that the performance of the control GLM was improved by combining the light intensity (*x*) with its first derivative (d*x*/d*t*) (Figure 5—figure supplement 3). For the majority of ramps, this improvement did, however, not match the quality of the fit produced by the integrated stimulus-to-behavior GLM (Table 4). We concluded that the nonlinear response characteristics of the OSN have a noticeable influence on the control of orientation behavior.

#### Predicting run-to-turn transitions in virtual olfactory gradients

To test the relevance of the integrated stimulus-to-behavior GLM in conditions in which the sensorimotor loop is closed, we synthesized a controlled light gradient with a shape comparable to that of the odor gradient (Figure 6A). In this stimulation paradigm, the light intensity was continuously updated based on the position of the larva (‘Materials and methods’). Figure 6A illustrates the behavior of an *Or42a*>ChR2 larva in a light gradient. As observed for the odor-evoked behavior (Gomez-Marin et al., 2011), the larva ascended the light gradient and remained in the vicinity of its peak by implementing a series of runs and directed turns. In Figure 6B, we examined how the *Or42a*>ChR2 OSN responds to a replay of the light intensity changes experienced during the trajectory shown in Figure 6A. The spiking activity of the OSN displayed considerable processing of the stimulation pattern. This transformation of the stimulus was well captured by the IFF model. To predict the temporal evolution of the turn probability associated with individual runs, we fed the predicted spiking activity of the OSN into the GLM trained on the open-loop light ramps (Figure 5 and Table 3). Correlating the predictions of the model with the termination of the actual runs revealed that the initiation of a turn was typically preceded by a steady increase in the predicted probability of turning (Figure 6B,C and Video 1). To quantify this trend, we analyzed a large set of runs included in 25 trajectories, each trajectory corresponding to a different animal (representation of a subset of 10 trajectories in Figure 6D). Since every run corresponded to a unique sensory experience, the predictions of the stimulus-to-behavior GLM could only pertain to the average behavior observed over multiple runs. We therefore analyzed the averaged trend of the turn probability preceding individual turns.

As reported in previous work (Gomez-Marin et al., 2011), we found that the stimulus intensity decreases steadily for several seconds prior to a turn (data not shown). Accordingly, the stimulus-to-behavior GLM predicted that the stimulus downslope was transformed into a monotonic increase in turn probability (light blue line, Figure 6E). To establish the sensorimotor control underlying this trend, we computed the turn-triggered averages of the turn probability by using two control models (‘Materials and methods’): (1) behavioral predictions based on the assumption that the OSN spiking activity remained constant throughout the trajectory and (2) behavioral predictions upon uncoupling of the stimulus and the behavior by temporally inverting the reconstructed time course of the stimulus. In contrast to the test GLM, neither control displayed a substantial increase in turn probability prior to turning (red and back dashed lines, Figure 6E). The significance of the improvement in the predictive power of the test model relative to the controls was established by comparing the log-likelihood computed over the entire set of runs (Figures 6F, bottom panel and ‘Materials and methods’). This allowed us to conclude that the integrated neural-to-behavior model built on controlled conditions of stimulation (open-loop paradigm) was sufficient to predict run-to-turn transitions arising from free behavior in a virtual odor gradient (closed-loop paradigm).

#### Inhibition of OSN spiking activity facilitates turning during free behavior

Next, we tested the idea that inhibition of the OSN activity at the stimulus offset is sufficient to trigger a nearly deterministic release of turning during free behavior. To this end, we designed radially symmetrical light landscapes with geometrical features producing inhibition or maintenance of OSN activity during free motion. As a control, we considered a landscape with an exponential rise interrupted by an exponential fall at a fixed distance of 8 mm from the center (Figure 7A, top panel, ‘rim’ indicated by a dashed line). The shape of this landscape is reminiscent of a ‘volcano’. The geometry of the landscape was chosen such that a larva moving at a speed of 1 mm/s from the foot of the gradient toward its center would experience a light pattern similar to the 8-s exponential ramp (Figure 5F and Figure 7Ai). In response to an exponential ramp, the spiking activity of the OSN featured a steady increase followed by a rapid decrease. We therefore expected to observe turn suppression during the rising phase of the ramp and turn facilitation during the falling phase of the ramp. The tendency of larvae to initiate turning upon crossing of the volcano's rim was evident from the set of runs that moved from the outer to the inner edge of the volcano (Figure 7Aii, bottom panel). The alternation between turn suppression and turn facilitation resulted in a zigzagging of trajectories across the rim of the volcano. The integrated stimulus-to-behavior GLM predicted a rise in the turn probability prior to the interruption of a run (Figure 7E and Video 2).

We then considered an extreme version of the volcano: a well (Figure 7B). In this landscape, the light intensity experienced by a larva moving toward the center of the well corresponded to an exponential rise followed by a near-instantaneous drop. The IFF model correctly reproduced the strong inhibitory phase experimentally observed in the OSN spiking activity (Figure 7Bi, bottom panel). This inhibition was expected to generate a nearly deterministic release of turns. Consistently, larvae avoided the well region (Figure 7Bii). Such a behavior was correctly described by the GLM, which predicted a dramatic increase in turn probability following the crossing of the rim (Figure 7E and Video 3). To probe the idea that sustained OSN spiking activity suppresses turning, we synthesized a landscape complementary to the well: a ‘mesa’ in which the light intensity at the rim was extended to the central area of the landscape (Figure 7C). During the transition from an exponential rise in light intensity to a plateau value, the OSN underwent a mild drop in spiking activity before a stationary value was reached—a feature accurately reproduced by the IFF motif (Figure 7Ci). The stimulus-to-behavior GLM predicted a modest increase in turn probability upon crossing of the rim without significant avoidance of the central area of the mesa (Figure 7E and Video 4). This prediction was corroborated by our experimental results (Figure 7Cii, bottom panel).

Finally, we considered an intermediate landscape consisting of a linear ‘hat’ (a cone) in which runs moving toward the center underwent a deceleration in stimulus intensity during the transition from the exponential rise to the linear rise (‘linear’, Figure 7D). Due to the sensitivity of the OSN activity to deceleration in the stimulus intensity, the linear hat landscape led to a modest drop in firing rate similar to that observed for the mesa (Figure 7Di). The IFF model faithfully reproduced this counterintuitive observation. At a behavioral level, the stimulus-to-behavior GLM predicted no significant difference between the behavior evoked by the mesa and the linear hat landscapes (Figure 7E and Video 5). These predictions were in good agreement with the free behavior of larvae (Figure 7Dii, bottom panel).

To assess the predictive power of the integrated stimulus-to-behavior GLM, we compared the average turn probability preceding a turn (Figure 7E) with the observed latency to turning upon crossing of the rim (Figure 7F). The well was associated with the prediction of the steepest increase in turn probability, leading to the expectation that most runs stopped within 2 s of the rim crossing. The volcano led to a milder increase in the predicted turn probability for about 3 s, while the mesa and linear hat were predicted to generate an even weaker increase. As shown in Figure 7F, we found that the average latency to turn was shortest for the well landscape (0.93 s) followed by the volcano (3.48 s). We observed significantly longer turn latencies for the mesa and linear hat with no difference between the two conditions (6.6 s and 6.7 s, respectively). In conclusion, the use of synthetic light landscapes permitted us to experimentally demonstrate that sustained OSN spiking activity suppresses turning during free behavior, whereas inhibition of the OSN activity promotes run-to-turn transitions in a nearly deterministic manner. This approach established that the relatively simple linear control underlying the GLM trained on the behavior of larvae experiencing stereotyped open-loop light stimulations is sufficient to account for the control of behavior elicited under conditions of closed-loop light stimulation.

#### Sensorimotor control can be predicted for free behavior in odor gradients

Our ultimate goal was to test the ability of the integrated stimulus-to-behavior model to predict the duration of runs in an odor gradient. In a real odor landscape (Figure 8A), larvae accumulated at the peak of the gradient with a dispersal notably larger than that observed in a light gradient (Figure 6D). This apparent decrease in orientation performances can be partly explained by the shallower geometry of the odor gradient (Figure 8—figure supplement 1). In Figure 8B, the goodness of fit between the spiking activity of the OSN and the output of the IFF+IFB model can be appreciated for the representative trajectory highlighted in Figure 8A (magenta trace). To predict run-to-turn transitions during free motion in a real odor gradient, we replaced the pure IFF model devised for light-evoked spiking activity by the composite IFF+IFB model as input for the stimulus-to-behavior GLM trained on the open-loop light ramps (Figure 5D and Table 3). The model predicted that runs were on average associated with a monotonic increase in the turn probability during several seconds before a turn (Figure 8C). Based on these predictions, we computed the likelihood of the ensemble of runs observed in the odor gradient. This likelihood was significantly larger than that computed for two control models (Figure 8D). Together, these results establish that the structure and parameters of the integrated stimulus-to-behavior GLM form a solid conceptual basis to describe how the sensory dynamics of single OSNs influence run-to-turn transitions during naturalistic behavior (Video 6).

### Discussion

Most primary sensory neurons operate differently from proportional counters (Rieke, 1997; Song et al., 2012). Individual OSNs of *C. elegans* and cockroaches function as bipolar detectors that selectively respond to either increases or decreases in stimulus intensity (Tichy et al., 2005; Chalasani et al., 2007). A similar specialization into ON-OFF detection pathways has been observed for thermotaxis in *C. elegans* (Suzuki et al., 2008) and motion perception in adult flies (Joesch et al., 2010). In contrast with these binary sensory responses, we discovered that a single larval OSN is sensitive to both the stimulus intensity and its first derivative. The enhanced information-processing capacity of primary olfactory neurons in the larva is consistent with the response characteristics of OSNs in adult flies, which encode complex dynamical features of airborne odorant stimuli (Kim et al., 2011; Martelli et al., 2013).

To describe the input–output response properties of single larval OSNs, we set out to build a biophysical model of the olfactory transduction pathway. IFB motifs constitute the core mechanism of chemoreception in bacteria, olfactory transduction, and phototransduction (Yi et al., 2000; De Palo et al., 2013). In adult flies, Nagel and Wilson (2011) investigated how the potential involvement of negative feedback on the olfactory transduction cascade could account for dynamical and adaptive features of OSN response. On the other hand, IFF motifs are implicated in the regulation of numerous cellular and developmental processes (Goentoro and Kirschner, 2009; Lim et al., 2013), and their contribution to sensory processing has been documented in recent work (Kato et al., 2014; Liu et al., 2015). These results led us to conjecture that two regulatory motifs might be involved in larval olfactory transduction: an IFB and an IFF featuring direct excitation and indirect inhibition (Figure 4A,B). Using a parameter optimization approach, we found that a pure IFF motif is sufficient to approximate the response properties of the OSN. Combining the IFF and IFB motifs was nonetheless necessary to recapitulate the richness of OSN dynamics elicited by naturalistic olfactory stimuli (Figure 4 and Figure 4—figure supplement 1). Consistent with the model proposed by Nagel and Wilson (2011), our numerical simulations indicate that the integral feedback applies to the signaling pathway specific to the odorant receptor (OR). Nagel and Wilson have suggested that a diffusible effector—potentially intracellular calcium—inhibits the activity of the OR, thereby affecting the onset and offset kinetics of the OSN response. By contrast, the IFF motif would describe a regulatory mechanism acting on components of the transduction pathway downstream from the OR (Gu et al., 2009). It is plausible that the IFF regulation is also mediated by intracellular calcium.

What features of the olfactory stimulus are encoded in the spiking dynamics of single larval OSNs? Our biophysical model of the olfactory transduction cascade shows that the spiking activity of the OSN follows a standard hyperbolic dose-response when stimulated by prolonged pulses of odor (‘Materials and methods’). In this regime, the maximum OSN firing rate we observed for IAA is modest (Figure 3—figure supplement 1). Changes in odor concentration occurring on a timescale relevant to the behavior—a second or shorter—can produce significantly higher (or lower) firing rates. This sensitivity to positive and negative changes in stimulus intensity can be explained by the mathematical solution we derived for the OSN dynamics (Equation 1). Upon changes in odor concentration, the dose–response function describing the OSN spiking activity is transiently rescaled (or ‘normalized’) by the short-term history of the stimulus derivative (‘memory’ on characteristic time scale of 1 s, see ‘Materials and methods’). As a result, positive derivatives in stimulus intensity excite the OSN. Negative derivatives can inhibit the OSN firing rate in a manner consistent with the stimulus-offset inhibitions observed in adult-fly OSNs (Hallem et al., 2004; Nagel and Wilson, 2011). Our model indicates that a single *Or42a* OSN combines the function of a slope (ON) detector in response to positive gradients and an OFF detector in response to negative gradients. When larvae ascend Gaussian odor gradients originating from single odor sources, we thus expect high OSN firing rates. Robust inhibition of OSN spiking activity would result from motion that takes larvae down the odor gradient.

How relevant are the features encoded by the spiking activity of the *Or42a* OSN to the behavioral dynamics directing chemotaxis? To address this question, we substituted the odor stimulation with optogenetics-based light stimulation and gained unprecedented control over the spiking activity evoked in a genetically targeted OSN. Under the conditions of open-loop light stimulation, we found that OFF responses (offset inhibition of the OSN firing) promote turning, whereas ON responses (sustained high firing) suppress turning (Figure 5). We applied a GLM to describe the link between the OSN spiking dynamics and the probability of switching from a run to a turn (Figure 5D). The accuracy of the model's output showed a striking dependence on the nonlinear transformation achieved by the olfactory transduction cascade (Figure 5—figure supplement 3). Ultimately, we combined the biophysical model for the OSN spiking dynamics with the GLM to make robust predictions about closed-loop behavior in virtual and in real odor gradients (Figures 6–8).

The integrated stimulus-to-behavior GLM clarifies how features encoded in the activity pattern of individual primary olfactory neurons influence behavioral dynamics. The information transmitted by a single larval OSN is sufficient to represent positive and negative odor gradients through the excitation and inhibition of spiking activity. Unlike for chemotaxis and thermotaxis in *C. elegans* where the ON and OFF pathways are associated with different cellular substrates (Chalasani et al., 2007; Suzuki et al., 2008), the same larval OSN is capable of controlling up-gradient and down-gradient sensorimotor programs. This observation echoes findings recently made for thermotaxis in the *Drosophila* larva (Klein et al., 2015). Furthermore, it corroborates the idea that sensory representations are rapidly transformed into motor representations in the circuit controlling chemotaxis (Luo et al., 2014).

In the future, it will be important to define whether the sensorimotor principles proposed for the *Or42a* OSN can be generalized to OSNs expressing other odorant receptors (Fishilevich et al., 2005; Kreher et al., 2008; Mathew et al., 2013). In addition, the network of interneurons located in the larval antennal lobe (Das et al., 2013) is expected to participate in the processing of olfactory information arising from the OSNs (Asahina et al., 2009; Larkin et al., 2010). Although our work suggests that the computations achieved by the antennal lobe are not strictly necessary to guide robust chemotaxis (see also ‘Materials and methods’), the function of the transformation carried out by the synapse between the *Or42a* OSN and its cognate projection neuron (PN) remains to be elucidated in the larva (Ramaekers et al., 2005; Asahina et al., 2009; Masuda-Nakagawa et al., 2009). As adult-fly PNs encode the second derivative of olfactory stimuli (Kim et al., 2015) including circuit elements downstream of the OSNs in the present multilevel model are expected to improve the accuracy of the behavioral predictions of the model.

The aim of this study was to clarify the relationships between the peripheral encoding of naturalistic olfactory stimuli and gradient ascent toward an odor source. By exploiting the sufficiency of a single OSN to direct larval chemotaxis (Fishilevich et al., 2005; Louis et al., 2008), we developed a mathematical model accounting for the transformation of time-varying stimuli into the firing rate of an OSN and the conversion of dynamical patterns of OSN activity into the selection between two basic types of action—running and turning. It will be interesting to examine the validity of the present model for the sensorimotor control of other aspects of larval chemotaxis such as turn orientation through lateral head casts (casting-to-turn transitions). In adult flies, turn orientation is determined by the crossing of the boundaries of odor plumes: upon encountering of an odor plume, flies veer upwind whereas exiting the plume initiates lateral and vertical casting (van Breugel and Dickinson, 2014)—an orientation strategy related to the surge-and-cast response of moths (Carde and Willis, 2008). To orient in a rapidly changing olfactory landscape, the OSNs of various flying insects are capable of tracking rapid odor pulses on sub-second timescales and differentiating these signals (Kim et al., 2011; Fujiwara et al., 2014; Szyszka et al., 2014). Whether the processing of turbulent olfactory inputs involves more temporal integration than that described by the sensorimotor model proposed here remains to be elucidated. Finally, the *Drosophila* larva offers a unique opportunity to delineate the neural circuit basis of behavior (Ohyama et al., 2013, 2015). Interdisciplinary approaches combining behavioral screens, functional imaging, and circuit reconstruction on the one hand (Yao et al., 2012), and computational modeling and robotics on the other hand (Grasso et al., 2000; Webb, 2002; Izquierdo and Lockery, 2010; Ando et al., 2013), should improve our understanding of how brains with reduced numerical complexity exploit streams of sensory information to direct action selection.

### Materials and methods

#### Fly stocks

All behavioral experiments shown in the main figures were achieved with third instar larvae expressing the co-receptor Orco in only one OSN (Fishilevich et al., 2005) (*Or42a*-Gal4>UAS-*Orco*,UAS-ChR2-H134R;*Orco*^{−/−}) in a double blind background (*GMR*-*hid*/+;*dTrpA1*^{1}) (Kwon et al., 2008; Xiang et al., 2010). For the control experiments shown Figure 18, the double blind background was achieved with the null alleles *glass*^{60j} and *dTrpA1*^{1} (Moses et al., 1989; Busto et al., 1999). The UAS-ChR2-H134R transgene was donated by Stefan Pulver and Leslie C Griffith (Pulver et al., 2009). Flies were raised on standard fly food containing 0.5 mM all-*trans*-retinal in an incubator in complete darkness (food vials wrapped in aluminum foil). Exposure to ambient light was minimized until the experimental test. Approximately 96 hr after egg laying, third instar larvae were taken out of the food and immersed in a 15% (wt/V) glucose solution.

#### Experimental arena with controlled odor gradient

A controlled odorant environment was created in a 120 × 120 × 12 mm arena consisting of a polystyrene dish (the lid of a Greiner square dish ref. number: 688102, Sigma–Aldrich, St. Louis, MO) standing on a 2% wt/V agarose surface inside the closed-loop tracker. A 3-μl odor droplet of IAA (0.25 M) was placed inside a plastic reinforcement ring at the center of the dish (internal diameter of disk occupied by the odor droplet: 5 mm). Inside the arena, an odor gradient emerged as a result of the diffusion from the source for 30 s prior to the introduction of a single larva. This step required a brief opening of the arena. The tracking was carried out for a minimum duration of 3 min. A minority of trajectories associated with no chemotactic response or with larvae idly dwelling under the odor source was excluded from the dataset.

#### Behavioral quantification

##### Run/non-run classifiers

To detect turning events, we adopted a geometrical approach based on the physical trajectory described by the larva. First, we parsed the trajectory into segments of equal sizes. Next, we calculated the angle between successive segments of the trajectory. Finally, we computed the distribution over these angles. This distribution had the characteristics of a long-tailed exponential (data not shown). We defined a threshold at the location of the ‘kink’ of the distribution. Turning events were associated with positions with a turning angle larger than the threshold. We empirically found that good results were obtained for trajectory segments of 5 mm and an angular threshold of 20°. The results of the behavioral classification were insensitive to the precise length of the trajectory segments and the angular threshold.

Throughout the present study, the identification of turns was based on the trajectory of the midpoint (point located on the skeleton at a third of the distance from the head). Due to the high sampling rate of the tracker and the inherent noise of the stepper motors moving the stage holding the camera, the positions of the points of interest were subject to minute jittering. Unless stated otherwise, the trajectories of every point of interest were smoothened with a Savitzky-Golay filter to remove fluctuations on a small spatial scale irrelevant to the motion of the larva. This geometric approach was used to classify the data obtained from the closed-loop experiments (Figures 1, 6–8). For the open-loop experiments described in Figure 5, turns were identified by the online classification carried out by the tracker software (see section Tracker, Figure 16).

#### Physical model for odor diffusion

For the experimental conditions used in previous work (Louis et al., 2008; Asahina et al., 2009; Gomez-Marin et al., 2011; Gomez-Marin and Louis, 2014), we obtained evidence that the odor gradients could be approximated as static. Due to the use of an odor source with reduced volume, this approximation did not hold in the present study. To correlate the behavior of the larva with a more accurate reconstruction of the odor gradient, we developed a physical model for the diffusion of the odor inside the behavioral arena (Figure 9). We used model-based estimation techniques for parameters underlying this physical model. We considered 3D diffusion with separate diffusion constants for air and the droplet. Exposed plastic surfaces of the chamber were treated as adsorptive boundaries. Since the odor gradient was initially established in the arena for 30 s prior to the introduction of a larva, our model also included non-zero initial concentration of the odor in the air, agarose, and plastic chamber. COMSOL Multiphysics v4.3 (COMSOL, Burlington, MA) was used to solve the diffusion equation with these boundary conditions. Parameter estimation was performed using the MATLAB/Optimization toolbox (MathWorks, Natick, MA) by solving a nonlinear least squares problem that matched the simulated odor concentration to measurements at the same time points.

The geometry of the experimental arena is described in Figure 9. The radius *r*_{ring} of the odor ring confines the liquid droplet so that the radius of the flat face is equal to *r*_{ring}. The volume *V*_{drop} of the droplet, made up of odor and solvent, is fixed to be 3 μl. According to the formula of a sphere, $\hspace{0.17em}{V}_{\mathrm{drop}}=\hspace{0.17em}\frac{\pi}{6}\hspace{0.17em}{h}_{\mathrm{drop}}\left({h}_{\mathrm{drop}}^{2}+3{r}_{\mathrm{ring}}^{2}\right)$ where *h*_{drop} is the droplet height. The agarose layer at the bottom of the chamber was modeled as a two-dimensional sheet with an independent diffusion constant.

##### Boundary conditions

The top flat face of the droplet that contacts the plastic cap was treated as a no-flux boundary. Flux continuity was imposed on the spherical interface with air. The remaining boundaries, air-agarose, and air-plastic, were modeled as Robin boundary conditions to accommodate the possibility of adsorption-desorption reactions at the boundary. Although the standard way of treating adsorption reactions would be to use a reactive boundary condition where the odorant is treated as free in the air or bound to the boundary, we modeled these boundaries as a Robin boundary condition, which reduces the number of parameters to be considered (Singer et al., 2008). This simplification of the boundary conditions was necessary for us to estimate the associated parameters with a single experiment.

Considering a diffusing chemical species with concentration $x(t,\overrightarrow{r})$ that varies with time *t* and location $\overrightarrow{r}\hspace{0.17em}$ within the chamber, the flux vector $\overrightarrow{J}$ of this chemical is given by $\overrightarrow{J}=-D\overrightarrow{\nabla}x$, where *D* is the diffusion constant in air. If the normal direction to the boundary under consideration denoted as $\widehat{n}$, the Robin boundary condition relates to the normally incident flux to the boundary reaction by $-\widehat{n.}\overrightarrow{J}={k}_{i}({x}_{0,i}-x)$ where *k*_{i} is related to the reaction rate at the boundary *i* (agar or plastic), and *x*_{0,i} is the saturation concentration of the odorant on this boundary. This reaction drives the flux toward the saturation concentration of the boundary. For example, if the concentration of the odorant in air is lower than the saturation concentration, the boundary would become an odor source by undergoing desorption, with a rate governed by *k*_{i}. Conversely, a higher concentration of the odorant in air would lead to adsorption at the boundary.

##### Diffusion equation and coupling of the evaporation-diffusion process

There were two simultaneous diffusion processes, both of which were modeled using a PDE:$\frac{\partial x}{\partial t}={D}_{i}{\nabla}^{2}x.$

The diffusion constant *D*_{i} depended on whether the medium *i* is air or droplet. We used a flux continuity condition at the droplet-air boundary, that is, the odorant could not accumulate at this boundary. As a result of the flux continuity at the droplet-air boundary, and because diffusion through air was substantially faster than through the droplet, the odor developed a radial profile within the droplet despite starting with a homogenous initial concentration. This process is our approximation of the coupled evaporation-diffusion process. Modeling the diffusion limited evaporation process (Kelly-Zion et al., 2011) would render this problem intractable in the context of our model-based parameter estimation. We, therefore, used an approximation for the evaporation process. Although inaccuracies could arise from this approximation because we ignored natural convection and concentration-dependent changes in volatility of the odorant arising from chemical interactions with the solvent, our model was able to match experimental measurements with good fidelity as seen from the results of our model-based estimation (Figure 9B–D).

##### Calibration of FT-IR measurements

Following the protocol described in (Louis et al., 2008), we used a gas-flow cell and Fourier Transform-Infrared Spectroscopy (FT-IR) (Bruker, USA) to assess the molar extinction coefficient of the odor in gaseous phase. The odor (isoamyl acetate, IAA) was mixed with the solvent n-hexane in different proportions. The solution was then injected directly into the gas flow cell by using a 10 μl Hamilton syringe (Hamilton Company, Reno, NV). The quantities of odor tested were 0, 0.01, 0.1, 0.2, 0.25, 0.5, and 1 μl. In all cases, the absorbance was measured by calculating the height of the absorption peak at the wave number 1765 cm^{−1}—a wavelength specific to IAA. Between trials, the gas flow cell was disassembled and all parts were rinsed with n-hexane. The absorption coefficient was estimated to be 479.87 M^{−1}cm^{−1} at 25°C. The concentration of saturated odor was estimated by injecting 10 μl of pure IAA into the gas-flow cell. The absorbance saturated at a value close to 1.36. Using the absorption coefficient, the concentration of the saturated vapor was estimated to be 278.45 μM.

##### Model-based estimation of PDE parameters

Absorbance of infrared light was measured through the air along sections of the behavioral arena. As described in (Louis et al., 2008), the average odor concentration along the light path was estimated using the Beer–Lambert law. Based on this, we defined the parameters of the PDE model by characterizing the geometry of the gradient produced by a single odor source of 3 μl of IAA at a concentration of 1.0 M. A higher source concentration was used for the infrared spectroscopic measurements than for the behavioral experiments (0.25 M) to ensure the accuracy of the concentration estimates. We measured the absorbance along sections located at distances 0 mm, 7.5 mm, 15 mm, 22.5 mm, 30 mm, 37.5 mm, and 45 mm from the center of the droplet (Figure 9B–D). The measurements were taken after the odorant was placed in the chamber following the exact same protocol as for the behavioral experiments. From these, we inferred the average concentration at these 7 sections over a time interval of 360 s. For a given set of parameters based on an initial guess about the order of magnitude, we simulated the diffusion process. To this end, we used trapezoidal integration to estimate the average of the concentration along the sections that corresponded to the experimental measurements. The objective function to be minimized for estimating the parameters was the root-mean-squared error of the average concentration at each of the seven locations and at all times.

To minimize the objective function, we used sequential quadratic programming as implemented by the function *fmincon* in MATLAB v8.2. The Jacobian of the cost function with respect to the parameters being estimated was computed using finite differences. We constrained all physical parameters to be greater than 0. None of these inequality constraints were active for the converged solution. We tried 20 random initial guesses, and one where all parameters were set to 0. Once the optimization converged, we perturbed the converged estimates using random numbers. The perturbed estimates were fed back to the estimator, and the optimization ran again until convergence. We carried out 20 such restarts, and all of them converged to the same estimates, which are reported in Table 5. As described in Figure 10, the reconstruction of the odor gradient experienced by freely moving larvae (3-μl source of IAA at a concentration of 0.25 M) was then achieved by scaling down the gradient obtained at a source concentration of 1.0 M. We noted that the temporal evolution of the odor gradient is non-negligible (Figure 10B,C), which justified its integration in the entire analysis.

Parameter | Physical description | Converged value |
---|---|---|

D_{air} | Diffusion constant in air | 8.9377 × 10^{−7} m^{2}s^{−1} |

D_{drop} | Diffusion constant in droplet | 8.7859 × 10^{−11} m^{2}s^{−1} |

c_{0,air} | Initial odorant concentration in air | 4.0492 × 10^{−7} mol l^{−1} |

c_{0,drop} | Initial odorant concentration in droplet | 0.0450 mol l^{−1} |

k_{agar} | Robin rate for air-agar boundary | 1.5762 × 10^{−6} ms^{−1} |

k_{plastic} | Robin rate for air-plastic boundary | 5.8025 × 10^{−5} ms^{−1} |

c_{0,agar} | Saturation concentration of agar | 3.6817 × 10^{−5} mol l^{−1} |

c_{0,plastic} | Saturation concentration of plastic | 5.7921 × 10^{−7} mol l^{−1} |

The parameters are optimized for an odor gradient of isoamyl acetate under the experimental condition outlined in Figure 9.

#### Electrophysiology

Third instar larvae were transferred from the food vial into 15% (wt/V) glucose solution. Dissection of tissues was carried out in cold extracellular saline solution (Singleton and Woodruff, 1994) where the head was separated from the rest of the body while the brain was left intact. Using tissue glue (Histoacryl B, Braun, Germany), the dissected head was then glued in the middle of a glass slide at the bottom of a flow chamber. The cuticle covering the mouth hook was removed using a 3 mm Vanna spring scissor (Fine Science Tools, Germany) to make the dorsal organ ganglion accessible to the recording electrode. Throughout the experiment, the head was immersed in extracellular saline. The flow chamber was connected to two syringe pumps (Aladdin2-220, World Precision Instruments, Sarasota, FL) to perfuse the preparation with fresh saline and to ensure the continuous evacuation of the odor out of the chamber. The chamber volume was approximately 500 μl. The flow in the chamber was 28.4 μl/s, leading to a turnover of the chamber volume in 17.6 s.

Recording electrodes were pulled (P97, Sutter Instruments) out of borosilicate glass capillaries (1.5 mm/1.12 mm outer/inner diameters (OD/ID), World Precision Instruments, Novato, CA) with a 10 μm open tip. Electrodes were then back-filled with 3 μl of extracellular saline. A chlorinated silver wire (0.38 mm in diameter) was used to connect the electrode to the head stage of a microelectrode amplifier (Axon MultiClamp 700B, Molecular Devices, Sunnyvale, CA). The electrode was mounted on an automated micromanipulator (ROE-200 & MPC-200, Sutter Instruments). The antennal nerve in close vicinity of the dorsal ganglion was sucked into the recording pipette by applying a negative pressure (−20 kpa) created through vacuum. The extracellular signal was amplified 100 times at the microelectrode amplifier; it was visualized on an oscilloscope (Tektronix, Beaverton, OR), and recorded at a sample rate of 20 kHz by a personal computer (PC) equipped with the free data acquisition software SpikeHound (Lott et al., 2009). The conception of this preparation and recording technique benefited from pioneering recordings from the larval olfactory organ (Oppliger et al., 2000; Kreher et al., 2005; Hoare et al., 2008).

##### Light stimulation at electrophysiology rig

For the light stimulation, a blue light emitting diode (LED) (LCS-0470-03-22 LED, Mightex, Canada) was mounted in a lighthouse (U-DULHA, Olympus, Japan) and integrated into the light path of the microscope (BX51, Olympus) allowing for localized stimulation of the larval head through a 40× immersion objective. The light intensity arriving at the larval head was estimated by measuring the photocurrent under the objective with a photodiode (SM05PD7A, Thorlabs, Newton, NJ) connected to a bench top photodiode amplifier (PDA200C, Thorlabs). The LED was controlled by a custom Labview (National Instruments, Austin, TX) interface available from the following link: https://github.com/LabLouis/eLife_2015/tree/master/Electrophysiology. The current controlling the LED was fed into the data acquisition software, where it was recorded along with the signal from the suction electrode. Pulses of blue light elicited spikes exclusively in OSNs expressing ChR2 (Figure 2B,C and Figure 11A).

##### Spike-sorting algorithm

Spike-sorting and PSTH analysis was performed with Matlab using custom scripts available from the following link: https://github.com/pahammad/OpSIN. In the *Orco* null background, spontaneous activity of OSNs is drastically reduced but not abolished (Hoare et al., 2008). Furthermore, non-OSNs contribute to the activity monitored from the DO ganglion. We devised an optogenetic spike-sorting strategy to distinguish spikes of the *Or42a* OSN from other spikes (Figure 11B,C) (Lima et al., 2009). Channelrhodopsin-2 (ChR2-H134R) was expressed in the single functional *Or42a* OSN (*Or42a*>ChR2). The spike-sorting algorithm (called OpSIN) parsed the extracellular recording data and collected candidate ChR2-evoked spikes specifically during light-activation time windows based on amplitude thresholding and local non-maximum suppression. Template candidates were separated into clusters using an affinity propagation algorithm (Frey and Dueck, 2007). Spike selection was accomplished by comparing candidate waveforms identified throughout the recording to ChR2 derived waveform templates. Candidate waveforms were then transformed to appear as similar as possible to the template waveform via dynamic time warping (Berndt and Clifford, 1994). The probability of spike occurrence at every candidate location was estimated by warping the residual distance between the candidate waveform *X* and the chosen set of spike templates *T*.$d\left(T,X\right)=\sqrt{{\left(X-DTW\left(T\to X\right)\right)}^{2}}.$

A spike-probability-histogram-based cut-off was applied across the entire recording to select the correct spikes and assign identities.$p\left(T,{X}_{i}\right)={e}^{\left(\frac{d\left(T,{X}_{i}\right)}{K}\right)},$where *K* is the median of all the pair wise distances computed across the set of spike-candidates.$p\left(T\right)=\text{max}\left(p\left(T,{X}_{i}\right)\right),$where the spike candidate's probability is based on its best matched template. Every PSTH was mildly low-pass filtered using a Savitzky-Golay filter.

##### Liquid phase odor stimulation

For the odor stimulation two-barrel pipettes (1.5 mm/0.84 mm OD/ID, World Precision Instruments) were pulled using a PMP-107 Multipipette Puller (MicroData Instrument, South Plainfield, NJ) resulting in a two-barrel tip with a 5 µm OD. One barrel was back-filled with the odor solution (IAA dissolved in extracellular saline), and the other with extracellular saline alone. An injection needle (0.51 mm/0.26 mm OD/ID, Becton, Dickinson and Company, Franklin Lakes, NJ) was inserted into the back of each barrel and airtight sealed using hot-melt adhesive. Each barrel was subsequently connected to separate channels of a pressure-driven flow controller (Fluigent, France). The tip of the odor stimulation pipette was placed and maintained at a distance of 10 μm in front of the larval dorsal organ with a micromanipulator (ROE-200 & MPC-200, Sutter Instruments). The output pressure and thereby the flow of each individual channel of the odor delivery pipette was controlled at a temporal resolution of 10 Hz via a custom Labview interface available from the following link: https://github.com/LabLouis/eLife_2015/tree/master/Electrophysiology. Rapid concentration changes of the odorous stream were achieved by varying the flow between the empty channel and the odor channel while keeping the overall flow constant at a set value of 0.32 nl/s (measured flow rate corresponding to a 320 mbar output pressure). The experimental setup is outlined in Figure 12A.

The liquid phase odor stimulation system was calibrated using a dilution series of the fluorescent dye fluorescein, which was expelled at a constant pressure (320 mbar) into the perfusion chamber (Bioscience Tools, San Diego, CA) while imaging the tip of the pipette with a high-speed camera (Andor, United Kingdom). We determined that the relationship between the fluorescein concentration and the measured fluorescence was best fitted by a linear function (Figure 12E, left panel). When varying the output pressure while keeping the concentration of fluorescein constant, the observed fluorescence could be mapped to the output pressure using a linear function (Figure 12E, right panel). The concentration arriving at the dorsal organ was quantified by comparing the fluorescence measured at the tip of the odor delivery pipette (region of interest *ROI*_{tip}) to the fluorescence measured right at the dorsal organ (*ROI*_{dorsal}). Assuming that the fluorescence measured at the tip of the odor delivery pipette represents the undiluted concentration, the dilution factor (*d*) was calculated according to:$d=\frac{\Delta F\left(RO{I}_{tip}\right)}{\Delta F\left(RO{I}_{dorsal}\right)}.$

The time lag between the pressure output and the odor arriving at the dorsal organ was quantified by computing the cross correlation between the recorded output pressure of the mass-flow controller system (MFCS) and the measured fluorescence at the larval dorsal organ. By calculating the shift of the peak of the cross correlation with respect to the peak of the autocorrelation of the pressure output signal, the final lag for each experiment was determined. The lag was estimated to be 500 ms.

##### Phase conversion for olfactory stimulation

Gas-phase odor stimulation was achieved by means of a custom olfactometer delivering a continuous stream of air (510 ml/min). The air stream, regulated by two mass flow controllers (Cole–Parmer, Vernon Hills, IL), was humidified and subsequently passed through the odor solution and delivered to the tip of the larval head. Rapid concentration changes of the odorized stream were achieved by varying the flow between the empty channel and the odor channel while keeping the overall airflow constant. A custom Labview protocol was used to control the flow rate of the individual mass flow controllers at a rate of 30 Hz. This script is available from the following link: https://github.com/LabLouis/eLife_2015/tree/master/Electrophysiology. The experimental setup is outlined in Figure 12B: it is similar in design to past olfactometers (Borst and Heisenberg, 1982; Kim et al., 2011) and it was adapted to produce a stimulus time course on the timescale of a typical run.

Odor concentrations were estimated in gaseous phase by using a mini photoionization detector (200B miniPID, Aurora Scientific, Canada). Calibration of the miniPID (photoionization detector) was achieved by passing an air stream through pure IAA to obtain saturated vapor. Since the PID signal saturated at high concentrations of airborne odor, it was necessary to establish the calibration curve in an odor range that was significantly lower than saturated vapor. The saturated airflow was therefore diluted into clear air in ratios of 1:10.0, 1:19.2, 1:38.5, and 1:83.0. Gaseous concentrations and PID voltage readings followed a linear relationship (Figure 12F), which allowed us to convert the PID readout into absolute concentration.

As illustrated in Figure 12C, the OSN activity was monitored by means of calcium imaging at the axon terminal of the OSNs at the larval antennal lobe (*Or42a*>GCaMP3) using a high-speed camera (Andor, United Kingdom) and a fluorescence microscope (BX51 mounted with 40× water immersion objective, Olympus). The OSN activity was measured during odor stimulation in gaseous and liquid phase, respectively. The phase correlation between liquid and gaseous stimulations was established for an 8-s exponential ramp. In liquid phase, both background and maximum concentration were fixed to the pre-existing experimental conditions used for the electrophysiology: they corresponded to a range spanning between 50 μM and 530 μM. The corresponding ΔF/F of the OSN response ranged between 10% and 60% in liquid phase. The background and maximum concentration of the airborne ramp were adjusted to obtain an activity profile with a ΔF/F matching the liquid phase stimulations.

Using the miniPID, the estimate of the final air-phase exponential odor time course ranged from 2.20 to 20.13 μM and led to an OSN response ranging between 10% and 59%. From the original ΔF/F, it was found that the ratio of the max ΔF/F in gaseous and liquid phases was 0.98. The ratio of the integral of ΔF/F over the full time course of the stimulation was 0.87. We established the equivalence of the OSN calcium responses elicited by an exponential ramp with a concentration range of 50–530 μM in liquid phase and with a concentration range of 2.20–20.13 μM in gaseous phase, with comparable OSN response dynamics for both phases (Figure 12D). To map the concentration range of 2.20–20.13 μM in gaseous phase onto the concentration range of 50–530 μM in liquid phase, we used the ratio between the maximum concentrations of the ramp in liquid and gaseous phases: ρ^{liquid → gas} = 26.73. This conversion was applied to predict the behavior of larvae in an airborne odor gradient on the basis of the model for the OSN activity developed for liquid phase stimulation (Figure 4).$y\left(t\right)={F}_{\text{liquid}}\left({x}_{\mathrm{gas}}\left(t\right)\times {\text{\rho}}^{\text{liquid}\to \mathrm{gas}}\right),$where *y* denotes the activity of the OSN, *x*_{gas} the concentration in gaseous phase, and *F*_{liquid} the predicted neural activity from the IFF+IFB (ODE) model introduced in Figure 4B.

#### Reverse-correlation analysis of OSN response dynamics

Standard systems identification approaches have shown that the important aspects of the response of invertebrate photoreceptors can be approximated as linear (Marmarelis and McCann, 1977), even though the modeling of nonlinear features of the response requires a more sophisticated treatment (French et al., 1993). More recently, it has been suggested that the response dynamics of OSNs in *C. elegans* and primary thermosensory neurons in the *Drosophila* larva are largely linear (Kato et al., 2012; Klein et al., 2015). We therefore examined whether a linear-nonlinear model could be used to describe the OSN response of the larva. Following a reverse-correlation approach, we stimulated the *Or42a*>ChR2 OSN by a M-sequence induced with light (Figure 13A). Reproducible patterns of neural activity were observed (Figure 13C), from which a biphasic filter was computed (Figure 13B). This filter had a shape similar to those found in retinal ganglion cells (Chichilnisky, 2001) and insect OSNs (Geffen et al., 2009; Martelli et al., 2013). To test the predictive power of this filter, we reconstructed the activity elicited by an exponential and a sigmoid ramp (Figure 13D,E). Whereas the linear filter led to a reasonable reconstruction of the firing pattern elicited by the M-sequence (Figure 13C), it produced unsatisfactory results for the graded ramps with a mismatch so pronounced that it could not be rectified by a nonlinear function. This conclusion is consistent with the nonlinear response dynamics observed in adult-fly OSNs upon stimulation by graded odor ramps (Kim et al., 2011).

#### IFF and IFB motifs

The dynamics of the pure IFF motif (Figure 4Bi) is described by a 3-variable ODE system (Figure 4Bii). We hypothesized that the firing rate of the OSN (*y*) results from the combined effects of direct excitation and indirect inhibition of the OSN activity. The excitation is mediated by the gating of the OR by the binding of odorant molecules or the absorption of photons by channelrhodopsin-2 (ChR2). By analogy to the olfactory transduction cascade in the moth (Gu et al., 2009), we speculated that the indirect inhibition is mediated by an intermediate variable (*u*) that might represent the concentration of calcium bound to calmodulin. For the pure IFF motif, the dynamics of variable *u* results from a production term proportional to the stimulus *x* and a first-order decay term*.*

To model the direct excitation and indirect inhibition of the OSN activity, we used a control function (d(*x*,*u*) where d stands for depolarization) inspired by the *cis*-regulatory logic of gene transcription (Goentoro and Kirschner, 2009):$d\left(x,u\right)={\beta}_{1}\frac{x}{{\beta}_{2}+x+{\beta}_{3}u}.$

This expression was built from thermodynamic considerations about the state of a promoter occupied by transcription factors (Ackers et al., 1982; Bintu et al., 2005). Here, we hypothesized that a similar function is suitable to describe the depolarizing effects of the opening of the OR (or ChR2), and the indirect hyperpolarizing effects that calcium bound to calmodulin might have on the OSN membrane. The contribution of each trend is described by *x* and *β*_{3}*u*, respectively.

In addition, we assumed that the intermediate variable (*u*) and the OSN spiking activity (*y*) undergo a first-order decay. For the OSN activity, the introduction of such a decay can be justified by speculating about the existence of ion pumps that restore the membrane to resting potential after an initial increase of cations following the gating of the OR (or ChR2) (Gu et al., 2009). By trial and error, we also discovered the necessity of including a constitutive decay (offset) term that vanishes at a low firing rate. Although the molecular correlate of this offset remains undefined, it could be explained by the homeostatic function of ion pumps. The combined effects of the two decays are mathematically described as:$h\left(y\right)=-{\beta}_{4}\frac{{y}^{2}}{{y}^{2}+{\theta}^{2}}-{\beta}_{5}y,$where *h* stands for hyperpolarization. To keep the model as simple as possible, the membrane potential was not modeled explicitly. Instead, we assumed that depolarizing d(*x*,*u*) and hyperpolarizing *h*(*x*) effects on the OSN membrane can be translated into excitatory and inhibitory effects on the OSN firing rate. While our knowledge about the olfactory transduction cascade in *Drosophila* was insufficient to justify these assumptions, the goodness of fit resulting from the integration of the ODE model demonstrated that the OSN dynamics could be captured by the combination of d(*x*,*u*) and *h*(*x*). By combining the previous relationships, we obtained the following systems of ODEs:$\frac{du}{dt}={\alpha}_{1}x-{\alpha}_{2}u,$$\frac{dy}{dt}={\beta}_{1}\frac{x}{{\beta}_{2}+x+{\beta}_{3}u}-{\beta}_{4}\frac{{y}^{2}}{{y}^{2}+{\theta}^{2}}-{\beta}_{5}y.$(2)

The second regulatory motif we considered is a negative IFB. This motif has been implicated in the process of olfactory transduction and adaptation in adult flies (Nagel and Wilson, 2011). It also forms the regulatory basis of the transduction pathway underlying adaptive chemoreception in bacterial chemotaxis (Yi et al., 2000; Tu et al., 2008). For this motif, we assumed that the activity of the neuron had an excitatory effect on the intermediate variable *u*, which in turn has an inhibitory effect on the OSN activity. In a first approximation, the negative feedback was assumed to be linear. The difference between the IFF and IFB motifs lies in the production of the intermediate variable (*u*), which in the case of the IFB is proportional to the firing rate (*y*) and not the stimulus intensity (*x*). These considerations yielded the following system of ODEs:$\frac{du}{dt}={\alpha}_{3}y-{\alpha}_{2}u,$$\frac{dy}{dt}={\beta}_{1}\frac{x}{{\beta}_{2}+x+{\beta}_{3}u}-{\beta}_{4}\frac{{y}^{2}}{{y}^{2}+{\theta}^{2}}-{\beta}_{5}y.$(3)

Using numerical simulations, we found that the IFB motif alone cannot account for the dynamics of the OSN activity. In contrast, we discovered that the combination of the IFF and IFB motifs leads to substantial improvements in the quality of the fit (Figure 4). For all simulations achieved in this work, the ODE equations were numerically integrated by the solver *ode23s* built in Matlab.

#### Parameter fitting of the composite IFF+IFB and pure IFF models

To optimize the parameters of the model to the experimental data, a standard fitting procedure was applied. As outlined in Figure 4Bi, we considered three possible models: the motif IFF, the motif IFB, and a combination of the two motifs. The joint probability of the observations was maximized as a function of the internal parameters for the neural activity patterns elicited by a set of 6 linear ramps, 5 nonlinear ramps, (Figure 4—figure supplement 1) and a naturalistic stimulus (Figure 2D,E). For each stimulation protocol, the confidence interval of the OSN activity (PSTH) was used to achieve a robust fit of the free parameters of the model. This procedure was applied to each of the three models independently.

In the ODE systems presented in Figure 4Bii and Equations 2, 3, we observe that the time derivative of *u* can be multiplied by an arbitrary scaling factor reabsorbed by the fitting parameter *β*_{3} in the time derivative of *y.* For this reason one is forced to fix one of the eight parameters to a constant value. For numerical convenience we chose to fix *α*_{1} = 0.1. To infer the actual value of this parameter, one would need to experimentally access the value of the intermediate variable *u*, whose molecular identity remains unknown. For the pure IFF model, the number of free parameters is therefore seven. In addition to these parameters, we considered the scaling of the firing rate *y* elicited by individual stimulation protocols via a multiplicative factor accounting for variability across experimental conditions (e.g., minute differences in the positions of the stimulation pipette).

The maximization of the likelihood function was achieved by means of the Nelder-Mead (NM) method (Nelder and Mead, 1965), which proved to be fast and reliable. The result of the NM optimization was then refined through a gradient search algorithm (Brun and Rademakers, 1997). For the dataset corresponding to the light stimulation, the fitting procedure led us to rule out the relevance of the IFB model alone with a probability of *χ*^{2} very close to zero. In contrast, the IFF was able to reproduce the experimental observation with good accuracy. On the other hand, in the case of the odor stimulation, we obtained a significant improvement of the model fit by adding an IFB component to the IFF motif (addition of the term *α*_{3}*y* to the dynamics of *u*).

The fitted value of the composite IFF+IFB motif indicated that the IFB component was not negligible during the stimulation and accounted for about 30% of the final firing rate (Figure 4D). In contrast to the pure IFF model, variables *u* and *y* of the IFF+IFB model were entangled in the structure of the ODE resulting in a coupling that allowed us to fit the value of parameter *α*_{1}. We also examined the effect of introducing additional terms in the denominator of the function defining *y*, such as the product *u* × *y*. Besides the test of other circuit motifs, the introduction of additional free parameters represented a qualitative test against the possibility of over-fitting. The improvements in the fitting obtained in these cases were very marginal.

With regards to both light and odor stimulation protocols, the data comprised stimulation patterns on diverse timescales and with varying stimulus durations: 10 linear and nonlinear ramps lasting less than 25 s and one ‘naturalistic’ stimulus lasting more than 200 s. We found that the parameter set leading to a good fit during the first 30 s of the light or odor stimulation did not yield an accurate fit for longer durations. By fitting the activity at the beginning and the end of the naturalistic stimulation, we discovered that the discrepancy between both time ranges was mainly due to a change in the threshold *θ* of the Hill term in the time derivative of *y* (Equation 2)*.* We therefore allowed the threshold *θ* to change smoothly between the two different time ranges with the functional expression: *θ′ = θ×*(*τ/t*)^{2} for *t* > *τ* with *τ* = 30 s. A third set of measurements of the firing rate at steady state (time interval 20–24 s in Figure 3—figure supplement 1) was used as an independent control of the parameter fit obtained from the fitting of the other stimulation protocols.

#### Derivation of the mathematical solution of the IFF motif

As observed in Figure 4E,F, the pure IFF motif not only accounts for the response of the OSN stimulated by light, but it also represents a good approximation of the OSN dynamics stimulated by an odor (Figure 4E,F and Table 2). The general solution of Equation 2 is:$u\left(t\right)={\alpha}_{1}{e}^{-{\alpha}_{2}t}\underset{\mathrm{o}}{\overset{t}{{\displaystyle \int}}}{e}^{{\alpha}_{2}t\prime}x\left(t\prime \right)dt\prime +{C}^{ste}{e}^{-{\alpha}_{2}t}.$

For times *t* larger than *α*_{2}, the second term of the solution converges to zero, and we obtain the more compact form:$u\left(t\right)={\alpha}_{1}\underset{\mathrm{o}}{\overset{t}{{\displaystyle \int}}}{e}^{-{\alpha}_{2}\left(t-t\prime \right)}x\left(t\prime \right)dt\prime .$(4)

By sequentially integrating (4) by parts, we obtain the following identities:$u\left(t\right)={\alpha}_{1}{\langle x\left(t\right)\rangle}_{{\alpha}_{2}}=\frac{{\alpha}_{1}}{{\alpha}_{2}}x\left(t\right)-\frac{{\alpha}_{1}}{{\alpha}_{2}}{\langle \frac{dx}{dt}\left(t\right)\rangle}_{{\alpha}_{2}}.$(5)where the brackets < > denote the convolution introduced in relationship (4). While timescale of the dynamics of variable *u* is given by *α*_{2}, the time scale of the stimulus can be approximated as${\tau}_{x}\simeq \frac{{x}_{\mathrm{max}}-{x}_{\mathrm{min}}}{{\left(\frac{dx}{dt}\right)}_{\mathrm{max}}}.$

For the linear and nonlinear ramps tested in Figure 3, *τ*_{x} is typically 10 s. As the value of *α*_{2} is 0.88 s^{–1} (Table 1), the variable *u* evolves on a timescale approximately 10 times faster than the stimulus. Using relationship (4), Equation 2 can be rewritten as:$\frac{dy}{dt}={\beta}_{1}\frac{x}{{\beta}_{2}+x+{\beta}_{3}{\alpha}_{1}{{\displaystyle \int}}^{\text{}}{e}^{-{\alpha}_{2}\left(t-t\prime \right)}x\left(t\prime \right)dt\prime}-{\beta}_{4}\frac{{y}^{2}}{{y}^{2}+{\theta}^{2}}-{\beta}_{5}y.$(6)

The function multiplying parameter *β*_{4} is a steep sigmoid (or Hill function) whose value is close to 1 when *y* is reasonably larger than 0. More formally, this approximation is valid for values of *y* larger than the threshold $\tilde{y}$:$\frac{{\stackrel{~}{y}}^{2}}{{\stackrel{~}{y}}^{2}+{\theta}^{2}}=\left(1-\epsilon \right)\to \stackrel{~}{y}=\sqrt{\frac{\left(1-\epsilon \right)}{\epsilon}}\theta .$(7)

Given that the value of *θ* of 0.3, we see that the Hill term will be larger than 0.95 for values of *y* larger than 1.3 Hz. For this range of values, Equation 6 can be rewritten as:$\frac{dy}{dt}=f\left(x\left(t\right),t\right)-{\beta}_{5}y,$(8)where *f*(*t*) is a function independent of *y*. This function evolves on a timescale slower than *α*_{2}. If we assume that the firing rate *y* (0) is initially 0, the solution of (8) is:$y\left(t\right)=\underset{\mathrm{o}}{\overset{t}{{\displaystyle \int}}}{e}^{-{\beta}_{5}\left(t-t\prime \right)}f\left(x\left(t\prime \right),t\prime \right)dt\prime .$(9)

Equation 9 shows that the dynamics of *y*(*t*) obeys a characteristic time given by *β*_{5}. Since *β*_{5} = 13.03 s^{−1} (Table 1), variable *y* evolves on a timescale more than 10 times faster than the stimulus. In view of this separation of the timescales, it is justified to assume that *y* is at quasi-steady-state (QSSA, $dy/dt\simeq 0$) during the evolution of the stimulus *x* and variable *u*. By combining this assumption with (6), we find that:${y}^{QSSA}\left(t\right)=\frac{{\beta}_{1}}{{\beta}_{5}}\left(\frac{x\left(t\right)}{{\beta}_{2}+x\left(t\right)+{\alpha}_{1}{\beta}_{3}{\displaystyle \int}{e}^{-{\alpha}_{2}(t-t\prime )}x\left(t\prime \right)dt\prime}\right)-\frac{{\beta}_{4}}{{\beta}_{5}},$(10)

Based on the values of the parameters of the original ODE system (Table 1), we obtain *β*_{1}/*β*_{5} = 132.9 Hz, *β*_{2} = 1.27 W/m^{2}, *α*_{1}*β*_{3} = 0.25 s^{−1}, and *β*_{4}/*β*_{5} = 93.17 Hz. It is interesting to note that the convolution of *x* is necessarily smaller when *x* takes on larger values. Using the identities (5), we can rewrite (10) as:${y}^{QSSA}\left(t\right)={\delta}_{1}\left(\frac{x\left(t\right)}{{\delta}_{2}+x\left(t\right)-{\delta}_{3}{\displaystyle \int}{e}^{-{\alpha}_{2}\left(t-t\prime \right)}\frac{dx}{dt\prime}\left(t\prime \right)dt\prime}\right)-{\delta}_{4}\hspace{0.17em},$(11)where${\delta}_{1}=\frac{{\beta}_{1}}{{\beta}_{5}}\frac{{\alpha}_{2}}{\left({\alpha}_{2}+{\alpha}_{1}{\beta}_{3}\right)}=103.66\hspace{0.17em}Hz.$${\delta}_{2}={\beta}_{2}\frac{{\alpha}_{2}}{\left({\alpha}_{2}+{\alpha}_{1}{\beta}_{3}\right)}=0.99\hspace{0.17em}W/{m}^{2}.$${\delta}_{3}=\frac{{\alpha}_{1}{\beta}_{3}}{\left({\alpha}_{2}+{\alpha}_{1}{\beta}_{3}\right)}=\mathrm{0.22.}$${\delta}_{4}=\frac{{\beta}_{4}}{{\beta}_{5}}=93.17\hspace{0.17em}Hz.$

As expected, the QSSA solution is in excellent agreement with the results of the integration of the full ODE system (Figure 14). Given the values of the parameters (Table 1), the denominator of relationship (11) is mostly driven by the stimulus intensity for slowly evolving stimuli. The contribution of the convolution over the first derivative is significant for rapid and large changes of the stimulus intensity. In the limit where the stimulus is constant over time (d*x*/d*t* = 0), the scaling term S(*x*,*t*) is equal to zero and the QSSA predicts the dose–response function displayed in Figure 3—figure supplement 1C:${y}^{\mathrm{QSSA}}\propto \frac{x}{x+{\delta}_{2}}-{C}_{1}\text{\hspace{1em}}dx/dt=0,$where *C*_{1} is a constant. For stimulation patterns in which the intensity changes at a constant rate (linear ramps, Figure 4E and Figure 4—figure supplement 1A), the first derivative is constant with a positive or a negative sign.${y}^{\mathrm{QSSA}}\propto \frac{x}{x+{\delta}_{2}-{C}_{2}}-{C}_{1}\text{\hspace{1em}constant\hspace{0.17em}}dx/dt,$with *C*_{1} and *C*_{2} being constants. The sign of *C*_{2} is determined by that of d*x*/d*t*. For constant stimulus gradients (linear increases in concentration), we predict that the firing rate also followed a hyperbolic function (dose–response) of the stimulus intensity (Figure 3—figure supplement 1). This time, however, the dose–response is expected to saturate at lower values of the stimulus intensity when the gradient is positive (rising phase of the linear ramps) and higher values of the stimulus intensity when the gradient is negative (falling phase of the linear ramps). These predictions are consistent with the firing patterns observed in Figure 4.

#### Tracker

The tracker outlined in Figure 5 is presented in more detail in Figure 15. It was conceived and built at the Instrumentation Design and Fabrication Facility at the Janelia Research Campus. Part of the construction was carried out by KeyTech (Baltimore, USA). Unlike other tracking systems (Faumont et al., 2011; Leifer et al., 2011; Kocabas et al., 2012), our setup was designed to keep the stage on which the larva evolves fixed by mounting the camera and stimulation LEDs on a moving stage whose position was continuously updated to stay locked with the animal's position (Figure 15). The upper and lower moving stage were powered by a pair of stepper motors (T-LSR450B, Zaber Technologies, Canada). The blueprint of the tracker and list of parts are available from the following link: https://github.com/LabLouis/eLife_2015/tree/master/Tracker%20Hardware. The light stimulation module consisted of three LEDs, connected in series (LCS-0470-03-22, Mightex Systems) to an LED controller (SLA-1200-2, Mightex Systems) whose output current limit was set to 750 mA. The angle and position of each LED was fixed to cover the camera's field of view with maximum light intensity. The controller's output current scaled proportionally to the analog voltage fed into the controller board. The light intensity reaching the arena was estimated by measuring the current emitted by a photodiode (SM05PD7A, Thorlabs) connected to a benchtop amplifier (PDA200C, Thorlabs). The tracker's video camera (A622f, Basler, Germany) was placed at the center of the three blue LEDs; it delivered images at a resolution of 800 × 800 pixels at a frame time interval of 23 ms. Combined with the time required to process the image and actuate the position of the stage, the effective frame rate was 30 Hz.

As summarized in Figure 15C, the larval tracker control unit (LTCU) formed the main hardware interface controlling the LEDs and acquiring images from the video camera. While the camera was controlled via a transistor–transistor logic pulse signal, a 12-bit digital-to-analog converter output was used to send the control signals (0–5 V analog signal) to the LED controller. An in-circuit debugging (ICD) Port was used to connect the LTCU to an ICD3 programmable interface controller via a registered jack (RJ11) connector interface, while an USB Port enabled the LTCU's communication to the PC. A customized program written in C was used to direct the function of the LTCU. This C program enabled the LTCU to respond to the commands issued by the PC. The software interface of the tracking and image analysis software interfacing the LTCU was written in JAVA. Both the C program and JAVA interface are available from the following links: https://github.com/LabLouis/eLife_2015/tree/master/Wormsign (tracker) and https://github.com/LabLouis/eLife_2015/tree/master/Venkman (JAVA controller interface).

##### Update of light intensity

For closed-loop experiments described in Figures 6, 7, the light intensity was updated based on the position of the head of the larva mapped on a predefined light landscape. The light landscape was loaded and interpolated by the software controller environment from a matrix with a spatial resolution of 1 × 1 mm. Since the position of the larva was monitored at a higher resolution, the intensity of the spatial landscape was redefined by using a bi-linear interpolation along the *x*- and *y*-axis. The position of the center of the light gradient was automatically adjusted at the beginning of the experiment in such a way that every larva started in a direction facing the center of the gradient at a fixed distance of 9.6 mm from the center for the exponential light gradient (Figure 6) and a distance of 17.1 mm for the family of light landscapes (Figure 7). The minority of trajectories from which larvae failed to detect the presence of the light gradient was discarded from the dataset.

For open-loop experiments described in Figure 5, the LED intensity was updated based on a predefined temporal function. This function was only implemented when the larva was classified in a run mode according to the rules described in Figure 16. Throughout the study, odor and light gradient landscapes were represented using brewermap (S. Cobeldick, MathWorks file exchange) with color schemes from http://colorbrewer2.org/.

#### Computation and predictions of the turn probability

In the behavioral experiments of Figure 5, the probability of turning (‘turn rate’) was estimated from the relative number of turns that took place during a 1-s time window centered on the time point of interest. If we denote the number of runs observed at the beginning and the end of the ith time window as Nb_{i} and Ne_{i}, respectively, Nb1 represents the total number of runs contained in the dataset. Over time, Nb_{i} decreases monotonically to 0. The turn probability associated with the ith time point was estimated as the fraction of runs that ended during the corresponding time window: (Nb_{i} − Ne_{i})/Nb_{i}. A sliding time window was then applied to estimate the turn probability corresponding to every time point of the experiment. The turn probability was thus defined as the likelihood of implementing a turn within a 1 s time window, resulting in values smaller than 1 (in the case of 1 all runs entering a given time window switch to a turn) and larger or equal to 0 (in the case of 0 no turn takes place during a given time window). While a short time window led to noisy turn probability estimates, long time windows led to undesirable averaging effects. We empirically found that a time window of 1 s (or 30 time points) offered a good tradeoff.

##### Generalized linear model for turn predictions

As described in Figure 5, the predicted probability of turning was computed from a GLM based on a linear function of the firing rate of the OSN, *y*. To map the domain of definition of the firing rate ([0, ∞]) onto the domain of definition of the turn probability ([0, 1]), we applied a logit link function (Myers et al., 2002). This led to the following relationship:$\mathrm{ln}\left(\frac{\lambda \left(t\right)}{1-\lambda \left(t\right)}\right)={\gamma}_{0}+{\gamma}_{1}y\left(t\right).$(13)

The two parameters of the model, *γ*_{0} and *γ*_{1}, were trained on a set of 10 light ramps listed in Figure 5—figure supplement 1. Parameter *γ*_{0} corresponds to a term related to the basal turn rate. The values of the parameters of the model are reported in Table 3.

As shown in Figure 17, the logit transform included in the GLM improved the accuracy of the fit without being essential. The predictive value of the model trained on open-loop behavior was then evaluated when applied to closed-loop experiments such as those described in Figures 6–8. The performance of the test model was compared to a control model devoid of sensory processing of the OSN. For the control model, relationship (13) became:$\text{ln}\left(\frac{\lambda \left(t\right)}{1-\lambda \left(t\right)}\right)=\gamma {\prime}_{0}+\gamma {\prime}_{1}x\left(t\right),$(14)where the parameters *γ′*_{0} and *γ′*_{1} were computed from a linear regression on the open-loop experiments listed in Figure 5—figure supplement 1 (parameter values listed in Table 3).

Finally, the contribution of the first derivative of the stimulus intensity was assessed in the enhanced control model:$\text{ln}\left(\frac{\lambda \left(t\right)}{1-\lambda \left(t\right)}\right)=\gamma {\u2033}_{0}+\gamma {\u2033}_{1}x\left(t\right)+\hspace{0.17em}\gamma {\u2033}_{2}\frac{dx}{dt}\left(t\right).$(15)

The time derivative of the stimulus was defined by the change in stimulus intensity that occurred during the frame (33 ms) preceding the present time point *t*. The goodness of fit of the two control models can be compared to the test model in Figure 5—figure supplement 3.

#### Statistical procedures and data analysis

This section summarizes the methods used for the quantification of physiological and behavioral data.

##### Quantification of goodness of fit of the OSN and behavioral models (material pertaining to Tables 2, 4, Figures 13, 18)

For the firing rate of the OSN and the probability of turning, two metrics were used to quantify the goodness of fit of the models. First, we used Pearson's correlation coefficient. If we denote the experimental observations as *X*_{t} and the output from the model as *Y*_{t}, the correlation coefficient was computed as:$r=\frac{{\displaystyle {\sum}_{t=1}^{n}\left({X}_{t}-\overline{X}\right)\left({Y}_{t}-\overline{Y}\right)}}{{s}_{X}{s}_{Y}},$where *s*_{X} is the standard deviation of variable *X* and *n* represents the total number of time points in the dataset. The second metric used is the coefficient of variation (CV) of the root-mean-square error (RMSE) defined as:$\text{CV}\left(\text{RMSE}\right)=\frac{\sqrt{\frac{1}{n}{{\displaystyle \sum}}_{t=1}^{n}{({X}_{t}-{Y}_{t})}^{2}}}{\overline{X}}.$

##### Error bars for the PSTHs (material pertaining to Figures 2–8)

Except for Figure 13, all PSTH were computed on a sliding time window of 50 ms (Dayan and Abbott, 2001). Throughout the manuscript, the error bars (shaded areas) associated with the firing rate of the *Or42a>*ChR2 OSN (PSTH) denote the standard deviation.

##### Error bars for the turn probabilities estimated from open-loop behavioral experiments (material pertaining to Figures 5, 17, 18)

Error bars for the turn probability were estimated by resampling the initial distribution of runs 100 times without replacement and with a sample containing half of the original set of runs. The error bars reported in the figures (shaded areas) correspond to the standard deviations calculated on the resampled sets of runs.

##### Cross-validation of the ODE model for the OSN spiking activity (material pertaining to Figure 4—figure supplement 2)

The composite IFF+IFB model developed to reproduce and predict the activity elicited by odor stimulation was trained on the full set of odor ramps listed in Figure 4—figure supplement 1 together with the natural stimulus shown in Figure 2D,E. The parameters derived through this training procedure (Table 1) were used throughout the study. To validate the structure of the ODE model, we followed a cross-validation approach in which the IFF+IFB model was trained on the 4-s linear ramps listed in Figure 4—figure supplement 1Ai–ii and used to accurately predict the activity elicited by the 8-s ramps listed in Figure 4—figure supplement 2B (middle panel) as well as the naturalistic stimulus shown in Figure 4—figure supplement 2C (top panel). The same approach was followed to provide a successful validation of the IFF model to describe the spiking activity elicited by light stimulations (Figure 4—figure supplement 2, bottom panels).

##### Controls for behavioral experiments: open-loop light stimulation (material pertaining to Figure 5)

In open-loop stimulation experiments (Figure 5), the output of the integrated stimulus-to-behavior GLM described in (13) was computed for each time point of the experiment. The performances of the test model were compared to a control GLM in which the turn probability was predicted from the stimulus intensity without any sensory processing from the OSN. For this control model, we independently fitted a GLM identical to that presented in Figure 5D after replacement of the firing rate by the stimulus intensity alone or a combination of the stimulus intensity and its first derivative (Figure 5—figure supplement 3). The goodness of fit of the test and control GLMs are reported in Table 4.

##### Controls for behavioral experiments: closed-loop light and odor stimulation (material pertaining to Figures 6, 8)

In closed-loop experiments conducted in light and odor gradients (Figures 6, 8), the predictions of the integrated stimulus-to-behavior GLM described in equation (13) were analyzed by computing the turn-triggered average of the turn probability. This average time course was compared to two controls. The first control consisted in achieving turn predictions based on a sensory experience whose relation to the corresponding behavior was uncoupled. To this end, we inverted the time course of the light (odor) intensity and associated it with the forward time course of the behavior. This first control preserved the statistics of the stimulus intensity experienced by the larva. The second control was based on the assumption that the OSN firing rate was constant over time and corresponded to the mean activity predicted by a typical trajectory. Given that each larva experienced a different time course of light intensity, the mean OSN firing rate was computed on a trajectory-by-trajectory basis. Note that the control GLM derived in equation (14) for the open-loop light ramps was deemed inadequate to predict closed-loop behaviors in odor gradients due to the mismatch between the dynamic range of the stimulus associated with the light ramps and that experienced in the odor gradient.

##### Cross-validation of the GLM for the turn probabilities (material pertaining to Figure 5—figure supplement 2)

The integrated stimulus-to-behavior GLM was trained on the full set of light ramps listed in Figure 5—figure supplement 1. To validate the structure of the GLM, we followed a cross-validation approach in which the GLM was trained on the 4-s linear ramps listed in Figure 5—figure supplement 2A and used to accurately predict the activity elicited by the 8-s ramps listed in Figure 5—figure supplement 2Bi–iii. Furthermore, we demonstrated that training the GLM on a single light ramp was sufficient to make accurate predictions on a different ramp (Figure 5—figure supplement 2C).

##### Likelihood analysis for behavioral predictions (material pertaining to Figures 6, 8)

To assess the quality of the behavioral predictions obtained from the stimulus-to-behavior GLM described in equation (13), we computed the likelihood associated with the observation of the entire set of runs obtained in the closed-loop light and odor gradients. Let us denote the total number of runs observed in a particular gradient as N. The likelihood of the ith run was computed based on the turn probability predicted on bins of 1 s. The probability of observing a turn between time *t* and (*t* +1 s) is: *λ*_{i} (*t*) where the index *i* refers to the sensory experience associated with the ith run. The probability of not turning during a time interval (*t*, *t* +1) is: 1 − *λ*_{i} (*t*). Thus, the probability of observing a given run lasting 5.6 s can be estimated as:${p}_{i}=\left(1-{\lambda}_{i}\left(0.6\right)\right).\left(1-{\lambda}_{i}\left(1.6\right)\right).\left(1-{\lambda}_{i}\left(2.6\right)\right).\left(1-{\lambda}_{i}\left(3.6\right)\right).{\lambda}_{i}\left(4.6\right).$(16)

Using relationship (16), we calculated the likelihood of the entire set of runs as:$L={\displaystyle \prod}_{i=1}^{N}{p}_{i}.$(17)

The log-likelihoods (logL) of the predictions associated with the test model and the two controls (see previous section) were computed. To evaluate the reliability of differences between the test model and controls, we applied a standard bootstrap approach (Martinez and Martinez, 2001). From the original collection of runs, we generated 10,000 independent new samples of runs based on random resampling with replacement. For each sample, we computed the logL of the test model and the controls. Next we considered the relative difference in logL between the model and the control defined as:$\frac{\text{\Delta logL}}{{\text{logL}}_{\text{test}}}=\frac{\left({\text{logL}}_{\text{test}}-{\text{logL}}_{\text{control}}\right)}{{\text{logL}}_{\text{test}}}.$

The distribution of this variable is reported in Figure 6F for the behavior elicited by the light gradient, and in Figure 8D for the behavior elicited by the odor gradient. Finally, we computed the number of instances where $\text{\Delta logL}/{\text{logL}}_{\text{test}}$ was lower than 0 (control outperforming the test model) and derived a p-value for the hypothesis that the test model yields a larger likelihood than the controls.

#### Optogenetics-based chemotaxis in the background of a silenced and intact olfactory system

For optimal results, the spike-sorting method (OpSIN, Figure 11B) developed in this work required that the recordings of the odor-stimulated OSN activity be achieved in the background of a silenced olfactory system (*Orco*^{−/−}). For this reason, the genotype of the larvae used throughout the study for physiological and behavioral quantification resulted from the cross: *w*;*Or42a*-Gal4,*GMR*-*hid*;*Orco*^{2},*dTrpA1*^{1} × *w*;UAS-*Orco*,UAS-ChR2-H134R;*Orco*^{2},*dTrpA1*^{1}*.* Given that interneurons of the larval antennal lobe clearly contribute to the neural representation of odors (Asahina et al., 2009; Larkin et al., 2010), it was important to determine whether the sensorimotor principles controlling chemotactic behavior in a silenced and intact olfactory system are the same. In this aim, we examined the behavior of larvae with ChR2 expressed in the *Or42a* OSN in the background of a fully functional olfactory system (21 intact OSNs): UAS-ChR2-H134R/*Or42a*-Gal4;*gl*^{60j},*dTrpA1*^{1}*.* Larvae bearing the double mutant alleles *gl*^{60j} and *dTrpA1*^{1} were insensitive to light (data not shown). In closed-loop and open-loop conditions of light stimulation, we found a high similarity of the chemotactic responses observed in the background of 1 or 21 functional OSNs (Figure 18). This result corroborates the idea that the basic control principles learned from single functional OSN larvae are relevant to wild-type larvae.

#### Scripts

All scripts described in the ‘Materials and methods’ as well as the blueprint of the larval tracker are available for download from the following website: https://github.com/LabLouis/eLife_2015.

## References

- Quantitative model for gene regulation by lambda phage repressorProceedings of the National Academy of Sciences of USA, 79, 1129-1133, 1982
- An introduction to systems biology: design principles of biological circuitsChapman & Hall/CRC, Boca Raton, FL, 2007
- E. coli in motionSpringer, 2004
- Using dynamic time warping to find patterns in time seriesKDD workshop, Seattle, WA, 1994
- Transcriptional regulation by the numbers: modelsCurrent Opinion in Genetics & Development, 15, 116-124, 2005
- ROOT—an object oriented data analysis frameworkNuclear Instruments and Methods in Physics Research Section A, 389, 81-86, 1997
- Genetic dissection of behavior: modulation of locomotion by light in the
*Drosophila melanogaster*larva requires genetically distinct visual system functionsThe Journal of Neuroscience, 19, 3337-3344, 1999 - Theoretical neuroscience: computational and mathematical modeling of neural systemsMassachusetts Institute of Technology Press, Cambridge, Mass, 2001
- Odor coding in a model olfactory organ: the
*Drosophila*maxillary palpThe Journal of Neuroscience, 19, 4520-4532, 1999 - The orientation of animalsDover Publications, New York, 1961
- Sensorimotor structure of
*Drosophila*larva phototaxisProceedings of the National Academy of Sciences of USA, 110, E3868-E3877, 2013 - Sensory determinants of behavioral dynamics in
*Drosophila*thermotaxisProceedings of the National Academy of Sciences of USA, 112, E220-E229, 2015 - G-prime: a free, windows based data acquisition and event analysis software package for physiology in classrooms and research labsJournal of Undergraduate Neuroscience Education, 8, A50-A54, 2009
- Computational statistics handbook with MATLABCRC press, 2001
- Localized olfactory representation in mushroom bodies of
*Drosophila*larvaeProceedings of the National Academy of Sciences of USA, 106, 10314-10319, 2009 - Functional diversity among sensory receptors in a
*Drosophila*olfactory circuitProceedings of the National Academy of Sciences of USA, 110, E2134-E2143, 2013 - Generalized linear models: with applications in engineering and the sciencesJ. Wiley, New York, 2002
- Signal transduction in vertebrate olfactory ciliaThe neurobiology of olfaction, Boca Raton (FL), 2010
- Spikes: exploring the neural codeMIT Press, Cambridge, Mass, 1997
- Spatial orientation: the spatial control of behavior in animals and manPrinceton University Press, Princeton, NJ, 1984
- High-speed odor transduction and pulse tracking by insect olfactory receptor neuronsProceedings of the National Academy of Sciences of USA, 111, 16925-16930, 2014
- Olfactory receptors on the cockroach antenna signal odour ON and odour OFF by excitationThe European Journal of Neuroscience, 22, 3147-3160, 2005
- Modeling the chemotactic response of
*Escherichia coli*to time-varying stimuliProceedings of the National Academy of Sciences of USA, 105, 14855-14860, 2008 - Coding and transformations in the olfactory systemAnnual Review of Neuroscience, 37, 363-385, 2014
- Molecular architecture of smell and taste in
*Drosophila*Annual Review of Neuroscience, 30, 505-533, 2007 - Early olfactory processing in
*Drosophila*: mechanisms and principlesAnnual Review of Neuroscience, 36, 217-241, 2013 - Early events in olfactory processingAnnual Review of Neuroscience, 29, 163-201, 2006
- Robust perfect adaptation in bacterial chemotaxis through integral feedback controlProceedings of the National Academy of Sciences of USA, 97, 4649-4653, 2000

## Acknowledgements

We thank A Leonardo, E Knoche, and the Louis lab for comments on the manuscript. The tracker was developed with the help of L Ramaswamy (ID&F at Janelia Research Campus). We are grateful to the following individuals for insightful discussions at different stages of the project: C Bargmann (molecular interpretation of the IFF motif), H Davidowitz and D Rinberg (design of olfactometer in gaseous phase), A Kim and A Lazar (comparison between transfer function adult and larval OSNs), A Leonardo (linear filter analysis and data interpretation), R Moreno (likelihood analysis), M Phillips (turn classifiers). We thank S Pulver and L Griffith for donating the UAS-ChR2-H134R transgenic stock. ML acknowledges funding from the Spanish Ministry of Science and Innovation (MICINN, BFU2008-00362, BFU2009-07757-E/BMC and BFU2011-26208). We are grateful to KeyTech (Baltimore, USA) for advising about the design of the tracker and for carrying out the assembly of the hardware. AS, AGM, VGR, MM, JS, JR, DJ, and ML were supported by the EMBL/CRG Systems Biology Program. JS was supported by ICREA. AD was funded by the European Commission FP7 Initial Training Network FLiACT (289941). MS was partially funded by the National Centre for Biological Sciences—Tata Institute of Fundamental Research. GL, PA, ETT, CW, SD, and VJ were supported by the Howard Hughes Medical Institute. This project received support from the HHMI Janelia Research Campus visitor program (AS, AGM, VGR, DJ, and ML).

## Decision letter

eLife posts the editorial decision letter and author response on a selection of the published articles (subject to the approval of the authors). An edited version of the letter sent to the authors after peer review is shown, indicating the substantive concerns or comments; minor concerns are not usually shown. Reviewers have the opportunity to discuss the decision before the letter is sent (see review process). Similarly, the author response typically shows only responses to the major concerns raised by the reviewers.

Thank you for sending your work entitled “Dynamical feature extraction at the sensory periphery guides chemotaxis” for consideration at *eLife*. Your article has been favorably evaluated by Eve Marder (Senior editor) and three reviewers, one of whom, Ronald L Calabrese, is a member of our Board of Reviewing Editors.

The Reviewing editor and the other reviewers discussed their comments before we reached this decision, and the Reviewing editor has assembled the following comments to help you prepare a revised submission.

The authors present an extraordinarily thorough electrophysiological and behavioral analysis of the chemotaxis in *Drosophila* larvae in natural odor gradients, defined odor gradients, and optogenetically induced fictive olfactory gradients. These analyses relate OSN activity empirically determined to behavior using a model of sensory transduction and a GLM relating neural activity to the probability of turning. They also create closed loop virtual reality environments to test the effectiveness of their models. They conclude that OSN activity accurately predicts turning probability by a simple linear transform and thus OSN spiking dynamics in odor gradients are key for understanding chemotaxis.

The major biological findings are:

1) Real odor landscapes even in a controlled chamber are complex and they can be described quantitatively.

2) OSN activity in real odor and in fictive odor landscapes can be assayed and then modeled (albeit in an ad hoc manner) so that OSN activity can be accurately predicted in both real and fictive odor landscapes.

3) Fictive controlled odor landscapes can be navigated in a chemotatic way and turn probability can be accurately predicted (using the OSN model and a further ad hoc model) based on OSN activity. Fictive odor landscapes are elegantly designed to extract real behavioral principles. For example a ‘well’ landscape shows that a precipitous drop in predicted (and confirmed) OSN activity induces turns.

4) When real odor landscapes are chemotaxed, then turn probability can be accurately predicted based on predicted (and confirmed) OSN activity.

The major technical innovations are:

1) Real odor landscapes can be calculated based on diffusion equations with sufficient accuracy to extract real odor dynamics for a moving maggot. Confirmed by IR spectroscopy.

2) It is possible to move between the liquid phase and the gas phase when experiments demand it by matching liquid phase and gas phase OSN activity.

3) Identical fictive and real odor waveform leads to measureable differences in OSN activity owing to adaptive processes in the OSN during odor stimuli.

4) Ad hoc models of OSNs can be constructed that capture their essential activity to real and fictive odor stimuli.

5) GLM ad hoc models can capture the relationship of the ONS activity to turn probability, and used as a tool to understand real chemotaxis in an odor gradient.

6) Tracker technology can present freely moving maggots with fictive odor gradients to determine turn probability.

At the paragraph level the writing is clear and the paper is thoroughly illustrated, but finding the above major contributions amid the voluminous data (especially supplemental data) is difficult owing to the overall structure of the paper. Moreover the Discussion seems to focus too much on the OSN model and its implications at the expense of the biological insights for chemotaxis. The authors must be at pains to bring out these contributions in the way they structure the paper and in Abstract and Discussion. The logical flow of the techniques (tool development) and experiments and the conclusions must be made more apparent. One thing that will help immensely with flow will be to delete some of the supplemental figures on tool development or to place the call outs in Materials and methods (simply refer—no figure call outs—to Materials and methods in the Results): Figure 1–figure supplement 1, 2, 3 in Materials and methods; Figure 2–figure supplement 1 can be eliminated, as it is a negative result; Figure 2–figure supplement 2 can be eliminated; Figure 4 can be made into a supplemental figure and placed in Materials and methods; Figure 5–figure supplement 1, 2, 5 in Materials and methods; Figure 6–figure supplement 1 eliminated; Figure 8–figure supplement 1 in Materials and methods.

There are some technical concerns that must be addressed:

1) Statistics. In Materials and methods add a statistics section and write a clear description of the statistical tests used. This is somewhat scattered throughout Materials and methods now. Much of the statistics is in tables and in the figure legends and needs to be made more apparent. Figures 6F and 8D, E present critical statistical tests that are based on a subset of long run trajectory. The rationale and validity of excluding short runs need to be made more apparent.

2) There is some concern about whether parameters for the models were fixed at some point or whether they were changed with each experiment. One possible reading is that the parameters of Table 1 and Table 3 represent fixed parameters based on the ‘training’ of the associated figure and that subsequent uses of the models used these fixed parameters. The authors must make this explicit. If parameters, were changed with each new experiments then this would seriously diminish the value of the modeling. Specifically, the authors' need to address the question of whether models that were trained on a set of input–output pairs generalize to an equivalent set of pairs that were not in the original training set.

3) There is the concern that the sensory neuron model is fitted to events on a time scale of less than 10 sec (Figure 2, 3, 4, etc.), whereas the dynamics of chemosensory stimuli during behavior in an odor gradient occur on a time scale of about 30 sec. The authors should acknowledge in text any difference in time scale and dynamic range between real odor time courses and the input domain over which the model was fitted.

4) The odor and channelrhodopsin (ChR) experiments are done in *Or83b* mutant background. Thus the dynamics of *Or42a*-ORNs can be more easily related to behavior in an otherwise silent olfactory system. Will the same be the case in the presence of spontaneous spiking of other ORNs? Another important issue with doing behaviors in a completely silent system is that local interaction at higher levels of olfactory circuits would likely be diminished if not completely absent. Therefore OSN activity-to-turn probability transformation determined might not be representative of that in the WT animal. The authors must address this limitation forthrightly in Discussion.

5) The logit transform of the equation in Figure 5D caused some reviewer confusion; here is a case where some explanation in the text is needed and not just a reference to Materials and methods.

The results presented and tools developed have important implications for behavioral analysis of chemotaxis in animals and set a standard for further mechanistic studies in this important model system. Moreover, the approach used here can be a model for analyses of sensory-motor transformations in other systems.

[Editors' note: further revisions were requested prior to acceptance, as described below.]

Thank you for resubmitting your work entitled “Dynamical feature extraction at the sensory periphery guides chemotaxis” for further consideration at *eLife*. Your revised article has been favorably evaluated by Eve Marder (Senior editor), a Reviewing editor, and one of the original reviewers. The manuscript has been improved but there are some remaining issues that need to be addressed before acceptance, as outlined below:

This revision meets the major expectations set down by the previous reviews. The flow of the paper now is greatly improved. All the main technical points have been resolved and the new statistical section adds significantly. There are a few minor points that should still be considered.

1) The authors belabor the description of Figure 3. The figure itself has too much data (3D and 3E are the only panels that are essential.). Emphasize the main point of the figure: the sensitivity of ORNs to concentration slope. Between the subsection “Characterization of the features encoded by a single larval OSN stimulated by controlled olfactory signals”, where you have concluded that linear filters won't work, and the passage, in the subsection “Phenomenlogical model of the olfactory transduction cascade”, where you start with the dynamical system approach, you lose momentum. The authors can do a better job of explaining how the qualitative observations in Figure 3 led them to the model they built in Figure 4.

2) In the Discussion, or when the paper is cited, it might be appropriate to compare the approach of Nagel and Wilson, 2011.