anindya64 commited on
Commit
5241ffa
·
verified ·
1 Parent(s): 45f6d1f

Add normalized Parquet train/test UniRef50 shard index

Browse files
README.md CHANGED
@@ -1,97 +1,126 @@
1
  ---
 
2
  license: cc-by-4.0
3
- pretty_name: UniRef50
4
- size_categories:
5
- - 10M<n<100M
6
- task_categories:
7
- - other
8
- language:
9
- - en
10
  tags:
11
- - biology
12
- - proteins
13
- - sequences
14
- - fasta
15
- - uniref
16
- - clustering
 
 
 
 
 
 
 
 
17
  ---
18
 
19
- # UniRef50
20
 
21
- Normalized FASTA shards of UniRef50 cluster representative sequences (50% sequence identity threshold).
22
 
23
- Processed and uploaded by the [MegaData](https://github.com/) post-download pipeline
24
- (internal repo). Original source: <https://www.uniprot.org/help/uniref>.
25
 
26
- ## Statistics
27
 
28
- | | |
29
- |---|---|
30
- | Source files | 1 |
31
- | Shards | 61 |
32
- | Compressed shard bytes | 10.74 GiB (11,527,890,402) |
33
- | Records (per-source manifest sum) | 60,315,044 |
34
- | Residues (per-source manifest sum) | 17,282,055,793 |
35
- | Aggregate manifest `total_records` | 60315044 |
 
36
 
37
- ## Layout
 
 
 
 
 
 
38
 
 
 
 
 
39
  ```
40
- .
41
- ├── _MANIFEST.json # aggregate manifest written by the pipeline
42
- ├── manifests/<source_slug>.json # per-source manifest (records, residues, shards)
43
- ├── metadata/<source_slug>.records.jsonl # per-record provenance
44
- └── sequences/<source_slug>/shard-NNNNNN.fasta.zst
 
 
 
 
45
  ```
46
 
47
- `<source_slug>` corresponds 1:1 with an upstream source archive; e.g.
48
- `sequence_uniprotkb_uniprot_sprot.fasta.gz`.
49
 
50
- ## Loading
 
 
 
 
 
51
 
52
- Stream every shard of one source (replace `<source_slug>` with the directory of
53
- interest under `sequences/`):
 
 
 
 
 
 
 
 
 
54
 
55
  ```bash
56
  hf download LiteFold/UniRef50 --repo-type dataset \
57
- --include 'sequences/<source_slug>/shard-*.fasta.zst' \
58
  --local-dir ./uniref50
59
- zstd -dc ./uniref50/sequences/<source_slug>/shard-*.fasta.zst | head
60
  ```
61
 
62
- Programmatic streaming with [`zstandard`](https://pypi.org/project/zstandard/):
63
 
64
  ```python
65
- from huggingface_hub import snapshot_download
66
  from pathlib import Path
67
  import zstandard as zstd
68
 
69
- local = snapshot_download(
70
- repo_id="LiteFold/UniRef50",
71
- repo_type="dataset",
72
- allow_patterns=["sequences/*/shard-*.fasta.zst"],
73
- )
74
-
75
  dctx = zstd.ZstdDecompressor()
76
- for shard in sorted(Path(local).rglob("shard-*.fasta.zst")):
77
- with shard.open("rb") as f, dctx.stream_reader(f) as reader:
78
- buf = b""
79
- while chunk := reader.read(1 << 20):
80
- buf += chunk
81
- *lines, buf = buf.split(b"\n")
82
- for line in lines:
83
- ... # naive splitter; swap in your FASTA parser
84
  ```
85
 
86
- ## License
87
 
88
- CC BY 4.0 (UniProt Consortium).
89
-
90
- ## Citation
91
-
92
- > Suzek BE, Wang Y, Huang H, McGarvey PB, Wu CH; UniProt Consortium. UniRef clusters: a comprehensive and scalable alternative for improving sequence similarity searches. Bioinformatics, 31(6):926-32, 2015.
93
-
94
- ## Provenance
95
-
96
- Built from the local manifest entry `uniref50` of `manifests/atlas_download_plan.json`.
97
- Pipeline source: `megadata-post normalize --dataset uniref50`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pretty_name: UniRef50 Shard Index
3
  license: cc-by-4.0
 
 
 
 
 
 
 
4
  tags:
5
+ - biology
6
+ - proteins
7
+ - sequences
8
+ - fasta
9
+ - uniref
10
+ - clustering
11
+ - parquet
12
+ configs:
13
+ - config_name: default
14
+ data_files:
15
+ - split: train
16
+ path: data/train-*.parquet
17
+ - split: test
18
+ path: data/test-*.parquet
19
  ---
20
 
21
+ # UniRef50 Shard Index
22
 
23
+ This dataset contains the original UniRef50 FASTA shards plus a viewer-friendly file/shard index. The full sequence data is stored as 61 `.fasta.zst` shards and the per-record metadata JSONL is very large, so the default Dataset Viewer table indexes repository files instead of expanding all 60,315,044 sequence records.
24
 
25
+ Use the original `sequences/.../shard-*.fasta.zst` files for complete FASTA records. Use the default Parquet table for Dataset Viewer previews, source discovery, file sizes, and download patterns.
 
26
 
27
+ ## Splits
28
 
29
+ The split is deterministic by file ID: `sha256(file_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
30
+
31
+ | Split | Rows |
32
+ |---|---:|
33
+ | train | 60 |
34
+ | test | 6 |
35
+ | total | 66 |
36
+
37
+ ## Source Statistics
38
 
39
+ | Field | Value |
40
+ |---|---:|
41
+ | UniRef50 records | 60,315,044 |
42
+ | Residues | 17,282,055,793 |
43
+ | Sequence shards | 61 |
44
+ | Compressed sequence shard bytes | 11,527,890,402 |
45
+ | Metadata JSONL bytes | 20,952,410,229 |
46
 
47
+ ## Usage
48
+
49
+ ```bash
50
+ pip install datasets
51
  ```
52
+
53
+ Load the shard index:
54
+
55
+ ```python
56
+ from datasets import load_dataset
57
+
58
+ ds = load_dataset("LiteFold/UniRef50")
59
+ print(ds)
60
+ print(ds["train"][0])
61
  ```
62
 
63
+ Load one split:
 
64
 
65
+ ```python
66
+ from datasets import load_dataset
67
+
68
+ train = load_dataset("LiteFold/UniRef50", split="train")
69
+ test = load_dataset("LiteFold/UniRef50", split="test")
70
+ ```
71
 
72
+ List sequence shards:
73
+
74
+ ```python
75
+ from datasets import load_dataset
76
+
77
+ index = load_dataset("LiteFold/UniRef50", split="train")
78
+ shards = index.filter(lambda row: row["is_sequence_shard"])
79
+ print(shards[0]["path"])
80
+ ```
81
+
82
+ Download sequence shards:
83
 
84
  ```bash
85
  hf download LiteFold/UniRef50 --repo-type dataset \
86
+ --include 'sequences/sequence_uniref50_uniref50.fasta.gz/shard-*.fasta.zst' \
87
  --local-dir ./uniref50
 
88
  ```
89
 
90
+ Stream a downloaded shard with Python:
91
 
92
  ```python
 
93
  from pathlib import Path
94
  import zstandard as zstd
95
 
96
+ shard = next(Path("./uniref50").rglob("shard-*.fasta.zst"))
 
 
 
 
 
97
  dctx = zstd.ZstdDecompressor()
98
+ with shard.open("rb") as f, dctx.stream_reader(f) as reader:
99
+ print(reader.read(1024).decode("utf-8", errors="replace"))
 
 
 
 
 
 
100
  ```
101
 
102
+ ## Columns
103
 
104
+ | Column | Description |
105
+ |---|---|
106
+ | `file_id` | Stable row ID, equal to the repository path. |
107
+ | `repo_id` | Hugging Face dataset repository. |
108
+ | `source_sha` | Source repository commit used to build the index. |
109
+ | `source_slug` | Source slug from the original pipeline manifest. |
110
+ | `path` | File path in the repository. |
111
+ | `role` | File role, such as `sequence_shard`, `metadata_records`, or `source_manifest`. |
112
+ | `shard_index` | Numeric shard index for sequence shards. |
113
+ | `size_bytes` | File size in bytes. |
114
+ | `compression` | Compression format, when applicable. |
115
+ | `records_total` | Total UniRef50 records from the manifest. |
116
+ | `residues_total` | Total residue count from the manifest. |
117
+ | `total_shards` | Total sequence shard count. |
118
+ | `is_sequence_shard` | Whether the row points to a FASTA shard. |
119
+ | `is_metadata_records` | Whether the row points to the per-record metadata JSONL. |
120
+ | `download_pattern` | Recommended path or glob for downloading. |
121
+ | `access_note` | Note describing the index scope. |
122
+ | `split_bucket` | Deterministic split bucket from `sha256(file_id) % 10`. |
123
+
124
+ ## Preparation
125
+
126
+ The normalization script used to create the Parquet files is included at `scripts/prepare_uniref50_dataset.py`.
data/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1808c2d557216240386f8ed9a2ca0ae387d91d6efd2a6835fdab7b6d75565d3
3
+ size 12024
data/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5da513a8582a409da3851d079324345aebc337ebd351673e691cc32659c1b460
3
+ size 12890
dataset_summary.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source": "LiteFold/UniRef50",
3
+ "source_sha": "45f6d1f6eb68c847f89b719d7f1da3e7fa9e6611",
4
+ "viewer_table_scope": "file/shard index",
5
+ "source_slug": "sequence_uniref50_uniref50.fasta.gz",
6
+ "records_total": 60315044,
7
+ "residues_total": 17282055793,
8
+ "total_shards": 61,
9
+ "index_rows": 66,
10
+ "sequence_shard_rows": 61,
11
+ "sequence_shard_bytes": 11527890402,
12
+ "metadata_records_bytes": 20952410229,
13
+ "splits": {
14
+ "train": 60,
15
+ "test": 6
16
+ },
17
+ "split_strategy": "deterministic sha256(file_id) % 10; bucket 0 is test, buckets 1-9 are train",
18
+ "role_counts": {
19
+ "sequence_shard": 61,
20
+ "git_attributes": 1,
21
+ "readme": 1,
22
+ "aggregate_manifest": 1,
23
+ "source_manifest": 1,
24
+ "metadata_records": 1
25
+ },
26
+ "columns": [
27
+ "file_id",
28
+ "repo_id",
29
+ "source_sha",
30
+ "source_slug",
31
+ "path",
32
+ "role",
33
+ "shard_index",
34
+ "size_bytes",
35
+ "compression",
36
+ "records_total",
37
+ "residues_total",
38
+ "total_shards",
39
+ "is_sequence_shard",
40
+ "is_metadata_records",
41
+ "download_pattern",
42
+ "access_note",
43
+ "split_bucket"
44
+ ]
45
+ }
metadata/source_files.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b52a47516fb4ecfb44e002f618a132219e9c2b9d26fb14e78cf21044e32321a
3
+ size 13100
scripts/prepare_uniref50_dataset.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Build viewer-friendly file/shard index Parquet splits for LiteFold/UniRef50."""
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 pandas as pd
16
+ from huggingface_hub import HfApi, hf_hub_download
17
+
18
+
19
+ INDEX_COLUMNS = [
20
+ "file_id",
21
+ "repo_id",
22
+ "source_sha",
23
+ "source_slug",
24
+ "path",
25
+ "role",
26
+ "shard_index",
27
+ "size_bytes",
28
+ "compression",
29
+ "records_total",
30
+ "residues_total",
31
+ "total_shards",
32
+ "is_sequence_shard",
33
+ "is_metadata_records",
34
+ "download_pattern",
35
+ "access_note",
36
+ "split_bucket",
37
+ ]
38
+
39
+
40
+ def load_token() -> str | None:
41
+ for key in ("HF_TOKEN", "HUGGINGFACE_HUB_TOKEN"):
42
+ value = os.environ.get(key)
43
+ if value:
44
+ return value
45
+ env_path = Path(".env")
46
+ if env_path.exists():
47
+ for line in env_path.read_text().splitlines():
48
+ stripped = line.strip()
49
+ if not stripped or stripped.startswith("#") or "=" not in stripped:
50
+ continue
51
+ key, value = stripped.split("=", 1)
52
+ if key.strip() in {"HF_TOKEN", "HUGGINGFACE_HUB_TOKEN"}:
53
+ value = value.strip().strip('"').strip("'")
54
+ if value:
55
+ return value
56
+ return None
57
+
58
+
59
+ def stable_bucket(value: str, buckets: int = 10) -> int:
60
+ digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
61
+ return int(digest, 16) % buckets
62
+
63
+
64
+ def role_for_path(path: str) -> tuple[str, str | None, int | None, bool, bool]:
65
+ shard_match = re.search(r"sequences/([^/]+)/shard-(\d+)\.fasta\.zst$", path)
66
+ if shard_match:
67
+ return "sequence_shard", shard_match.group(1), int(shard_match.group(2)), True, False
68
+ metadata_match = re.search(r"metadata/(.+)\.records\.jsonl$", path)
69
+ if metadata_match:
70
+ return "metadata_records", metadata_match.group(1), None, False, True
71
+ manifest_match = re.search(r"manifests/(.+)\.json$", path)
72
+ if manifest_match:
73
+ return "source_manifest", manifest_match.group(1), None, False, False
74
+ if path == "_MANIFEST.json":
75
+ return "aggregate_manifest", None, None, False, False
76
+ if path == "README.md":
77
+ return "readme", None, None, False, False
78
+ if path == ".gitattributes":
79
+ return "git_attributes", None, None, False, False
80
+ return "other", None, None, False, False
81
+
82
+
83
+ def compression_for_path(path: str) -> str | None:
84
+ if path.endswith(".fasta.zst"):
85
+ return "zstd"
86
+ return None
87
+
88
+
89
+ def build_dataset(repo_id: str, raw_dir: Path, out_dir: Path) -> dict[str, Any]:
90
+ token = load_token()
91
+ api = HfApi(token=token)
92
+ info = api.dataset_info(repo_id, files_metadata=True)
93
+ raw_dir.mkdir(parents=True, exist_ok=True)
94
+ manifest_path = Path(
95
+ hf_hub_download(
96
+ repo_id=repo_id,
97
+ repo_type="dataset",
98
+ filename="_MANIFEST.json",
99
+ local_dir=raw_dir,
100
+ token=token,
101
+ )
102
+ )
103
+ manifest = json.loads(manifest_path.read_text())
104
+ source = manifest["sources"][0]
105
+ source_slug = source["source_slug"]
106
+ records_total = int(source["records"])
107
+ residues_total = int(source["residues"])
108
+ total_shards = int(source["shards"])
109
+
110
+ rows = []
111
+ for sibling in sorted(info.siblings or [], key=lambda item: item.rfilename):
112
+ path = sibling.rfilename
113
+ role, inferred_slug, shard_index, is_sequence_shard, is_metadata_records = role_for_path(path)
114
+ file_id = path
115
+ rows.append(
116
+ {
117
+ "file_id": file_id,
118
+ "repo_id": repo_id,
119
+ "source_sha": info.sha,
120
+ "source_slug": inferred_slug or source_slug,
121
+ "path": path,
122
+ "role": role,
123
+ "shard_index": shard_index,
124
+ "size_bytes": int(getattr(sibling, "size", 0) or 0),
125
+ "compression": compression_for_path(path),
126
+ "records_total": records_total,
127
+ "residues_total": residues_total,
128
+ "total_shards": total_shards,
129
+ "is_sequence_shard": is_sequence_shard,
130
+ "is_metadata_records": is_metadata_records,
131
+ "download_pattern": f"sequences/{source_slug}/shard-*.fasta.zst"
132
+ if is_sequence_shard
133
+ else path,
134
+ "access_note": "File/shard index for UniRef50; download sequence shards for FASTA records.",
135
+ "split_bucket": stable_bucket(file_id),
136
+ }
137
+ )
138
+
139
+ if out_dir.exists():
140
+ shutil.rmtree(out_dir)
141
+ data_dir = out_dir / "data"
142
+ metadata_dir = out_dir / "metadata"
143
+ data_dir.mkdir(parents=True, exist_ok=True)
144
+ metadata_dir.mkdir(parents=True, exist_ok=True)
145
+
146
+ df = pd.DataFrame.from_records(rows, columns=INDEX_COLUMNS)
147
+ train = df[df["split_bucket"].ne(0)].sort_values("path", kind="mergesort")
148
+ test = df[df["split_bucket"].eq(0)].sort_values("path", kind="mergesort")
149
+ train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
150
+ test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
151
+ df.to_parquet(metadata_dir / "source_files.parquet", index=False, compression="zstd")
152
+
153
+ sequence_bytes = int(df[df["is_sequence_shard"]]["size_bytes"].sum())
154
+ metadata_bytes = int(df[df["is_metadata_records"]]["size_bytes"].sum())
155
+ summary = {
156
+ "source": repo_id,
157
+ "source_sha": info.sha,
158
+ "viewer_table_scope": "file/shard index",
159
+ "source_slug": source_slug,
160
+ "records_total": records_total,
161
+ "residues_total": residues_total,
162
+ "total_shards": total_shards,
163
+ "index_rows": int(len(df)),
164
+ "sequence_shard_rows": int(df["is_sequence_shard"].sum()),
165
+ "sequence_shard_bytes": sequence_bytes,
166
+ "metadata_records_bytes": metadata_bytes,
167
+ "splits": {"train": int(len(train)), "test": int(len(test))},
168
+ "split_strategy": "deterministic sha256(file_id) % 10; bucket 0 is test, buckets 1-9 are train",
169
+ "role_counts": {str(k): int(v) for k, v in df["role"].value_counts().to_dict().items()},
170
+ "columns": INDEX_COLUMNS,
171
+ }
172
+ (out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
173
+ return summary
174
+
175
+
176
+ def main() -> None:
177
+ parser = argparse.ArgumentParser()
178
+ parser.add_argument("--repo-id", default="LiteFold/UniRef50")
179
+ parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_UniRef50_raw"))
180
+ parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_UniRef50_processed"))
181
+ args = parser.parse_args()
182
+ summary = build_dataset(args.repo_id, args.raw_dir, args.out_dir)
183
+ print(json.dumps(summary, indent=2))
184
+
185
+
186
+ if __name__ == "__main__":
187
+ main()