# rostlab/bio_embeddings architecture

> Architecture diagram of the GitHub repository rostlab/bio_embeddings, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rostlab/bio_embeddings
- Repository: https://github.com/rostlab/bio_embeddings

## Overview

##### Project Type and Purpose
- From the name and README we see that “bio_embeddings” is a Python‐based bioinformatics library and CLI tool for generating protein or DNA embeddings using pre‐trained models.
- Its primary functionality is:
- Ingest biological sequence data (FASTA, CSV, etc.)
- Run it through one or more embedding backends (e.g., ESM, ProSE, ProtTrans)
- Return fixed‐length numeric vectors to downstream analysis pipelines or persist them to disk/databases.

##### High-Level Components
A. CLI / Entry Point
- A command‐line interface (scripts under `bin/` or entry_points in `setup.py`) that orchestrates input parsing, backend selection, and output handling.
B. Core Library (Python Package)
- `bio_embeddings` module containing sub‐packages:
- `io` (reading/writing sequences & embeddings)
- `models` (wrappers around pre‐trained embedding models)
- `pipeline` (sequencing of tasks: load → embed → post‐process)
- `utils` (logging, configuration, caching)
C. Embedding Backends
- External ML frameworks (PyTorch, TensorFlow) and model zoos (HuggingFace, fairseq).
D. Configuration & Dependency Management
- `setup.py` or `pyproject.toml` for packaging; `requirements.txt` or `environment.yml` for pinned dependencies.
E. Data Storage
- Local filesystem or optional key‐value store / database (e.g., SQLite, LMDB) for caching embeddings.
F. Hardware Layer
- GPU/CPU resource orchestration, possibly via `torch.device` abstractions.

##### Relationships and Data Flows
- User invokes CLI → CLI parses arguments → Loads pipeline configuration →
For each input sequence:
1. IO module reads raw sequence
2. Pipeline module dispatches to selected embedding backend
3. Backend module calls underlying ML framework (PyTorch/TensorFlow)
4. Generated embedding flows back to pipeline for optional post‐processing
5. IO module writes result to disk or database
- Optional: The pipeline may include asynchronous batch scheduling or distributed execution (e.g., via Dask or multiprocessing).

##### Architectural Patterns and Design Principles
- Modular plugin architecture: each embedding backend implements a common interface (Strategy pattern).
- Pipeline pattern for sequence of processing steps.
- Separation of concerns: IO, Model invocation, Post‐processing, Configuration.
- Dependency Injection for swapping in/out different models or storage backends.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    UserInput(("User Input")):::external
    UserOutput(("User Output")):::external

    %% CLI Entry Point
    CLI["CLI / Entry Point\n(Click / argparse)"]:::internal

    %% Core Library Modules
    subgraph "Core Library"
        direction TB
        IO["IO\nRead/Write Sequences"]:::internal
        Pipeline["Pipeline\nPipeline Pattern"]:::internal
        Models["Models\nPlugin Interface"]:::internal
        Utils["Utils\nLogging, Config, Caching"]:::internal
    end

    %% External Frameworks & Model Zoos
    subgraph "External Frameworks" 
        direction TB
        PyTorch["PyTorch ≥1.x"]:::external
        Transformers["Transformers"]:::external
        HuggingFace["HuggingFace Model Zoo"]:::external
    end

    %% Hardware Layer
    Hardware["GPU / CPU"]:::hardware

    %% Storage Layer
    Storage["Data Store\nSQLite / LMDB / Flat files"]:::storage

    %% Data Flow
    UserInput -->|invokes| CLI
    CLI -->|parses & config| IO
    IO -->|reads sequences| Pipeline
    Pipeline -->|dispatch| Models
    Models -->|calls| PyTorch
    Models -->|calls| Transformers
    Transformers -->|fetch models| HuggingFace
    PyTorch -->|executes on| Hardware
    Transformers -->|executes on| Hardware
    Models -->|returns embeddings| Pipeline
    Pipeline -->|post-process| IO
    IO -->|writes embeddings| Storage
    Storage -->|provides data| UserOutput

    %% Legend
    subgraph Legend
        direction LR
        A["Internal Modules"]:::internal
        B["External Dependencies"]:::external
        C["Storage"]:::storage
        D["Hardware"]:::hardware
    end

    %% Styles
    classDef internal fill:#cdeccd,stroke:#2e7d32,color:#000;
    classDef external fill:#ffd59e,stroke:#ef6c00,color:#000;
    classDef storage fill:#aedff7,stroke:#0288d1,color:#000;
    classDef hardware fill:#e0e0e0,stroke:#616161,color:#000;
```
