High-resolution analysis of individual Drosophila melanogaster larvae uncovers individual variability in locomotion and its neurogenetic modulation

Neuronally orchestrated muscular movement and locomotion are defining faculties of multicellular animals. Due to its simple brain and genetic accessibility, the larva of the fruit fly Drosophila melanogaster allows one to study these processes at tractable levels of complexity. However, although the faculty of locomotion clearly pertains to the individual, most studies of locomotion in larvae use measurements aggregated across animals, or animals tested one by one, an extravagance for larger-scale analyses. This prevents grasping the inter- and intra-individual variability in locomotion and its neurogenetic determinants. Here, we present the IMBA (individual maggot behaviour analyser) for analysing the behaviour of individual larvae within groups, reliably resolving individual identity across collisions. We use the IMBA to systematically describe the inter- and intra-individual variability in locomotion of wild-type animals, and how the variability is reduced by associative learning. We then report a novel locomotion phenotype of an adhesion GPCR mutant. We further investigated the modulation of locomotion across repeated activations of dopamine neurons in individual animals, and the transient backward locomotion induced by brief optogenetic activation of the brain-descending 'mooncrawler' neurons. In summary, the IMBA is an easy-to-use toolbox allowing an unprecedentedly rich view of the behaviour and its variability of individual larvae, with utility in multiple biomedical research contexts.


Introduction
Understanding the neuronal control of movement and locomotion, that is of how we do what we do, is an important and rewarding task for basic research in the behavioural and neural sciences. Furthermore, such an understanding can inspire the development of medical and technical applications, for example regarding gait analysis for medical diagnosis, or bioinspired robotics [1][2][3]. A comprehensive analysis of neuromuscular control in humans remains a formidable challenge, however, not least because of the complexity of our brains and bodies, complexity that is scarcely less in other mammals. In the past few years, the larva of the fruit fly Drosophila melanogaster has emerged as a model organism for studying many aspects of these processes [4]. The combination of a rich toolbox for cell-specific transgenic manipulation, a nervous system of only about 10 000 neurons, and the availability of an electron-microscope-based synaptic connectome allows neuronal processes to be studied in unrivalled detail. The utility of the larva for behavioural neuroscience has been further aided both by its relatively simple body and the relatively moderate level of complexity in its locomotion. Locomotion in Drosophila larvae can, simplifying somewhat, be described as consisting of periods of relatively straight runs characterized by peristaltic waves of muscle contraction along the body wall that alternate with occasional lateral head movements [4][5][6][7][8][9][10][11][12][13][14]. This results in a zig-zagging pattern of locomotion towards their target, similarly observed in adult flies and mosquitoes.
Most studies of locomotion in larval Drosophila either use en-masse, group assays and measurements aggregated across individual animals, or they need to measure single animals one at a time, which practically precludes larger-scale analyses. It has thus remained difficult to come to grips with the causes and consequences of the variability in locomotion both between and within individual animals (henceforth called inter-individual and intra-individual variability, respectively). Yet individual idiosyncrasies in behaviour are described across the animal kingdom, including Drosophila [15][16][17]. Such inter-individual variance in behaviour may be regarded not as noise, but as an inroad to studying the determinants and implications of such variability and (if these are heritable) as raw material for natural selection. Likewise, intra-individual variability in behaviour is essential to initiate operant learning, that is to generate novel actions capable of bringing about desired outcomes. To study behavioural differences within and across individuals efficiently, we need to be able to (i) observe behaviour in individual animals, (ii) measure large numbers of animals in a short period of time and (iii) manipulate the candidate cellular and molecular substrates of the observed behaviour easily and precisely. An increasing number of video-tracking approaches have been developed in the past decade to facilitate such analyses in larval Drosophila. Some of these were designed to track the behaviour of individually assayed animals, e.g. [18][19][20]. These usually provide a very high temporal and spatial resolution, but are extravagantly timeconsuming if high sample sizes are required. Other approaches were designed to track groups of animals (e.g. [21][22][23][24][25][26][27][28][29]). These focus on the average behaviour of groups of animals and thus do not allow for individuals to be followed. More recent approaches have tried to combine the advantages of both types of tracking [30,31]. The major challenge in these cases is that individual Drosophila larvae look very much alike. As a result, when two larvae collide, their identity is lost, resulting in a multitude of separated tracks and no opportunity for the experimenter to disentangle which tracks belong to which of the animals. Two different strategies have been followed in tackling this problem: one relies on the parallel tracking of many separated individual animals [30]; the other tries to resolve the collisions between larvae and thus to keep track of the identity of individual larvae within a group of animals [31] (for an earlier approach not specific to Drosophila larvae, see [32]; for a similar approach in Caenorhabditis elegans, see [33]). The latter solution is so far not implemented in any ready-to-use tracking software. The first approach is suitable to track and analyse high numbers of individual animals, but has specific requirements regarding the physical setup for video-recording, and therefore requires extensive redesigns of established behavioural assays in order to be used. We follow a different approach by starting from an established standard behavioural assay and developing a tracking solution that works for that assay and that non-expert users can easily implement in their research programmes using that assay or its derivatives.
Here, we present the IMBA. It consists of the IMBAtracker and the IMBAvisualizer. Together, these can track and analyse the behaviour of individual larvae within groups. They allow collisions to be resolved between individual larvae using a combination of statistical and computational approaches that can be applied to videos obtained by non-expert users in standard experimental assays. They do not require any specific hardware beyond a camera and stable lighting, and can therefore be easily applied to various derivatives of these standard behavioural assays, including ones that are commonly used for olfactory, gustatory or visual choice [34][35][36][37][38], or associative learning [39][40][41]. We further show the utility of the IMBA as a research tool by deepening our insights into the modulations of behaviour by associative training, by discovering a novel, complex locomotion phenotype in mutants of an adhesion G protein-coupled receptor gene (Latrophilin/Cirl) [42] and by studying the effects of repeatedly activating dopamine neurons (as covered by the TH-Gal4 driver) on locomotion. The utility of the IMBA is further demonstrated for patterns of locomotion it was not originally designed to study, using as an example the backward movements induced by optogenetic activation of the so-called 'mooncrawler' neurons (as covered by the R53F07-Gal4 driver). In all these cases, we pay particular attention to the inter-individual and intra-individual variability in behaviour.

Results
In this study, we investigate the behaviour of individuals within groups of Drosophila larvae. Our approach to the problem of losing track of individual identities upon collisions involves two critical steps: first, for our analysis we only considered tracks that were more than half the length of the recorded video, so we were sure that no two tracks in our analysis belonged to the same individual animal; second, we tried to stitch together tracks from the same individual across collisions in order to maximize the number of individual animals that we could include within our analysis. To this end, we employed a combination of a computational approach modelling the shape of larvae and keeping their identities during a collision, and a statistical approach comparing larvae before and after a collision. We used the shape model approach for short collisions involving either two larvae or a single larva briefly touching a larger assembly, and the statistical approach for longer collisions involving either two or three larvae. We did not attempt to resolve collisions of larger groups as the success rate was extremely low in preliminary experiments (not shown). For more details, see the Material and methods section.
royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 2.1. The IMBA allows the behaviour of individuals within groups to be studied In order to evaluate our approach, we compared the results with manual assessments of collisions by an experienced experimenter. In 48 videos with approximately 20 larvae each (for an example video, see electronic supplementary material, movie S1), 1844 collisions were found by the experimenter. We attempted to resolve 1531 by means of the IMBAtracker, and of these, 1511 were correctly resolved (electronic supplementary material, figure S1a). In total, 83.7% of all tracked data belonged to tracks that fulfiled our criterion of being at least half the length of the video after collision resolution and were used in the analysis (electronic supplementary material, figure S1b-d). Notably, without the collision resolution implemented, this fraction dropped to 46.7%, demonstrating the importance of this processing step (electronic supplementary material, figure S1d).
To further evaluate IMBAtracker, we applied it to videos from different sources: (i) to videos gathered with the same setup but with smaller Petri dishes (9 cm diameter instead of 15 cm), used for figures 8-13, (ii) to videos gathered at the University of Leipzig with an independently developed setup, used for figures 5-7, (iii) to videos of the dataset 'LCD2A' published at www.uni-muenster.de/Geoinformatics.cvmls/media/datasets.shtml, based on [43], and (iv) to videos published along with [26]. The videos from all these sources could successfully be tracked. Electronic supplementary material, movies S2-S5 show the annotated output of the IMBAtracker for one example of each video type, and demonstrate the range of video types and qualities handled by the IMBAtracker. The dataset (iv) was recorded with the popular FIMtrack setup [25,43] and provides short videos, each depicting a collision of two larvae, sorted into three classes of increasing complexity of the collision. We manually assessed the output of the IMBAtracker on these videos and found high rates of correct assessments in all three classes (electronic supplementary material, figure S1e). This demonstrates that the IMBAtracker is able to reliably track and resolve collisions between larvae.
In the next step, we developed an R-based shiny application to analyse and visualize the behaviour of these individual larvae. This application, called the IMBAvisualizer, calculates a total of 95 attributes for each animal that can be explored and visualized in an interactive manner (for all attributes used in this study, see tables [1][2][3][4]. For an overview of the process, see electronic supplementary material, figure S2. Both the code and a full documentation of this application can be accessed via GitHub at https://github.com/mthane/IMBA and will be regularly updated and further developed in the future. The locomotion of Drosophila larvae has been studied in detail in the past decade [5][6][7]. In brief, the locomotion can be described as sequences of run phases, consisting of relatively straight, forward peristaltic movement and reorientation manoeuvres, consisting of lateral head casts (HCs), which are usually associated with a strong reduction in speed and are followed by changes in direction (figure 1a) [8]. Accordingly, we first defined HC phases by the above-threshold angular velocity of the animal's head vector (HV) (figure 1b,c) (for details, see the Material and methods section). Animals were considered to be in a run phase whenever they were not in a HC phase. A period of 1.5 s before and after each HC was excluded from the run phases to prevent the potential effects of HCs on run behaviour. All these definitions are in line with our previous work [28,44]. For a more detailed analysis of run periods, we defined the cycles of peristaltic movement by means of the animal's forward velocity (figure 1d). Each local maximum of forward velocity during a run was defined as one 'step', with the period between two steps (inter-step, IS) capturing one complete cycle of peristaltic movement (for a similar approach, see [19]).

Attributes of basic locomotion in larvae are variable across individuals
On the basis of these observations, and considering the innate, i.e. experimentally naive, behaviour of 875 animals in an odour gradient, we determined a set of six behavioural attributes to describe the basic locomotion of larvae: the IS speed, indicating the average speed across all peristaltic cycles (figure 2a); the IS distance, indicating the average size of the steps (figure 2b); the IS interval, indicating the average time between two steps (figure 2c); the absolute bending angle, indicating how much the body of a larva was bent throughout the whole observation period (figure 2d); the HC rate, indicating how many HCs an animal performed per second (figure 2e); and the absolute HC angle, indicating the average size of an animal's HCs (figure 2f ). To determine the variability in each behavioural attribute, we calculated the coefficient of variation (CV), which indicates the standard deviation as a percentage of the mean and allows the inter-individual variability to be compared across different behavioural attributes. The CV was lowest for the IS distance (15.6%) and highest for the HC rate (47.4%). One important reason for variability across animals is known from previous studies: the size of animals [19]. We therefore investigated the impact of animals' size on the six behavioural locomotion attributes and found that both IS speed and IS distance were correlated with the body length of a larva, whereas other attributes were not affected (electronic supplementary material, figure S3). This finding is in line with previous work [19]. We therefore decided to correct for the body length in all following analyses by dividing any

Bending and head-casting behaviour is more variable within individuals than peristaltic forward locomotion
After investigating the inter-individual variability, we explored the intra-individual variability in behaviour (figure 2g-i).
We found that attributes related to the peristaltic forward movement such as the IS speed, IS distance and IS interval were much less variable than attributes associated with directional changes such as the absolute bending and HC angles (figure 2i; as the HC rate is calculated as a single value per individual it is excluded from this analysis). This finding suggests that peristaltic forward movement is a highly stable, regular behaviour with little variation, whereas directional changes are much more variable. Interestingly, the directional changes, but not the peristaltic forward movement, were much more variable within each individual than across individuals (figure 2i). As animals in this dataset were exposed to an odour source, it is conceivable that their behaviour, in particular the variability in their directional changes, may be affected by the individuals' distance from the odour as well as their orientation with respect to the odour. To account for these potential effects, we analysed the animals' behaviour separately for low and high distances from the odour source (below and above 60 mm, respectively) and found the same pattern of results, with low variability for the IS speed, IS distance and IS interval, and high variability for the absolute bending and HC angles (electronic supplementary material, figure S4a,b). Likewise, animals oriented towards the odour source (defined as an absolute bearing angle of below 90°) and animals oriented away from the odour source (absolute bearing angle of above 90°) showed the same result (electronic supplementary material, figure S4c,d). Finally, we tested experimentally naive animals in absence of any odour source and found once more the same result (electronic supplementary material, figure S4e).

Attributes of peristaltic forward locomotion are stable over time within individuals
Next, we wondered how stable the behaviour of individual animals was over time. To this end, we determined each of the six behavioural attributes for each individual in the first and in the third minute of the 3 min video, and asked whether the behaviour in either minute would be correlated with that in the other. We detected mild correlations of the HC rate as well as the absolute bending and HC angles, and strong correlations of the IS speed, the IS distance and the IS interval ( figure 3). This suggests that the behaviour of individual animals, though variable, was nevertheless remarkably consistent over time: the fastest animals in the first minute were also the fastest in the third minute, and the animals making the largest HCs in the first minute tended to do the same in the third minute. Next, we extended this analysis with respect to the distance from the odour source as well as the orientation to the odour source. We found strong correlations of the IS speed, IS distance and IS interval, and weaker correlations of the HC rate, the absolute bending and HC angles, when comparing behaviour while the animals were near or far from the odour source (electronic supplementary material, figure S5a-f). A similar result was observed when comparing behaviour while the animals were oriented towards or away from the odour source (electronic supplementary material, figure S5g-l). Finally, we probed for the stability of the behaviour over time using animals that were tested without any odour source. We detected overall weaker correlations in this dataset, with moderate correlations of the IS speed, IS distance and IS interval and virtually no correlations of the HC rate, the absolute bending and the absolute HC angle (electronic supplementary material, figure  S6). Across all these analyses, attributes of peristaltic forward locomotion were more stable within individuals than attributes of directional changes.
To put the newly developed technology to the test, we next performed a number of experiments and detailed analyses to quantify modulations of locomotor behaviour. Our strategy was to start from a previously described or expected effect on locomotion, and challenge our software to uncover

Previous training modulates HC behaviour
First, we preformed detailed analyses of larval locomotion and its modulations in response to previous associative odour-sugar training. Such associative learning experiments are established for about two decades and used in many laboratories [39][40][41][45][46][47]. In brief, groups of larvae were trained to associate an odour with a sugar reward by repeated pairings and subsequently tested with the odour source on one side of the Petri dish. Other groups were trained in an explicit unpaired fashion, with odour and sugar being presented in separate trials (figure 4a). We compared the behaviour of those trained animals with experimentally naive animals tested in the same way. Please note that this 'innate' condition is the same data as used in figures 2 and 3. All three experiments were done in parallel for a previous study [28]. As expected, the three experimental conditions differ in their preference for the odour: after paired training the larvae approached the odour, after unpaired training they avoided it, and experimentally naive animals showed an intermediate preference ( figure 4b).
Previously, we investigated the modulations of behaviour by learning using group averages, and found that mainly two aspects of behaviour were modulated: the HC rate and the HC direction [28,44,48]. Here, we first replicated these results using individual animals (electronic supplementary material, figure S7). Specifically, we found that after paired training larvae (i) were on average more oriented towards the odour source than after unpaired training (electronic supplementary material, figure S7a), (ii) modulated their HC rate to be lower when heading towards the odour source and higher when heading away from it, compared to larvae after unpaired training (electronic supplementary material, figure S7b,c) (iii) and directed their HCs more towards the odour source than after unpaired training (electronic supplementary  , of the sample larva displayed in (a). During runs, the velocity oscillates regularly. Each oscillation marks one cycle of peristaltic forward movement. Therefore, we define each peak of the tail forward velocity during runs as one 'step', indicated by grey lines in this and analogous figures. During HCs, the regular forward movement is stopped. Therefore, 1.5 s before and after each HC, no steps are detected.
royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 material, figure S7d). Experimentally naive animals displayed intermediate behaviour in all these cases. In addition, just like in previous studies, we found a non-significant trend of higher speed when heading towards the odour than when heading away from it after paired training (electronic supplementary material, figure S7e,f ) [28,44].
Previous studies suggested that odour preference is controlled by a single motor output that integrates all innate and learned behavioural tendencies and causes constant leftright oscillations that are modulated by the presence of attractive or aversive stimuli such as trained odours [28,49,50]. According to this hypothesis, the behavioural attributes in our study, in particular the modulations of the HC rate and HC direction, should be strongly correlated with each other because they are materializations of the same motor output. We indeed found correlations in all three experimental  , and across animals (blue diamonds). The median is displayed as the middle line, the 25% and 75% quantiles as boxes and the 10% and 90% quantiles as whiskers. The underlying source data can be accessed in electronic supplementary material, source data file S1. 'bl', individual body lengths; 'bl s −1 ', body lengths per second.
royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 conditions (electronic supplementary material, figure S7g). However, the correlations were rather weak overall, and relatively strongest between the modulations of the HC rate and HC direction. This rather weak correlation may suggest that the HC rate and HC direction, at least partially, can be modulated independently from each other.

Previous training reduces intra-individual variability
Next, we wondered how the six basic attributes of locomotion would be modulated by previous training. We found several small but significant differences between naive and trained animals, but only in one case a significant difference between animals after paired and unpaired training. Specifically, we found a decreased IS speed and IS distance, but not IS interval, in trained animals compared to experimentally naive animals (figure 4c,e,g). Furthermore, the intra-individual variability in these three attributes was reduced after training (figure 4d,f,h). Regarding the directional changes, naive animals displayed larger absolute bending angles and HC rates, as well as more variable absolute HC angles, compared to trained animals (figure 4i-m). Thus, experimentally naive animals were overall faster, stronger bent and made more HCs than trained animals, and the behaviour of naive animals was overall more variable than that of trained animals. The kind of training, paired or unpaired, made no difference in these aspects of locomotion behaviour, with the exception of a slightly lower absolute bending angle after paired than after unpaired training (figure 4i). Thus, previous training had two fundamental effects: it guided the animals towards or away from the trained odour source by modulating the respective behaviour in opposite ways after paired and unpaired training (electronic supplementary material, figure S7), and it reduced overall activity and variability independent of the kind of training received (figure 4).

The Cirl mutation reduces speed, bending and head-casting behaviour
After investigating the modulations by training, we performed detailed analyses of larval locomotion and its modulations upon genetic manipulation. To this end, we first chose the Latrophilin homolog Cirl, which is broadly expressed throughout the larval nervous system. Importantly, Cirl KO mutant larvae are known to exhibit a strong locomotion deficit compared to wild-type animals as well as a genomic Cirl Rescue control [42], which has not, however, been studied in detail thus far. We tracked and analysed the behaviour of 225 mutant and 147 rescue control larvae (figure 5). First, we confirmed the previously observed phenotype in crawling speed (figure 5b) [42]. Then, we analysed mutant and control animals regarding the six behavioural attributes described above. We found that the IS speed of the mutants was less compared to the control (figure 5c). Notably, a lower speed can come about in two ways: the larvae may make a slower peristaltic movement, resulting in a higher IS interval, or they may move less per peristaltic cycle, resulting in a lower IS distance. In the present case, we found only a small difference in the IS distance and a large difference in the IS interval (figure 5d,e). An even closer look into the run behaviour revealed that mutant animals are  Figure 3. Basic locomotor attributes differ in how consistent they are over time. We determined each behavioural attribute for each individual independently for the first and the third minute of the video. We uncovered differences across behavioural attributes: we found moderate to strong correlations for (a) the IS speed, (b) the IS distance and (c) the IS interval, but only very weak, yet significant correlations for (d) the absolute bending angle, (e) the HC rate and ( f ) the absolute HC angle. Correlations are determined by SC tests. The underlying source data, as well as the results of the statistical tests, can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second.
royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 disturbed in their regular peristaltic cycle (see below). In addition to the expected phenotype in speed, we detected a reduced absolute bending (figure 5f ), which was accompanied by a reduced HC rate, as well as a reduced absolute HC angle, in the Cirl KO mutant larvae (figure 5g,h). That is, the mutants made fewer and smaller HCs, and were bending less. This suggests that mutant larvae are generally impaired in the bending of the body and in directional changes, possibly due to impaired functioning of the chordotonal organs. This result was surprising, as in a previous study a qualitative description after paired training after unpaired training 90 60 Figure 4. Previous associative training decreases activity and the variability of locomotion. (a) We compared the basic locomotor attributes of animals tested for their odour preference either naively (innate), or after paired or unpaired training with odour and a sugar reward. (b) After paired training, the animals were attracted the most, after unpaired training they were attracted least to the odour. Compared to trained larvae, naive larvae displayed (c) a higher IS speed, (d ) a higher intra-individual variability (as indicated by the coefficient of variation (CV)) of the IS speed, (e) a higher IS distance, ( f ), a higher CV IS distance, (g) an unchanged IS interval, (h) and a higher CV IS interval. (i) The absolute bending angle was highest in naive animals and lowest after paired training. Compared to trained larvae, naive larvae showed ( j ) an unchanged CV absolute bending angle, (k) a higher HC rate, (l ) an unchanged absolute HC angle and (m) a higher CV absolute HC angle. The median is displayed as the middle line, the 25% and 75% quantiles as boxes and the 10% and 90% quantiles as whiskers. Asterisks indicate significant differences in MW tests. The underlying source data, as well as the results of the statistical tests, can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second. of the Cirl KO mutant locomotion implied an increased number of HCs [42].
We also analysed the variability of each of the behavioural attributes within individuals, and observed increased variability in the IS speed and the IS interval in Cirl KO mutant larvae compared to the controls (electronic supplementary material, figure S8).

A machine-learning approach reveals additional modulations of locomotion in Cirl KO mutants
So far, our analysis had focused on the six basic locomotion attributes. But the loss of Cirl may affect behaviour in further ways. We therefore extended our analysis to include additional behavioural attributes, including angular velocities of the head and tail, accelerations of head and tail, as well as the coefficients of variation whenever applicable. A full list of the 30 behavioural attributes used can be found in tables 2 and 3. We then employed an unbiased, machine-learning-based approach to determine the most decisive attributes that differentiated mutants and control larvae. Random forests work by building a large number of decision trees, each of them trying to classify each individual animal according to either one genotype or the other. Importantly, random forests are not only useful in classifying data, but also in estimating which attributes are most important for the classification. For more details, see the Material and methods section. Applying this approach to our dataset, we were able to discriminate mutant and control larvae with an accuracy of 0.91 (figure 6a). Our assessment of which of the behavioural attributes were the most important in discriminating the behaviour of the two  The mutants displayed a strongly reduced midpoint speed compared to the control animals, confirming earlier results. (c) Also limited to run phases, the speed of mutants was reduced. (d ) The IS distance was decreased and (e) the IS interval increased. ( f ) In addition, the mutants were on average bending less than the control animals, which manifested itself as a decreased (g) HC rate and (h) absolute HC angle. The median is displayed as the middle line, the 25% and 75% quantiles as boxes and the 10% and 90% quantiles as whiskers. Asterisks indicate significant differences in MW tests. The underlying source data, as well as the results of the statistical tests, can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second.
royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 genotypes found that most of the top behavioural attributes were those already covered in our previous analysis: the IS speed, the IS interval, the absolute bending and HC angle, as well as the CV of the IS speed and the IS interval (figure 6b). This result confirmed our analyses so far. However, the random forest method also revealed four additional behavioural attributes: the distance travelled by the larva, the absolute angular speeds of the HV and tail vector (TV), as well as the CV of the forward velocity. A closer look revealed that the Cirl KO mutant larvae travelled shorter distances (figure 6c), consistent with their reduced speed. Furthermore, the mutants had decreased absolute HV and TV angular speeds (figure 6d,e), consistent with the general observation of decreased bending and turning rates in the mutant. Finally, we did not observe any clear difference in intra-individual variability in the tail forward velocity between mutant and rescue (figure 6f ). The last result implies that the random forest can use attributes to differentiate individual animals that do not display obvious differences when plotted as box plots.
To confirm that these top ten behavioural attributes were indeed the critical ones for describing the behaviour of Cirl KO mutants and control animals, we ran the random forest algorithm again, but this time with only those ten attributes. The algorithm was able to discriminate the two genotypes with an accuracy of 0.91, just as high as with the full set of behavioural attributes. The ten attributes in question were thus fully sufficient to discriminate between the genotypes. In turn, when we ran the random forest algorithm with the remaining 20 attributes and excluding the top ten, the accuracy was still 0.83. This suggests some redundancy in our analysis, with multiple attributes providing related information such that the algorithm can employ substitute attributes to discriminate between the genotypes even when the most decisive attributes are excluded.

Cirl KO mutant larvae have an altered rhythmic peristaltic cycle
In order to understand the origin of the Cirl KO phenotype in crawling speed, we analysed the temporal behavioural patterns of individual animals (figure 7). Just like wild-type larvae (figure 1d ), Cirl Rescue controls displayed a very regular rhythm in their forward velocity, indicated by a smooth, wave-like curve with local maxima of very similar heights that we detected as steps, and always one local minimum between two steps (figure 7a, top; electronic supplementary material, movie S6). Cirl KO mutants, in contrast, regularly exhibited a pattern of two local minima with one very small local maximum between two steps (figure 7a, bottom; electronic supplementary material, movie S7), resulting in IS intervals that were longer and more variable than those    Displayed are the median as the middle line, the 25% and 75% quantiles as boxes and the 10% and 90% quantiles as whiskers. Asterisks indicate significant MW tests, hash symbols significant WS tests. The underlying source data, as well as the results of the statistical tests, can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second.
of Cirl Rescue controls (figure 5e, electronic supplementary material, figure S8c). For further analyses, we defined each period between two steps with only one local minimum in the tail forward velocity as normal stepping, and each period with two local minima as 'stumble' stepping. A quantification revealed that stumble stepping was much more common in mutant than in control larvae, and that their proportion increased with increased IS intervals (figure 7b,c). Next, we directly compared the animals' behaviour specifically during normal stepping and stumble stepping. We found that larvae were slower and had longer IS intervals, but unchanged IS distances during stumble stepping compared to normal stepping (figure 7d-f ). In other words, stumble steps took longer to complete, but were not larger. Moreover, neither the animals' bending nor the angular speed of their HV was different between normal and stumble steps; only the angular speed of the TV was slightly decreased (figure 7g-i). This suggests that the phenotype in bending and turning that we observed was largely independent of the irregular stepping behaviour of the Cirl KO mutants.
In summary, we found that the Cirl KO mutants' phenotype in crawling speed can be at least partially attributed to an unusual stepping pattern that causes a slower peristaltic forward locomotion, and a largely independent phenotype in bending and turning.

Optogenetic activation of dopamine neurons triggers stopping and bending
Next, we investigated how the acute activation of genetically defined sets of neurons affected the locomotion of individual larvae. First, we applied our unbiased approach to the behaviour of Drosophila larvae upon optogenetic activation of dopamine neurons. To this end, we used larvae that expressed the highly sensitive effector Channelrhodopsin2-XXL (ChR2-XXL) [51] in a broad subset of dopaminergic neurons, as defined by the TH-Gal4 driver strain (experimental genotype). Groups of larvae were allowed to move freely over a Petri dish for 30 s in darkness, followed by 30 s of blue light in order to trigger the activation of the dopaminergic neurons, and another 60 s of darkness. The behaviour of the animals was compared to that of heterozygous driver and effector controls that did not express ChR2-XXL (figure 8). Upon light stimulation, animals of all three genotypes increased their absolute bending, suggesting that this was a response to the sudden light. However, the experimental genotype did so to a much greater extent than the genetic controls, suggesting that this stronger reaction was caused by the activation of the dopaminergic neurons (figure 8b, electronic supplementary material, movie S8). In order to evaluate the reaction of the animals to the light stimulation and the light-induced neuronal activation, we normalized each individual animal's behaviour during the 30 s of light stimulation by subtracting its behaviour in the 30 s of darkness before. The normalized values of 30 behavioural attributes (called Δ-values) were fed into the random forest. The random forest classified the three genotypes with an accuracy of 0.90 and provided the top ten most important attributes that differed between the three genotypes in their change in response to the light stimulation (figure 8c). In detail, we found a more strongly reduced distance travelled by larvae of the experimental genotype than of the genetic controls and accordingly a more strongly reduced tail forward velocity and midpoint speed (figure 8d-f ). Interestingly, the intra-individual variability in the midpoint speed, as determined by the CV, was increased in all three genotypes, but more in the experimental genotype (figure 8g). In addition, the random forest approach provided three behavioural attributes regarding the animals' bending. For the bending angle, which is positive if a larva is bent to the left and negative if bent to the right, we found no significant differences, but a strongly increased scatter of the data in the experimental genotype (figure 8h). Fittingly, the absolute bending angle, not taking the direction into account, was increased in all three genotypes, but much more so in the experimental genotype (figure 8i). The intraindividual variability in the absolute bending angle was increased only in the genetic controls, but not in the experimental genotype (figure 8j). Finally, the angular speeds of the animals' head and TVs also differed between the genotypes: both angular speeds were increased more strongly in the experimental genotype than in the controls (figure 8k,l ). Regarding the TV angular speed, the intra-individual variability was also more strongly increased in the experimental genotype (figure 8m).
In summary, activating a broad set of dopaminergic neurons caused the animals to slow down markedly and to bend and rotate their bodies (for a time-resolved view of the three genotypes' behaviour, see electronic supplementary material, figure S9).

Individuals reduce speed consistently upon repeated activation of dopamine neurons
In wild-type animals we observed that behavioural attributes associated with peristaltic forward crawling were more consistent within each animal than attributes associated with bending and HC behaviour (figures 2 and 3; electronic supplementary material, figures S3-S6). We therefore wondered whether this would also be true for the dopamine-induced changes in behaviour that we had observed. To tackle this question, we repeated the previous experiment with the experimental genotype expressing ChR2-XXL in TH-Gal4 neurons, but this time we activated the neurons three times for 10 s, each time followed by 60 s of darkness (figure 9). Then we determined the changes in the four behavioural attributes that had previously been found to be most important by the random forest method (figure 8c): tail forward velocity, midpoint speed, absolute bending angle and absolute angular speed of the HV. On average, the animals reacted very similarly to the three neuronal activations (figure 9). As regards the changes in behaviour within each animal, however, we found differences between the behavioural attributes. We observed mild to moderate correlations across the three neuronal activations for the tail forward velocity and the midpoint speed (figure 9b,d; electronic supplementary material, figure S10ad), but no correlations for the absolute bending angle and the absolute angular speed of the HV (figure 9f,h; electronic supplementary material, figure S10e-h). Thus, we indeed found that the reduction in speed upon activation of dopamine neurons was consistent within individual animals, whereas the increases in bending and lateral head movement were not. This further stresses the distinction between forward crawling and bending behaviour with respect to intra-individual variability.
royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308   In order to probe the utility of our approach further, we applied it to an analogous experiment to that described above, but activating a very different set of neurons. This time we chose the driver strain R53F07-Gal4, which reportedly covers a rather broad set of interneurons in the ventral nerve cord (VNC), the insects' functional analogue of the spinal cord, including the so-called moonwalker descending neurons royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 (MDNs) [52]. Optogenetically activating these neurons (henceforth called 'mooncrawler' neurons) had caused larvae to crawl backwards in a previous study [52], but an in-depth analysis of their behaviour is lacking. Therefore, we crossed R53F07-Gal4 to the UAS-ChR2-XXL effector strain, performed the same experiment as described above, and compared the animals' behaviour with the respective genetic controls (figure 10). Light stimulation did indeed cause backward crawling, as indicated by a negative forward velocity, in animals of the experimental genotype but not of the genetic controls (figure 10b, electronic supplementary material, movie S9). We applied the same strategy as before, fed the Δ-values of behavioural attributes into the random forest (accuracy 0.83), and obtained the top ten attributes that differed between the three genotypes in their change in response to the light stimulation ( figure 10c). Similarly to the case of dopaminergic neurons, we found the distance travelled, the tail forward velocity and the midpoint speed to be more strongly decreased in the experimental genotype than in the genetic controls, and the intra-individual variability of the midpoint speed to be more strongly increased (figure 10d-g). By contrast to the previous experiment, however, the IS speed and the IS interval were also among the top ten attributes: we found the IS speed to be strongly reduced, and the IS interval to be strongly increased, in the experimental genotype but not the genetic controls (figure 10h,i). Again, we found the animals' bending to be important, yet in a different way from the previous experiment: the absolute bending angle was reported as an important attribute by random forest, but the experimental genotype was different only from the effector control, not from the driver control (figure 10j). Thus, there was no evidence that the activation of the R53F07-Gal4 neurons were responsible for the change in the absolute bending angle. Interestingly, the intra-individual variability in the absolute bending angle was increased in the genetic controls but decreased in the experimental genotype (figure 10k). Although the change in the average bending was not significantly different from the genetic controls, thereby activating the R53F07-Gal4 neurons made the bending less variable. Finally, the angular speed of the HV as well as the HC rate were reported by the random forest. However, for the angular speed we found a significant difference in the experimental genotype only in relation to the driver, but not the effector control (figure 10l ), and no significant differences in the HC rate at all (figure 10m).

Individuals differ in the timing of their switching gears from backward to forward locomotion
A closer look at the temporal patterns of the behavioural attributes induced by the two sets of neurons activated revealed striking differences. The activation of dopaminergic neurons triggered a number of behavioural changes that quickly reverted back to normal as soon as the light stimulation ended (electronic supplementary material, figure S9). By contrast, activating the R53F07-Gal4 neurons triggered behavioural changes of very different, more complex dynamics (electronic supplementary material, figure S11). For example, the tail forward velocity dropped quickly to the negative upon light onset and started to become more positive gradually over the course of 90 s (electronic supplementary material, figure S11a). The midpoint speed and IS speed, in contrast, continued to drop slowly until a minimum was reached about 30-40 s after light onset (electronic supplementary material, figure S11b,c). The absolute bending angle was increased in all three genotypes during light stimulation. But whereas it reverted back to normal upon light offset in the genetic controls, it remained high for another 30 s in the experimental genotype before gradually decreasing (electronic supplementary material, figure S11e). What is the cause of these complex temporal patterns?
We compared the temporal pattern of the tail forward velocity across individual animals (electronic supplementary material, figure S12). Whereas all the individuals switched to backward crawling within a few seconds after light onset, the reverse switch to forward crawling was highly variable, with some animals not reverting at all within the recording time ( figure 11a). In other words, most larvae continued to crawl backwards even after the optogenetic activation of the R53F07-Gal4 neurons had finished, and each reverted to forward crawling in its own time. On average, those animals that did revert to forward locomotion within the recording time crawled backwards for about 51 s ( figure 11b). This also means that our previous analysis was confounded by mixing unknown numbers of forward and backward crawling individuals at any given time point. Therefore, we determined the switching points in each individual animal (electronic supplementary material, figure S12) and compared the individual animals' behaviour while the animals were crawling backward (i.e. between the switching points) with their behaviour while crawling forward (figure 11c).
We found that the midpoint speed was reduced, but its intra-individual variability was increased, while animals crawled backwards (figure 11d,e). Taking only run phases into account, the IS speed was reduced and the IS interval was accordingly increased, during backward crawling (figure 11f,g). The absolute bending angle was increased, with reduced intra-individual variability, while larvae crawled backwards (figure 11h,i). Finally, we found no differences between forward and backward crawling regarding the angular speed of the HV, but a reduced HC rate during backward crawling (figure 11j,k).
In summary, backward crawling was characterized by longer IS intervals, leading to a reduced and more variable speed, and by increased but less variable bending of the larvae, compared to forward crawling.

Switches between forward and backward locomotion are characterized by changes in speed, and peaks in bending and head-casting behaviour
Finally, we wondered how specifically the animals' behaviour was altered during the switches between forward and backward locomotion. To this end, we aligned the data of all the animals either to the switch to backward crawling, or to the switch to forward crawling (figure 12a). This alignment revealed that both midpoint speed and IS speed rapidly dropped at the switch to backward crawling, followed by a slow further decrease in the following seconds. Both speeds decreased until a few seconds before the switch to forward crawling and quickly rose again after the switch royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 ( figure 12b,c). Fittingly, the IS interval increased after the backward switch and decreased again after the forward switch (figure 12d). The absolute bending angle rapidly increased precisely at the backward switch and stayed constant afterwards. At the forward switch, the absolute bending angle peaked and then dropped quickly back to normal levels (figure 12e). The absolute angular speed of the HV did not change at all at the backward switch but peaked at the forward switch ( figure 12f ). Finally, the HC rate peaked at both switching points, albeit on different absolute levels (figure 12g).  Displayed are the mean and the 95% confidence interval in (b,c), and the median as the middle line, the 25% and 75% quantiles as boxes and the 10% and 90% quantiles as whiskers in (d-m). Asterisks indicate significant differences in MW tests. The underlying source data, as well as the results of the statistical tests, can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second.
In order to determine how the direction of crawling changed at each switching point, we calculated the change in the TV in the 10 s before and after each switch (figure 12h). We found that in both cases the larvae changed their crawling direction by about 100°, suggesting that either switch was followed by a movement approximately orthogonal to the previous direction.
We characterized backward switches by a decrease in speed and an increase in absolute bending angle, and forward switches by an increase in speed, and peaks in absolute bending angle and absolute angular speed of the HV. How stable were these changes for repeated switches across and within individuals? To address this question, we stimulated the R53F07-Gal4 neurons three times for 10 s and  Figure 11. Backward locomotion is characterized by reduced yet more variable speed, and increased yet less variable bending. (a) Distribution of the switching points to backward crawling (white) and forward crawling (grey). n = 97, 64. (b) Distribution of backward crawling durations, only taking those animals into account that perform both switches, i.e. that start to crawl backward and revert to forward crawling later (n = 58). (c-k) Within-animal comparison of the backward crawling phase (i.e. between the switching points) and the forward crawling phases, regarding (c) the tail forward velocity, (d ) the midpoint speed, (e) its coefficient of variation (CV), ( f ) the IS speed, (g) the IS interval, (h) the absolute bending angle, (i) its CV, ( j ) the HV absolute angular speed, and (k) the HC rate. Displayed are the median as the middle line, the 25% and 75% quantiles as boxes and the 10% and 90% quantiles as whiskers. Hash symbols indicate significant differences in WS tests. The underlying source data, as well as the results of the statistical tests, can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second.
aligned all animals either to the backward or to the forward switch ( figure 13). We found that the average behaviour of the animals was astonishingly consistent across all three backward and forward switches. Looking at individual behaviour with regard to the changes in tail forward velocity and midpoint speed, we observed mild to moderate correlations across repeated backward switches (figure 13a,c; electronic supplementary material, figure S13a,c), but not  Figure 12. Switching between forward and backward locomotion (and vice versa) is characterized by changes in speed and peaks in bending and head casting. (a-g) The tracks of animals from the experimental genotype (R53F07 > ChR2-XXL) were aligned either to the switch from forward to backward crawling (left, 'backward switch'), or to the switch from backward to forward crawling (right, 'forward switch'). Only animals that performed the respective switch were considered (n = 97, 64). (a) Tail forward velocity, (b) midpoint speed, (c) IS speed, (d ) IS interval, (e) absolute bending angle, ( f ) absolute head vector (HV) angular speed, (g) HC rate. Displayed are the mean and 95% confidence intervals of all data within each 2 s bin, except for the HC rate which was calculated within each 2 s bin by dividing all frames with a HC by all frames in the bin. (h) The orientation of the animal's body, indicated by the tail vector, was compared in the 10 s before and after a switch. Displayed is the percentage of animals that changed their orientation by the respective absolute angle, in brackets of 20°. The underlying source data can be accessed in electronic supplementary material, source data file S1. bl, individual body lengths; bl s −1 , body lengths per second. across repeated forward switches (figure 13b,d; electronic supplementary material, figure S13b,d). A notable exception was a significant moderate correlation in the midpoint speed between the second and third forward switch (electronic supplementary material, figure S13d). By contrast, no correlations were found for the absolute bending angle and the absolute angular speed of the HV (figure 13e,f,h; electronic supplementary material, figure S13e,f,h). The IS speed, IS interval and HC rate were not included in this analysis, as steps and HCs occur too rarely within the short observation periods used for this analysis.
In addition, we determined the duration of each of the three backward crawling phases upon each activation of R53F07-Gal4 neurons in individual animals, and found positive correlations that were significant between the first and the second, as well as between the second and third backward phases (electronic supplementary material, figure S13g). Between the first and third backward phase too, a positive correlation was observed; this remained non-significant due to the sample size of only seven animals that completed both backward phases (figure 13g).
In summary, we again found that changes in speed upon neuronal activation were more consistent within individuals than changes in bending or lateral head movement, just as we found to be the case with respect to dopamine neurons.

Discussion
In this study, we demonstrate the utility of the IMBA with five examples: our findings provide new insights into variability in locomotor behaviour, the modulations of behaviour by associative training, the complex behavioural phenotypes of an adhesion G protein-coupled receptor (GPCR) mutation, the effects of repeatedly activating dopamine neurons on locomotion, and the 'switching of gears' between forward and backward locomotion. In the following paragraphs, we first discuss the implications of our findings and the possible future directions for each of these cases, before summarizing the more general potential of the IMBA.

Bending and head-casting behaviour is variable; peristaltic locomotion is stable
Our analysis revealed that peristaltic forward locomotion is characterized by very low intra-individual variability and high consistency over time (figures 2 and 3; electronic supplementary material, figures S4-S6). Bending and headcasting behaviour, in contrast, is much more variable, and less stable. We note that, while similar findings have led to the suggestion that peristaltic forward locomotion would thus be best suitable for high-throughput phenotyping [19], we found reliable effects of transgenic manipulations on bending and HC behaviour, too (figures 5f-h, 8i-m and 10j-m). In any event, when we repeatedly activated the same set of neurons in the same individual animals, we found mild yet significant correlations for these repetitions for peristaltic forward locomotion, but not for bending and head-casting behaviour. This was true for both dopamine neurons and mooncrawler neurons (as covered by the R53F07-Gal4 driver) (figures 9 and 13). This suggests that individual larvae not only have a fairly stable, inherent rhythm of peristaltic locomotion, but they also modify this rhythm in a relatively idiosyncratic manner upon repeated neuronal activation. Bending and head-casting behaviour, on the other hand, appear highly variable and are modulated not only by previous experience (electronic supplementary material, figure S7) but also in an unpredictable manner upon repeated neuronal activation. The reason for this apparent difference in variability between peristaltic locomotion on the one hand and bending and head-casting behaviour on the other hand is not known. Interestingly, however, previous studies have found that peristaltic locomotion originates in both the anterior and posterior segments of the VNC, whereas head-casting behaviour and bending originate more anteriorly [53,54]. In both cases, input from the brain is reportedly not required. Input from the brain is required, in contrast, for organizing peristalsis, bending and head-casting behaviour in a goal-directed manner [53]. Consistently with this, we repeatedly found that 'higher' brain functions, such as associative memories, almost exclusively modulate head-casting behaviour, but not peristaltic runs (electronic supplementary material, figure S7) [28,44,48]. Overall therefore it seems that the characteristics of peristaltic runs that are particularly relevant for speed are relatively stable features of a given individual animal, 'hard-wired' in the VNC, whereas bending and head-casting behaviour, and thus changes in direction, are more flexible features that can be adaptively modulated by external stimuli and internal goals, modulations that apparently take place via the brain. We are curious whether such a distinction between speed-related, hard-wired, stable motor outputs from the VNC and direction-related, flexible, brain-modulated behaviours may turn out to be a general principle of behavioural control.
We note that intra-individual variability itself can be affected by specific experimental manipulations: for example, we found that the Cirl KO mutants show an increased variability in their IS interval (electronic supplementary material, figure S8). The optogenetic activation of select sets of neurons can also elicit changes in the variability of behaviour (figures 8g,j,m and 10g,k). One might therefore expect there to be cases in which experimental manipulation specifically affects the variability of a behavioural measure, but not its average. This was indeed the case when comparing innate locomotion with locomotion after a previous associative training (figure 4). We found a couple of differences, for example in the speed and the HC rate that likely reflected some level of fatigue after the training procedures. Importantly, in four out of five locomotor attributes, trained larvae displayed a lower intra-individual variability than experimentally naive animals, including in the IS interval and the absolute HC angle which did not differ in their average ( figure 4g,h,l,m). Such decreased levels of variability may reflect a loss of degrees of freedom by a training during which animals learn how to pursue their goal (i.e. finding food). Similar effects on the variability of behaviour would be interesting in particular in relation to processes for which behavioural variability is of particular value, e.g. for generating unpredictable actions during escape, for generating novel actions in pursuit of desired outcomes in operant learning, or for adapting to changed environmental contingencies during reversal learning.
Our findings suggest that individual larvae may have behavioural traits that are different between, but consistent within, individual animals. However, given that we only included videos of a maximal length of 4 min, it is possible royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 that even the attributes that are relatively stable within animals, such as those related to peristaltic locomotion, reflect transient internal states or 'moods' rather than permanent behavioural idiosyncrasies. To detect such idiosyncrasies, longer recordings and ideally repeated recordings of the same individual over several days or even across metamorphosis would be required. In adult Drosophila, repeated behavioural measurements demonstrated such behavioural idiosyncrasies even in strongly inbred fly populations [16,17]. In principle, inter-individual behavioural variation can originate from genetic, developmental and environmental factors. A previous study found highly significant correlations between the expression patterns of many genes and a broad array of behavioural attributes [17]. A particularly striking example of a genetic factor causing interindividual differences in behaviour is the polymorphism of the rover gene that causes different foraging strategies in larvae [15]. On the other hand, non-heritable, random asymmetries in the wiring of a specific set of visual interneurons were found responsible for inter-individual variability in a visual task studied in adult Drosophila [16]. Whether the inter-individual differences we report in this study reflect behavioural idiosyncrasy, and what would be their causes, remains to be determined.

Cirl KO mutants exhibit 'stumble' steps
We discovered a new, complex behavioural phenotype of Latrophilin/Cirl mutants. Cirl constitutes an aGPCR (adhesion G protein-coupled receptor) expressed in larval mechanosensory organs crucial for proprioception [42]. Previously, it was known only that mutants were slower, as was confirmed by our analysis (figure 5b). Here we found that the reason for the reduced speed was the abnormal 'stumble' stepping of the mutant animals, in which the peristaltic cycle was interrupted, and the time required to complete one cycle was therefore prolonged (figure 7). Interestingly, this different way of stepping was in itself rather regular, such that some mutant individuals always performed stumble steps (figure 7a). The stumble stepping explained parts of the observed behavioural phenotype: the IS interval was increased, and the IS speed was thus decreased during stumble stepping compared to 'normal' stepping in the same individual mutant animals (figure 7d,f ). However, the normal stepping phases of mutant and control animals also differed in these behavioural attributes, suggesting that the peristaltic cycles that we classified as 'normal' were partially impaired as well. Moreover, we found that mutant animals bent and turned less than control animals, a phenotype that was completely independent of the kind of stepping the animals performed ( figure 7g,h).
The molecular mechanisms through which aGPCRs exert their function remain incompletely understood. However, it is known that chordotonal neuron-located Cirl suppresses cAMP levels to shape larval proprioception and thus behaviour [42,55]. If and how Cirl has an impact in other cells that are part of the neuronal circuits that modulate locomotion remains elusive. Our analysis suggests that the correct functioning of the receptor is required for a normal, uninterrupted peristaltic cycle, but that even without the receptor larvae can eventually crawl forward. This is in line with published accounts showing decreased but existent proprioceptive capability [42]. It will be interesting to study larval locomotion in animals that express genetically modified Cirl proteins or specific Cirl isoforms [56], and the ability of Cirl mutants to successfully reach goals such as odours or tastants despite their impairment in crawling.

Activation of dopamine neurons makes larvae stop and turn
Across the animal kingdom, the dopaminergic system is closely associated with locomotion and the generation of movement [57,58]. In humans, the progressive death of dopaminergic neurons is widely accepted as a cause of Parkinson's disease, which results in difficulties in initiating movement [59][60][61].
Based on studies mostly of rodents, locomotion has been found to be controlled by interactions of several dopamine receptors in the ventral striatum, with some of them increasing, others inhibiting forward locomotion [62]. Turning behaviour can be induced by the unilateral administration of dopamine receptor agonists [63]. The administration of cocaine, which strongly activates the dopaminergic system, causes complex, concentration-dependent modulations of locomotion, including increased forward locomotion upon administration of lower concentrations of cocaine, and circling behaviour as well as a reduced forward movement upon repeated, or highly concentrated cocaine administration [64][65][66]. In Drosophila too, the dopaminergic system is linked to locomotion. Genetic fly models for Parkinson's disease show similar impairments in locomotion, as well as the death of dopaminergic neurons as found in mammals [67]. Cocaine administration leads successively to a reduction in forward movement, circling behaviour and rotating, before the animals stop moving at all, similar to the case in mammals [68]. In a pioneering optogenetic study, activation of the dopamine neurons covered by TH-Gal4 resulted in increased locomotion in flies that were little active before, and decreased locomotion in flies that were highly active [69]. Recently, a study has found the activity of specific dopamine neurons to be correlated with speed and turning of flies, suggesting that dopamine neurons both report and change specific movements [70].
Much less is known about the impact of dopamine on locomotion in Drosophila larvae. In this study, we optogenetically activated most dopamine neurons, and found that larvae stop forward locomotion and start strong bending (figure 8). Such behaviour would correspond to the behaviour of adult flies and mice after cocaine administration [64][65][66]68], and to what was observed in highly active flies upon activation of dopamine neurons [69]. Our results are also in line with one of the very few studies that link dopamine function with locomotion in larvae: a transgenic knockdown of the dopamine receptor Dop1R1, one of the two Drosophila homologues of the vertebrate D1-type dopamine receptors, was reported to increase locomotion in larvae [71]. Our experimental treatment, in contrast, acutely increased dopamine signalling, leading to reduced forward locomotion.
Interestingly, the effects of the Dop1R1-knockdown were also observed when it occurred locally only in the mushroom body, one of the central brain regions in insects [71]. The dopamine neurons innervating the mushroom body play a crucial role in signalling reward or punishment information in associative learning [30,[72][73][74][75][76]. The mushroom bodyinnervating neurons covered by TH-Gal4 are mostly linked to punishment signalling, with the reward-signalling dopamine neurons notably missing in the expression pattern [72,77,78]. This raises the question of what the activation of these neurons 'means' to the animals. On the one hand, stopping and turning can be interpreted as an avoidance behaviour in response to a sudden punishment signal (for a similar interpretation regarding the activation of dopaminedownstream neurons, see [79]). On the other hand, an excessive release of dopamine, as probably happens in our experiment, may cause malfunctions in the motor control pathways, similar to what was observed upon cocaine administration in adults [68]. The fine genetic tools available make the Drosophila larva an ideal study case to answer this question. Dopamine neurons can be manipulated in small subsets and even one by one [73][74][75] to find out which neuron causes which behavioural reaction.

Switching from forward to backward locomotion, and back again
In free, undisturbed locomotion, Drosophila larvae normally crawl forward, and backward crawling is very rarely observed. They do, however, perform short bouts of backward locomotion on encountering an obstacle or receiving a noxious stimulus to their head [80,81]. Thus, backward locomotion can be seen as part of an avoidance reaction. In recent years, several Gal4 driver strains have been described that cover neurons which induce backward locomotion upon activation [52,81,82]. One of them, R53F07-Gal4, we used in the present study [52]. We described many facets of the behaviour of individual animals over extended phases of backward locomotion, including the bending and head-casting behaviour that had not been looked at in previous studies [52,81,82]. We found, for example, that during backward locomotion bending was increased in amplitude, but decreased in variability, and that the HC rate was decreased compared to forward locomotion ( figure 11h-k). Moreover, we found that larvae did not revert to forward locomotion immediately after the optogenetic activation terminated. Rather, they continued to crawl backward for various time periods, and then quickly switched to forward locomotion (electronic supplementary material, figure S12). Both kinds of switches were accompanied by characteristic changes in speed and bending behaviours (figures 12 and 13). The reason for the inter-individual variability in reverting to forward locomotion is unknown. In this specific case, in addition to general genetic variation, differences in transient internal states or behavioural idiosyncrasies (see above), also differences in transgene expression strength may contribute to the inter-individual variability. At the neuronal level, both forward and backward locomotion are characterized by waves of activity in the motor neurons and interneurons of the segmented VNC, which travel from anterior to posterior during forward locomotion, and the other way around during backward locomotion [8,53,83,84]. More specifically, two pairs of command-like neurons have been identified in the rather broad expression pattern of R53F07-Gal4, called mooncrawler descending neurons (MDNs), which inhibit forward and induce backward locomotion [82]. It is likely that the effects of activating R53F07-Gal4 neurons come about through these MDNs. Two main effects of activating the MDNs have been proposed: on the one hand, one of their main downstream partners, called Pair1, stops forward locomotion by inhibiting the forward movement-inducing A27h neuron; on the other hand, another downstream partner, A18b, induces backward locomotion specifically in the most anterior segment of the VNC [11,14,82]. Remarkably, both the MDNs and Pair1 neurons persist through metamorphosis, and induce analogous behavioural effects in adult flies [82,85,86].
It is a straight-forward assumption that the switches between forward and backward locomotion that we describe here may be caused by the backward movementinducing A18b and the forward movement-inducing A27h neurons, respectively. The observation that larvae did not revert to forward locomotion as soon as the optogenetic activation ended suggests that activating the MDN → A18b pathway leads to backward locomotion that continues until forward locomotion is triggered again, potentially by A27h. Our behavioural approach, together with the available tools for fine circuit analysis, is suited to test this hypothesis.

Utility for analysing individual behaviour
The IMBA software introduced here can serve to track, visualize and analyse the behaviour of individual Drosophila larvae within groups. The IMBA is compatible with wellestablished, standard Petri dish assays and requires no specific additional hardware beyond reasonable light conditions and a camera. In this study, we only used videos of up to 4 min, as many standard Petri dish assays are performed in a similar time frame. Longer videos can be processed by the IMBA, but larvae tend to follow the Petri dish walls where they are very difficult to track. Therefore, attempts to use longer videos require precautions such as larger behavioural arenas, or borders that do not reflect light and therefore allow for the tracking of the larvae. In any case, the present study features data from setups located both at the Leibniz Institute for Neurobiology and the University of Leipzig, which use different means of lighting, cameras and video quality. We also successfully tracked videos from previous publications from other laboratories [26,43]. In total, we used five kinds of videos with different resolutions, cameras and light settings which we could successfully track. Electronic supplementary material, movies S1-S5 show the results of these tracking attempts and demonstrate the wide variety of video qualities that could be handled. Such robustness makes the IMBA a useful tool for studying a broad range of research questions using derivatives of this standard assay. In the present study, we focused on locomotion and used the IMBA to compare innate and learned behaviour in odour gradients (figures 2-4, electronic supplementary material, figures S4-S7), phenotype a mutant (figures 5-7) and study the effects of optogenetic neuronal activation (figures 8-13). Other future applications may include the screening of pharmacological effectors [87] and libraries for RNAi knockdown, and comparisons across inbred strains of Drosophila or across species.
A critical property of the IMBA that allows for such broad use is that we included a large number of behavioural attributes that can be adapted and extended by the user (the full list is available online under https://github.com/ mthane/IMBA). Among them are 22 attributes describing behaviour relative to a local stimulus. This makes the IMBA useful for experiments on behaviour towards stimuli such as odours, tastants, light or temperature, as well as for analysing stimulus-related behaviour after various types of learning experiment (as we exemplified in electronic supplementary material, figure S7). Importantly, we combine this large number of behavioural attributes with an approach to selecting the most relevant ones for each particular dataset in an unbiased way. Random forest analysis provides a ranking of behavioural attributes according to their importance for differentiating animals in the particular experimental conditions of the particular dataset under study (compare figures 8c and 10c). This includes attributes that do not differ in their centres of distribution (and thus result in non-significant standard statistical tests) but rather in the distribution of the data (figures 6f and 8h).
The IMBA is versatile for analysing relatively fine-grained temporal patterns of behaviour. This has led us to discover stumble stepping in Cirl KO mutants ( figure 7). Indeed, the IMBA allows for the analysis of even more extreme kinds of 'silly walks' that it was not designed to study, such as the backward locomotion elicited by activation of MDN neurons (figures [10][11][12][13]. Furthermore, the IMBA lends itself to protocols that involve repeated experimental stimulation, as in the case of the repeated activation of select sets of neurons (figures 9 and 13). This should make it possible to establish larval versions of paradigms such as prepulse inhibition or repetition priming, which are workhorse paradigms in the experimental neuropsychology of rodents and humans. Last but not least, the IMBA allows data to be aligned to changes in behaviour (that is, to the time of action initiation rather than stimulus application), revealing effects that would otherwise be masked by differences in action-timing between individuals (figures 12 and 13).
A crucial step for the above-mentioned applications is the ability to resolve collisions. Obviously, some of the results we reported here could also have been obtained at the level of sub-individual tracks or group averages. But many of our findings required to analyse the behaviour of individuals, such as the comparison between inter-and intra-individual variability, the repeated neuronal activation experiments or the alignment to the switches between forward and backward locomotion. Without collision resolution, such analyses would either require recording animals one by one, or would need to be made on a much smaller database, restricted to those few animals that happen to not collide with others, which is potentially not representative of the whole population of the experiment (electronic supplementary material, figure S1d). We are not aware of any other ready-to-use tracking software that can perform similar analyses for animals tested in groups. The arguably most complete and widely used tracking approach for larvae so far, the FIMtrack, does not yet include such collision resolution [24,25,31]. In addition, the FIMtrack software provides basic attributes like bending and velocity, but no more detailed attributes like the inter-step distance and interval, HC angles or angular speeds that we employed here. Modifying the FIMtrack is possible but requires at least basic programming skills. In table 5, we compare the capabilities between the FIMtrack and the IMBA.
In summary, the IMBA is an easy-to-use toolbox providing an unprecedentedly rich view of behaviour and behavioural variability across the multitude of biomedical research contexts in which larval Drosophila can be used.

Datasets
We used seven different datasets for our analysis: • A set of 102 videos with 1852 individual animals entering the analysis was used for figures 1-4, electronic supplementary material, figures S1a-d, S3, S4a-d, S5 and S7. Wild-type larvae of the Canton-S strain were tested for odour preference, either innately or after odour-sugar training, on Petri dishes of 15 cm over 3 min. Note that figures 2 and 3, electronic supplementary material, figures S1, S3, S4a-d and S5 only use the innate condition (48 videos, 875 individuals). These data were previously published in [28], and are re-analysed in this study regarding individual animals. The used wild-type Canton-S strain originated at the University of Würzburg and was continuously inbred since at least 2009.

Behavioural experiments 4.2.1. Animals
Third-instar feeding-stage larvae (D. melanogaster), aged 5 days after egg laying, were used throughout. Flies were royalsocietypublishing.org/journal/rsob Open Biol. 13: 220308 maintained on standard medium, in mass culture at 25°C, 60-70% relative humidity and a 12/12 h light/dark cycle. We took a spoonful of food medium from a food vial, randomly selected the desired number of larvae, briefly rinsed them in tap water and started the experiment.
For the experiments regarding the Cirl mutant, we used two genotypes: the Cirl KO null mutant and a genomic rescue strain, Cirl Rescue . For a detailed description of the genotypes, see [42].
For optogenetic experiments, we used transgenic larvae to express the ChR2-XXL light-gated ion channel in DANs. To this end, the effector strain UAS-ChR2-XXL (Bloomington Stock Center no. 58374) [51] was crossed to one of two driver strains: either TH-Gal4 (Bloomington Stock Center no. 8848) or R53F07-Gal4 (Bloomington Stock Center no. 50442) to obtain double-heterozygous offspring. As driver controls, the driver strains were crossed to a local copy of w 1118 (Bloomington Stock Center no. 3605, 5905, 6326). As effector controls, either w 1118 , or a strain carrying the landing site used for the Gal4 (attP2), yet without a Gal4 domain inserted (empty) [89], was crossed to UAS-ChR2-XXL. Because ChR2-XXL is sensitive enough to be activated by daylight (not shown), the flies were raised in vials constantly darkened by black cardboard wrapping.  [24,25,31]. The cross-platform tracking was done as described in the results part of this study. were mounted to provide illumination that was invisible to the larvae, yet allowed the recording and tracking of their behaviour for offline analysis. To this end, a camera (Basler acA204090umNIR; Basler, Ahrensburg, Germany) equipped with an infrared-pass filter was placed above the Petri dish. Experiments were performed by placing seven to eight larvae in the middle of a Petri dish, and letting them walk freely for 2 or 4 min. The first 30 s were in darkness, followed either by a 30 s light stimulation period and another 60 s of darkness, or by three cycles of 10 s light stimulation and 60 s of darkness.

Tracking
We developed the IMBAtracker to track multiple larvae on a single Petri dish while keeping track of their identity. Although several tracking solutions have been developed in recent years [18][19][20][21][22][23][24][25][26][27][28], the development of new tracking software seemed necessary to ensure two important aspects: first, increasing and controlling the overall measurement precision according to the needs of the analysis; second, reducing the data fragmentation caused by collisions or by the larvae leaving the region of interest. This attempt to reduce fragmentation is especially important since it paves the way for the individual-level analysis.

Architecture
The tracker is designed to process a region of interest (the Petri dish area), which is defined per video. We do not require the region to contain all the objects of interest at all times (i.e. larvae can exit the region of interest). Videos should be made from above or below with a minimum resolution of 30 pixels per animal (although higher resolutions improve accuracy). Either a light background with dark objects or a dark background with light objects is supported, and any colour information is discarded as the image is converted to greyscale. In order to deal efficiently with the issue of fragmentation, it is crucial to separate the tracking into three distinct phases (see below). The general architecture is depicted in figure 14.

Implementation
The software is written in C++ using OpenCV [90] as a base for input-output and image processing, lpsolve for linear optimization, and further standard algorithms and data structures. This ensures fast processing of the videos, which can be performed on a commodity PC. A simple user interface (written in Python) is provided.

First phase
The first tracking phase works similarly to other tracking software: we perform image processing, segmentation and extraction of objects of interest as connected components. However, instead of discarding objects during collisions, the contours are used to detect and record the types and objects involved in those collisions. An overview of the process can be seen in figure 14a.
We perform the following image-processing steps to extract the foreground from the background and to separate our objects of interest: Background subtraction. We opt for a very simple background subtraction. The background model consists simply of the pixel-wise average value of 100 equidistantly spaced frames of the central third of the video to increase robustness against sudden video changes towards the beginning or end of the video.
Thresholding. A threshold separates the image into two classes: the objects of interest in the foreground, and the background. To perform this thresholding in an automated  Figure 14. Overview of the tracking process. The IMBAtracker works through a sequence of three phases. (a) In the first phase, the image is processed; for example, by background subtraction, objects (blobs) are detected by thresholding, and initial assignments of individual larvae are made (before collision resolution). (b) In the second phase, the head and tail of each larva is determined, and a contour-based model of colliding larvae is applied to undertake a first round of collision resolution. (c) For collisions that could not be resolved in the second phase, the third phase adds a statistical collision resolution approach that compares attributes such as the size of the larvae to match individuals before and after the collision.
fashion we make use of Otsu's method [91], which selects the threshold that minimizes the in-class variance. Blob extraction. This step tries to extract all connected components of the foreground as objects, which we refer to as blobs. For this step we use a library called cvBlob. The algorithm used by the library is derived from Chang et al. [92].
At each video frame we receive new blobs from the blob extraction routine. In order to see how well the blobs match the blobs from the previous frame, we test each blob from the new frame on its overlap with all blobs from the previous frame. Here, we have the following categories: • 1 − 1: 1 blob from the old frame matches 1 blob from the new frame. • 1 ∼ 1: 1 blob from the old frame partially matches 1 blob from the new frame. The latter three cases point to collisions of larvae, as they occur, for example, when larvae merge with one object from a given frame (N − 1), as well as when they split again (1 − N). In this way, blobs that consist of several larvae can be separated from blobs that probably only consist of a single larva. This information can be visualized in a collision graph with parental nodes (blobs that split into several new blobs) and child nodes (blobs that emerge from the parental node) that will be used in the second phase of the tracking.
For those blobs that could be single larvae we try to extract some key information on the shape. To do this, we first reconstruct the contour using parametric cubic smoothing splines. We generate a contour of 200 points for each blob based on the splines. We then compute curvatures of the reconstructed contour points and, after applying a multiple-pass moving average filter over the contour for noise reduction, we detect the two biggest local maxima. These indicate the endpoints (head, tail) of the larva and are the base for the spine reconstruction. We always match the endpoints across frames based on distance, thereby storing the trajectories of each endpoint during the track. For cases where the continuation is unclear (such as where there is curling or a spine cannot be reconstructed), the track is interrupted and split into subtracks in which the endpoints' trajectories are continuous.

Second phase
After the basic processing of the video, we attempt to clarify and reduce the fragmentation of the data by merging subtracks. We initially work on two aspects, the larva count in each blob and accurate head/tail detection. We then tackle the issue of fragmentation.
To clarify whether a blob is a larva or a cluster of colliding larvae, we observe that a good approximation of the contents is given by trying to find the minimum number of larvae needed to fulfil the parent-child constraints, namely that parental nodes have the same number of larvae as their children nodes. We formalize this as a linear optimization problem over a collision graph. Nodes store the uncertain number of colliding larvae, which is to be determined during optimization, and edges represent the parent-child relationship.
Given the collision graph G(V, E), where V are the nodes and E the set of edges (i, j ) from node i to node j, we want to solve the following integer optimization problem: where vector x = (x 1 ,…, x n ) contains the number of larvae for every node i as components x i , vector 1 = (1,…, 1)∈{1} n and the system of inequalities Ax ≤ b is constructed from the following two constraints with the sets of parent nodes P i and child nodes C i of a node i.
The number of larvae x i in a blob i is at least the number of incoming parent edges, outgoing child edges or 1, whichever is highest: The number of parent larvae and the number of child larvae of every blob, more specifically every internal node i, should be in balance: Note that this equality constraint can be rewritten as two non-strict inequalities for the system of inequalities in the above minimization problem.
Matrix A is totally unimodular, which guarantees that the problem is tractable, that we can use linear optimization techniques to solve it, and that these techniques will return integral solutions only [93].
We can now proceed to disambiguate the head/tail assignment. As mentioned above, all larva tracks are split into subtracks in which the endpoints have clear and continuous trajectories. For these trajectories we calculate several metrics per endpoint (figure 14b, middle panel), such as • Average brightness around 10 pixels of the endpoint • Total distance covered • Total distance of the endpoint relative to the centroid in the previous frame, i.e. the endpoint moves towards or away from the centroid.
The head is then assigned according to votes from each of these measurements. We assign one head vote to endpoint A and one tail vote to endpoint B in each of the following cases (and the reverse otherwise): • Average brightness of A < Average brightness of B • Total distance covered of A > Total distance covered of B • A moves away from the centroid We assign endpoint A to be the head if it has more head votes than endpoint B; otherwise we assign B to be the head.
As our main interest lies in studying the behaviour of freely moving larvae, we do not try to disentangle their behaviour within a collision. In order to decrease the fragmentation of tracks, we decided first to disentangle the ephemeral collisions. During these, behaviour should be minimally affected, and their elimination should allow for longer tracks and greater preservation of identity.
We define a larva shape model for tracking purposes based on orientation and four joint angles as depicted in figure 14b (right-most panel). In order to avoid wrong assignments, we restrict this larva model to ephemeral collisions (i.e. collisions of two larvae that last less than 8 s, or short touches of single larvae on larger blobs). This representation is initialized for the collision participants one frame before the collision, using the values that we have already calculated. For each frame of the collision, the contour of each larva in collision is approximated by subtracting the contours of the counterparts from the previous frame from the complete contour of the current frame. We then search, using a brute-force grid search, through the parameter space (i.e. orientation and joint angles) for the best neighbouring fit of our model to the approximated contour. When the collision is finished we compare the centroids of the collided models of the last frame of the collision to the new larvae coming out of it and assign the closest match.

Third phase: statistical collision resolution
The first approach for resolving collisions, described above, is limited to collisions of two larvae that do not take longer than 8 s. For collisions that involve up to three larvae, or take longer, a second approach for collision resolution based on statistical attributes is adopted. In brief, for each larva entering a collision that was not already resolved by the first approach, the distributions of its body length, width, area and perimeter values are compared by non-parametric testing with those of each larva leaving the collision (figure 14c).
Taking a collision of two larvae as an example, we first perform a principal component analysis (PCA) over the standardized values of the body length, width, area and perimeter, using only the first resulting principal component, which explains about 83-94% of all variance in a test dataset, for all further steps. Then we perform Mann-Whitney U-tests between the two ingoing and the two outgoing larvae, and compare the resulting p-values. The rationale is that a high p-value indicates little difference between the data, so the higher the p-value, the higher the chance that an ingoing and an outgoing larva are actually the same individual. Such comparison is legitimate if all the tests include the identical sample size [94]. Therefore, we restrict the tests to the minimal number of frames for any larva involved (i.e. the frames before the collision for the ingoing larvae, and the frames after the collision for the outgoing larvae), up to a maximum of 45 frames, as higher frame numbers decreased the rate of correct assignments in a test dataset (not shown). With two ingoing (larvae 1 and 2) and two outgoing (larvae A and B) animals, there are only two logical assignments: either 1-A and 2-B is correct, or 1-B and 2-A. A collision is resolved if both p-values for one assignment are higher by a factor of 1000 (i.e. the larvae are more similar) than both p-values for the other assignment. If no logical assignment can be made, or the difference between the p-values is too small, the collision remains unresolved. Collisions of three larvae are performed in an analogous way. We do not attempt to resolve collisions of four or more animals, as the chances of a resolution are extremely low.
We also apply this approach to asymmetrical collisions (e.g. when a single larva leaves a collision of three animals or when the tracker loses track of larvae either at the Petri dish wall or at objects such as odour containers in olfactory experiments). In the latter cases, whenever a larva re-enters the arena from the Petri dish wall, for example, it is statistically compared to all larvae that were previously lost at the wall. In these asymmetrical cases, we perform additional U-tests between all ingoing larvae (e.g. all larvae that have been lost at the wall). Such a collision is resolved if the p-value of a test between the outgoing and one of the ingoing larvae is higher by a factor of 1000 than all other p-values. If no logical assignment can be made, or the difference between the p-values is too small, the collision remains unresolved.

Data analysis
The main output of the IMBAtracker is a time series of 12 spine points that reach from the head of the animal to its tail, as well as 24 contour points (figure 1). These data are the basis for all further data analyses and visualizations with the IMBAvisualizer. To prevent multiple tracks from the same individual animal from entering the analysis, we discarded all tracks shorter than half of the video length after the collision resolution.
The spatial resolution in our video recordings was not sufficient to resolve the peristaltic wave along individual body segments. However, we noted that the rhythmic velocity changes of the tail point provided a reliable indicator for the occurrence of one peristaltic forward movement (figure 1). We therefore defined each local maximum in the tail forward velocity as one step, and the period between two maxima, i.e. one complete peristaltic cycle, as an interstep (IS) period (figure 1d). Since the local-maxima detection algorithm we employed also produced false maxima during intervals of little or no forward motion, we discarded maxima detected whenever the tail speed in a forward direction was less than 0.6 mm s −1 .
Lateral HCs are a very prominent feature during larval chemotaxis on a plain agarose surface. We quantified these head movements based on the angular speed of the HV, where the HV was defined as the vector between the ninth and the eleventh spine point (figure 1b). In order to detect HCs to the left (or right) we first detected all intervals of angular speed smaller than −35°s −1 (or larger than 35°s −1 ) (figure 1c). The start and endpoints of these intervals correspond to salient movements of the head part of the animal to the left or right side. We next introduced two criteria in order to discard incorrectly assigned HCs. (1) We discarded any initially detected HC whenever the angular speed of the TV during head casting exceeded 45°s −1 . This criterion takes account of the visual observation that whenever the tail parts of the animal reorient, these periods most likely do not coincide with an active lateral head casting movement, but rather a stretching out of the body bending angle when stepping is resumed. (2) We discarded any initially detected HC whenever more than one step was detected during head casting. This criterion takes account of the observation that any active lateral head casting interval can coincide with at most one forward stepping detection point.
After the detection of runs, steps and HCs, we calculated a number of behavioural attributes. In the following we provide a detailed description of all the attributes used in this study. A full list of attributes implemented by the IMBAvisualizer is available online (https://github.com/mthane/ IMBA). Please note that for some attributes two versions exist, using either mm or individual body lengths (bl) as the unit. Unless explicitly mentioned in the results, it was always the version using body lengths that was applied.

Attributes
We summarize all attributes in this study in tables 1-4. Whenever the behaviour of an individual larva is displayed over time (figure 1; electronic supplementary material, figure S12), the respective attributes are calculated per video frame. Whenever the average behaviour of a group of larvae is displayed over time (figures 8b, 9a,c,e,g, 10b, 12 and 13; electronic supplementary material, figures S9 and S11), the mean and the 95% confidence intervals of the respective attribute are calculated per 2 s time bin. Whenever data are displayed in box plots to compare across experimental conditions, or in scatter plots to determine correlations, the mean of each attribute is calculated for each individual larva across the whole observation period.
For the optogenetic experiments, we were interested in the difference in a given attribute X between different time intervals. In these cases we calculated Δ-values as the difference in X during each of the time intervals. For figures 8 and 10, we calculated X during the 30 s of light stimulation minus X during the 30 s before light stimulation. For figure 9, we calculated X during the 10 s of light stimulation minus X during the 10 s before. In figure 13, we calculated X in the 10 s after a switching point minus X in the 10 s before the switching point. In figure 13, we additionally calculated so-called peak values of the absolute bending angle and the absolute HV angular speed in order to quantify the local maxima of these values at the forward switching points. The peak values were calculated as X during the 10 s interval around the switching point minus X during the 5 s before and the 5 s after that interval.

User interface for visual analysis
The interactive IMBAvisualizer is a visual analytics concept [95]. Visual analytics generally includes approaches such as visually supported dimension reduction techniques [96][97][98] or visual parameterization support [99,100] in order to support a human-centred context-related analysis cycle [101]. The IMBAvisualizer was created using the R programming language [102] and the Shiny library, which allows user interfaces to be built for data visualization [103]. For this, the analysed datasets are saved in RDS files which are serialized R objects. These RDS files can be uploaded in order to plot various visualizations based on the attributes that are calculated. In addition, the data are saved in CSV files that can easily be opened and further processed by other software. In the following paragraphs, we very briefly introduce the essential functions of the software. A detailed documentation can be found online along with the code.
In the 'Individual Mode' the user has the possibility to visualize individual tracks, compare different time series attributes, and compare different tracks. The track selection menu allows multiple tracks to be selected. This way of analysing the data permits a detailed analysis of the time dependent attributes for individual animals which allowed us to find anomalies in the behaviour of the larvae.
Data aggregation allows attributes to be calculated, usually as means or variance, from all the data either on the Petri dish or the individual animal. Using different sliders, it is possible to filter the aggregated data by time, absolute bearing angle, absolute HC angle and the distance from the source of a stimulus, e.g. an odour (in experiments using such a stimulus). For the analysis of backward-walking larvae, it is also possible to filter the data based on the run direction (forwards, backwards). These filtering options permit a detailed analysis for different subsets of the data.
We used random forest models, which were established by Leo Breiman and are based on CART (classification and regression trees) [104,105]. The random forest algorithm works by building N number of decision trees and then predicting the class label of an instance using a majority voting. Each tree is trained on a random subspace of the data, only using a sample of the instances. To evaluate the random forest classification, we used five-fold cross validation, which was repeated three times. Five-fold cross validation means that the test set for the model is used from five different, disjoint sets of the dataset. The dataset is then shuffled, and the procedure is repeated three times. Cross validation is used to make sure that the model is not based merely on the selected data, but can explain the full dataset.
For the applications of the random forest in this study, we pre-selected 30 behavioural attributes to be included (tables 2 and 3). The pre-selection was warranted to avoid using largely redundant attributes (such as the IS speed in both bl s −1 and in mm s −1 ), and to exclude non-behavioural attributes such as the size of the larvae. In order to provide a good estimate of the importance of each attribute, the complete random forest model (including the cross validation) was performed 10 times for any given dataset, and the importance rank of each attribute was noted.

Statistical tests
Two-tailed non-parametric tests were used throughout. When multiple comparisons were performed within one analysis, a Bonferroni-Holm correction was applied to keep the experiment-wide error rate below 5% [106]. Values were compared across multiple independent groups with Kruskal-Wallis tests (KW tests). In the case of significance, subsequent pair-wise comparisons used Mann-Whitney Utests (MW tests). In cases of within-animal comparisons we used Wilcoxon signed-rank tests (WS tests). For correlations, we employed Spearman's rank correlation test (SC tests).
Data accessibility. All raw data used for analyses and figures in this study are available as electronic supplementary material to this article [107]. The complete code of the IMBA software is available via https:// github.com/mthane/IMBA.