Datasets:
Add default Parquet file/table index for UniProtKB
Browse files- README.md +104 -79
- data/test-00000-of-00001.parquet +3 -0
- data/train-00000-of-00001.parquet +3 -0
- dataset_summary.json +70 -0
- metadata/source_files.parquet +3 -0
- scripts/prepare_uniprotkb_dataset.py +330 -0
README.md
CHANGED
|
@@ -17,7 +17,16 @@ tags:
|
|
| 17 |
- protein-sequences
|
| 18 |
- bioinformatics
|
| 19 |
- train-validation-test-split
|
|
|
|
| 20 |
configs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
- config_name: sprot
|
| 22 |
data_files:
|
| 23 |
- split: train
|
|
@@ -55,41 +64,68 @@ configs:
|
|
| 55 |
|
| 56 |
# UniProtKB Processed
|
| 57 |
|
| 58 |
-
This
|
| 59 |
-
It converts UniProtKB FASTA headers into normalized records that can be browsed
|
| 60 |
-
in the Hugging Face Dataset Viewer and loaded with the `datasets` library.
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
## Dataset Summary
|
| 68 |
|
| 69 |
-
| Source set | Description |
|
| 70 |
|---|---|---:|
|
| 71 |
| `sprot` | Swiss-Prot reviewed canonical proteins | 574,627 |
|
| 72 |
| `sprot_varsplic` | Swiss-Prot alternative isoform sequences | 41,333 |
|
| 73 |
| `trembl` | TrEMBL unreviewed proteins | 202,556,314 |
|
| 74 |
| **Total** | | **203,172,274** |
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
Exact duplicate sequences are kept in the same split.
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|---|---:|
|
| 83 |
| `train` | 162,548,965 |
|
| 84 |
| `validation` | 20,308,533 |
|
| 85 |
| `test` | 20,314,776 |
|
| 86 |
|
| 87 |
-
These are exact-sequence splits, not homology-cluster splits. For strict
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
Load Swiss-Prot reviewed entries:
|
| 93 |
|
| 94 |
```python
|
| 95 |
from datasets import load_dataset
|
|
@@ -100,7 +136,7 @@ valid = sprot["validation"]
|
|
| 100 |
test = sprot["test"]
|
| 101 |
```
|
| 102 |
|
| 103 |
-
Load Swiss-Prot alternative
|
| 104 |
|
| 105 |
```python
|
| 106 |
from datasets import load_dataset
|
|
@@ -108,82 +144,72 @@ from datasets import load_dataset
|
|
| 108 |
isoforms = load_dataset("LiteFold/UniProtKB", "sprot_varsplic")
|
| 109 |
```
|
| 110 |
|
| 111 |
-
|
| 112 |
|
| 113 |
```python
|
| 114 |
from datasets import load_dataset
|
| 115 |
|
| 116 |
-
|
| 117 |
-
for row in
|
| 118 |
print(row["accession"], row["protein_name"])
|
| 119 |
break
|
| 120 |
```
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
```python
|
| 125 |
-
from datasets import load_dataset
|
| 126 |
-
|
| 127 |
-
ds = load_dataset("LiteFold/UniProtKB", "sprot", split="train")
|
| 128 |
-
human = ds.filter(lambda x: x["taxon_id"] == 9606)
|
| 129 |
-
reviewed_kinases = human.filter(lambda x: "kinase" in x["protein_name"].lower())
|
| 130 |
-
```
|
| 131 |
-
|
| 132 |
-
For large-scale TrEMBL use, prefer streaming:
|
| 133 |
|
| 134 |
```python
|
| 135 |
from datasets import load_dataset
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
```
|
| 141 |
|
| 142 |
-
|
| 143 |
-
a single mixed `default` config. Load one of `sprot`, `sprot_varsplic`, or
|
| 144 |
-
`trembl` explicitly.
|
| 145 |
-
|
| 146 |
-
## Columns
|
| 147 |
|
| 148 |
| Column | Type | Description |
|
| 149 |
|---|---|---|
|
| 150 |
-
| `
|
| 151 |
-
| `
|
| 152 |
-
| `
|
| 153 |
-
| `
|
| 154 |
-
| `
|
| 155 |
-
| `
|
| 156 |
-
| `
|
| 157 |
-
| `
|
| 158 |
-
| `
|
| 159 |
-
| `
|
| 160 |
-
| `
|
| 161 |
-
| `
|
| 162 |
-
| `
|
| 163 |
-
| `
|
| 164 |
-
| `
|
| 165 |
-
| `
|
| 166 |
-
| `
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
|
| 188 |
## License
|
| 189 |
|
|
@@ -191,7 +217,6 @@ CC BY 4.0.
|
|
| 191 |
|
| 192 |
## Citation
|
| 193 |
|
| 194 |
-
If you use
|
| 195 |
|
| 196 |
-
The UniProt Consortium. UniProt: the Universal Protein Knowledgebase in 2023.
|
| 197 |
-
Nucleic Acids Research, 51(D1):D523-D531, 2023.
|
|
|
|
| 17 |
- protein-sequences
|
| 18 |
- bioinformatics
|
| 19 |
- train-validation-test-split
|
| 20 |
+
- parquet
|
| 21 |
configs:
|
| 22 |
+
- config_name: default
|
| 23 |
+
data_files:
|
| 24 |
+
- split: train
|
| 25 |
+
path:
|
| 26 |
+
- data/train-*.parquet
|
| 27 |
+
- split: test
|
| 28 |
+
path:
|
| 29 |
+
- data/test-*.parquet
|
| 30 |
- config_name: sprot
|
| 31 |
data_files:
|
| 32 |
- split: train
|
|
|
|
| 64 |
|
| 65 |
# UniProtKB Processed
|
| 66 |
|
| 67 |
+
This repository contains two useful views of LiteFold/UniProtKB:
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
- `default`: a compact Parquet file/table shard index that is easy to browse in the Hugging Face Dataset Viewer.
|
| 70 |
+
- `sprot`, `sprot_varsplic`, and `trembl`: the full parsed UniProtKB protein-entry tables from the original repository.
|
| 71 |
+
|
| 72 |
+
The `default` config does not duplicate all 203M protein rows. It indexes the repository files, table shards, source sets, source sizes, and split-level row counts so the dataset has a stable table preview while the full source-specific tables remain available through named configs.
|
| 73 |
|
| 74 |
## Dataset Summary
|
| 75 |
|
| 76 |
+
| Source set | Description | Protein records |
|
| 77 |
|---|---|---:|
|
| 78 |
| `sprot` | Swiss-Prot reviewed canonical proteins | 574,627 |
|
| 79 |
| `sprot_varsplic` | Swiss-Prot alternative isoform sequences | 41,333 |
|
| 80 |
| `trembl` | TrEMBL unreviewed proteins | 202,556,314 |
|
| 81 |
| **Total** | | **203,172,274** |
|
| 82 |
|
| 83 |
+
Additional source totals:
|
| 84 |
+
|
| 85 |
+
| Metric | Value |
|
| 86 |
+
|---|---:|
|
| 87 |
+
| Total residues | 75,747,523,712 |
|
| 88 |
+
| Sequence shards | 205 |
|
| 89 |
+
| Protein-entry table shards | 615 |
|
| 90 |
+
| Default index rows | 830 |
|
| 91 |
+
| Sequence shard bytes | 46,504,287,641 |
|
| 92 |
+
| Metadata records bytes | 74,373,082,266 |
|
| 93 |
+
| Protein-entry table bytes | 18,549,213,567 |
|
| 94 |
|
| 95 |
+
## Default Index Splits
|
|
|
|
| 96 |
|
| 97 |
+
The default Dataset Viewer index is split deterministically by `sha256(file_id) % 10`: bucket `0` is `test`, and buckets `1` through `9` are `train`.
|
| 98 |
+
|
| 99 |
+
| Split | Rows |
|
| 100 |
+
|---|---:|
|
| 101 |
+
| `train` | 733 |
|
| 102 |
+
| `test` | 97 |
|
| 103 |
+
|
| 104 |
+
## Protein-Entry Splits
|
| 105 |
+
|
| 106 |
+
The full protein-entry tables use deterministic exact-sequence hash splits. Exact duplicate amino-acid sequences are kept in the same split.
|
| 107 |
+
|
| 108 |
+
| Split | Protein records |
|
| 109 |
|---|---:|
|
| 110 |
| `train` | 162,548,965 |
|
| 111 |
| `validation` | 20,308,533 |
|
| 112 |
| `test` | 20,314,776 |
|
| 113 |
|
| 114 |
+
These are exact-sequence splits, not homology-cluster splits. For strict homology-aware model evaluation, create an additional split using UniRef, MMseqs, or another sequence-clustering method.
|
| 115 |
+
|
| 116 |
+
## Loading With `datasets`
|
| 117 |
+
|
| 118 |
+
Load the default file/table index:
|
| 119 |
|
| 120 |
+
```python
|
| 121 |
+
from datasets import load_dataset
|
| 122 |
+
|
| 123 |
+
index = load_dataset("LiteFold/UniProtKB")
|
| 124 |
+
print(index)
|
| 125 |
+
print(index["train"][0])
|
| 126 |
+
```
|
| 127 |
|
| 128 |
+
Load Swiss-Prot reviewed protein entries:
|
| 129 |
|
| 130 |
```python
|
| 131 |
from datasets import load_dataset
|
|
|
|
| 136 |
test = sprot["test"]
|
| 137 |
```
|
| 138 |
|
| 139 |
+
Load Swiss-Prot alternative isoform entries:
|
| 140 |
|
| 141 |
```python
|
| 142 |
from datasets import load_dataset
|
|
|
|
| 144 |
isoforms = load_dataset("LiteFold/UniProtKB", "sprot_varsplic")
|
| 145 |
```
|
| 146 |
|
| 147 |
+
Stream TrEMBL entries:
|
| 148 |
|
| 149 |
```python
|
| 150 |
from datasets import load_dataset
|
| 151 |
|
| 152 |
+
rows = load_dataset("LiteFold/UniProtKB", "trembl", split="train", streaming=True)
|
| 153 |
+
for row in rows:
|
| 154 |
print(row["accession"], row["protein_name"])
|
| 155 |
break
|
| 156 |
```
|
| 157 |
|
| 158 |
+
Use the default index to discover table shards:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
```python
|
| 161 |
from datasets import load_dataset
|
| 162 |
|
| 163 |
+
index = load_dataset("LiteFold/UniProtKB", split="train")
|
| 164 |
+
trembl_train_shards = index.filter(
|
| 165 |
+
lambda row: row["role"] == "protein_entry_table_shard"
|
| 166 |
+
and row["source_set"] == "trembl"
|
| 167 |
+
and row["table_split"] == "train"
|
| 168 |
+
)
|
| 169 |
+
print(trembl_train_shards[0]["path"])
|
| 170 |
```
|
| 171 |
|
| 172 |
+
## Default Columns
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
| Column | Type | Description |
|
| 175 |
|---|---|---|
|
| 176 |
+
| `file_id` | string | Stable file identifier, currently the repository path. |
|
| 177 |
+
| `repo_id` | string | Hugging Face dataset repository id. |
|
| 178 |
+
| `source_sha` | string | Source repository commit used to build the index. |
|
| 179 |
+
| `dataset_id` | string | Source dataset id from `_MANIFEST.json`. |
|
| 180 |
+
| `source_set` | string | `sprot`, `sprot_varsplic`, `trembl`, or empty for repository-level files. |
|
| 181 |
+
| `source_slug` | string | Source file slug used in the original manifests. |
|
| 182 |
+
| `source_file` | string | Original source file path. |
|
| 183 |
+
| `path` | string | Path in this Hugging Face repository. |
|
| 184 |
+
| `role` | string | File role such as `protein_entry_table_shard`, `sequence_shard`, or `metadata_records`. |
|
| 185 |
+
| `table_split` | string | Protein-entry split for table shards. |
|
| 186 |
+
| `shard_index` | int64 | Parsed shard index when present. |
|
| 187 |
+
| `size_bytes` | int64 | File size in bytes. |
|
| 188 |
+
| `compression` | string | Compression format when applicable. |
|
| 189 |
+
| `records_in_source` | int64 | Protein records in the source set. |
|
| 190 |
+
| `residues_in_source` | int64 | Residues in the source set. |
|
| 191 |
+
| `shards_in_source` | int64 | Number of sequence shards in the source set. |
|
| 192 |
+
| `records_in_table_split` | int64 | Protein records in that source set and split. |
|
| 193 |
+
| `records_total` | int64 | Total protein records across UniProtKB. |
|
| 194 |
+
| `residues_total` | int64 | Total residues across UniProtKB. |
|
| 195 |
+
| `total_sequence_shards` | int64 | Total sequence shards. |
|
| 196 |
+
| `is_sequence_shard` | bool | Whether the row points to a FASTA sequence shard. |
|
| 197 |
+
| `is_table_shard` | bool | Whether the row points to a parsed protein-entry table shard. |
|
| 198 |
+
| `is_metadata_records` | bool | Whether the row points to metadata records. |
|
| 199 |
+
| `download_pattern` | string | Glob or exact path that can be used for file downloads. |
|
| 200 |
+
| `access_note` | string | Short note describing how to load the row's data. |
|
| 201 |
+
| `split_bucket` | int64 | Deterministic bucket used for the default train/test split. |
|
| 202 |
+
|
| 203 |
+
## Files
|
| 204 |
+
|
| 205 |
+
- `data/*.parquet`: default file/table index for Dataset Viewer.
|
| 206 |
+
- `tables/source_set=*/split=*/*.jsonl.gz`: full parsed protein-entry tables.
|
| 207 |
+
- `sequences/*/*.fasta.zst`: compressed source sequence shards.
|
| 208 |
+
- `metadata/*.records.jsonl`: source metadata records.
|
| 209 |
+
- `_MANIFEST.json`: source sequence manifest.
|
| 210 |
+
- `_POSTPROCESS_MANIFEST.json`: table-generation manifest.
|
| 211 |
+
- `dataset_summary.json`: summary of the default index build.
|
| 212 |
+
- `scripts/prepare_uniprotkb_dataset.py`: script used to generate the default index.
|
| 213 |
|
| 214 |
## License
|
| 215 |
|
|
|
|
| 217 |
|
| 218 |
## Citation
|
| 219 |
|
| 220 |
+
If you use the UniProtKB records, cite UniProt:
|
| 221 |
|
| 222 |
+
The UniProt Consortium. UniProt: the Universal Protein Knowledgebase in 2023. Nucleic Acids Research, 51(D1):D523-D531, 2023.
|
|
|
data/test-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ad09814374b0b7a4a08ced4b9506e1942211af9762888d686d9aad8a0606f74
|
| 3 |
+
size 12040
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b79c8277efcf4c59fc191a9ebda30acaac2ab774e6945db6f7e40b364bdab42
|
| 3 |
+
size 19485
|
dataset_summary.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "LiteFold/UniProtKB",
|
| 3 |
+
"source_sha": "d8eb6d76820f33ce4e3d6bcee582f6b474f3bbd9",
|
| 4 |
+
"viewer_table_scope": "file/table shard index",
|
| 5 |
+
"dataset_id": "uniprotkb",
|
| 6 |
+
"source_count": 3,
|
| 7 |
+
"records_total": 203172274,
|
| 8 |
+
"residues_total": 75747523712,
|
| 9 |
+
"total_sequence_shards": 205,
|
| 10 |
+
"protein_entry_table_shards": 615,
|
| 11 |
+
"index_rows": 830,
|
| 12 |
+
"sequence_shard_rows": 205,
|
| 13 |
+
"sequence_shard_bytes": 46504287641,
|
| 14 |
+
"metadata_records_bytes": 74373082266,
|
| 15 |
+
"protein_entry_table_bytes": 18549213567,
|
| 16 |
+
"protein_entry_split_counts": {
|
| 17 |
+
"test": 20314776,
|
| 18 |
+
"train": 162548965,
|
| 19 |
+
"validation": 20308533
|
| 20 |
+
},
|
| 21 |
+
"splits": {
|
| 22 |
+
"train": 733,
|
| 23 |
+
"test": 97
|
| 24 |
+
},
|
| 25 |
+
"split_strategy": "default index uses deterministic sha256(file_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 26 |
+
"protein_entry_split_strategy": "uniprotkb_exact_sequence_hash_v1",
|
| 27 |
+
"role_counts": {
|
| 28 |
+
"git_attributes": 1,
|
| 29 |
+
"readme": 1,
|
| 30 |
+
"aggregate_manifest": 1,
|
| 31 |
+
"postprocess_manifest": 1,
|
| 32 |
+
"source_manifest": 3,
|
| 33 |
+
"metadata_records": 3,
|
| 34 |
+
"sequence_shard": 205,
|
| 35 |
+
"protein_entry_table_shard": 615
|
| 36 |
+
},
|
| 37 |
+
"source_set_index_counts": {
|
| 38 |
+
"sprot": 6,
|
| 39 |
+
"sprot_varsplic": 6,
|
| 40 |
+
"trembl": 814
|
| 41 |
+
},
|
| 42 |
+
"columns": [
|
| 43 |
+
"file_id",
|
| 44 |
+
"repo_id",
|
| 45 |
+
"source_sha",
|
| 46 |
+
"dataset_id",
|
| 47 |
+
"source_set",
|
| 48 |
+
"source_slug",
|
| 49 |
+
"source_file",
|
| 50 |
+
"path",
|
| 51 |
+
"role",
|
| 52 |
+
"table_split",
|
| 53 |
+
"shard_index",
|
| 54 |
+
"size_bytes",
|
| 55 |
+
"compression",
|
| 56 |
+
"records_in_source",
|
| 57 |
+
"residues_in_source",
|
| 58 |
+
"shards_in_source",
|
| 59 |
+
"records_in_table_split",
|
| 60 |
+
"records_total",
|
| 61 |
+
"residues_total",
|
| 62 |
+
"total_sequence_shards",
|
| 63 |
+
"is_sequence_shard",
|
| 64 |
+
"is_table_shard",
|
| 65 |
+
"is_metadata_records",
|
| 66 |
+
"download_pattern",
|
| 67 |
+
"access_note",
|
| 68 |
+
"split_bucket"
|
| 69 |
+
]
|
| 70 |
+
}
|
metadata/source_files.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d69339351bc5098075c828e72cb58eb90206744e2106e7f11bbcb6eed4eff7e8
|
| 3 |
+
size 20213
|
scripts/prepare_uniprotkb_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"""Build a viewer-friendly default file/table index for LiteFold/UniProtKB."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import re
|
| 11 |
+
import shutil
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from typing import Any
|
| 14 |
+
|
| 15 |
+
import pyarrow as pa
|
| 16 |
+
import pyarrow.parquet as pq
|
| 17 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
INDEX_COLUMNS = [
|
| 21 |
+
"file_id",
|
| 22 |
+
"repo_id",
|
| 23 |
+
"source_sha",
|
| 24 |
+
"dataset_id",
|
| 25 |
+
"source_set",
|
| 26 |
+
"source_slug",
|
| 27 |
+
"source_file",
|
| 28 |
+
"path",
|
| 29 |
+
"role",
|
| 30 |
+
"table_split",
|
| 31 |
+
"shard_index",
|
| 32 |
+
"size_bytes",
|
| 33 |
+
"compression",
|
| 34 |
+
"records_in_source",
|
| 35 |
+
"residues_in_source",
|
| 36 |
+
"shards_in_source",
|
| 37 |
+
"records_in_table_split",
|
| 38 |
+
"records_total",
|
| 39 |
+
"residues_total",
|
| 40 |
+
"total_sequence_shards",
|
| 41 |
+
"is_sequence_shard",
|
| 42 |
+
"is_table_shard",
|
| 43 |
+
"is_metadata_records",
|
| 44 |
+
"download_pattern",
|
| 45 |
+
"access_note",
|
| 46 |
+
"split_bucket",
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
SCHEMA = pa.schema(
|
| 51 |
+
[
|
| 52 |
+
pa.field("file_id", pa.string()),
|
| 53 |
+
pa.field("repo_id", pa.string()),
|
| 54 |
+
pa.field("source_sha", pa.string()),
|
| 55 |
+
pa.field("dataset_id", pa.string()),
|
| 56 |
+
pa.field("source_set", pa.string()),
|
| 57 |
+
pa.field("source_slug", pa.string()),
|
| 58 |
+
pa.field("source_file", pa.string()),
|
| 59 |
+
pa.field("path", pa.string()),
|
| 60 |
+
pa.field("role", pa.string()),
|
| 61 |
+
pa.field("table_split", pa.string()),
|
| 62 |
+
pa.field("shard_index", pa.int64()),
|
| 63 |
+
pa.field("size_bytes", pa.int64()),
|
| 64 |
+
pa.field("compression", pa.string()),
|
| 65 |
+
pa.field("records_in_source", pa.int64()),
|
| 66 |
+
pa.field("residues_in_source", pa.int64()),
|
| 67 |
+
pa.field("shards_in_source", pa.int64()),
|
| 68 |
+
pa.field("records_in_table_split", pa.int64()),
|
| 69 |
+
pa.field("records_total", pa.int64()),
|
| 70 |
+
pa.field("residues_total", pa.int64()),
|
| 71 |
+
pa.field("total_sequence_shards", pa.int64()),
|
| 72 |
+
pa.field("is_sequence_shard", pa.bool_()),
|
| 73 |
+
pa.field("is_table_shard", pa.bool_()),
|
| 74 |
+
pa.field("is_metadata_records", pa.bool_()),
|
| 75 |
+
pa.field("download_pattern", pa.string()),
|
| 76 |
+
pa.field("access_note", pa.string()),
|
| 77 |
+
pa.field("split_bucket", pa.int64()),
|
| 78 |
+
]
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
SOURCE_SET_BY_SLUG = {
|
| 83 |
+
"sequence_uniprotkb_uniprot_sprot.fasta.gz": "sprot",
|
| 84 |
+
"sequence_uniprotkb_uniprot_sprot_varsplic.fasta.gz": "sprot_varsplic",
|
| 85 |
+
"sequence_uniprotkb_uniprot_trembl.fasta.gz": "trembl",
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def load_token() -> str | None:
|
| 90 |
+
for key in ("HF_TOKEN", "HUGGINGFACE_HUB_TOKEN"):
|
| 91 |
+
value = os.environ.get(key)
|
| 92 |
+
if value:
|
| 93 |
+
return value
|
| 94 |
+
env_path = Path(".env")
|
| 95 |
+
if env_path.exists():
|
| 96 |
+
for line in env_path.read_text().splitlines():
|
| 97 |
+
stripped = line.strip()
|
| 98 |
+
if not stripped or stripped.startswith("#") or "=" not in stripped:
|
| 99 |
+
continue
|
| 100 |
+
key, value = stripped.split("=", 1)
|
| 101 |
+
if key.strip() in {"HF_TOKEN", "HUGGINGFACE_HUB_TOKEN"}:
|
| 102 |
+
value = value.strip().strip('"').strip("'")
|
| 103 |
+
if value:
|
| 104 |
+
return value
|
| 105 |
+
return None
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def stable_bucket(value: str, buckets: int = 10) -> int:
|
| 109 |
+
digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
|
| 110 |
+
return int(digest, 16) % buckets
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def parse_path(path: str) -> dict[str, Any]:
|
| 114 |
+
table_match = re.search(r"tables/source_set=([^/]+)/split=([^/]+)/protein_entries_shard-(\d+)\.jsonl\.gz$", path)
|
| 115 |
+
if table_match:
|
| 116 |
+
return {
|
| 117 |
+
"role": "protein_entry_table_shard",
|
| 118 |
+
"source_set": table_match.group(1),
|
| 119 |
+
"table_split": table_match.group(2),
|
| 120 |
+
"source_slug": None,
|
| 121 |
+
"shard_index": int(table_match.group(3)),
|
| 122 |
+
"is_sequence_shard": False,
|
| 123 |
+
"is_table_shard": True,
|
| 124 |
+
"is_metadata_records": False,
|
| 125 |
+
}
|
| 126 |
+
sequence_match = re.search(r"sequences/([^/]+)/shard-(\d+)\.fasta\.zst$", path)
|
| 127 |
+
if sequence_match:
|
| 128 |
+
source_slug = sequence_match.group(1)
|
| 129 |
+
return {
|
| 130 |
+
"role": "sequence_shard",
|
| 131 |
+
"source_set": SOURCE_SET_BY_SLUG.get(source_slug),
|
| 132 |
+
"table_split": None,
|
| 133 |
+
"source_slug": source_slug,
|
| 134 |
+
"shard_index": int(sequence_match.group(2)),
|
| 135 |
+
"is_sequence_shard": True,
|
| 136 |
+
"is_table_shard": False,
|
| 137 |
+
"is_metadata_records": False,
|
| 138 |
+
}
|
| 139 |
+
metadata_match = re.search(r"metadata/(.+)\.records\.jsonl$", path)
|
| 140 |
+
if metadata_match:
|
| 141 |
+
source_slug = metadata_match.group(1)
|
| 142 |
+
return {
|
| 143 |
+
"role": "metadata_records",
|
| 144 |
+
"source_set": SOURCE_SET_BY_SLUG.get(source_slug),
|
| 145 |
+
"table_split": None,
|
| 146 |
+
"source_slug": source_slug,
|
| 147 |
+
"shard_index": None,
|
| 148 |
+
"is_sequence_shard": False,
|
| 149 |
+
"is_table_shard": False,
|
| 150 |
+
"is_metadata_records": True,
|
| 151 |
+
}
|
| 152 |
+
manifest_match = re.search(r"manifests/(.+)\.json$", path)
|
| 153 |
+
if manifest_match:
|
| 154 |
+
source_slug = manifest_match.group(1)
|
| 155 |
+
return {
|
| 156 |
+
"role": "source_manifest",
|
| 157 |
+
"source_set": SOURCE_SET_BY_SLUG.get(source_slug),
|
| 158 |
+
"table_split": None,
|
| 159 |
+
"source_slug": source_slug,
|
| 160 |
+
"shard_index": None,
|
| 161 |
+
"is_sequence_shard": False,
|
| 162 |
+
"is_table_shard": False,
|
| 163 |
+
"is_metadata_records": False,
|
| 164 |
+
}
|
| 165 |
+
role = {
|
| 166 |
+
"_MANIFEST.json": "aggregate_manifest",
|
| 167 |
+
"_POSTPROCESS_MANIFEST.json": "postprocess_manifest",
|
| 168 |
+
"README.md": "readme",
|
| 169 |
+
".gitattributes": "git_attributes",
|
| 170 |
+
}.get(path, "other")
|
| 171 |
+
return {
|
| 172 |
+
"role": role,
|
| 173 |
+
"source_set": None,
|
| 174 |
+
"table_split": None,
|
| 175 |
+
"source_slug": None,
|
| 176 |
+
"shard_index": None,
|
| 177 |
+
"is_sequence_shard": False,
|
| 178 |
+
"is_table_shard": False,
|
| 179 |
+
"is_metadata_records": False,
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def compression_for_path(path: str) -> str | None:
|
| 184 |
+
if path.endswith(".fasta.zst"):
|
| 185 |
+
return "zstd"
|
| 186 |
+
if path.endswith(".jsonl.gz"):
|
| 187 |
+
return "gzip"
|
| 188 |
+
return None
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def build_dataset(repo_id: str, raw_dir: Path, out_dir: Path) -> dict[str, Any]:
|
| 192 |
+
token = load_token()
|
| 193 |
+
api = HfApi(token=token)
|
| 194 |
+
info = api.dataset_info(repo_id, files_metadata=True)
|
| 195 |
+
raw_dir.mkdir(parents=True, exist_ok=True)
|
| 196 |
+
manifest_path = Path(
|
| 197 |
+
hf_hub_download(repo_id=repo_id, repo_type="dataset", filename="_MANIFEST.json", local_dir=raw_dir, token=token)
|
| 198 |
+
)
|
| 199 |
+
postprocess_path = Path(
|
| 200 |
+
hf_hub_download(
|
| 201 |
+
repo_id=repo_id,
|
| 202 |
+
repo_type="dataset",
|
| 203 |
+
filename="_POSTPROCESS_MANIFEST.json",
|
| 204 |
+
local_dir=raw_dir,
|
| 205 |
+
token=token,
|
| 206 |
+
)
|
| 207 |
+
)
|
| 208 |
+
manifest = json.loads(manifest_path.read_text())
|
| 209 |
+
postprocess = json.loads(postprocess_path.read_text())
|
| 210 |
+
|
| 211 |
+
dataset_id = str(manifest["dataset_id"])
|
| 212 |
+
total_records = int(manifest["total_records"])
|
| 213 |
+
total_residues = int(manifest["total_residues"])
|
| 214 |
+
total_sequence_shards = int(manifest["total_shards"])
|
| 215 |
+
sources_by_slug = {source["source_slug"]: source for source in manifest["sources"]}
|
| 216 |
+
post_by_source_set = {source["source_set"]: source for source in postprocess["sources"]}
|
| 217 |
+
|
| 218 |
+
rows = []
|
| 219 |
+
for sibling in sorted(info.siblings or [], key=lambda item: item.rfilename):
|
| 220 |
+
path = sibling.rfilename
|
| 221 |
+
if path.startswith("data/") or path.startswith("dataset_summary") or path.startswith("scripts/"):
|
| 222 |
+
continue
|
| 223 |
+
parsed = parse_path(path)
|
| 224 |
+
source_slug = parsed["source_slug"]
|
| 225 |
+
source_set = parsed["source_set"]
|
| 226 |
+
if source_slug is None and source_set:
|
| 227 |
+
post_source = post_by_source_set.get(source_set)
|
| 228 |
+
if post_source:
|
| 229 |
+
source_slug = post_source["source_slug"]
|
| 230 |
+
source = sources_by_slug.get(source_slug or "")
|
| 231 |
+
post_source = post_by_source_set.get(source_set or "")
|
| 232 |
+
table_split = parsed["table_split"]
|
| 233 |
+
file_id = path
|
| 234 |
+
rows.append(
|
| 235 |
+
{
|
| 236 |
+
"file_id": file_id,
|
| 237 |
+
"repo_id": repo_id,
|
| 238 |
+
"source_sha": info.sha,
|
| 239 |
+
"dataset_id": dataset_id,
|
| 240 |
+
"source_set": source_set,
|
| 241 |
+
"source_slug": source_slug,
|
| 242 |
+
"source_file": source.get("source_file") if source else (post_source.get("source_file") if post_source else None),
|
| 243 |
+
"path": path,
|
| 244 |
+
"role": parsed["role"],
|
| 245 |
+
"table_split": table_split,
|
| 246 |
+
"shard_index": parsed["shard_index"],
|
| 247 |
+
"size_bytes": int(getattr(sibling, "size", 0) or 0),
|
| 248 |
+
"compression": compression_for_path(path),
|
| 249 |
+
"records_in_source": int(source["records"]) if source else (int(post_source["records_written"]) if post_source else None),
|
| 250 |
+
"residues_in_source": int(source["residues"]) if source else None,
|
| 251 |
+
"shards_in_source": int(source["shards"]) if source else None,
|
| 252 |
+
"records_in_table_split": int(post_source["split_counts"][table_split])
|
| 253 |
+
if post_source and table_split
|
| 254 |
+
else None,
|
| 255 |
+
"records_total": total_records,
|
| 256 |
+
"residues_total": total_residues,
|
| 257 |
+
"total_sequence_shards": total_sequence_shards,
|
| 258 |
+
"is_sequence_shard": parsed["is_sequence_shard"],
|
| 259 |
+
"is_table_shard": parsed["is_table_shard"],
|
| 260 |
+
"is_metadata_records": parsed["is_metadata_records"],
|
| 261 |
+
"download_pattern": f"tables/source_set={source_set}/split={table_split}/*.jsonl.gz"
|
| 262 |
+
if parsed["is_table_shard"]
|
| 263 |
+
else (f"sequences/{source_slug}/shard-*.fasta.zst" if parsed["is_sequence_shard"] else path),
|
| 264 |
+
"access_note": "Default index over UniProtKB files. Load configs sprot, sprot_varsplic, or trembl for protein-entry rows.",
|
| 265 |
+
"split_bucket": stable_bucket(file_id),
|
| 266 |
+
}
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
if out_dir.exists():
|
| 270 |
+
shutil.rmtree(out_dir)
|
| 271 |
+
data_dir = out_dir / "data"
|
| 272 |
+
metadata_dir = out_dir / "metadata"
|
| 273 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 274 |
+
metadata_dir.mkdir(parents=True, exist_ok=True)
|
| 275 |
+
|
| 276 |
+
train_rows = sorted((row for row in rows if row["split_bucket"] != 0), key=lambda row: row["path"])
|
| 277 |
+
test_rows = sorted((row for row in rows if row["split_bucket"] == 0), key=lambda row: row["path"])
|
| 278 |
+
pq.write_table(pa.Table.from_pylist(train_rows, schema=SCHEMA), data_dir / "train-00000-of-00001.parquet", compression="zstd")
|
| 279 |
+
pq.write_table(pa.Table.from_pylist(test_rows, schema=SCHEMA), data_dir / "test-00000-of-00001.parquet", compression="zstd")
|
| 280 |
+
pq.write_table(pa.Table.from_pylist(rows, schema=SCHEMA), metadata_dir / "source_files.parquet", compression="zstd")
|
| 281 |
+
|
| 282 |
+
role_counts: dict[str, int] = {}
|
| 283 |
+
source_set_counts: dict[str, int] = {}
|
| 284 |
+
for row in rows:
|
| 285 |
+
role_counts[row["role"]] = role_counts.get(row["role"], 0) + 1
|
| 286 |
+
if row["source_set"]:
|
| 287 |
+
source_set_counts[row["source_set"]] = source_set_counts.get(row["source_set"], 0) + 1
|
| 288 |
+
|
| 289 |
+
sequence_bytes = sum(int(row["size_bytes"]) for row in rows if row["is_sequence_shard"])
|
| 290 |
+
metadata_bytes = sum(int(row["size_bytes"]) for row in rows if row["is_metadata_records"])
|
| 291 |
+
table_bytes = sum(int(row["size_bytes"]) for row in rows if row["is_table_shard"])
|
| 292 |
+
summary = {
|
| 293 |
+
"source": repo_id,
|
| 294 |
+
"source_sha": info.sha,
|
| 295 |
+
"viewer_table_scope": "file/table shard index",
|
| 296 |
+
"dataset_id": dataset_id,
|
| 297 |
+
"source_count": int(manifest["source_count"]),
|
| 298 |
+
"records_total": total_records,
|
| 299 |
+
"residues_total": total_residues,
|
| 300 |
+
"total_sequence_shards": total_sequence_shards,
|
| 301 |
+
"protein_entry_table_shards": sum(1 for row in rows if row["is_table_shard"]),
|
| 302 |
+
"index_rows": len(rows),
|
| 303 |
+
"sequence_shard_rows": sum(1 for row in rows if row["is_sequence_shard"]),
|
| 304 |
+
"sequence_shard_bytes": sequence_bytes,
|
| 305 |
+
"metadata_records_bytes": metadata_bytes,
|
| 306 |
+
"protein_entry_table_bytes": table_bytes,
|
| 307 |
+
"protein_entry_split_counts": postprocess["split_counts"],
|
| 308 |
+
"splits": {"train": len(train_rows), "test": len(test_rows)},
|
| 309 |
+
"split_strategy": "default index uses deterministic sha256(file_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 310 |
+
"protein_entry_split_strategy": postprocess["split_version"],
|
| 311 |
+
"role_counts": role_counts,
|
| 312 |
+
"source_set_index_counts": source_set_counts,
|
| 313 |
+
"columns": INDEX_COLUMNS,
|
| 314 |
+
}
|
| 315 |
+
(out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
| 316 |
+
return summary
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def main() -> None:
|
| 320 |
+
parser = argparse.ArgumentParser()
|
| 321 |
+
parser.add_argument("--repo-id", default="LiteFold/UniProtKB")
|
| 322 |
+
parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_UniProtKB_raw"))
|
| 323 |
+
parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_UniProtKB_processed"))
|
| 324 |
+
args = parser.parse_args()
|
| 325 |
+
summary = build_dataset(args.repo_id, args.raw_dir, args.out_dir)
|
| 326 |
+
print(json.dumps(summary, indent=2))
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
main()
|