anindya64 commited on
Commit
d67f21a
·
verified ·
1 Parent(s): 71591c7

Add normalized Parquet train/test InterPro entry table

Browse files
README.md ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: InterPro Entries
3
+ license: other
4
+ tags:
5
+ - biology
6
+ - protein
7
+ - protein-family
8
+ - protein-domain
9
+ - interpro
10
+ - ontology
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
+ # InterPro Entries
22
+
23
+ This dataset contains a viewer-friendly Parquet table derived from the InterPro current release files in this repository. Each row is one InterPro entry from `current_release/interpro.xml.gz`.
24
+
25
+ The original source release files remain in the repository. The default `datasets` configuration uses the normalized Parquet files under `data/` so that the Hugging Face Dataset Viewer and `load_dataset()` can read the entries directly.
26
+
27
+ Large release artifacts such as `current_release/match_complete.xml.gz`, `current_release/protein2ipr.dat.gz`, and `current_release/sites.xml.gz` are preserved as source files but are not loaded by the default table.
28
+
29
+ ## Splits
30
+
31
+ The split is deterministic by InterPro identifier: `sha256(interpro_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
32
+
33
+ | Split | Rows |
34
+ |---|---:|
35
+ | train | 46,440 |
36
+ | test | 5,049 |
37
+ | total | 51,489 |
38
+
39
+ ## Dataset Statistics
40
+
41
+ | Field | Value |
42
+ |---|---:|
43
+ | InterPro release | `108.0` |
44
+ | Release date | `29th January 2026` |
45
+ | Entries | 51,489 |
46
+ | Member database rows | 18 |
47
+ | Entries with GO mappings | 14,799 |
48
+ | InterPro-to-GO mapping rows | 30,200 |
49
+ | Entries with structures | 30,172 |
50
+ | Entries with publications | 38,194 |
51
+
52
+ | Entry type | Rows |
53
+ |---|---:|
54
+ | Family | 27,308 |
55
+ | Domain | 19,276 |
56
+ | Homologous_superfamily | 3,510 |
57
+ | Conserved_site | 768 |
58
+ | Repeat | 395 |
59
+ | Active_site | 133 |
60
+ | Binding_site | 82 |
61
+ | PTM | 17 |
62
+
63
+ | GO category | Mappings |
64
+ |---|---:|
65
+ | molecular_function | 13,802 |
66
+ | biological_process | 11,059 |
67
+ | cellular_component | 5,339 |
68
+
69
+ ## Usage
70
+
71
+ Install the Hugging Face Datasets library:
72
+
73
+ ```bash
74
+ pip install datasets
75
+ ```
76
+
77
+ Load all splits:
78
+
79
+ ```python
80
+ from datasets import load_dataset
81
+
82
+ ds = load_dataset("LiteFold/InterPro")
83
+ print(ds)
84
+
85
+ row = ds["train"][0]
86
+ print(row["interpro_id"], row["name"], row["entry_type"])
87
+ ```
88
+
89
+ Load one split:
90
+
91
+ ```python
92
+ from datasets import load_dataset
93
+
94
+ train = load_dataset("LiteFold/InterPro", split="train")
95
+ test = load_dataset("LiteFold/InterPro", split="test")
96
+ ```
97
+
98
+ Stream rows without downloading the full table first:
99
+
100
+ ```python
101
+ from datasets import load_dataset
102
+
103
+ stream = load_dataset("LiteFold/InterPro", split="train", streaming=True)
104
+ for row in stream.take(5):
105
+ print(row["interpro_id"], row["short_name"], row["protein_count"])
106
+ ```
107
+
108
+ Filter entries with GO mappings:
109
+
110
+ ```python
111
+ from datasets import load_dataset
112
+
113
+ ds = load_dataset("LiteFold/InterPro", split="train")
114
+ with_go = ds.filter(lambda row: row["go_count"] > 0)
115
+ print(with_go[0]["interpro_id"], with_go[0]["go_ids"])
116
+ ```
117
+
118
+ Filter protein domains with PDB structures:
119
+
120
+ ```python
121
+ from datasets import load_dataset
122
+
123
+ ds = load_dataset("LiteFold/InterPro", split="train")
124
+ domains_with_structures = ds.filter(
125
+ lambda row: row["entry_type"] == "Domain" and row["structure_count"] > 0
126
+ )
127
+ print(domains_with_structures[0]["interpro_id"], domains_with_structures[0]["pdb_ids"][:5])
128
+ ```
129
+
130
+ Load release database metadata directly:
131
+
132
+ ```python
133
+ import pandas as pd
134
+ from huggingface_hub import hf_hub_download
135
+
136
+ path = hf_hub_download(
137
+ repo_id="LiteFold/InterPro",
138
+ repo_type="dataset",
139
+ filename="metadata/database_info.parquet",
140
+ )
141
+ database_info = pd.read_parquet(path)
142
+ print(database_info)
143
+ ```
144
+
145
+ ## Columns
146
+
147
+ | Column | Description |
148
+ |---|---|
149
+ | `interpro_id` | InterPro accession, such as `IPR000001`. |
150
+ | `interpro_numeric_id` | Numeric portion of `interpro_id`. |
151
+ | `name` | Full InterPro entry name. |
152
+ | `short_name` | Short InterPro entry name from the XML attribute. |
153
+ | `entry_type` | Entry class, such as `Family`, `Domain`, or `Homologous_superfamily`. |
154
+ | `protein_count` | Number of proteins matched by the entry in the release XML. |
155
+ | `is_llm` | Whether the entry is marked as LLM-generated in the source XML. |
156
+ | `is_llm_reviewed` | Whether the LLM marker is reviewed in the source XML. |
157
+ | `abstract` | Normalized text from the entry abstract. |
158
+ | `go_ids` | GO identifiers mapped to the InterPro entry. |
159
+ | `go_terms` | GO term names corresponding to `go_ids`. |
160
+ | `go_categories` | GO namespaces corresponding to `go_ids`. |
161
+ | `go_count` | Number of mapped GO terms. |
162
+ | `member_databases` | Member databases contributing signatures. |
163
+ | `member_accessions` | Signature accessions from member databases. |
164
+ | `member_names` | Signature names from member databases. |
165
+ | `member_protein_counts` | Protein counts for member signatures. |
166
+ | `member_count` | Number of member signatures. |
167
+ | `external_databases` | External resource database names. |
168
+ | `external_accessions` | External resource accessions. |
169
+ | `external_xrefs` | Combined external cross-references as `DB:ACCESSION`. |
170
+ | `external_xref_count` | Number of external cross-references. |
171
+ | `pdb_ids` | PDB structure identifiers. |
172
+ | `structure_count` | Number of PDB structure links. |
173
+ | `publication_ids` | InterPro publication identifiers. |
174
+ | `pubmed_ids` | PubMed identifiers, when available. |
175
+ | `publication_titles` | Publication titles. |
176
+ | `publication_years` | Publication years, with `0` used when missing. |
177
+ | `publication_count` | Number of publications attached to the entry. |
178
+ | `parent_ids` | Parent InterPro entries from the XML hierarchy. |
179
+ | `child_ids` | Child InterPro entries from the XML hierarchy. |
180
+ | `parent_count` | Number of parents. |
181
+ | `child_count` | Number of children. |
182
+ | `tree_depth` | Minimum hierarchy depth from `ParentChildTreeFile.txt`, when present. |
183
+ | `taxonomy_names` | Taxa listed in the taxonomy distribution. |
184
+ | `taxonomy_protein_counts` | Protein counts for `taxonomy_names`. |
185
+ | `taxonomy_count` | Number of taxonomy distribution rows. |
186
+ | `key_species_names` | Key species names listed for the entry. |
187
+ | `key_species_protein_counts` | Protein counts for `key_species_names`. |
188
+ | `key_species_count` | Number of key species rows. |
189
+ | `in_entry_list` | Whether the entry appears in `entry.list`. |
190
+ | `entry_list_type` | Entry type from `entry.list`. |
191
+ | `entry_list_name` | Entry name from `entry.list`. |
192
+ | `names_dat_name` | Entry name from `names.dat`. |
193
+ | `short_names_dat_name` | Short name from `short_names.dat`. |
194
+ | `split_bucket` | Deterministic split bucket from `sha256(interpro_id) % 10`. |
195
+
196
+ ## Preparation
197
+
198
+ The normalization script used to create the Parquet files is included at `scripts/prepare_interpro_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:da82f415ec9ece8eba0441fdbc7fa67b30ff839e7ab3ac0078d4ea838de18e5d
3
+ size 3319102
data/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01a1a4dbdb606336d593586d89be0da6d15ed65a3c80fb1b6f0aed210569145b
3
+ size 25874374
dataset_summary.json ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source": "LiteFold/InterPro",
3
+ "release": "108.0",
4
+ "release_date": "29th January 2026",
5
+ "last_entry": "IPR061508",
6
+ "entry_rows": 51489,
7
+ "database_info_rows": 18,
8
+ "entry_list_rows": 51489,
9
+ "names_dat_rows": 51489,
10
+ "short_names_dat_rows": 51489,
11
+ "tree_entries": 10748,
12
+ "interpro2go_mapping_rows": 30200,
13
+ "release_notes_interpro2go_mappings": 30200,
14
+ "splits": {
15
+ "train": 46440,
16
+ "test": 5049
17
+ },
18
+ "split_strategy": "deterministic sha256(interpro_id) % 10; bucket 0 is test, buckets 1-9 are train",
19
+ "entry_type_counts": {
20
+ "Family": 27308,
21
+ "Domain": 19276,
22
+ "Homologous_superfamily": 3510,
23
+ "Conserved_site": 768,
24
+ "Repeat": 395,
25
+ "Active_site": 133,
26
+ "Binding_site": 82,
27
+ "PTM": 17
28
+ },
29
+ "entries_with_go": 14799,
30
+ "entries_with_members": 51489,
31
+ "entries_with_structures": 30172,
32
+ "entries_with_publications": 38194,
33
+ "top_member_databases": {
34
+ "PFAM": 26620,
35
+ "PANTHER": 10491,
36
+ "NCBIFAM": 7069,
37
+ "CDD": 5040,
38
+ "PIRSF": 3223,
39
+ "CATHGENE3D": 2820,
40
+ "HAMAP": 2386,
41
+ "PRINTS": 1938,
42
+ "SSF": 1649,
43
+ "PROFILE": 1303,
44
+ "PROSITE": 1282,
45
+ "SMART": 1276,
46
+ "SFLD": 160
47
+ },
48
+ "go_category_counts": {
49
+ "molecular_function": 13802,
50
+ "biological_process": 11059,
51
+ "cellular_component": 5339
52
+ },
53
+ "top_external_databases": {
54
+ "REACTOME": 497598,
55
+ "METACYC": 78901,
56
+ "EC": 12551,
57
+ "GP": 6186,
58
+ "PROSITEDOC": 1485,
59
+ "IUPHAR": 185,
60
+ "CAZY": 116
61
+ },
62
+ "columns": [
63
+ "interpro_id",
64
+ "interpro_numeric_id",
65
+ "name",
66
+ "short_name",
67
+ "entry_type",
68
+ "protein_count",
69
+ "is_llm",
70
+ "is_llm_reviewed",
71
+ "abstract",
72
+ "go_ids",
73
+ "go_terms",
74
+ "go_categories",
75
+ "go_count",
76
+ "member_databases",
77
+ "member_accessions",
78
+ "member_names",
79
+ "member_protein_counts",
80
+ "member_count",
81
+ "external_databases",
82
+ "external_accessions",
83
+ "external_xrefs",
84
+ "external_xref_count",
85
+ "pdb_ids",
86
+ "structure_count",
87
+ "publication_ids",
88
+ "pubmed_ids",
89
+ "publication_titles",
90
+ "publication_years",
91
+ "publication_count",
92
+ "parent_ids",
93
+ "child_ids",
94
+ "parent_count",
95
+ "child_count",
96
+ "tree_depth",
97
+ "taxonomy_names",
98
+ "taxonomy_protein_counts",
99
+ "taxonomy_count",
100
+ "key_species_names",
101
+ "key_species_protein_counts",
102
+ "key_species_count",
103
+ "in_entry_list",
104
+ "entry_list_type",
105
+ "entry_list_name",
106
+ "names_dat_name",
107
+ "short_names_dat_name",
108
+ "split_bucket"
109
+ ],
110
+ "source_files_used": [
111
+ "current_release/interpro.xml.gz",
112
+ "current_release/entry.list",
113
+ "current_release/names.dat",
114
+ "current_release/short_names.dat",
115
+ "current_release/ParentChildTreeFile.txt",
116
+ "current_release/interpro2go",
117
+ "current_release/release_notes.txt"
118
+ ]
119
+ }
metadata/database_info.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8aa65e0a5a7d151a6391c3f7272d6db34eb0e469e0df8951bc8c9ee877efe6b5
3
+ size 3287
scripts/prepare_interpro_dataset.py ADDED
@@ -0,0 +1,467 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Build viewer-friendly Parquet splits for LiteFold/InterPro."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import gzip
8
+ import hashlib
9
+ import json
10
+ import re
11
+ import shutil
12
+ import xml.etree.ElementTree as ET
13
+ from collections import Counter
14
+ from pathlib import Path
15
+ from typing import Any
16
+
17
+ import pandas as pd
18
+
19
+
20
+ ENTRY_COLUMNS = [
21
+ "interpro_id",
22
+ "interpro_numeric_id",
23
+ "name",
24
+ "short_name",
25
+ "entry_type",
26
+ "protein_count",
27
+ "is_llm",
28
+ "is_llm_reviewed",
29
+ "abstract",
30
+ "go_ids",
31
+ "go_terms",
32
+ "go_categories",
33
+ "go_count",
34
+ "member_databases",
35
+ "member_accessions",
36
+ "member_names",
37
+ "member_protein_counts",
38
+ "member_count",
39
+ "external_databases",
40
+ "external_accessions",
41
+ "external_xrefs",
42
+ "external_xref_count",
43
+ "pdb_ids",
44
+ "structure_count",
45
+ "publication_ids",
46
+ "pubmed_ids",
47
+ "publication_titles",
48
+ "publication_years",
49
+ "publication_count",
50
+ "parent_ids",
51
+ "child_ids",
52
+ "parent_count",
53
+ "child_count",
54
+ "tree_depth",
55
+ "taxonomy_names",
56
+ "taxonomy_protein_counts",
57
+ "taxonomy_count",
58
+ "key_species_names",
59
+ "key_species_protein_counts",
60
+ "key_species_count",
61
+ "in_entry_list",
62
+ "entry_list_type",
63
+ "entry_list_name",
64
+ "names_dat_name",
65
+ "short_names_dat_name",
66
+ "split_bucket",
67
+ ]
68
+
69
+
70
+ def normalize_text(value: str | None) -> str | None:
71
+ if value is None:
72
+ return None
73
+ text = re.sub(r"\s+", " ", value).strip()
74
+ return text or None
75
+
76
+
77
+ def parse_int(value: str | None) -> int | None:
78
+ if value is None or value == "":
79
+ return None
80
+ try:
81
+ return int(value)
82
+ except ValueError:
83
+ return None
84
+
85
+
86
+ def parse_bool(value: str | None) -> bool | None:
87
+ if value is None or value == "":
88
+ return None
89
+ lowered = value.lower()
90
+ if lowered == "true":
91
+ return True
92
+ if lowered == "false":
93
+ return False
94
+ return None
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 text_of(parent: ET.Element, tag: str) -> str | None:
103
+ child = parent.find(tag)
104
+ if child is None:
105
+ return None
106
+ return normalize_text("".join(child.itertext()))
107
+
108
+
109
+ def xref_value(db: str | None, dbkey: str | None) -> str:
110
+ if db and dbkey:
111
+ return f"{db}:{dbkey}"
112
+ return dbkey or db or ""
113
+
114
+
115
+ def parse_two_column_file(path: Path) -> dict[str, str]:
116
+ mapping: dict[str, str] = {}
117
+ if not path.exists():
118
+ return mapping
119
+ with path.open("r", encoding="utf-8", errors="replace") as handle:
120
+ for line in handle:
121
+ stripped = line.rstrip("\n")
122
+ if not stripped:
123
+ continue
124
+ parts = stripped.split("\t", 1)
125
+ if len(parts) == 2 and parts[0].startswith("IPR"):
126
+ mapping[parts[0]] = parts[1]
127
+ return mapping
128
+
129
+
130
+ def parse_entry_list(path: Path) -> dict[str, dict[str, str]]:
131
+ entries: dict[str, dict[str, str]] = {}
132
+ if not path.exists():
133
+ return entries
134
+ with path.open("r", encoding="utf-8", errors="replace") as handle:
135
+ header = next(handle, "").rstrip("\n").split("\t")
136
+ for line in handle:
137
+ parts = line.rstrip("\n").split("\t")
138
+ if len(parts) != len(header):
139
+ continue
140
+ row = dict(zip(header, parts))
141
+ entry_id = row.get("ENTRY_AC")
142
+ if entry_id:
143
+ entries[entry_id] = row
144
+ return entries
145
+
146
+
147
+ def parse_tree_depths(path: Path) -> dict[str, int]:
148
+ depths: dict[str, int] = {}
149
+ pattern = re.compile(r"^(?P<prefix>-*)(?P<id>IPR\d+)::")
150
+ if not path.exists():
151
+ return depths
152
+ with path.open("r", encoding="utf-8", errors="replace") as handle:
153
+ for line in handle:
154
+ match = pattern.match(line.strip())
155
+ if not match:
156
+ continue
157
+ entry_id = match.group("id")
158
+ depth = len(match.group("prefix")) // 2
159
+ previous = depths.get(entry_id)
160
+ if previous is None or depth < previous:
161
+ depths[entry_id] = depth
162
+ return depths
163
+
164
+
165
+ def parse_interpro2go_count(path: Path) -> int:
166
+ count = 0
167
+ if not path.exists():
168
+ return count
169
+ with path.open("r", encoding="utf-8", errors="replace") as handle:
170
+ for line in handle:
171
+ stripped = line.strip()
172
+ if stripped and not stripped.startswith("!"):
173
+ count += 1
174
+ return count
175
+
176
+
177
+ def parse_release_notes(path: Path) -> dict[str, Any]:
178
+ notes = path.read_text(encoding="utf-8", errors="replace") if path.exists() else ""
179
+ release_match = re.search(r"Release\s+([0-9.]+),\s+([^\n]+)", notes)
180
+ last_entry_match = re.search(r"Last Entry\s+(IPR\d+)", notes)
181
+ go_match = re.search(r"Number of GO terms mapped to InterPro\s+-\s+([0-9]+)", notes)
182
+ return {
183
+ "release": release_match.group(1) if release_match else None,
184
+ "release_date": release_match.group(2).strip() if release_match else None,
185
+ "last_entry": last_entry_match.group(1) if last_entry_match else None,
186
+ "interpro_to_go_mappings": int(go_match.group(1)) if go_match else None,
187
+ }
188
+
189
+
190
+ def parse_dbinfo(release: ET.Element) -> list[dict[str, Any]]:
191
+ rows = []
192
+ for item in release.findall("dbinfo"):
193
+ rows.append(
194
+ {
195
+ "dbname": item.attrib.get("dbname"),
196
+ "version": item.attrib.get("version"),
197
+ "entry_count": parse_int(item.attrib.get("entry_count")),
198
+ "file_date": item.attrib.get("file_date"),
199
+ }
200
+ )
201
+ return rows
202
+
203
+
204
+ def extract_taxa(container: ET.Element | None) -> tuple[list[str], list[int]]:
205
+ names = []
206
+ counts = []
207
+ if container is None:
208
+ return names, counts
209
+ for taxon in container.findall("taxon_data"):
210
+ name = taxon.attrib.get("name")
211
+ count = parse_int(taxon.attrib.get("proteins_count"))
212
+ if name:
213
+ names.append(name)
214
+ counts.append(count if count is not None else 0)
215
+ return names, counts
216
+
217
+
218
+ def interpro_row(
219
+ elem: ET.Element,
220
+ entry_list: dict[str, dict[str, str]],
221
+ names_dat: dict[str, str],
222
+ short_names_dat: dict[str, str],
223
+ tree_depths: dict[str, int],
224
+ ) -> dict[str, Any]:
225
+ entry_id = elem.attrib.get("id", "")
226
+ numeric_match = re.match(r"IPR(\d+)$", entry_id)
227
+ entry_info = entry_list.get(entry_id, {})
228
+
229
+ class_list = elem.find("class_list")
230
+ go_ids: list[str] = []
231
+ go_terms: list[str] = []
232
+ go_categories: list[str] = []
233
+ if class_list is not None:
234
+ for item in class_list.findall("classification"):
235
+ go_id = item.attrib.get("id")
236
+ if not go_id:
237
+ continue
238
+ go_ids.append(go_id)
239
+ go_terms.append(text_of(item, "description") or "")
240
+ go_categories.append(text_of(item, "category") or "")
241
+
242
+ member_databases: list[str] = []
243
+ member_accessions: list[str] = []
244
+ member_names: list[str] = []
245
+ member_protein_counts: list[int] = []
246
+ member_list = elem.find("member_list")
247
+ if member_list is not None:
248
+ for item in member_list.findall("db_xref"):
249
+ member_databases.append(item.attrib.get("db") or "")
250
+ member_accessions.append(item.attrib.get("dbkey") or "")
251
+ member_names.append(item.attrib.get("name") or "")
252
+ member_protein_counts.append(parse_int(item.attrib.get("protein_count")) or 0)
253
+
254
+ external_databases: list[str] = []
255
+ external_accessions: list[str] = []
256
+ external_xrefs: list[str] = []
257
+ external_doc_list = elem.find("external_doc_list")
258
+ if external_doc_list is not None:
259
+ for item in external_doc_list.findall("db_xref"):
260
+ db = item.attrib.get("db")
261
+ dbkey = item.attrib.get("dbkey")
262
+ external_databases.append(db or "")
263
+ external_accessions.append(dbkey or "")
264
+ external_xrefs.append(xref_value(db, dbkey))
265
+
266
+ pdb_ids: list[str] = []
267
+ structure_db_links = elem.find("structure_db_links")
268
+ if structure_db_links is not None:
269
+ for item in structure_db_links.findall("db_xref"):
270
+ dbkey = item.attrib.get("dbkey")
271
+ if dbkey:
272
+ pdb_ids.append(dbkey)
273
+
274
+ publication_ids: list[str] = []
275
+ pubmed_ids: list[str] = []
276
+ publication_titles: list[str] = []
277
+ publication_years: list[int] = []
278
+ pub_list = elem.find("pub_list")
279
+ if pub_list is not None:
280
+ for publication in pub_list.findall("publication"):
281
+ publication_ids.append(publication.attrib.get("id") or "")
282
+ title = text_of(publication, "title")
283
+ publication_titles.append(title or "")
284
+ year = parse_int(text_of(publication, "year"))
285
+ publication_years.append(year if year is not None else 0)
286
+ xref = publication.find("db_xref")
287
+ if xref is not None and xref.attrib.get("db") == "PUBMED":
288
+ dbkey = xref.attrib.get("dbkey")
289
+ if dbkey:
290
+ pubmed_ids.append(dbkey)
291
+
292
+ parent_ids = []
293
+ parent_list = elem.find("parent_list")
294
+ if parent_list is not None:
295
+ parent_ids = [item.attrib["ipr_ref"] for item in parent_list.findall("rel_ref") if item.attrib.get("ipr_ref")]
296
+
297
+ child_ids = []
298
+ child_list = elem.find("child_list")
299
+ if child_list is not None:
300
+ child_ids = [item.attrib["ipr_ref"] for item in child_list.findall("rel_ref") if item.attrib.get("ipr_ref")]
301
+
302
+ taxonomy_names, taxonomy_protein_counts = extract_taxa(elem.find("taxonomy_distribution"))
303
+ key_species_names, key_species_protein_counts = extract_taxa(elem.find("key_species"))
304
+
305
+ abstract = elem.find("abstract")
306
+ abstract_text = normalize_text(" ".join(abstract.itertext())) if abstract is not None else None
307
+
308
+ return {
309
+ "interpro_id": entry_id,
310
+ "interpro_numeric_id": int(numeric_match.group(1)) if numeric_match else None,
311
+ "name": text_of(elem, "name"),
312
+ "short_name": elem.attrib.get("short_name") or None,
313
+ "entry_type": elem.attrib.get("type") or None,
314
+ "protein_count": parse_int(elem.attrib.get("protein_count")),
315
+ "is_llm": parse_bool(elem.attrib.get("is-llm")),
316
+ "is_llm_reviewed": parse_bool(elem.attrib.get("is-llm-reviewed")),
317
+ "abstract": abstract_text,
318
+ "go_ids": go_ids,
319
+ "go_terms": go_terms,
320
+ "go_categories": go_categories,
321
+ "go_count": len(go_ids),
322
+ "member_databases": member_databases,
323
+ "member_accessions": member_accessions,
324
+ "member_names": member_names,
325
+ "member_protein_counts": member_protein_counts,
326
+ "member_count": len(member_accessions),
327
+ "external_databases": external_databases,
328
+ "external_accessions": external_accessions,
329
+ "external_xrefs": external_xrefs,
330
+ "external_xref_count": len(external_xrefs),
331
+ "pdb_ids": pdb_ids,
332
+ "structure_count": len(pdb_ids),
333
+ "publication_ids": publication_ids,
334
+ "pubmed_ids": pubmed_ids,
335
+ "publication_titles": publication_titles,
336
+ "publication_years": publication_years,
337
+ "publication_count": len(publication_ids),
338
+ "parent_ids": parent_ids,
339
+ "child_ids": child_ids,
340
+ "parent_count": len(parent_ids),
341
+ "child_count": len(child_ids),
342
+ "tree_depth": tree_depths.get(entry_id),
343
+ "taxonomy_names": taxonomy_names,
344
+ "taxonomy_protein_counts": taxonomy_protein_counts,
345
+ "taxonomy_count": len(taxonomy_names),
346
+ "key_species_names": key_species_names,
347
+ "key_species_protein_counts": key_species_protein_counts,
348
+ "key_species_count": len(key_species_names),
349
+ "in_entry_list": entry_id in entry_list,
350
+ "entry_list_type": entry_info.get("ENTRY_TYPE"),
351
+ "entry_list_name": entry_info.get("ENTRY_NAME"),
352
+ "names_dat_name": names_dat.get(entry_id),
353
+ "short_names_dat_name": short_names_dat.get(entry_id),
354
+ "split_bucket": stable_bucket(entry_id),
355
+ }
356
+
357
+
358
+ def parse_xml(
359
+ path: Path,
360
+ entry_list: dict[str, dict[str, str]],
361
+ names_dat: dict[str, str],
362
+ short_names_dat: dict[str, str],
363
+ tree_depths: dict[str, int],
364
+ ) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
365
+ rows: list[dict[str, Any]] = []
366
+ dbinfo_rows: list[dict[str, Any]] = []
367
+ with gzip.open(path, "rb") as handle:
368
+ for _, elem in ET.iterparse(handle, events=("end",)):
369
+ if elem.tag == "release":
370
+ dbinfo_rows = parse_dbinfo(elem)
371
+ elem.clear()
372
+ elif elem.tag == "interpro":
373
+ rows.append(interpro_row(elem, entry_list, names_dat, short_names_dat, tree_depths))
374
+ elem.clear()
375
+ return rows, dbinfo_rows
376
+
377
+
378
+ def build_dataset(raw_dir: Path, out_dir: Path) -> dict[str, Any]:
379
+ current_dir = raw_dir / "current_release"
380
+ entry_list = parse_entry_list(current_dir / "entry.list")
381
+ names_dat = parse_two_column_file(current_dir / "names.dat")
382
+ short_names_dat = parse_two_column_file(current_dir / "short_names.dat")
383
+ tree_depths = parse_tree_depths(current_dir / "ParentChildTreeFile.txt")
384
+ release_notes = parse_release_notes(current_dir / "release_notes.txt")
385
+ interpro2go_count = parse_interpro2go_count(current_dir / "interpro2go")
386
+ rows, dbinfo_rows = parse_xml(
387
+ current_dir / "interpro.xml.gz",
388
+ entry_list=entry_list,
389
+ names_dat=names_dat,
390
+ short_names_dat=short_names_dat,
391
+ tree_depths=tree_depths,
392
+ )
393
+
394
+ if out_dir.exists():
395
+ shutil.rmtree(out_dir)
396
+ data_dir = out_dir / "data"
397
+ metadata_dir = out_dir / "metadata"
398
+ data_dir.mkdir(parents=True, exist_ok=True)
399
+ metadata_dir.mkdir(parents=True, exist_ok=True)
400
+
401
+ df = pd.DataFrame.from_records(rows, columns=ENTRY_COLUMNS)
402
+ df = df.sort_values(["split_bucket", "interpro_id"], kind="mergesort")
403
+ train = df[df["split_bucket"].ne(0)].sort_values("interpro_id", kind="mergesort")
404
+ test = df[df["split_bucket"].eq(0)].sort_values("interpro_id", kind="mergesort")
405
+ train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
406
+ test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
407
+
408
+ dbinfo_df = pd.DataFrame.from_records(dbinfo_rows)
409
+ dbinfo_df.to_parquet(metadata_dir / "database_info.parquet", index=False, compression="zstd")
410
+
411
+ entry_type_counts = df["entry_type"].value_counts(dropna=False).to_dict()
412
+ member_database_counts = Counter(database for values in df["member_databases"] for database in values)
413
+ go_category_counts = Counter(category for values in df["go_categories"] for category in values)
414
+ external_database_counts = Counter(database for values in df["external_databases"] for database in values)
415
+
416
+ summary = {
417
+ "source": "LiteFold/InterPro",
418
+ "release": release_notes.get("release"),
419
+ "release_date": release_notes.get("release_date"),
420
+ "last_entry": release_notes.get("last_entry"),
421
+ "entry_rows": int(len(df)),
422
+ "database_info_rows": int(len(dbinfo_df)),
423
+ "entry_list_rows": int(len(entry_list)),
424
+ "names_dat_rows": int(len(names_dat)),
425
+ "short_names_dat_rows": int(len(short_names_dat)),
426
+ "tree_entries": int(len(tree_depths)),
427
+ "interpro2go_mapping_rows": int(interpro2go_count),
428
+ "release_notes_interpro2go_mappings": release_notes.get("interpro_to_go_mappings"),
429
+ "splits": {
430
+ "train": int(len(train)),
431
+ "test": int(len(test)),
432
+ },
433
+ "split_strategy": "deterministic sha256(interpro_id) % 10; bucket 0 is test, buckets 1-9 are train",
434
+ "entry_type_counts": {str(k): int(v) for k, v in entry_type_counts.items()},
435
+ "entries_with_go": int(df["go_count"].gt(0).sum()),
436
+ "entries_with_members": int(df["member_count"].gt(0).sum()),
437
+ "entries_with_structures": int(df["structure_count"].gt(0).sum()),
438
+ "entries_with_publications": int(df["publication_count"].gt(0).sum()),
439
+ "top_member_databases": dict(member_database_counts.most_common(20)),
440
+ "go_category_counts": dict(go_category_counts.most_common()),
441
+ "top_external_databases": dict(external_database_counts.most_common(20)),
442
+ "columns": ENTRY_COLUMNS,
443
+ "source_files_used": [
444
+ "current_release/interpro.xml.gz",
445
+ "current_release/entry.list",
446
+ "current_release/names.dat",
447
+ "current_release/short_names.dat",
448
+ "current_release/ParentChildTreeFile.txt",
449
+ "current_release/interpro2go",
450
+ "current_release/release_notes.txt",
451
+ ],
452
+ }
453
+ (out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
454
+ return summary
455
+
456
+
457
+ def main() -> None:
458
+ parser = argparse.ArgumentParser()
459
+ parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_InterPro_raw"))
460
+ parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_InterPro_processed"))
461
+ args = parser.parse_args()
462
+ summary = build_dataset(args.raw_dir, args.out_dir)
463
+ print(json.dumps(summary, indent=2))
464
+
465
+
466
+ if __name__ == "__main__":
467
+ main()