Datasets:
Add normalized Parquet train/test Human Protein Atlas table
Browse files- README.md +107 -56
- data/test-00000-of-00001.parquet +3 -0
- data/train-00000-of-00001.parquet +3 -0
- dataset_summary.json +127 -0
- metadata/cancer_prognostics.parquet +3 -0
- metadata/rna_expression_measurements.parquet +3 -0
- scripts/prepare_hpa_dataset.py +313 -0
README.md
CHANGED
|
@@ -1,83 +1,134 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
size_categories:
|
| 5 |
-
- 10K<n<100K
|
| 6 |
-
task_categories:
|
| 7 |
-
- other
|
| 8 |
-
language:
|
| 9 |
-
- en
|
| 10 |
tags:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
---
|
| 17 |
|
| 18 |
-
# Human Protein Atlas
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
(internal repo). Original source: <https://www.proteinatlas.org/about/download>.
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
| | |
|
| 28 |
-
|---|---|
|
| 29 |
-
|
|
| 30 |
-
|
|
| 31 |
-
|
|
| 32 |
|
| 33 |
-
##
|
| 34 |
|
| 35 |
-
|
|
| 36 |
-
|---|---:|
|
| 37 |
-
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
├── _MANIFEST.json # aggregate manifest (per-table counts)
|
| 44 |
-
└── tables/<source_slug>.jsonl # normalized rows (one JSON object per line)
|
| 45 |
```
|
| 46 |
|
| 47 |
-
|
| 48 |
-
`dataset_id`, `row` (the raw upstream row), `row_index`, and `source_file`
|
| 49 |
-
fields, so every row carries its upstream provenance.
|
| 50 |
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
```
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
```python
|
| 60 |
-
import
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
local = snapshot_download(repo_id="LiteFold/HumanProteinAtlas", repo_type="dataset")
|
| 65 |
-
for jsonl in sorted(Path(local, "tables").glob("*.jsonl")):
|
| 66 |
-
with jsonl.open() as f:
|
| 67 |
-
for line in f:
|
| 68 |
-
row = json.loads(line)
|
| 69 |
-
... # row["row"] is the upstream record
|
| 70 |
```
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
##
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
pretty_name: Human Protein Atlas Gene Annotations
|
| 3 |
+
license: other
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
tags:
|
| 5 |
+
- biology
|
| 6 |
+
- proteins
|
| 7 |
+
- human
|
| 8 |
+
- human-protein-atlas
|
| 9 |
+
- gene-expression
|
| 10 |
+
- subcellular-localization
|
| 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 |
+
# Human Protein Atlas Gene Annotations
|
| 22 |
|
| 23 |
+
This dataset contains a viewer-friendly gene-level Parquet table derived from the Human Protein Atlas JSONL source in this repository. Each row is one gene/protein entry. Repeated cancer-prognostic and RNA expression measurements are available as metadata tables.
|
| 24 |
|
| 25 |
+
## Splits
|
|
|
|
| 26 |
|
| 27 |
+
The split is deterministic by Ensembl ID: `sha256(ensembl_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
|
| 28 |
|
| 29 |
+
| Split | Rows |
|
| 30 |
+
|---|---:|
|
| 31 |
+
| train | 18,138 |
|
| 32 |
+
| test | 2,024 |
|
| 33 |
+
| total | 20,162 |
|
| 34 |
|
| 35 |
+
## Dataset Statistics
|
| 36 |
|
| 37 |
+
| Field | Value |
|
| 38 |
+
|---|---:|
|
| 39 |
+
| Gene rows | 20,162 |
|
| 40 |
+
| Cancer prognostic metadata rows | 442,504 |
|
| 41 |
+
| RNA expression measurement rows | 149,150 |
|
| 42 |
|
| 43 |
+
## Usage
|
| 44 |
|
| 45 |
+
```bash
|
| 46 |
+
pip install datasets
|
|
|
|
|
|
|
| 47 |
```
|
| 48 |
|
| 49 |
+
Load all splits:
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
```python
|
| 52 |
+
from datasets import load_dataset
|
| 53 |
|
| 54 |
+
ds = load_dataset("LiteFold/HumanProteinAtlas")
|
| 55 |
+
print(ds)
|
| 56 |
+
print(ds["train"][0]["gene"])
|
| 57 |
```
|
| 58 |
|
| 59 |
+
Load one split:
|
| 60 |
|
| 61 |
```python
|
| 62 |
+
from datasets import load_dataset
|
| 63 |
+
|
| 64 |
+
train = load_dataset("LiteFold/HumanProteinAtlas", split="train")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
```
|
| 66 |
|
| 67 |
+
Filter genes with protein-level evidence:
|
| 68 |
|
| 69 |
+
```python
|
| 70 |
+
from datasets import load_dataset
|
| 71 |
+
|
| 72 |
+
ds = load_dataset("LiteFold/HumanProteinAtlas", split="train")
|
| 73 |
+
protein_level = ds.filter(lambda row: row["evidence"] == "Evidence at protein level")
|
| 74 |
+
print(protein_level[0])
|
| 75 |
+
```
|
| 76 |
|
| 77 |
+
Load metadata tables directly:
|
| 78 |
|
| 79 |
+
```python
|
| 80 |
+
import pandas as pd
|
| 81 |
+
from huggingface_hub import hf_hub_download
|
| 82 |
+
|
| 83 |
+
prognostics_path = hf_hub_download(
|
| 84 |
+
repo_id="LiteFold/HumanProteinAtlas",
|
| 85 |
+
repo_type="dataset",
|
| 86 |
+
filename="metadata/cancer_prognostics.parquet",
|
| 87 |
+
)
|
| 88 |
+
prognostics = pd.read_parquet(prognostics_path)
|
| 89 |
+
print(prognostics.head())
|
| 90 |
+
|
| 91 |
+
expression_path = hf_hub_download(
|
| 92 |
+
repo_id="LiteFold/HumanProteinAtlas",
|
| 93 |
+
repo_type="dataset",
|
| 94 |
+
filename="metadata/rna_expression_measurements.parquet",
|
| 95 |
+
)
|
| 96 |
+
expression = pd.read_parquet(expression_path)
|
| 97 |
+
print(expression.head())
|
| 98 |
+
```
|
| 99 |
|
| 100 |
+
## Key Columns
|
| 101 |
|
| 102 |
+
| Column | Description |
|
| 103 |
+
|---|---|
|
| 104 |
+
| `ensembl_id` | Ensembl gene ID. |
|
| 105 |
+
| `gene` | Gene symbol. |
|
| 106 |
+
| `gene_description` | Gene/protein description. |
|
| 107 |
+
| `uniprot` | UniProt accession, when available. |
|
| 108 |
+
| `chromosome` | Chromosome. |
|
| 109 |
+
| `position` | Genomic position string. |
|
| 110 |
+
| `evidence` | Main HPA evidence level. |
|
| 111 |
+
| `hpa_evidence` | HPA-specific evidence level. |
|
| 112 |
+
| `uniprot_evidence` | UniProt evidence level. |
|
| 113 |
+
| `nextprot_evidence` | neXtProt evidence level. |
|
| 114 |
+
| `antibodies` | HPA antibody IDs. |
|
| 115 |
+
| `gene_synonyms` | Gene synonyms. |
|
| 116 |
+
| `protein_classes` | Protein class labels. |
|
| 117 |
+
| `biological_processes` | Biological process annotations. |
|
| 118 |
+
| `molecular_functions` | Molecular function annotations. |
|
| 119 |
+
| `disease_involvement` | Disease involvement labels. |
|
| 120 |
+
| `subcellular_main_locations` | Main subcellular locations. |
|
| 121 |
+
| `subcellular_additional_locations` | Additional subcellular locations. |
|
| 122 |
+
| `secretome_locations` | Secretome location annotations. |
|
| 123 |
+
| `secretome_functions` | Secretome function annotations. |
|
| 124 |
+
| `rna_tissue_specificity` | RNA tissue specificity category. |
|
| 125 |
+
| `rna_tissue_distribution` | RNA tissue distribution category. |
|
| 126 |
+
| `prognostic_cancer_count` | Number of cancers where the gene is prognostic. |
|
| 127 |
+
| `validated_prognostic_cancer_count` | Number of validated prognostic cancer entries. |
|
| 128 |
+
| `potential_prognostic_cancer_count` | Number of potential prognostic cancer entries. |
|
| 129 |
+
| `prognostic_cancers` | Cancer names with prognostic entries. |
|
| 130 |
+
| `split_bucket` | Deterministic split bucket from `sha256(ensembl_id) % 10`. |
|
| 131 |
+
|
| 132 |
+
## Preparation
|
| 133 |
+
|
| 134 |
+
The normalization script used to create the Parquet files is included at `scripts/prepare_hpa_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:94e1aa6381607bf895a4c4d0493485e44bde2a9b93e9689c11daeef0d134e1e1
|
| 3 |
+
size 234848
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2269abf21bc9f3f570bfb81647703955161296da985941a88e7e8c291dfd5a0c
|
| 3 |
+
size 1646557
|
dataset_summary.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "LiteFold/HumanProteinAtlas",
|
| 3 |
+
"entry_rows": 20162,
|
| 4 |
+
"cancer_prognostic_rows": 442504,
|
| 5 |
+
"rna_expression_measurement_rows": 149150,
|
| 6 |
+
"splits": {
|
| 7 |
+
"train": 18138,
|
| 8 |
+
"test": 2024
|
| 9 |
+
},
|
| 10 |
+
"split_strategy": "deterministic sha256(ensembl_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 11 |
+
"evidence_counts": {
|
| 12 |
+
"Evidence at protein level": 18564,
|
| 13 |
+
"Evidence at transcript level": 1344,
|
| 14 |
+
"No human protein/transcript evidence": 254
|
| 15 |
+
},
|
| 16 |
+
"rna_tissue_specificity_counts": {
|
| 17 |
+
"Low tissue specificity": 8096,
|
| 18 |
+
"Tissue enhanced": 6356,
|
| 19 |
+
"Tissue enriched": 3132,
|
| 20 |
+
"Group enriched": 1547,
|
| 21 |
+
"Not detected": 1031
|
| 22 |
+
},
|
| 23 |
+
"top_subcellular_main_locations": {
|
| 24 |
+
"Nucleoplasm": 4897,
|
| 25 |
+
"Cytosol": 3087,
|
| 26 |
+
"Vesicles": 1661,
|
| 27 |
+
"Plasma membrane": 1648,
|
| 28 |
+
"Mitochondria": 974,
|
| 29 |
+
"Golgi apparatus": 886,
|
| 30 |
+
"Nucleoli": 638,
|
| 31 |
+
"Endoplasmic reticulum": 486,
|
| 32 |
+
"Nuclear speckles": 412,
|
| 33 |
+
"Nuclear bodies": 326,
|
| 34 |
+
"Centrosome": 248,
|
| 35 |
+
"Microtubules": 237,
|
| 36 |
+
"Nucleoli fibrillar center": 193,
|
| 37 |
+
"Nuclear membrane": 193,
|
| 38 |
+
"Cell Junctions": 192,
|
| 39 |
+
"Mid piece": 151,
|
| 40 |
+
"Principal piece": 140,
|
| 41 |
+
"Primary cilium": 140,
|
| 42 |
+
"Basal body": 139,
|
| 43 |
+
"Actin filaments": 138
|
| 44 |
+
},
|
| 45 |
+
"top_protein_classes": {
|
| 46 |
+
"Predicted intracellular proteins": 15915,
|
| 47 |
+
"Predicted membrane proteins": 5573,
|
| 48 |
+
"Disease related genes": 4906,
|
| 49 |
+
"Human disease related genes": 4555,
|
| 50 |
+
"Enzymes": 3777,
|
| 51 |
+
"Plasma proteins": 3750,
|
| 52 |
+
"Metabolic proteins": 2882,
|
| 53 |
+
"Transporters": 2138,
|
| 54 |
+
"Essential proteins": 2023,
|
| 55 |
+
"Predicted secreted proteins": 1902,
|
| 56 |
+
"Potential drug targets": 1757,
|
| 57 |
+
"Cancer-related genes": 1672,
|
| 58 |
+
"Transcription factors": 1485,
|
| 59 |
+
"FDA approved drug targets": 854,
|
| 60 |
+
"G-protein coupled receptors": 743,
|
| 61 |
+
"CD markers": 384,
|
| 62 |
+
"RAS pathway related proteins": 235,
|
| 63 |
+
"Immunoglobulin genes": 214,
|
| 64 |
+
"T-cell receptor genes": 196,
|
| 65 |
+
"Ribosomal proteins": 180
|
| 66 |
+
},
|
| 67 |
+
"columns": [
|
| 68 |
+
"ensembl_id",
|
| 69 |
+
"gene",
|
| 70 |
+
"gene_description",
|
| 71 |
+
"uniprot",
|
| 72 |
+
"chromosome",
|
| 73 |
+
"position",
|
| 74 |
+
"evidence",
|
| 75 |
+
"hpa_evidence",
|
| 76 |
+
"uniprot_evidence",
|
| 77 |
+
"nextprot_evidence",
|
| 78 |
+
"antibodies",
|
| 79 |
+
"gene_synonyms",
|
| 80 |
+
"protein_classes",
|
| 81 |
+
"biological_processes",
|
| 82 |
+
"molecular_functions",
|
| 83 |
+
"disease_involvement",
|
| 84 |
+
"subcellular_main_locations",
|
| 85 |
+
"subcellular_additional_locations",
|
| 86 |
+
"secretome_locations",
|
| 87 |
+
"secretome_functions",
|
| 88 |
+
"reliability_if",
|
| 89 |
+
"reliability_ih",
|
| 90 |
+
"reliability_mouse_brain",
|
| 91 |
+
"interactions",
|
| 92 |
+
"ccd_protein",
|
| 93 |
+
"ccd_transcript",
|
| 94 |
+
"blood_expression_cluster",
|
| 95 |
+
"brain_expression_cluster",
|
| 96 |
+
"cell_line_expression_cluster",
|
| 97 |
+
"single_cell_expression_cluster",
|
| 98 |
+
"tissue_expression_cluster",
|
| 99 |
+
"rna_tissue_specificity",
|
| 100 |
+
"rna_tissue_distribution",
|
| 101 |
+
"rna_tissue_specificity_score",
|
| 102 |
+
"rna_cell_line_specificity",
|
| 103 |
+
"rna_cell_line_distribution",
|
| 104 |
+
"rna_cell_line_specificity_score",
|
| 105 |
+
"rna_cancer_specificity",
|
| 106 |
+
"rna_cancer_distribution",
|
| 107 |
+
"rna_cancer_specificity_score",
|
| 108 |
+
"rna_single_cell_type_specificity",
|
| 109 |
+
"rna_single_cell_type_distribution",
|
| 110 |
+
"rna_single_cell_type_specificity_score",
|
| 111 |
+
"rna_blood_cell_specificity",
|
| 112 |
+
"rna_blood_cell_distribution",
|
| 113 |
+
"rna_blood_cell_specificity_score",
|
| 114 |
+
"prognostic_cancer_count",
|
| 115 |
+
"validated_prognostic_cancer_count",
|
| 116 |
+
"potential_prognostic_cancer_count",
|
| 117 |
+
"favorable_prognostic_cancers",
|
| 118 |
+
"unfavorable_prognostic_cancers",
|
| 119 |
+
"prognostic_cancers",
|
| 120 |
+
"source_row_index",
|
| 121 |
+
"split_bucket"
|
| 122 |
+
],
|
| 123 |
+
"metadata_tables": [
|
| 124 |
+
"metadata/cancer_prognostics.parquet",
|
| 125 |
+
"metadata/rna_expression_measurements.parquet"
|
| 126 |
+
]
|
| 127 |
+
}
|
metadata/cancer_prognostics.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb2be087d1c8e9f2af45770e988c5f1caa75f4ef4f87496b229977a913447aad
|
| 3 |
+
size 1232620
|
metadata/rna_expression_measurements.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0aaae1c210442b91464ae97102e9efd10b21c68bd9d70c220562107ecc771f8d
|
| 3 |
+
size 872017
|
scripts/prepare_hpa_dataset.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build viewer-friendly Parquet splits for LiteFold/HumanProteinAtlas."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import re
|
| 10 |
+
import shutil
|
| 11 |
+
from collections import Counter
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from typing import Any
|
| 14 |
+
|
| 15 |
+
import pandas as pd
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
ENTRY_COLUMNS = [
|
| 19 |
+
"ensembl_id",
|
| 20 |
+
"gene",
|
| 21 |
+
"gene_description",
|
| 22 |
+
"uniprot",
|
| 23 |
+
"chromosome",
|
| 24 |
+
"position",
|
| 25 |
+
"evidence",
|
| 26 |
+
"hpa_evidence",
|
| 27 |
+
"uniprot_evidence",
|
| 28 |
+
"nextprot_evidence",
|
| 29 |
+
"antibodies",
|
| 30 |
+
"gene_synonyms",
|
| 31 |
+
"protein_classes",
|
| 32 |
+
"biological_processes",
|
| 33 |
+
"molecular_functions",
|
| 34 |
+
"disease_involvement",
|
| 35 |
+
"subcellular_main_locations",
|
| 36 |
+
"subcellular_additional_locations",
|
| 37 |
+
"secretome_locations",
|
| 38 |
+
"secretome_functions",
|
| 39 |
+
"reliability_if",
|
| 40 |
+
"reliability_ih",
|
| 41 |
+
"reliability_mouse_brain",
|
| 42 |
+
"interactions",
|
| 43 |
+
"ccd_protein",
|
| 44 |
+
"ccd_transcript",
|
| 45 |
+
"blood_expression_cluster",
|
| 46 |
+
"brain_expression_cluster",
|
| 47 |
+
"cell_line_expression_cluster",
|
| 48 |
+
"single_cell_expression_cluster",
|
| 49 |
+
"tissue_expression_cluster",
|
| 50 |
+
"rna_tissue_specificity",
|
| 51 |
+
"rna_tissue_distribution",
|
| 52 |
+
"rna_tissue_specificity_score",
|
| 53 |
+
"rna_cell_line_specificity",
|
| 54 |
+
"rna_cell_line_distribution",
|
| 55 |
+
"rna_cell_line_specificity_score",
|
| 56 |
+
"rna_cancer_specificity",
|
| 57 |
+
"rna_cancer_distribution",
|
| 58 |
+
"rna_cancer_specificity_score",
|
| 59 |
+
"rna_single_cell_type_specificity",
|
| 60 |
+
"rna_single_cell_type_distribution",
|
| 61 |
+
"rna_single_cell_type_specificity_score",
|
| 62 |
+
"rna_blood_cell_specificity",
|
| 63 |
+
"rna_blood_cell_distribution",
|
| 64 |
+
"rna_blood_cell_specificity_score",
|
| 65 |
+
"prognostic_cancer_count",
|
| 66 |
+
"validated_prognostic_cancer_count",
|
| 67 |
+
"potential_prognostic_cancer_count",
|
| 68 |
+
"favorable_prognostic_cancers",
|
| 69 |
+
"unfavorable_prognostic_cancers",
|
| 70 |
+
"prognostic_cancers",
|
| 71 |
+
"source_row_index",
|
| 72 |
+
"split_bucket",
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
PROGNOSIS_COLUMNS = [
|
| 77 |
+
"ensembl_id",
|
| 78 |
+
"gene",
|
| 79 |
+
"cancer",
|
| 80 |
+
"source",
|
| 81 |
+
"is_prognostic",
|
| 82 |
+
"p_value",
|
| 83 |
+
"prognostic",
|
| 84 |
+
"prognostic_type",
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
EXPRESSION_COLUMNS = [
|
| 89 |
+
"ensembl_id",
|
| 90 |
+
"gene",
|
| 91 |
+
"measurement",
|
| 92 |
+
"sample",
|
| 93 |
+
"value",
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def stable_bucket(value: str, buckets: int = 10) -> int:
|
| 98 |
+
digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
|
| 99 |
+
return int(digest, 16) % buckets
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def as_list(value: Any) -> list[str]:
|
| 103 |
+
if value is None or value == "NA":
|
| 104 |
+
return []
|
| 105 |
+
if isinstance(value, list):
|
| 106 |
+
return [str(item) for item in value if item is not None and item != ""]
|
| 107 |
+
return [str(value)] if value != "" else []
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def clean_scalar(value: Any) -> Any:
|
| 111 |
+
if value in {"NA", ""}:
|
| 112 |
+
return None
|
| 113 |
+
return value
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def parse_float(value: Any) -> float | None:
|
| 117 |
+
if value in {None, "", "NA"}:
|
| 118 |
+
return None
|
| 119 |
+
try:
|
| 120 |
+
return float(value)
|
| 121 |
+
except (TypeError, ValueError):
|
| 122 |
+
return None
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def score(value: Any) -> float | None:
|
| 126 |
+
return parse_float(value)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def normalize_cancer_name(column: str) -> tuple[str, str]:
|
| 130 |
+
label = column.removeprefix("Cancer prognostics - ")
|
| 131 |
+
source = "validation" if "(validation)" in label else "TCGA" if "(TCGA)" in label else ""
|
| 132 |
+
cancer = re.sub(r"\s*\((TCGA|validation)\)\s*$", "", label).strip()
|
| 133 |
+
return cancer, source
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def entry_row(wrapper: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]], list[dict[str, Any]]]:
|
| 137 |
+
row = wrapper["row"]
|
| 138 |
+
ensembl = row.get("Ensembl")
|
| 139 |
+
gene = row.get("Gene")
|
| 140 |
+
prognosis_rows = []
|
| 141 |
+
prognostic_cancers = []
|
| 142 |
+
validated = 0
|
| 143 |
+
potential = 0
|
| 144 |
+
favorable = []
|
| 145 |
+
unfavorable = []
|
| 146 |
+
|
| 147 |
+
expression_rows = []
|
| 148 |
+
for key, value in row.items():
|
| 149 |
+
if key.startswith("Cancer prognostics -") and isinstance(value, dict):
|
| 150 |
+
cancer, source = normalize_cancer_name(key)
|
| 151 |
+
is_prognostic = bool(value.get("is_prognostic"))
|
| 152 |
+
prognostic = value.get("prognostic") or None
|
| 153 |
+
prognostic_type = value.get("prognostic type") or None
|
| 154 |
+
if is_prognostic:
|
| 155 |
+
prognostic_cancers.append(cancer)
|
| 156 |
+
if prognostic == "validated prognostic":
|
| 157 |
+
validated += 1
|
| 158 |
+
elif prognostic == "potential prognostic":
|
| 159 |
+
potential += 1
|
| 160 |
+
if prognostic_type == "favorable":
|
| 161 |
+
favorable.append(cancer)
|
| 162 |
+
elif prognostic_type == "unfavorable":
|
| 163 |
+
unfavorable.append(cancer)
|
| 164 |
+
prognosis_rows.append(
|
| 165 |
+
{
|
| 166 |
+
"ensembl_id": ensembl,
|
| 167 |
+
"gene": gene,
|
| 168 |
+
"cancer": cancer,
|
| 169 |
+
"source": source,
|
| 170 |
+
"is_prognostic": is_prognostic,
|
| 171 |
+
"p_value": parse_float(value.get("p_val")),
|
| 172 |
+
"prognostic": prognostic,
|
| 173 |
+
"prognostic_type": prognostic_type,
|
| 174 |
+
}
|
| 175 |
+
)
|
| 176 |
+
elif key.startswith("RNA ") and isinstance(value, dict):
|
| 177 |
+
for sample, measurement in value.items():
|
| 178 |
+
expression_rows.append(
|
| 179 |
+
{
|
| 180 |
+
"ensembl_id": ensembl,
|
| 181 |
+
"gene": gene,
|
| 182 |
+
"measurement": key,
|
| 183 |
+
"sample": sample,
|
| 184 |
+
"value": parse_float(measurement),
|
| 185 |
+
}
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
entry = {
|
| 189 |
+
"ensembl_id": ensembl,
|
| 190 |
+
"gene": gene,
|
| 191 |
+
"gene_description": row.get("Gene description"),
|
| 192 |
+
"uniprot": row.get("Uniprot"),
|
| 193 |
+
"chromosome": row.get("Chromosome"),
|
| 194 |
+
"position": row.get("Position"),
|
| 195 |
+
"evidence": row.get("Evidence"),
|
| 196 |
+
"hpa_evidence": row.get("HPA evidence"),
|
| 197 |
+
"uniprot_evidence": row.get("UniProt evidence"),
|
| 198 |
+
"nextprot_evidence": row.get("NeXtProt evidence"),
|
| 199 |
+
"antibodies": as_list(row.get("Antibody")),
|
| 200 |
+
"gene_synonyms": as_list(row.get("Gene synonym")),
|
| 201 |
+
"protein_classes": as_list(row.get("Protein class")),
|
| 202 |
+
"biological_processes": as_list(row.get("Biological process")),
|
| 203 |
+
"molecular_functions": as_list(row.get("Molecular function")),
|
| 204 |
+
"disease_involvement": as_list(row.get("Disease involvement")),
|
| 205 |
+
"subcellular_main_locations": as_list(row.get("Subcellular main location")),
|
| 206 |
+
"subcellular_additional_locations": as_list(row.get("Subcellular additional location")),
|
| 207 |
+
"secretome_locations": as_list(row.get("Secretome location")),
|
| 208 |
+
"secretome_functions": as_list(row.get("Secretome function")),
|
| 209 |
+
"reliability_if": clean_scalar(row.get("Reliability (IF)")),
|
| 210 |
+
"reliability_ih": clean_scalar(row.get("Reliability (IH)")),
|
| 211 |
+
"reliability_mouse_brain": clean_scalar(row.get("Reliability (Mouse Brain)")),
|
| 212 |
+
"interactions": row.get("Interactions"),
|
| 213 |
+
"ccd_protein": clean_scalar(row.get("CCD Protein")),
|
| 214 |
+
"ccd_transcript": clean_scalar(row.get("CCD Transcript")),
|
| 215 |
+
"blood_expression_cluster": clean_scalar(row.get("Blood expression cluster")),
|
| 216 |
+
"brain_expression_cluster": clean_scalar(row.get("Brain expression cluster")),
|
| 217 |
+
"cell_line_expression_cluster": clean_scalar(row.get("Cell line expression cluster")),
|
| 218 |
+
"single_cell_expression_cluster": clean_scalar(row.get("Single cell expression cluster")),
|
| 219 |
+
"tissue_expression_cluster": clean_scalar(row.get("Tissue expression cluster")),
|
| 220 |
+
"rna_tissue_specificity": clean_scalar(row.get("RNA tissue specificity")),
|
| 221 |
+
"rna_tissue_distribution": clean_scalar(row.get("RNA tissue distribution")),
|
| 222 |
+
"rna_tissue_specificity_score": score(row.get("RNA tissue specificity score")),
|
| 223 |
+
"rna_cell_line_specificity": clean_scalar(row.get("RNA cell line specificity")),
|
| 224 |
+
"rna_cell_line_distribution": clean_scalar(row.get("RNA cell line distribution")),
|
| 225 |
+
"rna_cell_line_specificity_score": score(row.get("RNA cell line specificity score")),
|
| 226 |
+
"rna_cancer_specificity": clean_scalar(row.get("RNA cancer specificity")),
|
| 227 |
+
"rna_cancer_distribution": clean_scalar(row.get("RNA cancer distribution")),
|
| 228 |
+
"rna_cancer_specificity_score": score(row.get("RNA cancer specificity score")),
|
| 229 |
+
"rna_single_cell_type_specificity": clean_scalar(row.get("RNA single cell type specificity")),
|
| 230 |
+
"rna_single_cell_type_distribution": clean_scalar(row.get("RNA single cell type distribution")),
|
| 231 |
+
"rna_single_cell_type_specificity_score": score(row.get("RNA single cell type specificity score")),
|
| 232 |
+
"rna_blood_cell_specificity": clean_scalar(row.get("RNA blood cell specificity")),
|
| 233 |
+
"rna_blood_cell_distribution": clean_scalar(row.get("RNA blood cell distribution")),
|
| 234 |
+
"rna_blood_cell_specificity_score": score(row.get("RNA blood cell specificity score")),
|
| 235 |
+
"prognostic_cancer_count": len(set(prognostic_cancers)),
|
| 236 |
+
"validated_prognostic_cancer_count": validated,
|
| 237 |
+
"potential_prognostic_cancer_count": potential,
|
| 238 |
+
"favorable_prognostic_cancers": sorted(set(favorable)),
|
| 239 |
+
"unfavorable_prognostic_cancers": sorted(set(unfavorable)),
|
| 240 |
+
"prognostic_cancers": sorted(set(prognostic_cancers)),
|
| 241 |
+
"source_row_index": wrapper.get("row_index"),
|
| 242 |
+
"split_bucket": stable_bucket(str(ensembl or gene or wrapper.get("row_index"))),
|
| 243 |
+
}
|
| 244 |
+
return entry, prognosis_rows, expression_rows
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def build_dataset(raw_dir: Path, out_dir: Path) -> dict[str, Any]:
|
| 248 |
+
source = raw_dir / "tables/annotation_human_protein_atlas_proteinatlas.json.gz.jsonl"
|
| 249 |
+
rows = []
|
| 250 |
+
prognosis_rows = []
|
| 251 |
+
expression_rows = []
|
| 252 |
+
with source.open("r", encoding="utf-8") as handle:
|
| 253 |
+
for line in handle:
|
| 254 |
+
wrapper = json.loads(line)
|
| 255 |
+
entry, prognosis, expression = entry_row(wrapper)
|
| 256 |
+
rows.append(entry)
|
| 257 |
+
prognosis_rows.extend(prognosis)
|
| 258 |
+
expression_rows.extend(expression)
|
| 259 |
+
|
| 260 |
+
if out_dir.exists():
|
| 261 |
+
shutil.rmtree(out_dir)
|
| 262 |
+
data_dir = out_dir / "data"
|
| 263 |
+
metadata_dir = out_dir / "metadata"
|
| 264 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 265 |
+
metadata_dir.mkdir(parents=True, exist_ok=True)
|
| 266 |
+
|
| 267 |
+
df = pd.DataFrame.from_records(rows, columns=ENTRY_COLUMNS)
|
| 268 |
+
train = df[df["split_bucket"].ne(0)].sort_values("ensembl_id", kind="mergesort")
|
| 269 |
+
test = df[df["split_bucket"].eq(0)].sort_values("ensembl_id", kind="mergesort")
|
| 270 |
+
train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
|
| 271 |
+
test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
|
| 272 |
+
|
| 273 |
+
prognosis_df = pd.DataFrame.from_records(prognosis_rows, columns=PROGNOSIS_COLUMNS)
|
| 274 |
+
prognosis_df.to_parquet(metadata_dir / "cancer_prognostics.parquet", index=False, compression="zstd")
|
| 275 |
+
expression_df = pd.DataFrame.from_records(expression_rows, columns=EXPRESSION_COLUMNS)
|
| 276 |
+
expression_df.to_parquet(metadata_dir / "rna_expression_measurements.parquet", index=False, compression="zstd")
|
| 277 |
+
|
| 278 |
+
evidence_counts = df["evidence"].fillna("missing").value_counts().to_dict()
|
| 279 |
+
tissue_specificity_counts = df["rna_tissue_specificity"].fillna("missing").value_counts().to_dict()
|
| 280 |
+
location_counts = Counter(location for values in df["subcellular_main_locations"] for location in values)
|
| 281 |
+
protein_class_counts = Counter(item for values in df["protein_classes"] for item in values)
|
| 282 |
+
summary = {
|
| 283 |
+
"source": "LiteFold/HumanProteinAtlas",
|
| 284 |
+
"entry_rows": int(len(df)),
|
| 285 |
+
"cancer_prognostic_rows": int(len(prognosis_df)),
|
| 286 |
+
"rna_expression_measurement_rows": int(len(expression_df)),
|
| 287 |
+
"splits": {"train": int(len(train)), "test": int(len(test))},
|
| 288 |
+
"split_strategy": "deterministic sha256(ensembl_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 289 |
+
"evidence_counts": {str(k): int(v) for k, v in evidence_counts.items()},
|
| 290 |
+
"rna_tissue_specificity_counts": {str(k): int(v) for k, v in tissue_specificity_counts.items()},
|
| 291 |
+
"top_subcellular_main_locations": dict(location_counts.most_common(20)),
|
| 292 |
+
"top_protein_classes": dict(protein_class_counts.most_common(20)),
|
| 293 |
+
"columns": ENTRY_COLUMNS,
|
| 294 |
+
"metadata_tables": [
|
| 295 |
+
"metadata/cancer_prognostics.parquet",
|
| 296 |
+
"metadata/rna_expression_measurements.parquet",
|
| 297 |
+
],
|
| 298 |
+
}
|
| 299 |
+
(out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
| 300 |
+
return summary
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
def main() -> None:
|
| 304 |
+
parser = argparse.ArgumentParser()
|
| 305 |
+
parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_HumanProteinAtlas_raw"))
|
| 306 |
+
parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_HumanProteinAtlas_processed"))
|
| 307 |
+
args = parser.parse_args()
|
| 308 |
+
summary = build_dataset(args.raw_dir, args.out_dir)
|
| 309 |
+
print(json.dumps(summary, indent=2))
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
if __name__ == "__main__":
|
| 313 |
+
main()
|