Ethome
Ethome: tools for machine learning of animal behavior - Published in JOSS (2024)
Science Score: 98.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 2 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org, zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Scientific Fields
Repository
Tools for machine learning of animal behavior
Basic Info
- Host: GitHub
- Owner: benlansdell
- License: mit
- Language: HTML
- Default Branch: master
- Homepage: https://benlansdell.github.io/ethome/
- Size: 23.7 MB
Statistics
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 1
- Releases: 4
Topics
Metadata Files
README.md
Ethome
Tools for machine learning of animal behavior.
This library interprets pose-tracking files and behavior annotations to create features, train behavior classifiers, interpolate pose tracking data and other common analysis tasks.
At present pose tracking data from DLC, SLEAP and NWB formats are supported, and behavior annotations from BORIS and NWB formats are supported.
Full documentation is posted here: https://benlansdell.github.io/ethome/.
Features
- Read in animal pose data and corresponding behavior annotations to make supervised learning easy
- Scale data to desired physical units
- Interpolate pose data to improve low-confidence predictions
- Create generic features for analysis and downstream ML tasks
- Create features specifically for mouse resident-intruder setup
- Quickly generate plots and movies with behavior predictions
Installation
pip install ethome-ml
ethome has been tested with Python 3.7 and 3.8.
Conda environment
Note that dependencies have tried to be kept to a minimum so that ethome can work easily alongside other programs that may be part of your behavior analysis pipeline (e.g. DeepLabCut) -- thus you can try running the pip install line above in an existing virtual environment.
That said, you may want a separate environment for running ethome. A conda environment can be created with the following steps:
- Download the conda environment yaml file ethome-conda.yaml
- (From the location you downloaded the yaml file) Create the environment:
conda env create -f ethome-conda.yaml - Run
conda activate ethome - And finally
pip install ethome-ml
Optional packages
With both install methods, you may want to also install tensorflow (at least version 2.0) if you want to use the CNN features for a resident-intruder setup.
Quickstart
It's easiest to start with an NWB file, which has metadata already connected to the pose data.
Import
python
from ethome import create_dataset
from ethome.io import get_sample_nwb_paths
Gather a sample NWB file
python
fn_in = get_sample_nwb_paths()
Create the dataframe:
python
dataset = create_dataset(fn_in)
dataset is an extended pandas DataFrame, so can be treated exactly as you would treat any other dataframe. ethome adds a bunch of metadata about the dataset, for instance you can list the body parts with:
python
dataset.pose.body_parts
A key functionality of ethome is the ability to easily create features for machine learning. You can use pre-built featuresets or make your own. For instance:
python
dataset.features.add('distances')
will compute all distances between all body parts (both between and within animals).
We can load pose data from DLC, and behavior annotation data from BORIS, provided we also provide a little metadata for context. E.g.:
python
pose_files, behavior_files = get_sample_data_paths_dlcboris()
metadata = create_metadata(pose_files, labels = behavior_files, fps = 30)
dataset = create_dataset(metadata)
There are featuresets specifically tailored for social mice studies (the resident-intruder setup). For instance,
python
dataset.features.add('cnn1d_prob')
Uses a pretrained CNN to output probabilities of 3 behaviors (attack, mount, social investigation). For this, you must have labeled your body parts in a certain way (refer to How To). Other, more generic, feature creation functions are provided that work for any animal configuration.
Now you can access a features table, labels, and groups for learning with dataset.ml.features, dataset.ml.labels, dataset.ml.group. From here it's easy to use some ML libraries to train a behavior classifier. For example:
```python
from sklearn.ensemble import RandomForestClassifier
from sklearn.modelselection import crossval_score, LeaveOneGroupOut
cv = LeaveOneGroupOut() model = RandomForestClassifier() crossvalscore(model, dataset.ml.features, dataset.ml.labels, groups = dataset.ml.group, cv = cv) ```
Since the dataset object is just an extended Pandas dataframe we can manipulate it as such. E.g. we can add our model predictions to the dataframe:
python
from sklearn.model_selection import cross_val_predict
predictions = cross_val_predict(model,
dataset.ml.features,
dataset.ml.labels,
groups = dataset.ml.group,
cv = cv)
dataset['prediction'] = predictions
If the raw video file paths are provided in the metadata, under the video key, we can make a movie overlaying these predictions over the original video:
python
dataset.io.save_movie(['label', 'prediction'], '.')
where label and prediction reference column names to annotate the video with.
A more detailed run through of features is provided in the How To guide. Also checkout examples for working demos to quickly see how things work.
Supported input data formats
The following animal pose/behavior annotation data formats are supported.
DeepLabCut
From DLC documentation: The labels are stored in a MultiIndex Pandas Array, which contains the name of the network, body part name, (x, y) label position in pixels, and the likelihood for each frame per body part. These arrays are stored in an efficient Hierarchical Data Format (HDF) in the same directory, where the video is stored. However, if the flag saveascsv is set to True, the data can also be exported in comma-separated values format (.csv), which in turn can be imported in many programs, such as MATLAB, R, Prism, etc.
BORIS
Behavioral Observation Research Interactive Software: BORIS is an easy-to-use event logging software for video/audio coding and live observations. It provides flexible and powerful behavior annotation from a set of videos. Data should be exported to a csv so that ethome can import behavior annotations.
NeuroData Without Borders (NWB)
NWB is a data standard for neurophysiology, providing neuroscientists with a common standard to share, archive, use, and build analysis tools for neurophysiology data. NWB is designed to store a variety of neurophysiology data, including data from intracellular and extracellular electrophysiology experiments, data from optical physiology experiments, and tracking and stimulus data. It includes ability to store animal behavior data and pose data, through the ndx-pose extenstion (here). Nwb files must have a PoseEstimationSeries and/or PoseEstimation datatypes in it to be importable into ethome.
SLEAP
SLEAP is an open source deep-learning based framework for multi-animal pose tracking. It can be used to track any type or number of animals and includes an advanced labeling/training GUI for active learning and proofreading. SLEAP data must be in exported analysis h5 files, to import into ethome.
Sample notebooks
Sample notebooks are available (here) that you can use as a starting point for your own analyses, using either: * NWB files * SLEAP files * DLC tracking and BORIS annotations
Contributing
Refer to CONTRIBUTING.md for guidelines on how to contribute to the project, and report bugs, etc.
Development
You can setup your dev environment using the conda yaml file provided. Compiling the docs requires the following packages are also installed:
pip install mkdocs-material mkdocs-awesome-pages-plugin twine build
Animal data
Sample data was obtained from resident-intruder open field recordings performed as part of on going social memory studies performed in the Zakharenko lab at St Jude Children's Research Hospital (e.g. [1,2]). All animal experiments were reviewed and approved by the Institutional Animal Care & Use Committee of St. Jude Children’s Research Hospital.
[1] "SCHIZOPHRENIA-RELATED MICRODELETION GENE 2510002D24Rik IS ESSENTIAL FOR SOCIAL MEMORY" US Patent US20220288235A1. Stanislav S. Zakharenko, Prakash DEVARAJU https://patents.google.com/patent/US20220288235A1/en [2] "A murine model of hnRNPH2-related neurodevelopmental disorder reveals a mechanism for genetic compensation by Hnrnph1". Korff et al. Journal of clinical investigation 133(14). 2023.
Owner
- Name: Ben Lansdell
- Login: benlansdell
- Kind: user
- Location: Santa Fe, NM
- Company: Health stealth
- Website: benlansdell.github.io
- Twitter: benlansdell
- Repositories: 111
- Profile: https://github.com/benlansdell
Machine learning and applied mathematics | Former postdoc @KordingLab UPenn, PhD in applied mathematics @Fairhall-Lab UW
JOSS Publication
Ethome: tools for machine learning of animal behavior
Authors
Developmental Neurobiology, St Jude Children's Research Hospital, Memphis, Tennessee, United States of America
Developmental Neurobiology, St Jude Children's Research Hospital, Memphis, Tennessee, United States of America
Tags
supervised-learning deeplabcut boris neurodata-without-borders pose-tracking ndx-pose animal-behaviorCitation (CITATION.cff)
cff-version: "1.2.0"
authors:
- family-names: Lansdell
given-names: Benjamin
orcid: "https://orcid.org/0000-0003-1444-1950"
- family-names: Shirinifard
given-names: Abbas
doi: 10.5281/zenodo.10680136
message: If you use this software, please cite our article in the
Journal of Open Source Software.
preferred-citation:
authors:
- family-names: Lansdell
given-names: Benjamin
orcid: "https://orcid.org/0000-0003-1444-1950"
- family-names: Shirinifard
given-names: Abbas
date-published: 2024-03-08
doi: 10.21105/joss.05623
issn: 2475-9066
issue: 95
journal: Journal of Open Source Software
publisher:
name: Open Journals
start: 5623
title: "Ethome: tools for machine learning of animal behavior"
type: article
url: "https://joss.theoj.org/papers/10.21105/joss.05623"
volume: 9
title: "Ethome: tools for machine learning of animal behavior"
CodeMeta (codemeta.json)
{
"@context": "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld",
"@type": "Code",
"author": [
{
"@id": "http://orcid.org/0000-0003-1444-1950",
"@type": "Person",
"email": "ben.lansdell@gmail.com",
"name": "benlansdell",
"affiliation": ""
}
],
"identifier": "",
"codeRepository": "https://github.com/benlansdell/ethome",
"datePublished": "2023-04-12",
"dateModified": "2023-04-12",
"dateCreated": "2023-04-12",
"description": "Tools for machine learning of animal behavior",
"keywords": "supervised-learning, dlc, boris, neurodata-without-borders,deeplabcut, pose-tracking, ndx-pose",
"license": "MIT",
"title": "ethome",
"version": "v0.4.0"
}
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| benlansdell | b****l@s****g | 233 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 12
- Total pull requests: 2
- Average time to close issues: about 1 month
- Average time to close pull requests: 2 days
- Total issue authors: 2
- Total pull request authors: 1
- Average comments per issue: 0.58
- Average comments per pull request: 0.5
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- benlansdell (11)
Pull Request Authors
- benlansdell (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 21 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 10
- Total maintainers: 1
pypi.org: ethome-ml
Tools for machine learning of animal behavior.
- Homepage: https://github.com/benlansdell/ethome
- Documentation: https://ethome-ml.readthedocs.io/
- License: MIT License
-
Latest release: 0.6.2
published about 2 years ago
Rankings
Maintainers (1)
Dependencies
- keras >=2.4.3
- matplotlib *
- numpy *
- pandas *
- protobuf >=3.20.0
- scikit-image *
- scikit-learn *
- setuptools >=42
- tensorflow >=2.4.1
- tensorflow-addons *
- tqdm *
- typeguard *
- typing *
- umap-learn *
- wheel *
- actions/checkout master composite
- actions/setup-python master composite
- codecov/codecov-action v2 composite
- actions/checkout v3 composite
- actions/upload-artifact v1 composite
- openjournals/openjournals-draft-action master composite
- actions/checkout v3 composite
- actions/setup-python v3 composite
- pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite