afdb / STRUCTURES.md
tonynzh2's picture
Document GO/ASR folders as a separate dataset; note AF3 completeness
a8e2169 verified
|
Raw History Blame Contribute Delete
8.23 kB
# Structures for the GPBridge expanded-GO dataset
One structure per sequence for **322,992 sequences**, assembled from three
sources. They are meant to be used together, so the first thing to read is
`structure_index.tsv`: it resolves any `seq_id` to a file, whichever source
provides it.
Sequence ids are `seq_<sha256(sequence)[:20]>`, so an id always identifies an
exact sequence.
## Coverage
| Source | Sequences | What it is |
|---|---:|---|
| `gpbridge/afdb/` | 304,787 | AlphaFold DB, **AlphaFold 2**, model v6 |
| `gpbridge/pdb/` | 11,495 | experimental structures from RCSB |
| `predictions/missing_pdb_afdb/` | 6,540 | **AlphaFold 3**, predicted here |
| no structure | 11,075 | neither source has one |
10,904 sequences have both an AFDB model and a PDB entry — the index exposes
both so you can choose per use case.
**These come from three different methods.** AF2, AF3 and experiment are not
interchangeable, and the split is not random: see *Provenance* below before
training on the union.
## Resolve a sequence to a file
`structure_index.tsv` — one row per sequence, all sources on the same row:
```
seq_id length split best af3_archive afdb_archive afdb_file
pdb_archive pdb_file pdb_all_ids note
```
`best` is a suggested default, not a judgement: `af3` where one was predicted,
otherwise `afdb`, otherwise `pdb`. That ordering follows the source bundle's own
guidance — AFDB is the workhorse, while a PDB hit may be a construct, a single
domain, or one chain of a complex and is not guaranteed to cover the full
sequence. For experimental ground truth, prefer `pdb_archive` explicitly.
```python
import csv, io, json, tarfile, zstandard
from huggingface_hub import hf_hub_download
REPO = "tonynzh2/afdb"
idx = {r["seq_id"]: r for r in csv.DictReader(
open(hf_hub_download(REPO, "structure_index.tsv", repo_type="dataset")),
delimiter="\t")}
def structure(seq_id, prefer=None):
"""Returns (source, text). prefer='pdb' to force experimental when present."""
r = idx[seq_id]
order = [prefer] if prefer else []
order += ["af3", "afdb", "pdb"]
for src in order:
if src == "af3" and r["af3_archive"]:
return "af3", _from_zst(r["af3_archive"], seq_id)
if src == "afdb" and r["afdb_archive"]:
return "afdb", _from_tar(r["afdb_archive"], r["afdb_file"], gz=True)
if src == "pdb" and r["pdb_archive"]:
return "pdb", _from_tar(r["pdb_archive"], r["pdb_file"], gz=True)
return "none", None
def _from_tar(archive, member, gz=False):
import gzip
path = hf_hub_download(REPO, archive, repo_type="dataset")
with tarfile.open(path) as tar: # plain tar, members are .gz
raw = tar.extractfile(member).read()
return gzip.decompress(raw).decode() if gz else raw.decode()
def _from_zst(archive, seq_id):
path = hf_hub_download(REPO, archive, repo_type="dataset")
with open(path, "rb") as fh:
stream = zstandard.ZstdDecompressor().stream_reader(fh)
with tarfile.open(fileobj=stream, mode="r|") as tar:
for m in tar:
if m.isfile() and m.name == f"{seq_id}/{seq_id}_model.cif":
return tar.extractfile(m).read().decode()
return None
```
The AFDB and PDB archives are plain `.tar` holding already-gzipped `.cif.gz`
members; the AF3 archives are `.tar.zst` holding whole output directories. Both
are bundled by shard because 350,000+ loose objects would make the repo
unusable.
## Provenance — read before combining
The three sources differ in method, and **which source a sequence gets is not
random**:
- Reconstructed ancestral sequences have no UniProt accession, so they can never
have an AFDB model. They are predicted or nothing.
- Well-studied proteins are the ones with PDB entries.
- The 6,540 AF3 predictions are, by construction, the sequences with *neither* a
PDB entry nor an AFDB model — i.e. the thinnest-homology corner of the dataset.
So source correlates with sequence properties. If a model trained on the union
behaves differently on AF2-labelled versus AF3-labelled sequences, that is
confounded with those properties and not attributable to the structures alone.
Record which source each label came from — the index's `best` column does this —
and check it as a covariate rather than assuming exchangeability.
Version details worth recording: AFDB files are **model v6** (not the v4 many
papers cite), and the AF3 predictions use v3.0.4 with stock settings, seed
20260916, 5 diffusion samples, 10 recycles, full 4-database MSA and template
search. Per-shard details are in `predictions/missing_pdb_afdb/README.md`.
## Known gaps
| Issue | Count | Handling |
|---|---:|---|
| AFDB accession linked but **no model exists** at any version | 1,508 | in `gpbridge/afdb_no_model_needs_af3.fasta`; not in any fetch list and not in `missing_pdb_afdb_training.fasta` either — they need prediction |
| PDB entries **withdrawn** by RCSB | 7 | fetched into `gpbridge/pdb_obsolete/`, flagged in the index's `note` |
| No structure from any source | 11,075 | `best = none` |
The 1,508 are worth emphasising: the source bundle's coverage table counts them
as having an AlphaFold DB model. They do not — they are live UniProt entries of
ordinary length returning 404 on both v6 and v4. Nothing in the original
pipeline covered them.
## Not part of this dataset
The repository also holds `predictions/00001_00256/` and
`predictions/00257_00512/`. These are **a different dataset** - the GO + ASR
catalog (292,804 sequences: Gene Ontology couplings and ancestral sequence
reconstructions), predicted with the same stock AlphaFold 3 settings but
unrelated to the GPBridge expanded-GO set documented here.
They are deliberately absent from `structure_index.tsv`, which covers only the
322,992 GPBridge sequences. Do not join them by `seq_id` and assume membership:
both datasets use `seq_<sha256(sequence)[:20]>` ids, so an id collision means
the two sets genuinely share that exact sequence, not that the row belongs here.
That campaign is partially complete and its shards are named by length band.
## Layout
```
structure_index.tsv every sequence -> its file(s)
gpbridge/join.tsv.gz original join table from the source bundle
gpbridge/coverage.csv source bundle's coverage, all 13 populations
gpbridge/BUNDLE_README.md source bundle's own documentation
gpbridge/afdb/<2-char>.tar 211 archives, AF2 model v6
gpbridge/pdb/<2-char>.tar 1,088 archives, experimental
gpbridge/pdb_obsolete/ 7 withdrawn entries
gpbridge/afdb_no_model.tsv the 1,508, with their 404s
gpbridge/afdb_no_model_needs_af3.fasta their sequences
predictions/missing_pdb_afdb/ AF3 output + its own README and index
predictions/00001_00256/ GO+ASR catalog - a DIFFERENT dataset
predictions/00257_00512/ GO+ASR catalog - a DIFFERENT dataset
```
### Completeness
`predictions/missing_pdb_afdb/` is **still being produced**: 6 of 14 archives
are published at the time of writing. `structure_index.tsv` lists all 6,540 of
those sequences regardless, because the index describes the dataset, not the
current upload state. Check which archives exist before assuming a sequence is
retrievable:
```python
from huggingface_hub import HfApi
have = {x.rfilename for x in HfApi().repo_info("tonynzh2/afdb",
repo_type="dataset").siblings}
missing = {s: r for s, r in idx.items()
if r["af3_archive"] and r["af3_archive"] not in have}
```
The AFDB and PDB portions are complete: 211 and 1,088 archives respectively.
## Terms of use
AlphaFold 3 output in `predictions/` is subject to the
[AlphaFold 3 Output Terms of Use](OUTPUT_TERMS_OF_USE.md) — non-commercial, and
redistribution must carry the terms. AlphaFold DB structures are CC-BY-4.0 from
EMBL-EBI. PDB entries are in the public domain.
Cite AlphaFold 3: Abramson, J. et al. *Nature* **630**, 493–500 (2024).
Cite AlphaFold DB: Varadi, M. et al. *Nucleic Acids Research* (2024).