Add normalized Parquet train/test DisProt protein table
Browse files- README.md +90 -56
- data/test-00000-of-00001.parquet +3 -0
- data/train-00000-of-00001.parquet +3 -0
- dataset_summary.json +97 -0
- metadata/regions.parquet +3 -0
- scripts/prepare_disprot_dataset.py +286 -0
README.md
CHANGED
|
@@ -1,84 +1,118 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
license: cc-by-4.0
|
| 3 |
-
pretty_name: DisProt
|
| 4 |
-
size_categories:
|
| 5 |
-
- n<1K
|
| 6 |
-
task_categories:
|
| 7 |
-
- other
|
| 8 |
-
language:
|
| 9 |
-
- en
|
| 10 |
tags:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
---
|
| 18 |
|
| 19 |
-
# DisProt
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
-
(internal repo). Original source: <https://disprot.org/>.
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
| | |
|
| 29 |
-
|---|---|
|
| 30 |
-
|
|
| 31 |
-
|
|
| 32 |
-
|
|
| 33 |
|
| 34 |
-
##
|
| 35 |
|
| 36 |
-
|
|
| 37 |
-
|---|---:|
|
| 38 |
-
|
|
|
|
|
| 39 |
|
| 40 |
-
##
|
| 41 |
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
├── _MANIFEST.json # aggregate manifest (per-table counts)
|
| 45 |
-
└── tables/<source_slug>.jsonl # normalized rows (one JSON object per line)
|
| 46 |
```
|
| 47 |
|
| 48 |
-
|
| 49 |
-
`dataset_id`, `row` (the raw upstream row), `row_index`, and `source_file`
|
| 50 |
-
fields, so every row carries its upstream provenance.
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
```
|
| 57 |
|
| 58 |
-
|
| 59 |
|
| 60 |
```python
|
| 61 |
-
import
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
local = snapshot_download(repo_id="LiteFold/DisProt", repo_type="dataset")
|
| 66 |
-
for jsonl in sorted(Path(local, "tables").glob("*.jsonl")):
|
| 67 |
-
with jsonl.open() as f:
|
| 68 |
-
for line in f:
|
| 69 |
-
row = json.loads(line)
|
| 70 |
-
... # row["row"] is the upstream record
|
| 71 |
```
|
| 72 |
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
##
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
pretty_name: DisProt Protein Disorder Annotations
|
| 3 |
license: cc-by-4.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
tags:
|
| 5 |
+
- biology
|
| 6 |
+
- proteins
|
| 7 |
+
- intrinsic-disorder
|
| 8 |
+
- disprot
|
| 9 |
+
- annotation
|
| 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 |
+
# DisProt Protein Disorder Annotations
|
| 21 |
|
| 22 |
+
This dataset contains a viewer-friendly protein-level Parquet table derived from the DisProt JSONL source in this repository. Each row is one DisProt protein entry. Curated disorder/function/transition regions are also available as `metadata/regions.parquet`.
|
| 23 |
|
| 24 |
+
## Splits
|
|
|
|
| 25 |
|
| 26 |
+
The split is deterministic by DisProt ID: `sha256(disprot_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
|
| 27 |
|
| 28 |
+
| Split | Rows |
|
| 29 |
+
|---|---:|
|
| 30 |
+
| train | 2,875 |
|
| 31 |
+
| test | 324 |
|
| 32 |
+
| total | 3,199 |
|
| 33 |
|
| 34 |
+
## Dataset Statistics
|
| 35 |
|
| 36 |
+
| Field | Value |
|
| 37 |
+
|---|---:|
|
| 38 |
+
| Protein entries | 3,199 |
|
| 39 |
+
| Curated region rows | 13,396 |
|
| 40 |
|
| 41 |
+
## Usage
|
| 42 |
|
| 43 |
+
```bash
|
| 44 |
+
pip install datasets
|
|
|
|
|
|
|
| 45 |
```
|
| 46 |
|
| 47 |
+
Load all splits:
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
```python
|
| 50 |
+
from datasets import load_dataset
|
| 51 |
|
| 52 |
+
ds = load_dataset("LiteFold/DisProt")
|
| 53 |
+
print(ds)
|
| 54 |
+
print(ds["train"][0]["disprot_id"])
|
| 55 |
```
|
| 56 |
|
| 57 |
+
Load one split:
|
| 58 |
|
| 59 |
```python
|
| 60 |
+
from datasets import load_dataset
|
| 61 |
+
|
| 62 |
+
train = load_dataset("LiteFold/DisProt", split="train")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
```
|
| 64 |
|
| 65 |
+
Filter proteins with high disorder content:
|
| 66 |
|
| 67 |
+
```python
|
| 68 |
+
from datasets import load_dataset
|
| 69 |
+
|
| 70 |
+
ds = load_dataset("LiteFold/DisProt", split="train")
|
| 71 |
+
high_disorder = ds.filter(lambda row: row["disorder_content"] is not None and row["disorder_content"] >= 0.5)
|
| 72 |
+
print(high_disorder[0])
|
| 73 |
+
```
|
| 74 |
|
| 75 |
+
Load the region-level metadata:
|
| 76 |
|
| 77 |
+
```python
|
| 78 |
+
import pandas as pd
|
| 79 |
+
from huggingface_hub import hf_hub_download
|
| 80 |
+
|
| 81 |
+
path = hf_hub_download(
|
| 82 |
+
repo_id="LiteFold/DisProt",
|
| 83 |
+
repo_type="dataset",
|
| 84 |
+
filename="metadata/regions.parquet",
|
| 85 |
+
)
|
| 86 |
+
regions = pd.read_parquet(path)
|
| 87 |
+
print(regions.head())
|
| 88 |
+
```
|
| 89 |
|
| 90 |
+
## Key Columns
|
| 91 |
|
| 92 |
+
| Column | Description |
|
| 93 |
+
|---|---|
|
| 94 |
+
| `disprot_id` | DisProt protein identifier. |
|
| 95 |
+
| `accession` | UniProt accession. |
|
| 96 |
+
| `name` | Protein name. |
|
| 97 |
+
| `organism` | Organism name. |
|
| 98 |
+
| `ncbi_taxon_id` | NCBI taxonomy ID. |
|
| 99 |
+
| `length` | Protein sequence length. |
|
| 100 |
+
| `disorder_content` | Fraction of sequence annotated as disordered. |
|
| 101 |
+
| `dataset_labels` | DisProt dataset labels. |
|
| 102 |
+
| `sequence` | Protein sequence. |
|
| 103 |
+
| `region_count` | Number of curated region annotations. |
|
| 104 |
+
| `region_ids` | Curated region IDs. |
|
| 105 |
+
| `region_starts` | Region start positions. |
|
| 106 |
+
| `region_ends` | Region end positions. |
|
| 107 |
+
| `region_terms` | Region term names. |
|
| 108 |
+
| `evidence_codes` | Region evidence codes. |
|
| 109 |
+
| `reference_ids` | Region reference IDs. |
|
| 110 |
+
| `cross_refs` | Region cross-references such as PDB IDs. |
|
| 111 |
+
| `feature_databases` | Feature sources such as Pfam or Gene3D. |
|
| 112 |
+
| `feature_ids` | Feature IDs. |
|
| 113 |
+
| `gene_names` | Gene names and synonyms. |
|
| 114 |
+
| `split_bucket` | Deterministic split bucket from `sha256(disprot_id) % 10`. |
|
| 115 |
+
|
| 116 |
+
## Preparation
|
| 117 |
+
|
| 118 |
+
The normalization script used to create the Parquet files is included at `scripts/prepare_disprot_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:3ea5f7bd0b327d441708f0c846c800f0511ec513f4dccd3b36928352337b88ae
|
| 3 |
+
size 211361
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2d557701c4cbbeddeaa8e8fa6c0776379941dd2f8b3557475bcd862cbcd4e6f
|
| 3 |
+
size 1498217
|
dataset_summary.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "LiteFold/DisProt",
|
| 3 |
+
"entry_rows": 3199,
|
| 4 |
+
"region_rows": 13396,
|
| 5 |
+
"splits": {
|
| 6 |
+
"train": 2875,
|
| 7 |
+
"test": 324
|
| 8 |
+
},
|
| 9 |
+
"split_strategy": "deterministic sha256(disprot_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 10 |
+
"dataset_label_counts": {
|
| 11 |
+
"NDDs-related proteins": 324,
|
| 12 |
+
"Viral proteins": 230,
|
| 13 |
+
"RNA-binding proteins": 212,
|
| 14 |
+
"Cancer-related proteins": 181,
|
| 15 |
+
"Condensates-related proteins": 181,
|
| 16 |
+
"Autophagy-related proteins": 109,
|
| 17 |
+
"Neglected tropical diseases proteins": 105,
|
| 18 |
+
"Extracellular matrix proteins": 100,
|
| 19 |
+
"Bacterial virulence-related proteins": 76,
|
| 20 |
+
"Unicellular toxins and antitoxins": 51,
|
| 21 |
+
"Age-related disorders proteins": 42
|
| 22 |
+
},
|
| 23 |
+
"top_region_terms": {
|
| 24 |
+
"disorder": 7138,
|
| 25 |
+
"protein binding": 1558,
|
| 26 |
+
"disorder to order": 834,
|
| 27 |
+
"flexible linker": 426,
|
| 28 |
+
"molecular adaptor activity": 262,
|
| 29 |
+
"phosphorylation display site": 240,
|
| 30 |
+
"molecular function regulator": 188,
|
| 31 |
+
"lipid binding": 134,
|
| 32 |
+
"molecular condensate scaffold activity": 106,
|
| 33 |
+
"order": 104,
|
| 34 |
+
"pre-molten globule": 94,
|
| 35 |
+
"RNA binding": 86,
|
| 36 |
+
"order to disorder": 79,
|
| 37 |
+
"DNA binding": 78,
|
| 38 |
+
"nucleic acid binding": 77,
|
| 39 |
+
"amyloid fibril formation": 72,
|
| 40 |
+
"molecular function inhibitor activity": 72,
|
| 41 |
+
"flexible N-terminal tail": 72,
|
| 42 |
+
"molecular function activator activity": 63,
|
| 43 |
+
"flexible C-terminal tail": 58
|
| 44 |
+
},
|
| 45 |
+
"region_namespace_counts": {
|
| 46 |
+
"Structural state": 7394,
|
| 47 |
+
"Molecular function": 3405,
|
| 48 |
+
"Disorder function": 1028,
|
| 49 |
+
"Structural transition": 965,
|
| 50 |
+
"Biological process": 542,
|
| 51 |
+
"Cellular component": 62
|
| 52 |
+
},
|
| 53 |
+
"columns": [
|
| 54 |
+
"disprot_id",
|
| 55 |
+
"accession",
|
| 56 |
+
"uniparc",
|
| 57 |
+
"name",
|
| 58 |
+
"organism",
|
| 59 |
+
"ncbi_taxon_id",
|
| 60 |
+
"length",
|
| 61 |
+
"disorder_content",
|
| 62 |
+
"dataset_labels",
|
| 63 |
+
"taxonomy",
|
| 64 |
+
"released",
|
| 65 |
+
"date",
|
| 66 |
+
"creator",
|
| 67 |
+
"uniref100",
|
| 68 |
+
"uniref90",
|
| 69 |
+
"uniref50",
|
| 70 |
+
"sequence",
|
| 71 |
+
"region_count",
|
| 72 |
+
"region_ids",
|
| 73 |
+
"region_starts",
|
| 74 |
+
"region_ends",
|
| 75 |
+
"region_lengths",
|
| 76 |
+
"region_terms",
|
| 77 |
+
"region_term_ids",
|
| 78 |
+
"region_namespaces",
|
| 79 |
+
"evidence_codes",
|
| 80 |
+
"reference_ids",
|
| 81 |
+
"reference_sources",
|
| 82 |
+
"curator_names",
|
| 83 |
+
"cross_refs",
|
| 84 |
+
"feature_databases",
|
| 85 |
+
"feature_ids",
|
| 86 |
+
"feature_names",
|
| 87 |
+
"feature_count",
|
| 88 |
+
"gene_names",
|
| 89 |
+
"consensus_starts",
|
| 90 |
+
"consensus_ends",
|
| 91 |
+
"consensus_types",
|
| 92 |
+
"split_bucket"
|
| 93 |
+
],
|
| 94 |
+
"metadata_tables": [
|
| 95 |
+
"metadata/regions.parquet"
|
| 96 |
+
]
|
| 97 |
+
}
|
metadata/regions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a2582ccd4b3eed42b94e3de8897e7389e364381e1e085bcf1a5312717f7178d
|
| 3 |
+
size 1641034
|
scripts/prepare_disprot_dataset.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build viewer-friendly Parquet splits for LiteFold/DisProt."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import shutil
|
| 10 |
+
from collections import Counter
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
import pandas as pd
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
ENTRY_COLUMNS = [
|
| 18 |
+
"disprot_id",
|
| 19 |
+
"accession",
|
| 20 |
+
"uniparc",
|
| 21 |
+
"name",
|
| 22 |
+
"organism",
|
| 23 |
+
"ncbi_taxon_id",
|
| 24 |
+
"length",
|
| 25 |
+
"disorder_content",
|
| 26 |
+
"dataset_labels",
|
| 27 |
+
"taxonomy",
|
| 28 |
+
"released",
|
| 29 |
+
"date",
|
| 30 |
+
"creator",
|
| 31 |
+
"uniref100",
|
| 32 |
+
"uniref90",
|
| 33 |
+
"uniref50",
|
| 34 |
+
"sequence",
|
| 35 |
+
"region_count",
|
| 36 |
+
"region_ids",
|
| 37 |
+
"region_starts",
|
| 38 |
+
"region_ends",
|
| 39 |
+
"region_lengths",
|
| 40 |
+
"region_terms",
|
| 41 |
+
"region_term_ids",
|
| 42 |
+
"region_namespaces",
|
| 43 |
+
"evidence_codes",
|
| 44 |
+
"reference_ids",
|
| 45 |
+
"reference_sources",
|
| 46 |
+
"curator_names",
|
| 47 |
+
"cross_refs",
|
| 48 |
+
"feature_databases",
|
| 49 |
+
"feature_ids",
|
| 50 |
+
"feature_names",
|
| 51 |
+
"feature_count",
|
| 52 |
+
"gene_names",
|
| 53 |
+
"consensus_starts",
|
| 54 |
+
"consensus_ends",
|
| 55 |
+
"consensus_types",
|
| 56 |
+
"split_bucket",
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
REGION_COLUMNS = [
|
| 61 |
+
"region_id",
|
| 62 |
+
"disprot_id",
|
| 63 |
+
"accession",
|
| 64 |
+
"start",
|
| 65 |
+
"end",
|
| 66 |
+
"length",
|
| 67 |
+
"term_id",
|
| 68 |
+
"term_name",
|
| 69 |
+
"term_namespace",
|
| 70 |
+
"term_ontology",
|
| 71 |
+
"evidence_code",
|
| 72 |
+
"evidence_name",
|
| 73 |
+
"ec_go",
|
| 74 |
+
"reference_id",
|
| 75 |
+
"reference_source",
|
| 76 |
+
"curator_name",
|
| 77 |
+
"curator_orcid",
|
| 78 |
+
"date",
|
| 79 |
+
"released",
|
| 80 |
+
"statement_texts",
|
| 81 |
+
"statement_types",
|
| 82 |
+
"cross_refs",
|
| 83 |
+
"uniprot_changed",
|
| 84 |
+
"version",
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def stable_bucket(value: str, buckets: int = 10) -> int:
|
| 89 |
+
digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
|
| 90 |
+
return int(digest, 16) % buckets
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def strings(values: list[Any]) -> list[str]:
|
| 94 |
+
return [str(value) for value in values if value is not None and value != ""]
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def flatten_cross_refs(items: list[dict[str, Any]]) -> list[str]:
|
| 98 |
+
refs = []
|
| 99 |
+
for item in items or []:
|
| 100 |
+
db = item.get("db")
|
| 101 |
+
ident = item.get("id")
|
| 102 |
+
if db and ident:
|
| 103 |
+
refs.append(f"{db}:{ident}")
|
| 104 |
+
elif ident:
|
| 105 |
+
refs.append(str(ident))
|
| 106 |
+
return refs
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def gene_names(record: dict[str, Any]) -> list[str]:
|
| 110 |
+
names = []
|
| 111 |
+
for gene in record.get("genes") or []:
|
| 112 |
+
name = ((gene.get("name") or {}).get("value"))
|
| 113 |
+
if name:
|
| 114 |
+
names.append(name)
|
| 115 |
+
for key in ["synonyms", "orfNames", "olnNames"]:
|
| 116 |
+
for item in gene.get(key) or []:
|
| 117 |
+
value = item.get("value") if isinstance(item, dict) else item
|
| 118 |
+
if value:
|
| 119 |
+
names.append(str(value))
|
| 120 |
+
return sorted(set(names))
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def feature_lists(record: dict[str, Any]) -> tuple[list[str], list[str], list[str]]:
|
| 124 |
+
databases = []
|
| 125 |
+
ids = []
|
| 126 |
+
names = []
|
| 127 |
+
for database, features in (record.get("features") or {}).items():
|
| 128 |
+
for item in features or []:
|
| 129 |
+
databases.append(database)
|
| 130 |
+
ids.append(str(item.get("id") or ""))
|
| 131 |
+
names.append(str(item.get("name") or ""))
|
| 132 |
+
return databases, ids, names
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def consensus(record: dict[str, Any]) -> tuple[list[int], list[int], list[str]]:
|
| 136 |
+
starts = []
|
| 137 |
+
ends = []
|
| 138 |
+
types = []
|
| 139 |
+
for item in ((record.get("disprot_consensus") or {}).get("full") or []):
|
| 140 |
+
if item.get("start") is not None and item.get("end") is not None:
|
| 141 |
+
starts.append(int(item["start"]))
|
| 142 |
+
ends.append(int(item["end"]))
|
| 143 |
+
types.append(str(item.get("type") or ""))
|
| 144 |
+
return starts, ends, types
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def region_row(record: dict[str, Any], region: dict[str, Any]) -> dict[str, Any]:
|
| 148 |
+
start = region.get("start")
|
| 149 |
+
end = region.get("end")
|
| 150 |
+
statements = region.get("statement") or []
|
| 151 |
+
return {
|
| 152 |
+
"region_id": region.get("region_id"),
|
| 153 |
+
"disprot_id": record.get("disprot_id"),
|
| 154 |
+
"accession": record.get("acc"),
|
| 155 |
+
"start": int(start) if start is not None else None,
|
| 156 |
+
"end": int(end) if end is not None else None,
|
| 157 |
+
"length": int(end) - int(start) + 1 if start is not None and end is not None else None,
|
| 158 |
+
"term_id": region.get("term_id"),
|
| 159 |
+
"term_name": region.get("term_name"),
|
| 160 |
+
"term_namespace": region.get("term_namespace") or region.get("disprot_namespace"),
|
| 161 |
+
"term_ontology": region.get("term_ontology"),
|
| 162 |
+
"evidence_code": region.get("ec_id"),
|
| 163 |
+
"evidence_name": region.get("ec_name"),
|
| 164 |
+
"ec_go": region.get("ec_go"),
|
| 165 |
+
"reference_id": region.get("reference_id"),
|
| 166 |
+
"reference_source": region.get("reference_source"),
|
| 167 |
+
"curator_name": region.get("curator_name"),
|
| 168 |
+
"curator_orcid": region.get("curator_orcid"),
|
| 169 |
+
"date": region.get("date"),
|
| 170 |
+
"released": region.get("released"),
|
| 171 |
+
"statement_texts": strings([item.get("text") for item in statements if isinstance(item, dict)]),
|
| 172 |
+
"statement_types": strings([item.get("type") for item in statements if isinstance(item, dict)]),
|
| 173 |
+
"cross_refs": flatten_cross_refs(region.get("cross_refs") or []),
|
| 174 |
+
"uniprot_changed": region.get("uniprot_changed"),
|
| 175 |
+
"version": region.get("version"),
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def entry_row(record: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
| 180 |
+
regions = record.get("regions") or []
|
| 181 |
+
region_rows = [region_row(record, region) for region in regions]
|
| 182 |
+
feature_databases, feature_ids, feature_names = feature_lists(record)
|
| 183 |
+
consensus_starts, consensus_ends, consensus_types = consensus(record)
|
| 184 |
+
region_starts = [row["start"] for row in region_rows if row["start"] is not None]
|
| 185 |
+
region_ends = [row["end"] for row in region_rows if row["end"] is not None]
|
| 186 |
+
row = {
|
| 187 |
+
"disprot_id": record.get("disprot_id"),
|
| 188 |
+
"accession": record.get("acc"),
|
| 189 |
+
"uniparc": record.get("UniParc"),
|
| 190 |
+
"name": record.get("name"),
|
| 191 |
+
"organism": record.get("organism"),
|
| 192 |
+
"ncbi_taxon_id": record.get("ncbi_taxon_id"),
|
| 193 |
+
"length": record.get("length"),
|
| 194 |
+
"disorder_content": record.get("disorder_content"),
|
| 195 |
+
"dataset_labels": strings(record.get("dataset") or []),
|
| 196 |
+
"taxonomy": strings(record.get("taxonomy") or []),
|
| 197 |
+
"released": record.get("released"),
|
| 198 |
+
"date": record.get("date"),
|
| 199 |
+
"creator": record.get("creator"),
|
| 200 |
+
"uniref100": record.get("uniref100"),
|
| 201 |
+
"uniref90": record.get("uniref90"),
|
| 202 |
+
"uniref50": record.get("uniref50"),
|
| 203 |
+
"sequence": record.get("sequence"),
|
| 204 |
+
"region_count": len(region_rows),
|
| 205 |
+
"region_ids": strings([row["region_id"] for row in region_rows]),
|
| 206 |
+
"region_starts": region_starts,
|
| 207 |
+
"region_ends": region_ends,
|
| 208 |
+
"region_lengths": [row["length"] for row in region_rows if row["length"] is not None],
|
| 209 |
+
"region_terms": strings([row["term_name"] for row in region_rows]),
|
| 210 |
+
"region_term_ids": strings([row["term_id"] for row in region_rows]),
|
| 211 |
+
"region_namespaces": strings([row["term_namespace"] for row in region_rows]),
|
| 212 |
+
"evidence_codes": strings([row["evidence_code"] for row in region_rows]),
|
| 213 |
+
"reference_ids": strings([row["reference_id"] for row in region_rows]),
|
| 214 |
+
"reference_sources": strings([row["reference_source"] for row in region_rows]),
|
| 215 |
+
"curator_names": strings([row["curator_name"] for row in region_rows]),
|
| 216 |
+
"cross_refs": sorted({xref for row in region_rows for xref in row["cross_refs"]}),
|
| 217 |
+
"feature_databases": feature_databases,
|
| 218 |
+
"feature_ids": feature_ids,
|
| 219 |
+
"feature_names": feature_names,
|
| 220 |
+
"feature_count": len(feature_ids),
|
| 221 |
+
"gene_names": gene_names(record),
|
| 222 |
+
"consensus_starts": consensus_starts,
|
| 223 |
+
"consensus_ends": consensus_ends,
|
| 224 |
+
"consensus_types": consensus_types,
|
| 225 |
+
"split_bucket": stable_bucket(str(record.get("disprot_id") or record.get("acc"))),
|
| 226 |
+
}
|
| 227 |
+
return row, region_rows
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def build_dataset(raw_dir: Path, out_dir: Path) -> dict[str, Any]:
|
| 231 |
+
source = raw_dir / "tables/annotation_disprot_disprot_current.json.jsonl"
|
| 232 |
+
wrapper = json.loads(source.read_text(encoding="utf-8"))
|
| 233 |
+
records = wrapper["row"]["data"]
|
| 234 |
+
rows = []
|
| 235 |
+
region_rows = []
|
| 236 |
+
for record in records:
|
| 237 |
+
row, regions = entry_row(record)
|
| 238 |
+
rows.append(row)
|
| 239 |
+
region_rows.extend(regions)
|
| 240 |
+
|
| 241 |
+
if out_dir.exists():
|
| 242 |
+
shutil.rmtree(out_dir)
|
| 243 |
+
data_dir = out_dir / "data"
|
| 244 |
+
metadata_dir = out_dir / "metadata"
|
| 245 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 246 |
+
metadata_dir.mkdir(parents=True, exist_ok=True)
|
| 247 |
+
|
| 248 |
+
df = pd.DataFrame.from_records(rows, columns=ENTRY_COLUMNS)
|
| 249 |
+
train = df[df["split_bucket"].ne(0)].sort_values("disprot_id", kind="mergesort")
|
| 250 |
+
test = df[df["split_bucket"].eq(0)].sort_values("disprot_id", kind="mergesort")
|
| 251 |
+
train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
|
| 252 |
+
test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
|
| 253 |
+
|
| 254 |
+
region_df = pd.DataFrame.from_records(region_rows, columns=REGION_COLUMNS)
|
| 255 |
+
region_df.to_parquet(metadata_dir / "regions.parquet", index=False, compression="zstd")
|
| 256 |
+
|
| 257 |
+
dataset_counts = Counter(label for labels in df["dataset_labels"] for label in labels)
|
| 258 |
+
term_counts = Counter(term for terms in df["region_terms"] for term in terms)
|
| 259 |
+
namespace_counts = Counter(ns for namespaces in df["region_namespaces"] for ns in namespaces)
|
| 260 |
+
summary = {
|
| 261 |
+
"source": "LiteFold/DisProt",
|
| 262 |
+
"entry_rows": int(len(df)),
|
| 263 |
+
"region_rows": int(len(region_df)),
|
| 264 |
+
"splits": {"train": int(len(train)), "test": int(len(test))},
|
| 265 |
+
"split_strategy": "deterministic sha256(disprot_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 266 |
+
"dataset_label_counts": dict(dataset_counts.most_common()),
|
| 267 |
+
"top_region_terms": dict(term_counts.most_common(20)),
|
| 268 |
+
"region_namespace_counts": dict(namespace_counts.most_common()),
|
| 269 |
+
"columns": ENTRY_COLUMNS,
|
| 270 |
+
"metadata_tables": ["metadata/regions.parquet"],
|
| 271 |
+
}
|
| 272 |
+
(out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
| 273 |
+
return summary
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def main() -> None:
|
| 277 |
+
parser = argparse.ArgumentParser()
|
| 278 |
+
parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_DisProt_raw"))
|
| 279 |
+
parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_DisProt_processed"))
|
| 280 |
+
args = parser.parse_args()
|
| 281 |
+
summary = build_dataset(args.raw_dir, args.out_dir)
|
| 282 |
+
print(json.dumps(summary, indent=2))
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
if __name__ == "__main__":
|
| 286 |
+
main()
|