https://github.com/d-laub/basenji2-pytorch
PyTorch implementation of Basenji2.
https://github.com/d-laub/basenji2-pytorch
bioinformatics deep-learning genomics pytorch
Last synced: 5 months ago
JSON representation
PyTorch implementation of Basenji2.
- Host: GitHub
- URL: https://github.com/d-laub/basenji2-pytorch
- Owner: d-laub
- License: mit
- Created: 2022-11-16T17:13:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-29T15:20:50.000Z (about 1 year ago)
- Last Synced: 2026-01-03T00:30:36.577Z (6 months ago)
- Topics: bioinformatics, deep-learning, genomics, pytorch
- Language: Python
- Homepage:
- Size: 244 KB
- Stars: 19
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Basenji2 in PyTorch
This repo provides a PyTorch re-implementation of the Basenji2 model published in ["Cross-species regulatory sequence activity prediction"](https://doi.org/10.1371/journal.pcbi.1008050) by David Kelley. This implementation was checked by verifying that the Tensorflow and PyTorch version yielded the same output on random data. Small deviations were found, likely due to differences in the underlying algorithms used by Tensorflow and PyTorch (e.g. different matrix multiplication algorithms). In addition, [Qixiu Du kindly computed evaluation metrics](https://github.com/d-laub/basenji2-pytorch/issues/1) and found that the PyTorch re-implementation achieves competitive performance on real data, further validating the port.
## Installation
`pip install basenji2-pytorch`
## Usage
```python
import torch
from basenji2_pytorch import Basenji2, basenji2_params, basenji2_weights # or PLBasenji2 to also use training parameters from Kelley et al. 2020
# to use a headless model e.g. for transfer learning
# basenji2_params["model"].pop("head_human", None)
basenji2 = Basenji2(basenji2_params["model"])
basenji2.load_state_dict(torch.load(basenji2_weights()))
```
- `basenji2_params` is a dictionary of both training and model parameters matching the implementation in Kelley et al. 2020
- `basenji2_weights` is a function that uses [pooch](https://github.com/fatiando/pooch) to download weights from Zenodo and return the path as a string.
- `Basenji2` is a PyTorch nn.Module that can be initialized from the model parameters of `basenji2_params`
- `PLBasenji2` is a PyTorch Lightning module that can be initialized from `basenji2_params` to match both the training and architectural parameters of Basenji2