# lucian-ilie/e-score architecture

> Architecture diagram of the GitHub repository lucian-ilie/e-score, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lucian-ilie/e-score
- Repository: https://github.com/lucian-ilie/e-score

## Overview

#### Purpose and Entry Points
E-score is a Python protein-sequence alignment toolkit that replaces fixed substitution matrices with context-dependent cosine similarity between per-residue protein-language-model embeddings. It supports local, global-regular, and semi-global dynamic-programming alignments.

Primary entry points:
- `e_score_quick_start.py` — aligns one sequence pair.
- `full_test_example/testing_code.py` — batch-runs alignment examples and persists per-test alignments plus aggregate distances.
- `distances_and_extracting_local_alignments.py` — derives distances and extracts local-alignment results.

#### Embedding Model Boundary
Model initialization and embedding extraction are isolated in `initalizing_models_and_getting_embs.py`. This is the boundary between raw protein strings and residue-vector matrices consumed by scoring/alignment logic.

The repository targets Ankh primarily and documents compatibility with ProtT5, ProstT5, ProtBert, ProtAlbert, ProtXLNet, ESM1b, and ESM2. These are expected to be available locally from Hugging Face rather than downloaded at runtime; model inference is the material compute/memory dependency (recommended Python 3.10 and 24 GB RAM).

Paths:
- `initalizing_models_and_getting_embs.py`
- `requirement.txt`

#### Alignment and Scoring Core
`e_score_quick_start.py` is the user-facing orchestration layer: it accepts two sequences, embedding model/tokenizer, gap-open and gap-extension penalties, an integer cosine-score shift, and alignment mode. It returns aligned sequence strings and optimal DP score.

The scoring boundary is embedding-derived cosine similarity; the alignment boundary is classical DP with affine-style gap controls. This separation enables the same alignment flow to run against different embedding models and parameterizations.

Paths:
- `e_score_quick_start.py`
- `average_of_two_embedding_models.py`

#### Batch Experiment Pipeline
The batch runner reads an examples CSV and parameter CSV, initializes a selected model, then processes examples sequentially. Each test emits an alignment text file; a shared distances CSV aggregates test-level distance results. The checked-in `cd01068` run demonstrates the expected artifact layout and naming convention, including model and scoring parameters in filenames.

Paths:
- `full_test_example/testing_code.py`
- `full_test_example/parms.csv`
- `full_test_example/cd01068_tests_example_output/cd01068_distances/cd01068_Ankh_0.00000_-1.00000_-0.10000_distances.csv`

#### Inputs and Dataset Boundary
Inputs are file-based rather than database- or service-backed: curated local examples are packaged as ZIP archives, while global examples are supplied as BB/CDD archives and can be built from sequence pairs in an MSA. Batch input schemas are represented by the example CSVs and parameters CSV.

Paths:
- `example_data_local/1_CDD_natural.zip`
- `example_data_global/BB_example_files.zip`
- `full_test_example/cd01068_examples.csv`

#### Result Aggregation and Statistical Analysis
Post-processing operates on emitted CSV distance files. `combining_distance_files.py` consolidates result sets; `averages_and_pvals.py` computes comparative summaries/significance statistics. Notebooks and stored CSVs support method comparisons, sliding-window views, win ratios, and dot plots across Ankh, BLOSUM45, and US-alignment baselines.

Paths:
- `analyzing_results/combining_distance_files.py`
- `analyzing_results/averages_and_pvals.py`
- `analyzing_results/all_methods_compared_plots/sliding_window_plot.ipynb`

#### Execution and Infrastructure
This is a local/server-oriented Python workflow, with no deployable application or persistent backend represented in the tree. Batch-scale execution is supported by shell launch scripts, while local model files are the principal external asset. The referenced E-score web server is external to this repository.

Paths:
- `full_test_example/job.sh`
- `full_test_example/over_extensions_calculation/extension.sh`

Main entry points: [`full_test_example/testing_code.py`](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/testing_code.py) (Batch alignment runner), [`initalizing_models_and_getting_embs.py`](https://github.com/lucian-ilie/e-score/blob/main/initalizing_models_and_getting_embs.py) (Embedding extraction), [`full_test_example/cd01068_examples.csv`](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/cd01068_examples.csv) (Batch examples), [`full_test_example/cd01068_tests_example_output/cd01068_distances/cd01068_Ankh_0.00000_-1.00000_-0.10000_distances.csv`](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/cd01068_tests_example_output/cd01068_distances/cd01068_Ankh_0.00000_-1.00000_-0.10000_distances.csv) (Distance results)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Input Data"]
  node_local_archive["Local curated examples<br/>ZIP input<br/>[1_CDD_natural.zip]"]
  node_global_archive["Global BB/CDD examples<br/>ZIP input"]
  node_examples_csv["Batch examples<br/>CSV input"]
  node_parameters_csv["Alignment parameters<br/>CSV input<br/>[parms.csv]"]
end

subgraph group_core["Embedding &amp; Alignment Core"]
  node_quick_start["Single-pair alignment<br/>Python entry point"]
  node_embedding_boundary["Embedding extraction<br/>model adapter"]
  node_model_assets[("Local protein language models<br/>external model assets")]
  node_embedding_ensemble["Two-model embedding average<br/>embedding utility"]
  node_cosine_scoring{{"Cosine similarity scoring<br/>scoring boundary"}}
  node_dp_alignment{{"Affine-gap DP alignment<br/>alignment engine"}}
  node_requirements["Python dependencies<br/>dependency manifest<br/>[requirement.txt]"]
end

subgraph group_batch["Batch Execution"]
  node_batch_runner["Batch alignment runner<br/>Python entry point<br/>[testing_code.py]"]
  node_job_launcher["Batch job launcher<br/>shell script<br/>[job.sh]"]
  node_extension_launcher["Extension sweep launcher<br/>shell script<br/>[extension.sh]"]
  node_alignment_outputs["Per-test alignments<br/>text artifacts"]
  node_distance_results["Distance results<br/>CSV artifacts"]
  node_distance_extraction["Distance &amp; local extraction<br/>post-processing script"]
end

subgraph group_analysis["Result Analysis"]
  node_combine_distances["Distance consolidation<br/>analysis script"]
  node_statistics["Comparative statistics<br/>analysis script"]
  node_visualizations["Comparison visualizations<br/>analysis notebook"]
end

node_model_assets -->|"loaded by"| node_embedding_boundary
node_embedding_boundary -.->|"optional model outputs"| node_embedding_ensemble
node_embedding_boundary -->|"residue vectors"| node_cosine_scoring
node_embedding_ensemble -.->|"averaged vectors"| node_cosine_scoring
node_cosine_scoring -->|"substitution scores"| node_dp_alignment
node_quick_start -->|"embeds sequences"| node_embedding_boundary
node_quick_start -->|"runs alignment"| node_dp_alignment
node_local_archive -.->|"curated examples source"| node_examples_csv
node_global_archive -.->|"global examples source"| node_examples_csv
node_examples_csv -->|"sequence pairs"| node_batch_runner
node_parameters_csv -->|"run settings"| node_batch_runner
node_job_launcher -->|"launches"| node_batch_runner
node_extension_launcher -->|"sweeps extensions"| node_batch_runner
node_batch_runner -->|"initializes and embeds"| node_embedding_boundary
node_batch_runner -->|"aligns each test"| node_dp_alignment
node_batch_runner -->|"writes"| node_alignment_outputs
node_batch_runner -->|"aggregates"| node_distance_results
node_alignment_outputs -->|"alignment results"| node_distance_extraction
node_distance_extraction -->|"derived distances"| node_distance_results
node_distance_results -->|"result files"| node_combine_distances
node_combine_distances -->|"consolidated data"| node_statistics
node_statistics -->|"comparison metrics"| node_visualizations
node_requirements -.->|"runtime dependencies"| node_embedding_boundary

click node_quick_start "https://github.com/lucian-ilie/e-score/blob/main/e_score_quick_start.py"
click node_embedding_boundary "https://github.com/lucian-ilie/e-score/blob/main/initalizing_models_and_getting_embs.py"
click node_embedding_ensemble "https://github.com/lucian-ilie/e-score/blob/main/average_of_two_embedding_models.py"
click node_local_archive "https://github.com/lucian-ilie/e-score/blob/main/example_data_local/1_CDD_natural.zip"
click node_global_archive "https://github.com/lucian-ilie/e-score/blob/main/example_data_global/BB_example_files.zip"
click node_examples_csv "https://github.com/lucian-ilie/e-score/blob/main/full_test_example/cd01068_examples.csv"
click node_parameters_csv "https://github.com/lucian-ilie/e-score/blob/main/full_test_example/parms.csv"
click node_batch_runner "https://github.com/lucian-ilie/e-score/blob/main/full_test_example/testing_code.py"
click node_job_launcher "https://github.com/lucian-ilie/e-score/blob/main/full_test_example/job.sh"
click node_extension_launcher "https://github.com/lucian-ilie/e-score/blob/main/full_test_example/over_extensions_calculation/extension.sh"
click node_distance_results "https://github.com/lucian-ilie/e-score/blob/main/full_test_example/cd01068_tests_example_output/cd01068_distances/cd01068_Ankh_0.00000_-1.00000_-0.10000_distances.csv"
click node_distance_extraction "https://github.com/lucian-ilie/e-score/blob/main/distances_and_extracting_local_alignments.py"
click node_combine_distances "https://github.com/lucian-ilie/e-score/blob/main/analyzing_results/combining_distance_files.py"
click node_statistics "https://github.com/lucian-ilie/e-score/blob/main/analyzing_results/averages_and_pvals.py"
click node_visualizations "https://github.com/lucian-ilie/e-score/blob/main/analyzing_results/all_methods_compared_plots/sliding_window_plot.ipynb"
click node_requirements "https://github.com/lucian-ilie/e-score/blob/main/requirement.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_local_archive,node_global_archive,node_examples_csv,node_parameters_csv toneBlue
class node_quick_start,node_embedding_boundary,node_model_assets,node_embedding_ensemble,node_cosine_scoring,node_dp_alignment,node_requirements toneAmber
class node_batch_runner,node_job_launcher,node_extension_launcher,node_alignment_outputs,node_distance_results,node_distance_extraction toneMint
class node_combine_distances,node_statistics,node_visualizations toneRose
```

## Components

### Input Data

- [Local curated examples](https://github.com/lucian-ilie/e-score/blob/main/example_data_local/1_CDD_natural.zip): ZIP input · `example_data_local/1_CDD_natural.zip`
- [Global BB/CDD examples](https://github.com/lucian-ilie/e-score/blob/main/example_data_global/BB_example_files.zip): ZIP input · `example_data_global/BB_example_files.zip`
- [Batch examples](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/cd01068_examples.csv): CSV input · `full_test_example/cd01068_examples.csv`
- [Alignment parameters](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/parms.csv): CSV input · `full_test_example/parms.csv`

### Embedding & Alignment Core

- [Single-pair alignment](https://github.com/lucian-ilie/e-score/blob/main/e_score_quick_start.py): Python entry point · Accepts sequences, model settings, penalties, and alignment mode. · `e_score_quick_start.py`
- [Embedding extraction](https://github.com/lucian-ilie/e-score/blob/main/initalizing_models_and_getting_embs.py): model adapter · Converts protein strings into per-residue embedding matrices. · `initalizing_models_and_getting_embs.py`
- **Local protein language models**: external model assets · Ankh is primary; compatible Hugging Face models are loaded locally.
- [Two-model embedding average](https://github.com/lucian-ilie/e-score/blob/main/average_of_two_embedding_models.py): embedding utility · `average_of_two_embedding_models.py`
- **Cosine similarity scoring**: scoring boundary · Uses shifted cosine similarity between residue embeddings.
- **Affine-gap DP alignment**: alignment engine · Supports local, global-regular, and semi-global modes.
- [Python dependencies](https://github.com/lucian-ilie/e-score/blob/main/requirement.txt): dependency manifest · Defines the local Python environment dependencies. · `requirement.txt`

### Batch Execution

- [Batch alignment runner](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/testing_code.py): Python entry point · Sequentially runs examples and writes per-test outputs. · `full_test_example/testing_code.py`
- [Batch job launcher](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/job.sh): shell script · `full_test_example/job.sh`
- [Extension sweep launcher](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/over_extensions_calculation/extension.sh): shell script · `full_test_example/over_extensions_calculation/extension.sh`
- **Per-test alignments**: text artifacts · Filenames encode model and scoring parameters.
- [Distance results](https://github.com/lucian-ilie/e-score/blob/main/full_test_example/cd01068_tests_example_output/cd01068_distances/cd01068_Ankh_0.00000_-1.00000_-0.10000_distances.csv): CSV artifacts · `full_test_example/cd01068_tests_example_output/cd01068_distances/cd01068_Ankh_0.00000_-1.00000_-0.10000_distances.csv`
- [Distance & local extraction](https://github.com/lucian-ilie/e-score/blob/main/distances_and_extracting_local_alignments.py): post-processing script · Derives distances and local-alignment results. · `distances_and_extracting_local_alignments.py`

### Result Analysis

- [Distance consolidation](https://github.com/lucian-ilie/e-score/blob/main/analyzing_results/combining_distance_files.py): analysis script · `analyzing_results/combining_distance_files.py`
- [Comparative statistics](https://github.com/lucian-ilie/e-score/blob/main/analyzing_results/averages_and_pvals.py): analysis script · Computes summaries and significance statistics. · `analyzing_results/averages_and_pvals.py`
- [Comparison visualizations](https://github.com/lucian-ilie/e-score/blob/main/analyzing_results/all_methods_compared_plots/sliding_window_plot.ipynb): analysis notebook · Supports sliding-window and method-comparison views. · `analyzing_results/all_methods_compared_plots/sliding_window_plot.ipynb`

## Connections

- Local protein language models → Embedding extraction: loaded by
- Embedding extraction → Two-model embedding average: optional model outputs
- Embedding extraction → Cosine similarity scoring: residue vectors
- Two-model embedding average → Cosine similarity scoring: averaged vectors
- Cosine similarity scoring → Affine-gap DP alignment: substitution scores
- Single-pair alignment → Embedding extraction: embeds sequences
- Single-pair alignment → Affine-gap DP alignment: runs alignment
- Local curated examples → Batch examples: curated examples source
- Global BB/CDD examples → Batch examples: global examples source
- Batch examples → Batch alignment runner: sequence pairs
- Alignment parameters → Batch alignment runner: run settings
- Batch job launcher → Batch alignment runner: launches
- Extension sweep launcher → Batch alignment runner: sweeps extensions
- Batch alignment runner → Embedding extraction: initializes and embeds
- Batch alignment runner → Affine-gap DP alignment: aligns each test
- Batch alignment runner → Per-test alignments: writes
- Batch alignment runner → Distance results: aggregates
- Per-test alignments → Distance & local extraction: alignment results
- Distance & local extraction → Distance results: derived distances
- Distance results → Distance consolidation: result files
- Distance consolidation → Comparative statistics: consolidated data
- Comparative statistics → Comparison visualizations: comparison metrics
- Python dependencies → Embedding extraction: runtime dependencies
