TITLE: Kinovea tracking guide and distance calculation R script
AUTHORS: Simon  Benmaamar

[DESCRIPTION]
This protocol can be used to determine the travelled distances of larvae on a black-stained agar plate. For this purpose, videos of the moving animals are recorded, the movement is then tracked using the Kinovea program and the resulting files are evaluated using an R script.

[STEPS]
SECTION: Kinovea tracking guide
1. Start Kinovea program.
Import video by clicking on File -> Open Video File.
Set time format: Options -> Time markers format -> Total milliseconds.
To express distance in real life units add a line with the diagonal length of the black agar, then right click on the line -> Calibrate measure -> Change Real size of the segment to 8.5 cm (diameter of the agar plate).
For tracking the object: Right click in the middle of the larva -> Track path.
Start tracking by clicking on play.
If the tracking was misplaced go to the image corresponding to the misplaced point, then right click the path -> Restart Path Edition and adjust the point location. After editing the tracking, click on End Path Edition.
Safe trajectories by clicking on File -> Export to Spreadsheet -> Trajectories to simple text

More information about the program can be obtained at the Kinovea website (https://www.kinovea.org/help/en/109.html).

SECTION: R script guide
2. Analyse larval movement of a single group (Calculate_Distance.R)

Safe your text files from the Kinovea tracking program in folders referring to the 
Experiment and Fly Group (for example “Starved” -> “ForR”).
Open the Calculate_Distance.R script in R studio.
Make sure the required libraries are installed.
Set working directory by changing setwd to the file path where your folders are stored.
Change Experiment to the name of the experiment (= name of the Experiment folder, for example “Starved”) and Group to the fly group (= name of Group folder in the Experiment folder, for example “ForR”) you want to evaluate. If you have no subfolders in the Experiment-folder you need to adjust the code.
Run the script -> A csv-file is generated containing information about the name of the Experiment and Group, the distances in cm of each larva and the time of the first movement of each larva. To adjust where this file should be stored change setwd above the write.csv function to your desired file path. 
The plotted trajectories containing information about the name of the text file and the calculated distance can now be checked for each file.
You can also check the bar plots of mean distance and mean time of first movement.
3. Compare larval movement data of different groups (Compare_Distances.R)

Store the csv-files from the previous script in a folder where the same experimental groups are in the same folder (for example “Starved” folder contains the csv files of “Starved_ForR” and “Starved_ForS”).
Open the Compare_Distances.R script in R studio
Make sure the required libraries are installed.
Set working directory by changing setwd to the file path where your folder containing the different experimental groups is stored
Run the script.

Both R scripts are available at “https://github.com/SimonBnm/Kinovea-Trajectories-Evaluation”.