Add full TF Atlas MORF isoform ESM-C 600M embeddings
Browse files- .gitattributes +1 -0
- tf_atlas/esmc_600m_morf_isoforms/MANIFEST.json +124 -0
- tf_atlas/esmc_600m_morf_isoforms/README.md +73 -0
- tf_atlas/esmc_600m_morf_isoforms/REPRODUCE.md +83 -0
- tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_manifest.json +0 -0
- tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_protein_sequences.json +0 -0
- tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_summary.json +19 -0
- tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_vocab.json +0 -0
- tf_atlas/esmc_600m_morf_isoforms/scripts/build_tf_atlas_morf_isoform_inputs.py +146 -0
- tf_atlas/esmc_600m_morf_isoforms/scripts/generate_esmc.py +393 -0
- tf_atlas/esmc_600m_morf_isoforms/source/Sup_data_1.xlsx +3 -0
- tf_atlas/esmc_600m_morf_isoforms/tf_atlas_morf_isoforms_esmc_600m_mean_non_special.meta.json +30 -0
- tf_atlas/esmc_600m_morf_isoforms/tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy +3 -0
- tf_atlas/esmc_600m_morf_isoforms/tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy +3 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
tf_atlas/esmc_600m_morf_isoforms/source/Sup_data_1.xlsx filter=lfs diff=lfs merge=lfs -text
|
tf_atlas/esmc_600m_morf_isoforms/MANIFEST.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": "1.0",
|
| 3 |
+
"generated_utc": "2026-04-15T22:31:24Z",
|
| 4 |
+
"artifact_name": "tf_atlas_morf_isoforms_esmc_600m_mean_non_special",
|
| 5 |
+
"source": {
|
| 6 |
+
"paper": "Joung et al. TF Atlas",
|
| 7 |
+
"local_pdf": "readings/Joung_TFAtlas.pdf",
|
| 8 |
+
"source_table": "source/Sup_data_1.xlsx",
|
| 9 |
+
"source_table_title": "Data S1 | TF splice isoforms in the MORF library",
|
| 10 |
+
"source_table_sha256": "5b228ad02760a85fa5d38cf1408a9fd3e662e46ff2c1dc211bf1ec37c84f0dd5",
|
| 11 |
+
"library_rows_including_controls": 3550,
|
| 12 |
+
"tf_isoforms_excluding_controls": 3548,
|
| 13 |
+
"unique_tf_genes_excluding_controls": 1836,
|
| 14 |
+
"excluded_controls": [
|
| 15 |
+
"GFP",
|
| 16 |
+
"mCherry"
|
| 17 |
+
],
|
| 18 |
+
"source_counts": {
|
| 19 |
+
"Genewiz": 2955,
|
| 20 |
+
"Broad GPP": 593,
|
| 21 |
+
"Neither": 2
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"sequence_input": {
|
| 25 |
+
"vocab_path": "metadata/tf_atlas_morf_isoform_vocab.json",
|
| 26 |
+
"sequence_path": "metadata/tf_atlas_morf_isoform_protein_sequences.json",
|
| 27 |
+
"isoform_manifest_path": "metadata/tf_atlas_morf_isoform_manifest.json",
|
| 28 |
+
"translation": "standard genetic code from Data S1 ORF sequence column",
|
| 29 |
+
"min_protein_aa_length": 50,
|
| 30 |
+
"max_protein_aa_length": 3230,
|
| 31 |
+
"protein_aa_length_gt_2048": 49,
|
| 32 |
+
"max_length_used_for_embedding": 4096,
|
| 33 |
+
"vocab_sha256": "7764fe311387fffee349dbe85faa4705cc63eb3519fe767d691eac3167bc5121",
|
| 34 |
+
"sequence_sha256": "75d724d97145bf364bdf3f74e11737c418f3f3f6d600ea5b14d9becafd694499"
|
| 35 |
+
},
|
| 36 |
+
"model": {
|
| 37 |
+
"name": "esmc-600m-2024-12",
|
| 38 |
+
"hf_repo_id": "EvolutionaryScale/esmc-600m-2024-12",
|
| 39 |
+
"snapshot_commit": "d11cc14d44078eaecbc6a843d5eb20f4eecc1e7e",
|
| 40 |
+
"snapshot_dir": "data/raw/protein/esmc/esmc-600m-2024-12",
|
| 41 |
+
"pool": "mean_non_special",
|
| 42 |
+
"max_length": 4096,
|
| 43 |
+
"dimension": 1152,
|
| 44 |
+
"device": "cuda",
|
| 45 |
+
"use_flash_attn": true,
|
| 46 |
+
"packages": {
|
| 47 |
+
"esm": "3.2.1",
|
| 48 |
+
"torch": "2.10.0+cu129",
|
| 49 |
+
"numpy": "1.26.4"
|
| 50 |
+
}
|
| 51 |
+
},
|
| 52 |
+
"embedding": {
|
| 53 |
+
"path": "tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy",
|
| 54 |
+
"mask_path": "tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy",
|
| 55 |
+
"meta_path": "tf_atlas_morf_isoforms_esmc_600m_mean_non_special.meta.json",
|
| 56 |
+
"shape": [
|
| 57 |
+
3548,
|
| 58 |
+
1152
|
| 59 |
+
],
|
| 60 |
+
"dtype": "float32",
|
| 61 |
+
"finite": true,
|
| 62 |
+
"mask_sum": 3548,
|
| 63 |
+
"mean_abs": 0.013355808332562447,
|
| 64 |
+
"row_l2_norm_min": 0.7018150091171265,
|
| 65 |
+
"row_l2_norm_max": 1.7721850872039795
|
| 66 |
+
},
|
| 67 |
+
"reproducibility": {
|
| 68 |
+
"scripts": [
|
| 69 |
+
"scripts/build_tf_atlas_morf_isoform_inputs.py",
|
| 70 |
+
"scripts/generate_esmc.py"
|
| 71 |
+
],
|
| 72 |
+
"commands": "REPRODUCE.md"
|
| 73 |
+
},
|
| 74 |
+
"checksums": {
|
| 75 |
+
"README.md": {
|
| 76 |
+
"sha256": "2b7c6c9a3235693e6f600f744922563dc4555ec5ebfb7d361c612d4655c0390a",
|
| 77 |
+
"bytes": 2550
|
| 78 |
+
},
|
| 79 |
+
"REPRODUCE.md": {
|
| 80 |
+
"sha256": "04a41d8e3c352dace8d8265dcf46aa4ae8410d97c8ab87739e2437da27161a2d",
|
| 81 |
+
"bytes": 2605
|
| 82 |
+
},
|
| 83 |
+
"metadata/tf_atlas_morf_isoform_manifest.json": {
|
| 84 |
+
"sha256": "f2aa5e015c8967a73583547d8e6cffe1cf7847c92cfb5aa8ac943109739390c4",
|
| 85 |
+
"bytes": 1416236
|
| 86 |
+
},
|
| 87 |
+
"metadata/tf_atlas_morf_isoform_protein_sequences.json": {
|
| 88 |
+
"sha256": "75d724d97145bf364bdf3f74e11737c418f3f3f6d600ea5b14d9becafd694499",
|
| 89 |
+
"bytes": 2152477
|
| 90 |
+
},
|
| 91 |
+
"metadata/tf_atlas_morf_isoform_summary.json": {
|
| 92 |
+
"sha256": "97dd8ff6b48e420ae4bdf3ac65bfebbdb05bd781874a23abc2e05ce2d0110464",
|
| 93 |
+
"bytes": 598
|
| 94 |
+
},
|
| 95 |
+
"metadata/tf_atlas_morf_isoform_vocab.json": {
|
| 96 |
+
"sha256": "7764fe311387fffee349dbe85faa4705cc63eb3519fe767d691eac3167bc5121",
|
| 97 |
+
"bytes": 103546
|
| 98 |
+
},
|
| 99 |
+
"scripts/build_tf_atlas_morf_isoform_inputs.py": {
|
| 100 |
+
"sha256": "bbb85e35ee7b77788ad377fc0f563b2a59e37be81d5c39ff1232e3cb90ab0895",
|
| 101 |
+
"bytes": 5549
|
| 102 |
+
},
|
| 103 |
+
"scripts/generate_esmc.py": {
|
| 104 |
+
"sha256": "7f800d3ab6fc9e4191fa92e44c4a4e4de65dbe83a0e2ef60c0a3f8fc1bb05b3b",
|
| 105 |
+
"bytes": 14896
|
| 106 |
+
},
|
| 107 |
+
"source/Sup_data_1.xlsx": {
|
| 108 |
+
"sha256": "5b228ad02760a85fa5d38cf1408a9fd3e662e46ff2c1dc211bf1ec37c84f0dd5",
|
| 109 |
+
"bytes": 2479253
|
| 110 |
+
},
|
| 111 |
+
"tf_atlas_morf_isoforms_esmc_600m_mean_non_special.meta.json": {
|
| 112 |
+
"sha256": "4c127557ad4fb3c3443e023c166fee9ce81c8bb0a25f1fb1837f88bfeb962e1b",
|
| 113 |
+
"bytes": 1525
|
| 114 |
+
},
|
| 115 |
+
"tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy": {
|
| 116 |
+
"sha256": "727a7f3bb3677b527f34c921a460e423fa7e4ff1b92699d984a4d2f8c0f19957",
|
| 117 |
+
"bytes": 16349312
|
| 118 |
+
},
|
| 119 |
+
"tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy": {
|
| 120 |
+
"sha256": "fd6ed7fd4c0e0c59e8ef4ddaedac6af4b762544421e99fb34e01b9de6bbf5072",
|
| 121 |
+
"bytes": 3676
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
tf_atlas/esmc_600m_morf_isoforms/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# TF Atlas MORF isoform ESM-C 600M embeddings
|
| 2 |
+
|
| 3 |
+
This directory contains the corrected full isoform-level ESM-C embedding artifact for the Joung TF Atlas MORF library.
|
| 4 |
+
|
| 5 |
+
The identity source is `Data S1 | TF splice isoforms in the MORF library`, downloaded from the Joung TF Atlas PMC supplement. Data S1 defines the full MORF library as 3,548 TF splice isoforms across 1,836 TF genes, plus two controls.
|
| 6 |
+
|
| 7 |
+
## Artifact
|
| 8 |
+
|
| 9 |
+
- Embedding matrix: `tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy`
|
| 10 |
+
- Mask: `tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy`
|
| 11 |
+
- Model metadata: `tf_atlas_morf_isoforms_esmc_600m_mean_non_special.meta.json`
|
| 12 |
+
- Shape: `3548 x 1152`
|
| 13 |
+
- Dtype: `float32`
|
| 14 |
+
- Pooling: mean over non-special ESM-C tokens
|
| 15 |
+
- Model: `EvolutionaryScale/esmc-600m-2024-12`
|
| 16 |
+
- Snapshot commit: `d11cc14d44078eaecbc6a843d5eb20f4eecc1e7e`
|
| 17 |
+
- Maximum sequence length: `4096`
|
| 18 |
+
|
| 19 |
+
## Identity Contract
|
| 20 |
+
|
| 21 |
+
The MORF library table contains 3,550 rows:
|
| 22 |
+
|
| 23 |
+
- TF splice isoforms: `3,548`
|
| 24 |
+
- Unique TF genes: `1,836`
|
| 25 |
+
- Controls excluded from the embedding matrix: `GFP`, `mCherry`
|
| 26 |
+
- Genewiz constructs: `2,955`
|
| 27 |
+
- Broad GPP constructs: `593`
|
| 28 |
+
- Control constructs: `2`
|
| 29 |
+
|
| 30 |
+
Each embedding row is keyed by:
|
| 31 |
+
|
| 32 |
+
```text
|
| 33 |
+
<TFORF id>-<gene symbol>-<isoform id>
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Example:
|
| 37 |
+
|
| 38 |
+
```text
|
| 39 |
+
TFORF0001-HIF3A-HIF3A-1
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## Sequence Contract
|
| 43 |
+
|
| 44 |
+
The input sequence is translated directly from the Data S1 `ORF sequence` column using the standard genetic code.
|
| 45 |
+
|
| 46 |
+
- Minimum protein length: `50`
|
| 47 |
+
- Maximum protein length: `3230`
|
| 48 |
+
- Proteins longer than 2048 amino acids: `49`
|
| 49 |
+
- ESM-C generation used `--max-length 4096`, so none of the MORF proteins are truncated by the generator.
|
| 50 |
+
|
| 51 |
+
## Files
|
| 52 |
+
|
| 53 |
+
- `source/Sup_data_1.xlsx`: downloaded Data S1 source table.
|
| 54 |
+
- `metadata/tf_atlas_morf_isoform_manifest.json`: per-isoform metadata.
|
| 55 |
+
- `metadata/tf_atlas_morf_isoform_vocab.json`: embedding row order.
|
| 56 |
+
- `metadata/tf_atlas_morf_isoform_protein_sequences.json`: translated amino-acid sequences.
|
| 57 |
+
- `metadata/tf_atlas_morf_isoform_summary.json`: count and length summary.
|
| 58 |
+
- `scripts/build_tf_atlas_morf_isoform_inputs.py`: Data S1 parser and translator.
|
| 59 |
+
- `scripts/generate_esmc.py`: ESM-C embedding generator.
|
| 60 |
+
- `REPRODUCE.md`: exact reproduction commands.
|
| 61 |
+
- `MANIFEST.json`: machine-readable provenance, shape, validation, and checksums.
|
| 62 |
+
|
| 63 |
+
## Validation
|
| 64 |
+
|
| 65 |
+
The generated matrix was validated locally:
|
| 66 |
+
|
| 67 |
+
- Shape: `3548 x 1152`
|
| 68 |
+
- Mask sum: `3548`
|
| 69 |
+
- Finite values: `true`
|
| 70 |
+
- Mean absolute embedding value: `0.013355808332562447`
|
| 71 |
+
- Minimum row L2 norm: `0.7018150091171265`
|
| 72 |
+
- Maximum row L2 norm: `1.7721850872039795`
|
| 73 |
+
|
tf_atlas/esmc_600m_morf_isoforms/REPRODUCE.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reproduce TF Atlas MORF isoform ESM-C embeddings
|
| 2 |
+
|
| 3 |
+
Run from the MANTRA repository root.
|
| 4 |
+
|
| 5 |
+
## 1. Build isoform-level protein sequences
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
python data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/scripts/build_tf_atlas_morf_isoform_inputs.py \
|
| 9 |
+
--sup-data-1 data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/source/Sup_data_1.xlsx \
|
| 10 |
+
--out-dir data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/metadata
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
Expected summary:
|
| 14 |
+
|
| 15 |
+
```json
|
| 16 |
+
{
|
| 17 |
+
"library_rows_including_controls": 3550,
|
| 18 |
+
"tf_isoforms_excluding_controls": 3548,
|
| 19 |
+
"unique_tf_genes_excluding_controls": 1836,
|
| 20 |
+
"controls": [
|
| 21 |
+
"GFP",
|
| 22 |
+
"mCherry"
|
| 23 |
+
],
|
| 24 |
+
"source_counts": {
|
| 25 |
+
"Genewiz": 2955,
|
| 26 |
+
"Broad GPP": 593,
|
| 27 |
+
"Neither": 2
|
| 28 |
+
},
|
| 29 |
+
"min_protein_aa_length": 50,
|
| 30 |
+
"max_protein_aa_length": 3230,
|
| 31 |
+
"protein_aa_length_gt_2048": 49
|
| 32 |
+
}
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## 2. Generate ESM-C 600M embeddings
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
PYTHONPATH=src:. PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True python -m mantra.embeddings.generate_esmc \
|
| 39 |
+
--model-size 600m \
|
| 40 |
+
--device cuda \
|
| 41 |
+
--max-length 4096 \
|
| 42 |
+
--vocab-path data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_vocab.json \
|
| 43 |
+
--sequence-path data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_protein_sequences.json \
|
| 44 |
+
--out-dir data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m \
|
| 45 |
+
--out-prefix tf_atlas_morf_isoforms_esmc_600m_mean_non_special
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
Expected output:
|
| 49 |
+
|
| 50 |
+
- `tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy`
|
| 51 |
+
- `tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy`
|
| 52 |
+
- `tf_atlas_morf_isoforms_esmc_600m_mean_non_special.meta.json`
|
| 53 |
+
|
| 54 |
+
## 3. Validate
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
python - <<'PY'
|
| 58 |
+
import json
|
| 59 |
+
import numpy as np
|
| 60 |
+
from pathlib import Path
|
| 61 |
+
|
| 62 |
+
base = Path("data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/tf_atlas_morf_isoforms_esmc_600m_mean_non_special")
|
| 63 |
+
E = np.load(str(base) + ".npy")
|
| 64 |
+
mask = np.load(str(base) + "_mask.npy")
|
| 65 |
+
meta = json.load(open(str(base) + ".meta.json"))
|
| 66 |
+
print(E.shape)
|
| 67 |
+
print(E.dtype)
|
| 68 |
+
print(np.isfinite(E).all())
|
| 69 |
+
print(int(mask.sum()), len(mask))
|
| 70 |
+
print(meta["n_vocab"], meta["n_embedded"], meta["dimension"], meta["max_length"])
|
| 71 |
+
PY
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
Expected validation:
|
| 75 |
+
|
| 76 |
+
```text
|
| 77 |
+
(3548, 1152)
|
| 78 |
+
float32
|
| 79 |
+
True
|
| 80 |
+
3548 3548
|
| 81 |
+
3548 3548 1152 4096
|
| 82 |
+
```
|
| 83 |
+
|
tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_manifest.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_protein_sequences.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_summary.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source_file": "data/processed/embeddings/registry/compat_mechanistic_context/source_bundles/tf_atlas_joung_2023/Sup_data_1.pmc_download.xlsx",
|
| 3 |
+
"source_sha256": "5b228ad02760a85fa5d38cf1408a9fd3e662e46ff2c1dc211bf1ec37c84f0dd5",
|
| 4 |
+
"library_rows_including_controls": 3550,
|
| 5 |
+
"tf_isoforms_excluding_controls": 3548,
|
| 6 |
+
"unique_tf_genes_excluding_controls": 1836,
|
| 7 |
+
"controls": [
|
| 8 |
+
"GFP",
|
| 9 |
+
"mCherry"
|
| 10 |
+
],
|
| 11 |
+
"source_counts": {
|
| 12 |
+
"Genewiz": 2955,
|
| 13 |
+
"Broad GPP": 593,
|
| 14 |
+
"Neither": 2
|
| 15 |
+
},
|
| 16 |
+
"min_protein_aa_length": 50,
|
| 17 |
+
"max_protein_aa_length": 3230,
|
| 18 |
+
"protein_aa_length_gt_2048": 49
|
| 19 |
+
}
|
tf_atlas/esmc_600m_morf_isoforms/metadata/tf_atlas_morf_isoform_vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tf_atlas/esmc_600m_morf_isoforms/scripts/build_tf_atlas_morf_isoform_inputs.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build ESM-C inputs for the full Joung MORF TF isoform library."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import re
|
| 10 |
+
from collections import Counter
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import pandas as pd
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
CONTROLS = {"GFP", "mCherry"}
|
| 17 |
+
CODON_TABLE = {
|
| 18 |
+
"TTT": "F", "TTC": "F", "TTA": "L", "TTG": "L",
|
| 19 |
+
"TCT": "S", "TCC": "S", "TCA": "S", "TCG": "S",
|
| 20 |
+
"TAT": "Y", "TAC": "Y", "TAA": "*", "TAG": "*",
|
| 21 |
+
"TGT": "C", "TGC": "C", "TGA": "*", "TGG": "W",
|
| 22 |
+
"CTT": "L", "CTC": "L", "CTA": "L", "CTG": "L",
|
| 23 |
+
"CCT": "P", "CCC": "P", "CCA": "P", "CCG": "P",
|
| 24 |
+
"CAT": "H", "CAC": "H", "CAA": "Q", "CAG": "Q",
|
| 25 |
+
"CGT": "R", "CGC": "R", "CGA": "R", "CGG": "R",
|
| 26 |
+
"ATT": "I", "ATC": "I", "ATA": "I", "ATG": "M",
|
| 27 |
+
"ACT": "T", "ACC": "T", "ACA": "T", "ACG": "T",
|
| 28 |
+
"AAT": "N", "AAC": "N", "AAA": "K", "AAG": "K",
|
| 29 |
+
"AGT": "S", "AGC": "S", "AGA": "R", "AGG": "R",
|
| 30 |
+
"GTT": "V", "GTC": "V", "GTA": "V", "GTG": "V",
|
| 31 |
+
"GCT": "A", "GCC": "A", "GCA": "A", "GCG": "A",
|
| 32 |
+
"GAT": "D", "GAC": "D", "GAA": "E", "GAG": "E",
|
| 33 |
+
"GGT": "G", "GGC": "G", "GGA": "G", "GGG": "G",
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def sha256_file(path: Path) -> str:
|
| 38 |
+
digest = hashlib.sha256()
|
| 39 |
+
with path.open("rb") as handle:
|
| 40 |
+
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
| 41 |
+
digest.update(chunk)
|
| 42 |
+
return digest.hexdigest()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def clean_dna(value: object) -> str:
|
| 46 |
+
dna = re.sub(r"\s+", "", str(value).upper())
|
| 47 |
+
if not re.fullmatch(r"[ACGTN]+", dna):
|
| 48 |
+
raise ValueError("ORF sequence contains non-DNA characters")
|
| 49 |
+
if len(dna) % 3:
|
| 50 |
+
raise ValueError("ORF sequence length is not divisible by three")
|
| 51 |
+
return dna
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def translate_orf(dna: str) -> str:
|
| 55 |
+
aa = "".join(CODON_TABLE.get(dna[idx : idx + 3], "X") for idx in range(0, len(dna), 3))
|
| 56 |
+
if "*" in aa:
|
| 57 |
+
raise ValueError("translated ORF contains a stop codon")
|
| 58 |
+
return aa
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def make_isoform_id(row: pd.Series) -> str:
|
| 62 |
+
name = str(row["Name"]).strip()
|
| 63 |
+
gene = str(row["RefSeq Gene Name"]).strip()
|
| 64 |
+
isoform = str(row["Isoform ID"]).strip()
|
| 65 |
+
return f"{name}-{gene}-{isoform}"
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def main() -> int:
|
| 69 |
+
parser = argparse.ArgumentParser()
|
| 70 |
+
parser.add_argument("--sup-data-1", required=True, type=Path)
|
| 71 |
+
parser.add_argument("--out-dir", required=True, type=Path)
|
| 72 |
+
args = parser.parse_args()
|
| 73 |
+
|
| 74 |
+
args.out_dir.mkdir(parents=True, exist_ok=True)
|
| 75 |
+
df = pd.read_excel(args.sup_data_1, sheet_name="Data S1", header=1)
|
| 76 |
+
required = [
|
| 77 |
+
"Source",
|
| 78 |
+
"Name",
|
| 79 |
+
"RefSeq Gene Name",
|
| 80 |
+
"RefSeq and Gencode ID",
|
| 81 |
+
"Isoform ID",
|
| 82 |
+
"ORF sequence",
|
| 83 |
+
"Barcode Sequence",
|
| 84 |
+
"Epitope Tag",
|
| 85 |
+
]
|
| 86 |
+
missing = [column for column in required if column not in df.columns]
|
| 87 |
+
if missing:
|
| 88 |
+
raise ValueError(f"missing expected columns: {missing}")
|
| 89 |
+
|
| 90 |
+
records = []
|
| 91 |
+
sequences = {}
|
| 92 |
+
for _, row in df.iterrows():
|
| 93 |
+
gene = str(row["RefSeq Gene Name"]).strip()
|
| 94 |
+
is_control = gene in CONTROLS
|
| 95 |
+
dna = clean_dna(row["ORF sequence"])
|
| 96 |
+
aa = translate_orf(dna)
|
| 97 |
+
isoform_id = make_isoform_id(row)
|
| 98 |
+
record = {
|
| 99 |
+
"isoform_embedding_id": isoform_id,
|
| 100 |
+
"name": str(row["Name"]).strip(),
|
| 101 |
+
"source": str(row["Source"]).strip(),
|
| 102 |
+
"gene_symbol": gene,
|
| 103 |
+
"refseq_and_gencode_id": str(row["RefSeq and Gencode ID"]).strip(),
|
| 104 |
+
"isoform_id": str(row["Isoform ID"]).strip(),
|
| 105 |
+
"barcode_sequence": str(row["Barcode Sequence"]).strip(),
|
| 106 |
+
"epitope_tag": str(row["Epitope Tag"]).strip(),
|
| 107 |
+
"orf_nt_length": len(dna),
|
| 108 |
+
"protein_aa_length": len(aa),
|
| 109 |
+
"is_control": is_control,
|
| 110 |
+
}
|
| 111 |
+
records.append(record)
|
| 112 |
+
if not is_control:
|
| 113 |
+
sequences[isoform_id] = aa
|
| 114 |
+
|
| 115 |
+
vocab = [record["isoform_embedding_id"] for record in records if not record["is_control"]]
|
| 116 |
+
if len(records) != 3550:
|
| 117 |
+
raise ValueError(f"expected 3550 MORF rows including controls; got {len(records)}")
|
| 118 |
+
if len(vocab) != 3548:
|
| 119 |
+
raise ValueError(f"expected 3548 non-control TF isoforms; got {len(vocab)}")
|
| 120 |
+
if len(vocab) != len(set(vocab)):
|
| 121 |
+
raise ValueError("isoform embedding ids are not unique")
|
| 122 |
+
|
| 123 |
+
lengths = [record["protein_aa_length"] for record in records if not record["is_control"]]
|
| 124 |
+
summary = {
|
| 125 |
+
"source_file": str(args.sup_data_1),
|
| 126 |
+
"source_sha256": sha256_file(args.sup_data_1),
|
| 127 |
+
"library_rows_including_controls": len(records),
|
| 128 |
+
"tf_isoforms_excluding_controls": len(vocab),
|
| 129 |
+
"unique_tf_genes_excluding_controls": len({r["gene_symbol"] for r in records if not r["is_control"]}),
|
| 130 |
+
"controls": [r["gene_symbol"] for r in records if r["is_control"]],
|
| 131 |
+
"source_counts": dict(Counter(r["source"] for r in records)),
|
| 132 |
+
"min_protein_aa_length": min(lengths),
|
| 133 |
+
"max_protein_aa_length": max(lengths),
|
| 134 |
+
"protein_aa_length_gt_2048": sum(length > 2048 for length in lengths),
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
(args.out_dir / "tf_atlas_morf_isoform_manifest.json").write_text(json.dumps(records, indent=2) + "\n")
|
| 138 |
+
(args.out_dir / "tf_atlas_morf_isoform_vocab.json").write_text(json.dumps(vocab, indent=2) + "\n")
|
| 139 |
+
(args.out_dir / "tf_atlas_morf_isoform_protein_sequences.json").write_text(json.dumps(sequences, indent=2) + "\n")
|
| 140 |
+
(args.out_dir / "tf_atlas_morf_isoform_summary.json").write_text(json.dumps(summary, indent=2) + "\n")
|
| 141 |
+
print(json.dumps(summary, indent=2))
|
| 142 |
+
return 0
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
if __name__ == "__main__":
|
| 146 |
+
raise SystemExit(main())
|
tf_atlas/esmc_600m_morf_isoforms/scripts/generate_esmc.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
from dataclasses import dataclass, field
|
| 5 |
+
from datetime import datetime, timezone
|
| 6 |
+
import hashlib
|
| 7 |
+
import json
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any, Protocol
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
|
| 13 |
+
from mantra.embeddings.generate_esm3 import POOL_MODES, pool_token_embeddings, sanitize_sequence
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
DEFAULT_META_DIR = Path("data/processed/metadata")
|
| 17 |
+
DEFAULT_SNAPSHOT_ROOT = Path("data/raw/protein/esmc")
|
| 18 |
+
DEFAULT_OUT_ROOT = Path("data/processed/embeddings/registry/protein_sequence/source_gene_artifacts")
|
| 19 |
+
DEFAULT_MODEL_SIZE = "300m"
|
| 20 |
+
DEFAULT_POOL = "mean_non_special"
|
| 21 |
+
|
| 22 |
+
ESMC_MODELS: dict[str, dict[str, Any]] = {
|
| 23 |
+
"300m": {
|
| 24 |
+
"repo_id": "EvolutionaryScale/esmc-300m-2024-12",
|
| 25 |
+
"revision": "a19d363f07313a10a64d08a2d6b41376a73df5c8",
|
| 26 |
+
"snapshot_name": "esmc-300m-2024-12",
|
| 27 |
+
"weight_path": "data/weights/esmc_300m_2024_12_v0.pth",
|
| 28 |
+
"builder": "ESMC_300M_202412",
|
| 29 |
+
"dimension": 960,
|
| 30 |
+
},
|
| 31 |
+
"600m": {
|
| 32 |
+
"repo_id": "EvolutionaryScale/esmc-600m-2024-12",
|
| 33 |
+
"revision": "d11cc14d44078eaecbc6a843d5eb20f4eecc1e7e",
|
| 34 |
+
"snapshot_name": "esmc-600m-2024-12",
|
| 35 |
+
"weight_path": "data/weights/esmc_600m_2024_12_v0.pth",
|
| 36 |
+
"builder": "ESMC_600M_202412",
|
| 37 |
+
"dimension": 1152,
|
| 38 |
+
},
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class SequenceExtractor(Protocol):
|
| 43 |
+
def embed(self, sequence: str) -> np.ndarray:
|
| 44 |
+
raise NotImplementedError
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@dataclass(frozen=True)
|
| 48 |
+
class EsmcGenerationConfig:
|
| 49 |
+
model_size: str = DEFAULT_MODEL_SIZE
|
| 50 |
+
meta_dir: Path = DEFAULT_META_DIR
|
| 51 |
+
snapshot_root: Path = DEFAULT_SNAPSHOT_ROOT
|
| 52 |
+
snapshot_dir: Path | None = None
|
| 53 |
+
out_root: Path = DEFAULT_OUT_ROOT
|
| 54 |
+
out_dir: Path | None = None
|
| 55 |
+
out_prefix: str | None = None
|
| 56 |
+
vocab_path: Path | None = None
|
| 57 |
+
sequence_path: Path | None = None
|
| 58 |
+
device: str = "auto"
|
| 59 |
+
pool: str = DEFAULT_POOL
|
| 60 |
+
max_length: int = 2048
|
| 61 |
+
limit: int | None = None
|
| 62 |
+
use_flash_attn: bool = True
|
| 63 |
+
|
| 64 |
+
@property
|
| 65 |
+
def model_info(self) -> dict[str, Any]:
|
| 66 |
+
if self.model_size not in ESMC_MODELS:
|
| 67 |
+
raise ValueError(f"model_size must be one of {tuple(ESMC_MODELS)}; got {self.model_size!r}")
|
| 68 |
+
return ESMC_MODELS[self.model_size]
|
| 69 |
+
|
| 70 |
+
@property
|
| 71 |
+
def resolved_snapshot_dir(self) -> Path:
|
| 72 |
+
return self.snapshot_dir if self.snapshot_dir is not None else self.snapshot_root / self.model_info["snapshot_name"]
|
| 73 |
+
|
| 74 |
+
@property
|
| 75 |
+
def resolved_out_dir(self) -> Path:
|
| 76 |
+
return self.out_dir if self.out_dir is not None else self.out_root / self.model_info["snapshot_name"].replace("-", "_")
|
| 77 |
+
|
| 78 |
+
@property
|
| 79 |
+
def resolved_out_prefix(self) -> str:
|
| 80 |
+
return self.out_prefix if self.out_prefix is not None else f"{self.model_info['snapshot_name'].replace('-', '_')}_{self.pool}"
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def resolved_vocab_path(self) -> Path:
|
| 84 |
+
return self.vocab_path if self.vocab_path is not None else self.meta_dir / "vocab_k562_gwps_full.json"
|
| 85 |
+
|
| 86 |
+
@property
|
| 87 |
+
def resolved_sequence_path(self) -> Path:
|
| 88 |
+
return self.sequence_path if self.sequence_path is not None else self.meta_dir / "regulator_sequences.json"
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def embedding_path(self) -> Path:
|
| 92 |
+
return self.resolved_out_dir / f"{self.resolved_out_prefix}.npy"
|
| 93 |
+
|
| 94 |
+
@property
|
| 95 |
+
def mask_path(self) -> Path:
|
| 96 |
+
return self.resolved_out_dir / f"{self.resolved_out_prefix}_mask.npy"
|
| 97 |
+
|
| 98 |
+
@property
|
| 99 |
+
def metadata_path(self) -> Path:
|
| 100 |
+
return self.resolved_out_dir / f"{self.resolved_out_prefix}.meta.json"
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
@dataclass
|
| 104 |
+
class EsmcSequenceExtractor:
|
| 105 |
+
model_size: str = DEFAULT_MODEL_SIZE
|
| 106 |
+
snapshot_root: Path = DEFAULT_SNAPSHOT_ROOT
|
| 107 |
+
snapshot_dir: Path | None = None
|
| 108 |
+
device: str = "auto"
|
| 109 |
+
pool: str = DEFAULT_POOL
|
| 110 |
+
max_length: int = 2048
|
| 111 |
+
use_flash_attn: bool = True
|
| 112 |
+
_model: Any = field(default=None, init=False, repr=False)
|
| 113 |
+
_esm_protein: Any = field(default=None, init=False, repr=False)
|
| 114 |
+
_logits_config: Any = field(default=None, init=False, repr=False)
|
| 115 |
+
_resolved_device: str | None = field(default=None, init=False, repr=False)
|
| 116 |
+
|
| 117 |
+
def __post_init__(self) -> None:
|
| 118 |
+
if self.model_size not in ESMC_MODELS:
|
| 119 |
+
raise ValueError(f"model_size must be one of {tuple(ESMC_MODELS)}; got {self.model_size!r}")
|
| 120 |
+
if self.pool not in POOL_MODES:
|
| 121 |
+
raise ValueError(f"pool must be one of {POOL_MODES}; got {self.pool!r}")
|
| 122 |
+
if self.max_length <= 0:
|
| 123 |
+
raise ValueError("max_length must be positive")
|
| 124 |
+
|
| 125 |
+
@property
|
| 126 |
+
def model_info(self) -> dict[str, Any]:
|
| 127 |
+
return ESMC_MODELS[self.model_size]
|
| 128 |
+
|
| 129 |
+
@property
|
| 130 |
+
def resolved_snapshot_dir(self) -> Path:
|
| 131 |
+
return self.snapshot_dir if self.snapshot_dir is not None else self.snapshot_root / self.model_info["snapshot_name"]
|
| 132 |
+
|
| 133 |
+
@property
|
| 134 |
+
def model(self) -> Any:
|
| 135 |
+
if self._model is None:
|
| 136 |
+
self._load_model()
|
| 137 |
+
return self._model
|
| 138 |
+
|
| 139 |
+
@property
|
| 140 |
+
def resolved_device(self) -> str:
|
| 141 |
+
if self._resolved_device is None:
|
| 142 |
+
self._resolved_device = resolve_device(self.device)
|
| 143 |
+
return self._resolved_device
|
| 144 |
+
|
| 145 |
+
def _load_model(self) -> None:
|
| 146 |
+
import esm.pretrained as pretrained
|
| 147 |
+
import esm.utils.constants.esm3 as constants
|
| 148 |
+
from esm.sdk.api import ESMProtein, LogitsConfig
|
| 149 |
+
|
| 150 |
+
snapshot_dir = self.resolved_snapshot_dir
|
| 151 |
+
assert_snapshot_complete(snapshot_dir, model_size=self.model_size)
|
| 152 |
+
|
| 153 |
+
def local_data_root(model: str) -> Path:
|
| 154 |
+
if str(model).startswith("esmc-300"):
|
| 155 |
+
return snapshot_dir if self.model_size == "300m" else self.snapshot_root / ESMC_MODELS["300m"]["snapshot_name"]
|
| 156 |
+
if str(model).startswith("esmc-600"):
|
| 157 |
+
return snapshot_dir if self.model_size == "600m" else self.snapshot_root / ESMC_MODELS["600m"]["snapshot_name"]
|
| 158 |
+
return snapshot_dir
|
| 159 |
+
|
| 160 |
+
constants.data_root = local_data_root
|
| 161 |
+
pretrained.data_root = local_data_root
|
| 162 |
+
builder = getattr(pretrained, self.model_info["builder"])
|
| 163 |
+
self._esm_protein = ESMProtein
|
| 164 |
+
self._logits_config = LogitsConfig
|
| 165 |
+
self._model = builder(self.resolved_device, use_flash_attn=self.use_flash_attn)
|
| 166 |
+
self._model.eval()
|
| 167 |
+
|
| 168 |
+
def embed(self, sequence: str) -> np.ndarray:
|
| 169 |
+
sequence_clean = sanitize_sequence(sequence, self.max_length)
|
| 170 |
+
if not sequence_clean:
|
| 171 |
+
raise ValueError("cannot embed an empty sequence")
|
| 172 |
+
protein = self._esm_protein(sequence=sequence_clean) if self._esm_protein is not None else None
|
| 173 |
+
if protein is None:
|
| 174 |
+
self._load_model()
|
| 175 |
+
protein = self._esm_protein(sequence=sequence_clean)
|
| 176 |
+
tokens = self.model.encode(protein)
|
| 177 |
+
logits_config = self._logits_config(return_embeddings=True)
|
| 178 |
+
import torch
|
| 179 |
+
|
| 180 |
+
with torch.inference_mode():
|
| 181 |
+
output = self.model.logits(tokens, logits_config)
|
| 182 |
+
embedding = output.embeddings.detach().float().cpu().numpy()
|
| 183 |
+
return pool_token_embeddings(embedding, pool=self.pool)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def resolve_device(device: str) -> str:
|
| 187 |
+
if device != "auto":
|
| 188 |
+
return device
|
| 189 |
+
import torch
|
| 190 |
+
|
| 191 |
+
return "cuda" if torch.cuda.is_available() else "cpu"
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def utc_now_iso() -> str:
|
| 195 |
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def load_json(path: Path) -> Any:
|
| 199 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 200 |
+
return json.load(handle)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def load_vocab(path: Path) -> list[str]:
|
| 204 |
+
payload = load_json(path)
|
| 205 |
+
if not isinstance(payload, list) or not all(isinstance(item, str) for item in payload):
|
| 206 |
+
raise ValueError(f"vocab must be a JSON string list: {path}")
|
| 207 |
+
return payload
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def load_sequence_map(path: Path) -> dict[str, str]:
|
| 211 |
+
payload = load_json(path)
|
| 212 |
+
if not isinstance(payload, dict):
|
| 213 |
+
raise ValueError(f"sequence map must be a JSON object: {path}")
|
| 214 |
+
return {str(key): str(value) for key, value in payload.items() if str(value)}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def sha256_file(path: Path) -> str:
|
| 218 |
+
digest = hashlib.sha256()
|
| 219 |
+
with path.open("rb") as handle:
|
| 220 |
+
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
| 221 |
+
digest.update(chunk)
|
| 222 |
+
return digest.hexdigest()
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def assert_snapshot_complete(snapshot_dir: Path, *, model_size: str) -> None:
|
| 226 |
+
if model_size not in ESMC_MODELS:
|
| 227 |
+
raise ValueError(f"model_size must be one of {tuple(ESMC_MODELS)}; got {model_size!r}")
|
| 228 |
+
required = (
|
| 229 |
+
".gitattributes",
|
| 230 |
+
"README.md",
|
| 231 |
+
"config.json",
|
| 232 |
+
ESMC_MODELS[model_size]["weight_path"],
|
| 233 |
+
)
|
| 234 |
+
missing = [str(snapshot_dir / rel_path) for rel_path in required if not (snapshot_dir / rel_path).exists()]
|
| 235 |
+
if missing:
|
| 236 |
+
raise FileNotFoundError("ESM-C snapshot is incomplete:\n" + "\n".join(missing))
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def package_versions() -> dict[str, str | None]:
|
| 240 |
+
versions: dict[str, str | None] = {}
|
| 241 |
+
for package in ("esm", "torch", "numpy"):
|
| 242 |
+
try:
|
| 243 |
+
module = __import__(package)
|
| 244 |
+
versions[package] = getattr(module, "__version__", None)
|
| 245 |
+
except Exception:
|
| 246 |
+
versions[package] = None
|
| 247 |
+
return versions
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def build_metadata(
|
| 251 |
+
*,
|
| 252 |
+
config: EsmcGenerationConfig,
|
| 253 |
+
genes: list[str],
|
| 254 |
+
mask: np.ndarray,
|
| 255 |
+
dim: int,
|
| 256 |
+
embedding_path: Path,
|
| 257 |
+
) -> dict[str, Any]:
|
| 258 |
+
info = config.model_info
|
| 259 |
+
return {
|
| 260 |
+
"schema_version": "1.0",
|
| 261 |
+
"generated_utc": utc_now_iso(),
|
| 262 |
+
"model": info["snapshot_name"],
|
| 263 |
+
"model_size": config.model_size,
|
| 264 |
+
"hf_repo_id": info["repo_id"],
|
| 265 |
+
"snapshot_dir": str(config.resolved_snapshot_dir),
|
| 266 |
+
"snapshot_commit": info["revision"],
|
| 267 |
+
"pool": config.pool,
|
| 268 |
+
"max_length": config.max_length,
|
| 269 |
+
"device": config.device,
|
| 270 |
+
"limit": config.limit,
|
| 271 |
+
"use_flash_attn": config.use_flash_attn,
|
| 272 |
+
"vocab_path": str(config.resolved_vocab_path),
|
| 273 |
+
"sequence_path": str(config.resolved_sequence_path),
|
| 274 |
+
"vocab_sha256": sha256_file(config.resolved_vocab_path),
|
| 275 |
+
"sequence_sha256": sha256_file(config.resolved_sequence_path),
|
| 276 |
+
"embedding_path": str(embedding_path),
|
| 277 |
+
"mask_path": str(config.mask_path),
|
| 278 |
+
"n_vocab": len(genes),
|
| 279 |
+
"n_embedded": int(mask.sum()),
|
| 280 |
+
"dimension": int(dim),
|
| 281 |
+
"expected_dimension": int(info["dimension"]),
|
| 282 |
+
"dtype": "float32",
|
| 283 |
+
"packages": package_versions(),
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def generate_esmc_embeddings(
|
| 288 |
+
config: EsmcGenerationConfig,
|
| 289 |
+
*,
|
| 290 |
+
extractor: SequenceExtractor | None = None,
|
| 291 |
+
) -> dict[str, Any]:
|
| 292 |
+
if config.pool not in POOL_MODES:
|
| 293 |
+
raise ValueError(f"pool must be one of {POOL_MODES}; got {config.pool!r}")
|
| 294 |
+
genes_all = load_vocab(config.resolved_vocab_path)
|
| 295 |
+
genes = genes_all[: config.limit] if config.limit is not None else genes_all
|
| 296 |
+
seq_map = load_sequence_map(config.resolved_sequence_path)
|
| 297 |
+
sequence_extractor = extractor or EsmcSequenceExtractor(
|
| 298 |
+
model_size=config.model_size,
|
| 299 |
+
snapshot_root=config.snapshot_root,
|
| 300 |
+
snapshot_dir=config.snapshot_dir,
|
| 301 |
+
device=config.device,
|
| 302 |
+
pool=config.pool,
|
| 303 |
+
max_length=config.max_length,
|
| 304 |
+
use_flash_attn=config.use_flash_attn,
|
| 305 |
+
)
|
| 306 |
+
rows: list[np.ndarray] = []
|
| 307 |
+
mask = np.zeros(len(genes), dtype=bool)
|
| 308 |
+
dim: int | None = None
|
| 309 |
+
for idx, gene in enumerate(genes):
|
| 310 |
+
sequence = sanitize_sequence(seq_map.get(gene, ""), config.max_length)
|
| 311 |
+
if not sequence:
|
| 312 |
+
if dim is None:
|
| 313 |
+
rows.append(np.zeros((0,), dtype=np.float32))
|
| 314 |
+
else:
|
| 315 |
+
rows.append(np.zeros((dim,), dtype=np.float32))
|
| 316 |
+
continue
|
| 317 |
+
vector = np.asarray(sequence_extractor.embed(sequence), dtype=np.float32)
|
| 318 |
+
if vector.ndim != 1:
|
| 319 |
+
raise ValueError(f"extractor returned non-vector embedding for {gene}: {vector.shape}")
|
| 320 |
+
if dim is None:
|
| 321 |
+
dim = int(vector.shape[0])
|
| 322 |
+
rows = [np.zeros((dim,), dtype=np.float32) if row.size == 0 else row for row in rows]
|
| 323 |
+
elif vector.shape[0] != dim:
|
| 324 |
+
raise ValueError(f"extractor dimension changed from {dim} to {vector.shape[0]} for {gene}")
|
| 325 |
+
rows.append(vector)
|
| 326 |
+
mask[idx] = True
|
| 327 |
+
if dim is None:
|
| 328 |
+
raise ValueError("no sequences were embedded; check the vocabulary and sequence map")
|
| 329 |
+
matrix = np.vstack(rows).astype(np.float32, copy=False)
|
| 330 |
+
config.resolved_out_dir.mkdir(parents=True, exist_ok=True)
|
| 331 |
+
np.save(config.embedding_path, matrix)
|
| 332 |
+
np.save(config.mask_path, mask)
|
| 333 |
+
metadata = build_metadata(
|
| 334 |
+
config=config,
|
| 335 |
+
genes=genes,
|
| 336 |
+
mask=mask,
|
| 337 |
+
dim=dim,
|
| 338 |
+
embedding_path=config.embedding_path,
|
| 339 |
+
)
|
| 340 |
+
config.metadata_path.write_text(json.dumps(metadata, indent=2) + "\n", encoding="utf-8")
|
| 341 |
+
return metadata
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def parse_args(argv: list[str] | None = None) -> EsmcGenerationConfig:
|
| 345 |
+
parser = argparse.ArgumentParser(description="Generate local ESM-C protein embeddings.")
|
| 346 |
+
parser.add_argument("--model-size", choices=tuple(ESMC_MODELS), default=DEFAULT_MODEL_SIZE)
|
| 347 |
+
parser.add_argument("--meta-dir", type=Path, default=DEFAULT_META_DIR)
|
| 348 |
+
parser.add_argument("--snapshot-root", type=Path, default=DEFAULT_SNAPSHOT_ROOT)
|
| 349 |
+
parser.add_argument("--snapshot-dir", type=Path)
|
| 350 |
+
parser.add_argument("--out-root", type=Path, default=DEFAULT_OUT_ROOT)
|
| 351 |
+
parser.add_argument("--out-dir", type=Path)
|
| 352 |
+
parser.add_argument("--out-prefix", type=str)
|
| 353 |
+
parser.add_argument("--vocab-path", type=Path)
|
| 354 |
+
parser.add_argument("--sequence-path", type=Path)
|
| 355 |
+
parser.add_argument("--device", type=str, default="auto")
|
| 356 |
+
parser.add_argument("--pool", choices=POOL_MODES, default=DEFAULT_POOL)
|
| 357 |
+
parser.add_argument("--max-length", type=int, default=2048)
|
| 358 |
+
parser.add_argument("--limit", type=int)
|
| 359 |
+
parser.add_argument("--no-flash-attn", action="store_true")
|
| 360 |
+
args = parser.parse_args(argv)
|
| 361 |
+
return EsmcGenerationConfig(
|
| 362 |
+
model_size=args.model_size,
|
| 363 |
+
meta_dir=args.meta_dir,
|
| 364 |
+
snapshot_root=args.snapshot_root,
|
| 365 |
+
snapshot_dir=args.snapshot_dir,
|
| 366 |
+
out_root=args.out_root,
|
| 367 |
+
out_dir=args.out_dir,
|
| 368 |
+
out_prefix=args.out_prefix,
|
| 369 |
+
vocab_path=args.vocab_path,
|
| 370 |
+
sequence_path=args.sequence_path,
|
| 371 |
+
device=args.device,
|
| 372 |
+
pool=args.pool,
|
| 373 |
+
max_length=args.max_length,
|
| 374 |
+
limit=args.limit,
|
| 375 |
+
use_flash_attn=not args.no_flash_attn,
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
# Example invocation:
|
| 379 |
+
# PYTHONPATH=src:. python -m mantra.embeddings.generate_esmc \
|
| 380 |
+
# --device cuda \
|
| 381 |
+
# --vocab-path /tmp/mantra_one_tf_vocab.json \
|
| 382 |
+
# --sequence-path data/processed/metadata/regulator_sequences.json \
|
| 383 |
+
# --out-dir /tmp/mantra_esm3_gata1 \
|
| 384 |
+
# --out-prefix GATA1_esm3
|
| 385 |
+
|
| 386 |
+
def main(argv: list[str] | None = None) -> int:
|
| 387 |
+
metadata = generate_esmc_embeddings(parse_args(argv))
|
| 388 |
+
print(json.dumps(metadata, indent=2))
|
| 389 |
+
return 0
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
if __name__ == "__main__": # pragma: no cover
|
| 393 |
+
raise SystemExit(main())
|
tf_atlas/esmc_600m_morf_isoforms/source/Sup_data_1.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5b228ad02760a85fa5d38cf1408a9fd3e662e46ff2c1dc211bf1ec37c84f0dd5
|
| 3 |
+
size 2479253
|
tf_atlas/esmc_600m_morf_isoforms/tf_atlas_morf_isoforms_esmc_600m_mean_non_special.meta.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": "1.0",
|
| 3 |
+
"generated_utc": "2026-04-15T22:29:59Z",
|
| 4 |
+
"model": "esmc-600m-2024-12",
|
| 5 |
+
"model_size": "600m",
|
| 6 |
+
"hf_repo_id": "EvolutionaryScale/esmc-600m-2024-12",
|
| 7 |
+
"snapshot_dir": "data/raw/protein/esmc/esmc-600m-2024-12",
|
| 8 |
+
"snapshot_commit": "d11cc14d44078eaecbc6a843d5eb20f4eecc1e7e",
|
| 9 |
+
"pool": "mean_non_special",
|
| 10 |
+
"max_length": 4096,
|
| 11 |
+
"device": "cuda",
|
| 12 |
+
"limit": null,
|
| 13 |
+
"use_flash_attn": true,
|
| 14 |
+
"vocab_path": "data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_vocab.json",
|
| 15 |
+
"sequence_path": "data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_protein_sequences.json",
|
| 16 |
+
"vocab_sha256": "7764fe311387fffee349dbe85faa4705cc63eb3519fe767d691eac3167bc5121",
|
| 17 |
+
"sequence_sha256": "75d724d97145bf364bdf3f74e11737c418f3f3f6d600ea5b14d9becafd694499",
|
| 18 |
+
"embedding_path": "data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy",
|
| 19 |
+
"mask_path": "data/processed/embeddings/registry/protein_sequence/source_gene_artifacts/tf_atlas_morf_isoforms_esmc_600m/tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy",
|
| 20 |
+
"n_vocab": 3548,
|
| 21 |
+
"n_embedded": 3548,
|
| 22 |
+
"dimension": 1152,
|
| 23 |
+
"expected_dimension": 1152,
|
| 24 |
+
"dtype": "float32",
|
| 25 |
+
"packages": {
|
| 26 |
+
"esm": "3.2.1",
|
| 27 |
+
"torch": "2.10.0+cu129",
|
| 28 |
+
"numpy": "1.26.4"
|
| 29 |
+
}
|
| 30 |
+
}
|
tf_atlas/esmc_600m_morf_isoforms/tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:727a7f3bb3677b527f34c921a460e423fa7e4ff1b92699d984a4d2f8c0f19957
|
| 3 |
+
size 16349312
|
tf_atlas/esmc_600m_morf_isoforms/tf_atlas_morf_isoforms_esmc_600m_mean_non_special_mask.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fd6ed7fd4c0e0c59e8ef4ddaedac6af4b762544421e99fb34e01b9de6bbf5072
|
| 3 |
+
size 3676
|