Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales

Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales

Article Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales Graphical Abstract Global neuronal activity states (Level I) L...

4MB Sizes 0 Downloads 39 Views

Article

Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales Graphical Abstract Global neuronal activity states (Level I)

Local motor circuits (Levels II & III)

Authors

Forward crawling

~0.05 Hz

Backward crawling

Correspondence Propagated bends

Turn

~0.5 Hz

The nervous system must coordinate behavior across several timescales. A decades-old hypothesis in ethology posits that this occurs via hierarchical control. Kaplan et al. show that C. elegans employs hierarchically nested neuronal dynamics across brain and motor circuits to implement such multi-timescale behavioral organization.

~1 Hz

Nested neuronal dynamics: Level I ~0.05 Hz Level II ~0.5 Hz ~1 Hz

Forward

[email protected]

In Brief

Head-casts

Level III

Harris S. Kaplan, Oriana Salazar Thula, Niklas Khoss, Manuel Zimmer

Forward + head-casts

Backward

Turn

Highlights d

Slow dynamics across brain and motor circuits drive upperhierarchy motor states

d

Fast dynamics in motor circuits drive lower-hierarchy movements within these states

d

Slower dynamics tightly constrain the state and function of faster ones

d

This rigid hierarchy nevertheless enables flexible behavioral control

Kaplan et al., 2020, Neuron 105, 1–15 February 5, 2020 ª 2019 The Author(s). Published by Elsevier Inc. https://doi.org/10.1016/j.neuron.2019.10.037

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Neuron

Article Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales Harris S. Kaplan,1,2,3 Oriana Salazar Thula,1,2,3 Niklas Khoss,1,2 and Manuel Zimmer1,2,4,* 1Department

of Neurobiology, University of Vienna, Althanstrasse 14, 1090 Vienna, Austria Institute of Molecular Pathology (IMP), Vienna BioCenter (VBC), Campus-Vienna-BioCenter 1, 1030 Vienna, Austria 3These authors contributed equally 4Lead Contact *Correspondence: [email protected] https://doi.org/10.1016/j.neuron.2019.10.037 2Research

SUMMARY

Classical and modern ethological studies suggest that animal behavior is organized hierarchically across timescales, such that longer-timescale behaviors are composed of specific shorter-timescale actions. Despite progress relating neuronal dynamics to single-timescale behavior, it remains unclear how different timescale dynamics interact to give rise to such higher-order behavioral organization. Here, we show, in the nematode Caenorhabditis elegans, that a behavioral hierarchy spanning three timescales is implemented by nested neuronal dynamics. At the uppermost hierarchical level, slow neuronal population dynamics spanning brain and motor periphery control two faster motor neuron oscillations, toggling them between different activity states and functional roles. At lower hierarchical levels, these faster oscillations are further nested in a manner that enables flexible behavioral control in an otherwise rigid hierarchical framework. Our findings establish nested neuronal activity patterns as a repeated dynamical motif of the C. elegans nervous system, which together implement a controllable hierarchical organization of behavior. INTRODUCTION Animal behavior unfolds over a wide range of timescales, from sub-second muscle contractions to circadian rhythms. Nervous systems not only act on each of these timescales but must also coordinate across them to implement long-term behavioral strategies and avoid interfering actions. Classical (Dawkins, 1976; Tinbergen, 1951) and modern (Berman et al., 2016; Glaze and Troyer, 2006; Gomez-Marin et al., 2016; Marques et al., 2018; Wiltschko et al., 2015; Duistermars et al., 2018) ethological studies posit that such inter-timescale coordination is hierarchical, with longer timescales at higher hierarchical levels. Specific shorter-timescale actions are constrained to occur only in the context of a hierarch, a particular longer-timescale motor program or behavioral state (Dawkins, 1976). Tinbergen described

stickleback behavior as hierarchical, with the reproductive instinct encompassing sub-behaviors like nest building or defensive fighting; each of these, in turn, consists of specific subactions like digging or biting (Tinbergen, 1951). Modern quantitative analyses suggest that behaviors as diverse as birdsong and Drosophila locomotion are organized hierarchically (Berman et al., 2016; Glaze and Troyer, 2006). While behavioral evidence supports the hierarchical model, neurophysiological evidence is lacking. It thus remains possible that the underlying neuronal mechanisms are entirely non-hierarchical (Berman et al., 2016). For example, while birdsong can be described hierarchically (Glaze and Troyer, 2006), neurophysiological evidence suggests a sequential chain of neuronal activities as the underlying mechanism (Long et al., 2010). In rodents, distinct behavioral timescales are represented by separable neuronal populations (Jin and Costa, 2015; Moore et al., 2013), which potentially provide a substrate for inter-timescale coordination. Rhythmic orofacial behaviors operating at different frequencies appear to be coordinated by a hierarchical phaseresetting mechanism, according to behavioral and anatomical evidence (Moore et al., 2013). Still, it remains unclear how different timescale neuronal dynamics interact to implement hierarchical behavior. Addressing this question necessitates fine-grained analysis of both behavior and neuronal activity (Krakauer et al., 2017). We therefore examined C. elegans locomotion. C. elegans behaviors include sub-second body-bends, seconds- to minutes-long motor states such as forward and reverse crawling, and longer-lasting states of exploration, exploitation, and quiescence. Detailed analyses of postural dynamics have hinted at an underlying hierarchical organization (Gomez-Marin et al., 2016). Physiological studies, however, have primarily focused on single timescales. For example, calcium imaging studies have described motor neuron dynamics underlying the oscillatory gait (Gao et al., 2018; Shen et al., 2016; Wen et al., 2012; Xu et al., 2018; Fouad et al., 2018) and interneuron dynamics underlying forward/ reverse locomotion switches (Kato et al., 2015; Kawano et al., 2011; Li et al., 2014; Piggott et al., 2011). Here, we use quantitative behavior analysis, nervous-systemwide single-cell-resolution functional imaging, and circuit manipulations to reveal nested neuronal dynamics giving rise to a behavioral hierarchy in C. elegans. At the uppermost hierarchical level, an 0.05-Hz nervous-system-wide neuronal activity cycle drives switches between forward and reverse crawling states

Neuron 105, 1–15, February 5, 2020 ª 2019 The Author(s). Published by Elsevier Inc. 1 This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

E

Segment #

Tail 0

0 2

4 6 Time (seconds)

F

Dorsal / ventral Prop-bends Head-casts

8D

-0.3

Angle (rad)

V P

V 0.3

5 10 15 20

0.4 0.04

12

0.2

D ****

0 0 5 10 15 20 Head Tail Final propagation segment #

Prop-bend phase (rad)

Dorsal 0 prop-bend maximum

Ventral prop-bend maximum

-0.3

0.6

0.08

Dorsal head-casts Ventral head-casts All phases (control)

0.3 0

0.8

0.56

V Head-bend angle (rad)

Propagatedbends 1

Cumulative fraction

Segment #

0.3 mm

V D -0.4 0 0.4 Angle (rad)

Headcasts 0.6

Head 24

A D

C

Cycle period (seconds)

B

1

Fraction

A

100

**** 10 1 0.1

Fwd/ Prop- Headrev bends casts cycle

G Fwd/Rev cycle

F

~ 0.05 Hz

R

D

~ 0.5 Hz

V

Propagatedbends

D

~1 Hz

V

Head-casts

D Prop-bend phase (rad) 0 32

0

5 Time (seconds)

0

0.2 Fraction

0.4

Figure 1. A Multi-timescale Behavioral Hierarchy (A) Body angle measurement. A, anterior; P, posterior; V, ventral; D, dorsal. (B) Lower: example posture time series kymogram. Head-bend propagations traced by black lines. Upper: worm images with propagated-bends (filled arrows) and head-casts (open arrows) indicated. Scale bar, 0.4 mm. (C) Fractional and cumulative distributions of each head bend’s most posterior propagation segment. Dotted line indicates cutoff used to distinguish head casts and propagated bends in subsequent quantifications. n = 45,129 head bends pooled from 28 assays, 20 animals per assay. (D) Violin plot showing median and 1st and 3rd quartiles of cycle periods for forward/reverse (forward + reverse bout duration, n = 1,259), propagated-bend (n = 25,817), and head-cast cycles (n = 341) pooled from 14 assays, 20 animals per assay. ****p < 0.0001, Mann-Whitney test. (E) Example head-bend angle time series illustrating propagated-bend phase measurement. Red and blue dashed lines indicate initial head-cast phases, quantified in (F). (F) Fractional distributions of initial head-casts binned according to their propagated-bend oscillation phases. n = 427 dorsal and 194 ventral head-casts pooled from 21 animals. p < 106 for both distributions, indicating the probability that each is drawn from the full data distribution shown in gray. (G) Hierarchical model of behavior with approximate cycle frequencies. See also Figure S1.

and also controls two faster neuronal oscillations, toggling them between different dynamical states and functional roles. At the intermediate hierarchical level, B-class motor neurons (B-MNs) drive 0.5-Hz crawling undulations. At the lowest hierarchical level, SMD motor neurons drive 1-Hz head-casts, which are further nested within specific phases of the mid-level oscillation. Crucially, by comparing neuronal activity in moving versus immobilized animals, we show that these nested dynamics persist in the absence of behavioral execution. Hierarchically nested neuronal dynamics are therefore an intrinsic property of these neurons and their circuit interactions. RESULTS A Multi-timescale Behavioral Hierarchy of Motor Actions To identify behaviors with relationships across timescales, we video-tracked animals to measure motor programs and associated gaits. C. elegans switch stochastically between forward- or reverse-directed crawling (Roberts et al., 2016); each of these motor programs consists of alternating dorsal/ventral undulatory bends. During the predominant forward locomotion state, bends originate in the head and propagate posteriorly. We

2 Neuron 105, 1–15, February 5, 2020

quantified 24 bend angles along the worm’s body (Figure 1A) and traced each head bend’s propagation to its posteriormost segment (Figures 1B and S1A). This revealed a bimodal distribution, indicating two distinct types: one propagating completely to the tail (henceforth ‘‘propagated-bends’’) and another terminating anterior to the mid-body (henceforth ‘‘head-casts’’) (Figures 1B and 1C). Several metrics suggested that head-casts were a distinct class of actions, as opposed to aborted propagated-bends (Figures S1B–S1D). Head-casts were reminiscent of previously described ‘‘foraging’’ movements of the nose (Huang et al., 2008). The exact definition of foraging is ambiguous, and previous measures likely included head-casts as well as faster, more anterior nose movements (for discussion, see Yemini et al., 2013). Here, we rely on a precise definition based on propagation and, therefore, use ‘‘head-casts’’ instead of ‘‘foraging.’’ Forward locomotion consisted primarily of propagated-bends (Figure 1C) intermittently superimposed with episodes of head-cast oscillations (Figures S1A and S1E); when they did occur, head-cast oscillation cycles were typically faster than propagated-bend ones (Figure 1D). Together with forward/reverse locomotion switches, these behaviors occurred on three distinct timescales (Figure 1D).

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Nevertheless, these behaviors were considerably coupled. Head casts were ventral- or dorsal-biased, depending on whether the previous propagated-bend was ventral or dorsal (Figures 1E, upper, and S1F). To investigate this further, we calculated the phase of the propagated-bend cycle, with dorsal – ventral – dorsal corresponding to 0 – 1p – 2p rad (Figure 1E, lower). This revealed that head-cast episodes were only initiated at restricted phases (Figure 1F). This phase dependence, which we term ‘‘phase-nesting,’’ suggests a brief window of opportunity for head-casts within each propagated-bend cycle. Indeed, head-casts preferentially occurred during the longest-duration propagated-bend cycles, consistent with longer cycles having wider windows of opportunity (Figures S1G–S1I). Alternatively, head-cast occurrence could stall and, therefore, lengthen the propagated-bend cycle, a possibility we examine below. Both head-bend types occurred exclusively during forward locomotion: during reversals, bends propagated from tail to head, and no head-casts occurred (Figures S1J and S1K). Together, these data suggest a hierarchical organization of behavior, in which shorter-timescale behaviors are strictly constrained by specific longer-timescale behavioral phases or states (Figure 1G). We next examined neuronal activities underlying these behaviors. A Nervous-System-wide Representation of the Uppermost Hierarchical Level In our previous work, we developed a single-cell-resolution, whole-brain, Ca2+-imaging approach in immobilized animals (Kato et al., 2015; Schro¨del et al., 2013). Using principal-component analysis (PCA), we reported a low-dimensional, brain-wide activity cycle that dominates head ganglia. This included descending (and other) interneurons, which, in freely moving animals, were strictly active during forward or reverse locomotion (Kato et al., 2015), the uppermost level of our hierarchical model. These same neurons show coordinated dynamics during immobilization, with relationships to each other as expected from their behavior correlations (i.e., forward-active neurons were positively correlated with each other and negatively correlated with reverse-active neurons). Therefore, specific neuronal activity patterns in immobilized worms can be ascribed to forward or reverse motor command states (Kato et al., 2015). Here, we expanded this approach beyond head ganglia to the entire nervous system, including ventral nerve cord (VNC, containing body motor neurons) and tail ganglia (n = 5; Figures 2A–2D and S2A; Video S1). Using PCA, we found low-dimensional dynamics strikingly similar to those restricted to head ganglia (Figures 2C and S2B). Notably, interneuron and motor neuron activities were equally well represented in this lowdimensional PCA space (Figure 2E), and both neuron classes showed strong modulations by forward/reverse command state (Figure S2C). Network activity corresponding to motor commands therefore extends from head ganglia to the motor periphery (Figure 2D), consistent with previous work showing premotor interneuron control of VNC motor neurons (Kawano et al., 2011; Xu et al., 2018). The AVB (Xu et al., 2018) and AVA (Kawano et al., 2011) pre-motor interneurons have been shown to exert powerful control over VNC activity and are likely responsible for connecting interneuron and motor neuron population

dynamics into one coordinated signal. Accordingly, our results show that this signal permeates many VNC neurons even in completely immobilized animals (Figures 2E and S2C). In conclusion, a long-timescale, nervous-system-wide neuronal activity cycle underlies the uppermost hierarchical level. Identification of Candidate CPG Circuits for Lower Hierarchical Levels PCA is sensitive to global correlations in time series data but less so to local and transient neuronal activity fluctuations. Therefore, we used additional approaches to screen our datasets for shorter-timescale activities underlying lower hierarchical levels. Rhythmic behaviors such as head bending are typically driven by central pattern generators (CPGs), neurons or circuits that can generate motor-pattern-like activity without any external feedback (Kiehn, 2011; Marder and Bucher, 2001). As our immobilized worm recordings lack dynamic proprioceptive inputs, they are particularly well suited for identifying CPG candidates. Behavioral studies have implicated B-MNs, along with an unknown head neuron class, as potential CPGs for forward locomotion (Fouad et al., 2018; Xu et al., 2018). Eighteen B-MNs distributed along the worm’s anterior-posterior axis synapse locally onto either dorsal (for DB01-DB07 B-MNs) or ventral (for VB01-VB11 B-MNs) muscle and are crucial for forward locomotion (Chalfie et al., 1985) (Figure 2A). Based on anatomical features (STAR Methods), we were able to identify most individual B-MNs in our data. We indeed found shorter-timescale fluctuations: some neuron classes, including certain B-MNs, showed several Ca2+ peaks nested within single forward command states (Figure 3A). Most of these neurons rarely peaked during reverse command states (Figure S2D). We focused on rhythmically active neuron classes, which we define as those with non-random inter-peak intervals (Figure 3A; STAR Methods). Two of these were excitatory motor neuron classes targeting head and neck muscle, making them top CPG candidates: SMD neurons (dorsal-projecting SMDDL and SMDDR and ventral-projecting SMDVL and SMDVR) and B-MNs DB01 and DB02 (Figures 2D and 3B). We hereafter refer to these neuronal classes as ‘‘oscillators,’’ given their rhythmic activity (Figures 3A and S3E–S3H). To determine whether SMD and DB01/02 were part of larger oscillator circuits, we performed an appropriate variant of cross-correlation analysis: we calculated covariograms, which are shuffle-corrected, peri-event time histograms of one neuron’s Ca2+ peaks relative to another (Brody, 1999) (Figure 3C). This analysis delineated three small oscillator circuits (highlighted in different colors in Figure 3C): (1) SMDD and GABAergic ventral-projecting RMED head motor neurons oscillate in synchrony; (2) SMDV, dorsal-projecting RMEV, and the VB01 B-MN oscillate in synchrony and antagonistically with the SMDD oscillator (also see Hendricks et al., 2012; Shen et al., 2016); and (3) DB01 and DB02 oscillate in synchrony with weak correlations with the SMDV oscillator. CPGs typically show both rhythm-generating (regularly repeating) and pattern-generating (coordinated across neurons, e.g., those controlling antagonistic muscles) activity (discussed in Kiehn, 2011). SMDD/V oscillator antagonism is consistent with both rhythm and pattern generation for antagonistic

Neuron 105, 1–15, February 5, 2020 3

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

A

dorsal AVA SMDV anterior RIB VB01

DB motor neuron VB motor neuron

posterior ventral

SMDD DB02

VB08

DB01

Head ganglia

B

Command state:

DB07 VB11

DB05

Ventral nerve cord (VNC)

Forward

Tail ganglia

C

Reverse

F

Level I

PC1 31.4%

Forward

R

5 4 3

DB01

2

1 0 0

5

10 Time (minutes)

15

20

Command state: Forward

D RIB (forward-active) AVA (reverse-active) VB02 VA02

E

Interneurons Motor neurons Other neurons

Reverse 0.75 0.5 F / F0

DB01 SMDV SMDD

0.45

0.15 0

Reversal

Post-reversal turn

reconstruction quality (correlation)

SMDVL SMDDL SMDDR SMDVR

PC3 PC2 5.1% 24.5%

RIBL RIBR DB02

F / F0

Neurons

AVAL AVAR

5

10 Time (minutes)

15

20

1

1-2 1-3 1-4 PCs

1-5

Figure 2. A Nervous-System-wide Representation of the Uppermost Hierarchical Level (A) Worm schematic. Neurons investigated in subsequent panels are labeled. (B–D) Example whole-nervous-system GCaMP6f recording. (B) Upper: motor command states inferred from neuronal activity (STAR Methods). Lower: fluorescence time series of 129 neurons, sorted by correlation. (C) Low-dimensional representation of nervous-system-wide activity, from principal-component analysis (PCA). Color key indicates motor command state inferred from neuronal activity (STAR Methods; arrowheads indicate directional flow). Coordinates depict principal component (PC) axes orientations and % variance explained. (D) Activity traces of selected neurons. Scale bars on the right represent 0.5 DF/F0, colored according to corresponding trace. (E) Mean ± SEM correlation coefficient between neuronal activity traces and traces reconstructed using indicated top PCs. n = 5 datasets. See also Figure S2 and Video S1.

dorsal/ventral head bending. In contrast, DB01/02 oscillations showed positive correlations with VB01 activity (Figure 3C), despite targeting opposing muscles. Other B-MNs also ex-

4 Neuron 105, 1–15, February 5, 2020

hibited rhythmic activity (Figure 3A), but we found no significant coordination among them (Figure S2E). These data are consistent with previous studies implicating B-MNs as distributed

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

0.06 0.04 0.02

B motor neuron

0 AIBL AIBR AVER AVEL AVAR AVAL RIMR RIML OLQDR OLQVR OLQVL URYDR URYVL URYVR URYDL VA02 BAGL BAGR AVFL AVFR ALA CEPDR# CEPDL# SIBVL# RIVL RIVR RMDVR# VB04 RID Baseline AVBL VB02 SIBVR# DB05 DB04 VB03 DB03 AVBR VB01 VB09 VB08 RIBR RMER VD02 RMEL DB06 VB05 DB02 RMEV ASKR SMDVL SMDVR VB07 DB01 DVA VB06 VB10 RMED RIBL ASKL VB11p DB07a SMDDR SMDDL PDA

Frequency within forward command states (Hz)

A

B

SMDVL/R = SMD Ventral Left/Right dorsal anterior

posterior ventral

SMDDL/R = SMD Dorsal Left/Right DB01 / DB02 = Dorsal B Motor Neuron (B-MN)

C SMDDR

(-)

(-)

(-)

(-)

DB01

DB02

RMED

RMEV

VB01

SMDVL

SMDVR

(-)

(-)

(-)

(-)

(-)

(-)

DB02

0.8 0.4 0 -120 -60 0 60 120 Time (seconds)

Relative frequency (10-1 s)

DB01

SMDVR SMDVL SMDDR SMDDL

SMDDL

Reference Neuron

(-) = negative relationship

Target Neuron

Figure 3. Identification of Candidate CPG Circuits for Lower Hierarchical Levels (A) Activity peak frequencies within each forward command state for all identified neurons, pooled from n = 5 whole-nervous-system and n = 5 head ganglia recordings. Median, interquartile, and 5%–95% range shown. ‘‘Baseline’’ distribution for one peak per forward command state; red line indicates its median. Neurons above ‘‘baseline’’ peaked multiple times within forward command states. Red labels indicate significantly non-random inter-peak interval distributions (STAR Methods). See Table S2 for multiple-comparison corrected p values and n numbers (number of forward command states = number of data points). # ambiguous IDs, see STAR Methods for alternatives. (B) Worm head schematic illustrating positions and lateralized muscle innervations of CPG candidate motor neurons (not to scale). (legend continued on next page)

Neuron 105, 1–15, February 5, 2020 5

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

A

B

Figure 4. SMDs and VNC Neurons Are Required for Head-Casts and Propagated-Bends, Respectively (A) Frequencies as in Figure 3A for the indicated neurons in control, VNCACh-inhibited, and SMD-inhibited animals, pooled across paired neurons, and across n = 5 (control, SMD::HisCl) or 4 (VNCACh::HisCl) recordings. *p < 0.05, **p < 0.01, ****p < 0.0001, Mann-Whitney test. ns, not significant. Boxplots show median, interquartile, and range. (B) Effects of SMD (n = 9), VNCACh (n = 6), and SMD+VNCACh (n = 6) inhibition on propagated-bends (upper) and head-casts (lower), mean ± SD. Each data point is the mean of an experimental repeat with 20 animals each. **p < 0.01, ****p < 0.0001, Mann-Whitney test. ns, not significant. See also Figure S4.

rhythm generators (Fouad et al., 2018), and they further suggest that proprioceptive feedback (described for B-MNs in Wen et al., 2012; Xu et al., 2018) is required for B-MN pattern generation. SMDs were also reported to be proprioceptive (Yeon et al., 2018), presumably in addition to the activity we report in immobilized animals. We suggest that proprioception is required for both SMD and B-MN frequency entrainment, as we observed a 10-fold reduction of frequency upon immobilization (compare Figure 3A with head-bend frequencies in moving animals, shown in 1D); such a reduction is consistent with CPG studies in other species (Fox et al., 2006; Goulding, 2009). For the SMDs, we confirmed that our measured activity frequencies were not limited by our acquisition rate, using a separate set of singleplane 50-Hz recordings (Figure S3). For other neurons, we cannot exclude the possibility of faster dynamics not captured by our 1–3 Hz volumetric recordings. In summary, in addition to slow global dynamics, immobilized animal recordings also revealed faster local dynamics, with the head motor neurons SMD and DB01/02 exhibiting largely independent rhythmic activity. SMDs and VNC Neurons Are Required for Head-Casts and Propagated-Bends, Respectively To interrogate SMD and DB function, we transiently inhibited each using the histamine-gated chloride channel hisCl (Pokala et al., 2014). We first sought to confirm the oscillators’ independence in immobilized worms. Whole-brain recordings revealed DB01/02 oscillations in the absence of SMD activity (albeit with reduced DB01 frequency; Figure 4A). To examine SMD activity in DB01/02-inhibited animals, we generated VNCACh::hisCl animals, in which all B-MNs, including DB01/02, are inhibited, among other cholinergic VNC neurons (no specific DB01/02 genetic driver is available). Whole-brain imaging in VNCACh::hisCl

animals showed increased SMDD and decreased SMDV oscillation frequencies (Figure 4A). This differential effect could be explained by inhibition of VB01, which is the only B-MN showing activity tightly coupled to SMD activity (positively with SMDV and negatively with SMDD; Figure 3C) and the only B-MN synaptically connected to the SMDs (a gap junction to SMDVR). Regardless of the SMDD/V balance, these data show that SMD and DB01/02 can operate as independent oscillators. We next examined how oscillator inhibition affects locomotion. SMD::hisCl animals exhibited normal propagated-bend frequency but largely reduced head-cast frequency (Figures 4B, S4A, and S4B). VNCACh::hisCl animals exhibited reduced propagated-bend frequency and increased head-cast frequency (Figures 4B, S4A, and S4B). Combining VNCACh::hisCl and SMD::hisCl rendered animals almost completely immobile, with abnormally non-rhythmic head-cast-like bends (Figures 4B and S4A–S4E). In these animals, 11 head motor neuron classes were not targeted via hisCl but could not compensate for SMD and VNCACh inhibition, suggesting an especially prominent role for SMDs and VNCACh neurons. Altogether, these data suggest that the SMD and B-MNs are independently required for head-casts and propagated-bends, respectively. These behavioral experiments also provided support for two predictions of our hierarchy model. First, reduced head-cast frequency in SMD::hisCl animals did not result in shorter propagated-bend cycle periods (Figures S4C and S4D), suggesting that head-cast occurrence does not stall or lengthen the propagated-bend cycle. Second, VNCACh::hisCl showed a reciprocal effect on propagated-bends and head-casts (Figure 4B), consistent with longer propagated-bend cycles (Figure S4D) permitting wider windows of opportunity for head-casts. By contrast,

(C) Covariograms of SMD and DB with all coordinated neurons. All identified neurons were tested, but only those with significant correlation with at least one reference neuron are shown. Plots show relative frequencies of Ca2+ peaks of neurons in columns triggered to those in rows. Positive/negative values show higher/lower correlation than estimated by chance. Opaque plots differ significantly from random surrogate distributions (p values in Table S3). Colored borders denote significant positive relationships consistent within neuron classes. ‘‘(–)’’ denotes negative relationships. See also Figures S2 and S3.

6 Neuron 105, 1–15, February 5, 2020

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

A

B

C

D

E

H

I

F

G

J

K

Figure 5. Hierarchy Level I and II Interaction: SMD Neurons Are Multi-functional (A) Hierarchy levels investigated. (B and C) Example DB02 (B) and SMD (C) Ca2+-imaging in moving animals. DR/R0 = normalized GCaMP/mCherry ratio. Lower: posture kymograms, black indicates missing data. Dotted vertical lines: unilateral SMDD- or SMDV-only oscillations. (D–G) Fractional distributions of DB02 (D and E) or SMD (F and G) Ca2+ peaks binned by head-bend phase during forward (D and F) or reverse (E and G) locomotion. n = 746 (D), 35 (E), 478 (F, SMDD), 389 (F, SMDV), 150 (G, SMDD), and 158 (G, SMDV) peaks pooled across 11 (SMD) and 10 (DB02) animals. p < 106 for all distributions except SMDV (p = 3 3 106) and DB02 (ns, p = 0.26) during reverse locomotion, indicating the probability that distributions are drawn randomly. Probability that each neuron’s reversal distribution was drawn from its respective forward distributions: p < 106 (SMDD and SMDV) and 0.0014 (DB02). (H) Frequency (upper) and average amplitude (lower) of detected activity peaks. **p < 0.01, ***p % 0.001, Wilcoxon matched-pairs signed rank test. n = 11 (SMD) and n = 10 (DB02) animals. (I) Peak head-bend amplitudes in SMD::hisCl, mean ± SD. ****p < 0.0001, Mann-Whitney test; ns, not significant. (J) Reversal duration in SMD::hisCl, mean ± SD. ****p < 0.0001, Mann-Whitney test. Each data point in (I) and (J) is the mean of an experimental repeat (n = 9) with 20 animals each. (K) Reversal command duration from immobilized head ganglia imaging, mean ± SD. Each data point is the mean from one animal, n = 5 each condition. **p < 0.01, Mann-Whitney test. See also Figure S5 and Video S2.

reduced head casting in SMD::hisCl animals did not affect propagated-bend frequency (Figure 4B), consistent with a top-down effect of the longer-timescale behavior on the shorter-timescale one but not vice versa. Hierarchy Level I and II Interaction: SMD Neurons Are Multi-functional To determine how these circuits drive hierarchical behaviors, we performed Ca2+ imaging of SMDs and DB02 in freely moving an-

imals (Figures 5B and 5C; Video S2). Fourier analysis revealed peaks in neuronal activity power spectra overlapping with peaks in head-bend angle power spectra, as expected for motor neurons targeting head muscle (Figures S5A–S5C). These data also confirmed that SMD neurons’ activities fluctuated about an order of magnitude faster in moving versus immobilized animals (compare Figures S5A and S5B to S3E–S3H). We next asked how the uppermost hierarchical level impacts fastertimescale activities (Figure 5A). As both SMDs and DB02 target

Neuron 105, 1–15, February 5, 2020 7

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

A

B

C

Figure 6. AIB Interneurons Orchestrate Upper-Level SMD Switch (A) Experiment design and hypothesis. (B) Frequency (upper) and average amplitude (lower; DR/R0 = normalized GCaMP/mCherry ratio) of SMD activity peaks in AIB::hisCl freely moving animals, ± histamine. ns, not significant; *p < 0.05, **p < 0.01, ***p % 0.001, Wilcoxon matched-pairs signed rank test. n = 14 (histamine) and n = 15 (+histamine) animals. (C) Summary of investigated neuronal relationships. See also Figure S6 and Video S2.

head muscle, we examined neuronal activity relative to the headbend oscillation (corresponding to hierarchy level II). During forward locomotion, SMDD and DB02 peaked during dorsal bends, SMDV peaked during ventral bends, and each neuron peaked during nearly every head-bend cycle (Figures 5D, 5F, and S5D). During reverse locomotion, DB02 and SMD activities were altered in different ways. DB02 activity was largely reduced, showing small peaks with no correlation to head bending (Figures 5B, 5E, 5H, and S5D). SMDs peaked at altered head-bend phases (Figure 5G) with less reliability (Figure S5D) and with lower frequency and amplitude (Figure 5H) compared to forward states. These altered SMD activity patterns suggest altered SMD function during reversals. Consistent with this idea, SMD inhibition caused reduced head-bend amplitude only during forward locomotion (Figure 5I). If SMD activity during reversals does not promote head bending, what function does it serve? We reliably observed SMD Ca2+ peaks at reverse-to-forward transitions (Figure S5E). These transitions are typically accompanied by reorientation turns (Donnelly et al., 2013; Gray et al., 2005); the amplitude of these post-reversal turns correlated with SMD Ca2+-peak amplitude (Figure S5F), with mutually exclusive SMDV activity during ventral turns and SMDD activity during dorsal turns (Figure S5E). We therefore hypothesized that SMD reversal activity increases reverse-to-forward transition probability and promotes post-reversal turn amplitude. Indeed, SMD::hisCl animals showed increased reversal duration (Figures 5J and S5G) and lacked large-amplitude post-reversal turns (Figures S5H–S5J). SMDs therefore switch function depending on the long-timescale forward/reverse switch: during forward locomotion, they act as motor neurons, increasing head-bend amplitude and post-reversal turn amplitude, and driving headcasts; during reverse locomotion, in contrast, they do not affect head bending but rather promote state termination (Figure 5J). The latter suggests an interneuron-like role, consistent with SMDs synapsing onto interneurons in addition to their neuromuscular synapses (White et al., 1986). We next asked whether these hierarchical relationships arise from intrinsic circuit properties or from proprioceptive feedback. To distinguish these possibilities, we examined SMD and DB

8 Neuron 105, 1–15, February 5, 2020

activity during forward versus reverse command state in immobilized animals. As in behaving animals, mutually exclusive SMDD/V peaks were coincident with reversal command state termination (Figure S5K). Indeed, SMD::hisCl animals showed increased reverse command state durations (Figure 5K), confirming that this SMD function persists in the absence of behavior. Further, DB02 frequency and peak amplitude, SMDD peak amplitude (Figure S5L), and DB02 and SMD mean activity levels (Figure S2C) were reduced during reverse command states (Figure S5L), as in moving animals (Figure 5H). In conclusion, SMD and DB oscillations are hierarchically nested within the slower forward/reverse command cycle via circuit interactions. We next sought to determine which neurons trigger the switch in SMD activity pattern. Among SMD’s pre-synaptic partners, AIB and RIM stood out as candidates, as both neurons are more active during reverse compared to forward locomotion (Gordus et al., 2015; Kato et al., 2015; Laurent et al., 2015; Luo et al., 2014; Piggott et al., 2011). We therefore hypothesized that AIB and/or RIM inhibit SMD activity during reversals (Figure 6A). We found that AIB inhibition abolished the forward/reverse locomotion modulation of SMDD frequency, SMDV frequency, and SMDD amplitude (Figure 6B). These results suggest that AIB is crucial for switching SMD neurons between high-activity and low-activity states (Figure 6C). Because RIM::hisCl animals lacked reversals, we took a genetic approach to RIM manipulation. Several studies have shown that RIM signals via tyramine to affect head oscillations and reversal behavior (Alkema et al., 2005; Donnelly et al., 2013; Pirri et al., 2009). We found a specific role for tyramine in SMDD frequency only (Figure S6). In summary, we found a major (AIB) and minor (tyramine, likely from RIM) role for two SMD inputs in switching SMD activity states at the uppermost hierarchy level. These findings are consistent with the hierarchy’s implementation via circuit interactions. Hierarchy Level II and III Interaction: Neuronal Phase Nesting We next examined neuronal activity during the different headbend types (Figure 7A). All three neurons showed oscillations synchronized with propagated-bends: DB02 and SMDD were

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

B

D

A

I

C

F

E

G

H

Figure 7. Hierarchy Level II and III Interaction: Phase Nesting of SMD Activity (A) Hierarchy levels investigated. (B–E) Trigger-averaged kymograms (lower) and neuronal activity traces (upper; DR/R0 = normalized GCaMP/mCherry ratio) from DB02 (B and D) and SMD (C and E) imaging, aligned to either propagated-bends without subsequent head-casts (B and C) or initial head-casts (D and E). Left to right, n = 669, 680, 303, and 101 (B and D) and n = 377, 360, 178, and 119 (C and E). In (E), activity peaks during propagated-bends (filled arrowheads) and head-casts (open arrowheads) denoted. (F) Example SMD activity time series illustrating SMD alternation phase measurement. Red and blue dashed lines indicate unilateral SMDD-only or SMDV-only oscillations, quantified in (G). (G and H) Fractional distributions of unilateral SMDD-only or SMDV-only oscillations binned according to SMD alternation cycle phase, in freely moving (G) or immobilized (H) animals. n = 196 (G, SMDD), 147 (G, SMDV), 57 (H, SMDD), and 23 (H, SMDV). p % 106 for each SMD distribution in (G) and (H) indicates the probability that distributions are drawn randomly from the full data distribution shown in gray. Data in (B)–(E) and (G) pooled across 11 (SMD) and 10 (DB02) animals. Data in (H) pooled from 13 animals. (I) Summary of investigated neuronal relationships. See also Figure S7.

active during dorsal propagated-bends, and SMDV was active during ventral propagated-bends (Figures 7B and 7C). SMDD and SMDV therefore showed alternating activity peaks with alternating dorsal/ventral propagated-bends (Figure 7C). During head-casts, DB02 did not show activity fluctuations beyond those during propagated-bends (Figures 7B and 7D; excepting a minority of especially posterior propagating head-casts, Figure S7A). In contrast, SMDs consistently showed oscillations during head-casts superimposed onto their propagated-bend

activity (Figure 7E). In contrast to SMD’s alternating activities during propagated-bends, SMD head-cast oscillations were strictly unilateral: SMDD oscillated during dorsal head-casts while SMDV remained inactive, and vice versa during ventral head-casts (Figures 7E and S7B–S7D; dotted lines in Figure 5C). SMDs therefore exhibited distinct activity signatures for different behaviors: SMDD/SMDV alternations during propagated-bends and unilateral SMDD-only or SMDV-only oscillations during head-casts.

Neuron 105, 1–15, February 5, 2020 9

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

A

B

Forward/Reverse cycle

F

R

~ 0.05 Hz

F neurons R neurons VB DB SMDV SMDD

Head-casts

SMDD

~1 Hz

RIB::HisCl

Prop-bend cycle period (seconds)

RIB

E

Forward Ventral head-casts

F

+ATR +591nm

SMDV

RIB::Chrimson

Forward Dorsal head-casts

RIB 4

2 DB

***

VB

H

10 5

SMDD D

SMDV

0

Head-cast pair

0

15 20

***

K Head-casts / minute

Prop-bend cycle period (seconds)

J 4

2 21% O2

4% O2

40

D

-0.4

**** 8 4 0

21% O2

***

8 6 4

-ATR +ATR +591nm light

Roaming V

4% O2

0.4

5 10 0

15 20 0

20

M

40 60 Time (seconds)

**** 15 10 5 0

Dwell

Roam

D

80

N

Angle (rad)

10

20 30 Time (seconds)

4

0.4

5

10

6

Dwelling

L Angle (rad)

Segment #

V

0

8

-0.4

****

10 Head-casts / minute

21% O2 4% O2

Segment #

I

** 10

2

+His

Prop-bend cycle period (seconds)

-His

Reverse Post-reversal turn

G

RIB

***

6

15 Head-casts / minute

VB

SMDD

Forward Propagated-bends

D

RIB

DB

SMDV

SMDV

+His

C

SMDD

~ 0.5 Hz VB

Prop-bend cycle period (seconds)

DB

Head-casts / minute

Propagatedbends

5

0

Dwell

Roam

Figure 8. A Hierarchical Control Mechanism for Behavioral Flexibility (A) Neuron classes (F, forward-active; R, reverse-active) underlying each behavior. (B) Model traces (upper) and corresponding behavioral and neuronal hierarchical states (lower). (C) RIB inhibition model: longer propagated-bend cycle period results in increased head-cast frequency. (D and E) Propagated-bend cycle period (D) and head-cast frequency (E) in RIB::hisCl animals, mean ± SD n = 8 assays each. ***p < 0.001, Mann-Whitney test. (F) RIB activation model: shorter propagated-bend cycle period results in decreased head-cast frequency. (G and H) Propagated-bend cycle period (G) and head-cast frequency (H) in RIB::Chrimson animals during yellow light exposure. n = 8 assays each. **p < 0.01, ***p < 0.001, Mann-Whitney test. (I) Representative O2 downshift kymogram.

(legend continued on next page)

10 Neuron 105, 1–15, February 5, 2020

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

We next asked whether these SMD activity signatures were phase-nested like their co-occurring behaviors. We quantified the phase of the SMDD/SMDV alternation cycle with SMDD peak – SMDV peak – SMDD peak corresponding to 0 – 1 – 2p rad (Figure 7F). This revealed that unilateral SMD oscillations were initiated at restricted phases (Figure 7G, compare with Figure 1F). This suggests that phase-nested SMD activity may be causal for phase-nested behavior; if so, phase-nested SMD activity should persist in the absence of behavior. Indeed, in immobilized animal recordings, SMD activity showed the same phase-nested relationship (Figure 7H). Further, these recordings revealed SMD activity relationships that likely underlie the proposed window of opportunity (Figures S7E and S7F, compare with S1H). The preservation of these dynamical relationships in immobilized animals is especially striking given that SMD activities fluctuate about one order of magnitude slower in immobilized versus moving animals (compare Figures S3E–S3H with S5A and S5B). Taken together, our data indicate that phasenested neuronal dynamics are the cause, rather than consequence, of phase-nested behaviors (Figure 7I). Nested neuronal activity patterns are therefore a repeated dynamical motif of the C. elegans nervous system, which together constitute a hierarchical organization of neuronal activity and behavior across three timescales (Figures 8A and 8B). SMD-Head-Bend Synchrony Is Independent of RIA and GABA SMD activity and head bending are strongly synchronized during propagated-bends in freely moving animals (Figures 5F and 7C), yet propagated-bends are largely unaffected by SMD inhibition (Figures 4B and S4A–S4D). The SMDs therefore likely act as followers during this behavior (Figure 7I), which our data suggest is driven by B-MNs (Figures 4B and S4A–S4D). In immobilized animals, however, DB01/02 showed no correlation with SMDD, indicating that other neuronal inputs, or proprioception, might entrain SMD oscillations with both B-MNs and propagated-bends. We therefore examined two of SMD’s major inputs, RIA and RME. RIA is SMD’s most prominent presynaptic partner, and previous studies have shown a potent effect of RIA on SMD activity (Hendricks et al., 2012; Liu et al., 2018). We tested animals expressing tetanus toxin in RIA (Hendricks et al., 2012; Liu et al., 2018), thus blocking synaptic release, as well as RIA::hisCl animals (validated via imaging experiments, data not shown), and found no effect on the relationship between SMD activity and head bending (Figures S7G and S7H). RME activity showed strong, lateralized correlations with SMD activity in immobilized animals (Figure 3C) and has also been shown to functionally impact SMD activity via GABA signaling (Shen et al., 2016). unc-25 mutants lacking GABA synthesis showed no defect in the relationship between SMD activity and head bending (Figure S7I). We therefore suggest that proprioception plays a prom-

inent role in synchronizing SMD activity with propagated bends. Indeed, proprioception has been shown to modulate SMD activity (Yeon et al., 2018). Another possibility is that the B-MNs directly drive lateralized SMD activity in moving animals: B-MNs have also been shown to be proprioceptive (Wen et al., 2012) and are synaptically coupled to the SMDs via VB01. A Hierarchical Control Mechanism for Behavioral Flexibility Phase nesting implies a mechanism for behavioral regulation: head-cast occurrence may be controlled by manipulating the propagated-bend oscillation speed, thereby widening or narrowing the head-cast window of opportunity. Propagatedbend oscillation speed correlated strongly with locomotion speed (Figure S8A); we therefore manipulated the RIB interneuron, a forward-active neuron previously implicated in locomotion speed control (Kato et al., 2015; Li et al., 2014). Indeed, RIB inhibition slowed the propagated-bend cycle and, consistent with our model, increased head casting (Figures 8C–8E). Conversely, optogenetic RIB activation accelerated the propagated-bend cycle and decreased head casting (Figures 8F– 8H). To determine whether this antagonistic regulation occurs in more naturalistic conditions, we examined behaviors involving locomotion speed regulation. Off food, animals exposed to ambient O2 downshifts slow their locomotion (Zimmer et al., 2009), presumably to explore locally (Hums et al., 2016). Upon O2 downshift, slowed propagated-bend cycles were coupled with increased head casting (Figures 8I–8K and S8B; Video S3). On food, animals switch spontaneously between low-speed exploitative dwelling and high-speed explorative roaming states (Fujiwara et al., 2002). We found that roaming animals exhibited faster propagated-bend cycles and rarely head-casted compared to dwelling animals (Figures 8L–N, S8C, and S8D; Video S4). These results suggest context-dependent functions for head-casts, serving either exploration (off food) or exploitation (on food). They further implicate phase nesting as a mechanism for controlling behavioral output downstream of both sensory neurons and internal state regulators. DISCUSSION Here, we showed that nested neuronal dynamics coordinate different timescale behaviors into a behavioral hierarchy in C. elegans. Our results conceptually reveal an organizational principle in which upper-level behavioral programs are represented by slow global dynamics spread across many neurons, while lower-level behaviors are represented by fast local dynamics in a few multi-functional neurons. Persistent phases of neuronal activity driving higher-level behaviors gate the occurrence of faster neuronal activity fluctuations driving lower-level behaviors. As a consequence, at lower hierarchy levels, neurons

(J and K) Propagated-bend cycle period (J) and head-cast frequency (K) 30 s pre- and post-O2 downshift. n = 14 assays. ***p < 0.001, ****p % 0.0001, Wilcoxon matched-pairs signed rank test. (L) Example kymogram during dwelling to roaming switch. (M and N) Propagated-bend cycle period (M) and head-cast frequency (N) in dwelling or roaming animals. n = 19 assays. ****p < 0.0001, Wilcoxon matched-pairs signed rank test. All data points show the mean of an experiment repeat with 20 animals each. See also Figure S8 and Videos S3 and S4.

Neuron 105, 1–15, February 5, 2020 11

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

show dynamics that span multiple timescales incorporating those at the respective upper levels. Further, faster lower-level signals were exclusive to peripheral (i.e., motor) neurons, while slower upper-level signals permeated both central and peripheral neurons. SMD activity changes span all three timescales. They show fast head-cast-driving oscillations (level III) superimposed onto a slower propagated-bend-correlated activity oscillation shared with the B-MN population (level II), which enables phase-nested behaviors (Figure 7). Upon switching to reverse locomotion at the interneuron level (level I), B-MNs become inactive, while SMDs change their activity patterns and execute completely different functions. SMDs are therefore highly multi-functional, executing both motor- and interneuron-like functions, in a manner strictly controlled by the hierarchical organization. Because neurons like the SMDs play roles at multiple hierarchical levels, our findings are best described as a hierarchy of neuronal dynamical states (Figure 8B), with each state consisting of particular activity patterns across many neurons, as opposed to a hierarchy in which individual neurons occupy distinct states and levels. Some of the hierarchical relationships we describe can be straightforwardly linked to the worm’s known synaptic connectivity, such as descending interneuron control of motor neuron networks (Kawano et al., 2011; Xu et al., 2018). Other relationships, however, can be only partially explained by connectivity: while mutual inhibition between SMDD and SMDV could result from direct synapses between the two, phase nesting is a dynamical relationship that could be independent of connectivity. We nevertheless found that hierarchical nesting is a property of circuit interactions rather than feedback from proprioception or behavioral execution, as we could recapitulate nearly all of the nested relationships in paralyzed worms. Crucially, this indicates that the nervous system organizes its activities hierarchically, independent of behavior, and hierarchical behavior is inherited from this organization. The hierarchy we describe (Figure 8A) is a rigid framework in which specific lower-level behaviors may only be accessed via switches at upper levels. For example, SMDV never exhibited head-cast activity during dorsal propagated-bends (when DB02 and SMDD were active); during this state, low-level ventral head-casts may only be executed by first switching the mid-level phase to ventral. This feature is specific to non-overlapping hierarchies, in which no lower-level state is connected to multiple upper-level states (Figure S8E) (Dawkins, 1976). This rigid framework is, however, accessible to additional neuronal control, via either sensory input or behavioral state (Figures 8I–8N); both of these can modulate the crawling-phase velocity of the animal and therefore the window of opportunity for head casting. Given the ubiquity of neuronal activity oscillations as well as hierarchically organized behavior, the circuit interactions and control principles we describe may be relevant for other species. We also examined an even longer timescale of behavior above the forward-reverse switch: roaming and dwelling behavioral states. In contrast to the strict, all-or-none relationships of the motor hierarchy, actions within roaming and dwelling are not exclusive to those states but rather show differences in frequency: dwelling exhibits high frequencies of forward-reverse transitions and head-casts, while roaming consists of long

12 Neuron 105, 1–15, February 5, 2020

stretches of propagated-bend forward movement with low head-cast and reversal frequencies (Figures 8I–8N; Gallagher et al., 2013). We therefore suggest that such longer-timescale behavioral states, which rely on neuromodulation (Ben Arous et al., 2009; Flavell et al., 2013), are best described by a less restrictive overlapping hierarchical model, in which lower-level states may be shared by different upper-level states (Figure S8E; Dawkins, 1976). Tinbergen’s non-overlapping hierarchical model for stickleback behavior included longer-lasting states typically controlled by neuromodulators, such as a reproductive instinct (Tinbergen, 1951). The non-overlapping hierarchy we describe (Figure 8A) is more in line with recent studies describing hierarchies at the level of motor actions (Berman et al., 2016; Duistermars et al., 2018; Glaze and Troyer, 2006; Gomez-Marin et al., 2016; Marques et al., 2018; Wiltschko et al., 2015). A primary benefit of hierarchical behavior may be to coordinate the activities of motor neurons that target overlapping body parts, in order to prevent interfering actions. In contrast to the rigid framework studied here, longer-lasting behavioral states could gain flexibility by re-utilizing a combinatorial set of actions. The strict, nested relationships we uncovered bear striking resemblance to neuronal dynamics underlying multi-timescale rodent behaviors. For example, CPGs driving whisking and breathing appear to interact in a hierarchical manner: breathing resets the whisking phase, but not vice versa, and a unidirectional anatomical pathway from the breathing CPG to the whisking CPG has been described (Moore et al., 2013). Such a phaseresetting mechanism may also explain the impact of B-MNs on SMD activity, whereby B-MN oscillations may drive the SMDs into particular phases that restrict their unilateral oscillation and therefore head-casts. Further, basal ganglia circuits in mice show independent coding of different timescales during learned action sequences (Jin et al., 2014), suggesting a hierarchical ‘‘chunking’’ with theoretical advantages compared to serial sequencing (Jin and Costa, 2015). Our study demonstrates how circuits acting on different timescales can interact to implement hierarchical behavior and could therefore provide a starting point to search for similar circuit interactions in other organisms. The motor neuron dynamics showed a strong dependence on oscillation phase (Figures 7G and 7H). Oscillation phase is crucially important for the effect of motor neurons during insect locomotion (Fayyazuddin and Dickinson, 1999; Sponberg and Daniel, 2012) and has been proposed to act as a window for integrating inputs in flies (Gupta et al., 2016) and mammals (Buzsa´ki and Draguhn, 2004; Yuste et al., 2005). While forward- and reverse-state switches in C. elegans appear to be stochastic rather than oscillatory (Roberts et al., 2016), non-oscillatory phase coding has been demonstrated in the bat (Eliav et al., 2018). It has also been suggested that CPG circuits may foretell principles of cortical circuits (Yuste et al., 2005). Throughout the mammalian brain, longer-timescale oscillations spread across larger neuronal populations influence more local, shorter-timescale oscillations in a hierarchical manner (Buzsa´ki et al., 2013). Coupling between these nested oscillations could serve myriad functions (Hyafil et al., 2015); for example, the widening and narrowing of an alpha-oscillation window of opportunity has been proposed to enable gamma-oscillatory communication between neuronal populations (Hahn et al., 2019). Further, comprehension of

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

speech, a naturally hierarchical stimulus, involves the emergence of neuronal dynamics across timescales, with spatially dissociable representations for distinct frequencies (Ding et al., 2016). Our work demonstrates that such hierarchically nested dynamics can indeed organize neuronal activity patterns, and, consequently, animal behavior, across timescales. In conclusion, nested neuronal activity patterns implement a three-level hierarchy of behavior across timescales in C. elegans. Neuronal activity dynamics on different timescales are ubiquitous in neuroscience; we therefore speculate that such hierarchically nested activity patterns may be a common mechanism for organizing and regulating neuronal dynamics across timescales.

DECLARATION OF INTERESTS The authors declare no competing interests. Received: February 5, 2019 Revised: September 19, 2019 Accepted: October 28, 2019 Published: November 27, 2019 SUPPORTING CITATIONS The following references appear in the Supplemental Information: Bhatla and Horvitz (2015); Ringstad et al. (2009); Ruijtenberg and van den Heuvel (2015); Sohal et al. (2009). REFERENCES

STAR+METHODS Detailed methods are provided in the online version of this paper and include the following: d d d d

d

d

KEY RESOURCES TABLE LEAD CONTACT AND MATERIALS AVAILABILITY EXPERIMENTAL MODEL AND SUBJECT DETAILS METHOD DETAILS B Population behavior assays 2+ B Ca imaging in immobilized animals B Simultaneous imaging of neuronal activity and behavior B Data Analysis QUANTIFICATION AND STATISTICAL ANALYSIS B Reconstruction quality for neuronal subsets (panneuronal imaging) B Peak frequency quantification (pan-neuronal imaging) B Cross-correlation analysis (pan-neuronal imaging) B Polar histogram statistics DATA AND CODE AVAILABILITY

SUPPLEMENTAL INFORMATION Supplemental Information can be found online at https://doi.org/10.1016/j. neuron.2019.10.037. ACKNOWLEDGMENTS We thank Marie Gendrel, Oliver Hobert, Kyuhyung Kim, and Ken Miller for plasmids; Yun Zhang for strains; Shawn Lockery, Max Jo¨sch, Andrew Straw, Mara Andrione, Ulises Rey, and Charlie Fieseler for critically reading the manuscript and the Zimmer lab for critical feedback; and Annika Nichols for technical support. The research leading to these results has received funding from the European Community’s Seventh Framework Programme (FP7/ 2007-2013)/ERC grant agreement 281869, the Vienna Science and Technology Fund (#LS14-084), the University of Vienna, and the Research Institute of Molecular Pathology (IMP). M.Z. is supported by the Simons Foundation (#543069) and the International Research Scholar Program by the Wellcome Trust and Howard Hughes Medical Institute (#208565/A/17/Z). The IMP is funded by Boehringer Ingelheim. AUTHOR CONTRIBUTIONS H.S.K. and O.S.T. performed experiments, developed analytical methods, analyzed data, and wrote the manuscript. N.K. performed experiments. M.Z. led the project, developed analytical methods, and wrote the manuscript.

Alkema, M.J., Hunter-Ensor, M., Ringstad, N., and Horvitz, H.R. (2005). Tyramine Functions independently of octopamine in the Caenorhabditis elegans nervous system. Neuron 46, 247–260, https://doi.org/10.1016/j.neuron. 2005.02.024. Ben Arous, J., Laffont, S., and Chatenay, D. (2009). Molecular and sensory basis of a food related two-state behavior in C. elegans. PLoS ONE 4, e7584, https://doi.org/10.1371/journal.pone.0007584. Benjamini, Y., and Yekutieli, D. (2001). The control of the false discovery rate in multiple testing under dependency. Ann. Stat. 29, 1165–1188, https://doi.org/ 10.1214/aos/1013699998. Berman, G.J., Bialek, W., and Shaevitz, J.W. (2016). Predictability and hierarchy in Drosophila behavior. Proc. Natl. Acad. Sci. USA 113, 11943–11948, https://doi.org/10.1073/pnas.1607601113. Bhatla, N., and Horvitz, H.R. (2015). Light and hydrogen peroxide inhibit C. elegans Feeding through gustatory receptor orthologs and pharyngeal neurons. Neuron 85, 804–818, https://doi.org/10.1016/j.neuron.2014.12.061. Brenner, S. (1974). The genetics of Caenorhabditis elegans. Genetics 77, 71–94. Brody, C.D. (1999). Correlations without synchrony. Neural Comput. 11, 1537– 1551, https://doi.org/10.1162/089976699300016133. Buzsa´ki, G., and Draguhn, A. (2004). Neuronal oscillations in cortical networks. Science 304, 1926–1929, https://doi.org/10.1126/science.1099745. Buzsa´ki, G., Logothetis, N., and Singer, W. (2013). Scaling brain size, keeping timing: evolutionary preservation of brain rhythms. Neuron 80, 751–764, https://doi.org/10.1016/j.neuron.2013.10.002. Ca´ceres, Ide.C., Valmas, N., Hilliard, M.A., and Lu, H. (2012). Laterally orienting C. elegans using geometry at microscale for high-throughput visual screens in neurodegeneration and neuronal development studies. PLoS ONE 7, e35037, https://doi.org/10.1371/journal.pone.0035037. Chalfie, M., Sulston, J.E., White, J.G., Southgate, E., Thomson, J.N., and Brenner, S. (1985). The neural circuit for touch sensitivity in Caenorhabditis elegans. J. Neurosci. 5, 956–964, https://doi.org/10.1523/JNEUROSCI.0504-00956.1985. Charlie, N.K., Schade, M.A., Thomure, A.M., and Miller, K.G. (2006). Presynaptic UNC-31 (CAPS) is required to activate the G a(s) pathway of the Caenorhabditis elegans synaptic signaling network. Genetics 172, 943–961, https://doi.org/10.1534/genetics.105.049577. Chartrand, R. (2011). Numerical differentiation of noisy, nonsmooth data. ISRN Appl. Math. 2011, 1–11, https://doi.org/10.5402/2011/164564. Chen, T.-W., Wardill, T.J., Sun, Y., Pulver, S.R., Renninger, S.L., Baohan, A., Schreiter, E.R., Kerr, R.A., Orger, M.B., Jayaraman, V., et al. (2013). Ultrasensitive fluorescent proteins for imaging neuronal activity. Nature 499, 295–300, https://doi.org/10.1038/nature12354. Collins, K.M., and Koelle, M.R. (2013). Postsynaptic ERG potassium channels limit muscle excitability to allow distinct egg-laying behavior states in Caenorhabditis elegans. J. Neurosci. 33, 761–775, https://doi.org/10.1523/ JNEUROSCI.3896-12.2013.

Neuron 105, 1–15, February 5, 2020 13

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Dawkins, R. (1976). Hierarchical organisation: A candidate principle for ethology. In Growing points in ethology, P.P.G. Bateson and R.A. Hinde, eds. (Oxford, England: Cambridge U Press), pp. 7–45.

Goulding, M. (2009). Circuits controlling vertebrate locomotion: moving in a new direction. Nat. Rev. Neurosci. 10, 507–518, https://doi.org/10.1038/ nrn2608.

Ding, N., Melloni, L., Zhang, H., Tian, X., and Poeppel, D. (2016). Cortical tracking of hierarchical linguistic structures in connected speech. Nat. Neurosci. 19, 158–164, https://doi.org/10.1038/nn.4186.

Gray, J.M., Hill, J.J., and Bargmann, C.I. (2005). A circuit for navigation in Caenorhabditis elegans. Proc. Natl. Acad. Sci. USA 102, 3184–3191, https:// doi.org/10.1073/pnas.0409009101.

Donnelly, J.L., Clark, C.M., Leifer, A.M., Pirri, J.K., Haburcak, M., Francis, M.M., Samuel, A.D.T., and Alkema, M.J. (2013). Monoaminergic orchestration of motor programs in a complex C. elegans behavior. PLoS Biol. 11, e1001529, https://doi.org/10.1371/journal.pbio.1001529.

Gupta, N., Singh, S.S., and Stopfer, M. (2016). Oscillatory integration windows in neurons. Nat. Commun. 7, 13808, https://doi.org/10.1038/ncomms13808.

Duistermars, B.J., Pfeiffer, B.D., Hoopfer, E.D., and Anderson, D.J. (2018). A brain module for scalable control of complex, multi-motor threat displays. Neuron 100, 1474–1490.e4, https://doi.org/10.1016/j.neuron.2018.10.027. Eliav, T., Geva-Sagiv, M., Yartsev, M.M., Finkelstein, A., Rubin, A., Las, L., and Ulanovsky, N. (2018). Nonoscillatory phase coding and synchronization in the bat hippocampal formation. Cell 175, 1119–1130.e15, https://doi.org/10. 1016/j.cell.2018.09.017. Faumont, S., Rondeau, G., Thiele, T.R., Lawton, K.J., McCormick, K.E., Sottile, M., Griesbeck, O., Heckscher, E.S., Roberts, W.M., Doe, C.Q., and Lockery, S.R. (2011). An image-free opto-mechanical system for creating virtual environments and imaging neuronal activity in freely moving Caenorhabditis elegans. PLoS ONE 6, e24666, https://doi.org/10.1371/journal.pone.0024666. Fayyazuddin, A., and Dickinson, M.H. (1999). Convergent mechanosensory input structures the firing phase of a steering motor neuron in the blowfly, Calliphora. J. Neurophysiol. 82, 1916–1926, https://doi.org/10.1152/jn.1999. 82.4.1916. Flavell, S.W., Pokala, N., Macosko, E.Z., Albrecht, D.R., Larsch, J., and Bargmann, C.I. (2013). Serotonin and the neuropeptide PDF initiate and extend opposing behavioral states in C. elegans. Cell 154, 1023–1035, https://doi.org/ 10.1016/j.cell.2013.08.001. Fouad, A.D., Teng, S., Mark, J.R., Liu, A., Alvarez-Illera, P., Ji, H., Du, A., Bhirgoo, P.D., Cornblath, E., Guan, S.A., and Fang-Yen, C. (2018). Distributed rhythm generators underlie Caenorhabditis elegans forward locomotion. eLife 7, 713, https://doi.org/10.7554/eLife.29913. Fox, L.E., Soll, D.R., and Wu, C.-F. (2006). Coordination and modulation of locomotion pattern generators in Drosophila larvae: effects of altered biogenic amine levels by the tyramine b hydroxlyase mutation. J. Neurosci. 26, 1486– 1498, https://doi.org/10.1523/JNEUROSCI.4749-05.2006. Fujiwara, M., Sengupta, P., and McIntire, S.L. (2002). Regulation of body size and behavioral state of C. elegans by sensory perception and the EGL-4 cGMP-dependent protein kinase. Neuron 36, 1091–1102, https://doi.org/10. 1016/S0896-6273(02)01093-0. Gallagher, T., Bjorness, T., Greene, R., You, Y.J., and Avery, L. (2013). The geometry of locomotive behavioral states in C. elegans. PLoS ONE 8, e59865, https://doi.org/10.1371/journal.pone.0059865. Gao, S., Guan, S.A., Fouad, A.D., Meng, J., Kawano, T., Huang, Y.-C., Li, Y., Alcaire, S., Hung, W., Lu, Y., et al. (2018). Excitatory motor neurons are local oscillators for backward locomotion. eLife 7, e29915, https://doi.org/10. 7554/eLife.29915. Gendrel, M., Atlas, E.G., and Hobert, O. (2016). A cellular and regulatory map of the GABAergic nervous system of C. elegans. eLife 5, e17686, https://doi. org/10.7554/eLife.17686. Glaze, C.M., and Troyer, T.W. (2006). Temporal structure in zebra finch song: implications for motor coding. J. Neurosci. 26, 991–1005, https://doi.org/10. 1523/JNEUROSCI.3387-05.2006. Gomez-Marin, A., Stephens, G.J., and Brown, A.E.X. (2016). Hierarchical compression of Caenorhabditis elegans locomotion reveals phenotypic differences in the organization of behaviour. J. R. Soc. Interface 13, 20160466, https://doi.org/10.1098/rsif.2016.0466. Gordus, A., Pokala, N., Levy, S., Flavell, S.W., and Bargmann, C.I. (2015). Feedback from network states generates variability in a probabilistic olfactory circuit. Cell 161, 215–227, https://doi.org/10.1016/j.cell.2015.02.018.

14 Neuron 105, 1–15, February 5, 2020

Hahn, G., Ponce-Alvarez, A., Deco, G., Aertsen, A., and Kumar, A. (2019). Portraits of communication in neuronal networks. Nat. Rev. Neurosci. 20, 117–127, https://doi.org/10.1038/s41583-018-0094-0. Haklai-Topper, L., Soutschek, J., Sabanay, H., Scheel, J., Hobert, O., and Peles, E. (2011). The neurexin superfamily of Caenorhabditis elegans. Gene Expr. Patterns 11, 144–150, https://doi.org/10.1016/j.gep.2010.10.008. Hendricks, M., Ha, H., Maffey, N., and Zhang, Y. (2012). Compartmentalized calcium dynamics in a C. elegans interneuron encode head movement. Nature 487, 99–103, https://doi.org/10.1038/nature11081. Huang, K.-M., Cosman, P., and Schafer, W.R. (2008). Automated detection and analysis of foraging behavior in Caenorhabditis elegans. J. Neurosci. Methods 171, 153–164, https://doi.org/10.1016/j.jneumeth.2008.01.027. Hums, I., Riedl, J., Mende, F., Kato, S., Kaplan, H.S., Latham, R., Sonntag, M., €ller, L., and Zimmer, M. (2016). Regulation of two motor patterns Traunmu enables the gradual adjustment of locomotion strategy in Caenorhabditis elegans. eLife 5, e14116, https://doi.org/10.7554/eLife.14116. Hyafil, A., Giraud, A.-L., Fontolan, L., and Gutkin, B. (2015). Neural crossfrequency coupling: connecting architectures, mechanisms, and functions. Trends Neurosci. 38, 725–740, https://doi.org/10.1016/j.tins.2015.09.001. Jin, X., and Costa, R.M. (2015). Shaping action sequences in basal ganglia circuits. Curr. Opin. Neurobiol. 33, 188–196, https://doi.org/10.1016/j.conb. 2015.06.011. Jin, X., Tecuapetla, F., and Costa, R.M. (2014). Basal ganglia subcircuits distinctively encode the parsing and concatenation of action sequences. Nat. Neurosci. 17, 423–430, https://doi.org/10.1038/nn.3632. Kato, S., Kaplan, H.S., Schro¨del, T., Skora, S., Lindsay, T.H., Yemini, E., Lockery, S., and Zimmer, M. (2015). Global brain dynamics embed the motor command sequence of Caenorhabditis elegans. Cell 163, 656–669, https://doi. org/10.1016/j.cell.2015.09.034. Kawano, T., Po, M.D., Gao, S., Leung, G., Ryu, W.S., and Zhen, M. (2011). An imbalancing act: gap junctions reduce the backward motor circuit activity to bias C. elegans for forward locomotion. Neuron 72, 572–586, https://doi.org/ 10.1016/j.neuron.2011.09.005. Kiehn, O. (2011). Development and functional organization of spinal locomotor circuits. Curr. Opin. Neurobiol. 21, 100–109, https://doi.org/10.1016/j.conb. 2010.09.004. Kim, K., and Li, C. (2004). Expression and regulation of an FMRFamide-related neuropeptide gene family in Caenorhabditis elegans. J. Comp. Neurol. 475, 540–550, https://doi.org/10.1002/cne.20189. Klapoetke, N.C., Murata, Y., Kim, S.S., Pulver, S.R., Birdsey-Benson, A., Cho, Y.K., Morimoto, T.K., Chuong, A.S., Carpenter, E.J., Tian, Z., et al. (2014). Independent optical excitation of distinct neural populations. Nat. Methods 11, 338–346, https://doi.org/10.1038/nmeth.2836. Krakauer, J.W., Ghazanfar, A.A., Gomez-Marin, A., MacIver, M.A., and Poeppel, D. (2017). Neuroscience needs behavior: correcting a reductionist bias. Neuron 93, 480–490, https://doi.org/10.1016/j.neuron.2016.12.041. Laurent, P., Soltesz, Z., Nelson, G.M., Chen, C., Arellano-Carbajal, F., Levy, E., and de Bono, M. (2015). Decoding a neural circuit controlling global animal state in C. elegans. eLife 4, e1004156, https://doi.org/10.7554/eLife.04241. Li, Z., Liu, J., Zheng, M., and Xu, X.Z.S. (2014). Encoding of both analog- and digital-like behavioral outputs by one C. elegans interneuron. Cell 159, 751–765, https://doi.org/10.1016/j.cell.2014.09.056. Liu, J., Ward, A., Gao, J., Dong, Y., Nishio, N., Inada, H., Kang, L., Yu, Y., Ma, D., Xu, T., et al. (2010). C. elegans phototransduction requires a G protein-dependent

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

cGMP pathway and a taste receptor homolog. Nat. Neurosci. 13, 715–722, https://doi.org/10.1038/nn.2540. Liu, H., Yang, W., Wu, T., Duan, F., Soucy, E., Jin, X., and Zhang, Y. (2018). Cholinergic sensorimotor integration regulates olfactory steering. Neuron 97, 390–405.e3, https://doi.org/10.1016/j.neuron.2017.12.003. Long, M.A., Jin, D.Z., and Fee, M.S. (2010). Support for a synaptic chain model of neuronal sequence generation. Nature 468, 394–399, https://doi.org/10. 1038/nature09514. Luo, L., Wen, Q., Ren, J., Hendricks, M., Gershow, M., Qin, Y., Greenwood, J., Soucy, E.R., Klein, M., Smith-Parker, H.K., et al. (2014). Dynamic encoding of perception, memory, and movement in a C. elegans chemotaxis circuit. Neuron 82, 1115–1128, https://doi.org/10.1016/j.neuron.2014.05.010. Maier, W., Adilov, B., Regenass, M., and Alcedo, J. (2010). A neuromedin U receptor acts with the sensory system to modulate food type-dependent effects on C. elegans lifespan. PLoS Biol. 8, e1000376, https://doi.org/10.1371/journal.pbio.1000376. Marder, E., and Bucher, D. (2001). Central pattern generators and the control of rhythmic movements. Curr. Biol. 11, R986–R996, https://doi.org/10.1016/ s0960-9822(01)00581-4. Marques, J.C., Lackner, S., Fe´lix, R., and Orger, M.B. (2018). Structure of the zebrafish locomotor repertoire revealed with unsupervised behavioral clustering. Curr. Biol. 28, 181–195.e5, https://doi.org/10.1016/j.cub.2017.12.002. McCloskey, R.J., Fouad, A.D., Churgin, M.A., and Fang-Yen, C. (2017). Food responsiveness regulates episodic behavioral states in Caenorhabditis elegans. J. Neurophysiol. 117, 1911–1934, https://doi.org/10.1152/jn.00555.2016. Moore, J.D., Descheˆnes, M., Furuta, T., Huber, D., Smear, M.C., Demers, M., and Kleinfeld, D. (2013). Hierarchy of orofacial rhythms revealed through whisking and breathing. Nature 497, 205–210, https://doi.org/10.1038/ nature12076. Nichols, A.L.A., Eichler, T., Latham, R., and Zimmer, M. (2017). A global brain state underlies C. elegans sleep behavior. Science 356, eaam6851, https://doi. org/10.1126/science.aam6851. Piggott, B.J., Liu, J., Feng, Z., Wescott, S.A., and Xu, X.Z.S. (2011). The neural circuits and synaptic mechanisms underlying motor initiation in C. elegans. Cell 147, 922–933, https://doi.org/10.1016/j.cell.2011.08.053. Pirri, J.K., McPherson, A.D., Donnelly, J.L., Francis, M.M., and Alkema, M.J. (2009). A tyramine-gated chloride channel coordinates distinct motor programs of a Caenorhabditis elegans escape response. Neuron 62, 526–538, https://doi.org/10.1016/j.neuron.2009.04.013. Pokala, N., Liu, Q., Gordus, A., and Bargmann, C.I. (2014). Inducible and titratable silencing of Caenorhabditis elegans neurons in vivo with histamine-gated chloride channels. Proc. Natl. Acad. Sci. USA 111, 2770–2775, https://doi.org/ 10.1073/pnas.1400615111.

Shen, Y., Wen, Q., Liu, H., Zhong, C., Qin, Y., Harris, G., Kawano, T., Wu, M., Xu, T., Samuel, A.D., and Zhang, Y. (2016). An extrasynaptic GABAergic signal modulates a pattern of forward movement in Caenorhabditis elegans. eLife 5, e14197, https://doi.org/10.7554/eLife.14197. Skora, S., Mende, F., and Zimmer, M. (2018). Energy scarcity promotes a brain-wide sleep state modulated by insulin signaling in C. elegans. Cell Rep. 22, 953–966, https://doi.org/10.1016/j.celrep.2017.12.091. Sohal, V.S., Zhang, F., Yizhar, O., and Deisseroth, K. (2009). Parvalbumin neurons and gamma rhythms enhance cortical circuit performance. Nature 459, 698–702, https://doi.org/10.1038/nature07991. Sponberg, S., and Daniel, T.L. (2012). Abdicating power for control: a precision timing strategy to modulate function of flight power muscles. Proc. Biol. Sci. 279, 3958–3966, https://doi.org/10.1098/rspb.2012.1085. Starich, T.A., Xu, J., Skerrett, I.M., Nicholson, B.J., and Shaw, J.E. (2009). Interactions between innexins UNC-7 and UNC-9 mediate electrical synapse specificity in the Caenorhabditis elegans locomotory nervous system. Neural Dev. 4, 16, https://doi.org/10.1186/1749-8104-4-16. Tinbergen, N. (1951). The study of instinct (Oxford Eng.: Clarendon Press). Turek, M., Lewandrowski, I., and Bringmann, H. (2013). An AP2 transcription factor is required for a sleep-active neuron to induce sleep-like quiescence in C. elegans. Curr. Biol. 23, 2215–2223, https://doi.org/10.1016/j.cub.2013. 09.028. Von Stetina, S.E., Fox, R.M., Watkins, K.L., Starich, T.A., Shaw, J.E., and Miller, D.M., 3rd (2007). UNC-4 represses CEH-12/HB9 to specify synaptic inputs to VA motor neurons in C. elegans. Genes Dev. 21, 332–346, https://doi. org/10.1101/gad.1502107. Wen, Q., Po, M.D., Hulme, E., Chen, S., Liu, X., Kwok, S.W., Gershow, M., Leifer, A.M., Butler, V., Fang-Yen, C., et al. (2012). Proprioceptive coupling within motor neurons drives C. elegans forward locomotion. Neuron 76, 750–761, https://doi.org/10.1016/j.neuron.2012.08.039. White, J.G., Southgate, E., Thomson, J.N., and Brenner, S. (1986). The structure of the nervous system of the nematode Caenorhabditis elegans. Philos. Trans. R. Soc. Lond. B Biol. Sci. 314, 1–340, https://doi.org/10.1098/rstb. 1986.0056. Wiltschko, A.B., Johnson, M.J., Iurilli, G., Peterson, R.E., Katon, J.M., Pashkovski, S.L., Abraira, V.E., Adams, R.P., and Datta, S.R. (2015). Mapping sub-second structure in mouse behavior. Neuron 88, 1121–1135, https://doi.org/10.1016/j.neuron.2015.11.031. Winnier, A.R., Meir, J.Y., Ross, J.M., Tavernarakis, N., Driscoll, M., Ishihara, T., Katsura, I., and Miller, D.M., 3rd (1999). UNC-4/UNC-37-dependent repression of motor neuron-specific genes controls synaptic choice in Caenorhabditis elegans. Genes Dev. 13, 2774–2786.

Ramot, D., Johnson, B.E., Berry, T.L., Jr., Carnell, L., and Goodman, M.B. (2008). The Parallel Worm Tracker: a platform for measuring average speed and drug-induced paralysis in nematodes. PLoS ONE 3, e2208, https://doi. org/10.1371/journal.pone.0002208.

Xu, T., Huo, J., Shao, S., Po, M., Kawano, T., Lu, Y., Wu, M., Zhen, M., and Wen, Q. (2018). Descending pathway facilitates undulatory wave propagation in Caenorhabditis elegans through gap junctions. Proc. Natl. Acad. Sci. USA 115, E4493–E4502, https://doi.org/10.1073/pnas.1717022115.

Ringstad, N., Abe, N., and Horvitz, H.R. (2009). Ligand-gated chloride channels are receptors for biogenic amines in C. elegans. Science 325, 96–100, https://doi.org/10.1126/science.1169243.

Yemini, E., Jucikas, T., Grundy, L.J., Brown, A.E.X., and Schafer, W.R. (2013). A database of Caenorhabditis elegans behavioral phenotypes. Nat. Methods 10, 877–879, https://doi.org/10.1038/nmeth.2560.

Roberts, W.M., Augustine, S.B., Lawton, K.J., Lindsay, T.H., Thiele, T.R., Izquierdo, E.J., Faumont, S., Lindsay, R.A., Britton, M.C., Pokala, N., et al. (2016). A stochastic neuronal model predicts random search behaviors at multiple spatial scales in C. elegans. eLife 5, e12572, https://doi.org/10.7554/ eLife.12572.

Yeon, J., Kim, J., Kim, D.-Y., Kim, H., Kim, J., Du, E.J., Kang, K., Lim, H.-H., Moon, D., and Kim, K. (2018). A sensory-motor neuron type mediates proprioceptive coordination of steering in C. elegans via two TRPC channels. PLoS Biol. 16, e2004929, https://doi.org/10.1371/journal.pbio.2004929.

Ruijtenberg, S., and van den Heuvel, S. (2015). G1/S inhibitors and the SWI/ SNF complex control cell-cycle exit during muscle differentiation. Cell 162, 300–313, https://doi.org/10.1016/j.cell.2015.06.013. Schro¨del, T., Prevedel, R., Aumayr, K., Zimmer, M., and Vaziri, A. (2013). Brainwide 3D imaging of neuronal activity in Caenorhabditis elegans with sculpted light. Nat. Methods 10, 1013–1020, https://doi.org/10.1038/nmeth.2637.

Yuste, R., MacLean, J.N., Smith, J., and Lansner, A. (2005). The cortex as a central pattern generator. Nat. Rev. Neurosci. 6, 477–483, https://doi.org/10. 1038/nrn1686. Zimmer, M., Gray, J.M., Pokala, N., Chang, A.J., Karow, D.S., Marletta, M.A., Hudson, M.L., Morton, D.B., Chronis, N., and Bargmann, C.I. (2009). Neurons detect increases and decreases in oxygen levels using distinct guanylate cyclases. Neuron 61, 865–879, https://doi.org/10.1016/j.neuron.2009.02.013.

Neuron 105, 1–15, February 5, 2020 15

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

STAR+METHODS KEY RESOURCES TABLE

REAGENT or RESOURCE

SOURCE

IDENTIFIER

C. elegans: Strain ZIM958: lite-1 (ce314)

This study

N/A

C. elegans: Strain ZIM1466: lite-1 (ce314); mzmEx877[Pnlr-1(150;-1)::HisCl::SL2::mCherry ]; mzmIs52[Punc-31::NLSGCaMP6f]

This study

N/A

C. elegans: Strain ZIM1564: lite-1 (ce314); mzmEx929[Punc-7 s::CreVDH;Pmyo-3::mCherry]

This study

N/A

C. elegans: Strain ZIM1725: lite-1 (ce314); mzmEx1018[Punc-7 s::CreVDH;Pmyo-3::mCherry]

This study

N/A

C. elegans: Strain ZIM1418: lite-1 (ce314); mzmEx858[Pflp-22::DIO-HisCl::SL2::mCherry; Pelt-2::NLSdsRedNLS]

This study

N/A

C. elegans: Strain ZIM1473: lite-1 (ce314); mzmIs28[Punc-17beta::HisCl::SL2::mCherry]

This study

N/A

C. elegans: Strain ZIM1628: lite-1 (ce314); mzmEx877[Pnlr-1(150;-1)::HisCl::SL2::mCherry]; mzmEx929 [Punc-7 s::CreVDH;Pmyo-3::mCherry];mzmIs52 [Punc-31::NLSGCaMP6f]

This study

N/A

C. elegans: Strain ZIM1748: lite-1 (ce314); mzmEx877[Pnlr-1(150;-1)::HisCl::SL2::mCherry]; mzmEx1018 [Punc-7 s::CreVDH;Pmyo-3::mCherry];mzmIs52 [Punc-31::NLSGCaMP6f]

This study

N/A

C. elegans: Strain ZIM1562: lite-1 (ce314); mzmEx877[Pnlr-1(150;-1)::HisCl::SL2::mCherry]; mzmEx858 [Pflp-22::DIO-HisCl::SL2::mCherry;Pelt-2::NLSdsRedNLS ];mzmIs52 [Punc-31:: NLSGCaMP6f]

This study

N/A

C. elegans: Strain ZIM1574: lite-1 (ce314); mzmEx877[Pnlr-1(150;-1)::HisCl::SL2::mCherry]; mzmIs28 [Punc-17beta::HisCl::SL2::mCherry];mzmIs52 [Punc-31::NLSGCaMP6f]

This study

N/A

C. elegans: Strain ZIM1658: lite-1 (ce314); mzmEx981[Punc-17beta::NLSGCaMP6f]

This study

N/A

C. elegans: Strain ZIM1467: lite-1 (ce314); mzmEx882[Punc-7S::CreVDH;Pflp-22::DIOmCherry;Pflp-22::DIO-GCaMP6Fopt]

This study

N/A

C. elegans: Strain ZIM2122: lite-1 (ce314); mzmEx1268[Pinx-1::hisCl; Pflp-17::mCherry]

This study

N/A

C. elegans: Strain ZIM2105: lite-1 (ce314); tdc-1 (n3419); mzmEx882[Punc-7S::CreVDH; Pflp-22::DIO-mCherry; Pflp-22::DIO-GCaMP6Fopt]

This study

N/A

C. elegans: Strain ZIM2106: lite-1 (ce314); lgc-55(n4331); mzmEx882[Punc-7S::CreVDH; Pflp-22::DIO-mCherry; Pflp-22::DIO-GCaMP6Fopt];

This study

N/A

C. elegans: Strain ZIM2124: lite-1 (ce314); yxEx696 [Pglr-3::TeTx::mCherry; Punc-122::dsRed]; mzmEx882[Punc-7S::CreVDH; Pflp-22::DIO-mCherry; Pflp-22::DIO-GCaMP6Fopt]

This study

N/A

C. elegans: Strain ZIM2120: lite-1 (ce314); mzmEx1262 [Pglr-3::hisCl::SL2::mCherry; Pflp-17::mCherry]; mzmEx882[Punc-7S::CreVDH; Pflp-22::DIO-mCherry; Pflp-22:: DIO-GCaMP6Fopt]

This study

N/A

C. elegans: Strain ZIM2128: lite-1 (ce314); unc-25 (e156); mzmEx882[Punc-7S::CreVDH; Pflp-22::DIO-mCherry; Pflp-22::DIO-GCaMP6Fopt];

This study

N/A

C. elegans: Strain ZIM1749: lite-1 (ce314); mzmEx1041[Psto-3::HisCl::mCherry;Punc-122::GFP]

This study

N/A

C. elegans: Strain ZIM1563: lite-1 (ce314); mzmEx928[Psto-3::Chrimson::mCherry;Punc-122::GFP]

This study

N/A

Experimental Models: Organisms/Strains

LEAD CONTACT AND MATERIALS AVAILABILITY All unique/stable reagents generated in this study are available from the Lead Contact (M.Z., [email protected]) with a completed Materials Transfer Agreement. EXPERIMENTAL MODEL AND SUBJECT DETAILS All experiments were performed in lite-1 (ce314) animals to reduce light responses (Liu et al., 2010). Young adult hermaphrodites were used for all experiments. Worms were maintained using standard methods (Brenner, 1974) and grown at 20 C on nematode growth media (NGM) plates, which were seeded with Escherichia coli OP50 as a food source. A detailed list of all transgenic strains used is provided in the Key Resources Table and Table S1.

e1 Neuron 105, 1–15.e1–e9, February 5, 2020

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

METHOD DETAILS Population behavior assays For on-food assays (Figures 8G, 8H, 8L–8N, S8C, and S8D), 20 animals (young adults, 0 eggs to 1 row of eggs) were transferred to a 15cm NGM assay plate seeded with OP50 (previously grown for 16 h at room temperature). For off-food assays (all other behavior experiments) animals were picked onto a food-free NGM plate, immersed in 1mL S-basal to remove transferred food, and picked again onto a food-free 15cm NGM assay plate. Data in Figure 1C are combined from an equal number of on- and off-food experiments, because head-casts make up the majority of bends on-food and propagated-bends make up the majority off-food. Data in Figure 1D and Figures S1B-S1D, S1G, and S1H are taken only from animals off-food to enable comparison within a single condition. Data in Figures S1E–S1G are taken from Ca2+ imaging experiments, which showed a higher number of head-cast episodes with more 4-6 head-casts and which had dorsal/ventral sides annotated, unlike animals recorded in behavior assays. In both on- and off-food cases, a 36mm x 36mm assay arena was delineated by Whatman paper soaked with 20mM CuCl2, a repellent used to prevent worms from leaving the arena. A custom transparent plexiglass gas flow device (Hums et al., 2016) of 39mm x 39mm x 0.7mm was placed on top of this arena, through which 21% O2 was delivered at 25mL/min via a static gas mixer connected to mass flow controllers (Vo¨gtlin Instruments), operated by custom written LabVIEW scripts (National Instruments). For off-food assays, 21% O2 was switched to 4% O2 to examine sensory responses; for on-food assays, 21% O2 was required to observe significant roaming periods. Arenas were illuminated with red LEDs and movies were recorded at 10fps on 5 megapixel CMOS cameras (Teledyne DALSA) with a pixel resolution of 0.0129 mm/pixel. Animals were allowed to acclimate for either 5min (off-food) or 1 h (on-food) prior to recordings. For histamine assays, prior to picking onto the assay plates, animals were incubated for 30-45min on plates with NGM agar including either 20mM histamine (+His; histamine dihydrochloride, Sigma-Aldrich) or an equal volume of water (-His) and seeded with OP50 across the entire agar surface to enhance histamine uptake. Recordings were performed on +His and -His assay plates. For optogenetics assays, animals expressing the optogenetic activator Chrimson (Klapoetke et al., 2014) were grown on NGM plates seeded with OP50 plus either 100 mM all-trans retinal (ATR) or an equal volume of ethanol lacking ATR (Control). One day prior to assays, L3 and L4 animals were picked onto fresh ATR or Control plates. After 30min without light, constant 591nm light was delivered, via a custom-made ring of LEDs above the assay plate, at 45 mW/mm2 for 30min. Movies were analyzed using custom image processing and tracking code in MATLAB (Mathworks), built upon previously published scripts (Ramot et al., 2008). Briefly, worms were detected by gray level thresholding, and trajectories were found by adjoining nearby centroid coordinates in adjacent frames. These centroid data were used for speed, angular speed, reversal, and heading change quantifications. To measure bend angles, worm images were analyzed as described in (Hums et al., 2016). Briefly, binarized worm images were skeletonized to produce splines tracing the midline of each worm. Splines were smoothed and divided into 25 equally spaced body segments. Head versus tail positions were determined by direction of centroid movement. Angles were measured between adjacent segments as in Figure 1A to produce 24 angle measurements for each frame in each worm’s trajectory. Power spectra in Figures S3E–S3H, S4C, and S5A–S5C were calculated using the MATLAB (Mathworks) function fft on the timeseries concatenated across experiments. For experiments in which manipulations caused a loss of animal movement, it was important to exclude time-averaged background subtraction prior to gray level thresholding, and to assign head position manually. Ventral and dorsal were indistinguishable in these lower-resolution recordings, so angle sign was assigned randomly; all panels distinguishing ventral and dorsal directions made use of higher-resolution movies recorded along with Ca2+ imaging (see below). Ca2+ imaging in immobilized animals For immobilized Ca2+ imaging whole-brain and whole-nervous system experiments, transgenic adult C. elegans (1 day after larval L4 stage, 0-10 eggs) expressing genetically-encoded calcium indicator NLS-GCaMP6f (Chen et al., 2013) panneuronally (using the Punc-31 promoter) were recorded as described previously (Kato et al., 2015) with following modifications. Previously, we found that forward command states occasionally terminate in quiescence periods (Kato et al., 2015; Nichols et al., 2017). Thus, to increase forward command state occurrence, we expressed the Drosophila hisCl channel (Pokala et al., 2014) in the quiescence-promoting neuron RIS (Nichols et al., 2017; Turek et al., 2013) with the Pnlr-1 (Gendrel et al., 2016; Haklai-Topper et al., 2011) promoter. To silence the SMDs, hisCl was expressed specifically in these neurons using a Cre-lox strategy. To this end, we expressed Cre with the Punc-7S promoter (Starich et al., 2009) and the HisCl::SL2::mCherry construct within a double inverted open reading frame (DIO) with the Pflp-22 promoter (Kim and Li, 2004). SMD inhibition was confirmed using the mCherry marker co-expressed with HisCl while co-recording GCaMP from the SMD neurons; animals showing residual SMD activity (50% of animals) were excluded from further analysis. Residual SMD activity often observed in mCherry-positive neurons (data not shown) may explain residual head-casting in SMD::hisCl animals (Figure 4B). Body MNs were silenced by expressing hisCl and mCherry in VNC cholinergic motor neuron classes AS, DA, DB, VA, VB with promoter Punc-17b (Charlie et al., 2006); this promoter is referred to as VNCACh throughout. While we could not use the mCherry marker to unambiguously identify DB01 and DB02 in these animals, we confirmed that all mCherrypositive neurons in the retrovesicular ganglion (where DB01 and DB02 nuclei reside) showed little to no activity. Immobilized Ca2+ imaging experiments were performed with custom-made microfluidic two-layer PDMS devices as previously described (Kato et al., 2015; Schro¨del et al., 2013), with modifications. In addition to the curve in the worm channel used to align worms laterally (Ca´ceres et al., 2012), a straightening of the channel was followed by a second curve designed to fit a young adult

Neuron 105, 1–15.e1–e9, February 5, 2020 e2

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

worm. This curve was designed to align the animal’s head and tail, thus reducing the necessary imaging area to record the activity of all neurons in the C. elegans body; it also contains a narrowing in order to keep the animal’s head in place. A technical drawing of the design is provided in Figure S2A. As previously described (Hums et al., 2016; Zimmer et al., 2009), the worm channel of the microfluidic device was connected to a syringe containing nematode growth medium (NGM) buffer with 1 mM tetramisole and 20 mM histamine (his-tet-NGM). All components were connected using Tygon tubing (0.02 in ID, 0.06 in OD; Norton) or polyethylene tubing (0.066 in ID, 0.095 in OD; Intramedic) using 23G Luer-stub adapters (Intramedic). Constant gas delivery at 21% O2 at a flow rate of 50ml/min was regulated with a gas mixer attached to mass flow controllers (Vo¨gtlin Instruments) that mixed oxygen and nitrogen from pressurized gas tanks, using LabView software. Well-fed worms were transferred onto NGM agar plates seeded with OP50 E. coli mixed with 20 mM histamine to feed on for 30-45 min. To rid them of bacteria covering the body, the animals were transferred into a drop of his-tet-NGM on a food-free NGM agar plate and then onto a second NGM plate with his-tet-NGM buffer. A vacuum was manually applied with the syringe to suck up individual animals into Tygon tubing; this tubing was subsequently reconnected to the worm inlet to arrange the worm in the curved channel. The fluorescence values were recorded 5 min after loading; the illumination and piezo stage were switched on 2-3 min before acquisition start. Animals were imaged at 21% O2 for 30 min. High-resolution data of neuronal activity in the head ganglia (whole-brain recordings) was acquired with an inverted UltraViewVoX spinning disk confocal microscope (PerkinElmer) using an EMCCD camera (C9100-13, Hamamatsu) and a 40x 1.3 NA EC PlanNeofluar oil-immersion objective (Zeiss). The volume spanning the animals’ head ganglia was recorded in 13-15 2 mm z-planes, each illuminated for 10ms to record GCaMP6f fluorescence, resulting in acquisition rates of 1.55 - 2.23 volumes/sec. High-speed, high-resolution data of SMD neuronal activity in immobilized animals was acquired to confirm that the acquisition rate of whole-brain recordings was sufficient to capture SMD dynamics. This was achieved using with an inverted spinning disk confocal microscope (Observer Z1, Zeiss with Yokogawa CSU-X1 spinning disk) with a 40x 1.2 NA LCI Plan-Apochromat multi-immersion objective (Zeiss) with an EMCCD camera (Evolve 512, Photometrics). To obtain data with high temporal resolution, we recorded single planes illuminated for 20ms, resulting in an acquisition speed of 50 Hz. Whole-nervous system neuronal activity was recorded using an inverted fluorescence microscope (Observer Z1, Zeiss) with a 25x 0.8 NA LCI Plan-Neofluar multi-immersion objective (Zeiss) and recorded with a scientific complementary metal-oxide-semiconductor (sCMOS) camera (pco.edge 4.2, PCO) using Visiview software (Visitron Systems). The nervous system was recorded in 30 1 mm z-planes illuminated each for 10ms, resulting in an acquisition rate of 3.0303 volumes/sec. To increase the contrast and resolution of the image data in the immobilized whole-nervous-system recordings exclusively, we used a deconvolution algorithm (classic maximum likelihood estimation) using Huygens software (signal/noise ratio, 8; automatic background estimation; iterations, 40; quality change stopping criterion, 0.1). After deconvolution, the neuronal activity traces extracted from immobilized whole-nervous-system recordings were compared to ‘‘ground truth’’ high-resolution whole-brain recordings acquired with spinning disk confocal microscopy in order to assess the quality of the whole-nervous-system data and to ensure that the deconvolution procedure did not introduce artifacts. Importantly, deconvolution was performed only for whole nervous system recordings in immobilized worms because a standard spinning disk confocal microscope (Yokogawa CSU-X1 scanning head) does not provide the needed field of view. Head-tail multi neuron imaging and all imaging on freely moving animals did not include image deconvolution post processing steps. Simultaneous imaging of neuronal activity and behavior Transgenic young adult worms (0-6 eggs), expressing GCaMP6f and mCherry in specific neurons of interest, were placed onto a foodless NGM agar plate, allowed to crawl away from food, then picked onto another foodless NGM agar plate. Then, as in (Collins and Koelle, 2013), a 40mm x 40mm chunk of agar surrounding the worm was removed and covered with a 45mm x 50mm #1.5 coverglass, so that the worm was between coverglass and agar. Under these conditions worms move slower but with qualitatively normal body shapes and behavior. The coverglass setup was placed into a motorized stage with associated controller (MS-2000PhotoTrack, Applied Scientific Instrumentation). After a 5min acclimation period including at least 2min excitation light exposure, each worm was recorded for 8min. Images were acquired using an inverted compound microscope (Ziess Axio Observer.Z1) with two Charge-Coupled Device cameras (Evolve 512, Photometrics). A CoolLED pE-2 excitation system provided dual wavelength excitation light (470 and 585 nm) with an ET-EGFP/mCherry filter set (59022x, Chroma) and dichroic (59022bs, Chroma). A 63x oil objective (Zeiss Plan-Apochromat, 1.4 NA) was used to stream unbinned single-plane fluorescence images at 33ms exposure time, resulting in 30 Hz imaging frame rate, with Visiview software (Visitron Systems GmbH). Sparse drivers were used to enable stable GCaMP expression specifically to neurons of interest (and few others), a precaution necessary to ensure the unambiguous identification of specific neurons of interest and the subsequent extraction of their neuronal signals. The neuron(s) of interest were re-centered onto the objective using the system described in (Faumont et al., 2011): a dichroic mirror (620 spxr, Chroma) directed the high-wavelength portion of the mCherry emission to a four-quadrant photomultiplier tube (Hamamatsu). Remaining emission light was split by a DualCam DC2 cube (565 lpxr, Photometrics) to each CCD camera, one for mCherry (641/75nm, Brightline) and one for GCaMP (520/35nm, Brightline). Simultaneous behavior recordings were made under infrared illumination (780nm) using a CCD camera (Manta Prosilica GigE, Applied Vision Technologies) at 4x magnification and 100ms exposure time. Approximately 8 min of data were acquired for each animal.

e3 Neuron 105, 1–15.e1–e9, February 5, 2020

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Data Analysis Neuronal time series extraction from immobilized pan-neuronal imaging experiments As described before (Kato et al., 2015), neuronal activity traces were obtained by tracking the intensity maxima in each volume over time and calculating the single-cell fluorescence intensities (F). F0 was calculated as the mean fluorescence intensity across the trial. After background subtraction, DF/ F0 was calculated for each neuron. DF/F0 neural traces were then detrended to correct for bleaching in a two-step procedure which gave qualitatively better results compared to the previously described method (Kato et al., 2015). First, we performed and exponential fit to each trace, followed by fitting a single exponential function to peaks of the neural traces. This second bleach-correction step (referred to as detrending), occasionally drastically over-corrected and resulted in distorted neuronal traces in a small number of instances. Thus, we calculated the relative change in variance of each trace after the second detrending step ðvarðpost detrendingÞ varðpre detrendingÞ =varðpre detrendingÞÞ as a measure of distortion. The distribution of these measures across all neurons exhibited a long tail and instructed us to determine a relative change of 8 as a cutoff for distorted traces. For neural traces above the variance change cutoff (3.31% of the neuronal traces analyzed), we resorted to the single bleachcorrected version of the trace. Neuronal identification (pan-neuronal imaging) In whole-brain Ca2+ imaging data, the activity of 113-129 neurons was detected in the head ganglia, which corresponds to 49.7 66.15% of expected neurons. The rest likely were constitutively inactive and thus showed very low fluorescence levels; we further cannot exclude that the label is not expressed in a small fraction of neurons. In whole-nervous system Ca2+ imaging data, 103129 neurons were detected across the whole body (39.4 - 42.7%). The identification of the neurons of interest was done according to their activity patterns, anatomical location (https://www. wormatlas.org/) and our experience with red fluorophore expression in specific marker lines reported in previous recordings (Kato et al., 2015; Nichols et al., 2017; Skora et al., 2018). In addition, the SMD neurons were identified by driving worm codon-optimized mCherry (wCherry) (Kawano et al., 2011) expression with the Pflp-22 and Punc-7 s promoters; henceforth, we disambiguated the uncertain cell class identity of these neurons reported in previous studies (SMDD versus SMB or RMF)(Kato et al., 2015; Schro¨del et al., 2013). B-MNs along the VNC were identified with the Pacr-5 promoter (Winnier et al., 1999); PDA was identified with a Crelox strategy using the Pflp-7::Cre and Pnmur-1::DIO-mCherry constructs (Kim and Li, 2004; Maier et al., 2010). We denoted # cases in which reliably observed activity patterns in distinct locations could not be unambiguously assigned to neuronal identities; their neuronal identities and possible alternatives are shown in brackets: URY (URA, IL1), RMD (SAA, RIA, SIB, RIH), SIB (SIA, RMD, RMH). B-MN IDs were determined by a combination of position, activity, and specific marker line information. We consistently observed four neurons in the retrovesicular ganglion (RVG) with heightened activity during forward command states; we labeled the anteriormost neuron VB02 and the posterior-most neuron DB01, in agreement with previous IDs (https://www.wormatlas.org/). Of the remaining two neurons, we consistently found one with activity patterns like DB01 and VB02 (i.e., slow rises following AVA fall and activity plateaus throughout forward command states) and one with more spike-like, unpredictable activity transients. We used Pceh-12::mCherry to label VB neurons (Von Stetina et al., 2007) while recording and found that the latter neuron is VB01; the former is therefore DB02. Other B-MNs are reported to occur in a specific pattern along the VNC: DB03 and VB04 are posterior to the RVG and separated by cell bodies of other neuron classes, and posterior to VB04 is a repeating pattern of consecutive (i.e., uninterrupted by other cell bodies) VB/DB pairs followed by single VB neurons. We used Pacr-5::mCherry to label all B-MNs and their processes and confirmed this 2-1-2-1 pattern. This marker also showed that in VB/DB pairs, the VB neuron is always anterior (DB but not VB neurons have commissures that cross to the dorsal side). One exception to this rule was the posterior-most pair: 11/20 animals showed DB07 anterior to VB11. In whole-nervous-system recordings, we found the expected number of neurons in the expected anatomical pattern showing heightened activity during forward command states in all recordings. This allowed us to assign IDs to all such neurons except DB07 and VB11; we labeled the anterior of this pair DB07a and the posterior VB11p. Principal Component Analysis (PCA; immobilized pan-neuronal imaging) Our previously reported neuronal activity studies in freely moving animals showed that behavioral parameters like motor state, crawling speed and turning strength can sometimes better be decoded either from the time derivatives or original Ca2+-imaging traces, depending on neuronal class (Kato et al., 2015). Unlike in our previous work, where we performed PCA only on the time derivatives (Kato et al., 2015; Nichols et al., 2017; Skora et al., 2018), we here performed PCA on both original Ca2+-imaging traces plus their derivatives, thus each neuron is represented by two variables (rather than one) where each recording frame is one observation. This procedure is less biased as it captures both instantaneous Ca2+-levels as well as the dynamics of each neuron. First, the time derivatives of DF/F0 of the detrended neuronal activity traces were calculated using the total variation regularized differentiation method (Chartrand, 2011). The neural traces were normalized so that each trace and its time derivative had equal variance. PCA was performed on the detrended DF/F0 neural traces and their time derivatives simultaneously using the MATLAB (Mathworks) pca function, which also calculated variance explained for each PC. For visualization purposes, a 10-sample sliding average filter was applied to the PCA-phase plot trajectories. Command state coloring of the phase plot trajectories was performed similarly as described previously (Kato et al., 2015). Shortly, AVA, SMDD and SMDV activities were used to assign behavior state commands to population neuronal activity. For this, RISE, HIGH, FALL and LOW phases were identified for these neurons as follows: RISE and FALL phases were defined as time points when their time derivative was greater than a small positive threshold or smaller than a negative

Neuron 105, 1–15.e1–e9, February 5, 2020 e4

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

threshold, respectively. The remaining time points were assigned to HIGH and LOW phases based on behavioral state order and a threshold. The time points in the trajectory of neuronal activity were then colored by AVA phase (AVA rise and high as reversal, fall as a post-reversal turn, and low as forward command)(Figures 2C and S2B). Note that AVA falls were coupled to either SMDV or SMDD rises and these were mutually exclusive in 100% of all detected AVA falls (Figure S5K). Command state identification, duration quantification (immobilized pan-neuronal imaging) Forward command states were inferred from the activity of interneuron AVA, as previously described (Kato et al., 2015). Shortly, time points of falling Ca2+ transients and low intensity AVA Ca2+ signals were defined as forward command states. Time points of rising Ca2+ transients and high intensity Ca2+ signals were defined as reversal command states. Mean activity difference quantification (pan-neuronal imaging) In order to assess whether neuronal activity levels are modulated by the forward/reverse command state, we calculated for each neuron the mean DF/F0 of the Ca2+ imaging neural activity traces in all forward and reverse command states, separately, and calculated the difference. As for the peak frequency quantification (see below), all neurons identified in at least three recordings were taken into account. We determined which neurons showed a significant difference between their mean activity levels in the forward versus reverse command states with a paired t test (p values reported in Table S2). The distribution of forward command state duration was bimodal (data not shown) and states shorter than 50 s rarely allowed for more than one fluctuation per state. In order to avoid a bias in our analysis because of lack of data, forward command states shorter than 50 s were excluded from the analysis. Frequencies were calculated as the number of maximum peaks within each forward command state divided by the duration of each forward command state for each neuron. Instances where a neuron was identified but no peaks were detected were counted as zero. Peak frequency quantification (immobilized pan-neuronal imaging and freely moving imaging) Peak detection was used to quantify neuronal activity data shown in Figures 3, 4, 5, 6, 7G, 7H, S2D, S2E, S3C, S3D, S5D, S5L, S6, and S7E–S7I. For Figures 3, 4, S2D, and S2E only, peaks were detected on derivative timeseries: for all neurons identified in at least three recordings, we obtained their smoothed time derivatives with the total variation regularized differentiation method (Chartrand, 2011). For all peak detections, derivative and non-derivative, we took the following approach. We detected local maxima and minima in each trace: maximum peaks were found as maximal values that were preceded and followed by minima values separated from the maximum by an amplitude difference of at least delta, a key parameter. Peak detection involves a tradeoff between false positives and false negatives; the parameter delta determines how liberal (more false positives) or conservative (more false negatives) the peak detection is. We developed a simple method to automatically determine a near-optimal delta value (i.e., minimizing both false positives and false negatives) for each neuronal activity trace. We first perform peak detection with a wide range of deltas that spans from too liberal (many false positives, due to detection of noise) to too conservative (many false negatives, large amplitude peaks not detected). Then, we plot the number of peaks detected as a function of delta. The shape of this curve varies depending on the activity trace, but often resembles a piecewise linear function of two parts. At low delta values, the slope is high: the number of peaks detected by low delta values is dominated by false positives due to noise, and in this case, small increases in delta cause large decreases in the number of peaks detected. At high delta values, the slope is low: the peaks detected at high delta values are only real (i.e., large amplitude) ones, and in this case, small increases in delta typically result in little to no change in the number of detected peaks. Therefore, the slope of the curve at high delta values is much closer to 0 than at low delta values. In the ideal case, the change point between these two lines is clear, giving an optimal delta value at which the numbers of both false positives and false negatives are minimized. We determined this point using the MATLAB (Mathworks) function findchangepts, with the ‘linear’ option; this outputs the index of the curve at which both the mean and slope change most abruptly. This method matched our hand-chosen ‘‘ground truth’’ detected peaks remarkably well for several traces, and performed much better than choosing a single delta value for all traces in a dataset. However, this method remains dependent on two parameters. First, all peak detection methods depend strongly on the degree to which the data are smoothed. Second, the range of deltas tested determines whether or not this method will succeed. If the delta range is dominated by deltas that are too low or too high, it will not find an adequate changepoint, or the changepoint will be too liberal or too conservative for all traces. We found that a single range of deltas works well for all data in a particular noise (e.g., sampling rate, degree of smoothing) and amplitude (e.g., derivative or nonderivative) regime. We also found that a good starting point to determine the delta range for a particular trace was to use the standard deviation, setting this value as the maximum of the delta range, while setting the minimum and interval between deltas as the standard deviation divided by 100. In this work, for each of four different types of datasets, we used a different delta range, as follows. For peak detection on derivatives from immobilized worm recordings (Figures 3, 4, and S2), the delta range went from 104 to 0.03 in steps of 5x105. For peak detection on raw traces of immobilized worm recordings at 1.5-3 Hz (Figures 7H, S3C, S3D, S5L, and S7F), the delta range went from 0.001 to 0.5 in steps of 0.001. For peak detection on raw traces of immobilized worm recordings at 50 Hz (Figures S3C and S3D), the delta range went from 0.08 to 0.3 in steps of 0.0005. For freely moving imaging recordings (Figures 5, 6, 7, and S5–S7), the delta range went from 0.001 to 1 in steps of 0.001. For peak detection on derivatives, which gave better results across all neurons in brain-wide recordings than peak detection on raw traces, two additional steps were made: (1) peaks with amplitudes less than 0 were excluded, as these are changes in the slope of a fall rather than rises; (2) the second of two subsequent maxima was only included if the intervening minimum fell below 0. If the intervening minimum did not fall below 0, the two peaks correspond to changes in slope rather than individual calcium peaks, and the second peak was therefore excluded.

e5 Neuron 105, 1–15.e1–e9, February 5, 2020

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Cross-correlation analysis (immobilized pan-neuronal imaging) Covariograms were calculated for all neurons that could be reliably identified across at least three immobilized worm recordings. Covariograms report the frequency, relative to chance levels, of a ‘‘target’’ neuron’s peak at different time delays relative to a ‘‘reference’’ neuron’s peak. We found covariogram analysis superior to standard cross-correlation analysis for our sparse data. For example, neurons often showed only one or two activity transients per forward command state. Standard cross-correlation on sparse data would report a high value at a given lag for two neurons showing few activity transients each, despite having independent signals. For example, a toy dataset of two signals, one oscillatory and one with a single step or few step signals would result into a strong cross correlation signal, which would otherwise vanish, if the time-series could be expanded to capture many sparse signals, which often is experimentally unfeasible. Averaging max cross-correlation values across forward states would therefore result in high correlations for neurons showing sparse activity. Covariograms, by contrast, take into account the number of peaks detected, thus enabling statistical testing to exclude cases with few peaks from significance. Covariograms were computed as described in ref. (Brody, 1999) with some minor adjustments to account for variations in forward command state duration. For each neuron pair, we first computed raw cross-correlogram counts as follows. We used peaks identified as described in the above section, only during forward command states longer than 50 s. For each peak in the reference neuron (rows in Figures 3C and S2E), all peaks in the target neuron (columns in Figures 3C and S2E) during the same forward command state were considered; in 10 s bins, the time delays of these target neuron peaks relative to the reference peak were accumulated. This procedure was used across all reference peaks within each state, and ultimately to accumulate the full raw cross-correlogram across all forward command states across all recordings. Raw cross-correlogram counts were then converted to frequencies, by dividing by the number of available data for each bin (i.e., the number of possible frames in each bin in which spikes could have occurred, which varies due to differences in trial duration). 106 resampled raw cross-correlograms were computed by randomly selecting the same number of spike times of the target neuron within each forward state and normalizing in the same manner. This resampling procedure accounts for trial-to-trial co-fluctuations in neuronal activity frequencies that may be independent of peak timing relationships but inadvertently cause peaks in the cross-correlogram (Brody, 1999). Covariograms were then computed by subtracting the average resampled raw cross-correlograms (which serves as the ‘‘shuffle corrector’’ or ‘‘shift predictor’’ [Brody, 1999]) from actual raw cross-correlograms. For statistical significance test, see below, section ‘‘Quantification and statistical analysis.’’ Neuronal time series extraction and behavior analysis (freely moving imaging) GCaMP and mCherry signals acquired at 30 Hz were extracted by first tracking the mCherry signal of the nucleus or cell body of interest using Metamorph software (Molecular Devices). Then, using custom MATLAB (Mathworks) scripts, the coordinates of the tracked regions were used to extract the average of the 50 brightest pixels. A background measurement from the first frame per channel per recording was subtracted. The GCaMP/mCherry ratio, henceforth ‘‘R,’’ was then used to calculate an R0 value as the mean of the lowest 10% of ratio values. DR/R0 was then calculated as (R – R0) / R0. For subsequent analyses, peaks were detected using a parameter delta determined by manual inspection. A maximum point must be preceded and followed by a value lower by at least delta, and vice versa, a minimum point must be preceded and followed by a value higher by at least delta. Data were further normalized by the 95th percentile in each recording for Figures 5H and S5F. Reversals were identified manually by examining infrared movies. All other time points were considered as forward states. Custom MATLAB (Mathworks) scripts used a combination of edge detection and gray level thresholding to extract a binary worm image, which were used for subsequent skeletonization as described in (Hums et al., 2016) to quantify 24 angle measurements. Angle measurements were linearly interpolated to match the 30 Hz Ca2+ recording and manually inspected for correct ventral/dorsal assignment. Propagation analysis, head-bend type classification, and cycle period quantification (behavior assays and freely moving imaging) Note that data in Figures 1E, 1F, and S1E–S1G were obtained from Ca2+ imaging recordings, as these recordings were high enough resolution (and contained fluoresecent neuronal markers) to distinguish dorsal and ventral sides, and because head-casts were more prominent in these animals allowing us to quantify head-cast episodes containing more than two head-casts. All other data in these figures were obtained in population behavior assays. Kymograms from either population behavior assays or simultaneous Ca2+ imaging and behavior experiments were smoothed and, in the case of missing data due to poor skeletonization, linearly interpolated to fill gaps < 1 s. All subsequent analyses were performed separately on forward and reverse locomotion periods. For each angle timeseries, local maxima and minima were detected using a parameter delta determined by manual inspection. A maximum point must be preceded and followed by a value lower by at least delta, and vice versa, a minimum point must be preceded and followed by a value higher by at least delta. Each angle timeseries was thereby transformed into an ‘‘angle peak timeseries’’ containing for each frame either a maximum ( = 1), a minimum ( = 1), or neither ( = 0). Note that maxima (minima) can be dorsal (ventral) if the head-bend changes by at least delta but does not cross 0. The resulting matrix of all angle peak timeseries, or ‘‘peak kymogram,’’ (Figure S1A, lower) of the same size as the original kymogram, was analyzed to determine the propagation of each head-bend as follows. Because the first (anterior-most) angle is typically noisier than the others, peaks in the second angle were initially defined as head-bends. Head-bends were then analyzed in temporal order, in the following manner. For each head-bend (angle #2 peak), if the previous (i.e., backward or simultaneous in time) peak in angle #1 is of the same sign as the current head-bend

Neuron 105, 1–15.e1–e9, February 5, 2020 e6

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

(maximum, = 1, or minimum, = 1), and hasn’t been assigned to a previous head-bend, then that peak is assigned to the current head-bend. Similarly, if the next (i.e., forward or simultaneous in time) peak in angle #3 is of the same sign as the current head-bend (maximum, = 1, or minimum, = 1), and hasn’t been assigned to a previous-head-bend, then that peak is assigned to the current head-bend. The next peak in angle #4 is examined with respect to the current peak in angle #3 in the same way; this process is iterated posteriorly until the final angle (see Figure S1A, lower), or until the propagation is terminated as follows. If the next posterior peak is of the opposite sign as the current head-bend, the head-bend is terminated. If the next posterior peak (a) occurs > 10 s following the previous peak and/or (b) occurs following at least two unassigned peaks in the previous (i.e., anterior) angle, then it is likely not part of the current head-bend, so the head-bend propagation is terminated. In both above cases, if the final propagation angle was less than or equal to angle #13, then the head-bend is assigned as a head-cast. If the final propagation angle was angle #14 or greater, then the head-bend is assigned as a propagated-bend. If the animal reverses or if missing data are encountered, the head-bend is terminated as well; in this case, if the final propagation angle is #14 or greater, the head-bend is assigned as a propagated-bend, but if it is less than angle #14, it is ambiguous as to whether the head-bend would have propagated further and is therefore not classified. Head-bends that are not connected to bends in any other angle are also not classified as they are likely due to noise or artifacts in angle measurement. To account for such measurement noise, which may be amplified by peak detection, each head-bend is allowed to propagate backward in time by 0.1 s, and up to 1 s only once per propagation (for example, see Figure S1A, lower, t = 19 s, angle #24). Additionally, two segments per propagation may be skipped if a peak of the correct sign is not detected before the termination condition (for example, see Figure S1A, lower, t = 12 s, angles #22-23). These heuristics enabled the most robust detection of head-bend propagation upon inspection. Note that for the 2nd head-cast of each pair, there is some ambiguity with regard to whether posterior bends, which are of the same sign, should in fact be assigned to the previous propagated-bend as opposed to that head-cast (in which case that head-cast would instead be assigned as a propagated-bend). Our algorithm assigns these ambiguous posterior bends to the earliest possible headbend; for example, see Figure S1A, lower, first head-cast pair. Results from SMD and DB02 neuronal activity imaging during behavior suggest that this procedure meaningfully assigns different head-bend types, because neuronal activity during the earlier head-bend is indistinguishable from other propagated-bends, whereas neuronal activity during the later head-bend is markedly different (Figures 5C and 7E). Reversal states were analyzed the same way, only with kymograms flipped left/right such that bends are quantified as if they propagated head-to-tail, as during forward locomotion, rather than tail-to-head. This allows the classification of bends propagating fully from tail to head as well as bends that start in the neck and propagate toward the head, which for Figure S1J were considered head-casts. Also considered head-casts during reversals for Figure S1J were bends that propagate as head-casts normally do, which were found by analyzing reversal states without flipping left/right. Because head-casts typically occurred in only half-cycles (i.e., two head-casts, one ventral and one dorsal, without a return to the side of the first head-cast), head-cast cycle period in Figure 1D was calculated by doubling head-cast inter-bend intervals (only measured between two consecutive head-casts). For Figure 1D propagated-bend cycle periods were calculated regardless of intervening head-cast interruption; note that a reduction in head-casts caused only a small change in propagated-bend inter-bend intervals (Figure S4D). Note that head-casts were typically posterior to and slower than the 4-5Hz nose-tip movements previously described as ‘‘foraging,’’ (Huang et al., 2008) and were more in line with head movements described in refs. (McCloskey et al., 2017; Skora et al., 2018). Still, in agreement with (Yemini et al., 2013), we believe that previously described foraging movements include head-casts, yet we use a different term to distinguish our definition based on propagation. For Figure 8, propagated-bend cycle periods were calculated by doubling propagated-bend inter-bend intervals. For Figures 8G and 8H, data are taken from 10min post-lights-on. For Figure 5I, head-bend amplitude is the summed amplitudes of segment numbers 2 to 6. Phase quantifications Phases in Figures 1F, 7G, and 7H were quantified by linearly interpolating between detected peaks for each half cycle (a similar procedure was used by (Eliav et al., 2018)). Interpolation enabled a phase calculation that was independent of intervening headcasts or non-alternating SMD oscillations. In Figure 1F, 0 to p was interpolated from dorsal to ventral propagated-bend maxima (peaks in head-bend angle #2) and p to 2p was interpolated from ventral to dorsal propagated-bend maxima, regardless of any intervening head-casts. Ventral and dorsal head-casts were defined as head-casts following ventral or dorsal propagated-bends, respectively; each head-cast type was therefore restricted to a half cycle. Only the first head-cast following a propagated-bend was used to generate the histograms in Figure 1F. In Figures 7G and 7H, 0 to p was interpolated from the first SMDD peak following an SMDV peak (i.e., SMDD alternating peak) to the first SMDV peak following an SMDD peak, regardless of any intervening SMDD peaks. Similarly, p to 2p was interpolated from the first SMDV peak following an SMDD peak to the first SMDD peak following an SMDV peak, regardless of any intervening SMDV peaks. Because of this definition, SMDD-only and SMDV-only oscillations were each restricted to half cycles. To best compare to Figure 1F, we used the first trough (i.e., minimum, see Figure 7E, t = 0 s) of each SMDD-only or SMDV-only oscillation to generate the histograms, as these corresponded to the first head-cast following a propagated-bend.

e7 Neuron 105, 1–15.e1–e9, February 5, 2020

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Phases in Figure 5D–5G were calculated using the Hilbert transform of head-bend angle #4, smoothed, to remove head-cast signals. The Hilbert transform was applied individually to each period of forward or reverse locomotion, and border data were removed as these were often partial cycles. To quantify the proportion of cycles that contained neural activity peaks, individual cycles were segmented from 0 to 2p (SMDV) or from p to p (SMDD and DB02) so that the typical peak timing for each neuron was centered and was therefore unlikely to fall into a neighboring cycle due to noise. Only cycles without missing data in both angle and neural activity were considered. QUANTIFICATION AND STATISTICAL ANALYSIS Quantifications were performed using custom MATLAB (Mathworks) scripts. Standard statistical tests were performed using Graphpad Prism 7. These tests, along with the value of n and what n represents, are reported in the figure legends. Additional tests are described in detail in the following sections. Reconstruction quality for neuronal subsets (pan-neuronal imaging) To assess how well interneuron and motor neuron activity was captured in the top PC dimensions (Figure 2E; only identified neurons used), we calculated for each neuron the Pearson’s linear correlation coefficient between the original data (activity traces and their derivatives) and reconstructed traces after PCA. These reconstructed traces were obtained by matrix multiplication of the PC coefficients with the PC loadings of the top (i = 1 to 5) PCs and addition of the mean of the original data, as follows: Datarecon = ½PCCoeff 1 : PCCoeff i  3 ½PCLoad1 : PCLoadi  + meanðOrigDataÞ: We used the average correlation coefficient for all the traces of a neuronal cell type (inter neurons, motor neurons or other neurons) in a recording as a measure of how similar reconstructed traces are to their original counterparts. This measure, in contrast to meansquare-error, is insensitive to the magnitude of neuronal activity traces. Peak frequency quantification (pan-neuronal imaging) For all neurons that were identified in at least three recordings, we tested whether the inter-peak interval distribution between such peaks, across all such forward command states, was significantly different from random, as follows. For each forward command state, we randomly selected the same number of spike times to accumulate a random inter-peak interval distribution. This procedure was repeated 106 times to obtain an average random distribution. To measure the magnitude of deviation from random, we summed the absolute difference, bin-by-bin, between the average random distribution and the actual inter-peak interval distribution. This measure was also determined for each of the 106 resampled distributions, and the p value reported in Table S2 is the fraction of resampled distributions with at least as large of a deviation from random as the actual distribution. To correct for multiple comparisons, statistical significance was determined by the Benjamini-Hochberg-Yekutieli procedure (Benjamini and Yekutieli, 2001). Cross-correlation analysis (pan-neuronal imaging) Statistical significance was evaluated by comparing the actual and resampled covariograms as follows. First, the covariogram was assigned a positive or negative relationship, depending on whether the absolute value of the maximum or the minimum value of the covariogram was larger (across all time bins); negative relationships found in this manner are marked with ‘‘(-)’’ in Figure 3C. Then, each of the 106 resampled distributions were analyzed to determine the probability of finding correlations with absolute values as large as either the maximum (for previously determined positive relationships) or minimum (for negative relationships) value observed in the actual covariogram. The p value reported in Table S3 is the fraction of maxima or minima that are at least as large in absolute value as that obtained from the actual distribution. To correct for multiple comparisons across all neuron pairs, statistical significance was determined by the Benjamini-Hochberg-Yekutieli procedure (Benjamini and Yekutieli, 2001) Polar histogram statistics We tested the significance of the distributions in Figures 1F, 5D–5G, 7G, and 7H using resampling. We determined the probability of obtaining a distribution as skewed as the real one by chance. For each half-cycle (Figures 1F, 7G, and 7H) or full cycle (Figures 5D–5G) from which the real data had been extracted, we randomly selected one phase, to generate a random distribution of phases of the same number as the real distribution. Because peaks were detected using a parameter delta for Figures 1F, 7G, and 7H, we restricted the time points that could be selected to those where peaks could possibly have been found (i.e., those at least delta away from the previous peak). We binned the data in the same manner as the real data and quantified the absolute difference, bin-by-bin, between the resampled distribution and the all-phases distribution, which was calculated using the same phases from which the random data was selected. These bin-by-bin absolute differences were summed to give a total difference between the resampled data and the allphases distribution as a measure of sample distribution skewness. This procedure was repeated 106 times and the skewness of the real distribution was measured the same way. The p value is the fraction of randomly sampled distributions that were at least as skewed as the actual distribution.

Neuron 105, 1–15.e1–e9, February 5, 2020 e8

Please cite this article in press as: Kaplan et al., Nested Neuronal Dynamics Orchestrate a Behavioral Hierarchy across Timescales, Neuron (2019), https://doi.org/10.1016/j.neuron.2019.10.037

Significance between forward (Figure 5F) and reverse (Figure 5G) SMD peak distributions were determined by resampling independently for each SMD. The reverse distribution contained fewer peaks than the forward distribution, so we randomly selected, from the forward distribution, 106 samples of the same size as the reverse distribution. We binned the data in the same manner as the real data and quantified, bin-by-bin, the absolute difference between the resampled and real forward distribution. These bin-by-bin absolute differences were summed to give a total difference. The same procedure was done to measure the difference between the forward and reversal distributions, and the p value is the fraction of randomly sampled forward distributions that differed from the actual forward distribution at least as much as the reversal distribution did. DATA AND CODE AVAILABILITY Data and custom code generated in this study are available from the Lead Contact without restriction.

e9 Neuron 105, 1–15.e1–e9, February 5, 2020