Skip to content

Latest commit

 

History

305 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drawing

MaggotUBA : Drosophila Larva Unsupervised Behavior Analysis

Quickstart - using maggotuba command line tool

At the moment the pipeline is limited to the analysis of "Point dynamics" time series, which track the coordinates of 5 points along the longitudinal axis of the larva.

We assume your data is stored in a folder with the following structure :

raw_data_dir
├── t_5
│   ├── LINE_1
│   │   ├── protocol_1
│   │   │   ├── date_time1
│   │   │   │   ├── Point_dynamics_t5_LINE_1_protocol_1_larva_id_date_time1_larva_number_xx.txt
│   │   │   │   └──...
│   │   │   └──date_time2
│   │   │   └──date_time3
│   │   └──protocol_2
│   │   └──protocol_3
│   └──LINE_2
│   │   └──...
│   └──LINE_3
│           └──...
└──t_15
   └──mutatis mutandis

Most scripts support local multiprocessing. We recommend using a beefy desktop computer and setting the parameters N or n_workers to several dozens.

  1. Create a project folder and cd into it.
maggotuba setup path/to/raw_data_dir path/to/project --len_traj LEN_TRAJ
cd path/to/project
  1. Optionally, update parameters in config.json

  2. Count the proportion of each behavior in the database :

maggotuba db count -n_workers n_workers
  1. Create a balanced database :
maggotuba db buil --n_workers n_workers
  1. Train an autoencoder :
maggotuba model train --name experiment
  1. Evaluate it :
maggotuba model eval --name experiment
  1. Optionally, examine clusters in the latent space :
maggotuba model cluster --name experiment
  1. Compute the embeddings for the whole database.
maggotuba model embed --name experiment --n_workers n_workers
  1. Compute the MMD matrix for a particular tracker
maggotuba model embed --name experiment --tracker t5 --n_workers n_workers

Quickstart - legacy

  1. Create a new project folder : workspace/project

  2. Your data should be stored in workspace/larva_dataset according to the following tree structure

    workspace
    └── larva_dataset
        └── t5_t15_point_dynamics
        |    └── t5_t15_point_dynamics_data
        |        ├── t_5_point_dynamics
        |        │   └── point_dynamics_data
        |        │       ├── LINE_1
        |        │       │   ├── protocol_1
        |        │       │   │   ├── date_time1
        |        │       │   │   │   ├── Point_dynamics_t5_LINE_1_protocol_1_larva_id_date_time1_larva_number_xx.txt
        |        │       │   │   │   └──...
        |        │       │   │   └──date_time2
        |        │       │   │   └──date_time3
        |        │       │   └──protocol_2
        |        │       │   └──protocol_3
        |        │       └──LINE_2
        |        │       │   └──...
        |        │       └──LINE_3
        |        │           └──...
        |        └──t_15_point_dynamics_data
        |            └──mutatis mutandis
        └──long_trajectories
           └──point_dynamics_data
              └──t5
                 └──...
    

    The folder long_trajectories can be prepared from the larva_dataset using prepare_long_trajs.py.

  3. Optional : if you train on a database that is not t5+t15 Count the number of samples and store them in an appropriately named file :

    If you want to use larvae that are rescaled by thei length before the stimulus :

    python structured-temporal-convolution/src/data/precompute/exhaustive_sample_counting.py 15 --data_dir larva_dataset/t5_t15_point_dynamics/t5_t15_point_dynamics_data/ --output_file test_project/rescaled_counts.npy --rescale

    If you want to use larvae that are rescaled by their length on the sample window :

    python structured-temporal-convolution/src/data/precompute/exhaustive_sample_counting.py 15 --data_dir larva_dataset/t5_t15_point_dynamics/t5_t15_point_dynamics_data/ --output_file test_project/counts.npy

    Using 15 processes, this took well over 2 hours on my computer.

    Then, copy the output directly in exhaustive_dataset.py in lieu of N_SAMPLES_SCALED in the first case, N_SAMPLES_NOT_SCALED.

    I apologize for the poor choice of vocabulary which hopefully will be fixed in the future.

  4. Create a new set of samples on which the model will be trained :

    Assuming you want the samples to be rescaled by their length on the sample window :

    python $HOME/workspace/structured-temporal-convolution/src/data/precompute/build_sample_database.py 36 --data_dir $HOME/workspace/larva_dataset/t5_t15_point_dynamics/t5_t15_point_dynamics_data --sample_dir $HOME/workspace/test_project/t5_t15_balanced_samples --balance_data
    

    On the contrary, if you want samples to be scaled according to their length prior to activation :

    python $HOME/workspace/structured-temporal-convolution/src/data/precompute/build_sample_database.py 36 --data_dir $HOME/workspace/larva_dataset/t5_t15_point_dynamics/t5_t15_point_dynamics_data --sample_dir $HOME/workspace/test_project/t5_t15_balanced_samples_rescaled --balance_data --rescale

    Using 36 processes, this should take no more than 30mins.

    The folder structure now looks like :

    workspace
    └── larva_dataset
        └── ...
    └── test_project
    	   └── t5_t15_balanced_samples
    	       └── traj_20_pred_20
                └── data
                    ├── t5
                    |   ├── back
                    |   │   ├── after
                    |   |   |   ├── HASH1.txt
                    |   |   |   ├── HASH2.txt
                    |   |   |   └── ...
                    |   │   ├── before
                    |   │   ├── during
                    |   │   └── setup
                    |   ├── bend
                    |   │   └── ...
                    |   ├── hunch
                    |   │   └── ...
                    |   ├── roll
                    |   │   └── ...
                    |   └── run
                    |       └── ...
                    └── t15
                        └── ...
    
  5. Create a folder workspace/test_project/training_log

  6. The following code will :

    • create a batches folder
    • populate it with batches from the samples folder
    • launch a training for 1000 epochs

    For rescaling of the larvae according to the length before aactivation :

    python structured-temporal-convolution/train_model.py --batch_dir test_project/t5_t15_balanced_batches_rescaled --optim_iter 1000 --log_dir test_project/training_log --data_dir test_project/t5_t15_balanced_samples_rescaled --batch_size 128 --no_rescale_at_runtime

    For rescaling of the larvae according to the mean length during the sample :

    python structured-temporal-convolution/train_model.py --batch_dir test_project/t5_t15_balanced_batches --optim_iter 1000 --log_dir test_project/training_log --data_dir test_project/t5_t15_balanced_samples --batch_size 128 

    The performance of the model is evaluated and figures are created every 100 epochs.

Your folder structure should now look like this :

workspace
├── larva_dataset
|   └── ...
└── test_project
    ├── t5_t15_balanced_samples
    |   └── ...
    └── training_log
        └── DD-MM-AAAA_HH-MM-SS_100_
            ├── params.pt
            └── visu
                └── balanced_eval
                    └── bunch of stuff
  1. Finally, from a trained model, one can recreate all the figures plotted as the final evaluation phase using the following command :

    python structured-temporal-convolution/predict_model.py --eval_saved_model test_project/training_log/DATE_TIME_100_ --log_dir test_project/training_log --batch_dir test_project/t5_t15_balanced_batches_rescaled --data_dir larva_dataset/t5_t15_balanced_samples_rescaled --no_rescale_at_runtime

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages