feat(alphafold): custom MSA input for monomer and multimer predictions (#52)#235
feat(alphafold): custom MSA input for monomer and multimer predictions (#52)#235Elarwei001 wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #235 +/- ##
==========================================
+ Coverage 56.70% 57.16% +0.45%
==========================================
Files 29 29
Lines 9392 9468 +76
==========================================
+ Hits 5326 5412 +86
+ Misses 4066 4056 -10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add an `msa` parameter (Python) / -msa, --msa flag (CLI) to gget alphafold that lets users supply a custom multiple sequence alignment (a3m or aligned FASTA) instead of running the internal jackhmmer search. The first sequence in the MSA must be the query. When a custom MSA is provided, gget skips the jackhmmer search and the genetic-database download entirely and builds the MSA features directly from the file. New helpers detect_msa_format()/parse_custom_msa()/ read_custom_msa() handle format detection and a3m/FASTA parsing (lowercase a3m insertions are folded into the deletion matrix, matching AlphaFold's own parser). Currently supported for single-sequence (monomer) predictions; clear errors are raised otherwise. Default behavior is unchanged (backward compatible). Resolves scverse#52. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
22b4993 to
1de9260
Compare
Bilingual (ZH/EN) analysis of scverse/gget#235 (adds an msa argument to gget alphafold: supply a custom a3m/FASTA MSA, skip the jackhmmer search and the ~2GB database download). Covers platform fit (enhance an existing module), the a3m parsing that faithfully reproduces AlphaFold's own parse_a3m, the reproducibility gain, the CI-constrained parsing-level tests, and the pre-commit.ci red root cause (a single mypy narrowing at gget_alphafold.py:712). Updated README index + index.html card. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…xing (scverse#52) `custom_msa_paths` is assigned a list inside an earlier `if msa is not None:` block, so at the fold loop mypy still sees it as `list[str] | None` and rejects the indexing (the pre-commit.ci mypy failure). Guard on `custom_msa_paths is not None` (equivalent to `msa is not None`) so the type narrows. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
) Extends the custom-MSA input to multimer: pass one MSA file per chain (in the same order as the sequences) instead of the previous monomer-only restriction. - Extract the per-chain validation into a testable `_validate_custom_msa_paths` helper: one MSA file per chain, each file's format checked, and each chain's first MSA sequence must equal that chain's query (gaps removed). - For heteromer multimer, the custom MSA also serves as the "all_seq" MSA that AlphaFold-Multimer pairs across chains by species (reuses the existing msa_pairing / pipeline_multimer path); pairing degrades gracefully to unpaired when headers lack species identifiers. - CLI `--msa` now accepts multiple files (nargs="+"). - Tests for the validation helper (monomer/multimer OK, count mismatch, per-chain query mismatch, missing file). The fold/pairing path itself still cannot be exercised in CI (AlphaFold's heavy deps/GPU are unavailable); it reuses AlphaFold's own multimer feature pipeline unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
End-to-end verification of the multimer custom-MSA pathThe unit tests here cover the argument / parsing / validation layer (which is all CI can run, since AlphaFold's heavy runtime deps aren't available). To cover the part CI can't, I ran a full GPU fold of the new multimer path on a rented CUDA GPU. It passes end-to-end. Environment
Test case — a real small heterodimer: human insulin A chain (21 aa) + B chain (30 aa). Each chain gets a custom a3m whose first sequence is that chain's query, plus three species-tagged homologs (headers use the UniProt gget.alphafold(
["GIVEQCCTSICSLYQLENYCN", "FVNQHLCGSHLVEALYLVCGERGFFYTPKT"],
msa=["chainA.a3m", "chainB.a3m"],
relax=False, plot=False,
)Run log (key lines) Result — a valid two-chain complex + PAE:
So the new path ( Full artifacts (inputs, driver, run log, output PDB + PAE, environment snapshot): https://gist.github.com/Elarwei001/0e342e4e76997c7d07553279f778d5a8 One side note from setting this up: getting AlphaFold to actually install/import currently needs a couple of workarounds that are unrelated to this PR (they're in the |
End-to-end verification — monomer pathFollowing up on the multimer run above: I also verified the monomer custom-MSA path end-to-end on a GPU (the original issue #52 case — a single sequence with a single MSA, passing Environment — RTX A6000 (48 GB), Python 3.12, jax 0.4.26 (cuda12), Test case — human insulin B chain (30 aa) with a single custom a3m (query + 3 homologs): gget.alphafold(
"FVNQHLCGSHLVEALYLVCGERGFFYTPKT",
msa="chainM.a3m", # single string, not a list
relax=False, plot=False,
)Run log (key lines) Result — Artifacts (monomer inputs, driver, run log, output PDB + PAE, environment snapshot) are in the same gist as the multimer run, under the With this, both paths added in this PR are verified end-to-end on a real GPU: multimer (one MSA per chain) and monomer (single MSA). |
|
Hi @lauraluebbert , when you get a chance, could you take a look at #235? Quick summary:
Thanks! |
Resolves #52
Summary
gget alphafold: Adds a newmsaargument (-msa/--msaon the command line) that lets you supply a custom multiple sequence alignment instead of running the internal jackhmmer search. When an MSA is provided,gget alphafoldskips the jackhmmer search entirely, so no genetic databases are downloaded (the internal search otherwise fetches ~2 GB) — useful for folding from a manually curated MSA.Originally scoped to monomers (issue #52); this PR also extends the feature to MULTIMER predictions (one MSA file per chain).
What it does
.a3m) and aligned FASTA (.fasta/.fa/.afa). a3m lowercase insertions are parsed into the deletion matrix (matching AlphaFold's own a3m handling); aligned FASTA has no insertions, so its deletion matrix is all zeros.all_seqMSA, which Multimer pairs across chains by species. Pairing only finds matches when the MSA headers carry species identifiers; otherwise it degrades gracefully to an unpaired multimer.Implementation notes
_validate_custom_msa_paths(custom_msa_paths, sequences)enforces, before any prediction work:detect_msa_format,parse_custom_msa(a3m/FASTA → aligned sequences + deletion matrix + descriptions), andread_custom_msa(returns analphafold.data.parsers.Msa).chmod, per-chain search) is now gated behindmsa is Noneand left otherwise unchanged.--msausesnargs="+"so it accepts one or more files (one per chain);main.pyforwardsargs.msatoalphafold(...).Testing
Unit / validation tests added in
tests/test_alphafold.py(with a3m + aligned-FASTA fixtures intests/fixtures/), covering format detection, a3m/FASTA parsing and deletion-matrix behavior, the CLI--msaflag, and the monomer + multimer validation cases (count mismatch, query mismatch, missing file). These pass. AlphaFold's heavy runtime deps aren't available in CI, so tests run at the parsing/validation level; a full GPU end-to-end fold is in progress and not yet complete.Docs
docs/src/en/alphafold.md— documents the-msa/--msaargument.docs/src/en/updates.md— changelog entry.Resolves issue 52.