mikeleske/fasta-embed

This small repository is meant to assist you in quickly creating semantic embeddings for your DNA sequences.

Python

0

21 commits

updated May 11, 2026

See the code

README

fasta-embed

Embed your DNA sequences into vector space

Generate dense embeddings for DNA sequences using pluggable model backends
(DNABERT-S, Nucleotide Transformer v2 & 3, or your own).

Installation

pip install -r requirements.txt

Quick start

# Using CLI flags
python -m fasta_embed --embedder ntv3 --input sequences.fasta --output embeddings.npy

# Using a config file
cp config.example.yaml config.yaml   # edit as needed
python -m fasta_embed --config config.yaml

# Mix both (CLI flags override the config file)
python -m fasta_embed --config config.yaml --region V3V4 --device cuda:0

Available embedders

NameDefault model
dnabertzhihan1996/DNABERT-S
ntv2InstaDeepAI/nucleotide-transformer-v2-100m-multi-species
ntv3InstaDeepAI/NTv3_100M_pre
evo2evo2_1b_base
moderngena-baseAIRI-Institute/moderngena-base
moderngena-largeAIRI-Institute/moderngena-large

List them at any time:

python -m fasta_embed --list-embedders

Configuration

All options can be set via YAML config file, CLI flags, or both (CLI wins).
See config.example.yaml for the full reference.

Key options:

FlagConfig keyDescription
--embedderembedderEmbedder strategy name
--model-idmodel_idHuggingFace model ID or local path
--inputinput_fileInput FASTA or CSV file
--input-formatinput_formatfasta or csv
--outputoutput_fileOutput .npy file
--regionregion16S region (e.g. V3V4, V4, V1V9)
--inference-batch-sizeinference_batch_sizeSequences per forward pass (default 16)
--save-batch-sizesave_batch_sizeFlush-to-disk threshold (default 10000)
--devicedeviceTorch device (auto-detected if omitted)

Adding a custom embedder

  1. Create a new file in fasta_embed/embedders/, e.g. my_model.py.
  2. Subclass Embedder and decorate with @register:
from fasta_embed.embedders import register
from fasta_embed.embedders.base import Embedder

@register("my-model")
class MyModelEmbedder(Embedder):
    def __init__(self, model_id: str = "default/id", device: str | None = None):
        ...

    def load(self) -> None:
        ...

    def embed(self, sequence: str) -> np.ndarray:
        ...
  1. Import the module in fasta_embed/embedders/__init__.py:
from . import my_model  # noqa
  1. Use it: python -m fasta_embed --embedder my-model --input seqs.fasta

mikeleske/fasta-embed

This small repository is meant to assist you in quickly creating semantic embeddings for your DNA sequences.

Python

0

21 commits

updated May 11, 2026

See the code

README

fasta-embed

Embed your DNA sequences into vector space

Generate dense embeddings for DNA sequences using pluggable model backends
(DNABERT-S, Nucleotide Transformer v2 & 3, or your own).

Installation

pip install -r requirements.txt

Quick start

# Using CLI flags
python -m fasta_embed --embedder ntv3 --input sequences.fasta --output embeddings.npy

# Using a config file
cp config.example.yaml config.yaml   # edit as needed
python -m fasta_embed --config config.yaml

# Mix both (CLI flags override the config file)
python -m fasta_embed --config config.yaml --region V3V4 --device cuda:0

Available embedders

NameDefault model
dnabertzhihan1996/DNABERT-S
ntv2InstaDeepAI/nucleotide-transformer-v2-100m-multi-species
ntv3InstaDeepAI/NTv3_100M_pre
evo2evo2_1b_base
moderngena-baseAIRI-Institute/moderngena-base
moderngena-largeAIRI-Institute/moderngena-large

List them at any time:

python -m fasta_embed --list-embedders

Configuration

All options can be set via YAML config file, CLI flags, or both (CLI wins).
See config.example.yaml for the full reference.

Key options:

FlagConfig keyDescription
--embedderembedderEmbedder strategy name
--model-idmodel_idHuggingFace model ID or local path
--inputinput_fileInput FASTA or CSV file
--input-formatinput_formatfasta or csv
--outputoutput_fileOutput .npy file
--regionregion16S region (e.g. V3V4, V4, V1V9)
--inference-batch-sizeinference_batch_sizeSequences per forward pass (default 16)
--save-batch-sizesave_batch_sizeFlush-to-disk threshold (default 10000)
--devicedeviceTorch device (auto-detected if omitted)

Adding a custom embedder

  1. Create a new file in fasta_embed/embedders/, e.g. my_model.py.
  2. Subclass Embedder and decorate with @register:
from fasta_embed.embedders import register
from fasta_embed.embedders.base import Embedder

@register("my-model")
class MyModelEmbedder(Embedder):
    def __init__(self, model_id: str = "default/id", device: str | None = None):
        ...

    def load(self) -> None:
        ...

    def embed(self, sequence: str) -> np.ndarray:
        ...
  1. Import the module in fasta_embed/embedders/__init__.py:
from . import my_model  # noqa
  1. Use it: python -m fasta_embed --embedder my-model --input seqs.fasta