Datasets:
Add normalized Parquet train/test GO term table
Browse files- README.md +159 -0
- data/test-00000-of-00001.parquet +3 -0
- data/train-00000-of-00001.parquet +3 -0
- dataset_summary.json +86 -0
- metadata/typedefs.parquet +3 -0
- scripts/prepare_go_dataset.py +278 -0
README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: Gene Ontology Terms
|
| 3 |
+
license: cc-by-4.0
|
| 4 |
+
tags:
|
| 5 |
+
- biology
|
| 6 |
+
- ontology
|
| 7 |
+
- gene-ontology
|
| 8 |
+
- go
|
| 9 |
+
- obo
|
| 10 |
+
- parquet
|
| 11 |
+
configs:
|
| 12 |
+
- config_name: default
|
| 13 |
+
data_files:
|
| 14 |
+
- split: train
|
| 15 |
+
path: data/train-*.parquet
|
| 16 |
+
- split: test
|
| 17 |
+
path: data/test-*.parquet
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Gene Ontology Terms
|
| 21 |
+
|
| 22 |
+
This dataset contains a viewer-friendly Parquet table derived from the Gene Ontology OBO files in this repository. Each row is one `[Term]` stanza from `go.obo`, with repeated OBO fields stored as list columns.
|
| 23 |
+
|
| 24 |
+
The original source files are preserved in the repository:
|
| 25 |
+
|
| 26 |
+
- `go.obo`
|
| 27 |
+
- `go-basic.obo`
|
| 28 |
+
|
| 29 |
+
`in_go_basic` marks whether a term is also present in `go-basic.obo`. Relationship typedef metadata from `go.obo` is available as `metadata/typedefs.parquet`.
|
| 30 |
+
|
| 31 |
+
## Splits
|
| 32 |
+
|
| 33 |
+
The split is deterministic by GO identifier: `sha256(go_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
|
| 34 |
+
|
| 35 |
+
| Split | Rows |
|
| 36 |
+
|---|---:|
|
| 37 |
+
| train | 43,522 |
|
| 38 |
+
| test | 4,769 |
|
| 39 |
+
| total | 48,291 |
|
| 40 |
+
|
| 41 |
+
## Dataset Statistics
|
| 42 |
+
|
| 43 |
+
| Field | Value |
|
| 44 |
+
|---|---:|
|
| 45 |
+
| GO release | `releases/2026-03-25` |
|
| 46 |
+
| Terms | 48,291 |
|
| 47 |
+
| Typedefs | 11 |
|
| 48 |
+
| Terms in `go-basic.obo` | 48,291 |
|
| 49 |
+
| Active terms | 38,560 |
|
| 50 |
+
| Obsolete terms | 9,731 |
|
| 51 |
+
|
| 52 |
+
| Namespace | Rows |
|
| 53 |
+
|---|---:|
|
| 54 |
+
| biological_process | 30,857 |
|
| 55 |
+
| molecular_function | 12,839 |
|
| 56 |
+
| cellular_component | 4,595 |
|
| 57 |
+
|
| 58 |
+
## Usage
|
| 59 |
+
|
| 60 |
+
Install the Hugging Face Datasets library:
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
pip install datasets
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Load all splits:
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
from datasets import load_dataset
|
| 70 |
+
|
| 71 |
+
ds = load_dataset("LiteFold/GO")
|
| 72 |
+
print(ds)
|
| 73 |
+
|
| 74 |
+
row = ds["train"][0]
|
| 75 |
+
print(row["go_id"], row["name"], row["namespace"])
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
Load one split:
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from datasets import load_dataset
|
| 82 |
+
|
| 83 |
+
train = load_dataset("LiteFold/GO", split="train")
|
| 84 |
+
test = load_dataset("LiteFold/GO", split="test")
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
Stream rows without downloading the full table first:
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
from datasets import load_dataset
|
| 91 |
+
|
| 92 |
+
stream = load_dataset("LiteFold/GO", split="train", streaming=True)
|
| 93 |
+
for row in stream.take(5):
|
| 94 |
+
print(row["go_id"], row["name"])
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
Filter active biological process terms:
|
| 98 |
+
|
| 99 |
+
```python
|
| 100 |
+
from datasets import load_dataset
|
| 101 |
+
|
| 102 |
+
ds = load_dataset("LiteFold/GO", split="train")
|
| 103 |
+
active_bp = ds.filter(
|
| 104 |
+
lambda row: row["namespace"] == "biological_process" and not row["is_obsolete"]
|
| 105 |
+
)
|
| 106 |
+
print(active_bp[0])
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
Load typedef metadata directly:
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
import pandas as pd
|
| 113 |
+
from huggingface_hub import hf_hub_download
|
| 114 |
+
|
| 115 |
+
path = hf_hub_download(
|
| 116 |
+
repo_id="LiteFold/GO",
|
| 117 |
+
repo_type="dataset",
|
| 118 |
+
filename="metadata/typedefs.parquet",
|
| 119 |
+
)
|
| 120 |
+
typedefs = pd.read_parquet(path)
|
| 121 |
+
print(typedefs[["id", "name"]].head())
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## Columns
|
| 125 |
+
|
| 126 |
+
| Column | Description |
|
| 127 |
+
|---|---|
|
| 128 |
+
| `go_id` | GO identifier, such as `GO:0008150`. |
|
| 129 |
+
| `go_numeric_id` | Numeric portion of `go_id`. |
|
| 130 |
+
| `name` | Term name. |
|
| 131 |
+
| `namespace` | GO namespace: `biological_process`, `molecular_function`, or `cellular_component`. |
|
| 132 |
+
| `definition` | Parsed OBO definition text. |
|
| 133 |
+
| `definition_xrefs` | Cross-references attached to the definition. |
|
| 134 |
+
| `comment` | OBO comment text, when present. |
|
| 135 |
+
| `synonyms` | Parsed synonym strings. |
|
| 136 |
+
| `synonym_scopes` | Scope for each synonym, such as `EXACT`, `BROAD`, `NARROW`, or `RELATED`. |
|
| 137 |
+
| `alt_ids` | Alternate GO identifiers. |
|
| 138 |
+
| `subsets` | GO subsets or slims containing the term. |
|
| 139 |
+
| `xrefs` | Term cross-references. |
|
| 140 |
+
| `is_a_ids` | Direct `is_a` parent GO identifiers. |
|
| 141 |
+
| `relationship_edges` | Raw relationship edges with comments removed. |
|
| 142 |
+
| `relationship_types` | Relationship predicates, such as `part_of` or `regulates`. |
|
| 143 |
+
| `relationship_target_ids` | GO identifiers targeted by relationship edges. |
|
| 144 |
+
| `parent_ids` | Combined unique `is_a_ids` and `relationship_target_ids`. |
|
| 145 |
+
| `intersection_of` | Parsed `intersection_of` entries. |
|
| 146 |
+
| `union_of` | Parsed `union_of` entries. |
|
| 147 |
+
| `disjoint_from` | Parsed `disjoint_from` entries. |
|
| 148 |
+
| `replaced_by` | Replacement IDs for obsolete terms. |
|
| 149 |
+
| `consider` | Suggested replacement IDs for obsolete terms. |
|
| 150 |
+
| `property_values` | Raw OBO property values. |
|
| 151 |
+
| `created_by` | Creator metadata, when present. |
|
| 152 |
+
| `creation_date` | Creation date metadata, when present. |
|
| 153 |
+
| `is_obsolete` | Whether the term is obsolete. |
|
| 154 |
+
| `in_go_basic` | Whether the same GO ID appears in `go-basic.obo`. |
|
| 155 |
+
| `split_bucket` | Deterministic split bucket from `sha256(go_id) % 10`. |
|
| 156 |
+
|
| 157 |
+
## Preparation
|
| 158 |
+
|
| 159 |
+
The normalization script used to create the Parquet files is included at `scripts/prepare_go_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:0239e059d99d463f8ee0e045c79095faf2881128e64717e4a48b5622a2a3c591
|
| 3 |
+
size 702871
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2c8058ec1ec4480d707d9c5289641587d45224bcb0e941038a5901089e113165
|
| 3 |
+
size 4906337
|
dataset_summary.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "LiteFold/GO",
|
| 3 |
+
"data_version": "releases/2026-03-25",
|
| 4 |
+
"ontology": "go",
|
| 5 |
+
"license": "terms:license http://creativecommons.org/licenses/by/4.0/",
|
| 6 |
+
"term_rows": 48291,
|
| 7 |
+
"typedef_rows": 11,
|
| 8 |
+
"go_basic_term_rows": 48291,
|
| 9 |
+
"terms_in_go_basic": 48291,
|
| 10 |
+
"splits": {
|
| 11 |
+
"train": 43522,
|
| 12 |
+
"test": 4769
|
| 13 |
+
},
|
| 14 |
+
"split_strategy": "deterministic sha256(go_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 15 |
+
"namespace_counts": {
|
| 16 |
+
"biological_process": 30857,
|
| 17 |
+
"molecular_function": 12839,
|
| 18 |
+
"cellular_component": 4595
|
| 19 |
+
},
|
| 20 |
+
"obsolete_counts": {
|
| 21 |
+
"False": 38560,
|
| 22 |
+
"True": 9731
|
| 23 |
+
},
|
| 24 |
+
"top_relationship_types": {
|
| 25 |
+
"part_of": 7094,
|
| 26 |
+
"regulates": 2975,
|
| 27 |
+
"negatively_regulates": 2656,
|
| 28 |
+
"positively_regulates": 2656,
|
| 29 |
+
"has_part": 807,
|
| 30 |
+
"occurs_in": 174,
|
| 31 |
+
"happens_during": 13,
|
| 32 |
+
"ends_during": 1
|
| 33 |
+
},
|
| 34 |
+
"top_subsets": {
|
| 35 |
+
"gocheck_obsoletion_candidate": 544,
|
| 36 |
+
"gocheck_do_not_annotate": 460,
|
| 37 |
+
"goslim_pir": 426,
|
| 38 |
+
"goslim_synapse": 335,
|
| 39 |
+
"goslim_chembl": 294,
|
| 40 |
+
"goslim_drosophila": 173,
|
| 41 |
+
"goslim_yeast": 155,
|
| 42 |
+
"goslim_generic": 140,
|
| 43 |
+
"goslim_metagenomics": 111,
|
| 44 |
+
"goslim_prokaryote": 97,
|
| 45 |
+
"goslim_plant": 97,
|
| 46 |
+
"goslim_candida": 86,
|
| 47 |
+
"goslim_pombe": 64,
|
| 48 |
+
"goslim_plant_ribbon": 62,
|
| 49 |
+
"goslim_euk_cellular_processes_ribbon": 61,
|
| 50 |
+
"goslim_agr": 53,
|
| 51 |
+
"goslim_prokaryote_ribbon": 49,
|
| 52 |
+
"goslim_mouse": 45,
|
| 53 |
+
"goslim_flybase_ribbon": 44,
|
| 54 |
+
"goslim_virus": 20
|
| 55 |
+
},
|
| 56 |
+
"columns": [
|
| 57 |
+
"go_id",
|
| 58 |
+
"go_numeric_id",
|
| 59 |
+
"name",
|
| 60 |
+
"namespace",
|
| 61 |
+
"definition",
|
| 62 |
+
"definition_xrefs",
|
| 63 |
+
"comment",
|
| 64 |
+
"synonyms",
|
| 65 |
+
"synonym_scopes",
|
| 66 |
+
"alt_ids",
|
| 67 |
+
"subsets",
|
| 68 |
+
"xrefs",
|
| 69 |
+
"is_a_ids",
|
| 70 |
+
"relationship_edges",
|
| 71 |
+
"relationship_types",
|
| 72 |
+
"relationship_target_ids",
|
| 73 |
+
"parent_ids",
|
| 74 |
+
"intersection_of",
|
| 75 |
+
"union_of",
|
| 76 |
+
"disjoint_from",
|
| 77 |
+
"replaced_by",
|
| 78 |
+
"consider",
|
| 79 |
+
"property_values",
|
| 80 |
+
"created_by",
|
| 81 |
+
"creation_date",
|
| 82 |
+
"is_obsolete",
|
| 83 |
+
"in_go_basic",
|
| 84 |
+
"split_bucket"
|
| 85 |
+
]
|
| 86 |
+
}
|
metadata/typedefs.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6ac85cbea48babf83fd7b4c352d225acd3c61699f019d8d44db0cd58a5fb5fda
|
| 3 |
+
size 9479
|
scripts/prepare_go_dataset.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build viewer-friendly Parquet splits for LiteFold/GO."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import re
|
| 10 |
+
from collections import Counter, defaultdict
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import pandas as pd
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
TERM_COLUMNS = [
|
| 17 |
+
"go_id",
|
| 18 |
+
"go_numeric_id",
|
| 19 |
+
"name",
|
| 20 |
+
"namespace",
|
| 21 |
+
"definition",
|
| 22 |
+
"definition_xrefs",
|
| 23 |
+
"comment",
|
| 24 |
+
"synonyms",
|
| 25 |
+
"synonym_scopes",
|
| 26 |
+
"alt_ids",
|
| 27 |
+
"subsets",
|
| 28 |
+
"xrefs",
|
| 29 |
+
"is_a_ids",
|
| 30 |
+
"relationship_edges",
|
| 31 |
+
"relationship_types",
|
| 32 |
+
"relationship_target_ids",
|
| 33 |
+
"parent_ids",
|
| 34 |
+
"intersection_of",
|
| 35 |
+
"union_of",
|
| 36 |
+
"disjoint_from",
|
| 37 |
+
"replaced_by",
|
| 38 |
+
"consider",
|
| 39 |
+
"property_values",
|
| 40 |
+
"created_by",
|
| 41 |
+
"creation_date",
|
| 42 |
+
"is_obsolete",
|
| 43 |
+
"in_go_basic",
|
| 44 |
+
"split_bucket",
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def split_unquoted_comment(value: str) -> str:
|
| 49 |
+
in_quote = False
|
| 50 |
+
escaped = False
|
| 51 |
+
for index, char in enumerate(value):
|
| 52 |
+
if escaped:
|
| 53 |
+
escaped = False
|
| 54 |
+
continue
|
| 55 |
+
if char == "\\":
|
| 56 |
+
escaped = True
|
| 57 |
+
continue
|
| 58 |
+
if char == '"':
|
| 59 |
+
in_quote = not in_quote
|
| 60 |
+
continue
|
| 61 |
+
if char == "!" and not in_quote:
|
| 62 |
+
return value[:index].strip()
|
| 63 |
+
return value.strip()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_quoted_xrefs(value: str) -> tuple[str | None, list[str]]:
|
| 67 |
+
match = re.match(r'^"((?:[^"\\]|\\.)*)"\s*(?:\[(.*)\])?', value.strip())
|
| 68 |
+
if not match:
|
| 69 |
+
return value.strip() or None, []
|
| 70 |
+
text = bytes(match.group(1), "utf-8").decode("unicode_escape")
|
| 71 |
+
xrefs = []
|
| 72 |
+
if match.group(2):
|
| 73 |
+
xrefs = [part.strip() for part in match.group(2).split(",") if part.strip()]
|
| 74 |
+
return text, xrefs
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def parse_synonym(value: str) -> tuple[str | None, str | None]:
|
| 78 |
+
match = re.match(r'^"((?:[^"\\]|\\.)*)"\s+([A-Z]+)', value.strip())
|
| 79 |
+
if not match:
|
| 80 |
+
return value.strip() or None, None
|
| 81 |
+
text = bytes(match.group(1), "utf-8").decode("unicode_escape")
|
| 82 |
+
return text, match.group(2)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def stable_bucket(value: str, buckets: int = 10) -> int:
|
| 86 |
+
digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
|
| 87 |
+
return int(digest, 16) % buckets
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def parse_obo(path: Path) -> tuple[dict[str, list[str]], list[dict[str, list[str]]], list[dict[str, list[str]]]]:
|
| 91 |
+
header: dict[str, list[str]] = defaultdict(list)
|
| 92 |
+
terms: list[dict[str, list[str]]] = []
|
| 93 |
+
typedefs: list[dict[str, list[str]]] = []
|
| 94 |
+
current_type: str | None = None
|
| 95 |
+
current: dict[str, list[str]] | None = None
|
| 96 |
+
|
| 97 |
+
def flush() -> None:
|
| 98 |
+
nonlocal current, current_type
|
| 99 |
+
if current is None:
|
| 100 |
+
return
|
| 101 |
+
if current_type == "Term":
|
| 102 |
+
terms.append(current)
|
| 103 |
+
elif current_type == "Typedef":
|
| 104 |
+
typedefs.append(current)
|
| 105 |
+
current = None
|
| 106 |
+
current_type = None
|
| 107 |
+
|
| 108 |
+
with path.open("r", encoding="utf-8", errors="replace") as handle:
|
| 109 |
+
for raw_line in handle:
|
| 110 |
+
line = raw_line.rstrip("\n")
|
| 111 |
+
if not line or line.startswith("!"):
|
| 112 |
+
continue
|
| 113 |
+
if line.startswith("[") and line.endswith("]"):
|
| 114 |
+
flush()
|
| 115 |
+
current_type = line.strip("[]")
|
| 116 |
+
current = defaultdict(list)
|
| 117 |
+
continue
|
| 118 |
+
if ": " not in line:
|
| 119 |
+
continue
|
| 120 |
+
key, value = line.split(": ", 1)
|
| 121 |
+
target = header if current is None else current
|
| 122 |
+
target[key].append(value.strip())
|
| 123 |
+
flush()
|
| 124 |
+
return dict(header), terms, typedefs
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def first(stanza: dict[str, list[str]], key: str) -> str | None:
|
| 128 |
+
values = stanza.get(key) or []
|
| 129 |
+
return values[0] if values else None
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def list_values(stanza: dict[str, list[str]], key: str, strip_comment: bool = False) -> list[str]:
|
| 133 |
+
values = stanza.get(key) or []
|
| 134 |
+
if strip_comment:
|
| 135 |
+
return [split_unquoted_comment(value) for value in values]
|
| 136 |
+
return list(values)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def term_to_row(stanza: dict[str, list[str]], basic_ids: set[str]) -> dict:
|
| 140 |
+
go_id = first(stanza, "id") or ""
|
| 141 |
+
definition, definition_xrefs = parse_quoted_xrefs(first(stanza, "def") or "")
|
| 142 |
+
synonyms = []
|
| 143 |
+
synonym_scopes = []
|
| 144 |
+
for value in stanza.get("synonym", []):
|
| 145 |
+
synonym, scope = parse_synonym(value)
|
| 146 |
+
if synonym:
|
| 147 |
+
synonyms.append(synonym)
|
| 148 |
+
synonym_scopes.append(scope or "")
|
| 149 |
+
|
| 150 |
+
relationship_edges = list_values(stanza, "relationship", strip_comment=True)
|
| 151 |
+
relationship_types = []
|
| 152 |
+
relationship_target_ids = []
|
| 153 |
+
for edge in relationship_edges:
|
| 154 |
+
parts = edge.split()
|
| 155 |
+
if len(parts) >= 2:
|
| 156 |
+
relationship_types.append(parts[0])
|
| 157 |
+
relationship_target_ids.append(parts[1])
|
| 158 |
+
|
| 159 |
+
is_a_ids = [value.split()[0] for value in list_values(stanza, "is_a", strip_comment=True)]
|
| 160 |
+
parent_ids = sorted(set(is_a_ids + relationship_target_ids))
|
| 161 |
+
split_bucket = stable_bucket(go_id)
|
| 162 |
+
numeric = None
|
| 163 |
+
match = re.match(r"GO:(\d+)$", go_id)
|
| 164 |
+
if match:
|
| 165 |
+
numeric = int(match.group(1))
|
| 166 |
+
|
| 167 |
+
return {
|
| 168 |
+
"go_id": go_id,
|
| 169 |
+
"go_numeric_id": numeric,
|
| 170 |
+
"name": first(stanza, "name"),
|
| 171 |
+
"namespace": first(stanza, "namespace"),
|
| 172 |
+
"definition": definition,
|
| 173 |
+
"definition_xrefs": definition_xrefs,
|
| 174 |
+
"comment": " ".join(stanza.get("comment", [])) or None,
|
| 175 |
+
"synonyms": synonyms,
|
| 176 |
+
"synonym_scopes": synonym_scopes,
|
| 177 |
+
"alt_ids": list_values(stanza, "alt_id"),
|
| 178 |
+
"subsets": list_values(stanza, "subset"),
|
| 179 |
+
"xrefs": list_values(stanza, "xref", strip_comment=True),
|
| 180 |
+
"is_a_ids": is_a_ids,
|
| 181 |
+
"relationship_edges": relationship_edges,
|
| 182 |
+
"relationship_types": relationship_types,
|
| 183 |
+
"relationship_target_ids": relationship_target_ids,
|
| 184 |
+
"parent_ids": parent_ids,
|
| 185 |
+
"intersection_of": list_values(stanza, "intersection_of", strip_comment=True),
|
| 186 |
+
"union_of": list_values(stanza, "union_of", strip_comment=True),
|
| 187 |
+
"disjoint_from": list_values(stanza, "disjoint_from", strip_comment=True),
|
| 188 |
+
"replaced_by": list_values(stanza, "replaced_by", strip_comment=True),
|
| 189 |
+
"consider": list_values(stanza, "consider", strip_comment=True),
|
| 190 |
+
"property_values": list_values(stanza, "property_value"),
|
| 191 |
+
"created_by": first(stanza, "created_by"),
|
| 192 |
+
"creation_date": first(stanza, "creation_date"),
|
| 193 |
+
"is_obsolete": (first(stanza, "is_obsolete") or "").lower() == "true",
|
| 194 |
+
"in_go_basic": go_id in basic_ids,
|
| 195 |
+
"split_bucket": split_bucket,
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def typedef_to_row(stanza: dict[str, list[str]]) -> dict:
|
| 200 |
+
definition, definition_xrefs = parse_quoted_xrefs(first(stanza, "def") or "")
|
| 201 |
+
return {
|
| 202 |
+
"id": first(stanza, "id"),
|
| 203 |
+
"name": first(stanza, "name"),
|
| 204 |
+
"namespace": first(stanza, "namespace"),
|
| 205 |
+
"definition": definition,
|
| 206 |
+
"definition_xrefs": definition_xrefs,
|
| 207 |
+
"is_transitive": first(stanza, "is_transitive"),
|
| 208 |
+
"is_metadata_tag": first(stanza, "is_metadata_tag"),
|
| 209 |
+
"is_class_level": first(stanza, "is_class_level"),
|
| 210 |
+
"domain": list_values(stanza, "domain", strip_comment=True),
|
| 211 |
+
"range": list_values(stanza, "range", strip_comment=True),
|
| 212 |
+
"holds_over_chain": list_values(stanza, "holds_over_chain", strip_comment=True),
|
| 213 |
+
"inverse_of": list_values(stanza, "inverse_of", strip_comment=True),
|
| 214 |
+
"transitive_over": list_values(stanza, "transitive_over", strip_comment=True),
|
| 215 |
+
"property_values": list_values(stanza, "property_value"),
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def build_dataset(raw_dir: Path, out_dir: Path) -> dict:
|
| 220 |
+
header, terms, typedefs = parse_obo(raw_dir / "go.obo")
|
| 221 |
+
_, basic_terms, _ = parse_obo(raw_dir / "go-basic.obo")
|
| 222 |
+
basic_ids = {first(term, "id") for term in basic_terms if first(term, "id")}
|
| 223 |
+
|
| 224 |
+
rows = [term_to_row(term, basic_ids) for term in terms]
|
| 225 |
+
df = pd.DataFrame.from_records(rows, columns=TERM_COLUMNS)
|
| 226 |
+
df = df.sort_values(["split_bucket", "go_id"], kind="mergesort")
|
| 227 |
+
|
| 228 |
+
data_dir = out_dir / "data"
|
| 229 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 230 |
+
train = df[df["split_bucket"].ne(0)].sort_values("go_id", kind="mergesort")
|
| 231 |
+
test = df[df["split_bucket"].eq(0)].sort_values("go_id", kind="mergesort")
|
| 232 |
+
train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
|
| 233 |
+
test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
|
| 234 |
+
|
| 235 |
+
metadata_dir = out_dir / "metadata"
|
| 236 |
+
metadata_dir.mkdir(parents=True, exist_ok=True)
|
| 237 |
+
typedef_df = pd.DataFrame.from_records([typedef_to_row(item) for item in typedefs])
|
| 238 |
+
typedef_df.to_parquet(metadata_dir / "typedefs.parquet", index=False, compression="zstd")
|
| 239 |
+
|
| 240 |
+
namespace_counts = df["namespace"].value_counts(dropna=False).to_dict()
|
| 241 |
+
obsolete_counts = df["is_obsolete"].value_counts(dropna=False).to_dict()
|
| 242 |
+
relation_counts = Counter(rel for rels in df["relationship_types"] for rel in rels)
|
| 243 |
+
subset_counts = Counter(subset for subsets in df["subsets"] for subset in subsets)
|
| 244 |
+
summary = {
|
| 245 |
+
"source": "LiteFold/GO",
|
| 246 |
+
"data_version": (header.get("data-version") or [None])[0],
|
| 247 |
+
"ontology": (header.get("ontology") or [None])[0],
|
| 248 |
+
"license": next((value for value in header.get("property_value", []) if "terms:license" in value), None),
|
| 249 |
+
"term_rows": int(len(df)),
|
| 250 |
+
"typedef_rows": int(len(typedef_df)),
|
| 251 |
+
"go_basic_term_rows": int(len(basic_ids)),
|
| 252 |
+
"terms_in_go_basic": int(df["in_go_basic"].sum()),
|
| 253 |
+
"splits": {
|
| 254 |
+
"train": int(len(train)),
|
| 255 |
+
"test": int(len(test)),
|
| 256 |
+
},
|
| 257 |
+
"split_strategy": "deterministic sha256(go_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 258 |
+
"namespace_counts": {str(k): int(v) for k, v in namespace_counts.items()},
|
| 259 |
+
"obsolete_counts": {str(k): int(v) for k, v in obsolete_counts.items()},
|
| 260 |
+
"top_relationship_types": dict(relation_counts.most_common(20)),
|
| 261 |
+
"top_subsets": dict(subset_counts.most_common(20)),
|
| 262 |
+
"columns": TERM_COLUMNS,
|
| 263 |
+
}
|
| 264 |
+
(out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
| 265 |
+
return summary
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def main() -> None:
|
| 269 |
+
parser = argparse.ArgumentParser()
|
| 270 |
+
parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_GO_raw"))
|
| 271 |
+
parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_GO_processed"))
|
| 272 |
+
args = parser.parse_args()
|
| 273 |
+
summary = build_dataset(args.raw_dir, args.out_dir)
|
| 274 |
+
print(json.dumps(summary, indent=2))
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
if __name__ == "__main__":
|
| 278 |
+
main()
|