Bioinformatics · Spring 2026

BLOSUM, but for phage genes.

phamscore turns every cluster on PhagesDB into a log-odds substitution matrix over gene phamilies: how much more often two gene families sit opposite each other in a genome alignment than chance predicts.

Phamilies in matrix
30,873
Phages aligned
5,972
PhagesDB clusters
181
Observed pairs
439,362
phamscore — demo
Live demo

Score a pair of phamilies

The full matrix is 24 MB, so the browser demo works on three real 100 × 100 corners of it (the same blocks saved in matrix_samples.json). Pick two phamilies or click a cell in the heatmap. For any pair at all, run phamscore lookup A B locally.

Lookup

loading sample…
Top scoring pairs in this block (… non-zero)
Phamily APhamily BScore

Matrix heatmap

−530+53

Red: the pair aligns more often than chance. Blue: less often. Grey: never observed together. The diagonal is a phamily aligned with itself.

Rows and columns are PhamIDs in sorted order; the matrix is symmetric.

Distribution of scores across all observed pairs

How it works

Four stages, every one cached to disk

Each stage writes JSON under data/ and re-uses it on the next run, so rebuilding is incremental and the repository ships every intermediate.

1

Fetch

Pull every phage in a PhagesDB cluster and keep only its ordered list of PhamIDs.

Load_cluster_for_alignments.py
2

Align

Global dynamic-programming alignment of PhamID lists for every phage pair. Match +4, mismatch −1, gap −2. Pairs over 80 % identical are dropped.

Alignments.py
3a

Pair probabilities

Walk every aligned column (gaps skipped) and count how often each phamily pair is observed together: Pab.

prob_erator.py
3b

Background

Count how often each phamily appears at all: the background frequencies fa, fb.

counterator.py
4

Score

Pool across all 181 clusters, compute the log-odds, and save a 30,873² int16 matrix as parquet.

score_matrix_maker.py
The scoring equation
S(a, b) = round( λ · log2( Pab / (fa · fb · m) ) )
Pab
observed probability that phamilies a and b are aligned opposite each other, pooled over all clusters
fa, fb
background frequency of each phamily among all non-gap aligned columns
m
1 on the diagonal (a = b), 2 off it, because an unordered pair can appear in either orientation
λ
2, the scale that turns log-odds into readable integers (the matrix spans −26 to +53)

This is the BLOSUM construction of Henikoff & Henikoff (1992) applied to gene families instead of amino acids, with the 80 % identity filter playing the role of BLOSUM's clustering threshold. The full file-by-file walkthrough is in docs/project-flow.md.

Source explorer

Read the code

A snapshot of owner/repo. Every module is heavily commented; the whole pipeline is under 1,500 lines of Python.

src/phamscore/cli.pyOpen on GitHub ↗
Get it

Download or run from source

Checking the latest release…

Windows
…
Download
macOS
…
Download
Linux
…
Download

Each zip bundles the finished matrix, so phamscore lookup works offline with no Python install. Unzip, open a terminal in the folder, and run ./phamscore lookup 10013 10013.

Run from source

git clone …
cd phamscore
./run.sh        # Windows: run.bat

Creates a .venv, installs the package and its five dependencies, prints the data status and scores an example pair. Needs Python 3.10+. Then phamscore --help for lookup, fetch, align, cluster-score and build.

Use the matrix from Python

import pandas as pd
m = pd.read_parquet("data/Global_Weighted_Matrix.parquet",
                    columns=["10013"])
m.loc["10013", "10013"]        # 32

Row and column labels are PhamID strings. Reading one column takes about two seconds; the whole matrix is 1.9 GB in memory.

Embed

Put this demo on your own site

A compact version of this page (terminal, heatmap, download buttons) lives at embed.html. Paste the snippet anywhere HTML is allowed.