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.
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.
| Phamily A | Phamily B | Score |
|---|
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.
Each stage writes JSON under data/ and re-uses it on the next run, so rebuilding is incremental and the repository ships every intermediate.
Pull every phage in a PhagesDB cluster and keep only its ordered list of PhamIDs.
Load_cluster_for_alignments.pyGlobal dynamic-programming alignment of PhamID lists for every phage pair. Match +4, mismatch −1, gap −2. Pairs over 80 % identical are dropped.
Alignments.pyWalk every aligned column (gaps skipped) and count how often each phamily pair is observed together: Pab.
prob_erator.pyCount how often each phamily appears at all: the background frequencies fa, fb.
counterator.pyPool across all 181 clusters, compute the log-odds, and save a 30,873² int16 matrix as parquet.
score_matrix_maker.pyThis 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.
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 ↗
Checking the latest release…
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.
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.
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.
A compact version of this page (terminal, heatmap, download buttons) lives at embed.html. Paste the snippet anywhere HTML is allowed.