lhallee commited on
Commit
57a974f
·
verified ·
1 Parent(s): 3b8a449

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +189 -0
README.md CHANGED
@@ -30,4 +30,193 @@ configs:
30
  path: data/valid-*
31
  - split: test
32
  path: data/test-*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  path: data/valid-*
31
  - split: test
32
  path: data/test-*
33
+
34
+ license: cc-by-4.0
35
+ language:
36
+ - en
37
+ tags:
38
+ - biology
39
+ - protein
40
+ - protein-language-model
41
+ - embeddings
42
+ - representation-learning
43
+ - uniprot
44
+ - gene-ontology
45
+ pretty_name: PLAT (Protein Language Alignment Tuples)
46
+ task_categories:
47
+ - feature-extraction
48
+ - sentence-similarity
49
+ - text-classification
50
  ---
51
+
52
+ # PLAT: Protein Language Alignment Tuples
53
+
54
+ `plat_data` is a curated, cluster-split dataset of protein sequences paired with structured functional annotations and natural-language descriptions. It is designed to train and evaluate cross-encoder alignment models (Vec2Vec, Mat2Mat) that map representations between different protein language models (PLMs), or between PLMs and natural-language encoders.
55
+
56
+ Each row contains:
57
+
58
+ - a protein `sequence` (amino-acid string),
59
+ - an `annotation` list of integer IDs covering Gene Ontology, EC numbers, InterPro, Gene3D, cofactors, and UniProt keywords,
60
+ - a `description` string assembled from UniProt free-text curation (function, miscellaneous notes, subcellular localization, domain).
61
+
62
+ ## Dataset Schema
63
+
64
+ | Field | Type | Description |
65
+ |---------------|-------------|-------------|
66
+ | `sequence` | `string` | Canonical amino-acid sequence in single-letter IUPAC code. |
67
+ | `annotation` | `list[int]` | Sorted, deduplicated integer IDs decoded via the `label2id.pkl` vocabulary produced by `data/process_uniprot_av.py`. Each ID corresponds to a typed annotation key of the form `"<value>_<suffix>"` where suffix is one of `bp`, `cc`, `mf`, `ec`, `cofactor`, `ip`, `threed`, `keywords`. |
68
+ | `description` | `string` | Structured free-text block beginning with `"The following text describes a protein:"` and containing any present of `Function:`, `Miscellaneous:`, `Subcellular Localization:`, `Domain:` subsections. Every row is guaranteed to contain a `Function:` block (see "Preferential sampling" below). |
69
+ | `labels` | `int` | Placeholder column (always `0`), added by `data/add_dummy_labels.py` so downstream `Trainer` pipelines that expect a `labels` key work without modification. |
70
+
71
+ ### Splits
72
+
73
+ The dataset has three splits: `train`, `valid`, and `test`. Splitting is performed at the cluster level (see "Clustering and splitting" below), so no sequence in `valid` or `test` shares more than ~40% identity with any sequence in `train`.
74
+
75
+ ## Data Source
76
+
77
+ The primary upstream source is UniProtKB, restricted to entries with manually curated Gene Ontology annotations (the "GO manual" subset). Two snapshots are used:
78
+
79
+ - `uniprotkb_go_manual_2025_11_18.tsv.gz` (1,380,840 entries) for structured annotations.
80
+ - `uniprotkb_go_manual_2025_12_02.tsv.gz` (1,380,840 entries) for free-text descriptions.
81
+
82
+ Columns pulled from the UniProt TSV are:
83
+
84
+ | UniProt column | Used for | Parsing |
85
+ |----------------|----------|---------|
86
+ | `Entry` | record key | verbatim |
87
+ | `Sequence` | `sequence` | verbatim |
88
+ | `EC number` | annotations | split on `;`, strip |
89
+ | `Cofactor` | annotations | parse `Name=<x>` from each `COFACTOR:` entry |
90
+ | `Gene Ontology (biological process)` | annotations | extract `GO:xxxxxxx` IDs |
91
+ | `Gene Ontology (cellular component)` | annotations | extract `GO:xxxxxxx` IDs |
92
+ | `Gene Ontology (molecular function)` | annotations | extract `GO:xxxxxxx` IDs |
93
+ | `InterPro` | annotations | split on `;`, drop trailing empty |
94
+ | `Gene3D` | annotations | split on `;`, drop trailing empty |
95
+ | `Keywords` | annotations | split on `;`, strip |
96
+ | `Function [CC]` | description | see text cleaning |
97
+ | `Miscellaneous [CC]` | description | see text cleaning |
98
+ | `Subcellular location [CC]` | description | see text cleaning |
99
+ | `Domain [CC]` | description | see text cleaning |
100
+
101
+ ### Annotation vocabulary
102
+
103
+ `data/process_uniprot_av.py` streams the UniProt TSV twice. The first pass builds a `label2id` dictionary whose keys are typed strings (e.g. `GO:0016310_bp`, `1.1.1.1_ec`, `IPR000878_ip`, `ATP-binding_keywords`, `K(+)_cofactor`). The second pass emits `camp_data.csv` with columns `[sequence, annotations]`, where `annotations` is the sorted, deduplicated list of integer IDs for that protein. The `label2id.pkl` and `id2label.pkl` files are the authoritative mapping used throughout the pipeline. The resulting table is pushed to the intermediate dataset `lhallee/camp_data_11_2025`.
104
+
105
+ ### Description assembly
106
+
107
+ `data/process_uniprot_cc.py` builds the free-text description by concatenating the four CC columns in order (`Function`, `Miscellaneous`, `Subcellular location`, `Domain`), each under its own header. Text cleaning removes:
108
+
109
+ - `(PubMed:...)` inline citations,
110
+ - `{ECO:...}` evidence codes,
111
+ - UniProt CC prefixes (`FUNCTION: `, `MISC: `, `SUBCELLULAR LOCATION: `, `DOMAIN: `),
112
+ - redundant whitespace and stray punctuation artifacts from the removals above.
113
+
114
+ A resulting row looks like:
115
+
116
+ ```
117
+ The following text describes a protein:
118
+ Function:
119
+ Catalyzes the reversible conversion of methylmalonyl-CoA to succinyl-CoA...
120
+ Subcellular Localization:
121
+ Mitochondrial matrix...
122
+ ```
123
+
124
+ ## Build Pipeline
125
+
126
+ The full pipeline is four stages. All scripts live under [data/](data/) in the source repo.
127
+
128
+ ### Stage 1: UniProt ingestion and annotation curation
129
+
130
+ - Input: `uniprotkb_go_manual_2025_11_18.tsv.gz` and `uniprotkb_go_manual_2025_12_02.tsv.gz`.
131
+ - [data/process_uniprot_av.py](data/process_uniprot_av.py) produces `camp_data.csv` (sequence + integer annotation list) and the `label2id.pkl` / `id2label.pkl` vocabulary files.
132
+ - [data/process_uniprot_cc.py](data/process_uniprot_cc.py) produces `seq_descriptions.tsv` (entry + sequence + structured description).
133
+
134
+ The sequence-keyed dictionaries `seq_annotation_dict.pkl` and `seq_description_dict.pkl` are later used by the final assembly step to look up annotations and descriptions by exact sequence match.
135
+
136
+ The annotation table is pushed to [lhallee/camp_data_11_2025](https://huggingface.co/datasets/lhallee/camp_data_11_2025) as an intermediate artifact.
137
+
138
+ ### Stage 2: Deduplication
139
+
140
+ Before clustering, exact-duplicate sequences are removed with `drop_duplicates(subset=['sequence'])` (see [data/build_dataset.py](data/build_dataset.py)).
141
+
142
+ ### Stage 3: Clustering and splitting
143
+
144
+ Clustering and split assignment are performed by [data/build_dataset.py](data/build_dataset.py):
145
+
146
+ - Sequences are written to a FASTA file with integer IDs.
147
+ - CD-HIT is invoked inside a Docker container built from the official CD-HIT Dockerfile.
148
+ - **Identity threshold: 0.4** (40% sequence identity), word size `-n 5`. This is the threshold actually used for the published PLAT release, as recorded by the cluster filename `output_lhallee_camp_data_11_2025_0.4.clstr`.
149
+ - The `.clstr` output is parsed into `cluster_dict: {cluster_id -> [seq_ids]}` and `id_seq_dict: {seq_id -> sequence}`.
150
+ - Clusters are shuffled and partitioned:
151
+ - **5% valid clusters, 5% test clusters, 90% train clusters.**
152
+ - The four working pickles (`cluster_dict.pkl`, `id_seq_dict.pkl`, `final_cluster_dict.pkl`, `seq_annotation_dict.pkl`) are uploaded to an auxiliary private repo for reproducibility.
153
+
154
+ Because splits are assigned by cluster, any two sequences in different splits are less than ~40% identical under CD-HIT's greedy incremental clustering, which gives a realistic generalization benchmark for PLM alignment.
155
+
156
+ ### Stage 4: PLAT assembly (preferential sampling)
157
+
158
+ [data/build_plat_data.py](data/build_plat_data.py) produces the final dataset:
159
+
160
+ 1. For each cluster in each split, gather all member sequences.
161
+ 2. Keep only sequences for which both an `annotation` and a `description` exist.
162
+ 3. Keep only the subset whose `description` contains the literal substring `"Function:"` (that is, sequences with at least a UniProt `Function [CC]` annotation after text cleaning).
163
+ 4. Pick one sequence uniformly at random from that subset (seed `42`).
164
+ 5. If no candidate survives, **the cluster is skipped entirely**. This biases PLAT toward clusters containing at least one well-characterized member.
165
+ 6. The resulting records (`sequence`, `annotation`, `description`) are assembled into a `DatasetDict(train, valid, test)` and pushed to `lhallee/plat_data`.
166
+
167
+ A final `labels` column of constant `0` is added by [data/add_dummy_labels.py](data/add_dummy_labels.py) for compatibility with generic `Trainer` pipelines.
168
+
169
+ ## Reproducing the Build
170
+
171
+ ```bash
172
+ # 1. Parse UniProt TSV into annotations + vocabulary
173
+ py -m data.process_uniprot_av
174
+ # -> camp_data.csv, label2id.pkl, id2label.pkl
175
+ # -> pushes lhallee/camp_data_11_2025
176
+
177
+ # 2. Parse UniProt TSV into descriptions
178
+ py -m data.process_uniprot_cc
179
+ # -> seq_descriptions.tsv
180
+
181
+ # 3. Cluster with CD-HIT and split by cluster (requires Docker)
182
+ py -m data.build_dataset \
183
+ --hf_token <token> \
184
+ --dataset_path lhallee/camp_data_11_2025 \
185
+ --similarity_threshold 0.4 \
186
+ --n 5 \
187
+ --valid_percentage 0.05 \
188
+ --test_percentage 0.05
189
+
190
+ # 4. Assemble PLAT with preferential Function-aware sampling
191
+ py -m data.build_plat_data \
192
+ --hf_token <token> \
193
+ --repo_name lhallee/plat_data \
194
+ --seed 42
195
+ ```
196
+
197
+ ## Intended Use
198
+
199
+ PLAT was constructed to train and evaluate representation-alignment models:
200
+
201
+ - **Vec2Vec**: align pooled (mean + variance) embeddings from one PLM to another, or from a PLM to a natural-language encoder of the `description` field.
202
+ - **Mat2Mat**: align full residue-by-residue embedding matrices between two PLMs.
203
+ - **Cross-modal retrieval**: use the `description` column with a text encoder (for example ModernBERT or GPT-OSS) and the `sequence` column with a PLM (for example ESMC-600), then evaluate whether aligned embeddings retrieve each other.
204
+
205
+ Typical consumption patterns in the source repo read columns as `(sequence, sequence)`, `(sequence, description)`, or `(description, description)` pairs.
206
+
207
+ ## Licensing and Attribution
208
+
209
+ All sequences and annotations are derived from UniProtKB and are redistributed under the UniProt terms of use (Creative Commons Attribution 4.0, `CC BY 4.0`). If you use PLAT, please also cite UniProt:
210
+
211
+ > The UniProt Consortium. UniProt: the Universal Protein Knowledgebase in 2025. *Nucleic Acids Research*, 2025.
212
+
213
+ And the dependent databases surfaced in the annotation vocabulary: Gene Ontology, Enzyme Commission (IUBMB), InterPro, Gene3D, and the UniProt Keyword ontology.
214
+
215
+ ## Known Limitations
216
+
217
+ - **Manual-annotation bias.** Only UniProt entries with manually curated GO terms are considered, and only clusters containing at least one member with a `Function [CC]` block appear in the final dataset. Taxa and protein families that are underrepresented in Swiss-Prot are correspondingly underrepresented here.
218
+ - **One representative per cluster.** Within-cluster diversity (paralogs, species variants) is not preserved: each cluster contributes a single randomly chosen, function-annotated representative.
219
+ - **Descriptions are post-processed.** PubMed citations, ECO evidence codes, and the CC-prefix tags are stripped, which simplifies downstream tokenization but loses provenance information relative to the raw UniProt text.
220
+ - **Integer annotation labels are only meaningful via `label2id.pkl`.** The integer space mixes eight annotation types; training code that treats it as a single flat multi-label target should be aware that different IDs correspond to semantically different taxonomies.
221
+ - **Snapshot-frozen.** PLAT is built from a fixed UniProt release (manual-GO subset, November-December 2025) and will not reflect later curation updates until rebuilt.
222
+