Identity-preserving tracking of individual Drosophila behavior in social environments.
sociSleep is an identity-preserving behavioral tracking system for quantifying sleep, locomotion, and social dynamics of individual Drosophila housed in social environments.
Unlike conventional Drosophila sleep systems that require physical isolation of animals, sociSleep continuously tracks individuals within shared arenas, allowing long-term measurement of sleep while preserving social interactions.
- Identity-preserving tracking for individual flies
- Quantification of sleep and locomotor activity
- Simultaneous tracking of social groups
- Automatic detection of merged flies
- Support for multiple experimental plate layouts
- Multi-camera acquisition (1–2 USB cameras)
- Independent output for each camera
- Interactive OpenCV graphical interface
- Automatic CSV data logging
Currently supported plate configurations:
| Design | Left Arena | Right Arena |
|---|---|---|
| Solo vs Solo | 1 fly | 1 fly |
| Solo vs Group | 1 fly | 2 flies |
| Group vs Group | 2 flies | 2 flies |
Additional designs can be added by modifying plate_design.py.
USB Camera(s)
│
▼
FlyTracker Thread(s)
│
▼
Identity Tracking
│
▼
Behavior Detection
│
▼
CSV Logger
Each USB camera is handled by an independent tracking thread.
The dashboard combines all active cameras into a single live display.
Example:
+----------------------+----------------------+
| Camera 1 | Camera 2 |
| | |
| Arena A Arena B | Arena A Arena B |
| | |
+----------------------+----------------------+
sociSleep/
├── main.py
├── fly_tracker.py
├── dashboard.py
├── camera_detector.py
├── arena_config.py
├── design_selector.py
├── csv_logger.py
├── plate_design.py
├── config.py
└── ...
- Python 3.11+
- OpenCV-python=4.5.0
- NumPy
- pygrabber
- SciPy
- Pandas
Install dependencies:
pip install -r requirements.txtcamera_names.pyThe program automatically detects connected USB cameras, and output camera names.
camera_detector.pyModify camera names (just keyword) at Line 7.
run_sociSleep.pyLaunch sociSleep tracker.
The current version supports one or two USB cameras simultaneously.
Each camera operates independently while sharing the same experimental plate design.
Output files are generated separately:
results_camera1/
results_camera2/
Each directory contains:
- Tracking CSV
- Experiment log
- Optional snapshots
Before tracking begins, select one of the available plate layouts:
- Solo vs Solo
- Solo vs Group
- Group vs Group
The graphical control panel provides:
- Large clickable buttons
- Current design highlight
- Arena summary
- READY / LOCKED status
Once tracking starts, the plate design becomes locked to prevent accidental changes.
Each experiment generates CSV files containing:
- Timestamp
- Fly coordinates
- Fly movement (0:immobile; 1: moving)
- Arena assignment
Example:
| Time | A_x | A_y | A_movement | B_x | B_y | B_movement |
|---|
Integrated sociSleep_analyzer: version 4.3

sociSleep preserves fly identity during long-term recordings using:
- Kalman filter + nearest assignment
- Adaptative weight of size-based identity assignment
- Merge detection
- Arena-specific constraints
Identity switches are minimized during brief social interactions.
The OpenCV interface consists of:
- Live camera feeds
- Arena overlays
- Fly identities
- Tracking status
- Clickable plate layout selection
- Arena information
- Tracking status
Each camera has an independent calibration window for selecting arena positions before tracking.
- Connect USB camera(s).
- Launch
run_sociSleep.py. - Select the experimental plate design.
- Calibrate arena locations and camera parameters.
- Press START.
- Monitor tracking in the live dashboard.
- CSV files are automatically saved during acquisition.
If you use sociSleep in your research, please cite:
Binbin Wu, William Ja. Rencent social loss, not chronic isolation, reshapes sleep in Drosophila. Doi: https://doi.org/10.64898/2026.07.12.738068
GPL-3.0 open-source License
Binbin Wu
The Wertheim UF Scripps Institute
For questions, bug reports, or feature requests, please open a GitHub Issue.

