ARTICLES Optogenetic manipulation of neural activity in freely moving Caenorhabditis elegans Andrew M Leifer1'4, Christopher Fang-Yen1'2'4, Marc Gershow1, Mark J Alkema3 & Aravinthan D T Samuel1 We present an optogenetic illumination system capable of realtime light delivery with high spatial resolution to specified targets in freely moving Caenorhabditis elegans. A tracking microscope records the motion of an unrestrained worm expressing channelrhodopsin-2 or halorhodopsin in specific cell types. Image processing software analyzes the worm's position in each video frame, rapidly estimates the locations of targeted cells and instructs a digital micromirror device to illuminate targeted cells with laser light of the appropriate wavelengths to stimulate or inhibit activity. Because each cell in an unrestrained worm is a rapidly moving target, our system operates at high speed (~50 frames per second) to provide high spatial resolution (~30 (j.m). To test the accuracy, flexibility and utility of our system, we performed optogenetic analyses of the worm motor circuit, egg-laying circuit and mechanosensory circuits that have not been possible with previous methods. Researchers in systems neuroscience aim to understand how neural dynamics create behavior. Cytogenetics has accelerated progress in this area by making it possible to stimulate or inhibit neurons that express light-activated proteins, for example, channelrhodopsin-2 (ChR2) and halorhodopsin (also known as Halo/NpHR), by illuminating them1-7. The nematode C. elegans is particularly amenable to optogenetics owing to its optical transparency, compact nervous system and ease of genetic manipulation8-11. The ability to deliver light to one cell with spatial selectivity is essential for targeted optogenetic perturbation in the many cases in C. elegans in which genetic methods do not provide adequate specificity. In the worm motor circuit, for example, single neuron-specific promoters are not available to drive expression of light-activated proteins in only one or a few neurons of the ventral nerve cord (VNC). Optogenetics has been applied to the mechanosensory circuit in C. elegans, but only through simultaneous stimulation of all touch receptor neurons, because promoters specific to each neuron are unavailable1. Researchers can use laser killing to study the contribution of single touch receptor neurons to overall behavior by removing neurons, but it is often preferable to work with intact circuits12-14. Recently, a digital micro-mirror device (DMD) has been used to deliver light with high spatial selectivity in immobilized C. elegans10 and immobilized Danio rerio zebrafish15; each element of a DMD may be independently controlled to deliver light to a corresponding pixel of a microscope's field of view. In many cases, however, the normal operation of neural circuits can be studied only in freely behaving animals, requiring a more sophisticated instrument. Here we describe an optogenetic illumination system that allows perturbations of neural activity with high spatial and temporal resolution in an unrestrained worm, enabling us to control locomotion and behavior in real time (Colbert) in C. elegans. In the Colbert system, a video camera follows a worm under dark-field illumination, and a motorized stage keeps the worm centered in the camera's field of view. Machine-vision algorithms estimate the coordinates of targeted cells within the worm body and generate an illumination pattern that is projected onto the worm by a DMD with laser light, and the cycle repeats itself for the next frame. Because the worm is a moving target, the faster an image can be captured and translated into DMD directives, the more accurately an individual cell can be targeted. The Colbert system carries out all of these functions in -20 ms, providing a spatial resolution of-30 jam in optogenetic control for freely swimming C. elegans. We analyzed the motor circuit and mechanosensory circuit of unrestrained worms, demonstrating the performance of the Colbert system, a new tool that enhances the flexibility and power of optogenetic approaches in C. elegans. RESULTS Experimental setup To stimulate neurons using ChR2 or inhibit neurons using Halo/ NpHR, we used a 473-nm or 532-nm wavelength diode-pumped solid state (DPSS) laser, respectively (Fig. la). Either laser was incident onto a DMD with 1,024 x 768 elements. Laser light was reflected onto the specimen only when an individual micromirror was turned to the 'on' position. We illuminated the specimen under dark-field illumination by red light to avoid exciting ChR2 or Halo/NpHR. Filter cubes reflected the wavelengths for optogenetic illumination from the DMD onto the sample, while passing longer wavelengths for dark-field illumination to a camera. A motorized stage kept the specimen in the field of view. department of Physics and Center for Brain Science, Harvard University, Cambridge, Massachusetts, USA. 2Department of Bioengineering, University of Pennsylvania, Philadelphia, Pennsylvania, USA. 3Department of Neurobiology, University of Massachusetts Medical School, Worcester, Massachusetts, USA. 4These authors contributed equally to this work. Correspondence should be addressed to C.F.-Y. (fangyen@seas.upenn.edu) or A.S. (samuel@physics.harvard.edu). RECEIVED 23 AUGUST 2010; ACCEPTED 16 DECEMBER 2010; PUBLISHED ONLINE 16 JANUARY 2011; D0I:10.1038/NMETH.1554 NATURE METHODS | VOL.8 N0.2 | FEBRUARY 2011 | 147 ARTICLES ■u ID > U t/> S> w Ü c «5 o E < 3 (0 o CM © m Die mir iroic +4 or 1 Laser 532 nm or 473 ran Acquire image Figure 1 | High-resolution optogenetic control of freely moving C. etegans. (a) An individual worm swims or crawls on a motorized stage under red dark-field illumination. A highspeed camera images the worm. Custom software instructs a DMD to reflect laser light onto targeted cells, (b) Images are acquired and processed at -50 FPS. Each 1,024 x 768 pixel image is thresholded and the worm boundary is found. Head and tail are located as maxima of boundary curvature (red arrows). Centerline is calculated from the midpoint of Line segments connecting dorsal and ventral boundaries (blue bar) and is resampled to contain 100 equally spaced points. The worm is partitioned into segments by finding vectors (green arrows) from centerline to boundary, and selecting one that is most perpendicular to the centerline (orange arrow). Targets defined in worm coordinates are transformed into image coordinates and sent to the DMD for illumination (green bar), (c) Schematic of body-wall muscles. Anterior, to left; dorsal, to top. Bending wave speed of swimming worm expressing Halo/NpHR in its body-wall muscles subjected to green Light (10 mW mm-2) outside or inside the worm boundary (n = 5 worms, representative trace), (d) Schematic of HSN. A swimming worm expressing ChR2 in HSN was subjected to blue Light (5 mW mm-2). Histogram, position at which egg-Laying occurred when a narrow stripe of Light was slowly scanned along the worm's centerline (n = 13 worms). Once an egg was Laid, the worm was discarded. To accelerate real-time image analysis of worm posture, we developed the MindControl software package using the open-source OpenCV computer vision library16. With the graphical user interface (GUI), the user can dynamically target specific regions of freely moving worms. The MindControl software and documentation are available as Supplementary Software. The MindControl software carries out a sequence of image analysis operations on each frame received from the camera (Fig. lb). An image is captured by the computer, filtered and thresholded. Next, the boundary of the worm is calculated, and head and tail x-y motorized stage Custom computer vision software 5 Identify head, tail, boundary and centerline Define coordinate Illuminate system selected target 5 Body-wall muscle cells C I Illumination ' outside boundary I Illumination inside boundary 10 12 14 Time (s) 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fractional distance along centerline (head = 0; tail = 1) Bending dynamics at 0.10 along centerline are identified as local maxima of boundary curvature (the head is blunt and the tail is sharp). The worm centerline is calculated and the body is divided into 100 evenly spaced segments. These segments define a worm coordinate system invariant to worm posture or orientation, within which the user may define target positions. The software maps the position of targets onto the coordinates of the real image and finally sends the appropriate pattern to the DMD for illumination. For our current system, the total latency between image acquisition and DMD illumination is 20 ms: image exposure, 2 ms; data transfer to computer, 3 ms; image analysis, 10 ms; and data transfer to DMD, 5 ms. Given the size and speed of a swimming worm at lOx magnification, our system working at -50 frames per second (FPS) 0.25 0.50 0.75 1 I distance along centerline (head - 0; tail - 1 Normalized curvature Bending dynamics at 0.75 along centerline +5 +2.5 -2.5 0 2 4 Time (s) Figure 2 | Optogenetic inactivation of muscle cells, (a) Kymograph of time-varying body curvature along the centerline of a Pmyo3 ::Hato/NpHR::CFP transgenic worm. Between 0 s and 4 s, the worm was stimulated with green Light (10 mW mm-2) in a region spanning the worm diameter and between 0.38 and 0.6 of the fractional distance along the centerline. (b) For the kymograph in a, time-varying curvature at two points along the worm centerline, both anterior (top) and posterior (bottom) to the illuminated region. 148 | VOL.8 N0.2 | FEBRUARY 2011 | NATURE METHODS ARTICLES ■o ID > Q) t/> o c «5 o E < 3 AS o CM © 0 Fractional Figure 3 | Inhibition of motor neurons, (a) Schematic of cholinergic DB and VB motor neurons. Anterior, to Left; dorsal, to top. Kymograph of time-varying body curvature along the centerline of a Punc-17::Hato/ NpHR::CFP transgenic worm illuminated by a stripe of green light (10 mW mm-2) along its VNC between t = 0 s and 1.6 s. In the dorsal-ventral direction, the stripe width was equal to 50% of the worm diameter and centered on the ventral boundary. In the anterior-posterior direction, the stripe length was between 0.14 and 0.28 of the fractional distance along the body, (b) For the kymograph in a, time-varying curvature at two points along the worm centerline, both anterior (top) and posterior (bottom) to the illuminated region, (c) Video sequence of worm illuminated by a long stripe of green light (10 mW mm-2) spanning the VNC between t = 0 s and 1.8 s. Scale bar, ~100 |j,m. (d) Bending wave speed of a swimming worm illuminated by a long stripe of green light (10 mW mm-2) lasting 1.8 s and spanning the VNC (top) and dorsal nerve cord (bottom). delivers optogenetic illumination with a spatial resolution of -30 jam, not far from the spatial resolution limit imposed by the pixel density of the DMD (~5 jam at lOx magnification). Spatial resolution of the illumination system First, we confirmed that illumination is restricted to the targeted area. We examined a transgenic worm expressing Halo/NpHR '■ '■ CFP in all body-wall muscles. Whole-animal illumination of transgenic Pmyo-3 ::Halo/NpHR worms causes all muscles to relax6. We placed individual swimming worms in the Colbert system and used green light (532 nm, 10 mW mnr2) to alternately illuminate the entire region outside and inside the worm boundary (Fig. lc and Supplementary Video 1). Illuminating the entire region outside the worm boundary had no effect as bending waves propagated from head to tail at normal speed. Illuminating the entire region inside the worm boundary, however, arrested locomotion as the body relaxed and the speed of bending waves dropped to zero. To quantify the spatial resolution of the Colbert system, we measured its targeting accuracy in evoking egg-laying events by stimulating the HSN motor neurons. We used transgenic worms expressing ChR2 under the egl-6 promoter, which drives expression in the bilaterally symmetric HSN neurons (HSNL and HSNR) as well as glia-like cells in the worm's head17. Optogenetic stimulation of the HSN neurons, which innervate the vulval musculature, evokes egg-laying behavior (L. Emtage and N. Ringstad, personal communication). The two HSN neurons lie on top of one another when the worm is viewed laterally, so our system targets both neurons. We projected a thin stripe of blue light (473 nm, 5 mW mnr2) on the body of swimming P'egl-6 '■ '■ ChR2 transgenic worms. The long axis of the stripe was orthogonal to the worm centerline and spanned its diameter. The stripe width corresponded to 2% of the anterior-posterior length of the worm centerline (that is, -20 jam of the ~l-mm-long young adult worm). We used narrow stripes • DB motor neurons • VB motor neurons 2 +10 Bending dynamics at 0.10 along centerline Time (s) Bending dynamics at 0.75 along centerline 0.25 0.50 0.75 1 distance along centerline (head = 0; tail = 1) Normalized curvature a +20 re |+10 -o 0 N s -10 E o -20 0.5 cn 0.4 Q. C 0.3 0.2 IG 0.1 5 T3 O n 0 -3-2-101234 Time (s) Dorsal cord illumination -4 -3 -2 -1 0 1 2 3 4 5 6 Time (s) so that our illumination would be less probable to stimulate HSN when illuminating its process. We slowly moved the illumination stripe along the centerline of swimming worms while recording egg-laying events. Of 14 worms studied, we observed 13 egg-laying events, eight in which the stripe started at the head and five in which the stripe started at the tail. Egg-laying frequency sharply peaked when the center of the stripe coincided with the centerline coordinate of the HSN cell bodies, or 49.6% of the total distance from the anterior to the posterior of the body with 3.2% s.d. (Fig. Id and Supplementary Video 2). The width of this distribution suggests that the Colbert system provides at least -30 jam of spatial resolution. Optogenetic manipulation of muscle cells In C. elegans, forward movement is driven by motor neurons in the VNC, which coordinate the activity of 95 body wall muscle cells along the dorsal and ventral sides of the VNC 18. The circuit for worm locomotion is poorly understood in comparison to that of other undulatory animals such as the leech and lamprey19-21. Because this circuit probably operates normally only during normal movement, technology such as the Colbert system is necessary to dissect cellular activity in unrestrained animals . We used the Colbert system to suppress muscle activity in a region of the body in myo-3 '■ '■ Halo/NpHR '■ '■ CFP transgenic worms (Fig. 2 and Supplementary Video 3). This perturbation of undulatory dynamics can be shown graphically using a red-blue color map to represent the curvature of the body centerline in nondimensional units (that is, the curvature calculated at each point along the centerline, K, multiplied by worm length, L) as a function of time and fractional distance along the centerline, NATURE METHODS | VOL.8 N0.2 | FEBRUARY 2011 | 149 ARTICLES Figure 4 | Cytogenetic analysis of mechanosensory neurons, (a) Top, schematic of anterior and posterior touch receptor cells. Anterior, to left; dorsal, to top. Kymographs (left) of time-varying curvature of centerline of worms expressing ChR2 in mechanosensory neurons (Pmec-4 ::ChR2::GFP) subjected to rectangles of blue light (5 mW mm-2) targeting different groups of touch receptor neurons. Plots of bending wave speed (right) indicate stimulus-evoked changes in direction or speed. AVM and ALM neurons are subjected to 1.5 s of stimulation. Given a coordinate system where x specifies dorsal-ventral location (-1, dorsal boundary; 0, centerline; 1, ventral boundary) andy defines fractional distance along the worm's centerline (0, head; 1, tail), the rectangle of illumination has corners (x,y) = ((-1.1,0),(1.1,0.46)). (b) PVM and PLM neurons are subjected to 2.5 s of stimulation with a rectangular illumination (n = 5 worms, representative trace) with corners at (x,y) = ((-1.1,0.62),(1.1,0.99)). (c) ALM cell body is specifically stimulated by illuminating a small rectangle with corners at (x,y) = ((-0.3,0.38), (-0.9,0.46)). (d) AVM cell body is specifically stimulated by illuminating a small rectangle with corners at (x,y) = ((0.3,0.3),(0.9,0.38)). s, from head (s = 0) to tail (5=1) (Fig. 2a). Notably, hyperpolarizing muscle cells in one segment had no effect on undulatory dynamics anterior to the segment, but lowered the amplitude of the bending wave posterior to the illuminated segment (Fig. 2b). Representative data from one of five worms that we studied are shown in Figure 2. Thus, the bending of posterior body segments seems coupled to the bending of anterior body segments. One possibility is that muscle activity in posterior segments is directly promoted by muscle activity in anterior segments, perhaps by gap junction coupling between muscle cells22. Another possibility is that the motor circuit contains a proprioceptive mechanism that makes the activity of posterior segments directly sensitive to the bending of anterior segments. Cytogenetic manipulation of cholinergic motor neurons The cell bodies of motor neurons in C. elegans are distributed along the VNC13'18. Ventral muscles are innervated by the cholinergic VA, VB and VC motor neurons and GABAergic VD motor neurons. Dorsal muscles are innervated by the cholinergic DA, DB and AS motor neurons and GABAergic DD motor neurons23'24. A current model is that VA and DA drive muscle contraction during backward locomotion, VB and DB drive muscle contraction during forward locomotion and VD and DD motor neurons drive muscle relaxation during both forward and backward locomotion13'18'25. A repeating motif of synaptic connectivity between the motor neurons runs along the worm body and allows for contralateral inhibition18. During forward locomotion, for example, the DB (or VB) motor neurons can simultaneously excite a dorsal (or ventral) muscle cell while exciting the GABAergic VD (or DD) motor neurons that inhibit the opposing ventral • Posterior touch receptors • Anterior touch receptors +0 +0.4 +0.2 0 -0.2 -0.4 -0 -0.8 0 1 Time (s) i I +0 +0.5 +0.4 +0.3 +0.2 +0.1 0 -0.1 1 2 Time (s) +0.5 +0.4 +0.3 +0.2 +0.1 0 -0.1 -0.2 -0.3 -0.4 0 1 2 Time (s) 0.25 0.50 0.75 Fractional distance along centerline (head -Normalized curvature +10 5 0 -5 -11 0 1 Time (s) (or dorsal) muscle cell23'24. However, how this network drives the rhythmic undulatory wave is poorly understood. We analyzed the contributions of cholinergic neurons to forward locomotion using transgenic worms expressing Halo/NpHR in all cholinergic neurons under the control of the unc-17 promoter26. In Punc-17 '■ '■ Halo/NpHR '■ '■ CFP transgenic worms, illumination of a short segment of the VNC suppressed propagation of the undulatory wave to the entire region posterior to the illuminated segment without affecting the undulatory wave anterior to the illuminated segment (Fig. 3a,b and Supplementary Video 4). Representative data from one of five worms that we studied are shown in Figure 3a,b. This suggests that the activity of posterior VB and DB neurons is coupled to the activity of anterior VB and DB neurons, consistent with a wave of neuronal excitation that propagates from head to tail during forward movement. Using the Colbert system, we can also specifically illuminate either the dorsal nerve cord or the VNC (Supplementary Video 5). The VNC contains the cell bodies of the cholinergic motor neurons, whereas the dorsal nerve cord contains only nerve processes. Illuminating the entire VNC was particularly effective in hyperpolarizing the cholinergic motor neurons of Punc-17'■'■Halo/ NpHR '-'CFP worms, inducing paralysis. Illuminating the entire dorsal nerve cord, however, produced only a small (-15%) drop in the speed of wave propagation (Fig. 3c,d). The asymmetric effect 150 | VOL.8 N0.2 | FEBRUARY 2011 | NATURE METHODS ARTICLES ■u ID > U t/> U ü c «5 o E < 3 (0 o CM © Figure 5 | Habituation of individual touch receptor neuronal types. (a,b) Schematic showing anterior and posterior touch receptor neurons (top). Anterior, to left; dorsal, to top. A freely swimming worm expressing Kaede in touch receptor neurons was continuously tracked and illuminated with a small rectangle of 405-nm light (2 mW mm-2) centered on either AVM or ALM (as in Fig. 4c,d) for 60 s. Red and green fluorescence images are shown. Scale bars, 100 |a.m. (c-e) Individual ALM and AVM neurons were repeatedly stimulated with blue light (5 mW mm-2) for 1.5 s every 60 s for ~40 min, either alone (c,d) or interleaved within each experiment (e; ALM, 30 s; AVM, 30 s; ALM, 30 s; and so on). Fractional response to stimulus of each neuronal type was fit to an exponential, a + b exp(-t/f), using maximum likelihood estimator. Time constant for habituation, T, was extracted from each fit. Error bars, s.e.m. Fractional response of ALM when stimulated alone (c; n = 7 worms). Fractional response of AVM when stimulated alone (d; n = 8 worms). Fractional response of ALM (left) and AVM (right) during interleaved stimulation of both (e; n = 7 worms). <5 • Posterior touch receptors • Anterior touch receptors avmT_ I PVM»"Pll/r ALM stimulation every 60 s AVM stimulation every 60 s After AVM irradiation Red AVM _ Green PLM PVM AV_M ALM 10 20 30 Time (min) 10 20 30 Time (min) b After ALM irradiation Red ALMR _ ALML Interleaved AVM and ALM stimulation Green AVM ALMR ALML 10 20 30 Time (min) 10 20 30 Time (min) of illuminating the ventral and dorsal nerve cords is probably due to the higher density of optogenetic protein in the cell bodies. To our surprise, the paralysis evoked by illuminating the VNC can occur without allowing relaxation of the worm body. In this instance, as long as the entire cholinergic network within the VNC was deactivated, the worm retained the posture it had immediately before illumination (Fig. 3c). When the muscle cells of a swimming worm were hyperpolarized, on the other hand, the body straightened (Supplementary Video 1). This observation suggests that muscle cells can remain in contracted or relaxed states without requiring continuous cholinergic input. Optogenetic manipulation of single touch receptor types Next, we applied the Colbert system to the touch receptor system in C. elegans. Six cells are specialized for sensing gentle touch in C. elegans: the left and right anterior lateral microtubule cells (ALML and ALMR, respectively); the left and right posterior lateral microtubule cells (PLML and PLMR, respectively); the anterior ventral microtubule cell (AVM); and the posterior ventral microtubule cell (PVM)13. Gently touching the worm near its anterior stimulates reversal movement dependent on ALML, ALMR and AVM. Gently touching the worm near its posterior stimulates forward movement dependent on PLML and PLMR. The role of PVM remains unclear. Channelrhodopsin can be expressed in all six touch receptor cells using the mec-4 promoter. Illuminating the whole body of transgenic worms with blue light evokes reversal responses, presumably by simultaneously activating ALM, AVM and PLM1. With the spatial resolution afforded by the Colbert system, we could individually activate the ALM, AVM and PLM cell types. The left and right lateral cells (ALML and ALMR; PLML and PLMR) lie on top of one another when the worm is viewed laterally. Illuminating the anterior end containing both the AVM and ALM neurons triggered reverse movement (Fig. 4a and Supplementary Video 6). Illuminating the posterior end containing the PLM neurons triggered forward movement (Fig. 4b and Supplementary Video 7). Representative data from one of five worms that we studied are shown in Figure 4a,b. Using the Colbert system, we could also induce reversals by targeting just AVM or ALM with an illumination box (20 jam in the dorsal-ventral dimension; 30 jam in the anterior-posterior direction for a young adult worm) that was centered on each cell body (Fig. 4c,d and Supplementary Videos 8 and 9). Representative data from one of fourteen worms that we studied are shown in Figure 4c,d. Using these illumination boxes, we could avoid illuminating the axon of the nontargeted neuron. These observations are consistent with earlier work showing that single touch receptor types are sufficient to drive behavioral responses27. To confirm that the Colbert system can specifically target either AVM or ALM, we used transgenic worms expressing the photo-convertible fluorescent protein Kaede in the mechanosensory neurons28. Upon illumination by UV or violet light, Kaede converts from a green to a red fluorescent state. We used the Colbert system with 405-nm light to specifically illuminate either the AVM or ALM cell bodies for 60 s in freely moving mec-4 Kaede worms. We found that worms in which AVM or ALM had been targeted showed only detectable red fluorescence in AVM or ALM, respectively, whereas all mechanosensory neurons showed green fluorescence (Fig. 5a,b). When targeting ALM, a transient segmentation error owing to an omega turn by the worm caused the system to illuminate PLM and PVM for ~1 s, producing slight photoconversion in those neurons (Fig. 5b). By quantifying the ratio between the red and green fluorescence signals, we estimated that the nontargeted neurons were illuminated for less than ~1 s (Online Methods). It has been shown that the mechanosensory circuit habituates to repetitive optogenetic stimulation1. We used the Colbert system to quantify the rate of AVM and ALM habituation over 40 min by repeatedly stimulating either AVM or ALM every 60 s. We observed comparable rates of habituation for both ALM NATURE METHODS | VOL.8 N0.2 | FEBRUARY 2011 | 151 ARTICLES and AVM (Fig. 5c,d). Others have studied loci for habituation in the mechanosensory circuit by laser-killing touch receptor cells and/or downstream neurons and quantifying rates of habituation to gentle touch15. If habituation partly occurs at interneurons that are downstream of both ALM and AVM, then we might expect cross-habituation of the AVM response to repeated ALM stimulation, and vice-versa. Cross-habituation may also be mediated by electrical gap junction between AVM and ALM23. To test whether cross-habituation occurs, we subjected a worm to interleaved AVM and ALM stimulation every 30 s, such that each neuron type was stimulated every 60 s. We found that the rates of habituation to both AVM and ALM stimulation were indeed more rapid with interleaved stimulation than with individual stimulation. This effect was particularly marked in the case of AVM stimulation (Fig. 5e). DISCUSSION At present, the spatial resolution of Colbert is -30 jam when tracking a swimming worm. The system has better resolution when tracking the slower movements of a crawling worm but is ultimately limited to ~5-u,m resolution owing to the pixel resolution of the DMD. In principle, higher spatial resolution could be reached by tracking a specific region of the worm (for example, the nerve ring) at higher magnification. This modification to Colbert would require a different approach to image analysis and targeting, for example, analysis of cell body fluorescence instead of analysis of the posture of the whole worm. Colbert may be adapted to the optogenetic analysis of other genetically tractable, transparent animals such as the Drosophila melanogaster or D. rerio larvae. A simplified version of Colbert may also be used to facilitate optogenetic illumination in other settings, for example, studies of mammalian brain slices or exposed brain surfaces. Variants of Colbert using its capacity for rapid closed-loop feedback may be used to trigger optogenetic stimulation based on simultaneous recordings of neural activity in addition to animal posture. Colbert is a flexible and easy-to-use platform for designing and projecting arbitrary spatiotemporal patterns of illumination with closed-loop sensitivity to the real-time behavior of the worm. METHODS Methods and any associated references are available in the online version of the paper at http://www.nature.com/naturemethods/. Note: Supplementary information is available on the Nature Methods website. ACKNOWLEDGMENTS This work was supported by the Dana Foundation, US National Science Foundation and a US National Insitutes of Health Pioneer Award to A.D.T.S. A.M.L is supported by a National Science Foundation Graduate Research fellowship. We thank M. Zhen (Samuel tunenfeld Institute), N. Ringstad (Skirball Institute of Biomolecular Medicine, New York University School of Medicine), A. Gottschalk (Frankfurt Molecular Life Sciences Institute) and B. Neumann and M. Hilliard (Queensland Brain Institute, University of Queens) for gifts of transgenic strains; J. Stirman for sharing unpublished results about a similar system that he developed; B. Chow and T. Lindsay for useful discussions; and A. Tang and B. Schwartz for assistance with data analysis. AUTHOR CONTRIBUTIONS C.F.-Y. and A.M.L. designed the hardware setup; A.M.L. wrote the software, with supervision from M.G.; A.M.L., C.F.-Y., M.J.A. and A.D.T.S. designed experiments; A.M.L. carried out experiments; A.M.L. and C.F.-Y. analyzed data with advice from M.G.; A.M.L., C.F.-Y. and A.D.T.S. wrote the manuscript. COMPETING FINANCIAL INTERESTS The authors declare no competing financial interests. Published online at http://www.nature.com/naturemethods/. Reprints and permissions information is available online at http://npg.nature. com/reprintsandpermissions/. 1. Nagel, G. et al. Channelrhodopsin-2, a directly light-gated cation-selective membrane channel. Proc. Natl. Acad. Sci. USA 100, 13940-13945 (2003). 2. Boyden, E.S, Zhang, F. Bamberg, E., Nagel, G. & Deisseroth, K. Millisecond-timescale, genetically targeted optical control of neural activity. Nat. Neurosci. 8, 1263-1268 (2005). 3. Zhang, F., Wang, L., Boyden, E.S. & Deisseroth, K. Channelrhodopsin-2 and optical control of excitable cells. Nat. Methods 3, 785-792 (2006). 4. Han, X. & Boyden, E.S. Multiple-color optical activation, silencing, and desynchronization of neural activity, with single-spike temporal resolution. PLoS ONE 3, e299 (2007). 5. Szobota, S. et al. Remote control of neuronal activity with a light-gated glutamate receptor. Neuron 54, 535-545 (2007). 6. Zhang, F. et al. Multimodal fast optical interrogation of neural circuitry. Nature 446, 633-639 (2007). 7. Chow, B.Y. et al. High-performance genetically targetable optical neural silencing by light-driven proton pumps. Nature 463, 98-102 (2010). 8. Nagel, G. et al. Light activation of channelrhodopsin-2 in excitable cells of Caenorhabditis elegans triggers rapid behavioral responses. Curr. Biol. 15, 2279-2284 (2005). 9. Liewald, J.F. et al. Optogenetic analysis of synaptic function. Nat. Methods 5, 895-902 (2008). 10. Guo, Z.V., Hart, A.C. & Ramanathan, S. Optical interrogation of neural circuits in Caenorhabditis elegans. Nat. Methods 6, 891-896 (2009). 11. Stirman, J.N., Brauner, M., Gottschalk, A. & Lu, H. High-throughput study of synaptic transmission at the neuromuscular junction enabled by optogenetics and microfLuidics. J. Neurosci. Methods 191, 90-93 (2010). 12. Chalfie, M. et al. The neural circuit for touch sensitivity in Caenorhabditis elegans. J. Neurosci. 5, 956-964 (1985). 13. Wicks, S.R., Roehrig, C.J. & Rankin, C.H. A dynamic network simulation of the nematode tap withdrawal circuit: predictions concerning synaptic function using behavioral criteria. J. Neurosci. 16, 4017-4031 (1996). 14. Kitamura, K., Amano, S. & Hosono, R. Contribution of neurons to habituation to mechanical stimulation in Caenorhabditis elegans. J. Neurobiol. 46, 28-40 (2001). 15. Wyart, C. et al. Optogenetic dissection of a behavioural module in the vertebrate spinal cord. Nature 461, 407-410 (2009). 16. Bradski, G. The Open CV Library. Dr. Dobb's Journal of Software Tools 120-126 November (2000). 17. Ringstad, N. & Horvitz, H.R. FMRFamide neuropeptides and acetylcholine synergistically inhibit egg-laying by C. elegans. Nat. Neurosci. 325, 1168-1176 (2008). 18. Von Stetina, S.E., Treinin, M. & Miller, D.M. The motor circuit. Int. Rev. Neurobiol. 69, 125-167 (2006). 19. Marder, E. & Calabrese, R.L. Principles of rhythmic motor pattern generation. Physiol. Rev. 76, 687-717 (1996). 20. Bryden, J. & Cohen, N. Neural control of Caenorhabditis elegans forward locomotion: the role of sensory feedback. Biol. Cybem. 98, 339-351 (2008). 21. Karbowski, J., Schindelman, G., Cronin, C.J., Seah, A. & Sternberg, P.W Systems level circuit model of C. elegans undulatory locomotion: mathematical modeling and molecular genetics. J. Comput. Neurosci. 24, 253-276 (2008). 22. Liu, Q., Chen, B., Gaier, E., Joshi, J. & Wang, Z.W. Low conductance gap junctions mediate specific electrical coupling in body-wall muscle cells of Caenorhabditis elegans. J. Biol. Chem. 281, 7881-7889 (2006). 23. White, J., Southgate, E., Thomson, J.N. & Brenner, S. The structure of the ventral nerve cord of Caenorhabditis elegans. Phil. Trans. R. Soc. Land. B 275, 327-348 (1976). 24. Chen, B.L., Hall, D.H. & Chklovskii, D.B. Wiring optimization can relate neuronal structure and function. Proc. Natl. Acad. Sci. USA 103, 4723-4728 (2006). 25. Haspel, G., 0'Donovan, M.J. & Hart, A.C. Motoneurons dedicated to either forward or backward locomotion in the nematode Caenorhabditis elegans. J. Neurosci. 30, 11151-11156 (2010). 26. Roghani, A. et al. Molecular cloning of a putative vesicular transporter for acetylcholine. Proc. Natl. Acad. Sci. USA 91, 10620-10624 (1994). 27. Chalfie, M. & Sulston, J. Developmental genetics of the mechanosensory neurons of Caenorhabditis elegans. Dev. Biol. 82, 358-370 (1981). 28. Ando, R., Hama, H., Hino, M.K., Mizuno, H. & Miyawaki, A. An optical marker based on the UV-induced green-to-red photoconversion of a fLuorescent protein. Proc. Natl. Acad. Sci. USA 99, 12651-12656 (2002). 152 I VOL.8 N0.2 | FEBRUARY 2011 | NATURE METHODS ONLINE METHODS Strains. We cultivated transgenic worms in the dark at 20 °C on nematode growth medium (NGM) plates with OP50 bacteria with all-trans retinal. We made OP50-retinal plates by seeding 6-cm NGM plates with 250 ju.1 of a suspension of OP50 bacteria in LB, to which we added 1 ju.1 of 100 mM retinal in ethanol immediately before seeding. Plates were stored in the dark and all worms were handled in the dark or under red light. Strain FQ10 (Pegl-6::ChR2::YFP) was a gift of N. Ringstad. Strain QH3341 (vdExl28(Pmec-4 ::Kaede)) was a gift of B. Neumann and M. Hilliard. Strains ZX444 (Zm-25(n765ts); zxEx29 {Vmyo-3 '■'■NpHR'-'-ECFP; lin-15+)) and ZX422 (lin-15 (n765ts); zxEx33 {Vunc-17::NpHR ::ECFP; lin-15+)) were gifts of A. Gottschalk. Strain Ptnyo-3 '■'■Halo ::CFP used in our experiments was generated by integrating the transgene in ZX444 by cobalt-60 irradiation and outcrossing the resulting strain three times to the wild-type N2 strain. Strain Vunc-17 '■'■ Halo'■'■ CV9 used in our experiments was generated by M. Zhen by irradiating ZX422 using UV radiation and outcrossing twice to the wild-type N2 strain. The Pmec-4 ::ChR2 strain (QW309) was generated by injection of Vmec-4'-'-ChR2::YFP plasmid at 100 ng ju.1 1 into lin-15(n765ts) worms along with the lin-15 rescuing plasmid (pL15 EK) at 50 ng ju.1 x; the extrachromosomal array was integrated using gamma irradiation and outcrossed four times to wild-type N2. Microscopy. The setup is built around a Nikon Eclipse TE2000-U inverted microscope. We carried out dark-field imaging using annular illumination of the specimen through a Ph3 phase ring. A filter transmitting red light (Hoya) was mounted to the microscope illumination optical pathway to minimize inadvertent activation of ChR2 or Halo/NpHR owing to dark-field illumination. We imaged worms using a lOx, numerical aperture (NA) 0.45 Plan Apo objective. We used a custom optical system composed of two camera lenses (Nikon) to reduce the size of the image on the camera by a factor of 3.5. This allowed us to capture almost all of the 2.5-mm-diameter field of view on the camera sensor. We used a PhotonFocus MV2-D1280-640CL camera and BitFlow Karbon PCI Express x8 10-tap Full Camera Link frame grabber to capture images. The microscope stage was controlled by a Ludl BioPrecision2 XY motorized stage and MAC 6000 stage-controller. During data acquisition, computer software kept the worm centered in the field of view via an automated feedback loop. Optics and illumination. To stimulate ChR2 we used a DPSS laser (LP473-100,473-nm wavelength, 100-mW maximum power, LaserShowParts). Similarly, to stimulate Halo/NpHR we used a DPSS laser (LP532-200, 532-nm wavelength, 200-mW maximum power, LaserShowParts). To photoconvert Kaede, we used a DPSS laser (EL-100B, 405-nm wavelength, 100-mW maximum power, Laserwold). The beams from the 473-nm and 532-nm lasers were aligned to a common path by a dichroic beamsplitter. The beam from the 405-nm laser was aligned to the common path with a retractable mirror. For each experiment, however, only one of the three lasers was used. The laser beam was expanded using a telescope composed of two plano-convex lenses and incident onto a 1,024 x 768 pixel digital micromirror device (Texas Instruments DLP, Discovery 4000 BD VIS 0.55-inch XGA, Digital Light Innovations) attached to a mirror mount. Using a series of mirrors, the laser was aligned such that the reflected beam for the 'on' state of the DMD was centered on the optical axis of the illumination pathway. The plane of the DMD was imaged onto the sample via the epifluorescence illumination pathway of the microscope using an optical system composed of two achromatic doublet lenses. We used a dichroic filter, FF580-FDi01-25x36 (Semrock), to reflect 405-nm, 473-nm or 532-nm laser light onto the sample while passing wavelengths used for dark-field illumination (A > 600 nm). We used an emission filter, BLP01-594R-25 (Semrock), to prevent stray laser reflections from reaching the camera. The dichroic and emission filters were mounted in a custom filter cube in the microscope filter turret. Imaging Kaede photoconversion. To measure photoconversion of ALM and AVM neurons in mec-4 '■'■ Kaede worms, we imaged worms on 5% (wt/vol) agarose pads containing 3 mM sodium azide as anesthetic. We recorded images using epifluorescence filter cubes, a cooled charge-coupled device (CCD) camera (CoolSnap HQ2, Photometries) and the NIS Elements D imaging software (Nikon). We measured the ratio R between the integrated and background-subtracted fluorescence pixel counts in the red and green fluorescence channels. (_R depends on the filter sets, illumination power, wavelength dependence of CCD camera sensitivity, and other factors and cannot be directly compared to fluorescence ratios in other reports.) We first measured R for Kaede-expressing neurons in immobilized worms exposed to 405-nm light for defined durations, to establish the slope of the linear increase in R with light exposure28. We found that under our conditions, R increased by -0.1% for every second of illumination by 405-nm light at an irradiance of 1 mW mnr2. Next, we imaged mec-4 '■ -Kaede worms in which only AVM or only ALM had been illuminated by 405-nm laser light when freely moving. We found that nontargeted neurons had a fluorescence ratio R < 0.1%. Our measurements suggest that illumination of the off-target neuron occurs at a rate of at most -1% that of the targeted neuron. To prepare the fluorescence images of the mec-4 '■ -Kaede worms for display (Fig. 5a,b), we used ImageJ (version 1.42q) to linearly adjust the brightness levels and apply red or green false color. Software. The microscope and all its components were controlled with custom MindControl software running Windows XP on an Acer Veriton M670G computer with an Intel Core 2 Quad processor running at 2.83 GHz and 3 GB of RAM. MindControl enables the user to define arbitrary illumination patterns for optogenetic stimulation, and to deliver illumination patterns either manually or automatically. For rapid operation, MindControl was written in the C programming language using the open-source OpenCV computer vision library along with Intel's Integrated Performance Primitives for maximal speed. To further increase speed, we used multiple threads to separately handle image processing and the user interface. Every 20 ms, MindControl acquires an image from the camera, computes the location of the worm, generates an illumination pattern and sends that pattern to the DMD. For each video frame, the boundary and centerline of the worm and the status of the stimulus is recorded in a human- and computer-readable YAML file. Every frame is also recorded in two video streams, one containing annotations about optogenetic stimulation, doi:10.1038/nmeth.!554 NATURE METHODS and the other containing only images of the freely moving worm. A GUI allows the user to adjust the parameters of optogenetic stimulation in real time during each experiment. After each experiment, we used custom scripts written in Matlab to carry out quantitative analysis of the resulting video. All software and documentation is freely available for modification and redistribution under the GNU general public license. The software is available as Supplementary Software and at http://github.com/ samuellab/mindcontrol-analysis. The most up-to-date version of the software and precompiled binary executables are available at http://github.com/samuellab/mindcontrol. Behavioral experiments. For motor circuit experiments, we washed each young adult worm in NGM solution and transferred each worm to a chamber composed of ~ 100 ju.1 of a 30% dextran (wt/vol) in NGM solution sandwiched between two microscope slides separated by 0.127 mm. In this chamber the worm was approximately confined to two dimensions but otherwise able to move freely. We then placed the chamber on the microscope for data collection. To analyze egg-laying, we selected gravid adult worms, washed them in NGM and transferred them to chambers as described above. Each worm was subject to sequential pulses of 4 s of blue light illumination. Each pulse illuminated a stripe orthogonal to the worm centerline, spanning the worm diameter with width corresponding to 2% of total body length. The stripe progressed along the worm centerline from head to tail or from tail to head until the first egg was laid. After an egg was laid, the trial ended and the worm was killed. Out of 14 worms studied, one did not lay any eggs. For mechanosensory circuit experiments, we prescreened young adult Pmec-4 '■ '■ ChR2 worms on a fluorescence stereo microscope (Nikon SMZ 1500) by illuminating the anterior of the worm with blue light from a 50-W mercury lamp through a GFP excitation filter. Only worms that responded with a reversal were chosen for further experiments. We carried out this prescreening procedure because the Vmec-4'-'-ChR2 strain (QW309) showed noticeable worm-to-worm variability: only -70% responded robustly and consistently. The reasons for this variability are unclear. Worms that passed this prescreening were then transferred to an unseeded NGM agar plate and were allowed to crawl for -30 s to free themselves of bacteria. We then transferred worms onto a plate containing a 1-2-mm-thick layer of NGM agar and covered with mineral oil to improve optical imaging quality. Specific regions of each worm were targeted with blue light and illuminated for 1.5 s. We scored anterior touch responses by quantifying the bending wave speed 2 s before stimulus onset and 3 s after stimulus onset. We classified a successful response to stimuli as a reduction in wave speed by > 0.03 body lengths per second. To calculate habituation rates as in Figure 5c-e, multiple worms were repeatedly stimulated over time. Fractional response, as plotted, is the total number of observed responses divided by the total number of stimuli in a ~4-min window for all worms of a given experiment. Quantifying locomotory behavior. The locomotory behavior of individual worms was analyzed by quantifying time-varying worm posture in each video sequence. A least-squares cubic smoothing spline fit to the body centerline was calculated, and curvature was calculated at each point along the centerline as the derivative of the unit vector tangent to the centerline with respect to the distance along the centerline. To graphically display locomotory gait, we use kymographs of curvature as a function of distance along the centerline and time. We calculated the speed of the bending wave along the centerline within the reference frame of the worm body by measuring the displacement of curvature profiles along the centerline (Ax) at successive points in time (Af) according to v = Ax I Af. NATURE METHODS doi:10.1038/nmeth.!554