Correcting locomotion dependent observation biases in thermal preference of Drosophila

Sensing environmental temperatures is essential for the survival of ectothermic organisms. In Drosophila, two of the most used methodologies to study temperature preferences (TP) and the genes involved in thermosensation are two-choice assays and temperature gradients. Whereas two-choice assays reveal a relative TP, temperature gradients can identify the absolute Tp. One drawback of gradients is that small ectothermic animals are susceptible to cold-trapping: a physiological inability to move at the cold area of the gradient. Often cold-trapping cannot be avoided, biasing the resulting TP to lower temperatures. Two mathematical models were previously developed to correct for cold-trapping. These models, however, focus on group behaviour which can lead to overestimation of cold-trapping due to group aggregation. Here we present a mathematical model that simulates the behaviour of individual Drosophila in temperature gradients. The model takes the spatial dimension and temperature difference of the gradient into account, as well as the rearing temperature of the flies. Furthermore, it allows the quantification of cold-trapping and reveals unbiased TP. Additionally, our model reveals that flies have a range of tolerable temperatures, and this measure is more informative about the behaviour than commonly used TP. Online simulation is hosted at http://igloo.uni-goettingen.de. The code can be accessed at https://github.com/zerotonin/igloo.

Aversive stimuli are avoided more strongly in groups than by single individual 26 and sensing as well as decision making are enhanced in groups 27,28 . Both factors will bias the individual sensation and eventually the T P of a fly. Especially in spatial tasks (e.g. positioning within a temperature gradient) individual-based models surpass group models 29 . This can be exemplified by swarm behaviour in many different species including humans (reviewed in [30][31][32]: Only a small number of informed animals are needed to steer a large group (e.g. fish swarms 33,34 , reindeer herds 35 , groups of humans 36 ). In our case this would imply that only a few individuals have to align their T P to steer the whole group into their vicinity, which highlights the importance of testing individual preferences from an ethological point of view. Scrutinising the underlying physics of group models, it becomes clear that, as no two individuals can occupy the same space at the same time, a spatial distribution has to be broader in a simulation of a cohort than of an individual. This argument can be directly taken from theoretical physics which states that the probability density of gas molecules in a temperature gradient is flat regardless of temperature, but the probability density of a single molecule is shifted to colder temperatures.
Using a large behavioural database of D. melanogaster larvae and adults measured at different temperatures, we formulated a null model named IGLOO (IGLOO is a Gradient LOcomotion mOdel) that extends existing models. The model we propose allows simulating individual fly trajectories as a function of the ambient (T A ) and rearing temperature (T R ). Even though the model cannot predict individual fly behaviour it provides an estimate of the population behaviour of flies with no preference in a thermal gradient. We show that T R strongly influences locomotion at different T A , and offer a null model to correct for these and other biases introduced e.g. by cold-trapping. IGLOO distinguishes between the canonical absolute T P measurement, and the range of tolerated temperatures and avoidance of temperature, reducing the number of experimental trials and tested animals needed, and increasing the information obtained from gradient experiments. IGLOO´s most striking feature is its ability to predict if a mutant phenotype arises on the level of internal or external thermosensory systems.

Results
Our model is a simple random walk model (review 37 ). In general, random walk models include an agent that moves in steps of random direction through a virtual environment. Our environment is a one-dimensional temperature gradient in which the temperature between both extremes is linearly distributed. Therefore, our agent, the simulated fly, can only move up or down the gradient. Each step of our agent represents a bout of walking for the fly. The step size is derived from the step velocity and the step duration, which both depend on body temperature (T B ). The fly's T B is calculated by the ambient temperature (T A |see Eq. 4). In pseudocode, our model works as follows (compare Fig. 1): 1. Update body temperature from ambient temperature (Eq. 4., see Methods) 2. Pick a random number (0.0 to 1.0) = P V 3. Calculate a step velocity from histogram fit using P V (Eq. 2, see Methods) 4. Pick a random number (0.0 to 1.0) = P D 5. Calculate step duration from histogram fit using P D (Eq. 3.2, see Methods) Figure 1. Model Schematic. The red to blue bar represents the temperature gradient, with extremes as indicated. The simulated fly at time t 0 is positioned at the warmer end and therefore its cumulative distribution fit functions would more often render fast velocities and long bout durations than at time point t i . The fit fuctions are used basically as look up tables for the step generation. Circled numbers indicate the following procedural steps: 1. Update body temperature from ambient temperature. 2. Pick a random number (0.0 to 1.0) = P V . 3. Calculate a step velocity from histogram fit using P V . 4. Pick a random number (0.0 to 1.0) = P D . 5. Calculate step duration from histogram fit using P D . 6. Pick random direction (50%+ to 50%−) = P Dir . 7. Make Step. Graphs do not show real data and omit the influence of the rearing temperature (T R ).
Note that this can create steps that could make the agent (fly) collide with the gradient extremes. In these cases, the walls reflect the animal, and the animal instantly reverses its direction. This is equivalent to an infinite environment with repetitive sawtooth temperature gradients. Phases 1 to 7 are repeated until the accumulated step duration exceeds the simulation duration. Then the trace of the agent through the environment can be calculated as well as the probability density in the temperature gradient.
The model is based on Benzer climbing assays of flies reared at different temperatures (T R ) and larvae moving at different T A . Histograms of the velocity and bout duration of over 400 individual flies in total allow building a probability function for a bout of walking at a given temperature. Each individual bout has a certain velocity and duration, based on the T B and the T R of the modelled individual. We found qualitative and quantitative differences in the locomotion behaviour depending on the T A (Fig. 2). A clear influence of the T A on the median speed was observed ( Fig. 2A). Larvae (wt L ) and adults showed almost no movement at very low ambient temperatures, and their median speed increased with T A . Wild-type adults raised at 30 °C (wt 30 ) were generally slower ( Fig. 2A) and, compared to adults, larvae showed a higher average velocity. It should be noted that wt 30 flies were generally less active as well as viable and that a large proportion of their larval population died before or during pupation.
The second attribute our model is based on is the walking bout duration. This duration is constant over a large T A range for wild-type adults raised at 18 °C (wt 18 ) or at 25 °C (wt 25 ), only wt L reduce their bout duration significantly below 18 °C T A and above 38 °C T A (Fig. 2B). wt 18 were more active at lower T A than wt 25 or wt 30 , whereas the opposite effect was seen at higher T A (supp. Fig. 1). The activity index is the fraction of time the animal spent moving. wt 18 and wt 25 are able to sustain high activity levels throughout a large part of the T A spectrum, while wt 30 has a more erratic activity pattern (see discussion). wt L show very little activity in the lowest part of the range but www.nature.com/scientificreports www.nature.com/scientificreports/ if T A was above 10 °C the activity index (see materials and methods) increased up to 60%. wt L seem unaffected by the hottest ambient temperatures of the spectrum, unlike adults (supp. Fig. 2D).
To make the model simulation faster we fitted functions to the histograms as shown for wt 25 in Fig. 2C,D and for other strains in supp. Fig. 2. All further calculations shown in this article were also undertaken on the respective original histogram, qualitatively and quantitatively producing nearly identical results.
One of the most striking direct results was the emergence of similar µ (µ = central value of the Gaussian dis-tribution|σ width of the Gaussian distribution) in the temperature Gaussian functions of the fits to velocity and duration. As can be seen in Fig. 2C,D (arrows), our model centres these Gaussian functions for wt 25 at μ = 26 °C and σ ≈ 5.41 °C, and μ = 34 °C and σ = 2.27, respectively (temperature and bout duration). These temperatures resemble the thermal optima for transduction channels in thermosensation (dTRPA1: 25 °C 5 ) and nociception (>38 °C 2,4,38 ) of adult flies.
To simulate the probability density of a fly without T P in a thermal gradient we used the aforementioned equations in a random walk paradigm. In the initial state the fly's T B equals the T A . The model uses the interpolated probability function to determine the velocity and duration of a bout based on T B . The direction of the bout is random. T B is updated with respect to T A via the thermal transduction equation described in the Methods section, functionally equalling a low pass filter (Fig. 3A).
We simulated one thousand flies to obtain a null-probability density of a fly without T P (e.g. Fig. 3B). As can be seen in Fig. 3C, after about 10 minutes (50 min for wt 30 ) a stable ratio is formed in which a large percentage of the flies aggregate at the cold end of the gradient, apparently being cold-trapped. In a modelled temperature gradient ranging from 14 °C to 32 °C, the probability of cold-trapping, as well as the overall distribution within the gradient (see Fig. 3B, supp. Fig. 3 and sup. Fig. 4), depend on T R of the flies and the developmental stage (Fig. 3D). When starting from a medium or high temperature, however, all strains take equally long to become cold-trapped for the first time ( Fig. 3C), with the exception of wt 30 and wt L , which took much longer due to their slow speed of locomotion (compare Figs 2A and 3C). We found that after running the simulation for 10 minutes, a stable distribution of approximately 70-80% cold-trapped adult flies and approximately 60% cold-trapped larvae was always established (Fig. 3D), except for wt 30 which needed 60 min. wt 18 flies were less frequently cold-trapped than wt 25 and wt 30 . However, the distributions of non-cold-trapped flies were non-linear in the warmer range of the gradient and differed between T R cohorts.
By subtracting the modelled null distribution from the measured distribution of adult flies in a temperature gradient, avoidance, T P and tolerances can be easily identified and visualized (see Fig. 4A-C). As a result of using the 95% confidence interval (CI) of the median we can directly infer statistical significance. If the 95% CI of the measurement encloses the model prediction there is no significant preference or avoidance of the respective temperature. If the CI of the measured data is entirely below the model, this temperature is avoided (p < 0.05) or if the CI is entirely above the model this temperature is preferred (p < 0.05). Furthermore, there are values that are not significantly avoided or preferred at the fringes of the tolerable temperature zone (grey value Fig. 4A-C). Our analysis allows for a more differentiated interpretation of temperature behaviour.
To test the model, we assessed the T P of wt 18 and wt 25 in a temperature gradient and corrected the measured distribution. After the correction, we calculated the new T P (Fig. 4D), the start of cold and hot avoidance, and the range of tolerated temperatures. The mean T P was increased after the correction in both groups tested, proving that cold-trapping biases T P and that a correction of T P is needed. The change in T P was significant for wt 25 but not for wt 18 , suggesting that wt 25 are more susceptible to cold-trapping. The median T P obtained for wild-type (22.5 °C) corresponds well to already published T P 19,39 when taking the low humidity in the temperature gradient into account 40 . Although wt 18 distributed more broadly in the gradient than wt 25 (supp. Fig. 5), the overall T P , and the start of hot and cold avoidance were similar for both groups. This suggests that although there is an effect of T R on locomotion speeds ( Fig. 2A), this in fact does not affect T P (Fig. 4D).
As a proof of concept we tested two fly strains with impaired heat sensation, i.e. flies with ablated hot sensing neurons in the arista (hot cells) and a genome-wide knock down of the heat sensitive channel dTRPA1 (dtrpA1 ins mutants). We also chose a strain with impaired cold sensation (i.e., brv2 MI04916 mutant flies lacking Brivido2, a channel involved in cold sensation 8 ) to test if IGLOO would reveal their T P faithfully, without masking the original phenotype. To ablate hot cells (HC) we expressed the apoptotic factors Hid and Reaper 41,42 in HC using a HC-Gal4 driver line. Both HC-ablated and dtrpA1 ins have a well-characterised heat-sensing impairments 5,8 . The three mutant cohorts were reared at 25 °C.
The median T P was significantly increased in drtpA1 ins after correction, however the resulting median T P was not significantly increased compared to wt 25 controls (Fig. 4D). Nonetheless both the start of hot avoidance (Fig. 4E) and the range of tolerated temperatures (Fig. 4F) were significantly increased in these flies. The start of cold avoidance was significantly reduced, indicating that these flies have also problems in cold temperature avoidance.
The median T P of HC ablated flies was also significantly increased after correction. In contrast to drtpA1 ins flies, the resulting median T P was significantly higher than in wt 25 controls (Fig. 4D). This difference was not observed before correction, indicating that cold-trapping was obscuring the hot sensing impairment. The start of hot avoidance was significantly increased, whereas the cold avoidance was unaffected (Fig. 4E). The T P of these flies had a wider range of T P distribution than wt 25 controls which was shifted toward warmer T A (Fig. 4F), indicating that the flies were impaired in heat sensation as expected.
The mean T P of brv2 MI04916 mutants was not significantly different after correction compared to the uncorrected T P , but was significantly lower than in wt 25 controls (Fig. 4D). Additionally, the start of cold avoidance was significantly reduced, whereas the start of hot avoidance was unaffected (Fig. 3E). The overall distribution of these flies was shifted towards colder temperatures, suggesting an impairment in cold sensation. The fact that a cold impairment is still observed after correction shows that correction with IGLOO still allows for the detection of mutants defective in cold sensing. (2019) 9:3974 | https://doi.org/10.1038/s41598-019-40459-z www.nature.com/scientificreports www.nature.com/scientificreports/ www.nature.com/scientificreports www.nature.com/scientificreports/ wt L had a median T P around 18.5 °C and did not show a significant change in the median T P after correction, suggesting that cold-trapping is less severe for larvae than for adults (Fig. 4G). This is consistent with the temperature dependence of locomotion ( Fig. 2A,B). The start of hot avoidance was around 25 °C, and the start of cold avoidance around 16 °C (Fig. 4H). In contrast, dtrpA1 ins larvae had a significant increase in the T P after correction, and their T P was significantly higher than that of wt L . Additionally the start of cold and hot avoidance was significantly increased (Fig. 4H,I). The overall distribution of the mutant larvae in the gradient was shifted to warmer www.nature.com/scientificreports www.nature.com/scientificreports/ temperatures, suggesting that these larvae are impaired in heat sensation. A similar effect as in dtrpA1 ins larvae was observed in ninaE 17 mutants lacking Rhodopsin1, which is supposed to interact with TRPA1 channels and to be indispensable for warm temperature sensation 27 .

Discussion
In this article we provide an individual-based model for temperature gradient locomotion in small ectothermic animals. Especially in ectotherms such as Drosophila, the ability to move strongly depends on T A -a fact that may bias experimental results. Two pioneering models that address the problem were published by Anderson et al. 23 and Dillon et al. 24 . Both are diffusion-based models that simulate cohorts of animals in a thermal gradient and produce overall animal distributions. This is useful for experiments comparing e.g. the resulting null-distribution to a distribution obtained in an experiment. The drawback of group behaviour is the bias caused by group aggregation 25,30,31,36 , which influences sensation 27 , decision making 28 and enhances synchronisation of behaviour 26 .
Hence only a few animals with similar T P might bias the result via aggregation and decrease the natural variation of the behaviour. If tested individually the animals would disperse more as they do not aggregate to the group with similar T P . Therefore, it is not surprising that for locomotion individual-based models are preferred 29 . Given that many studies on thermosensation use group behaviour instead of individual behaviour 5,8,9,19,24 , but differences between group and individual studies in gradient behaviour are regularly observed, the potential choice of individual T P over group T P could become an important consideration when designing an experiment. In any case, modelling single-fly trajectories is essential for a detailed analysis of the behaviour of individual flies. We therefore present a simple model that is based on data of walking Drosophila at various temperatures.
T A strongly influences the locomotor performance in both larvae and adults. The strength of this influence, however, was much smaller in larvae, which revealed an almost linear relation between temperature and speed. These results suggest that larvae may have physiological mechanisms that make them more resistant to cold, probably because they cannot escape as fast as adults. To confirm this, when the experiments were carried out in the gradient to assess T P , larvae never seemed to enter a chill coma like the adults. Nevertheless, a cold bias may compromise the uncorrected larval gradient data since cold temperatures will make larvae slower, making the correction still necessary.
Rearing temperature also influenced the resistance to cold temperatures. Adults reared at 18 °C (wt 18 ) were more resistant and had higher activity in colder temperatures than adults reared at 25 °C (wt 25 ) which also resulted in a lower proportion of cold-trapped animals in the wt 18 simulation. The resistance to cold temperatures in wt 18 is consistent with previous studies demonstrating that development at low temperatures reduces the chill coma temperature and increases the resistance to cold in different Drosophila species [43][44][45] . The difference observed between wt 18 and wt 25 is probably reflected by physiological adaptation to colder temperatures. Development or acclimation to 15 °C increases the tolerance to colder temperatures by lowering the Na + concentration in the haemolymph, preventing the loss of haemolymph water caused by Na + imbalance at cold temperatures 46 . Ion imbalance has been proposed as one of the factors that may generate cold-trapping since extracellular and intracellular ion concentrations influence the excitability of muscles and neurons 47 . The differences seen in wt 30 adults cannot be excluded to be of similar origin, but it has to be noted that these flies walked very slow, died quickly, had very few offspring and large quantities of parental lines were needed to acquire enough adults. It is therefore more likely that the results reflect a general decreased fitness and deficiency in behaviour. Nonetheless, they give insight into the temperature behaviour of Drosophila under extreme hot T R .
An interesting outcome of our analysis was the ability to calculate not only the T p but also the range of tolerable temperatures and the start of hot and cold avoidance. These values allowed obtaining a more detailed picture of the behaviour of different strains, showing that animals tend not to have a specific temperature that is preferred but rather a range of temperatures that they find comfortable, and temperatures that tend to be avoided.
To test if IGLOO could isolate behavioural phenotypes of canonical mutants we tested a number of fly strains with impaired temperature sensation. Overall, flies with impaired thermosensation had a change in the T p , range of tolerable temperatures and start of hot or cold avoidance. Adults carrying the dtrpA1 ins mutation showed a slight increase in mean T P and tolerable range compared to wild-type. This can be explained by the surprising shift in cold avoidance, which increased the range of tolerated temperatures significantly (Fig. 4E,F). This behaviour was not described before. In the original publication by 5 , however, it can be observed that a larger proportion of dtrpA1 ins than of wild type flies prefer a temperature range of 20 °C to 22 °C. The authors pooled the data for temperatures from 18 °C to 22 °C, thereby unintentionally masking differences in avoidance. This explains why in their case avoidance of cold regions near the preferred regions was not different between groups, whereas in the present study, dtrpA1 ins mutants distribute at slightly cooler temperatures.
In contrast to dtrpA1 ins mutants, HC-ablated flies had a clear T P shift and an increase in the tolerable range. TRPA1 is reported to be present in internal sensory neurons which are located in the brain 5,48 , while HCs are external sensors 8,9,49 . It is easy to imagine that a system that cannot judge its desired temperature has a broader tolerance, contrary to a system with a defective sensor that might settle for the wrong temperature. This hypothesis is further corroborated by the larvae experiments. dtrpA1 ins in larvae has been implicated in the sensation of temperatures warmer than the preferred 18 °C by body-wall neurons 13,48,50 . The median T P of dtrpA1 ins larvae is significantly increased, while their tolerance is not (Fig. 4H,I). This resembles the adult HC phenotype (cmp. Fig. 4E,F,H,I).
The difference in T P between late 3rd instar larvae and adults is still present after correction with our model and it is consistent with previous reports 13,19,51 . In addition, the shift to warmer temperatures in dtrpA1 ins larvae and the changes in T P obtained when ablating or silencing hot and cold cells in the adult arista 8 were also present after the cold bias was removed. These examples demonstrate that our model is a suitable tool to study T P and thermal behaviour of small poikilothermic animals and to assess the role of different molecules or groups of cells in thermosensation. Given the simplicity of the model and the premises used for its generation, we believe it can www.nature.com/scientificreports www.nature.com/scientificreports/ be applied to other invertebrate species like mosquitos or nematodes, and ectothermic vertebrates like small fish and amphibians. Even though we only analysed spatial distribution as a measure of T P , also other behavioural measures are prone to bias by cold trapping, i.e. direction and velocity of movement elicited at a given temperature 10,18 . Due to the relation between movement velocity and temperature IGLOO can potentially be adapted to simulate a NULL hypothesis for these parameters by changing the underlying data. Future versions of IGLOO will include this feature. Additionally, further releases will include a more naturalistic movement generation by linking simulated speed to bout duration (see method section).
Using temperature gradients in addition to two-choice assays has become a standard method, in particular when investigating gene and protein function. IGLOO can help with planning such experiments in several ways: (1) determining temperature extremes for both two-choice assays and gradients, (2) thereby avoiding cold-trapping of the flies, (3) building null-hypotheses for a given temperature experiment, (4) planning the optimal duration of an experiment in order to reach equilibrium, and (5) obtaining avoidance, preferences, and tolerances, not just one preference. By integrating data from adult and larval Drosophila, as well as flies that were reared at different temperatures, our model can be applied to a wide range of experimental designs. Furthermore, IGLOO can increase the comparability between studies that use similar methods but differ in essential details such as gradient boundaries or rearing temperatures. Taken together, we anticipate that IGLOO will be a valuable tool for planning experiments and analysing results. Thirty CantonS wild-type flies of each of the three cohorts (reared at 18° (wt 18 ), 25° (wt 25 ), 30 °C (wt 30 )) were tested per temperature (5 repetitions), and the construction of our Benzer test arena allowed us to test up to 15 flies at the same time. The flies were sedated by cooling on ice for 30 seconds before being transferred to the Benzer arena, where they were allowed to recover for 10 minutes at room temperature (18°-20 °C, thermometer model 383T01, Conrad Electronics, Germany) before testing started. In each trial, the flies were knocked to the bottom of the arena and filmed at 30 frames per second while they walked up to the top, using a Hercules Optical Glass camera (Guillemot Cooperation, La Gacilly, France). Filming was stopped as soon as the last fly reached the top of the arena, or, in temperatures in which flies became less capable of moving, filming was stopped as soon as they had clearly settled at a certain position and did not move further upwards.

Methods
Larva crawling assay. The speed of locomotion of 3 rd instar CantonS larvae (wt L ) at different temperatures (8 -40 °C) was tested in the same incubator chamber used for the adults. In total 666 larvae were tested. A layer of agar (1% agarose) was placed on top of an acrylic glass pane with infrared LED inserted into the edges of the pane. Wandering larvae were washed twice in water to remove any food residues and placed on the agar. According to the principle of frustrated total internal reflection 53-55 , the infrared light only passes from the acrylic glass to the agar and from the agar to the larva, and is then reflected down to a camera (Teledyne Dalsa Motion Traveller 300, IS -Imaging Solutions GmbH, Eningen, Germany) that recorded the crawling larva from underneath using Troublepix software (NorPix Inc., Montreal, Canada). This resulted in images with increased contrast as most of the light captured by the camera came only from the larva. Once the larva started crawling it was recorded at 50 frames per second for 3 minutes or until it reached the edge of the arena. At very low temperatures where the larvae did not move the recording was started 1 minute after the larva was placed on the agar. Twenty CantonS wild-type larvae were individually tested per temperature (except for 8 °C where only 16 larvae were tested). The experiments were carried out in darkness for the larvae as they could not detect the infrared light emitted by the LED used in the setup 56 . tracing. The traces of adults were extracted using ivTrace (Jens P. Lindemann, Bielefeld University) and analysed in Matlab with respect to walking speed, overall activity, and bout duration. To calculate walking speed of adult flies, we used only upward movements, as falling flies would have resulted in much higher (downward) velocities. Walking speed was then calculated as the difference of the positions in two consecutive frames divided by the frame duration. Sideward movements were ignored. Bout duration was defined as the time span that a fly kept walking upwards without stopping for more than 1 second. The animal was considered active whenever its forward speed was faster than 0.2 mm/s, i.e. 10% of the body length per second. The activity index is the time spent moving faster than 10% body length per second, divided by the time the animal needed to reach the top. We also analysed whether or not a fly crossed the mid height and reached the top of the arena and used this information as a proxy for the overall fitness of the flies.
Larvae were traced with ivTrace (Jens P. Lindemann, Bielefeld University). The crawling speed of wt L was calculated for the entire duration of the recording, and the bout duration was defined as the duration of crawling before stopping for more than 1 second. Activity was determined in the same way as for adults.
Locomotion in temperature gradient. A temperature gradient was used to determine the T P of larvae and adults. An aluminium slab divided in 5 tracks (dimensions: 50 mm × 3 mm × 3 mm) was used to generate the gradient. The cold side of the gradient was generated by placing a brass cylinder containing ice water with salt on the aluminium slab. The hot side was generated by heating soldering irons. The gradient generated ranged from 14 °C (±1 °C) to 30 °C. For better temperature conductance no agar was used in the arena. Once the gradient was generated a larva or adult was placed into each track to obtain individual T P of each animal tested. Adults were anesthetised on ice before being placed in the arena. A translucent acrylic glass covered the tracks to prevent the animals from escaping. The acrylic glass was coated with Sigmacote (Sigma-Aldrich) to prevent the animals from crawling on it. The animals were allowed to walk/crawl and settle in the gradient for 11-12 minutes and were then recorded for 5 minutes at 50 frames per second. The relative humidity was 27% during recordings.
The temperature of the arena was recorded at a rate of 10 Hz by 30 thermoresistors (SEMI 833 ET, B + B Thermo-Technik GmbH, Donaueschingen, Germany) that were distributed inside the arena. The signal from the thermoresistors was collected by a program running on an Arduino Micro chip (arduino.cc) and sent via serial communication to a PC running Matlab. This allowed to monitor the gradient online and store the data for further analysis. The traces of the recorded videos were extracted using ivTrace to obtain the position of the animals in the arena over time. This position was then correlated with the temperature recorded for the same position in the arena for every frame to obtain the position of each animal in relation to temperature over time.
Null model for temperature-dependent locomotion -IGLoo. We use a Random Walk Monte Carlo-type (RWMC) model to simulate a fly that has no T P moving in a temperature gradient. IGLOO assumes that flies move randomly within the gradient, but that the speed and bout duration depend on the local temperature. Both parameters were obtained from the Benzer gravitaxis assay and larval crawling data. Further assumptions were that a) the thermal gradient is stable, linear and one-dimensional, b) moving towards the hot or the cold part of the gradient is equally probable at every point in the gradient, c) the upper and lower borders of the gradient are reflective, and d) bout duration and bout velocity are independent. The last point was chosen for computational ease. The bout duration is correlated to the median velocity, as the animal has to accelerate during the bout (Pearson's correlation coefficient 0.71924). The assumed independence of both parameters results in an underestimation of the distance travelled. Fortunately, the environmental temperature and the difference in correlated and uncorrelated distance are independent (Pearson's correlation coefficient 0.22477). Thus, we underestimate the travelled distance for high and low temperatures similarly and expect the resulting spatial null distribution to be affected minimally. The reflective borders were chosen as they resembled a behaviour often observed in fast moving flies: Flies that approached the end of the gradient with high velocity were often able to turn around and move out of the cold/hot zones. Slowly approaching flies were more often trapped.
We derived a formula to interpolate the temperature dependent locomotion of Drosophila based on the Benzer experiment and larval crawling data (see Equation 1, Fig. 1). We used fitted interpolation functions and not the discrete temperature values from the empirical data, to be able to simulate a continuous range of temperatures in the simulation. This formula consists of three terms: (1) a randomly assigned heading, represented by ±1, (2) a velocity term (in mm/s) v(p, T B T R ) and (3) a duration term d(p, T B , T R ), where T B is the body temperature, T R is the rearing temperature and p is a probabilistic value. The velocity v and the duration d are calculated and multiplied, rendering a distance that is added to the position of the animal, resulting in both a new position and a new ambient temperature.
The velocity function can be easily fitted with a two dimensional function consisting of Gaussian distributions (Eq. 2). In the temperature domain we need two Gaussians, one with a μ t1 of 26 °C and a σ t1 of about 5.41 °C and a second one with μ t2 = 34 °C and σ t2 = 2.27 °C. The probability domain can also be fitted with a Gaussian (μ = −1.49; σ = 0.5). We can fit the influence of the rearing temperature exclusively with the factor α. The fits for α are rather crude using rational or polynomial functions and are only defined within the limits of 18 °C ≤ T R ≤ 35 °C (rearing temperature). As rearing flies below and above these values is unlikely to be successful, this should encompass most encountered rearing temperatures.
The bout duration function can be denoted as a combination of three Gaussian functions (see Eq. 2) but only needs two rearing dependent factors (σ µ , IGLOO simulates larval temperature dependent locomotion with the identical constraints and assumptions as it does adult behaviour, compare Eqs 1 and 3.1.
The major adjustments of the algorithm are firstly that is does not include T R , as we only measured data for larvae raised at 25 °C. Secondly, larvae exhibited much stronger thermal resilience than adults (see Fig. 2), making adjustments in the interpolation formulae necessary. The larval velocity function is a product of a fourth degree (2019) 9:3974 | https://doi.org/10.1038/s41598-019-40459-z www.nature.com/scientificreports www.nature.com/scientificreports/ polynomial for the temperature domain and a third degree polynomial for the probabilistic domain.This derives a steady velocity profile that drops off sharply below 10 °C. Also the duration function had to be adjusted, as it is now the sum of two products of two Gaussian functions. The µ values of the temperature dependent Gaussians are 9.0 and 34.0, respectively.

thermodynamics of the Drosophila body.
A simple thermodynamic conduction model, rather than just applying the T A , determines the T B of the modelled animal. To estimate the body surface and conductivity roughly, we simulate Drosophila as a cylinder of water with a radius of 0.5 mm and a length of 2 mm, resulting in a surface of 7.85 mm 2 . The heat conductance of water is 0.6 * W m K 2 (see 57 ). To determine the change in temperature we used the heat flow formula (see Eq. 4), where λ is the heat conductance, A is the surface, D denotes the wall-to-wall thickness and T marks the two different temperatures. In our case, we multiplied the heat flow, which has the unit Joule per second, with the bout duration (t) in seconds.
Note that the resulting unit of this formula is now Joule. This energy can be easily factored into a temperature change by taking into account that Drosophila weighs about 0.25 mg and 1 Joule heats 1 g of water by 0.2449 °C. The assumed cylinder would weigh more (1.57 mg) than a typical Drosophila. The cylinder is employed only as rough estimate of the surface available for thermal conduction. This model, however close to the physical process, acts as a low pass filter for T A and could be easily exchanged for one (see Fig. 3A). t p correction. We determined the animals' T P in a gradient by first calculating the probability density of the animal at different temperatures. We tested two different strategies to determine the T P for each individual or a group of flies as a whole. One can either calculate a median temperature histogram from all individual histograms and the 95% confidence interval of each bin or calculate the individual histogram and calculate a confidence of each bin for each individual as rendered by binominal statistics. In both cases we subtract the temperature histogram of the model from the individual or group histogram and check if the 95% confidence interval is above, below or spanning zeros. In the last case this temperature is defined as not preferred, while values above are categorised as preferred and values below as antipreferred. Now one can use a weighted mean to calculate the T P , where the temperature bins labels are used to calculate the mean and the bins' value as weight. Hot and cold antipreference can be calculated accordingly.

Fly strains.
All adult flies and larvae tested in the Benzer gravitaxis and larva crawling assays (CantonS wild-type strain) and the brv2 MI04916 , were obtained from Bloomington Stock center (#64349 and #38067, respectively). Larvae were reared at 25 °C and adults were reared at three different temperatures: wt 18 were developed from egg to adult at 18 °C, wt 25 at 25 °C, and wt 30 at 30 °C. The UAS-hid,rpr line was provided by John Nambu and the HC-Gal4 and dtrpaA1 ins lines (described by 8 and 5 ) were obtained from Paul Garrity, and raised at 25 °C. All adults and larvae were reared on the same standard food medium and in the same light-dark cycle (12 h light, 12 h dark). statistic analysis. Significance tests were made as indicated either employing Fisher's permutation test 58 or a paired t-test. All p values were corrected with the Benjamini Hochberg false discovery rate detection 59 implemented by David Groppe and colleagues 60 . All statistical calculations were done using Matlab R2012b (The Mathworks, Natick, USA).
IGLOO is programmed in python 3 using numpy and scipy packages. The source code is available at https:// github.com/zerotonin/igloo and an full online version can be accessed on http://igloo.uni-goettingen.de/.

Data Availability
The source code of the model is available at https://github.com/zerotonin/igloo. An online application of the model can be accessed at http://igloo.uni-goettingen.de/. Original trajectories and measurement will be shared upon request.