anindya64 commited on
Commit
ce01506
·
verified ·
1 Parent(s): ea4b663

Use JSONL default file index for UniProtKB

Browse files
README.md CHANGED
@@ -17,16 +17,16 @@ tags:
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
@@ -66,7 +66,7 @@ configs:
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.
@@ -183,13 +183,13 @@ print(trembl_train_shards[0]["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. |
@@ -202,7 +202,7 @@ print(trembl_train_shards[0]["path"])
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.
 
17
  - protein-sequences
18
  - bioinformatics
19
  - train-validation-test-split
20
+ - jsonl
21
  configs:
22
  - config_name: default
23
  data_files:
24
  - split: train
25
  path:
26
+ - data/train-*.jsonl.gz
27
  - split: test
28
  path:
29
+ - data/test-*.jsonl.gz
30
  - config_name: sprot
31
  data_files:
32
  - split: train
 
66
 
67
  This repository contains two useful views of LiteFold/UniProtKB:
68
 
69
+ - `default`: a compact JSONL 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.
 
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, otherwise `-1`. |
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, otherwise `-1`. |
190
+ | `residues_in_source` | int64 | Residues in the source set, otherwise `-1`. |
191
+ | `shards_in_source` | int64 | Number of sequence shards in the source set, otherwise `-1`. |
192
+ | `records_in_table_split` | int64 | Protein records in that source set and split, otherwise `-1`. |
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. |
 
202
 
203
  ## Files
204
 
205
+ - `data/*.jsonl.gz`: 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.
data/{test-00000-of-00001.parquet → test-00000-of-00001.jsonl.gz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1ad09814374b0b7a4a08ced4b9506e1942211af9762888d686d9aad8a0606f74
3
- size 12040
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:76211f31cb7fd7946490c46d8bb51e6d6482af1718c509c3fa682637f2a29904
3
+ size 2870
data/{train-00000-of-00001.parquet → train-00000-of-00001.jsonl.gz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4b79c8277efcf4c59fc191a9ebda30acaac2ab774e6945db6f7e40b364bdab42
3
- size 19485
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8dee44ac9b822c1ea04309b67b7fe5c179cf70108befc8282819f462a5be40be
3
+ size 15807
dataset_summary.json CHANGED
@@ -1,7 +1,8 @@
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,
 
1
  {
2
  "source": "LiteFold/UniProtKB",
3
+ "source_sha": "ea4b6633410d5e2158cdb0b97fdcabd70bce3c27",
4
  "viewer_table_scope": "file/table shard index",
5
+ "data_format": "jsonl.gz",
6
  "dataset_id": "uniprotkb",
7
  "source_count": 3,
8
  "records_total": 203172274,
metadata/{source_files.parquet → source_files.jsonl.gz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d69339351bc5098075c828e72cb58eb90206744e2106e7f11bbcb6eed4eff7e8
3
- size 20213
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab93f039e7f37d0157a47ff2c0d839240edc7372f882a34d4c66d7ed6b8cebc2
3
+ size 17700
scripts/prepare_uniprotkb_dataset.py CHANGED
@@ -4,6 +4,7 @@
4
  from __future__ import annotations
5
 
6
  import argparse
 
7
  import hashlib
8
  import json
9
  import os
@@ -12,8 +13,6 @@ 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
 
@@ -47,36 +46,34 @@ INDEX_COLUMNS = [
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 = {
@@ -188,6 +185,24 @@ def compression_for_path(path: str) -> str | None:
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)
@@ -218,7 +233,12 @@ def build_dataset(repo_id: str, raw_dir: Path, out_dir: Path) -> dict[str, Any]:
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"]
@@ -275,9 +295,9 @@ def build_dataset(repo_id: str, raw_dir: Path, out_dir: Path) -> dict[str, Any]:
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] = {}
@@ -293,6 +313,7 @@ def build_dataset(repo_id: str, raw_dir: Path, out_dir: Path) -> dict[str, Any]:
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,
 
4
  from __future__ import annotations
5
 
6
  import argparse
7
+ import gzip
8
  import hashlib
9
  import json
10
  import os
 
13
  from pathlib import Path
14
  from typing import Any
15
 
 
 
16
  from huggingface_hub import HfApi, hf_hub_download
17
 
18
 
 
46
  ]
47
 
48
 
49
+ STRING_COLUMNS = {
50
+ "file_id",
51
+ "repo_id",
52
+ "source_sha",
53
+ "dataset_id",
54
+ "source_set",
55
+ "source_slug",
56
+ "source_file",
57
+ "path",
58
+ "role",
59
+ "table_split",
60
+ "compression",
61
+ "download_pattern",
62
+ "access_note",
63
+ }
64
+
65
+ INT_COLUMNS = {
66
+ "shard_index",
67
+ "size_bytes",
68
+ "records_in_source",
69
+ "residues_in_source",
70
+ "shards_in_source",
71
+ "records_in_table_split",
72
+ "records_total",
73
+ "residues_total",
74
+ "total_sequence_shards",
75
+ "split_bucket",
76
+ }
 
 
77
 
78
 
79
  SOURCE_SET_BY_SLUG = {
 
185
  return None
186
 
187
 
188
+ def viewer_row(row: dict[str, Any]) -> dict[str, Any]:
189
+ stable = {}
190
+ for column in INDEX_COLUMNS:
191
+ value = row.get(column)
192
+ if value is None and column in STRING_COLUMNS:
193
+ value = ""
194
+ elif value is None and column in INT_COLUMNS:
195
+ value = -1
196
+ stable[column] = value
197
+ return stable
198
+
199
+
200
+ def write_jsonl_gz(path: Path, rows: list[dict[str, Any]]) -> None:
201
+ with gzip.open(path, "wt", encoding="utf-8") as handle:
202
+ for row in rows:
203
+ handle.write(json.dumps(viewer_row(row), sort_keys=True, separators=(",", ":")) + "\n")
204
+
205
+
206
  def build_dataset(repo_id: str, raw_dir: Path, out_dir: Path) -> dict[str, Any]:
207
  token = load_token()
208
  api = HfApi(token=token)
 
233
  rows = []
234
  for sibling in sorted(info.siblings or [], key=lambda item: item.rfilename):
235
  path = sibling.rfilename
236
+ if (
237
+ path.startswith("data/")
238
+ or path.startswith("dataset_summary")
239
+ or path.startswith("scripts/")
240
+ or path.startswith("metadata/source_files.")
241
+ ):
242
  continue
243
  parsed = parse_path(path)
244
  source_slug = parsed["source_slug"]
 
295
 
296
  train_rows = sorted((row for row in rows if row["split_bucket"] != 0), key=lambda row: row["path"])
297
  test_rows = sorted((row for row in rows if row["split_bucket"] == 0), key=lambda row: row["path"])
298
+ write_jsonl_gz(data_dir / "train-00000-of-00001.jsonl.gz", train_rows)
299
+ write_jsonl_gz(data_dir / "test-00000-of-00001.jsonl.gz", test_rows)
300
+ write_jsonl_gz(metadata_dir / "source_files.jsonl.gz", sorted(rows, key=lambda row: row["path"]))
301
 
302
  role_counts: dict[str, int] = {}
303
  source_set_counts: dict[str, int] = {}
 
313
  "source": repo_id,
314
  "source_sha": info.sha,
315
  "viewer_table_scope": "file/table shard index",
316
+ "data_format": "jsonl.gz",
317
  "dataset_id": dataset_id,
318
  "source_count": int(manifest["source_count"]),
319
  "records_total": total_records,