# Optogenetics-Sleep-Deprivation

Analysis notebooks for a *Drosophila melanogaster* sleep-deprivation study using **ChRmine**-mediated optogenetic activation of candidate wake-promoting / sleep-modulating neurons. Behavioural recordings were collected with [ethoscopes](https://www.notion.so/ethoscope) and analysed with the [`ethoscopy`](https://github.com/gilestrolab/ethoscopy) Python library.

## Experimental design

Flies are tracked in ethoscopes for ~5 days. After a 48 h **baseline** period, a 24 h **stimulation** window of red (or green, as a control) LED light is delivered, followed by a recovery period. Sleep is quantified per fly and compared baseline vs. stimulus, split into 24 h, day (12 h) and night (12 h) windows.

Each notebook focuses on a single genotype or comparison:

| # | Notebook | Purpose |
|---|----------|---------|
| 1 | `1.CantonS_Baseline.ipynb` | Wild-type Canton-S baseline sleep |
| 2 | `2.CantonS_Red_Stimulus.ipynb` | Canton-S response to red light (control) |
| 3 | `3.CantonS_Green_Stimulus.ipynb` | Canton-S response to green light (control) |
| 4 | `4.CantonS_RedvsGreen.ipynb` | ΔSleep red vs. green in Canton-S |
| 5 | `5.UAS-ChRmine-attP2_Baseline.ipynb` | UAS-ChRmine (attP2 insertion) baseline |
| 6 | `6.UAS-ChRmine-attP5_Baseline.ipynb` | UAS-ChRmine (attP5 insertion) baseline |
| 7 | `7.UAS-ChRmine-attP5_Red_Stimulus.ipynb` | UAS-only effector control under red light |
| 8 | `8.11H05-GAL4_Red_Stimulus.ipynb` | 11H05-GAL4 driver-only control |
| 9 | `9.60D05-GAL4_Red_Stimulus.ipynb` | 60D05-GAL4 driver-only control |
| 10 | `10.11H05-GAL4_ChRmine_Red.ipynb` | 11H05 × ChRmine, no ATR |
| 11 | `11.60D05-GAL4_ChRmine_Red.ipynb` | 60D05 × ChRmine, no ATR |
| 12 | `12.11H05_ChRmine_Red_ATR.ipynb` | 11H05 × ChRmine, +ATR (functional optogenetics) |
| 13 | `13.60D05_ChRmine_Red_ATR.ipynb` | 60D05 × ChRmine, +ATR (functional optogenetics) |
| 14 | `14.11H05_ChRmine_noATRvsATR.ipynb` | ΔSleep no-ATR vs. ATR for 11H05 cross |
| 15 | `15.60D05_ChRmine_noATRvsATR.ipynb` | ΔSleep no-ATR vs. ATR for 60D05 cross |

**ChRmine** is a red-shifted channelrhodopsin that requires the cofactor **all-trans retinal (ATR)** to function; the *no-ATR vs. ATR* contrast (notebooks 14–15) therefore isolates the specific contribution of optogenetic activation from any non-specific effect of red light.

## Genotypes

- **Canton-S** — wild-type background
- **UAS-ChRmine** in two insertion sites: *attP2* and *attP5*
- **GAL4 drivers**: *11H05-GAL4*, *60D05-GAL4* (Janelia FlyLight collection)
- Experimental flies: `GAL4 > UAS-ChRmine` crosses, raised ± ATR food

## Analysis pipeline

Each notebook follows roughly the same structure:

1. **Load metadata** with `etho.link_meta_index(...)` and pull raw ethoscope data via `etho.load_ethoscope(..., FUN=etho.sleep_annotation)`.
2. **Build a `behavpy`** object combining data + metadata, pickle it for reuse.
3. **Baseline normalisation** with `df.baseline(column='baseline')`.
4. **Visualisations** — `heatmap`, `plot_overtime`, with the stimulation window shaded.
5. **Quantification** — total sleep over 24 h / 12 h day / 12 h night windows, ΔSleep = stimulus − baseline.
6. **Statistics** — paired tests (Wilcoxon / paired t-test) within group, Mann–Whitney U or independent t-test between groups; normality checked with Shapiro–Wilk.

## Requirements

- Python ≥ 3.10
- [`ethoscopy`](https://github.com/gilestrolab/ethoscopy)
- `pandas`, `numpy`, `scipy`, `matplotlib`, `seaborn`
- Jupyter / JupyterLab

```bash
pip install ethoscopy pandas numpy scipy matplotlib seaborn jupyterlab
```

## Data location

The notebooks read pickled `behavpy` objects from absolute paths under `/home/rdingjin/…` and raw ethoscope output from `/mnt/ethoscope_results`. Update these paths to point to your own metadata CSV and ethoscope data mount before re-running.

## License

Research code — please contact the authors before redistribution.
