Emergence of social cluster by collective pairwise encounters in Drosophila

Many animals exhibit an astonishing ability to form groups of large numbers of individuals. The dynamic properties of such groups have been the subject of intensive investigation. The actual grouping processes and underlying neural mechanisms, however, remain elusive. Here, we established a social clustering paradigm in Drosophila to investigate the principles governing social group formation. Fruit flies spontaneously assembled into a stable cluster mimicking a distributed network. Social clustering was exhibited as a highly dynamic process including all individuals, which participated in stochastic pair-wise encounters mediated by appendage touches. Depriving sensory inputs resulted in abnormal encounter responses and a high failure rate of cluster formation. Furthermore, the social distance of the emergent network was regulated by ppk-specific neurons, which were activated by contact-dependent social grouping. Taken together, these findings revealed the development of an orderly social structure from initially unorganised individuals via collective actions.

Numerous investigations have attempted to quantify the collective behaviours of animal groups, often by extracting high-level features of massive structures emerging from seemingly stochastic actions of individuals (Buhl et al., 2006;Nagy et al., 2010;Kim et al., 2012;Schneider et al., 2012;Ramdya et al., 2015;Jolles et al., 2017;Dombrovski et al., 2017;Jezovit et al., 2017). One shared feature of collective behaviours is the maintenance of a certain distance, or social space, between nearby individuals. For example, individuals within a group of tufted ducks (Conder., 1949), cliff swallows (Hutton, 1978) or sheep (King et al., 2012) maintain particular distances from each other within a group, which are also dynamically modulated by environmental stimuli (Bertrand et al., 2004). However, it remains unclear how individuals act together to form a cohesive social group and how social distance is regulated or maintained.
The transmission and perception of social signals within a group also plays an essential role in collective behaviour, particularly in coordinating group-level actions. In locusts, mechanosensation of abdominal tactile stimuli promotes the coordination of mass migration, while vision is required to detect the approach of others from behind (Buhl et al., 2006;Bazazi et al., 2008). In ants, tactile and chemosensory signals play an important role in cooperative foraging (Billen, 2006). Moreover, when traveling in a hierarchical group, pigeons rely on visual input from the left eye to respond quickly to the manoeuvres of others (Nagy et al., 2010). However, a systematic analysis of major sensory modalities to elucidate the functions underlying the assembly and sustainment of a social group has not yet been undertaken, partially due to a lack of suitable model organisms allowing for the effective manipulation of all members in a group with high precision and reproducibility.
Drosophila melanogaster is often overlooked when it comes to investigating group-level behaviours, despite the observation that fruit flies do indeed aggregate (Guo et al., 2017). In addition to assembling on food and oviposition sites (Lihoreau et al., 2016;Dombrovski et al., 2017), flies also exhibit local congregation without external artificial stimuli (Stalker and Harrison, 1961;Navarro and del Solar, 1975;Simon et al., 2012;Burg et al., 2013). The existing group-based behaviours, together with carefully controlled experimental conditions and powerful genetic tools, make fruit flies a promising neuroethological model for studying the mechanisms of collective behaviours (Ramdya et al., 2015;Ramdya et al., 2017;Dombrovski et al., 2017).
There are two major approaches among investigations of collective behaviours in Drosophila. One approach focuses on measuring the static end result, the last 'snapshot', of social aggregation and identifying potential sensory inputs (Stalker and Harrison, 1961;Navarro and del Solar, 1975;Simon et al., 2012;Burg et al., 2013), but does not examine the grouping process and its dynamics. The other approach is engaged in the study of patterns of interactions between individuals in a confined space, using networks of social interactions to understand information transmission (Schneider et al., 2012), but whether or how those described network properties contribute to social aggregation is not immediately clear. Interestingly, a study of the panic reactions of a group of flies to an aversive odour revealed features of collective avoidance (Ramdya et al., 2015). Social aggregation, in which individuals come together to eventually form a group, is distinct in many aspects from panic escape, where members of an existing group scatter. To date, there is no mechanistic framework explaining how dynamic social interactions between individuals (as a process) lead to a stable social aggregation (as a result), particularly in the absence of external stimuli.
In the current study, we established a paradigm for investigating connections between the collective actions of flies en masse and the process of social clustering, in which flies form a network with regularity. Analysis of the interaction dynamics of individual flies revealed that they rely on multiple sensory inputs, while collective local interactions drive the initiation and development of a stable, well-structured social cluster.

Spontaneous formation of social clusters
Although previous work has focused on social spacing (Simon et al., 2012;Burg et al., 2013) and modelling social interaction networks (SINs) (Schneider et al., 2012) in Drosophila, the mechanisms by which social clusters are formed remain unclear. To clarify this question, we developed an improved behavioural paradigm enabling the distribution of flies in a two-dimensional space to be determined using a programmable 8-megapixel digital camera (Figure 1-figure supplement 1A). In our set-up, a group of 50 male or female flies was allowed to walk freely on the surface of an agar pad (1% agar) in a horizontally placed circular arena (diameter: 90 mm) without external stimuli. The agar pad provided a moist environment for prolonged observation, and a soft substrate for flies to walk on, thus constituting a controlled but relatively naturalistic setting associated with minimal stress or disturbance to the flies (Figure 1-figure supplement 1A).
After a short exploration period, a group of wild-type flies (Canton-S, CS) spontaneously aggregated toward a small region of the arena ( . Each fly was fitted to an ellipse to obtain its geometric parameters including length, width, orientation and centre of mass ( Figure 1B,C). In subsequent quantifications, the location of a fly was represented by its centre of mass, and the distance between the centres of two flies was designated the inter-fly distance. To quantify the spatial distribution pattern of these flies, we first determined the accumulative distribution of all surrounding flies of each individual (designated as the reference fly) of one arena by aligning the centres of these individuals to the origin point and We next addressed whether such aggregation arose just by chance when individuals walked independently in the arena. We compared the spatial distributions of these social flies with that of 'random flies', which were presumed to act independently, with no social interactions between them (see Materials and methods). As shown in Figure 1E and Figure 1-figure supplement 2E-H, random flies exhibited different spatial distributions of merged surrounding flies, with more flies dispersed away from the origin, suggesting a dependency between individuals of wild-type groups to form spatial patterns, which was absent in a random distribution. Closely examining the distributions near the origin revealed that wild-type flies maintained a longer distance from their nearest neighbours than random flies ( Figure 1F). Thus, wild-type flies maintained a larger impermissible zone regarding social space.
We then calculated the distribution of surrounding flies using area-adjustment. As shown in  (P) Histogram of flies with NNDs in the indicated ranges of distance, with bin 1 = 0-5 mm, bin 2 = 5-10 mm, and bin 3 = 10-15 mm. The types of flies were female (red), male (blue) and random female (grey). N = 31, 35 and 40 arenas, respectively. (Q) Social Space Index was calculated from (P) by subtracting the value of bin2 from that of bin1 in each arena. N = 31, 35, 40 arenas for female (red), male (blue) and random female (grey), respectively. In a box and whisker plot, the scatter points show all data points, the box includes the 25th to 75th percentile, the whiskers mark minimum and maximum, and the middle line indicates the median of the data set. ***: p<0.001 (one-way ANOVA followed with Tukey's post hoc test for multiple comparisons). The online version of this article includes the following video, source data, and figure supplement(s) for figure 1: Source data 1. Figure 1M, P-Q source data and related summary statistics.                     Figure 1D. https://elifesciences.org/articles/51921#fig1video2 counting the number of surrounding flies may cause biased results, as the measuring distance (from the centre of each reference fly) increased beyond the arena edge. To compensate for under-estimation of the number of surrounding flies, we made an adjustment with the actual area within the arena (the intersecting area between the circle of the arena and the circle with a radius of the measured distance and a centre at the reference fly) (Figure 1-figure supplement 3A). As shown in Figure 1G and Figure 1-figure supplement 3B and C, compared with random flies, the wild-type flies had a greater number of surrounding flies over most of the measured distances. In other words, at a distance from any individual, there were, on average, more surrounding flies in a group of wildtype flies, suggesting a strong social aggregation of wild-type flies. Similarly, we calculated the density of surrounding flies within a distance. In wild-type flies, the density of surrounding flies decreased gradually as the measuring distance increased, whereas the density in random flies was lower and decreased faster ( Figure 1H; Figure 1-figure supplement 3D,E).
Besides quantifying the number of surrounding flies, we analysed the distance properties between the neighbouring flies. First, we calculated the distance matrix describing the distances between all possible pairs of flies in the group ( Figure 1I,J). The distance matrix enabled us to identify the nearest neighbour of each fly ( Figure 1J In contrast, the inter-fly distance of random flies began low but quickly exceeded that of wild-type flies when more additional pairs were considered ( Figure 1L; Figure 1-figure supplement 5A-E). The average NND over all arenas also indicated that wild-type flies in a group had a smaller social distance on average than random flies ( Figure 1M).
We set to quantify the nearness of a fly to its neighbours by measuring the average distance of a fly to its multiple near neighbours (up to 8-th nearest neighbours, including the nearest neighbours, Figure 1N; Figure 1-figure supplement 6). For both wild-type flies and random flies, the averaged multi-neighbour distance increased as more near neighbours were included ( Figure 1O; Figure 1figure supplement 6T), however, multi-neighbour distances in wild-type flies were smaller and increased more slowly than those of random flies ( Figure 1O; Figure 1-figure supplement 6T). As the trend was consistent for the numbers of near neighbours from 1 to 8, we used the distance to the 1st nearest neighbour (equivalent to NND) as the basis for further quantifying the fly group ( NND has been associated with social space (Mogilner et al., 2003;Simon et al., 2012). Wildtype flies displayed surprisingly consistent population NND for up to 50 min, and exhibited much lower NND than random flies ( Figure 1M; Figure 1-figure supplement 5E). Consistent with previous observations (Simon et al., 2012;Navarro and del Solar, 1975), a large proportion of wild-type flies (84 ± 9% for females, 87 ± 7% for males) exhibited a social distance within 5 mm from each other, approximately 1.5-2 body lengths ( Figure 1P; Figure 1-figure supplement 7D), while a significantly lower proportion (10%-11%) of wild-type flies lay within 5-10 mm of their nearest neighbour. Conversely, random flies exhibited a lower proportion within 0-5 mm (51 ± 8%) but a higher proportion within 5-10 mm (40 ± 7%) compared with wild-type flies.
We employed the 'Social Space Index' (SSI), based on the NND, to quantify distribution en masse, as described previously (Simon et al., 2012). A histogram of NND values for all flies in an arena was built using bins of 5 mm increments ( Figure 1P). SSI values were calculated as the percentage of flies in the first bin (NND range: 0-5 mm) minus that in the second bin (NND range: 5-10 mm) ( Figure 1P,Q); a larger SSI value indicates a smaller inter-fly distance. Our results revealed that wild-type fly groups exhibited significantly higher SSI values than the random flies (72%-77% vs 10%), in accord with previous studies ( Figure 1Q) (Burg et al., 2013;Simon et al., 2012).
Our comparison between the empirical results of wild-type flies with simulations of random flies suggested that self-organised clusters of wild-type flies would not emerge without interactions between individuals.

Social clusters in fruit flies are well-structured networks
To elucidate the local relationships of clustered flies, we designed a six-step procedure to define a cluster and further quantify the local regularity of the resultant cluster ( Figure 2A; Figure 2-video 1). Our algorithm used two criteria to build a cluster: area threshold and distance threshold. The algorithm first identified and grouped flies with residing areas smaller than an area threshold into a basic cluster, then repeatedly incorporated nearby flies within a threshold distance ( Figure 2A). Due to the inherent uncertainty of determining whether an object belongs to a cluster, we evaluated five criterial sets for clustering (CSC), with stringency from high to low ( Figure 2B, see Materials and methods). Higher stringency limited the number of qualified flies, and resulted in smaller clusters or no clusters at all (Figure 2-figure supplement 1).
With each set of criteria, clusters in all arenas were automatically identified, and the percentage of arenas with clusters was then calculated for three types of flies: male, female, and random female ( Figure 2C). Furthermore, the percentage of the number of clustered flies, out of the total flies in an arena (designated as CT value), was calculated then averaged over all arenas. As shown in Based on their locations in a cluster, flies were further classified into outsiders (the flies constituting the periphery of a cluster) and insiders (those being inside of a cluster) ( The residing area of individuals, particularly the insiders, was an important parameter describing the local properties of a cluster. We found that as the criteria became relaxed, the residing area increased greatly in random flies, but increased only slightly in female and male flies ( The social clusters of wild-type flies exhibited unique structural features of a typical distributed network (Baran, 1964), with individual flies as the interlinked nodes ( Figure 2A, Step 6). Thus, the flies self-organised into a structure with nearly uniform near-neighbour connections, similar to the lattice arrangement of atoms in a crystal. The number of links of a fly to its contiguous neighbours, a measure of connectivity ( Figure 2A, Step 6), was 5.53 ± 0.19 for males and 5.49 ± 0.30 for females when evaluated with criterial set #2 ( Figure 2F; Figure 2-figure supplement 3F). Furthermore, the average distance between these contiguous neighbours (the length of links) was 4.70 ± 0.36 for males, 4.65 ± 0.41 for females and 4.27 ± 1.13 for random flies ( Figure 2G; Figure 2-figure supplement 3G).
We noticed the near-uniform distributions of the flies in arenas and proceed to quantify the variation in the inter-fly spacing. To simplify the analysis, we considered the variation in the distance of contiguous neighbours (DCN) of inner flies, who did not border the arena edge ( Step 1: Thresholding to extract flies Step 2: Dividing the area between flies Step 3: Establishing the cluster core Step 4: Expanding the cluster to include surrouding flies Step 6: Measuring the connectivity within the cluster A Step 5  Step 1: Using digital image processing methods to extract the pixels of each fly from a raw image and calculating the geometric properties of the pixel set of that fly.
Step 2: Dividing the area between all flies and the edge of arena. The divided area surrounding each fly is designated as its residing area.
Step 3: Establishing the basic cluster by combining flies whose residing areas are smaller than an area threshold. Each red ellipse indicates a fly incorporated by the cluster; the corresponding pink shaded area indicates its residing area.
Step 4: Repeatedly expanding the cluster to include surrounding flies (green) within a threshold distance. The leftover fly was coloured grey.
Step 5: In the resultant cluster, identifying the insiders (red) and outsiders (blue).
Step 6: Quantifying the local regularity of the cluster. In a box and whisker plot, scatter points show all data points, the box includes 25th to 75th percentile, the whiskers mark minimum and maximum, and the middle line indicates the median of the data set. ***: p<0.001 (one-way ANOVA followed with Tukey's post hoc test for multiple comparisons). The online version of this article includes the following video, source data, and figure supplement(s) for figure 2: Source data 1. Figure 2D-G source data and related summary statistics.                      Figure 2 continued on next page 4C). As a small variation of a dataset is indicative of the homogenous nature of the measured property, the similar distances between contacting neighbours reflected a regular organisation of local near-neighbours across the entire social network of wild-type flies. The regularity of local spacing in the social clusters implied that cluster formation possibly involves cascades of local interactions guided by a set of common principles.
Quantification of cluster formation of 50 flies in circular arenas of different diameters (ranging from 90 mm to 170 mm) demonstrated that cluster formation was independent of the diameter or area of the testing arena, whereas the spatial features of random distribution were severely influenced by the size of arena ( We next surveyed the impacts of various factors on social clustering in wild-type flies. To better understand the relationship between the size of arena, the number of flies and social distance, we established groups of 'random dots' with random locations, which are set a minimal distance (impermissible distance or hard-core distance, see Materials and methods) away from each other ( (Baddeley et al., 2015). As a hard-core distance is indicative of local repulsion, tightness of clusters by actual flies suggested a global force of attraction on top of the local repulsion during cluster formation.
To evaluate whether the patterns of social clustering develop solely from interactions of attractive and repulsive cues without considering specific dynamic processes, we established a simplified model in which a fly walks under the combined influence of attraction and repulsion ( . Using Monte Carlo simulation, we found that a fly is strongly repelled by the fly set at close distances, but when the distance increases beyond a certain limit, the net force changes into attraction (Figure 2-figure supplement 7C). Even when the relative strength between repulsion and attraction (defined as the C factor) is adjusted over a broad range, such the abrupt switch from repulsion to attraction remains unchanged ( Figure 2-figure supplement 7D). Importantly, the net force decreases quickly to a very low level as distance increases, but remains attractive. As a result, a fly walking in a force field generated by a set of relatively stable flies, -consistently exhibits a tendency to move toward the set, if it is far away, but eventually stops approaching when it reaches the interface of zero net force at a critical distance to the set ( Figure 2-figure supplement 7E). The opposite forces on each side of the interface squeeze the fly to a defined distance from the set, and apparently to become a new  member of the set. Therefore, the antagonistic interaction between broad yet weak attractions and local but strong repulsions leads to a regular spacing between the clustered flies.
Furthermore, the SSI (Social Space Index) values of socially isolated flies (Xie et al., 2018;Simon et al., 2012), hungry flies and aged flies were lower than those of corresponding controls, suggesting a positive influence of social experience, and negative impacts of hunger and aging on clustering ( Overall, we demonstrated that fruit flies self-organised collectively into an orderly cluster with the topology of a distributed network. The robustness and unique features of such social clustering prompted us to further investigate the dynamic processes and mechanisms underlying cluster formation.

Collective dyadic interactions contribute to the clustering process
To better understand the dynamic process of social clustering, we recorded the arena with a camcorder from above and analysed the performance of groups of flies from video sequences. Massive sporadic movements of flies resulted in location changes for every individual by the end of the process. Individual flies walked for various distances, sometimes exploring the arena for a long time before occupying a final position in the cluster. During the period, flies involved numerous interactions with other flies.
It took wild-type flies approximately 4 min (3.6 ± 0.3 min for female flies and 3.8 ± 0.2 min for male flies), 8-10 min (9.9 ± 0.8 min for female flies and 7.6 ± 0.2 min for male flies) and 22 min (22.2 ± 0.6 min for female flies and 21.9 ± 1.2 min for male flies) to reach cluster sizes of 10, 25 and 45 flies, respectively ( Figure 3A). As the clusters grew quickly from 5 to 20 min, we subdivided this period into three 5 min phases (Stage 1, Stage 2 and Stage 3; Figure 3A).
Inter-fly interactions occurred exclusively between two flies, and the timing of these dyadic interactions appeared to be stochastic. We used two criteria to define an encounter event for a pair of flies: a) the distance between them was within 1.5 body length, and b) the approaching fly was facing and walking toward the other fly (i.e., the other fly was within its frontal 180˚view). As shown in Figure 3B, numerous encountering events occurred during cluster formation with the overall number of encountering events in males (509 per group) being twice that in females (237 per group). Further, by surveying all dyadic interaction events, we calculated the frequency of inter-fly encounters at each phase across the entire arena. Interaction events were more frequent at first (100 ± 5 for females and 203 ± 9 for males in Stage 1) and then decreased over each consecutive 5 min ( Figure 3C). These observations indicated that inter-fly interactions might contribute to the nucleation, growth and maturation of the social cluster.

Asymmetric interactions and stereotypic consequences of pair-wise social encounters
Closer inspection revealed that, in wild-type flies, inter-fly encounters were mainly asymmetric, occurring by one walking fly actively approaching a stationary fly, similar to findings reported by Schneider et al. (2012). The proportions of such asymmetric interactions among all encounter events in Stages 1-3 were 99%, 100%, and 100% in female groups, and 99%, 98%, and 98% in male groups, respectively. Adequate behavioural responses were elicited by the active fly through gentle touches of peripheral appendages when approaching the stationary fly ( Figure 3-video 1).
To characterise the dyadic interactions for an encounter event, we defined the actively approaching fly as the 'interactor' and the stationary fly as the 'interactee' in our behavioural observation ( Figure 3D). The encounters mostly (probability of 94%) led to active physical contact via legs and wings of both flies. The appendage-touch points were classified into eight types of actions from the point of view of the 'interactee', namely, frontal touch (F), rear touch (Rear or Wing) and leg touches (Legs: L1-L3 and R1-R3) ( Figure 3D). With an interactive behavioural labelling program, we obtained details of encounter events, including appendage-touch points and responses of the pair  Source data 1. Figure 3A-C, E-G, and I-J source data and related summary statistics. Figure 3 continued on next page of flies after encountering, as in the example data from wild-type females shown in Figure 3-figure supplement 1A and Figure 3-video 1. The approaching flies preferred to use their forelegs. Furthermore, in male encounters, the frequencies of rear-touches on the 'interactee' were higher than that on other sites ( Figure 3E), and the 'interactee' responded more frequently with wings (61%, percentage of all responses over three stages) than with legs (39%) ( Figure 3F). In females, however, the 'interactor' was more likely to approach the 'interactee' from the side and behind (Figure 3-figure supplement 1B), and responses of the 'interactee' relied mainly on legs (99%) and rarely on wings (1%) ( Figure 3G), revealing that female and male flies adopt different strategies for social encounters. These results suggest that sexually dimorphic neural mechanisms mediate social aggregation behaviour in flies. We next examined the consequences of encounters in pairs of flies, focusing on changes of locomotion of the pair, which collectively contribute to the group dynamics. After encountering, one or both flies would subsequently move away, but also become stationary ('interactor') or remain stationary ('interactee') ( Figure 3H; Figure 3-figure supplement 2; Figure 3-video 1). As shown in Figure 3I and J, female and male flies exhibited different tendencies for movement after encountering. In females, the 'interactor' tended to 'move-away' ('A Move', with alteration of walking trajectory) after encountering ( Figure 3I). However, over time, in the growing and maturation phases, the proportions of 'interactors' that moved-away and stayed ('A Move' and 'A Stay') became similar ( Figure 3I). For the female 'interactee', the tendencies to 'move-away' or 'stay' after encountering were approximately equal, with a slight increase of stay response over time ( Figure 3I). In contrast, in male flies, a large proportion of 'interactors' preferred to 'move-away' rather than becoming stationary, while a higher proportion of 'interactees' remained stationary rather than walking away ( Figure 3J). We observed an intriguing common pattern among males and females, by which, after a social encounter, the stationary fly tended to remain standing, whereas the incoming fly tended to move again and further 'probe' multiple stationary flies before settling down ( Figure 3I,J). The scale and scope of social encounters and stereotypic 'stay-or-move' responses suggested that social encounters not only generated the group-level dynamics prerequisite for cluster formation, but also actively drove cluster development.
Clustering grows by social encountering at the border To understand how seemingly spontaneous pairwise interactions result in a structured social network, we examined the contribution of encounter responses to cluster development. We focused on encounter events occurring at the periphery of a cluster. When a moving fly reached the cluster, it was likely (97% in male, 77% in female) to interact with flies composing the border, who were stationary. These 'moving' and 'stationary' flies were classified into three categories according to their final decisions after an encounter: stay in place, move out of the cluster, and move into the cluster ( Figure  Specifically, as shown in Figure 4B-C, the 'moving' males were inclined to 'Move-in' (76%) to join the cluster after an encounter, while a small proportion (3%) of 'moving' males directly walked into a cluster without any prior interactions with others at the border. Only 10% of 'moving' male flies that chose to walk away after encounters at the cluster edge ( Figure 4B,C). The 'moving' female flies displayed a similar tendency to join the cluster, with only 3% of moving females leaving the cluster (Figure 4-figure supplement 1A,B). The 'stationary' flies, which stayed at the cluster edge before encounters, showed a high rate (89% in males and 67% in females) of remaining within the cluster after an encounter ( Figure 4D   Source data 1. Figure 4B, D, F, and G-H source data and related summary statistics.    The combined high rate of joining the cluster ('Move in' + 'Stay' + 'Directly move in') and low rate of leaving the cluster ('Move out') by both 'moving' and 'stationary' flies effectively contributed to cluster expansion in both males and females ( Figure 4F-H; Figure 4-figure supplement 1E-G). Over 5 to 20 min (stage 1-3), almost every event at the cluster edge accounted for an increase in cluster size ( Figure 4H; Figure 4-figure supplement 1G).
The final positions of the flies joining the cluster were also dynamically determined. From video sequences, we observed that a new fly usually walked inside the cluster, disturbing other flies along the way (Figure 4-video 1), before it finally stopped. As the number of members of a cluster increased, the number of inter-fly interactions inside the cluster also increased (Figure 4-figure  supplement 2). These redistribution activities might lead to fine adjustment of the cluster toward its final structure, but did not affect cluster growth.
Taken together, our results suggest that numerous encounter events occurring at the cluster edge directly drive the steady growth of a social cluster, despite the highly dynamic and sporadic nature of these events.

Multiple sensory modalities are required for cluster formation
To disentangle how sensory modalities mediate social aggregation, we quantified social clustering after selectively disrupting each sense, including vision, olfaction, gustation, audition and mechanosensation. Previous studies suggested that visual input is essential for mediating aggregation in both larvae (Dombrovski et al., 2017;Dombrovski et al., 2019) and adult flies (Simon et al., 2012;Burg et al., 2013), suggesting that vision might be necessary in our paradigm. When depriving wildtype flies of visual inputs by testing under infrared light, SSI values markedly decreased, compared with those of control flies tested under regular white light ( Figure 5A). Furthermore, flies with visual deficiency, norpA 33 (Pak et al., 1970) failed to form clusters, instead dispersing throughout the arena and exhibiting large social space, suggesting that the absence of visual cues impaired social aggregation ( Figure 5A).
To test whether the olfactory pathway mediates social interaction during network formation, we analysed flies with impaired olfaction by mutating Orco, a gene that encodes an olfactory coreceptor in Drosophila (Larsson et al., 2004). The SIN analysis revealed that male Orco mutants moved slowly and exhibited a reduced ability to form SINs, but SINs that were formed had a higher proportion of reciprocated interactions and a longer average network distance between individuals (Schneider et al., 2012). On the other hand, the olfactory deficit in Orco males did not affect social space (Simon et al., 2012). Interestingly, while female Orco mutant flies exhibited lower SSI values, impaired olfaction in male Orco mutants had no effect on social clustering ( Figure 5B). Furthermore, the impaired behaviour in Orco -/females was rescued by re-expressing the Orco gene in the olfactory system ( Figure 5B). To further study the involvement of olfactory inputs in social clustering, we performed surgical experiments to eliminate olfactory inputs, removing antennae and maxillary palps housing olfactory receptors (Vosshall and Stocker, 2007). As shown in Figure 5B, without antennae and maxillary palps, female flies, but not male flies, displayed dramatically decreased SSI, confirming the phenotypes in female Orco mutants. This result suggests the possibility that the olfactory modality plays a sexually dimorphic role in social clustering behaviour.
To assess whether the gustatory system is required for social interactions, we studied flies with mutations in the Poxn gene (Dambly-Chaudière et al., 1992). This mutation transforms sensilla that are typically destined for chemical detection into mechanosensory sensilla (Awasaki and Kimura, 1997;Nottebohm et al., 1994). Mutations in Poxn reduced the ability to form SINs, while the structural features of the SINs formed were similar to those without social interactions (Schneider et al., 2012). We found that Poxn mutant flies showed significantly impaired social cluster formation ( Figure 5C). Although Poxn mutants exhibited strong deficits in forming networks of social  . Taken together, these data suggest that multiple chemical cues are required for social clustering.
To investigate the contribution of mechanosensory inputs to social aggregation behaviour, we tested several mutants, including inactive, nanchung (Gong et al., 2004)  , ppk (Adams et al., 1998;Zhong et al., 2010;Olds and Xu, 2014) and Piezo (Kim et al., 2012) which participate in mechanosensation in Drosophila. As shown in Figure 5D, the flies with defective mechanosensation had a dramatically decreased level of cluster formation, compared with controls. It was suggested that inactive and nanchung functioned both for audition (in Johnston's organ) and for mechanosensation (in other chordotonal organs over the body) (Gong et al., 2004;Karak et al., 2015). Surgical removal of a pair of aristae to block auditory detection by Johnston's organ did not impair SSI ( Figure 5-figure supplement 1B), excluding the mechanosensory contribution by Johnston's organ to social clustering.
Together, our surveys of basic sensory modalities suggested that social clustering depends on intact perception of multiple sensory cues, as disruption of any basic sensory input results in impaired cluster formation. The surprisingly high demand on precise perception of sensory cues was in accord with our observations that collective social behaviour was mediated by complicated interactions between highly mobile individuals within a constantly changing social environment.

Abnormal encounter dynamic, rather than locomotion deficits, precluded cluster formation
To investigate why sensory disrupted flies failed to form social clusters, we examined the period of cluster initiation. We identified the occurrence of small clusters (aggregations of at least five flies in close proximity, within 1.5 body lengths), which would develop into social clusters by incorporating additional members. Small clusters arose in the group of mutant flies similar to wild-type flies, but were quickly disrupted, within minutes; for example the Piezo KO flies in Figure 5E. Accordingly, we classified small clusters into two types: transient clusters (stable for at least 5 s, but no more than 1 min) and mini-clusters (stable for over 1 min, which is the potential core of the cluster growth). In the wild-type population, while transient clusters occurred earlier and more frequently, a mini-cluster occurred once and lasted for the entire observation period ( Figure 5F). Interestingly, in the population of Piezo KO and norpA 33 , transient clusters appeared much later than wild-type, and a stable mini-cluster never emerged in mutant flies despite multiple occurrences of transient clusters ( Figure 5G). It took substantially longer for occurrence of transient clusters in other mutants as well ( Figure 5H). The success in forming social clusters by wild-type flies did not depend on the frequency of transient clusters ( Figure 5I). However, compared with wild-type flies, these mutants showed shorter durations of transient clusters, suggesting an inability to maintain a budding cluster ( Figure 5J). We introduced the Nucleus Stability Index (NSI) to quantify changes in the size of Comparison of Nucleus Stability Index in flies with indicated genotypes. NSI describes the change in the size of the nascent cluster within 1 min. All genotypes and experimental conditions are indicated with the plots. In a box and whiskers plot, scatter points show all data points, the whiskers mark minimum and maximum, and the middle line indicates the median of the data set. n.s. indicates not significant (p>0.05); ***: p<0.001, **: p<0.01 (Student's t-test within each genotype for two-group comparisons, one-way ANOVA with Dunnett's test for multiple comparisons to control [CS]). In a bar graph plot, error bars in (H-K) indicate s.e.m. The online version of this article includes the following source data and figure supplement(s) for figure 5: Source data 1. Figure 5A-D, H-K source data and related summary statistics.  nascent small clusters within 1 min. While nascent mini-clusters (nuclei) in wild-type flies were stable and grew steadily, small clusters in mutant flies shrank quickly and collapsed when flies dispersed ( Figure 5K). These results demonstrated that sensory deficits affect the ability to develop or maintain a sizeable cluster.
To better understand the mechanisms underlying the ways in which sensory inputs mediate social clustering, we performed detailed analyses of encounter responses over the course of clustering in mutants including norpA, Orco, inactive, nanchung, and Piezo. Interestingly, comparing with wildtype flies, all of the mutant flies displayed a high frequency of social encounter events ( Figure 6A) and a short duration of social interaction ( Figure 6B), suggesting that the high encounter frequency in mutant populations did not lead to effective social clustering. Further quantification of behavioural responses after dyadic encounters revealed that mutant 'interactors' exhibited a similar tendency to 'move away' after encounters compared with wild-type flies ( Figure 6C). Conversely, mutant 'interactees' exhibited a significantly reduced tendency to 'stay' ( Figure 6C). Considering the net results for encounters in mutants, the difference between the likelihood for both flies to stay and for both to move away, it was more frequent for both flies to 'move' than for both to 'stay' ( Figure 6D). Therefore, the mutant pairs dispersed more effectively away from the encounter site.
To understand the encountering process in more detail, we analysed the transient velocities of flies before and after encounter events (+ /-0.8 s). 'Interactors' exhibited decreased velocity before impact ( Figure 6E-F) while 'interactees' exhibited increased velocities after encounters ( Figure 6G-H). Compared with wild-type flies, mutant flies generally exhibited higher transient speeds either before or after encounters ( Figure 6E-H).
To confirm that these mutant flies are capable of walking faster than wild-type flies, we observed the spontaneous walking and exploration of individual flies in a dish (diameter: 90 mm). As shown in Figure 6-figure supplement 1A-C, large proportions of mutant flies exhibited normal or faster spontaneous locomotive speeds (walking with higher average and maximum speeds). This strongly suggested that the inability to achieve formation of social clusters in these mutants was not due to locomotion deficits. In addition, the overall profiles of change of speed (acceleration and deceleration) in mutants were similar to or higher than the wild-type flies ( Figure 6-figure supplement 1D-E). Importantly, compared with wild-type flies, the rapid change of locomotion speed (reflected through average-and maximum-acceleration [and deceleration]) in these mutants strongly suggested that sensory disruptions did not affect their locomotion controls when walking on a horizontal surface ( Figure 6-figure supplement 1F-G).
Therefore, abnormal social interactions stemmed from defective inter-fly communications, rather than locomotion per se, contributing to unsuccessful formation, maintenance or growth of social clusters. The increased population dynamics, including high locomotion speed, frequent encounters, short interaction duration, and effective dispersion after encounter, in mutants likely indicated their elevated but failed attempts to compensate for the loss of social cues mediating cluster formation.

ppk-specific neurons participate in establishing normal social space
Stereotypic responses from dyadic interactions helped to build up the social cluster, these local interaction events highlighted the importance of physical contact in contributing to the clustering process, possibly by transducing mechanical and chemical signals. To further examine the neuronal basis of social clustering, we used neurogenetic approaches to modulate activities in target neurons while analysing behaviour change. The ubiquity of appendage-touch in eliciting encounter response prompted us to screen neurons potentially occurring in appendage organs using specific GAL4s, including all olfactory receptor-GAL4s, gustatory receptor-GAL4s, GAL4s labelling ion channels participating in mechanosensation in Drosophila including ppk (Adams et al., 1998;Zhong et al., 2010;Olds and Xu, 2014), inactive, nanchung (Gong et al., 2004;Karak et al., 2015;, nompC (Walker et al., 2000;Yan et al., 2013) and Piezo (Kim et al., 2012), and GAL4s targeted to the systems of neurotransmitters, neuropeptides, mechanosensation and those based on the expression patterns of a GAL4 driver line resource (Jenett et al., 2012;Ramdya et al., 2015;Tuthill and Wilson, 2016;Mamiya et al., 2018).
We utilised the GAL4/UAS binary system to express an optogenetic activator, CsChrimson (Klapoetke et al., 2014), to forcibly activate selected neurons during social clustering. Interestingly, among the approximately 500 lines screened, ppk >CsChrimson flies exhibited extensive aggregation with significantly decreased social space in male and female flies ( Figure 7A (Figure 7-figure supplement 1A,B). Moreover, to block the functions of mechanosensory neurons, we expressed tetanus toxin light chain (TNT) (Sweeney et al., 1995) in different candidate neurons. All flies with the corresponding neurons being silenced failed to form social clusters ( Figure 7C,E; Figure 7-figure supplement 1C,D), suggesting that the activities of these neurons, including ppk-GAL4-labelled neurons, are required for cluster formation. Notably, video sequences of cluster development revealed that activating ppk-labelled neurons resulted in early formation of clusters, indicating that the emergence of social clusters was faster in ppk >CsChrimson flies than in wild-type flies ( Figure 7F). However, the locomotion activity of ppk >CsChrimson flies was comparable to that of genetic controls ( Figure 7G), suggesting that faster clustering is unlikely to be due to faster walking.
The reporter protein green fluorescent protein (GFP) revealed that ppk-specific GAL4 labelled various populations in the peripheral nervous system, including legs and wing margins ( Figure 7H-K), whereas iav-GAL4, nan-GAL4, nompC-GAL4 and Piezo-GAL4 labelled limited numbers of neurons scattered in the appendages (Figure 7-figure supplement 2). These diverse expression patterns suggest potentially complementary roles of these mechanosensory neurons in social encounters via appendage-touches to mediate social communication.
Together, our results indicated that ppk-specific neurons play a unique role in regulating cluster formation and social distance.

Social grouping elevates activity in tarsal ppk neurons
Two findings, that appendage-touch played an important role in social encounters and that ppk was broadly expressed in the appendage organs, led us to investigate ppk neurons in appendages in more detail. We utilised an activity reporter system, calcium-dependent nuclear import of LexA (CaLexA) (Masuyama et al., 2012), to assess whether the activity of ppk neurons correlates with inter-fly physical interactions. Female flies were reared under isolated or social conditions, and the activities of ppk neurons were subsequently quantified. As shown in Figure 8A-C, flies raised in a group exhibited significantly increased activities in a small group of ppk neurons in the tip of the tarsus, compared with those raised alone. In contrast, there were no differences in CaLexA signals in neurons on the wing margin under single-or group-raised conditions (Figure 8-figure supplement  1A-D). Notably, grouping previously singly-raised flies together for 30 hr evoked substantial activity in ppk neurons in the tarsus ( Figure 8B,C), suggesting that frequent inter-fly interactions involving appendage-touches while living in a group might increase the activity of ppk neurons in the tarsus.
To discern the possible effects of contact pheromones, volatile chemicals and physical touch under grouped conditions, we raised a fly in a group but deprived it of direct contact with others. As shown in Figure 8D, each 'netted in a group' fly was grown in a small case and separated from the other flies via a double-layered net on top of the cage, while, as a control, 'netted single' flies were not in the presence of other flies outside the net. The net allowed odours, sounds and certain visual information to pass through, but blocked contact-dependent cues. Surprisingly, both 'netted single' and 'netted in a group' flies showed similar CaLexA signals in the tarsal ppk neurons as Source data 1. Figure 6A-C, E-H source data and related summary statistics. Figure supplement 1. Mutants failed to form social clusters, but were capable of locomotion manoeuvers.   Figure 8D,E), while re-grouping the 'netted single' flies for 24 hr was sufficient to induce an increase in CaLexA signals ( Figure 8D,E).
Together, these data suggested that the ppk-labelled neurons in the tarsus responded to physical touch, specifically from other flies. The elevated activities of tarsal ppk neurons from social contact highlighted their function in dyadic encounters to mediate appendage touches, which are important for social clustering.

Discussion
In this study, we established a simple collective behaviour paradigm using Drosophila as a model system to investigate how loosely distributed individuals come together to form a stable and orderly social cluster. Thus, we linked a dynamic progress (collective physical interactions) with its outcome (a structured cluster). We demonstrated that a group of individuals self-organised into a social cluster with topological features of a distributed network. This process relied on multiple sensory modalities as well as internal state and previous social experience. Moreover, the order emerged dynamically from stereotypical responses of numerous asymmetric encounters between pairs of individuals, while, abnormal encounter responses exhibited by mutant flies resulted in a failure of social clustering. These dyadic interactions, particularly near the border of a cluster, contributed to cluster growth, eventually incorporating all individuals. Physical contact in a group induced dramatic increases in the activity of tarsus ppk neurons, the activation of which caused flies to group quickly and form more compact clusters, demonstrating the important roles of ppk neurons in mediating dyadic interactions to promote clustering.
Many species exhibit massive collective behaviour, such as starling flocks (Nagy et al., 2010), schools of blue jack mackerel (Bertrand et al., 2004), stickleback shoals (Jolles et al., 2017), swarms of desert locusts (Buhl et al., 2006), and swarms of C. elegans (de Bono and Bargmann, 1998;de Bono, 2003). While Drosophila are commonly considered 'solitary' (Guo et al., 2017), increasing evidence suggests that Drosophila form social groups (Stalker and Harrison, 1961;Navarro and del Solar, 1975;Simon et al., 2012;Schneider et al., 2012;Burg et al., 2013;Ramdya et al., 2017;Guo et al., 2017). The lack of strikingly visible collective behaviour like that exhibited by birds and fish is made up for by the unique advantages of Drosophila for experimentally investigating the neural mechanisms underlying collective actions, including simple brain structure, tractable behaviour and a smaller genome. Additionally, in our paradigm, flies interacted collectively in a defined two-dimensional space, whereas many collective behaviours, including those of starlings and locusts, occur in an open three-dimensional space; thereby, our system reduced the difficulties of modelling. Furthermore, in a laboratory setting, we took into account the location and locomotion of all flies from the beginning, when individuals were still dispersed, to the end of the process, when all individuals joined to form a social cluster. Moreover, working with fruit flies allowed us to control many influential factors, including temperature, time of day, diet, physiological status of the animals (such as genetic background, age, and gender) and previous social experience. It is extremely difficult to control these factors in wild animals, despite the importance of such controls for social behaviour analysis. Homogenous data can help identify principal components by reducing undesirable variation bar: 10 mm), and portions of a wing (K1: pre-wing margin, K2: vein in wing, K3: post-wing margin, scale bars in K2-3: 30 mm). All genotypes and experimental conditions are indicated with the plots. In a box and whisker plot, scatter points show all data points, the box includes the 25th to 75th percentiles, the whiskers show the minimum and maximum, and the middle line indicates the median of the data set. n.s. indicates not significant (p>0.05); **p<0.01, ***: p<0.001 (Student's t-test). Error bars in (F) indicate s.e.m. The online version of this article includes the following source data and figure supplement(s) for figure 7: Source data 1. Figure 7D-G source data and related summary statistics. Figure supplement 1. Quantification of social clustering after activating or silencing neurons related to mechanosensory function. and noise. Drosophila offers a simpler alternative for examining the basic principles of collective behaviour by modelling with data from field observations. Although neural substrates in the peripheral and central nervous systems for controlling interactions between a pair of flies (such as in typical courtship and aggression behaviour) are increasingly well understood, little is known about the dynamics and structures of social groups in fruit flies. Built upon the investigations of aggregation of a group of Drosophila (Simon et al., 2012;Burg et al., 2013), our improved paradigm generates a relatively naturalistic environment with minimal perturbations to the flies, and reveals the unique structure of fly assemblage. The robust tendency to form organised social clusters provides an interesting entry point to investigate collective behaviours in fruit flies. As rudimentary as a Drosophila cluster appears compared with a swarm-like flock of starlings, the flies were not simply clumped together in a random manner. Rather, the arrangement of flies in clusters strongly resembled that of a distributed network, rather than a centralised or decentralised network (Baran, 1964). Previous studies revealed that maintaining appropriate social space in flies requires visual input (Simon et al., 2012;Burg et al., 2013), and is modulated by previous social experience (Simon et al., 2012) and anaesthetic treatment (Burg et al., 2013). Our quantitative behavioural analysis, in conjunction with neurogenetic approaches and surgical experiments, revealed that cluster formation by groups of flies is a highly dynamic process, requiring integration of visual, olfactory, gustatory, auditory and mechanosensory inputs. Impaired sensory functions resulted in abnormal encounter responses, and, in turn, a failure in cluster formation. Notably, we found sexual dimorphism in olfactory-mediated social aggregation, suggesting that, in male and female flies, different neural circuits regulate the process of social aggregation. Importantly, our data suggested that different sensory pathways are not functionally redundant, and even different mechanosensory neurons play different roles in shaping the formation and spacing of social clusters. Taken together, our results indicate that social clustering behaviour in fruit flies is more sophisticated than previously assumed and a model of dynamic integration of various sensory inputs is required to explain group-level aggregation behaviour.
We modelled how a fly behaves at different distances in response to influences from others, using a force field computed from putative attractive and repulsive forces. The attraction, likely mediated by vision and olfaction, is generally weak over a broad range of distances, whereas repulsion, likely through mechanosensation and gustation, is strong at short distances. The simulation results suggested that the antagonistic interaction between these forces is sufficient to generate the required social distance for cluster formation. Notably, Turing first proposed a theoretical model utilizing local activation and a long-range inhibition to explain a variety of patterns in biology (Turing, 1952). Similar models were developed to account for the self-organing pattern formation from cells to organisms, suggesting that diverse patterns of social structures do not necessitate the assumption of complex behavior (Detrain and Deneubourg, 2006). However, without the perspective of dynamic processes, our static models cannot account for the active process of pair-wise encounters. Our results demonstrated that a large number of random dyadic interactions can serve as a driving force for the emergence of an orderly social cluster. Generalized into a system of self-propelled particles (SPP), flies are likely to achieve clustering by a parallel process involving all individuals, each of which has only a strong local view, without a clear sense of other individuals or the final structure of the cluster.
Although the timing and locations of pair-wise encounters are highly variable, the types and consequences of these encounters are stereotypic, and, importantly, the net outcome of these collective events over time is the growth of a cluster to include all flies in the arena. Interestingly, in wild-type flies, the frequency of encounters decreases after the initiation of the social cluster, indicating that Figure 8 continued points, whiskers mark minimum and maximum, and the middle line indicates median of the data set. n.s. indicates not significant (p>0.05); **: p<0.01, ***: p<0.001 (Student's t-test within each genotype for two-group comparisons, one-way ANOVA with Tukey's post hoc test for multiple comparisons). The online version of this article includes the following source data and figure supplement(s) for figure 8: Source data 1. Figure 8C, E source data and related summary statistics. an increasing number of flies settle down through dyadic interactions. In addition, a large proportion of flies gradually joined the nascent cluster (nucleus), despite its sporadic occurrence and erratic location. Similar approaches have been observed in 'food searching-aggregation' behaviour of adult flies, in which signals were emitted from 'primers' for the subsequent arrival of 'followers' (Tinette et al., 2004), and in cooperative digging behaviour of larvae (Ben Jacob et al., 2004;Dombrovski et al., 2017;Dombrovski et al., 2019). Besides foraging, grouping together benefits individuals in other aspects of Drosophila life. For example, evidence suggests that grouping in flies can synchronise circadian rhythms (Levine et al., 2002), modulate gene expression (Krupp et al., 2008), change pheromone profiles (Krupp et al., 2008;Liu et al., 2011), facilitate social learning (Chabaud et al., 2009;Battesti et al., 2012) and generate a heightened awareness of environmental stressors (Ramdya et al., 2015). Therefore, our data support the existence of a generalised assembling strategy for a group of flies to form a well-structured social network with or without external stimuli.
Although flies also exhibit pairwise interactions during courtship and aggression, the dyadic actions of encounter events during social clustering are relatively distinct in several aspects. First, the duration of each encounter event is brief, lasting for less than 1 s. Second, two flies from an encounter event are unlikely to meet again within a short period. This might be partially due to the sheer number of flies in the arena. However, in settings with many flies, individuals during their aggression or courtship exhibit a strong tendency for object fixation, as the pairs chase and interact repeatedly despite surrounding flies. Third, the frequent mode of dyadic encounter is between a walking fly and a stationary fly. The typical output of encounter is one moving-away while the other staying. During courtship and aggression, however, it is more common for both flies to be moving before and after the interaction. The distinct behavioural characteristics of encounter events suggest that, during social clustering, flies are likely exhibiting a unique 'mental' state.
Social clustering is not the only instance in which a fly group uses pairwise interactions to convey information between individuals. Benton and colleagues demonstrated that enhanced CO 2 -avoidance of a group of flies over individual performance also depends on pairwise interactions (Ramdya et al., 2015). It is likely that additional situations exist in which Drosophila exhibit stereotypic pairwise interactions that serve as general driving force for the emergence of order from an initially disordered group. In ants, spontaneously mobilized individuals in nests can contact and excite other ants thereby spreading rhythmic activity across the colony (Couzin, 2009). In swarms of insects, schools of fish and flocks of birds, once the entire group accomplishes pattern formation and moves cohesively with high dynamics, an individual gathers information from near neighbors to adjust its own speed and direction (Sumpter et al., 2008;Buhl et al., 2011;Katz et al., 2011). In these examples to maintain a relatively uniformed distance between moving individuals, spreading information depends on non-contact pairwise interactions, unlike those seen in Drosophila mediated via physical touches. Previous studies have suggested that an individual engaged in collective movements 'averages' its pairwise interactions with near neighbors, although features of residual threebody interactions are also present (Katz et al., 2011;Herbert-Read, 2016). Furthermore, it is possible that pairwise interactions play roles before collective movements unfold, such as to accumulate a sufficient number of individuals into a small space to escalate the group density beyond a threshold. or to influence the collective mood or decision-making of the group for departure (Petit and Bon, 2010). Overall, there appear to be common rules in the collective behaviors of flies and other animals. Information is processed and exchanged at a local scale between near neighbors, and individuals do not (and do not need to) have a global view (Buhl et al., 2011). Furthermore, ordered organization only emerges when the group reaches to a certain size (Buhl et al., 2006).
Inspection of all dyadic encounters in our analysis demonstrated that touches of peripheral appendages between a pair of flies evoke stay-or-go responses, which is an important element during the initiation, growth and maintenance of the SIN. Similarly, cascades of appendage-touch elicited interactions between fly pairs are reported to be responsible for the collective avoidance of CO 2 (Ramdya et al., 2015). Drosophila possess an extensive mechanosensation system involving different types of mechanosensory neurons (Karkali and Martin-Blanco, 2017). Remarkably, our results demonstrated that manipulating neural activities of mechanosensory neurons caused aberrant social clustering, suggesting an important role of mechanosensation in regulating social networks in adult fruit flies. Considering the broad expression of mechanosensory genes, it is possible that multiple mechanosensory pathways mediate inter-fly tactile interactions in a coordinated and/or redundant way. Ants are also reported to use antennae to communicate with each other via tactile signals and chemosensation (Billen, 2006). In addition, crowding of solitary locusts induces transformation into the gregarious phase. Tactile signals via appendage touches between individuals play an important role in this process (Hö ltje and Hustert, 2003;Buhl et al., 2006;Bazazi et al., 2008). Interestingly, we found that in grouped flies, the activity of ppk neurons was elevated via a contact-dependent mechanism, suggesting a conserved role of tactile perception in social grouping. Taken together, our study not only revealed a novel role of appendage-mediated tactile signals in the dynamic formation of social networks in flies, but also provides evidence of common features of collective behaviours among different species.
Our modelling and observations indicated that animals use attractive signals to assemble a large group, whereas repulsive signals between individuals prevent them from forming a jumbled mass. Although this study did not pinpoint the attractive signal(s), the regular pattern of social clusters and the ubiquity of appendage interactions between pairs of flies strongly suggest that a stereotypic contact-mediated repulsive force keeps the nearby flies apart at a 'hard-core' distance. Mechanosensation is likely to be necessary for flies to both exert and receive physical forces during a dyadic interaction. The tarsal ppk neurons are activated during direct social contact, suggesting the possibility that they may sense social tactile cues. The expression patterns of ppk-positive neurons in the appendages suggest the possibility that the normal function of these neurons is to perceive touches from other flies. However, it is also possible that ppk-neurons are also required on the force-exerting side, for example, to gauge or control the level of force generated to repel other flies. Activating ppk neurons leads to decreased repulsion between flies supports the second hypothesis. Detailed dissection of the roles of each type of ppk-neuron necessitates manipulating the subclasses with high spatial and temporal precision, which should be possible with future genetic tools (Jenett et al., 2012).
In conclusion, we developed a self-organised aggregation paradigm as a model for studying the emergence of ordered structures from collective interactions of individuals. Our findings highlight the importance of stereotypic dyadic interactions and ppk neurons in social clustering and spacing. Further, comprehensive exploration of the dynamics and guiding principles in social clustering in Drosophila could enable the development of a novel framework for understanding the molecular and neural bases of collective behaviour in other animals. Continued on next page flies were carefully transferred to the centre of the arena. The arenas were back-illuminated by white LED arrays. For visual deprivation experiments, infrared LED arrays (850 nm) were used as the backlight source. The video-or time-lapse recordings started immediately when the flies were introduced to the arena; this was considered the zero hour.

Materials and methods
Our system used a typical setting for behavioral observations but with improvements that enabled us to consistently observe social cluster formation. Besides maintaining humidity inside the arena for long-term observation, the agar pad also served as a favorable surface for the flies to walk on, while the 'slippery' coating on the side and top of the arena prevented flies from staying on these areas. Moreover, social cluster formation also requires a tightly-controlled external environment, because high temperature (>30˚C), sound, vibration of the testing table, and moving shadows (of operators) could deter the clustering process. Our behavioral experiments were conducted in an isolated area within a quiet room. We also noticed that several factors, including small group size (<10 flies), mixed sex, starvation, and social isolation, negatively impacted the formation of clusters. Clustering in wild-type flies develops readily only when the internal and external perturbations discussed above are eliminated.
We estimated that over 225,000 flies of various genotypes were tested for social clustering in this project.

Image and video acquisition and analysis
Digital cameras (Canon A720) were used to capture a sequence of raw images (8 Megapixels) of fly distribution. A custom script was written to control the camera to acquire time-lapse images for 120 min. The recording began as soon as the flies were first introduced into the arena. The captured images were imported to Matlab for further analysis with custom scripts.
For dynamic analysis experiments, videos of fly distribution in the arena were obtained with camcorders (Sony HDR-CX240E), at 50 frames per second (FPS). High-speed videos were captured by a Camera Link camera (Gazelle, FLIR) at 500 FPS and the images were saved as uncompressed files.
Details of touch-evoked encounter responses were analysed semi-automatically. Tracing of flies was aided by custom scripts/GUIs written in Matlab. Throughout this paper, the distance between two flies was measured between body centres, not between body surfaces.

Social Space Index (SSI)
Photographs of the distribution of flies between 28 and 120 min after they were introduced into the arena were used for social space analysis. A Matlab program was written to extract the positions of flies and to quantify the social aggregation by calculating the NND for each fly. The percentages of flies with NNDs in bins of 5 mm were calculated. The SSI was then obtained by subtracting the percentage of flies in the second bin from that in the first bin (SSI = bin1 À bin2), as previously described (Simon et al., 2012).

Random flies
For simulating flies without interactions between each other in arenas of similar size, we generated 'random flies' which followed the natural distribution of actual flies. A Matlab script first randomly picked digital 'flies' from the dataset of wild-type flies of corresponding gender and experimental conditions. These flies were plotted onto a digital arena (a circle with a diameter of 90 mm) using their original coordinates, body lengths and orientations. Flies that overlapped with others already existed in the arena were then removed. This process was repeated until the total number of virtual flies in the digital arena finally reached 50. The constituted arenas with 'scrambled' flies were then treated similarly to the real arenas, with these flies identified to provide controls for comparison with the actual flies. Because they came from the same dataset, the random flies shared the same overall spatial distribution of the actual flies, including frequent occurrence near the edge of arenas.
Random males and random females were generated from the dataset of wild-type males and females, respectively. Because random males and females displayed almost identical averaged properties in our analysis, only the results from random females were shown in this paper.

Random dots
To generate a group of a given number of random dots, a Matlab script generated a series of dots with random locations within a circular arena (diameter: 90 mm), with the restriction that each dot was not in the proximity of the other dots (within an impermissible distance, or minimal allowed distance). The positions of these randomly generated dots were then used to compute their distribution. When the minimal allowed distance was 0 mm, the distribution of these random dots followed a Poisson distribution. When the minimal allowed distance was larger than 0 mm, their distribution followed a Maté rn hard-core point process (type II) with this distance serving as the hard-core distance (Turner, 2015). To simplify the narration, we used the hard-core distance for both distributions.
Using spatial statistics to construct 'random dots' in this way enabled us to obtain spatial point processes that would not be observed otherwise in real experiments. In a 90 mm dish, random dots with a total number ranging from 5 to 100 and a hard-core distance ranging from 0 to 10 mm were generated.

Fly identification and cluster reconstruction
Several Matlab scripts worked sequentially to automatically find and join the flies, whose surrounding areas and distances to neighbours met predefined criteria (described in the following section), into a cluster (also see Figure 2A; Figure 2-video 1).
The edge of the arena was manually or automatically labelled to generate a mask that allowed the following calculations to focus on only the inside of the arena. The background of a digital image of an arena with flies was first calculated by collecting the maximal values at each pixel position over the observed period. After background subtraction, the image was converted to a binary with a threshold. In the resultant image, groups of connected pixels were assigned as individual flies, each of which was fitted to an ellipse to obtain geometric parameters (body length, body width, body orientation, the centre of mass).
The inversion of the binary image resulted in a connected area between all flies and the edge of the arena. By repeatedly applying morphological shrink operations on the image while preserving its Euler number, the area was reduced into connected lines that separated individual flies. The region surrounded by some of these lines (serving as borders) for each enclosed fly was designated as the residing area of that fly. Two flies were considered contiguous neighbours (contacting neighbours) only when they shared a common border.
We identified contiguous flies whose residing areas were smaller than a threshold (area), and combined them into a basic cluster. The nearby flies (with larger residing areas) were further incorporated into a basic cluster if their distance to any flies in the basic cluster was shorter than a threshold (distance). The area threshold and distance threshold are described in the following section. The latter step was repeated to expand the cluster until no more flies met the distance criterion. The flies in the resultant cluster were treated equally in the following steps, regardless of whether they joined by area or distance criteria. In rare situations where two or more clusters formed in one arena, each cluster was treated in parallel.
Flies in a cluster were classified into insiders (whose residing area only bordered with residing areas of flies from the same cluster) and outsiders (whose residing area was juxtaposed to regions not belonging to flies of the same cluster). Due to variation among outsiders, we only quantified the connectivity of insiders. Additionally, only connections between contiguous neighbours were considered for calculating the numbers and lengths of these links.

Predefined criterial sets for cluster reconstruction
First, we calculated the area of the arena, the unit area, and the unit distance with the following formulas: Area of Arena ¼ p Ã ðRadius of ArenaÞ 2 : Unit Area ¼ Area of Arena = Total Number of Flies: Unit Distance ¼ sqrtð4 Ã Unit Area = pÞ or 2 Ã Radius of Arena = sqrt ðTotal Number of FliesÞ: Unit Area is the area per fly, assuming the area of the arena is divided evenly among all flies. Unit Distance is the diameter of a circle with an area equal to the Unit Area.
Each criterial set was based on one of five Stringent Factors (0.25, 0.302, 0.423, 0.49 and 0.723, from most stringent to most relaxed), the square roots of which were 0.5, 0.55, 0.65, 0.70 and 0.85, respectively. The thresholds for maximal allowable area and distance for each criterial set were calculated with the corresponding Stringent Factor: Area Threshold ¼ Unit Area Ã Stringent Factor Distance Threshold ¼ Unit Distance Ã sqrt ð0:5 Ã Stringent FactorÞ A pair of Area Threshold and Distance Threshold form a criterial set; thus, five Stringent Factors resulted in five criterial settings for clustering (CSCs) (with stringency from high to low, Figure 2B).

Surgical manipulation
For surgical removal of bilateral antenna, maxillary palps and arista, 3-day-old adult Canton S flies were used. The flies were anaesthetised on a CO 2 pad and specific operations were conducted with fine forceps under a stereo microscope (Leica, S6E). To minimise CO 2 toxicity, we operated on five flies in each batch. After the operations, the flies (50 in a group) were transferred to a standard food vial and maintained at 25˚C with 60% humidity for 2 days before behavioural testing.

Dust-induced grooming
The dust-induced grooming experiment was modified from a previous study (Seeds et al., 2014). A group of 50 flies was cold anaesthetised on ice and transferred to grooming chambers containing green phosphor (modified from a glass vial with a diameter of 31.8 mm and height of 80 mm). The chamber was gently shaken to uniformly coat each fly. Excess dust was removed by tapping the flies against nylon mesh before the flies were transferred to behavioural testing chambers for video recordings. Images of dusted flies in the behaviour chamber were checked at 0, 15 and 60 min under a fluorescence stereo microscope (Leica M205). Most body parts were almost clean at 15 min.

Optogenetic stimulation
A group of 50 flies were collected within 3 days after eclosion and transferred into a vial with regular food containing 200 mM all-trans retinal (Sigma R2500). The vials were wrapped in aluminium foil for protection from light, then kept at 25˚C and 60% humidity for 2-4 days. After transferral to the test arena, flies were allowed to recover for 1 min, and then stimulated with light. An array of white LEDs was used as the source of stimulation. Unless otherwise noted, light stimulation was presented continually throughout the observation period. The light intensity was 28 mW/cm 2 , measured using a spectrometer (CCS200/M, Thorlabs).

Inducible inactivation
To deactivate mechanosensing neurons, the tetanus toxin light chain, TNT, was expressed in the indicated GAL4 labelled neurons continuously from the embryonic stage, except for nompC-GAL4. As inactivation of nompC neurons at an early stage is lethal, TNT was expressed exclusively in the adult stage using the TARGET system (McGuire et al., 2004). Flies with nompC-GAL4, UAS-TNT and Tub-GAL80 ts were reared at 22˚C and collected within 5 days of eclosion. A 2-day temperature shift to 30˚C was applied to inhibit GAL80 activity, in order to induce TNT expression. Flies were collected and combined into 50 flies per vial one day prior to the test. The behavioural test was conducted at room temperature.

Expression patterns
Dissection and staining of the central nervous system were performed as previously described, with slight modification (Zhan et al., 2016). Dissection of intact brains of adult female flies was performed in cold phosphate buffered saline (PBS) under stereo microscopy and fixed in 4% fresh paraformaldehyde solution for 2 hr on ice. The tissues were then washed with PBT (0.1% Triton X-100 in 1 Â PBS) five times (15 min each), blocked for 30 min with PBT containing 5% normal goat serum, and incubated with anti-nc82 antibody (1:100) in blocking buffer for 24 hr at 4˚C. After washing with PBT five times, the tissues were incubated with secondary antibody (1:100) in PBT for 48 hr at 4˚C. Samples were then washed with PBT three times (15 min each) before mounting.
For the imaging of expression in the peripheral systems, wings and legs were bilaterally removed from adult flies 4 days post-eclosion with forceps on a CO 2 plate. For imaging of legs, after fixation in 4% freshly prepared paraformaldehyde solution for 2 hr on ice, legs were washed with PBT (0.1% Triton X-100 in 1 Â PBS) three times (15 min each) before mounting.
Samples were mounted in mounting medium (Vector, H-1000) under a coverslip. All of the fluorescent images were collected using a confocal microscope (Leica SP8) and processed with ImageJ (NIH).

CaLexA measurements
Flies with various social experiences were used for CaLexA experiments. 'Single': flies raised individually in isolation in a rearing tube (diameter: 31.8 mm, height: 80 mm) after hatching; 'Group': 50 flies (female and male) raised together after hatching; 'Re-Grouped': the singly-raised flies grouped together (10 flies/vial, diameter: 21 mm) and reared for additional 30 hr prior to imaging. 'Netted': single fly housed in a netted top tube cage with food at the bottom (diameter: 12 mm). 'Netted in group': single fly raised in a net house and surrounded by a group of untouchable flies. 'Netted regrouped': 10 single isolated flies were put together to form a new group for 24 hr prior to testing.
For CaLexA imaging, the ppk-GAL4 >CaLexA flies, 16 days old, were cold anaesthetised on ice for 5 min. The legs or wings were quickly removed with forceps, and mounted in mounting medium (Vector, H-1000) under a coverslip. Confocal images were acquired under a 40 Â oil immersion objective lens with a confocal microscope (Leica SP8). The sum of all pixel intensities of stacks comprising the whole regions of interest (ROI) were calculated in GFP and autofluorescence channels. Average GFP signal was used for analysis.

Statistics
Statistical analysis was performed using Prism 7 (GraphPad Software). All experiments were performed in parallel with both experimental and control genotypes. In box and whisker plots, all data points in a data set were plotted; each box includes data from the 25th to the 75th percentile, and the line within the box indicates the median. P values were determined using the unpaired two-tailed Student's t-tests for pairwise comparisons, one-way ANOVA with Tukey's or Dunnett's test for comparison of multiple groups. For bar graphs, the values shown were mean ± s.e.m.

Source data files
The source data for the behavioral analyses, summary statistics, and source code are included in the source data files.