Add viewer-friendly GOA Parquet sample and source manifest
Browse files- README.md +148 -0
- data/test-00000-of-00001.parquet +3 -0
- data/train-00000-of-00001.parquet +3 -0
- dataset_summary.json +116 -0
- metadata/source_files.parquet +3 -0
- scripts/prepare_goa_dataset.py +253 -0
README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: Gene Ontology Annotation UniProt Sample
|
| 3 |
+
license: other
|
| 4 |
+
tags:
|
| 5 |
+
- biology
|
| 6 |
+
- gene-ontology
|
| 7 |
+
- goa
|
| 8 |
+
- uniprot
|
| 9 |
+
- protein-annotation
|
| 10 |
+
- gaf
|
| 11 |
+
- gpa
|
| 12 |
+
- parquet
|
| 13 |
+
configs:
|
| 14 |
+
- config_name: default
|
| 15 |
+
data_files:
|
| 16 |
+
- split: train
|
| 17 |
+
path: data/train-*.parquet
|
| 18 |
+
- split: test
|
| 19 |
+
path: data/test-*.parquet
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# Gene Ontology Annotation UniProt
|
| 23 |
+
|
| 24 |
+
This dataset contains the original GOA UniProt source files plus a viewer-friendly Parquet sample/index table. The source `goa_uniprot_all.gaf.gz` and `goa_uniprot_all.gpa.gz` files are very large, so the default Dataset Viewer table contains the first 50,000 parsed annotation rows from each source file, along with a source-file manifest in `metadata/source_files.parquet`.
|
| 25 |
+
|
| 26 |
+
Use the original compressed files for complete GOA coverage. Use the default Parquet table for quick inspection, schema discovery, examples, and Dataset Viewer previews.
|
| 27 |
+
|
| 28 |
+
## Splits
|
| 29 |
+
|
| 30 |
+
The split is deterministic by `annotation_id`: `sha256(annotation_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
|
| 31 |
+
|
| 32 |
+
| Split | Rows |
|
| 33 |
+
|---|---:|
|
| 34 |
+
| train | 89,958 |
|
| 35 |
+
| test | 10,042 |
|
| 36 |
+
| total | 100,000 |
|
| 37 |
+
|
| 38 |
+
## Source Files
|
| 39 |
+
|
| 40 |
+
| File | Size |
|
| 41 |
+
|---|---:|
|
| 42 |
+
| `goa_uniprot_all.gaf.gz` | 15,387,303,487 bytes |
|
| 43 |
+
| `goa_uniprot_all.gpa.gz` | 9,462,421,263 bytes |
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
pip install datasets
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Load the viewer table:
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
from datasets import load_dataset
|
| 55 |
+
|
| 56 |
+
ds = load_dataset("LiteFold/GOA")
|
| 57 |
+
print(ds)
|
| 58 |
+
print(ds["train"][0])
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
Load one split:
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
from datasets import load_dataset
|
| 65 |
+
|
| 66 |
+
train = load_dataset("LiteFold/GOA", split="train")
|
| 67 |
+
test = load_dataset("LiteFold/GOA", split="test")
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
Stream rows:
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
from datasets import load_dataset
|
| 74 |
+
|
| 75 |
+
stream = load_dataset("LiteFold/GOA", split="train", streaming=True)
|
| 76 |
+
for row in stream.take(5):
|
| 77 |
+
print(row["db_object_id"], row["go_id"], row["evidence_code"])
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
Filter the sample for molecular-function GAF rows:
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
from datasets import load_dataset
|
| 84 |
+
|
| 85 |
+
ds = load_dataset("LiteFold/GOA", split="train")
|
| 86 |
+
mf = ds.filter(lambda row: row["source_format"] == "GAF" and row["aspect"] == "F")
|
| 87 |
+
print(mf[0])
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
Download the source manifest:
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
import pandas as pd
|
| 94 |
+
from huggingface_hub import hf_hub_download
|
| 95 |
+
|
| 96 |
+
path = hf_hub_download(
|
| 97 |
+
repo_id="LiteFold/GOA",
|
| 98 |
+
repo_type="dataset",
|
| 99 |
+
filename="metadata/source_files.parquet",
|
| 100 |
+
)
|
| 101 |
+
source_files = pd.read_parquet(path)
|
| 102 |
+
print(source_files)
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Download the full raw files when needed:
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
from huggingface_hub import hf_hub_download
|
| 109 |
+
|
| 110 |
+
gaf_path = hf_hub_download(
|
| 111 |
+
repo_id="LiteFold/GOA",
|
| 112 |
+
repo_type="dataset",
|
| 113 |
+
filename="goa_uniprot_all.gaf.gz",
|
| 114 |
+
)
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Columns
|
| 118 |
+
|
| 119 |
+
| Column | Description |
|
| 120 |
+
|---|---|
|
| 121 |
+
| `annotation_id` | Stable SHA-256 ID for the sampled annotation row. |
|
| 122 |
+
| `source_file` | Source file: GAF or GPA. |
|
| 123 |
+
| `source_format` | Parsed source format, `GAF` or `GPA`. |
|
| 124 |
+
| `source_row_number` | Row number within the source annotation stream. |
|
| 125 |
+
| `db` | Source database. |
|
| 126 |
+
| `db_object_id` | Annotated object identifier. |
|
| 127 |
+
| `db_object_symbol` | GAF object symbol, when available. |
|
| 128 |
+
| `qualifier` | Raw qualifier field. |
|
| 129 |
+
| `qualifiers` | Qualifier field split on `|`. |
|
| 130 |
+
| `go_id` | GO identifier. |
|
| 131 |
+
| `db_references` | References split on `|`. |
|
| 132 |
+
| `evidence_code` | GO or ECO evidence code. |
|
| 133 |
+
| `with_from` | With/from field split on `|`. |
|
| 134 |
+
| `aspect` | GAF aspect: `F`, `P`, or `C`; missing for GPA rows. |
|
| 135 |
+
| `db_object_name` | GAF object name, when available. |
|
| 136 |
+
| `db_object_synonyms` | GAF synonyms split on `|`. |
|
| 137 |
+
| `db_object_type` | GAF object type, when available. |
|
| 138 |
+
| `taxon_ids` | GAF taxon IDs split on `|`. |
|
| 139 |
+
| `interacting_taxon_id` | GPA interacting taxon ID, when available. |
|
| 140 |
+
| `date` | Annotation date. |
|
| 141 |
+
| `assigned_by` | Annotation provider. |
|
| 142 |
+
| `annotation_extension` | Annotation extension field. |
|
| 143 |
+
| `gene_product_form_id` | Gene product form identifier. |
|
| 144 |
+
| `split_bucket` | Deterministic split bucket from `sha256(annotation_id) % 10`. |
|
| 145 |
+
|
| 146 |
+
## Preparation
|
| 147 |
+
|
| 148 |
+
The normalization script used to create the Parquet files is included at `scripts/prepare_goa_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:27cb6f509ee3fbe8bb400914ce823a7c0d2ffd3ff13600f630b3f860c15fb269
|
| 3 |
+
size 722964
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f4dc08f8b26284d39f626c77d238250c7fbeb2fa7ab6d1c25081c39a63216228
|
| 3 |
+
size 4944988
|
dataset_summary.json
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "LiteFold/GOA",
|
| 3 |
+
"source_sha": "653d63a17c44418628790e65f3253cccec8f37f8",
|
| 4 |
+
"viewer_table_scope": "sample/index",
|
| 5 |
+
"sample_rows_per_annotation_file": 50000,
|
| 6 |
+
"annotation_sample_rows": 100000,
|
| 7 |
+
"splits": {
|
| 8 |
+
"train": 89958,
|
| 9 |
+
"test": 10042
|
| 10 |
+
},
|
| 11 |
+
"split_strategy": "deterministic sha256(annotation_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 12 |
+
"source_files": [
|
| 13 |
+
{
|
| 14 |
+
"repo_id": "LiteFold/GOA",
|
| 15 |
+
"filename": ".gitattributes",
|
| 16 |
+
"size_bytes": 2504,
|
| 17 |
+
"source_sha": "653d63a17c44418628790e65f3253cccec8f37f8"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"repo_id": "LiteFold/GOA",
|
| 21 |
+
"filename": "goa_uniprot_all.gaf.gz",
|
| 22 |
+
"size_bytes": 15387303487,
|
| 23 |
+
"source_sha": "653d63a17c44418628790e65f3253cccec8f37f8"
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"repo_id": "LiteFold/GOA",
|
| 27 |
+
"filename": "goa_uniprot_all.gpa.gz",
|
| 28 |
+
"size_bytes": 9462421263,
|
| 29 |
+
"source_sha": "653d63a17c44418628790e65f3253cccec8f37f8"
|
| 30 |
+
}
|
| 31 |
+
],
|
| 32 |
+
"source_metadata": [
|
| 33 |
+
{
|
| 34 |
+
"filename": "goa_uniprot_all.gaf.gz",
|
| 35 |
+
"sampled_rows": 50000,
|
| 36 |
+
"header_metadata": {
|
| 37 |
+
"gaf-version": "2.2",
|
| 38 |
+
"date-generated": "2026-04-10 11:33",
|
| 39 |
+
"generated-by": "UniProt",
|
| 40 |
+
"go-version": "http://purl.obolibrary.org/obo/go/releases/2026-04-06/extensions/go-plus.ofn"
|
| 41 |
+
}
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"filename": "goa_uniprot_all.gpa.gz",
|
| 45 |
+
"sampled_rows": 50000,
|
| 46 |
+
"header_metadata": {
|
| 47 |
+
"gpa-version": "1.1",
|
| 48 |
+
"Columns": "",
|
| 49 |
+
"DB": "Reference(s) required 1 or greater 6",
|
| 50 |
+
"Generated": "2026-04-10 14:56",
|
| 51 |
+
"GO-version": "http://purl.obolibrary.org/obo/go/releases/2026-04-06/extensions/go-plus.ofn"
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"format_counts": {
|
| 56 |
+
"GAF": 50000,
|
| 57 |
+
"GPA": 50000
|
| 58 |
+
},
|
| 59 |
+
"aspect_counts": {
|
| 60 |
+
"missing": 50000,
|
| 61 |
+
"F": 21511,
|
| 62 |
+
"P": 15246,
|
| 63 |
+
"C": 13243
|
| 64 |
+
},
|
| 65 |
+
"top_evidence_codes": {
|
| 66 |
+
"IEA": 49621,
|
| 67 |
+
"ECO:0000265": 25858,
|
| 68 |
+
"ECO:0007826": 23687,
|
| 69 |
+
"ECO:0000314": 387,
|
| 70 |
+
"IBA": 297,
|
| 71 |
+
"ISS": 26,
|
| 72 |
+
"ECO:0000250": 23,
|
| 73 |
+
"ECO:0000305": 19,
|
| 74 |
+
"IDA": 13,
|
| 75 |
+
"ECO:0000315": 13,
|
| 76 |
+
"IPI": 11,
|
| 77 |
+
"IMP": 9,
|
| 78 |
+
"HDA": 7,
|
| 79 |
+
"ECO:0000303": 6,
|
| 80 |
+
"ND": 5,
|
| 81 |
+
"EXP": 3,
|
| 82 |
+
"ECO:0000304": 3,
|
| 83 |
+
"ISM": 3,
|
| 84 |
+
"ISA": 2,
|
| 85 |
+
"ECO:0000266": 2
|
| 86 |
+
},
|
| 87 |
+
"db_counts": {
|
| 88 |
+
"UniProtKB": 100000
|
| 89 |
+
},
|
| 90 |
+
"columns": [
|
| 91 |
+
"annotation_id",
|
| 92 |
+
"source_file",
|
| 93 |
+
"source_format",
|
| 94 |
+
"source_row_number",
|
| 95 |
+
"db",
|
| 96 |
+
"db_object_id",
|
| 97 |
+
"db_object_symbol",
|
| 98 |
+
"qualifier",
|
| 99 |
+
"qualifiers",
|
| 100 |
+
"go_id",
|
| 101 |
+
"db_references",
|
| 102 |
+
"evidence_code",
|
| 103 |
+
"with_from",
|
| 104 |
+
"aspect",
|
| 105 |
+
"db_object_name",
|
| 106 |
+
"db_object_synonyms",
|
| 107 |
+
"db_object_type",
|
| 108 |
+
"taxon_ids",
|
| 109 |
+
"interacting_taxon_id",
|
| 110 |
+
"date",
|
| 111 |
+
"assigned_by",
|
| 112 |
+
"annotation_extension",
|
| 113 |
+
"gene_product_form_id",
|
| 114 |
+
"split_bucket"
|
| 115 |
+
]
|
| 116 |
+
}
|
metadata/source_files.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b2bf2a687c6614e31c3559ba5224654915d39af67cbf41f2c31bf3bcf097b78f
|
| 3 |
+
size 3119
|
scripts/prepare_goa_dataset.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build viewer-friendly sample/index Parquet splits for LiteFold/GOA."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import gzip
|
| 8 |
+
import hashlib
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
import shutil
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from typing import Any
|
| 14 |
+
|
| 15 |
+
import pandas as pd
|
| 16 |
+
import requests
|
| 17 |
+
from huggingface_hub import HfApi, hf_hub_url
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
ANNOTATION_COLUMNS = [
|
| 21 |
+
"annotation_id",
|
| 22 |
+
"source_file",
|
| 23 |
+
"source_format",
|
| 24 |
+
"source_row_number",
|
| 25 |
+
"db",
|
| 26 |
+
"db_object_id",
|
| 27 |
+
"db_object_symbol",
|
| 28 |
+
"qualifier",
|
| 29 |
+
"qualifiers",
|
| 30 |
+
"go_id",
|
| 31 |
+
"db_references",
|
| 32 |
+
"evidence_code",
|
| 33 |
+
"with_from",
|
| 34 |
+
"aspect",
|
| 35 |
+
"db_object_name",
|
| 36 |
+
"db_object_synonyms",
|
| 37 |
+
"db_object_type",
|
| 38 |
+
"taxon_ids",
|
| 39 |
+
"interacting_taxon_id",
|
| 40 |
+
"date",
|
| 41 |
+
"assigned_by",
|
| 42 |
+
"annotation_extension",
|
| 43 |
+
"gene_product_form_id",
|
| 44 |
+
"split_bucket",
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def load_token() -> str | None:
|
| 49 |
+
for key in ("HF_TOKEN", "HUGGINGFACE_HUB_TOKEN"):
|
| 50 |
+
value = os.environ.get(key)
|
| 51 |
+
if value:
|
| 52 |
+
return value
|
| 53 |
+
env_path = Path(".env")
|
| 54 |
+
if env_path.exists():
|
| 55 |
+
for line in env_path.read_text().splitlines():
|
| 56 |
+
stripped = line.strip()
|
| 57 |
+
if not stripped or stripped.startswith("#") or "=" not in stripped:
|
| 58 |
+
continue
|
| 59 |
+
key, value = stripped.split("=", 1)
|
| 60 |
+
if key.strip() in {"HF_TOKEN", "HUGGINGFACE_HUB_TOKEN"}:
|
| 61 |
+
value = value.strip().strip('"').strip("'")
|
| 62 |
+
if value:
|
| 63 |
+
return value
|
| 64 |
+
return None
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def stable_bucket(value: str, buckets: int = 10) -> int:
|
| 68 |
+
digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
|
| 69 |
+
return int(digest, 16) % buckets
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def split_pipe(value: str | None) -> list[str]:
|
| 73 |
+
if not value:
|
| 74 |
+
return []
|
| 75 |
+
return [part for part in value.split("|") if part]
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def make_annotation_id(parts: list[str], source_file: str, row_number: int) -> str:
|
| 79 |
+
seed = "|".join([source_file, str(row_number), *parts])
|
| 80 |
+
return hashlib.sha256(seed.encode("utf-8")).hexdigest()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def parse_gaf(parts: list[str], source_file: str, row_number: int) -> dict[str, Any] | None:
|
| 84 |
+
if len(parts) < 17:
|
| 85 |
+
return None
|
| 86 |
+
annotation_id = make_annotation_id(parts, source_file, row_number)
|
| 87 |
+
return {
|
| 88 |
+
"annotation_id": annotation_id,
|
| 89 |
+
"source_file": source_file,
|
| 90 |
+
"source_format": "GAF",
|
| 91 |
+
"source_row_number": row_number,
|
| 92 |
+
"db": parts[0],
|
| 93 |
+
"db_object_id": parts[1],
|
| 94 |
+
"db_object_symbol": parts[2],
|
| 95 |
+
"qualifier": parts[3] or None,
|
| 96 |
+
"qualifiers": split_pipe(parts[3]),
|
| 97 |
+
"go_id": parts[4],
|
| 98 |
+
"db_references": split_pipe(parts[5]),
|
| 99 |
+
"evidence_code": parts[6],
|
| 100 |
+
"with_from": split_pipe(parts[7]),
|
| 101 |
+
"aspect": parts[8] or None,
|
| 102 |
+
"db_object_name": parts[9] or None,
|
| 103 |
+
"db_object_synonyms": split_pipe(parts[10]),
|
| 104 |
+
"db_object_type": parts[11] or None,
|
| 105 |
+
"taxon_ids": split_pipe(parts[12]),
|
| 106 |
+
"interacting_taxon_id": None,
|
| 107 |
+
"date": parts[13] or None,
|
| 108 |
+
"assigned_by": parts[14] or None,
|
| 109 |
+
"annotation_extension": parts[15] or None,
|
| 110 |
+
"gene_product_form_id": parts[16] or None,
|
| 111 |
+
"split_bucket": stable_bucket(annotation_id),
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def parse_gpa(parts: list[str], source_file: str, row_number: int) -> dict[str, Any] | None:
|
| 116 |
+
if len(parts) < 12:
|
| 117 |
+
return None
|
| 118 |
+
annotation_id = make_annotation_id(parts, source_file, row_number)
|
| 119 |
+
return {
|
| 120 |
+
"annotation_id": annotation_id,
|
| 121 |
+
"source_file": source_file,
|
| 122 |
+
"source_format": "GPA",
|
| 123 |
+
"source_row_number": row_number,
|
| 124 |
+
"db": parts[0],
|
| 125 |
+
"db_object_id": parts[1],
|
| 126 |
+
"db_object_symbol": None,
|
| 127 |
+
"qualifier": parts[2] or None,
|
| 128 |
+
"qualifiers": split_pipe(parts[2]),
|
| 129 |
+
"go_id": parts[3],
|
| 130 |
+
"db_references": split_pipe(parts[4]),
|
| 131 |
+
"evidence_code": parts[5],
|
| 132 |
+
"with_from": split_pipe(parts[6]),
|
| 133 |
+
"aspect": None,
|
| 134 |
+
"db_object_name": None,
|
| 135 |
+
"db_object_synonyms": [],
|
| 136 |
+
"db_object_type": None,
|
| 137 |
+
"taxon_ids": [],
|
| 138 |
+
"interacting_taxon_id": parts[7] or None,
|
| 139 |
+
"date": parts[8] or None,
|
| 140 |
+
"assigned_by": parts[9] or None,
|
| 141 |
+
"annotation_extension": parts[10] or None,
|
| 142 |
+
"gene_product_form_id": parts[11] or None,
|
| 143 |
+
"split_bucket": stable_bucket(annotation_id),
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def stream_rows(repo_id: str, filename: str, token: str | None, limit: int) -> tuple[list[dict[str, Any]], dict[str, str]]:
|
| 148 |
+
url = hf_hub_url(repo_id=repo_id, filename=filename, repo_type="dataset")
|
| 149 |
+
headers = {"Authorization": f"Bearer {token}"} if token else {}
|
| 150 |
+
rows: list[dict[str, Any]] = []
|
| 151 |
+
metadata: dict[str, str] = {}
|
| 152 |
+
row_number = 0
|
| 153 |
+
parser = parse_gaf if filename.endswith(".gaf.gz") else parse_gpa
|
| 154 |
+
|
| 155 |
+
with requests.get(url, headers=headers, stream=True, timeout=60) as response:
|
| 156 |
+
response.raise_for_status()
|
| 157 |
+
with gzip.GzipFile(fileobj=response.raw) as handle:
|
| 158 |
+
for raw in handle:
|
| 159 |
+
line = raw.decode("utf-8", errors="replace").rstrip("\n")
|
| 160 |
+
if not line:
|
| 161 |
+
continue
|
| 162 |
+
if line.startswith("!"):
|
| 163 |
+
if ":" in line:
|
| 164 |
+
key, value = line.lstrip("!").split(":", 1)
|
| 165 |
+
metadata[key.strip()] = value.strip()
|
| 166 |
+
continue
|
| 167 |
+
if line.startswith("gpa-version:"):
|
| 168 |
+
metadata["gpa-version"] = line.split(":", 1)[1].strip()
|
| 169 |
+
continue
|
| 170 |
+
row_number += 1
|
| 171 |
+
parsed = parser(line.split("\t"), filename, row_number)
|
| 172 |
+
if parsed is not None:
|
| 173 |
+
rows.append(parsed)
|
| 174 |
+
if len(rows) >= limit:
|
| 175 |
+
break
|
| 176 |
+
return rows, metadata
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def build_dataset(repo_id: str, out_dir: Path, sample_rows_per_file: int) -> dict[str, Any]:
|
| 180 |
+
token = load_token()
|
| 181 |
+
api = HfApi(token=token)
|
| 182 |
+
info = api.dataset_info(repo_id, files_metadata=True)
|
| 183 |
+
|
| 184 |
+
source_files = []
|
| 185 |
+
for sibling in sorted(info.siblings or [], key=lambda item: item.rfilename):
|
| 186 |
+
source_files.append(
|
| 187 |
+
{
|
| 188 |
+
"repo_id": repo_id,
|
| 189 |
+
"filename": sibling.rfilename,
|
| 190 |
+
"size_bytes": int(getattr(sibling, "size", 0) or 0),
|
| 191 |
+
"source_sha": info.sha,
|
| 192 |
+
}
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
annotation_rows: list[dict[str, Any]] = []
|
| 196 |
+
source_metadata: list[dict[str, Any]] = []
|
| 197 |
+
for filename in ["goa_uniprot_all.gaf.gz", "goa_uniprot_all.gpa.gz"]:
|
| 198 |
+
rows, metadata = stream_rows(repo_id, filename, token, sample_rows_per_file)
|
| 199 |
+
annotation_rows.extend(rows)
|
| 200 |
+
source_metadata.append({"filename": filename, "sampled_rows": len(rows), "header_metadata": metadata})
|
| 201 |
+
|
| 202 |
+
if out_dir.exists():
|
| 203 |
+
shutil.rmtree(out_dir)
|
| 204 |
+
data_dir = out_dir / "data"
|
| 205 |
+
metadata_dir = out_dir / "metadata"
|
| 206 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 207 |
+
metadata_dir.mkdir(parents=True, exist_ok=True)
|
| 208 |
+
|
| 209 |
+
df = pd.DataFrame.from_records(annotation_rows, columns=ANNOTATION_COLUMNS)
|
| 210 |
+
df = df.sort_values(["split_bucket", "annotation_id"], kind="mergesort")
|
| 211 |
+
train = df[df["split_bucket"].ne(0)].sort_values("annotation_id", kind="mergesort")
|
| 212 |
+
test = df[df["split_bucket"].eq(0)].sort_values("annotation_id", kind="mergesort")
|
| 213 |
+
train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
|
| 214 |
+
test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
|
| 215 |
+
|
| 216 |
+
pd.DataFrame.from_records(source_files).to_parquet(metadata_dir / "source_files.parquet", index=False)
|
| 217 |
+
|
| 218 |
+
format_counts = df["source_format"].value_counts().to_dict()
|
| 219 |
+
aspect_counts = df["aspect"].fillna("missing").value_counts().to_dict()
|
| 220 |
+
evidence_counts = df["evidence_code"].value_counts().head(20).to_dict()
|
| 221 |
+
db_counts = df["db"].value_counts().to_dict()
|
| 222 |
+
summary = {
|
| 223 |
+
"source": repo_id,
|
| 224 |
+
"source_sha": info.sha,
|
| 225 |
+
"viewer_table_scope": "sample/index",
|
| 226 |
+
"sample_rows_per_annotation_file": int(sample_rows_per_file),
|
| 227 |
+
"annotation_sample_rows": int(len(df)),
|
| 228 |
+
"splits": {"train": int(len(train)), "test": int(len(test))},
|
| 229 |
+
"split_strategy": "deterministic sha256(annotation_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 230 |
+
"source_files": source_files,
|
| 231 |
+
"source_metadata": source_metadata,
|
| 232 |
+
"format_counts": {str(k): int(v) for k, v in format_counts.items()},
|
| 233 |
+
"aspect_counts": {str(k): int(v) for k, v in aspect_counts.items()},
|
| 234 |
+
"top_evidence_codes": {str(k): int(v) for k, v in evidence_counts.items()},
|
| 235 |
+
"db_counts": {str(k): int(v) for k, v in db_counts.items()},
|
| 236 |
+
"columns": ANNOTATION_COLUMNS,
|
| 237 |
+
}
|
| 238 |
+
(out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
| 239 |
+
return summary
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def main() -> None:
|
| 243 |
+
parser = argparse.ArgumentParser()
|
| 244 |
+
parser.add_argument("--repo-id", default="LiteFold/GOA")
|
| 245 |
+
parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_GOA_processed"))
|
| 246 |
+
parser.add_argument("--sample-rows-per-file", type=int, default=50000)
|
| 247 |
+
args = parser.parse_args()
|
| 248 |
+
summary = build_dataset(args.repo_id, args.out_dir, args.sample_rows_per_file)
|
| 249 |
+
print(json.dumps(summary, indent=2))
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
if __name__ == "__main__":
|
| 253 |
+
main()
|