Abstract
Understanding the neural basis of behavior requires imaging cellular activity in freely moving animals, which typically demands expensive, restrictive microscopy setups. To overcome these barriers, we developed Wormspy, a cost-effective, open-source epifluorescence microscopy system for high-magnification imaging and tracking of Caenorhabditis elegans. Wormspy enables the simultaneous recording of neuronal activity and behavioral dynamics without needing the animal to be restrained. We demonstrate its utility in imaging body wall muscles, sensory neurons, and subcellular calcium events within interneuron axons. Our platform reproduces known mutant phenotypes and uncovers, to the best of our knowledge, previously inaccessible sensorimotor correlations. We show that Wormspy provides a robust, modular framework that lowers technical barriers to high-resolution neural imaging, enabling flexible experimental designs for dissecting behavior in freely moving organisms.
Subject terms: Neural circuits, Fluorescence imaging
Wormspy is an open-source microscope and software package that tracks freely moving C. elegans while imaging neural activity. The system is validated in the study of known sensorimotor responses and is designed to be an affordable, modular system.
Introduction
The combination of smaller and cheaper imaging technology and tractable model organisms like Caenorhabditis elegans promises to be an important driver in our understanding of the neural correlates of behaviour. C. elegans is an excellent model organism for imaging-based experiments due to its small size, transparency, and genetic tools1. These properties have led C. elegans to be widely used in studies of development, cellular functioning, and neural signaling2, as well as being crucial for phenotyping models of disease and drug development3. Its cell lineage is largely invariant, allowing for individual cells to be tracked optically in both wild-type and mutant animals using differential interference contrast microscopy or fluorescent proteins4. Specifically, epifluorescence microscopy is a powerful tool for visualizing and studying cell activity, development, and the functioning of the nervous system.
Over the past decade, biological and neuroscience research has seen a marked shift toward custom, open hardware instrumentation, driven by advances in digital fabrication, commodity electronics, and open-source control software that make it feasible for individual labs to design and deploy bespoke systems5–8. This movement is not just a cost-saving measure, but a means of enabling task-specific experimental design and improving reproducibility through shared, modifiable platforms. Together, these developments have supported a growing ecosystem of open microscopes, electrophysiology rigs, and behavioral platforms that are increasingly central to modern experimental workflows. In behavioural neuroscience specifically, recent developments in hardware, such as smaller, more sensitive digital cameras, and software, such as segmentation methods based on computer vision models are increasingly making possible the semi-autonomous imaging of single cells, cell assemblies, and even whole nervous systems in freely moving animals.
Imaging in freely moving animals as opposed to restrained animals comes with a spate of engineering challenges, but makes possible new investigations of sensorimotor integration, navigational strategies, and a host of other behavioural research9,10. Existing imaging platforms developed to image freely moving C. elegans are broadly divided into two categories11. Some trackers use a high-resolution camera to image a large area and achieve higher resolution of behavioural and locomotion data by using machine vision software that can segment and track single or multiple animals11–14. These imaging platforms are used almost exclusively for behaviour. Other imaging platforms use high magnification objectives to achieve the resolution necessary to observe cellular processes such as neuronal calcium flux, but are more limited in the behavioural repertoire they can record15,16.
Systems based on spinning disk confocal microscopes using dual objectives, one for tracking posture measurements and one for volumetric imaging of fluorescent probes, have been used for whole brain imaging in C. elegans crawling between an agar substrate and a coverslip17,18. In order to resolve individual cells, indicator expression is typically targeted to the nucleus, or cytoplasmic expression is combined with a nuclear marker. While these systems are powerful for imaging cell bodies, several classes of C. elegans neurons exhibit characteristic axonal calcium events, which cannot be measured by this approach, either because the indicator is absent from processes or because axons cannot be individually identified in structures like the nerve ring. It is unclear the extent to which animals recapitulate naturalistic behaviours under these experimental conditions. These systems are also very expensive, typically requiring complex customization of high-end base microscopes, and the resulting datasets require considerable computational expertise to analyse and interpret. Finally, to keep the worm centred in the field of view, these imaging platforms typically use XY motors that move the stage, causing sporadic acceleration forces and vibrations, to which C. elegans are known to be highly sensitive19.
We concluded that there was a need for a compact, flexible design that would enable widefield imaging (or photoactivation) of genetically targetable cells in freely moving animals without expensive hardware or complex analysis pipelines. We therefore designed a user-friendly, inexpensive microscope and software package named Wormspy. Wormspy combines single worm tracking with a motor platform that moves the microscope relative to a fixed behavioural arena. 2-channel imaging through a single objective allows for simultaneous recordings of fluorescent signals and behaviour in a single optical path. While we have focused on calcium imaging, Wormspy can be adapted to any number of use cases with the simple exchange of filters and objectives. The modular design of the microscope allows for a high degree of customization to meet experimental needs, such as the inclusion of optogenetic photostimulation or ratiometric recording modules and can be applied to a wide range of experimental setups.
In this work, we demonstrate the applicability of our design to common use cases in C. elegans neurobiology. We use Wormspy to characterize the gait parameters and muscle activity underlying a previously described motor coordination phenotype. We show that Wormspy can resolve sensory activity by recording activity in the ASH polymodal sensory neuron as freely moving worms encounter hyperosmotic glycerol barriers. We demonstrate how Wormspy’s ability to simultaneously combine manual and automatic tracking makes it suitable for recordings in difficult environments by imaging the activity of the food-sensing AWCON neuron at a lawn border. Finally, we demonstrate the ability of Wormspy to resolve subcellular axonal calcium transients in the RIA interneuron.
Results
Microscope design
For a complete description, parts list, and build guide, see Supporting Information. Wormspy consists of a 2-channel fluorescence optical pathway mounted on a motorized stage (Fig. 1A). The modular design allows LED light sources and filter sets to be changed easily. For example, the use of a dual band dichroic mirror allows either simultaneous use of two fluorophores, a single fluorophore and brightfield image, or a photostimulation channel and a recording channel. This configuration was developed principally for calcium imaging applications in single or small numbers of neurons resolvable in the XY plane. Our configuration uses 470 and 565 nm excitation and two digital cameras, one receiving the emission spectra of GCaMP (502–538 nm), and one receiving the red transmission band from the dual band dichroic. The red transmission was used as a “bright field” image to silhouette the worm against the background for tracking and behavioural analysis, but the addition of an RFP emission filter (603–678 nm) also allowed us to use this channel for ratiometry in the ASH experiment.
Fig. 1. Wormspy hardware, software user interface, and data processing overview.
A Hardware schematic. Green and blue LEDs illuminate the stage through a dual band dichroic filter set, and the sample is captured by two cameras. XYZ motors for automated and manual tracking across a 50.4 × 50.4 mm area, as well as dynamic focus adjustment. Created with BioRender.com. B Software UI. (I) Start screen allows users to specify cameras. (II-III) Dual camera feeds. (IV) For manual tracking, a dual-joystick controller is recommended to allow for smooth adjustment of XY for tracking the animal and Z for manual focus correction. (V) Selection of tracking algorithm. (VI) FocusLock adjusts the Z motor to prevent focal drift. (VII) Directory and name to save recording. (VIII) Live histogram for evaluation of fluorescent marker intensity. C Example offline data processing pipeline. Brightfield videos can be analyzed to extract pose and behavioural features. Epifluorescence intensity can be analyzed using custom segmentation code. Stage position data can be analyzed to extract behaviourally relevant information, such as position in a gradient and reversals. Frame-synced recordings of brightfield, calcium and stage position data enable easy comparison of behaviour and cell activity.
Light from two LEDs coupled to excitation filters (in our example, GCaMP and RFP) is directed via a dichroic mirror to a dual band filter cube and reflected onto the sample through a 100 mm tube lens and 7.5x objective lens, which provides a 1440 × 900 μm field of view, just accommodating an adult C. elegans. The emission path from the sample passes through the dual bandpass mirror, where it is split with another dichroic mirror and filtered into green and red components to two machine vision cameras.
We used Teledyne FLIR computer vision USB cameras (BFS-U3-23S6M-C) with a sensor optimized for high quantum efficiency (QE) for calcium imaging, and a sensor with at least a frame rate of 10 Hz and a resolution of 1 MP for the brightfield camera (Supporting Information). The software is also compatible with Basler cameras and can be modified to work with other brands that have OpenCV compatible Python libraries.
The optical path is attached to a Z motor stage via a 90° mounting platform. We used a Zaber VSR20A vertical lift stage, which has sufficient torque to smoothly adjust the position of the microscope and keep the subject animal in focus. The Z motor in turn sits on two Zaber TSB60E horizontal translation stages that move the microscope in the XY plane to keep the subject centred in the field of view. The two cameras and the controllers for the three motors are connected via USB to a PC.
Software design and user interface
For more details, see the GitHub repository linked in the Supporting Information as well as Supplementary Movie 1. Wormspy comes with an open-source software package that includes a user interface written in Python, HTML, Typescript and open-source libraries such as OpenCV and Scikit-Image (Fig. 1B). Once both cameras are connected, the user can specify which camera corresponds to the desired left and right video feeds. If all necessary drivers are installed and the Zaber Launcher application is open to communicate with the stage motors, the program will then load the live feed of the left and right camera.
Once Wormspy is running, the user can enable ManualMode to use a dual-joystick controller to move the XY and Z motors to locate the animal and adjust focus. There are three automated tracking modes: (1) thresholding a dark object on a light background, which is most suitable for bright field channels and tracks the centroid of the worm; (2) thresholding fluorescent markers, which tracks the brightest object against a dark background; or (3) DeepLabCut20 (DLC) integration, which allows users to provide their own pre-trained model for tracking a specific feature like the nose or tail of the animal. Each tracking method calculates the centroid—or feature of interest in the case of DLC—of the thresholded object and makes the necessary conversions for the XY motors to adjust the field of view. This conversion keeps the region of interest centred as the animal moves. On a 100 mm plate, we can track animals for >30 min uninterrupted. For consistent tracking we recommend a minimum frame rate of 5–10 Hz.
Once the animal has been acquired and in focus, the user can also toggle FocusLock, which uses the variance of the Laplacian (2nd spatial derivative) to calculate the sharpness of the image from the right camera, and a proportional–integral–derivative (PID) control algorithm to smoothly adjust the Z motor to maintain the desired focus.
The user can specify a project title and directory to save the video recordings. Both cameras can save videos either as “MJPG” compressed video in an audio-video interleaved (AVI) container, which is useful for behaviour, or as a lossless 16-bit tagged image file format (TIFF) stack that preserves image detail and dynamic range. Cameras are frame synced, meaning the two recordings can be directly compared by frame number. A text log of stage position and real coordinates of tracked objects is output for the duration of the recording.
Calcium imaging in body wall muscle cells during C. elegans locomotion
As our first proof of concept, we used Wormspy to record locomotion and muscle activation dynamics in wild type and uncoordinated mutants. The motor networks that produce C. elegans locomotion are modulated by upstream interneurons. We previously reported that disrupting the function of the RIA interneuron via mutation of gar-3, which encodes a muscarinic acetylcholine receptor, is associated with increased body bend amplitude21 (Fig. 2A).
Fig. 2. Measurement of locomotion posture and body wall muscle calcium dynamics in freely moving animals.
A gar-3 mutants display motor coordination defects, including deeper body bends. B Example frame of a calcium recording of HBR4 showing GCaMP activation in BWMCs (left) and the segmentation skeleton applied to the worm’s midline (right). Scale bar = 250 µm C To characterize temporal and spatial distribution of calcium activity in BWMCs, worms were segmented into 28 evenly spaced ROIs by drawing perpendicular lines on either side of the worm’s midline (left). Heatmaps show calcium activity from each of these boxes arranged anterior to posterior on the X axis and temporally on the Y axis (right). D For each segment of the skeleton the angle relative to the previous segment was calculated (left) and arranged anterior to posterior as a heatmap (right). E Kymographs showing bending angle and right and left calcium activity in wild type and gar-3 worms. gar-3 animals show deeper body bends and disrupted coordination. F gar-3 (n = 12) worms show increased midline displacement (top) and a wider range of head angles (bottom) compared to wild type (n = 11). Shading in top is s.e.m. Data are provided as a Source data file.
To test the ability of Wormspy to characterize the effects of gar-3 mutation on gait and locomotion, we performed calcium imaging in freely moving animals expressing the calcium indicator GCaMP3 in body wall muscle cells (BWMCs) in wild type and gar-3 mutants. We then analysed the videos with a custom segmentation pipeline (Fig. 2B). In each video, the animal is segmented and a midline constructed from 28 evenly spaced points from nose to tail, and 27 corresponding dorsal and ventral ROIs were constructed from orthogonal line segments (Fig. 2). At each segment, the midline angle relative to the anteriorly adjacent segment was calculated, and the ROIs were used to measure GCaMP intensity in opposing muscle groups in each segment. We observed the expected calcium dynamics: calcium increased in dorsal BWMCs during dorsal bends and in ventral BWMCs during ventral bends (Fig. 2C, D). Time series analysis for muscle contraction patterns showed that oscillations are slower in gar-3, corresponding to a lower gait frequency (Fig. 2E). We confirmed that gar-3 animals displayed deeper body bends, though only in the anterior half of the body, and showed a broader distribution of head bending angles corresponding to increased gait amplitude, as previously described21 (Fig. 2F).
Calcium imaging in the polymodal ASH sensory neuron
To assess Wormspy’s ability to resolve single cells and detect sensory-evoked calcium activity, we performed calcium imaging in the polymodal sensory neuron ASH as worms encountered a glycerol barrier. ASH is a ciliated neuron whose dendrite extends to the tip of the nose, where it detects noxious sensory stimuli such as harsh touch, high osmolarity, and aversive odours. Calcium activity in ASH increases rapidly following exposure to these nociceptive cues, enabling reflex-like escape behaviour, including reversals22,23.
We adapted a behavioural assay by Ghosh et al.24 to measure the calcium response to a hyperosmotic glycerol barrier in freely-moving animals expressing GCaMP6f and DsRed in ASH (Fig. 3A). To control motion artefacts, we configured Wormspy for ratiometric recording by fitting the second camera with an RFP emission filter. We tracked animals and recorded from when they approached the glycerol barrier until reversal termination. Videos of GCaMP and DsRed signals were analysed using custom segmentation code, which calculates the average of the 25 brightest pixels within the cell soma for both the red and green channels (Fig. 3C). The traces of the green and red channels were then passed through Two-channel Motion Artifact Correction25 to isolate GCaMP dynamics (Fig. 3B) from shared motion signals. Consistent with previous reports24, we found that calcium dynamics increased in the ASH soma as C. elegans entered the glycerol barrier in the seconds leading up to a reversal, peaking in the initial phase of the reversal (Fig. 3D).
Fig. 3. Ratiometric recording of ASH sensory neuron calcium activity in response to an aversive glycerol barrier.
A Illustration of the ASH glycerol barrier assay. Created with BioRender.com. B Ratiometric recording of GCaMP6f and RFP allows for the separation of cellular activity from motion artefacts. C Example frame of ASH::GCaMP6f animal showing the ASH cell soma and dendrite. Scale bar = 50 µm. D Mean and standard error of ASH cell soma fluorescence changes aligned to reversal initiation show sustained activity increases at timescales consistent with the literature in restrained animals (n = 10). Source data are provided as a Source data file.
Calcium imaging in the AWCON sensory neuron on food
Tracking and recording calcium activity presents additional challenges when C. elegans are on food due to variations in lighting, background, and focal depth. Wormspy’s ability to simultaneously combine manual and automatic tracking modes makes it particularly suited to this task. We tested this capability by recording calcium activity in the AWCON neuron as worms exited a patch of food.
The AWCON neuron responds to decreases in the concentration of attractive, food-associated chemicals, driving local search behavior26. We therefore expected that we would see an increase in AWCON calcium activity as animals exit an E. coli lawn. Worms were placed on a small patch of food in the middle of the plate, which was aligned with the midpoint of the Wormspy field of view. This allowed us to convert the relative position of stage movements into the worm’s absolute position in the environment (Fig. 4A, C). Our recordings show AWCON activity increasing concurrently with the worm’s nose leaving the patch of food, consistent with the existing literature27 (Fig. 4B, D).
Fig. 4. Tracking and calcium imaging of the AWCON sensory neuron during food patch navigation.
A Illustration of the AWC food patch assay. Created with BioRender.com. B Example segmentation frames of AWCON::GCaMP animals navigating on food (left) and with their nose extending out of the food patch (right). C Stage position traces showing worms navigating the food patch assay over a period of 5 min. Scale bar = 1 mm. D Mean and standard error of AWCON fluorescence response aligned with the time of the worm’s nose leaving the food patch (n = 13). Source data are provided as a Source data file.
Calcium imaging in RIA axonal compartments
To demonstrate that Wormspy can resolve behaviourally relevant signals in subcellular compartments, we imaged worms expressing GCaMP6f in RIA. As previously described, local, compartmentalized calcium events in the ventral and dorsal segments of the RIA axon (nrV and nrD) are correlated with ventral and dorsal head bends, respectively (Fig. 5A)21. The orientation of the axon is such that the nrV and nrD compartments are resolvable in the same focal plane, allowing us to capture the activity in both segments of the axon as worms performed head bends during forward locomotion. Using the brightfield image, we extracted head angles for each frame by plotting points along the animal’s midline. We then used this angle to cancel out rotational movement of the neuron in the GCaMP recordings and used Segment Anything Model 2 (SAM2)28 to define consistent masks for both the nrV and nrD axonal compartments (Fig. 5B). We estimated the local period of head bends for each animal over time. By plotting nrV and nrD activity according to head oscillation period, we show that nrV activity peaks at the most ventral head position, and nrD peaks with dorsal head positions (Fig. 5C, D). Because the motor neuron activity driving local RIA calcium dynamics should be active during bending rather than at the terminus of a bend, we also plotted the derivatives of local calcium domain signals (Fig. 5C, D). Period analysis and cross-correlations showed that the peak rate of calcium increase in each compartment corresponds to peak ventral (positive) or dorsal (negative) head angle velocity. Interestingly, our previous measurements of RIA calcium in restrained worms showed a slightly different periodicity in which peak calcium levels and rates of increase lagged peak head position and velocity. This may reflect the fact that when restrained in microfluidic devices, animals rarely exhibit the regular head oscillations of forward locomotion and spend a large percentage of time in a reversal state, which may involve different timing of motor commands.
Fig. 5. Resolution of localized subcellular calcium events in the RIA interneuron axon during locomotion.
A RIA schematic: the RIA axon exhibits local calcium events in the nerve ring compartments nrV and nrD that encode head movements via reciprocal connections to SMDV and SMDD. Created with BioRender.com. B Example trace of head angle alongside nrV and nrD activity over time. Head angle was calculated from points placed along the midline of the worm, and nrD and nrV were segmented using a custom SAM2 analysis pipeline. C Polar plots showing mean and standard error nrV and nrD activity plotted according to oscillation period (left) and the time derivative of nrV and nrD (right). D Mean and standard error of cross-correlations of nrV and nrD signal vs head angle (left) and their time derivatives (right) (n = 7). Source data are provided as a Source data file.
Discussion
The potential exists for imaging technology to be made much more widely available through low-cost, open-source systems. We believe our microscope design is a contribution to this effort. Robust recording of epifluorescence signals and cellular activity has long been difficult in imaging environments that do not incapacitate or restrain the animal. Our design is intended to make fluorescence imaging in freely moving animals as inexpensive and simple as possible, without relying on commercial microscopy systems. While wide field imaging does not allow optical sectioning or resolving cells in the Z-axis, it is more robust with respect to focal movement artifacts, thus common approaches that impede natural movement, like compressing animals between a coverslip and the agar surface are not necessary.
Wormspy was able to resolve the phasic calcium transients of BWMCs and track worms for long intervals to characterize locomotion phenotypes. We imaged the AWCON neuron as worms exited a patch of food and demonstrated the platform’s ability to resolve single neurons in complex imaging environments. Given that both cameras use the same light path and frame-sync recordings, users can align the images in post. Analysis of both the behavioural data and neural activity collected using Wormspy allows users to make inferences about how neural activity affects behaviour and how the worm’s interactions with its environment affect neural activity (Fig. 1C).
Additionally, for more motion sensitive applications, we demonstrated Wormspy’s potential for ratiometric recording by imaging the ASH sensory neurons as worms reversed to escape a glycerol barrier. In RIA, we show that it is possible to record calcium activity not only in neuronal cell bodies, but also in dendritic or axonal compartments, provided a sufficiently bright GCaMP line is used. For example, in the RIA::GCaMP6f strain used here, we were able to record with an exposure time of 14 ms, minimizing motion artefacts. Our system allowed us to show how localized calcium dynamics in the RIA axon are correlated with locomotion, identifying temporal differences from data collected in restrained animals. Table 1 provides raw pixel values, dynamic range, and signal to background rations for neuronal GCaMP imaging experiments.
Table 1.
Raw fluorescence signals in imaging experiments. ΔF/F is the largest relative change in fluorescence observed, SBR is the signal to background ratio
| Experiment | Median pixel value (neuron) | Mean background | ΔF/F | SBR |
|---|---|---|---|---|
| ASH | 37623 | 1408 | 2.1 | 26.7 |
| AWC | 15540 | 3264 | 0.3 | 4.8 |
| RIA axon | 136 | 15 | 1.6 | 16 |
While Wormspy was developed for calcium imaging in head sensory and interneurons in C. elegans, its modular design and low cost allow it to be adapted by other researchers and find applications in other fields. Our system is built with off-the-shelf components and is intended to be highly extensible and modifiable. It is particularly amenable to applications like closed-loop optogenetic stimulation. We anticipate that it can easily be applied to other small organisms such as Drosophila melanogaster larvae (see Supplementary Movie 2 for a proof of concept recording of Drosophila larvae expressing GCaMP7 in body wall muscle as they perform nociceptive escape behaviour).
Multiple laboratories have developed solutions to image neural activity in freely moving C. elegans16,23,29–34. While not functionally unique, Wormspy adds to this tradition by providing a modular, low cost, open-source hardware and software package to enable combining behaviour and physiological measurements in C. elegans and potentially other small organisms. Similar recent work in an accompanying article by Ramahefarivo et al. works toward the same goal of open, modular hardware designs that reduce barriers to designing behavioural neuroscience experiments in C. elegans35. Wormspy’s design, flexibility, and use of standard components make it highly customizable to a wide range of experimental conditions.
Methods
All experiments complied with relevant ethical regulations. As this study exclusively utilized the invertebrate Caenorhabditis elegans, which does not require ethical approval in Canada, no institutional approval was necessary.
Animals. C. elegans were maintained under standard conditions and fed OP50 bacteria36. To provide age-synchronized young adults for calcium imaging experiments, we used a limited laying technique, transferring the eggs to a new rearing plate where they were raised at 25 °C for 2 days to minimize transgene silencing, before being transferred to 20 °C for 24 h preceding recording. MMH214 was maintained at 20 °C for the duration of development. For measuring BWMC activation, we used HBR4 and MMH116 expressing GCaMP3.3. To measure ASH activity in the glycerol barrier assay, we used TQ5856 animals expressing GCaMP6f. For AWCON recordings, we crossed AML175 with a lite-1 KO to CX17256 expressing GCaMP5 in AWCON (MMH214). HBR4, AML175, and CX17256 were obtained through the CGC. TQ5856 and BAR269 were generously provided by Shawn Xu and Arantza Barrios, respectively. A list of all strains used in this study is provided in Table 2.
Table 2.
Mutant and transgenic C. elegans strains used for behavioral and calcium imaging
| Strain | Genotype (description) |
|---|---|
| N2 | Bristol wild type |
| VC657 | gar-3 (gk305) |
| HBR4 | goeIs3 [pmec-4::sl1::gcamp3.35::sl2::mkate2-unc-54-3’utr, unc-119 (+)] (BWMC GCaMP3.3) |
| MMH116 | gar-3 (gk305); goels3 (HBR4 x VC657) |
| TQ5856 | xuEx1978 Psra-6::Gcamp6 (f);Psra-6::DsRed] (ASH GCaMP6f) |
| AML175 | lite-1 (ce314); wtfIs3 [rab-3p::NLS::GFP + rab-3p::NLS::tagRFP] |
| CX17256 | kyIs722 [str-2p::GCaMP5 (D380Y) + elt-2::mCherry] |
| MMH214 | lite-1 (ce314); kyIs722 (AML175 x CX17256) |
| BAR269 | oleEx103 [(glr-3::GCaMP6f::sl2::RFP) (30 ng/μL pLAU9)]; him-5 (e1490) (RIA GCaMP6f) |
Statistics and reproducibility
No statistical method was used to predetermine sample size. Sample sizes for the proof-of-concept experiments were chosen based on standard practices and established conventions in Caenorhabditis elegans neurobiology and imaging literature, which typically rely on similar cohort sizes to demonstrate robust functional readouts. The sample sizes (biological replicates) for each experimental group were as follows: n = 11 (HBR4) and n = 12 (MMH116) for calcium imaging in body wall muscles; n = 10 (TQ5856) for calcium imaging in the ASH neurons; n = 13 (MMH214) for calcium imaging in the AWCON neuron; and n = 7 (BAR269) for calcium imaging in RIA axonal compartments. All videos with robust segmentation were used for the analyses. The experiments were not randomized. The Investigators were not blinded to allocation during experiments and outcome assessment.
Microscopy system specifications
Complete technical specifications for the Wormspy epifluorescence system, including all optical components, illumination sources, camera details, and acquisition parameters utilized across the subsequent behavioral assays, are detailed in the Supplementary Information and Supplementary Data 1—Light microscopy reporting table.
Calcium imaging in body wall muscles
We transferred well-fed adult day 1 worms (HBR4 n = 11, MMH116 n = 12) individually to medium unseeded NGM plates before placing them under the Wormspy objective. The worms were illuminated with blue light and tracked using the user interface. Worms were recorded as they moved across the agar for five minutes. We then analysed the videos with a custom segmentation pipeline to measure ventral and dorsal BWMC activity (Fig. 2B).
Calcium imaging in the ASH neurons
Young adult TQ5856 (n = 10) worms were starved for 30 min. A ring of glycerol (≥99.0%, Sigma-Aldrich) 2 cm in diameter (approximately 12 μL in volume), was pipetted in the centre of medium unseeded NGM plates. To incentivize animals to enter the aversive glycerol barrier, two 1 μL drops of diacetyl (2,3-Butanedione, Sigma-Aldrich, 1:350 dilution) were pipetted outside of the ring, at opposite ends of the plate, about 1 cm from the border (Fig. 3A). The glycerol was allowed to absorb into the agar for ten minutes. Individual animals were then placed inside the centre of the ring and left to crawl freely for five minutes while being tracked and recorded using Wormspy. Blue light was turned on as worms approached the barrier to minimize bleaching. Changes of fluorescence intensity of the calcium indicator GCaMP6f in the ASH neuron were recorded via the GFP-filtered camera. Recordings where the worms encounter the glycerol barrier were segmented for the ASH cell soma via a custom segmentation pipeline (Fig. 3B, C). Frame counts where animals entered the glycerol barrier and initiated reversal were manually ascertained from the brightfield recordings.
Calcium imaging in the AWCON neuron
Well-fed MMH214 (n = 13) worms were individually transferred onto small NGM plates with a small patch of food in the center. Using a grid visible underneath the NGM plates, the plates were aligned such that at the start of a recording, the worm in the patch of food was as close as possible to the midpoint of the Wormspy range of motion (home position). Using a combination of automatic and manual tracking, worms were kept in view and in focus for 5 min as they explored the patch of food. Recordings were manually analyzed to identify frames where the worm’s nose exited the food. The brightest 25 pixels of the AWCON cell soma in the GCaMP6f channel were measured for each frame.
Calcium imaging in RIA axonal compartments
Well-fed BAR269 (n = 7) worms were individually transferred onto medium agarose plates without food and recorded using automatic tracking for 1–2 min at a framerate of 10 Hz and 14 ms exposure time to minimize motion artefacts. For each worm, 200 frames of uninterrupted forward runs were selected for analysis. The worm in the brightfield image was skeletonized by placing 12 evenly spaced points along the midline. Head angle was calculated using the angle between the vectors corresponding to points 3→2 and 2→0. The GCaMP6f channel recordings were cropped into 80 × 80 px frames centered on the neuron soma. Using custom code, we first used head orientation from the brightfield channel to rotationally register each neuron and then prompted the Segment Anything Model 2 (SAM2) to recognize the nrV and nrD compartments and create custom masks that were robust throughout the recording. The brightest 25 pixels in each mask were used for analysis. The traces were smoothed with an equally weighted moving average of window size 0.5 s (5 frames). nrV and nrD calcium were min/max normalized (0–1), and head angles were normalized to the deepest dorsal (−1) or ventral (+1) bend. Derivatives were calculated between adjacent time points on smoothed, normalized values. To estimate the period of oscillation a phase angle was calculated as ϕ=atan2 (∂angle, angle). Polar plots show mean values within 24 15° bins. For Figs. 5C, D binned by polar coordinates and averaged across worms (n = 7).
Reporting summary
Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.
Supplementary information
Description of additional supplementary files
Source data
Acknowledgements
We thank Arantza Barrios and Shawn Xu for strains. Elliott Hendricks assisted in the early stages of software development. A special thank you to Dr. Arjun Krishnaswamy for advice on instrument design. Figures 1a, 3a, 4a and 5a were created in part with assets from BioRender.com. Some strains were provided by the CGC, which is funded by NIH Office of Research Infrastructure Programs (P40 OD010440). This work was funded by grants from the Natural Sciences and Engineering Research Council of Canada (NSERC RGPIN-2020-04928, M.H. and NSERC PGSD 579692, H.O.) and the Canadian Institutes of Health Research (CIHR PJT-155980, M.H.).
Author contributions
S.N.W. and M.H. designed the instrument. S.N.W., L.W., and A.G. developed code. SNW and HO collected data. S.N.W., H.O., and M.H. analyzed data. S.N.W. and M.H. wrote the manuscript. MH obtained funding.
Peer review
Peer review information
Nature Communications thanks Matthias Truttmann and the other, anonymous, reviewer(s) for their contribution to the peer review of this work. A peer review file is available.
Data availability
The data generated in this study are accessible at 10.5281/zenodo.19477903. Source data are provided with this paper.
Code availability
https://github.com/Hendricks-Worm-Lab/WormsPy_paper_analysis. The custom software package used for microscope control and tracking (Wormspy) is available on GitHub https://sebzdead.github.io/WormsPy/37. The custom segmentation and analysis code is available on GitHub38.
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Supplementary information
The online version contains supplementary material available at 10.1038/s41467-026-72709-w.
References
- 1.Riddle, D. L., Blumenthal, T., Meyer, B. J. & Priess, J. R. The Biological Model (Cold Spring Harbor Laboratory Press, 1997). [PubMed]
- 2.Sengupta, P. & Samuel, A. D. T. Caenorhabditis elegans: a model system for systems neuroscience. Curr. Opin. Neurobiol.19, 637–643 (2009). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 3.Kaletta, T. & Hengartner, M. O. Finding function in novel targets: C. elegans as a model organism. Nat. Rev. Drug Discov.5, 387–398 (2006). [DOI] [PubMed] [Google Scholar]
- 4.Breimann, L., Preusser, F. & Preibisch, S. Light-microscopy methods in C. elegans research. Curr. Opin. Syst. Biol.13, 82–92 (2019). [Google Scholar]
- 5.Oellermann, M. et al. Open hardware in science: the benefits of open electronics. Integr. Comp. Biol.62, 1061–1075 (2022). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 6.Wenzel, T. Open hardware: from DIY trend to global transformation in access to laboratory equipment. PLoS Biol.21, e3001931 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 7.Siegle, J. H., Hale, G. J., Newman, J. P. & Voigts, J. Neural ensemble communities: open-source approaches to hardware for large-scale electrophysiology. Curr. Opin. Neurobiol.32, 53–59 (2015). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 8.Salido, J., Bueno, G., Ruiz-Santaquiteria, J. & Cristobal, G. A review on low-cost microscopes for Open Science. Microsc. Res. Tech.85, 3270–3283 (2022). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 9.Kaplan, H. S., Nichols, A. L. A. & Zimmer, M. Sensorimotor integration in Caenorhabditis elegans: a reappraisal towards dynamic and distributed computations. Philos. Trans. R. Soc. Lond. B Biol. Sci.373, 20170371 (2018). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 10.Parker, P. R. L., Brown, M. A., Smear, M. C. & Niell, C. M. Movement-related signals in sensory areas: roles in natural behavior. Trends Neurosci.43, 581–595 (2020). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 11.Husson, S. J., Costa, W. S., Schmitt, C. & Gottschalk, A. Keeping track of worm trackers. WormBook22, 1–17 (2013). [DOI] [PMC free article] [PubMed]
- 12.Koopman, M. et al. Assessing motor-related phenotypes of Caenorhabditis elegans with the wide field-of-view nematode tracking platform. Nat. Protoc.15, 2071–2106 (2020). [DOI] [PubMed] [Google Scholar]
- 13.Swierczek, N. A., Giles, A. C., Rankin, C. H. & Kerr, R. A. High-throughput behavioral analysis in C. elegans. Nat. Methods8, 592–598 (2011). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 14.Itskovits, E., Levine, A., Cohen, E. & Zaslaver, A. A multi-animal tracker for studying complex behaviors. BMC Biol.15, 29 (2017). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 15.Gengyo-Ando, K. et al. A new platform for long-term tracking and recording of neural activity and simultaneous optogenetic control in freely behaving Caenorhabditis elegans. J. Neurosci. Methods286, 56–68 (2017). [DOI] [PubMed] [Google Scholar]
- 16.Ben Arous, J., Tanizawa, Y., Rabinowitch, I., Chatenay, D. & Schafer, W. R. Automated imaging of neuronal activity in freely behaving Caenorhabditis elegans. J. Neurosci. Methods187, 229–234 (2010). [DOI] [PubMed] [Google Scholar]
- 17.Venkatachalam, V. et al. Pan-neuronal imaging in roaming Caenorhabditis elegans. Proc. Natl. Acad. Sci. USA113, E1082–E1088 (2016). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 18.Nguyen, J. P. et al. Whole-brain calcium imaging with cellular resolution in freely behaving Caenorhabditis elegans. Proc. Natl. Acad. Sci. USA113, E1074–E1081 (2016). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 19.Wicks, S. R. & Rankin, C. H. Integration of mechanosensory stimuli in Caenorhabditis elegans. J. Neurosci.15, 2434–2444 (1995). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 20.Mathis, A. et al. DeepLabCut: markerless pose estimation of user-defined body parts with deep learning. Nat. Neurosci.21, 1281–1289 (2018). [DOI] [PubMed] [Google Scholar]
- 21.Hendricks, M., Ha, H., Maffey, N. & Zhang, Y. Compartmentalized calcium dynamics in a C. elegans interneuron encode head movement. Nature487, 99–103 (2012). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 22.Hilliard, M. A. et al. In vivo imaging of C. elegans ASH neurons: cellular response and adaptation to chemical repellents. EMBO J.24, 63–72 (2005). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 23.Tanimoto, Y. et al. Calcium dynamics regulating the timing of decision-making in C. elegans. eLife6, e21629 (2017). [DOI] [PMC free article] [PubMed]
- 24.Ghosh, D. D. et al. Neural architecture of hunger-dependent multisensory decision making in C. elegans. Neuron92, 1049–1062 (2016). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 25.Creamer, M. S., Chen, K. S., Leifer, A. M. & Pillow, J. W. Correcting motion induced fluorescence artifacts in two-channel neural imaging. PLoS Comput. Biol.18, e1010421 (2022). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 26.Chalasani, S. H. et al. Neuropeptide feedback modifies odor-evoked dynamics in Caenorhabditis elegans olfactory neurons. Nat. Neurosci.13, 615–621 (2010). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 27.Chalasani, S. H. et al. Dissecting a circuit for olfactory behaviour in Caenorhabditis elegans. Nature450, 63–70 (2007). [DOI] [PubMed] [Google Scholar]
- 28.Ravi, N. et al. SAM 2: segment anything in images and videos. arXiv10.48550/arXiv.2408.00714 (2024).
- 29.Faumont, S. et al. An image-free opto-mechanical system for creating virtual environments and imaging neuronal activity in freely moving Caenorhabditis elegans. PLoS ONE6, e24666 (2011). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 30.Piggott, B. J., Liu, J., Feng, Z., Wescott, S. A. & Xu, X. Z. S. The neural circuits and synaptic mechanisms underlying motor initiation in C. elegans. Cell147, 922–933 (2011). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 31.Zheng, M., Cao, P., Yang, J., Xu, X. Z. S. & Feng, Z. Calcium imaging of multiple neurons in freely behaving C. elegans. J. Neurosci. Methods206, 78–82 (2012). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 32.Shipley, F. B., Clark, C. M., Alkema, M. J. & Leifer, A. M. Simultaneous optogenetic manipulation and calcium imaging in freely moving C. elegans. Front. Neural Circ.8, 28 (2014). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 33.Tsukada, Y. et al. Reconstruction of spatial thermal gradient encoded in thermosensory neuron AFD in Caenorhabditis elegans. J. Neurosci.36, 2571–2581 (2016). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 34.Ravi, B. et al. Ratiometric calcium imaging of individual neurons in behaving Caenorhabditis elegans. J. Vis. Exp. 10.3791/56911 (2018). [DOI] [PMC free article] [PubMed]
- 35.Ramahefarivo, E. et al. A modular multi-color fluorescence microscope for simultaneous tracking of cellular activity and behavior. Nat. Commun.10.1038/s41467-026-72710-3 (2026). [DOI] [PMC free article] [PubMed]
- 36.Brenner, S. The genetics of Caenorhabditis elegans. Genetics77, 71–94 (1974). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 37.Wittekindt, S. N., Owens, H., Guisnet, A., Wittekindt, L. & Hendricks, M. An epifluorescence microscope design for naturalistic behavior and cellular activity in freely moving Caenorhabditis elegans: wormspy. 10.5281/zenodo.19477899 (2026). [DOI] [PMC free article] [PubMed]
- 38.Wittekindt, S. N., Owens, H., Guisnet, A., Wittekindt, L. & Hendricks, M. An epifluorescence microscope design for naturalistic behavior and cellular activity in freely moving Caenorhabditis elegans: segmentation. 10.5281/zenodo.19477902 (2026). [DOI] [PMC free article] [PubMed]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Description of additional supplementary files
Data Availability Statement
The data generated in this study are accessible at 10.5281/zenodo.19477903. Source data are provided with this paper.
https://github.com/Hendricks-Worm-Lab/WormsPy_paper_analysis. The custom software package used for microscope control and tracking (Wormspy) is available on GitHub https://sebzdead.github.io/WormsPy/37. The custom segmentation and analysis code is available on GitHub38.





