Main

Many animals live in groups, the result of a basic social affiliative drive, which requires detection and approach of conspecifics. Social affiliation is a prerequisite of consummatory actions such as aggression, mating or play3, and is also a proximal cause of swarm, flock and herd formation. Although neural circuits that mediate such behaviours have received much attention3,15, relatively little is known about the sensory detection of social signals (beyond pheromones)15,16, and how such cues feed into the regulation of social distance. One important class of visual social signals is biological motion, which comprises conspecific movement patterns that trigger complex approach and pursuit behaviours17,18,19, and elicit a social percept in humans9,10. Biological motion is also a key driver of zebrafish shoaling, a collective behaviour with well-characterized interaction rules in groups or pairs of animals2,6,11,20, offering a model to investigate visual neural circuits underpinning social affiliation.

Neuronal activity during social affiliation

To identify the relevant neural circuits in juvenile zebrafish aged 21 days, we generated unbiased maps of recent neuronal activity after shoaling with real or virtual conspecifics (Fig. 1a). Virtual conspecifics were projected black dots moving either with fish-like biological motion, or continuously, which are highly attractive and weakly attractive, respectively2 (Fig. 1b). We then recorded a snapshot of neuronal activity by rapid fixation and labelling of c-fos (official gene symbol, fosab) mRNA21 using third-generation in situ hybridization chain reaction22 (HCR) analysis in the forebrain, midbrain and anterior hindbrain (Fig. 1a,c and Extended Data Fig. 1). Visual inspection of the registered and merged c-fos signal from all of the animals identified 31 distinct clusters with robust activity in response to one or more stimulus conditions (Fig. 1c and Extended Data Fig. 1).

Fig. 1: Fish-like motion activates a conserved social behaviour network.
figure 1

a, Schematic of stimulus presentation for activity mapping. b, Attraction towards stimuli shown in a. n = 17 (no stimulus) or n = 9 (continuous; bout-like) single animals; and n = 8 animals tested in 4 pairs (conspecific). Data are mean (black dots) ± 1 s.d. Exact P values were calculated using two-tailed t-tests compared with the no-stimulus group: P = 0.16 (continuous); P = 5.2 × 10−8 (bout-like); P = 8.1 × 10−11 (conspecific). Bonferroni-corrected α values: NS, P > 0.05/3 (NS); ***P < 0.001/3. c, Representative slices of maximum-intensity-normalized c-fos signal merged across all 28 registered animals. The views are horizontal (top row), sagittal (bottom left) and coronal (bottom right). The solid grey lines indicate the corresponding planes across the slices. The dashed line indicates the midline. Coloured patches indicate activity clusters (Extended Data Fig. 1). A, anterior; D, dorsal; L, lateral. d, The average normalized c-fos signal at the three representative horizontal planes indicated in c. n = 6 (no stimulus), n = 8 (continuous), n = 6 (bout-like) and n = 8 (conspecific) animals. e, The effect size (Cohen’s d) of normalized bulk c-fos induction compared with the no-stimulus condition. Negative values indicate a lower signal compared with the no-stimulus condition. The dendrogram represents hierarchical clustering. Statistical analysis was performed using two-tailed t-tests in each activity cluster versus the no-stimulus group. *P < 0.05/3, **P < 0.01/3, ***P < 0.001/3 (α values were Bonferroni-corrected per activity cluster). Animal numbers are the same as in d. Additional statistical information is provided as Source Data. Scale bars, 200 µm. DT, dorsal thalamus; En, entopeduncular nucleus; Hc1, caudal hypothalamus 1; Hc2, caudal hypothalamus 2; Hc3, caudal hypothalamus 3; Hi1, intermediate hypothalamus 1; Hi2, intermediate hypothalamus 2; Hi3, intermediate hypothalamus 3; Hrl, rostral hypothalamus, lateral; mHr, rostral hypothalamus, medial; MOd, medulla oblongata, dorsal; MOi, medulla oblongata, intermediate; nMLF, nucleus of the medial longitudinal fasciculus; OB, olfactory bulb; P, pallium; Pl, pallium, lateral; PM, magnocellular preoptic nucleus; Pn, pineal; PPa, anterior parvocellular preoptic nucleus; PPp, posterior parvocellular preoptic nucleus; Pr, pretectum; PT, posterior tuberculum; Ri, inferior raphe; SPd, subpallium, dorsal; SPv, subpallium, ventral; TeOa, tectum, anterior; TeOd, tectum, dorsal; TeOv, tectum, ventral; Tg, lateral tegmentum; TS, torus semicircularis; VT, ventral thalamus.

Source data

Splitting the data by stimulus group revealed that social context differentially activated these clusters. Activation by real and virtual conspecifics overlapped in a subset of clusters, including the lateral rostral hypothalamus (cluster Hrl) and intermediate hypothalamus (cluster Hi3), while showing a distinct pattern in other areas. In the optic tectum (TeO), virtual conspecifics activated a ventrolateral cluster, matching the retinotopic representation of the ventrally projected black dot visual stimulus23. By contrast, real conspecifics moving at the same elevation as the imaged fish activated the anterior and dorsal TeO more strongly (Fig. 1d). Virtual and real conspecifics activated a cluster in the dorsal thalamus (DT), and real conspecifics also activated an anterior cluster in the ventral thalamus (VT) (Fig. 1d). The DT c-fos cluster overlapped with an expression hotspot of the gene cortistatin (cort, also known as somatostatin 7 (sst7)), which we co-labelled using a third, multiplexed HCR probe and used subsequently as a DT landmark24 (Extended Data Fig. 2a,b). One cluster in the posterior tuberculum (PT) stood out as selectively active with bout-like motion and real conspecifics. By contrast, c-fos in the intermediate hypothalamic cluster Hi2 was highest for the no-stimulus condition and inversely related to stimulus attraction (Fig. 1d).

To quantify these trends, we calculated the average bulk c-fos intensity per cluster in each animal (Extended Data Figs. 1e and 2c). Statistical analysis of the c-fos signal revealed significant modulation of activity in 21 clusters by at least one stimulus relative to the no-stimulus condition (Fig. 1e). Hierarchical clustering of all areas separated five major groups of clusters that were qualitatively (1) not modulated relative to the absence of stimulus, (2) weakly suppressed by virtual conspecifics, (3) suppressed by most stimuli, (4) activated more by real conspecifics than virtual ones and (5) activated by most stimuli (Fig. 1e).

Together, this unbiased global activity map identified brain networks whose activity is modulated by real and virtual conspecifics with putative roles in social affiliation. These include posterior preoptic and rostral hypothalamic areas that are likely to be homologous to paraventricular and anterior hypothalamic nuclei commonly assigned to the conserved social behaviour network12,13,14 (Hrl, mHr, PPp). Clusters in groups 3 and 4, which were modulated exclusively by real conspecifics (Hc3, Hi2, PPp, Hc2), might reflect neuronal responses beyond those necessary for acute social affiliation. They may contribute to perception of threat or homeostatic stress mechanisms, potentially through visual cues that are not present in bout-like dot stimuli or additional sensory modalities such as olfaction and mechanosensation16,21,25,26. Thus, the set of clusters activated by virtual conspecifics highlights a core network underlying the visuomotor transformation associated with shoaling, beginning with the recognition of conspecifics.

Thalamic neurons encode biological motion

Our c-fos labelling method highlights putative visual input pathways for social affiliation. Biological motion probably enters the brain through the TeO and DT27, therefore providing an opportunity to investigate sensory detection of this social cue. To understand stimulus selectivity of individual neurons in these visual areas, we turned to volumetric two-photon calcium imaging of juvenile brain activity in response to presentation of virtual conspecifics.

Fish that expressed nuclear-localized GCaMP6s in almost all neurons (carrying the transgene elavl3:H2B-GCaMP6s) were immobilized on the stage of a microscope equipped with a custom-built remote focusing set-up for rapid image acquisition (Extended Data Fig. 3). We imaged simultaneously in 6 imaging planes at 5 Hz, extending 600 × 600 × 200 um (x,y,z) (Fig. 2a). This volume included the retinorecipient brain areas highlighted by our c-fos analysis, DT and TeO, as well as pretectum, nucleus isthmi, VT and habenulae (Fig. 2b and Extended Data Fig. 4). Analysis of 28,306 registered neurons across 11 animals revealed that responses to virtual conspecifics were most prominent in the TeO (51% of active neurons), followed by pretectum (12%), DT (10%) and nucleus isthmi (10%) (Extended Data Fig. 4), qualitatively matching the c-fos mapping results (Fig. 2c).

Fig. 2: Dorsal thalamus neurons are activated by fish-like motion.
figure 2

a, Schematic of the experimental set-up. b, Example imaging planes in the TeO and DT with all segmented neuronal ROIs, representative for n = 11 animals (left). Right, representative normalized ∆F/F traces of one tectal and one thalamic neuron. c, Horizontal view of all responsive neurons (n = 28,306 total, 2,573 ± 1,175 per fish) from 11 fish (18–22 d.p.f.) aligned to a juvenile reference brain (left). Colour indicates mean baseline ∆F/F (no stimulus), and responses to continuous and bout-like motion. The yellow line indicates the DT. Right, mean responses of all DT neurons per fish (n = 258 ± 198, 2,837 total) from n = 6 animals with a number of recorded DT-BPNs of >30. Data are mean ± 1 s.d. d, Mean ∆F/F responses of example neurons from b to all stimulus frequencies. e, The distribution of all responsive neurons from n = 11 fish in the reference brain. The colour map shows the BPI. Opacity scales with absolute BPI (0–0.5). f, The distribution of BPNs (312 ± 143 neurons per fish, 3,437 total). Colour reflects a Gaussian KDE; contours delineate densities of 0.1, 0.15 and 0.3 BPNs per 1,000 μm3. n = 11 fish. g, DT-BPN tuning to stimulus frequency. The mean peak across neurons was 1.2 Hz  ± 1.6 Hz. n = 563 neurons. The black lines represent the mean values of individual animals. Data are from a subset of animals in e with a number of recorded DT-BPNs of >30. n = 6 animals. h, DT-BPN tuning to average speed at 1.5 Hz or 60 Hz and acceleration. The cartoons show stimulus displacement over time. Data are mean ± 1 s.d. of all of the neurons shown above. n = 291 neurons. The black lines indicate individual animals. n = 4 fish, 73 ± 10 neurons per fish. i, DT-BPN and PreT responses to local dot motion and whole-field motion and their anatomical distribution. Circles (left) show the mean of individual animals. n = 4 fish, 77 ± 15 (DT-BPNs), 114 ± 48 (PreT) neurons per fish. Data are mean ± 1 s.d. j, The distribution of BPNs in 7 d.p.f. larvae (n = 4 fish, 230 ± 87 neurons per fish) as in f. Scale bars, 100 μm (b and i) and 200 μm (c, e, f and j).

Source data

To identify neurons that encode biological motion, we computed a bout preference index (BPI) as the normalized difference in the response to behaviourally attractive bout-like motion versus unattractive continuous motion (Fig. 2d,e). The majority of neurons did not differentiate between bout frequencies (mean BPI 0.01 ± 0.07). However, 13 ± 5% of all neurons scored BPI > 0.5, corresponding to a threefold increase in ∆F/F for bout-like motion compared with continuous motion in these neurons. We next focused our attention on these putative bout preference neurons (BPNs). In a subset of animals, we determined that the BPN population was largely unresponsive to looming and moving grating control stimuli (Extended Data Fig. 5a). Most BPNs were located in the TeO (36%) and DT (18%) (Extended Data Fig. 4). Gaussian kernel density estimation (KDE) yielded the DT as the anatomical area of highest BPN density (Fig. 2f). Within the DT, BPNs were concentrated in a posterior cluster, overlapping with DT c-fos activity (Fig. 1c). By contrast, tectal BPNs were distributed broadly along the anteroposterior and dorsoventral axes with lower relative frequency (Extended Data Fig. 4c). The anatomical overlap of c-fos and GCaMP signals in the TeO and DT suggests that virtual conspecifics in the open-loop configuration activate key circuits for social recognition even in immobilized animals.

If activity of DT-BPNs drives shoaling behaviour, their tuning should match specific parameters of biological motion. DT-BPNs had a response peak at a stimulus bout frequency of 1.2 ± 1.6 Hz, closely matching the juvenile’s typical swim bout frequency of around 1.25 Hz, which also most effectively elicits shoaling2 (Fig. 2g). To examine whether DT-BPNs encode acceleration or average speed of virtual conspecifics, we collected a separate dataset and systematically varied each parameter independently (Fig. 2h). At continuous motion, DT-BPNs were barely modulated by stimuli moving at 2 to 150 mm s−1. At 1.5 Hz, DT-BPNs yielded maximal responses at 7.2 ± 1.7 mm s−1 (Fig. 2h), similar to a juvenile’s typical swim speed at around 5 mm s−1 and, again, matching the behavioural tuning2. Morphing acceleration from continuous to bout-like along Gaussian speed profiles at fixed average speed of 5 mm s−1 and 1.5 Hz bout frequency modulated DT-BPN responses as a function of acceleration with a maximum at the highest possible acceleration of 12 m s−2 (projector limit). Taken together, DT-BPNs detect biological motion through periodic acceleration at fish-like speed and bout frequency, and are therefore tailored for the detection of juvenile zebrafish during shoaling.

To relate DT-BPN responses to naturalistic visual percepts, we tested another set of animals with ‘dot shoaling’ stimuli on trajectories that recapitulate positions of conspecifics relative to a real focal animal during shoaling (Extended Data Fig. 5b). DT-BPNs were strongly and persistently activated by such stimuli (Extended Data Fig. 5d). Self-motion during shoaling also generates global motion with temporal dynamics similar to the fish-like cues. To examine whether global motion activates DT-BPNs, we rotated whole-field stimuli with matched bout-like motion and spatial frequency (Extended Data Fig. 5c). Global motion strongly activated pretectal neurons27 but not DT-BPNs (Fig. 2i), suggesting that the latter encode fish-like biological motion and not self-motion-induced visual signals.

Zebrafish shoaling with real or virtual conspecifics emerges at around two weeks of age2,6,28, whereas younger fish show mainly interanimal repulsion2,29. We therefore hypothesized that functional maturation of BPNs coincides with this transition. Contrary to this prediction, BPNs already existed in larvae, but with lower fractions compared with the juveniles (10 ± 3% of all recorded neurons). Furthermore, BPNs were similarly distributed in the brain, with the KDE centre in the DT (Fig. 2j). Registration of the larval data to the Max Planck Zebrafish Brain Atlas30,31 (https://mapzebrain.org) confirmed localization of the DT-BPN cluster to the vglut2a-positive DT area, ventrally touching the gad1b-positive VT32. The larval DT-BPN cluster was molecularly defined by the expression of cort, as seen in juveniles, and pth2 (Extended Data Fig. 5e), a gene of which thalamic expression tracks the density of conspecifics in zebrafish through mechanosensory signals33. Overlap with pth2 raises the possibility of multimodal integration of conspecific signals in DT. Furthermore, the mean frequency tuning curve across all larval DT-BPNs and mean tuning peak were similar to juveniles (Extended Data Fig. 5f). Finally, we determined that DT-BPNs also developed in socially isolated larvae, demonstrating that tuning to conspecific motion in DT is largely independent of social experience (Extended Data Fig. 5g). Thus, functional BPN maturation precedes shoaling, and the developmental transition is either gradual in nature or requires a change in additional circuit nodes. The presence of BPNs in pre-juvenile stages provides an opportunity to investigate the circuit with the experimental tools and resources available in larvae.

EM reconstruction of the biological motion circuit

Across vertebrates, the thalamus acts as a gateway for state-dependent sensory information32,34. We hypothesized that DT-BPNs could serve that role for social cues, connecting visual brain areas and the conserved social behaviour network12,27. To reveal the anatomy of the DT-BPN circuit, we analysed an electron microscopy (EM) whole-brain dataset of a larval zebrafish at 5 days post-fertilization (d.p.f.), acquired at synaptic resolution35. We registered the larval DT onto the EM volume to identify the cell body location of putative BPNs (pBPN) in the DT (Extended Data Fig. 6a–c). We randomly selected and completely traced 34 cells in this region (Fig. 3a,b). All of these cells extended their primary neurite ventrolaterally and showed both dendritic and axonal arborizations in a thalamic neuropil region, posterior to retinal arborization field AF4 (Fig. 3b,c). In this region, we randomly selected presynaptic contact sites on putative BPN dendrites, supported by an automated synapse segmentation35 (Methods), and identified their partner neurons (Fig. 3c). A total of 26.7% of input synapses were provided by other DT neurons (Extended Data Fig. 6d) and, similarly, 26.7% arrived from tectal periventricular projection neurons (PVPNs; Fig. 3d). We also identified synaptic input from the VT (16.7%), ipsi- and contralateral nucleus isthmi (10%; Extended Data Fig. 6e), superior ventral medulla oblongata (6.7%), torus semicircularis (6.7%), hypothalamus (3.3%) and cerebellum (3.3%). Overall, the majority of input synapses were established by ipsilateral neurons (76.7%). Identified PVPNs (n = 13) send their axons ventrally through the postoptic commissure, and make ipsi- or contralateral connections to putative BPNs within the thalamic neuropil region. A single PVPN can be presynaptic to several putative BPNs (Fig. 3e), and a single BPN can receive input from several PVPNs, both ipsi- and contralaterally (Extended Data Fig. 6f). Next, we quantified presynaptic partners of DT-projecting PVPNs: 55% of all input synapses arrived from a specific class of retinal ganglion cells, which exclusively arborized in the SFGS3/4 layer of the tectum36 (Fig. 3f); 35% were from tectal periventricular interneurons and, interestingly, 10% of input synapses arrived from other PVPNs, which also projected to the DT and contacted pBPNs.

Fig. 3: Connectivity of the larval thalamic bout-preference region.
figure 3

a, Frontal view of an EM reconstruction of neurons in the bout-preference region (BPN KDE, red) of the DT. Axons are shown in blue. b, Top view of the neurons shown in a. c, Magnified view of the thalamic arborization field, outlined in b. Synapses with identified presynaptic partners are shown as blue spheres. One representative synapse of a tectal PVPN axon (white arrow) onto a putative BPN’s dendrite (pBPN, black arrow) is indicated below (randomly chosen). d, Frontal view of tectal PVPNs (green) and their postsynaptic pBPN partners (red). e, Example of a single PVPN (green), which makes ipsilateral synaptic contacts to at least four identified pBPNs (red). f, Side view of the left (top) and the right (bottom) tectal SFGS layers, showing the PVPNs (green) and their presynaptic retinal ganglion cell axons (different colours). PVPN axons are not shown for clarity. g, Side view of the pBPNs (red, axons in blue) and their axonal target regions (Supplementary Video 2). AF4 (yellow) is shown as a reference. h, Circuit diagram. Identified cell types are indicated next to arrows with cell numbers in parentheses. For c, scale bar, 0.5 µm.

We further investigated the downstream target regions of putative DT-BPNs. Of the 34 traced DT neurons, 24 had long projection axons and made synaptic contacts in other brain areas, whereas 10 neurons had local (n = 3) or premature (n = 7) axonal projections. Our analysis revealed the superior ventral medulla oblongata (n = 9 cells), rostral hypothalamus (n = 8), intermediate hypothalamus (n = 5), contralateral thalamus (n = 3), preoptic region (n = 1) and the tectum (n = 3) as axonal targets (Fig. 3g,h). Putative BPNs that projected to the tectum targeted the SFGS layer, where they contacted tectal periventricular interneurons (Extended Data Fig. 6g).

To complement the EM tracings, we next analysed the morphology of traced neurons residing in the BPN-KDE of the light microscopy mapzebrain atlas30. We identified 13 putative BPNs that all extended their primary neurites ventrolaterally into a neuropil area posterior of AF4, consistent with the EM data. Of these neurons, 12 projected into other brain areas, including the tectum (n = 1), preoptic area (n = 1), rostral hypothalamus (n = 1), intermediate hypothalamus (n = 3), superior ventral medulla oblongata (n = 5) and inferior ventral medulla oblongata (n = 2) (Extended Data Fig. 6h,i).

These findings suggest a pathway for the detection of biological motion: retinal information reaches DT-BPNs through tectal PVPNs and is subsequently transmitted to brain areas that are proposed to regulate social behaviour, including the preoptic region, and clusters in the rostral, intermediate and caudal hypothalamus, which showed c-fos signal during shoaling behaviour (Fig. 1f). Gradual maturation of DT projections and/or addition of synapses, such as those connecting the ventral forebrain at around 14 d.p.f., may then underlie the emergence of shoaling at the juvenile stage37.

Social attraction requires the biological motion circuit

As TeO and DT-BPNs are activated by fish-like motion, we hypothesized that this pathway is necessary for shoaling. To test this hypothesis, we ablated TeO and DT in juvenile animals and analysed effects on free-swimming interactions with virtual conspecifics.

We genetically targeted tectal cells for chemogenetic ablation using the SAGFF(lf)81c enhancer trap line to drive expression of nitroreductase. SAGFF(lf)81c is strongly expressed in tectal neurons and weakly expressed in parts of the pretectum, habenula, anterior DT and anterior VT (Fig. 4b and Extended Data Fig. 8). Although ablated animals appeared healthy and had slightly faster swim kinetics, they showed a severe loss of attraction towards virtual conspecifics (P < 0.001; Fig. 4c,d and Extended Data Fig. 7). To investigate the spatial scale of this behavioural defect, we computed neighbour density maps that represent relative spacing with virtual conspecifics. In the controls, neighbour maps revealed a central zone of short-range (5–15 mm) repulsion, surrounded by a ring of long-distance attraction (10–30 mm). In ablated animals, this balance was shifted. The ring of attraction was strongly reduced, whereas the zone of repulsion was intact (Extended Data Fig. 7a,b). Moreover, looming-induced startle responses were at the control level in ablated animals (Extended Data Fig. 7c). Finally, we confirmed that SAGFF(lf)81c ablation disrupted shoaling with a real conspecific (P < 0.001; Extended Data Fig. 7d).

Fig. 4: The TeO–DT circuit is necessary for social attraction.
figure 4

a, Schematic of the shoaling test after chemogenetic ablation. ctr., control. b, Two-photon image of 21 d.p.f. SAGFF(lf)81c:Gal4, UAS:NTR-mCherry and elavl3:H2B-GCaMP6s animals 24 h after ablation versus control treatment. Representative of three similar fish. c,d, Reduced neighbour density (c) and attraction (d) in 81c:NTR-ablated animals. Short-range repulsion is intact. n = 13 (ablated) and n = 15 (control) animals. The neighbour maps in c show the probability of finding the stimulus in space with the animal at the centre of the map, heading up. Each map is 60 mm × 60 mm. AU, arbitrary units. e, Schematic of volumetric two-photon imaging in the DT after 81c:NTR ablation. f, Mean and example ΔF traces of all DT-BPNs for ablated and control animals show that 81c:NTR ablation strongly reduces responses to bout-like motion. The vertical lines mark the start of stimulus presentation. The shaded areas denote 1 s.d. around the mean. n = 25 (ablated) and n = 849 (control). g,h, Fewer DT-BPNs in 81c:NTR (-ablated) animals. g, The anatomical location of all DT-BPNs across animals coloured by mean ΔF/F to bout-like motion. n = 25 (ablated) and n = 849 (control). The yellow area shows the DT. h, Quantification of DT-BPNs per animal. n = 7 (ablated) and 9 (control) animals. Cohen’s d effect size is shown. The P value was calculated using the two-sided Mann–Whitney U-test. i, Attraction is strongly reduced in s1026tEt:NTR-ablated animals. Short-range repulsion is intact. n = 7 (ablated), n = 21 (control) animals. j, Bilateral two-photon laser ablation of neurons in the DT-BPN region in juvenile zebrafish. k, Reduced attraction after DT laser ablation. n = 7 (ablated) and n = 9 (embedding control) animals. Short-range repulsion is intact. Data in d, h, i and k represent individual animals and mean ± 1 s.d. Cohen’s d effect size is shown. The P values were calculated using two-tailed Student’s t-tests with no correction. For b, e, g and j, scale bars, 100 µm.

Source data.

To understand the neural correlates of these effects, we recorded neuronal responses to continuous and bout-like motion in DT after SAGFF(lf)81c ablation. We found that ablation reduces the number of DT-BPNs by more than 95% (P = 0.0014, 4 ± 6 versus 94 ± 4 cells per animal) (Fig. 4f,g). We observed similar trends for dot motion at 1.5 and 60 Hz (continuous), at which tectal ablation significantly reduced the number of top-scoring neurons (P < 0.01). Responses to looming and translational grating motion in the surrounding pretectum were also reduced in ablated 21 d.p.f. juveniles but not in ablated 7 d.p.f. larvae (Extended Data Fig. 8). These results are consistent with our inferred wiring diagram, which places tectal PVPNs upstream of DT-BPNs as their main sensory driver.

Next, we tested the necessity of DT for shoaling by chemogenetic ablation using the s1026tEt enhancer trap line to drive expression of neuronally restricted nitroreductase. The s1026tEt Gal4 insertion drives strong and selective expression of a UAS-linked nitroreductase transgene in DT of juvenile zebrafish (Extended Data Fig. 8a). We found that ablation of s1026tEt cells in juveniles caused a selective loss of attraction (P = 0.002) and a modest increase in swim bout frequency, whereas short-range repulsion and visual escapes remained intact (Fig. 4i and Extended Data Fig. 7e). Finally, we tested the necessity of DT-BPNs directly by laser-ablation of the DT-BPN area in 21 d.p.f. animals. After ablation, we found a selective loss of attraction, whereas short-range repulsion, visual escapes and overall swim kinetics remained intact (P = 0.002; Fig. 4j,k and Extended Data Fig. 7e). Together, these results suggest that SAGFF(lf)81c neurons and DT-BPNs are essential elements of a pathway that mediates the affiliative aspect of shoaling, but are dispensable for collision avoidance during shoaling and visual escape from a looming threat.

Discussion

Affiliation with conspecifics is a core building block of social behaviours that offer benefits for collectives, such as efficient food detection or evasion of predators3,8,38. As a consequence, animals need to robustly recognize neighbours in cluttered environments during highly dynamic interactions. These interactions rely on the balance of attraction and repulsion into an appropriate distance1,4,5. Although empirical models of collective behaviour have postulated distinct individual-level behavioural rules5,7,8, the neuronal implementation of such coordination has remained unclear, largely because mutual interactions mask causal relationships between conspecific signals and receiver responses. Our results in shoaling zebrafish now highlight fish-like motion2,11 as a salient trigger signal of an attraction pathway that converges on a multimodal33, socially activated DT cluster and feeds into hypothalamic areas that are probably homologous with nodes of the proposed social behaviour network12,13,14,21. Neuronal activity in this circuit therefore represents an inherently kinetic metric of neighbouring animals, in contrast to current shoaling models that emphasize positional information1,4,6,20. By contrast, short-range repulsion engages a separate circuit, probably overlapping with the collision-avoidance pathway39,40,41. These results add support for the emerging importance of visual motion cues in social recognition10,42,43,44. The correspondence of sensory activation in freely shoaling versus immobilized animals with virtual conspecifics suggests that this approach can also reveal the role of neural circuit nodes in the downstream network during shoaling for an understanding how collective dynamics emerge from neuronal computations in individuals.

Methods

Animal care and transgenic zebrafish

Adult, juvenile and larval zebrafish (Danio rerio) were housed and handled according to standard procedures. All animal experiments were performed under the regulations of the Max Planck Society and the regional government of Upper Bavaria (Regierung von Oberbayern), approved protocols: ROB-55.2Vet-2532.Vet 03-15-16, ROB-55.2Vet-2532.Vet 02-16-31, and ROB55.2Vet-2532.Vet 02-16-122. Experimental animals were outcrosses to TL or TLN (nacre) unless otherwise noted. The following transgenic lines were used: Tg(elavl3:H2B-GCaMP6s)jf545, SAGFF(lf)81c (TeO Gal4 line)46, Tg(UAS-E1B:NTR-mCherry)c26447, Et(fos:Gal4-VP16)s1026t (DT Gal4 line)48, Tg(UAS:BGi-epNTR-TagRFPT-utr.zb3)mpn420 (this study).

Larvae were raised in Danieau solution under a 14–10 h light–dark cycle at 28.5 °C until 6 d.p.f. For experiments in juveniles, animals were then raised under standard facility conditions at 28.5 °C in groups of 20–25 individuals. The fish were fed by feeding robots once a day with artemia and 2–3 times a day with dry food.

Shoaling assay and behaviour quantification

Shoaling with real and virtual conspecifics was assayed as previously described2. In brief, 15 or 35 individual animals were transferred individually into shallow watch glass dishes of 10 cm or 7 cm diameter, respectively, separated by a grid of visual barriers and resting on a projection screen. Custom-written Bonsai49 workflows were used to project stimuli to each animal and to track animal location at 30 fps. Stimuli were black dots on a white background moving along a predefined, synthetic-trefoil shaped trajectory at an average speed of 5 mm s−1. For continuous motion, the stimulus position was updated 30 times per second. For bout-like motion, the stimulus position was updated once every 666 ms. Dot diameter was 2 mm unless noted otherwise, and 0 mm in the no-stimulus condition.

To assay shoaling of pairs of real conspecifics, we introduced a second animal in the same dish and did not show any projected stimuli. FastTrack50 was used for post hoc tracking of real pair shoaling.

Attraction and neighbourhood maps were quantified as previously described2 using custom-written Python software. We calculate the ‘real’ average interanimal distance or animal dot distance for each animal in 5 min chunks (IADr). Next, we generate 10 time-shifted trajectories and recalculate the shifted average inter animal or animal dot distance (IADs) for each time shift. Mean IADs for all time shifts are used to compute attraction as (IADs – IADr)/IADs.

For neighbourhood maps, neighbour position time series were transformed into the focal animal’s reference frame to compute a binned 2D histogram.

Repulsion was quantified as the reduction in attraction at the centre of each animal’s neighbour density map. Neighbour density maps were gaussian-filtered (sigma = 3 mm) before obtaining 24 radial line scans (width of 5 mm) starting from the centre of the map. Repulsion was the area above the average line scan, at radii less than the radius at which maximum neighbour density occurred (Extended Data Fig. 7a), divided by the full length of the scan (29 mm).

Looming stimuli were presented in the virtual shoaling setup41. Looming discs appeared once every minute at a defined offset of 5 mm to the left or the right from the current centre of mass of each animal. Looming discs expanded within 500 ms to the indicated final size and followed the animal. To compute an escape fraction, we defined an escape response as a trial in which the animal moved more than twice as far in a time window of 1 s immediately following the loom compared to the 1.3 s before. Bout duration was computed using peak detection on the velocity time series of each animal.

c-fos activity mapping

Shoaling assay for c-fos

For c-fos labelling, we used nacre;elavl3:H2B-GCaMP6s fish at 21 d.p.f. Thirty five fish were transferred into individual dishes and left without stimulation in the presence of white projector illumination from below for acclimatization and to establish a low, non-social c-fos baseline. Each animal was assigned randomly to one of the four stimulus groups. After 2 h, continuous or bout-like motion were shown to groups 1 and 2, respectively, whereas groups 3 and 4 continued to see no stimulus. After 45 min, groups 1, 2 and 3 were quickly euthanized and fixed. Four animals of group 4 were then transferred into the dishes of four other animals of this group for shoaling. After 45 min, these eight animals were euthanized and fixed as well.

HCR staining and imaging

Animals were euthanized and fixed on 4% ice cold paraformaldehyde (PFA). The PFA was washed out after 24 h with 1× PBS and the samples were gradually dehydrated and permeabilized with methanol and stored in −20 °C for several days until the HCR in situ labelling was performed. All of the HCR reagents were purchased from Molecular Instruments and the staining was performed according to the manufacturer's protocol for whole-mount zebrafish larvae. In brief, the samples were separated into 2 juvenile fish per single 1.5 ml Eppendorf tube. Rehydration steps were performed by washing for 5 min each in 75% methanol/PBST (1× PBS + 0.1% Tween-20), 50% methanol/PBST, 25% methanol/PBST and finally five times with 100% PBST. The samples were permeabilized with 30 µg ml−1 proteinase K for 45 min at room temperature, followed by postfix with 4% PFA for 20 min at room temperature and 5 washes in PBST for 5 min each. The samples were prehybridized in a 500 µl probe hybridization buffer (Molecular Instruments) for 30 min at 37 °C. Hybridization was performed by adding 2 pmol of each probe set to the hybridization buffer and incubating for 16 h at 37 °C. Probe sets for c-fos (B5 initiator), cort (B3 initiator) and elavl3 (B2 initiator) were purchased from and designed by Molecular Instruments. To remove the excess probes, the samples were then washed 4 times for 15 min each with a wash buffer (Molecular Instruments) at 37 °C, followed by 2 washes of 5 min each with 5× SSCT (5× SSC + 0.1% Tween-20) at room temperature. Pre-amplification was performed by incubating the samples for 30 min in an amplification buffer (Molecular Instruments) at room temperature. The fluorescently labelled hairpins (B2-488, B3-647, B5-546) were prepared by snap cooling: heating at 95 °C for 90 s and then cooling to room temperature for 30 min. Hairpin solution was prepared by adding 10 µl of the snapped-cooled hairpins (3 µM stock concentration) to a 500 µl amplification buffer. The pre-amplification buffer was removed, and the samples were incubated in the hairpin solution for 16 h at room temperature. The excess hairpins were washed three times with 5× SSCT for 20 min each wash, and the samples were stored in 5× SSCT in the dark at 4 °C until imaging.

For dorsal imaging, the samples were embedded in 2.5% low melting agarose in 1× PBS. Imaging was performed with a Leica SP8 confocal microscope equipped with a ×20 water-immersion objective. z-Stacks, comprising four tiles, covering of the entire brain were taken (final stitched image size: 1,950 px × 1,950 px, 1,406 µm × 1,406 µm, 3 µm in z). All 32 samples were imaged with the exact same laser power, gain, zoom, averaging and speed to faithfully quantify and compare the fluorescent signal between the samples. For ventral imaging, the samples were removed from the agarose and dissected to remove the jaw and the gills. After the dissections, the samples were embedded upside down and imaged in the same manner. Four brains were lost during ventral imaging and were therefore excluded entirely from the subsequent analysis.

Image registration

Image registration was performed using Advanced Normalization Tools (ANTs51) running on the MPCDF Draco/Raven Garching computing cluster. Before registration, stacks were batch-processed in ImageJ. Each stack was downsampled to 512 px width at the original aspect ratio using bilinear interpolation, split into individual channels and saved as .nrrd files. For ventral stacks, artefacts of the dissection such as left-over autofluorescent muscle fibres and skin were masked before registration. Initial attempts to register the elavl3 HCR channel of dorsal or ventral HCR confocal stacks to a live-imaged two-photon reference of elavl3-H2B-GCaMP6s expression were not successful, probably due to deformations resulting from the HCR protocol and diverse qualitative differences in image features between the imaging modalities. Instead, separate dorsal and ventral HCR registration templates were generated from scratch by running antsMultivariateTemplateConstruction2.sh on three manually selected stacks. Next, all dorsal and ventral stacks were registered to their respective templates using antsRegistration. Finally, the ventral template was registered to the dorsal template using affine + b-spline transformations via antsLandmarkBasedTransformInitializer with the help of 25 manually curated landmarks in each stack before applying standard antsRegistration. The resulting ventral-to-dorsal transform was then applied to re-register all ventral stacks into one common (dorsal) reference frame.

c-fos signal intensity quantification

Image analysis was performed using custom scripts in Python. Registered dorsal and ventral stacks were merged as the arithmetic mean intensity for each animal. To normalize to a drop in signal intensity with tissue depth, the c-fos signal was divided voxel-wise by the elavl3 HCR signal. For visualizations of imaging planes, the elavl3 signal used in normalization was filtered by a 3D gaussian (filter width: 55 µm, 55 µm, 15 µm x,y,z). For area-wise c-fos quantification, unfiltered elavl3 signal was used in normalization. To identify activity clusters, merged stacks from all animals per condition were generated by finding the maximum intensity at each voxel across animals. A combined RGB hyperstack was generated that showed c-fos signal for each condition, cort HCR and elavl3 HCR for reference in different colours for visual inspection. Activity clusters were manually drawn as 3D masks on the hyperstack using the ImageJ segmentation editor on orthogonal overlay views. Masks were drawn with the intent to outline prominent, distinct clusters of c-fos signal, irrespective of their modulation by social condition. The full hyperstack, including cluster masks is available. Brain areas housing the activity clusters were identified by comparison of the elavl3 reference to the mapzebrain atlas30 and additional resources13,52,53.

Individual cort- and c-fos-positive cells in DT were counted manually using the ImageJ cell counter plugin. For statistical analysis across activity clusters and conditions, bulk normalized c-fos signal was computed as the average intensity of all voxels belonging to a given cluster. Effect size was determined in each cluster for each condition versus the no-stimulus condition by pairwise computation of Cohen’s d defined as the difference of the means divided by the pooled standard deviation. To determine significant activity modulation compared to the no-stimulus condition, we performed repeated two-tailed t-tests and corrected for multiple comparisons in each family of tests (each activity cluster) using the Bonferroni correction. Hierarchical clustering of the activity clusters was performed on the effect sizes using the seaborn method clustermap with the default parameters for average Euclidean clustering.

Functional two-photon calcium imaging

Two-photon functional calcium imaging was performed on 6–8 d.p.f. larvae and 17–22 d.p.f. juvenile elavl3:H2B-GCaMP6s transgenic fish without paralysis or anaesthesia. The 6–8 d.p.f. larvae were embedded in 2% agarose with the tail freed as previously described39. Juveniles (17–22 d.p.f.) were embedded in 3% agarose. As juvenile zebrafish are prone to hypoxia in this preparation, several precautions were taken. A drop of low-melting agarose was placed onto a petri dish and allowed to cool before a fish was introduced and oriented with a pipette tip. Once solidified, agarose was removed from the mouth, gills and tail using scalpels to restore active and passive breathing (Extended Data Fig. 3). Additional oxygen was supplied by continuously perfusing the dish. The perfusion medium consisted of fish water freshly oxygenated to saturation at the start of the experiment and diluted 1:1 with demineralized water to support ionoregulation and buffered with 1.2 mM NaH2PO4 and 23 mM NaHCO354. To monitor health, we checked heartbeat and breathing movements of gills and mouth before and after an experiment. Only fish that were breathing and moving after the end of the experiment were included in the analysis. The embedded fish were mounted onto the stage of a modified two-photon moveable objective microscope (MOM, Sutter Instrument, with resonant-galvo scanhead) with a ×20 objective (Olympus XLUMPLFLN, NA 1.0) and imaged for at least 60 min. Typically, fish resumed swimming immediately after release from embedding. Only fish that did not drift up or down in their preparation were used for analysis. Fish in which no tectal responses could be observed were eliminated from the analysis. Fast volumetric imaging of the tectum and/or thalamus was performed using a custom-built remote focusing arm added before the microscope (Extended Data Fig. 3b). The remote focusing path was constructed using the 30 mm and 60 mm Thorlabs cage system, and consists of the following parts (in order of forwards traversal): a half-wave plate (Thorlabs, AHWP05M-980), a polarizing beam splitter (Thorlabs, PBS102), two lenses (Thorlabs, AC254-100-B-ML and AC508-200-B-ML), a quarter-wave plate (Thorlabs, AQWP10M-980), remote objective (Nikon, CFI ×16 0.8 NA), and a gold mirror (Thorlabs, PF05-03-M01) mounted onto a custom piezo (PPS-D08300-001 nanoFaktur, 300 µm closed loop range, with a nPoint LC.402 controller). The piezo was mounted on a xyz translation stage with tip-tilt control. Changing the mirror position is rapid (for the step sizes used for imaging, 1–2 ms) and results in a change of focus of the excitation beam exiting the main objective. Refocusing through the remote arm enabled rapid sequential imaging of 6 planes with a nonlinear step size ranging from 6–24 µm at 5 volumes per second. Remote focusing was not used for the high-resolution single-plane imaging in Fig. 2h,i. The plane size ranged from 370 µm × 370 µm for larvae to 1,075 µm × 1,075 µm for juveniles. Laser power ranged from 12.3 mW to 15.4 mW. The spatial sampling (0.7–2.1 µm px−1) and optical resolution enabled discrimination of single cells with cell body diameters typically in the range of 5 µm to 8 µm.

z-Stack acquisition and image registration

For each functionally imaged fish, a z-stack of the entire brain was taken (512 × 512 or 1,024 × 1,024 pixels, 2 µm in z, 835–920 nm laser wavelength, plane averaging 50–100×) with the two-photon microscope. Larval data were registered to the mapzebrain atlas30 using the elavl3:H2B-GCaMP6s reference. For juvenile data, a standard brain was generated from three high-quality z-stacks (150× frame averaging) as described in the ‘c-fos activity mapping’ section and each juvenile brain was registered to it. The generation of a standard brain and the parameters used for ANTs registration have been described in detail previously30.

To align functional regions of interest (ROIs) from 2P data to a common reference frame, a two-step strategy was used. First, average frames of all imaging planes were registered to individual z-stacks using template matching. Converted ROI locations in z-stack coordinates were then transformed to the larval and juvenile common reference frames by running the ANTs command antsApplyTransformsToPoints with the matrices from the z-stack registrations.

Visual stimuli

Visual stimuli were designed using PsychoPy and projected by an LED projector (Texas Instruments, DLP Lightcrafter 4500, with 561 nm long-pass filter) on Rosco tough rolux 3000 diffusive paper placed into a petri dish filled with fish water.

Frequency tuning

A black dot moving on a circular trajectory (radius, 18 mm) with the fish head in the centre was shown starting either perpendicular to the fish at the left, or in front of the fish. The dot was moved in discrete jumps at 0.75, 1.5, 3.0, 6.0 or 60.0 Hz at an overall speed of 5 mm s−1 (15.9 degrees (deg) s−1). Each frequency was presented using a dot diameter of 4 mm (12.7 deg). Moreover, 1.5 Hz and 60.0 Hz stimuli were also presented with dot diameters of 2 mm (6.4 deg) and 8 mm (25.1 deg). Both clockwise and counter-clockwise presentations were shown. The frequency, direction and, if applicable, size were randomly drawn at each stimulus instance. Each stimulus had a duration of 22.6 s and was followed by a 20 s break. A total of 13 stimuli were shown per 10 min recording. Five to nine of these recordings were performed in each fish, leading to an average of four to six presentations of each stimulus. For Fig. 2b, only responses to dots (4 mm diameter) with 1.5 Hz and 60 Hz bout frequency were analysed. For Fig. 2g, again only responses to 4 mm dots were analysed.

Specificity

Naturalistic stimulus trajectories consisted of a 4 mm diameter dot (12.7 deg) moving along real trajectories from one of two interacting juvenile zebrafish that were previously recorded2. The trajectory was computed as a fish-centric view of the conspecific with respect to a focal fish. To avoid noise in the heading calculation due to tracking jitter, the trajectory was convolved with a normalized hamming kernel (mode: valid, window length: 20). The naturalistic motion sequences were shown for 1 min each (Extended Data Fig. 5b). For the whole-field motion stimulus an image was created by combining random intensities and restricted spatial distributions in Fourier space, matching the size of the moving dot (Extended Data Fig. 5c). The computed image either rotated in discrete jumps of 1.5 Hz or continuously at 60 Hz. In both cases the stimulus took 22.6 s to finish a complete round. All stimuli, 1.5 Hz dot, 60 Hz dot, 1.5 Hz whole-field, 60.0 Hz whole-field and naturalistic dot motion were shown in a pseudo-random order during 6x10 min recordings.

Kinetic parameters

Presented 4 mm diameter (12.7 deg) dots moved clockwise on a circular trajectory (18 mm radius). Five speeds were tested using a continuously moving dot: 2.5, 5, 15, 50 and 150 mm s−1 (8, 15.9, 47.7, 159.2 and 477.5 deg s−1). Five speeds at a bout frequency of 1.5 Hz were tested by increasing the distance the dot moved during each bout. This increased both the average speed and the acceleration during bouts. The following parameters were tested: 1.25 mm s−1; 3 m s−2, 2.5 mm s−1; 6 m s−2, 5 mm s−1; 12 m s−2, 10 mm s−1; 24 m s−2, and 20 mm s−1; 48 m s−2 (4 deg s−1; 9.5 × 103 deg s−2, 8 deg s−1; 19.1 × 103 deg s−2, 15.9 deg s−1; 38.2 × 103 deg s−2, 31.8 deg s−1; 76.4 × 103 deg s−2 and 63.7 deg s−1; 152.8 × 103 deg s−2). Finally, for changing acceleration during each bout, we modelled each bout as a gaussian speed profile and changed the width of the curve. Each stimulus still had an average speed of 5 mm s−1 (15.9 deg s−1) through a normalization factor. The following peak accelerations were tested: 0.0, 0.02, 0.5, 2.0 and 12.0 m s−2 (0, 0.06, 1.6, 6.3 and 38.2 × 103 deg s−2).

Control stimuli after tectal ablation

Control stimuli consisted of translational gratings moving caudorostrally with respect to the fish (width, 20 mm; frequency, 0.12 Hz; duration, 20 s) and a looming stimulus (expansion from 0.6 deg to 110 deg in 83 ms, delay 10 s with disk and 20 s without stimulus) centred below the fish. One grating was shown at the beginning, followed by the dot stimuli, another grating and finally the looming stimulus. These recording sessions took 10 min each and were separated by a 1 min break to avoid potential habituation or response suppression due to the looming stimulus.

Data analysis for two-photon imaging

Suite2P55 was used for motion correction, ROI detection, cell classification and signal extraction. For the entire analysis, a GCaMP6s time-constant of 7 s was used to accommodate the slow kinetics partially due to the nuclear localization of this sensor. On the basis of a visual inspection of the raw data, a cell diameter of 4–6 px was used. In detail, raw recording files were deinterleaved into separate time series for each plane. An extra motion-correction step was required owing to ripple noise stemming from the resonant mirror: to avoid spurious alignment to the noise pattern, rigid and non-rigid motion correction was performed on a spatially low-pass filtered time series (Gaussian, sigma = 4). The resulting motion-correction parameters were applied to the raw data. Next, the time series were downsampled fivefold to one volume per second. On the downsampled data, ROIs were detected and fluorescent traces were extracted.

Thresholding

Neuron ROIs were thresholded in a two-step process. First, the built-in Suite2p classification algorithm iscell was applied using the default parameters. Second, iscell+ ROIs that showed a mean ∆F/F response to any stimulus above the 95th percentile (Fig. 2)/90th percentile (Fig. 4).

Mean ∆F/F responses

For each functional ROI, the fluorescent trace was normalized and split into stimulus episodes. ∆F/F was computed by using the 5 s before stimulus onset as the baseline. ∆F/F temporal responses were averaged across stimulus presentations per stimulus and then averaged over time to receive one value per stimulus.

BPI

On the basis of the behavioural tuning curves to bout frequency2, stimuli were split into bout-like (0.75–3 Hz) and continuous (6–60 Hz) categories, regardless of stimulus size or directionality. BPI was defined as the difference in mean over mean ∆F/F to bout-like stimuli and mean over mean ∆F/F to continuous stimuli divided by their sum (equation (1)). BPNs were considered all ROIs that scored BPI >0.5, which equates to a threefold higher bout response.

$$\frac{{\rm{mean}}\,\triangle F/F\,({\rm{bout}})\,-\,{\rm{mean}}\,\triangle F/F\,({\rm{continuous}})}{{\rm{mean}}\,\triangle F/F\,({\rm{bout}})\,+\,{\rm{mean}}\,\triangle F/F\,({\rm{continuous}})}$$
(1)

Tuning peaks

For computing peaks in the tuning of neurons to a variable, mean ∆F/F responses were interpolated with a one-dimensional spline (scipy.interpolate.InterpolatedUnivariateSpline, k = 2, second degree) and the location of the maximum was computed.

Gaussian KDE

To generate a kernel density estimate of BPNs in anatomical space, BPN coordinates were used to fit a Gaussian Kernel (sklearn.neighbors.KernelDensity(*, bandwidth = 10 (14 for 7 d.p.f.), algorithm=‘auto’, kernel=‘gaussian’, metric=‘euclidean’). In detail, the brain was divided along the rostrocaudal axis and, for each hemisphere, a separate kernel was fitted with the contained BPNs. The resulting two kernels were used to generate probability density fields of each hemisphere, which were then merged again. The resulting density was thresholded so that only voxels within the brain itself had values > 0 and all voxels in the volume surrounding the brain equalled 0. Probability values were then normalized so that the sum would result in the total number of BPNs. To draw contours of areas with certain threshold BPN density, the KDE volume was binarized so that all voxels above threshold equalled 1. Of the resulting binarized volume a two-dimensional maximum intensity projection was computed for each orthogonal anatomical axis and a contour-finding algorithm (skimage.measure.find_contours) was applied to the two-dimensional projection.

Definition of the larval DT

The outline of the larval thalamus proper was refined with expert help of M. Wullimann (LMU). The refinement was based on extensive analysis of gene expression52. The elavl3 reference stain was used to identify the diencephalic regions. Proliferative cells, however, which are abundant in the anterior DT at the larval stage, are not labelled by elavl3. The neurogenin line was used to indicate the early glutamatergic cells belonging to DT. Neurogenin is absent in the prethalamus (VT). The VT/DT boundary was further defined using gad1b and dlx4, which label late and early GABAergic cells, respectively. GABAergic cells are mainly found in VT, although the intercalated nucleus and the anterior nucleus of DT may contain some gad1b positive cells. The pretectum/DT boundary was defined using gad1b and th. The latter marks dopamine cells present in the pretectum.

EM and segmentation of mapzebrain regions

A detailed description of the EM dataset and region mapping is published elsewhere35. In brief, the Serial Block Face Scanning EM dataset was of a 5 d.p.f. larval zebrafish imaged at a resolution of 14 × 14 × 25 nm. A diffeomorphic mapping between the mapzebrain light-microscopy brain reference coordinate system and the EM coordinate system generated by the dipy (https://dipy.org/) Python library was used to overlay mapzebrain (https://mapzebrain.org) region annotations over the EM data. Registration accuracy was reviewed for different brain regions with an alignment error of maximal ~5 µm (midbrain) to ~20 µm (hindbrain). We applied flood-filling networks for an automated reconstruction of all neurons56 within the whole-brain EM dataset35. To correct for split and merge errors of the segmentation, we used the Knossos application (www.knossos.app). Proof-reading of single pBPN-DT cells started at the cell body location and ended when all branches were completely traced. Growth cones defined premature neurons. Proof-reading of partner cells started at the synapse and was again performed until the whole cell was completed. Synapses have been automatically segmented using the SyConn v2 pipeline35. Input to pBPN-DT cells and tectal PVPNs was quantified by randomly selecting ten incoming synapses per cell and tracing input partner cells, until their cell bodies were identified.

Nitroreductase ablations

To chemogenetically ablate neurons, fish expressing nitroreductase (NTR) were treated with 7.5 mM metronidazole (MTZ) in Danieau’s solution with 1 ml l−1 dimethylsulfoxid (DMSO) for larvae, or 7.5 mM MTZ in fish facility water with 2 ml l−1 DMSO for juvenile fish, respectively. Control fish were only treated with the respective DMSO concentration in the absence of MTZ. For SAGFF(lf)81c ablations, the canonical UAS-E1B:NTR-mCherry(c264) nitroreductase was used47.

Transgenic animals (RFP+) and control sibling fish (RFP) were incubated in MTZ + DMSO solution for 16–24 h overnight. For the experiment shown in Extended Data Fig. 7b,e, we additionally incubated RFP+ and RFP animals in DMSO only. Animals recovered for 16–24 h in system water before starting imaging or behaviour experiments.

In larvae, s1026tEt drives strong expression in the DT, dorsal VT, ventral pretectum and ventral telencephalon, and additional background expression in the heart and trunk musculature31,48. We found that MTZ mediated ablation of s1026tEt, UAS-E1B:NTR-mCherry(c264) double transgenic fish was lethal in 100% of animals. We therefore used a nitroreductase transgene of which the background muscle expression was suppressed by a 3′UTR: UAS:BGi-epNTR-TagRFPT-utr.zb357. To overcome strong variegation of the existing allele (y362) in s1026tEt cells, we created new alleles via Tol2 mediated transgenesis. We injected UAS:BGi-epNTR-TagRFPT-utr.zb3 together with Tol2 mRNA into the TLN s1026tEt background. We outcrossed individual founders to TLN and raised transgenic RFP+ offspring and control RFP siblings. At 19 d.p.f., we selected transgenic offspring of one founder for homogeneous RFP signal in the DT. This founder established the allele mpn420 of which the expression is largely confined to the DT (Extended Data Fig. 8). Half of transgenic and control animals were randomly assigned to MTZ + DMSO versus DMSO-only treatment. We observed no lethality after ablation in this line. Analogous, non-transgenic siblings were also split into two groups for MTZ + DMSO versus DMSO-only treatment. MTZ had no detectable effect on non-transgenic animals and we subsequently pooled all three control conditions.

Laser ablations

Juvenile (20–23 d.p.f.) elavl3:H2B-GCaMP6s transgenic fish were embedded as described above, anesthetized with Tricaine and placed under a two-photon laser scanning microscope (Femtonics). The DT-BPN region within each brain was visually identified by the experimenter. A 20 μm ROI was specified on the DT-BPN region of each brain hemisphere and scanned with a 800 nm/400 mW laser beam for 30 ms. After each scan, one image was captured to observe the resulting damage and potential off-target effects. This procedure was repeated 7 ± 3 times until no more nuclei could be observed in the target region that could be targeted without blood vessel damage. Fish were removed from the embedding and anaesthesia immediately after ablation. One fish that did not start swimming within a few minutes was excluded from subsequent behaviour testing and analysis. Fish were allowed to recover for at least 16 h before they were tested in a shoaling assay as described above.

Social isolation

Individual eggs from elav:H2B-GCaMP6s incrosses were placed into small petri dishes at 0 d.p.f. The side walls of the dishes were taped to prevent visual contact between dishes. For controls, 15 eggs were placed in one small petri dish. Larvae were imaged at 7 d.p.f. As no brain stacks were acquired for these animals, anatomical DT masks were drawn for each fish manually. The response threshold for data analysis was adjusted to 50% due to a lower number of recorded neurons in single-plane imaging.

Statistical analysis

All analyses were performed in Python, using NumPy, Scipy, MatplotLib, Suite2p, Pandas and Scikit-learn. All statistical details are described in the figure legends and the Methods. All tests were two-tailed, unless noted otherwise. Error bars represent 1 s.d., unless noted otherwise. N denotes the number of animals, unless noted otherwise.

Data collection software

The following data collection software were used: Bonsai (v.2.4.1); Leica LAS X (v.3.5.7); and ScanImage (v.5.6).

Data analysis software

The following data analysis software was used: Python (v.3.9) with NumPy (v.1.21.0), Scipy (v.1.7.0), MatplotLib (v.3.4.2), Pandas (v.1.3.0) and additional packages (full python environments are available with our code on bitbucket); Ants (v.1.9); Suite2p (v.0.9.3); and ImageJ (v.1.53c).

Reporting summary

Further information on research design is available in the Nature Research Reporting Summary linked to this paper.