# Workflow for spike sorting
[](https://hackmd.io/Cv9EWPSqT12RkovOfMVXaQ)
Say we are going to sort animal `DS_15` session 1 region AC data.
1. Create a folder on your local computer, say `D:/DualRecording/DS_15/DS_15 1/`
2. Copy the recording files to the folder, here I got the following files under the directory `P:\Electrophysiology\DS_15` on NAS.
- `Apr 8 2021 Dual DS_15_1001.ccf`
- `Apr 8 2021 Dual DS_15_1001.nev`
- `Apr 8 2021 Dual DS_15_1001.ns5`
- `Apr 8 2021 Dual DS_15_1001.ns6`
- `Apr 8 2021 Dual DS_15_1002.ccf`
- `Apr 8 2021 Dual DS_15_1002.nev`
- `Apr 8 2021 Dual DS_15_1002.ns5`
- `Apr 8 2021 Dual DS_15_1002.ns6`
- `Apr 8 2021 Dual DS_15_1003.ccf`
- `Apr 8 2021 Dual DS_15_1003.nev`
- `Apr 8 2021 Dual DS_15_1003.ns5`
- `Apr 8 2021 Dual DS_15_1003.ns6`
Note: make sure you have 4 files for each block of the session, `ccf`, `nev`, `ns5`, `ns6`.
3. Open Matlab, and run the scripts from `EphysAnalysis/Matlab Code/` in the following order:
- Run `repackage.m`, enter the number of blocks in the session, and open each block file ended with `.ns5` from the window that pops up.
- Run `saveTrials.m`, enter the number of trials in the session, and open each block file ended with `.ns6` from the window that pops up.
4. Run Kilosort in matlab:
- Run `kilosort.m`, select the correct `.bin` file (generated by the previous step) from the window that pops up.
- After running, three figures will pop up, align them together, take a screenshot, and save it as `DS_15 1 AC Drift Map.png`
5. Run Phy in terminal:
- Open terminal, navigate to the folder `D:/DualRecording/DS_15/DS_15 1/`
- Activate the conda environment by running `conda activate phy2`
- Run `phy template-gui params.py` to open the Phy GUI
- After sorting, save the results and close the GUI
6. Run `EphysAnalysis/Matlab Code/packageMetadata.m` in Matlab, look for the information required from the [lab notebook](https://docs.google.com/spreadsheets/d/1PHQ9fQUMWEAgZIQ-V3ok8NXkPfBXMZ74ZKpdqTZjT9s/edit?pli=1&gid=0#gid=0) and enter them when prompted.
---
A few tips when using Phy to sort:
1. Units with firing rate less than 0.2 spikes/s can be considered as noise
2. Sort by KiloSort labels and look at the good units first