Upload jolma_domains.py
Browse files- jolma_domains.py +73 -0
jolma_domains.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
logger = datasets.logging.get_logger(__name__)
|
| 5 |
+
|
| 6 |
+
URL = "https://huggingface.co/datasets/thewall/jolma_domains/resolve/main"
|
| 7 |
+
Protein_URL = "https://huggingface.co/datasets/thewall/DeepBindWeight/resolve/main"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class JolmaDomainsConfig(datasets.BuilderConfig):
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class JolmaDomains(datasets.GeneratorBasedBuilder):
|
| 15 |
+
BUILDER_CONFIGS = [
|
| 16 |
+
JolmaDomainsConfig(name=key) for key in ["Region", "Compositional bias", "Zinc finger", "Domain", "Motif", "Repeat", "Coiled coil"]
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
DEFAULT_CONFIG_NAME = "Region"
|
| 20 |
+
|
| 21 |
+
def _info(self):
|
| 22 |
+
return datasets.DatasetInfo(
|
| 23 |
+
features=datasets.Features(
|
| 24 |
+
{
|
| 25 |
+
"id": datasets.Value("int32"),
|
| 26 |
+
"protein": datasets.Value("string"),
|
| 27 |
+
"protein_id": datasets.Value("string"),
|
| 28 |
+
"type": datasets.Value("string"),
|
| 29 |
+
"detail": datasets.Sequence({
|
| 30 |
+
"start": datasets.Value("int32"),
|
| 31 |
+
"end": datasets.Value("int32"),
|
| 32 |
+
"span": datasets.Value("string"),
|
| 33 |
+
"description": datasets.Value("string"),
|
| 34 |
+
"evidence": datasets.Value("string")}),
|
| 35 |
+
}
|
| 36 |
+
),
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def _split_generators(self, dl_manager):
|
| 40 |
+
file = dl_manager.download(f"{URL}/domains.xlsx")
|
| 41 |
+
protein_file = dl_manager.download(f"{Protein_URL}/ERP001824-UniprotKB.xlsx")
|
| 42 |
+
return [
|
| 43 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": file,"protein_filepath": protein_file}),
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
def _generate_examples(self, filepath, protein_filepath):
|
| 47 |
+
"""This function returns the examples in the raw (text) form."""
|
| 48 |
+
protein_info = pd.read_excel(protein_filepath, index_col=0)
|
| 49 |
+
data = pd.read_excel(filepath, sheet_name=self.config.name)
|
| 50 |
+
|
| 51 |
+
groups = data.groupby("Entry")
|
| 52 |
+
for idx, (entry, rows) in enumerate(groups):
|
| 53 |
+
protein = protein_info[protein_info['Entry'] == entry].iloc[0]
|
| 54 |
+
sequence = protein['Sequence']
|
| 55 |
+
detail = []
|
| 56 |
+
for _, row in rows.iterrows():
|
| 57 |
+
detail.append({"span": row["span"],
|
| 58 |
+
"description": row['description'],
|
| 59 |
+
"evidence": row['evidence']})
|
| 60 |
+
span = list(map(int, row["span"].split("-")))
|
| 61 |
+
detail[-1]['start'] = span[0]-1
|
| 62 |
+
detail[-1]['end'] = span[1]
|
| 63 |
+
yield idx, {"id": idx,
|
| 64 |
+
"protein": sequence,
|
| 65 |
+
"protein_id": entry,
|
| 66 |
+
"type": self.config.name,
|
| 67 |
+
"detail": detail
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
if __name__=="__main__":
|
| 72 |
+
from datasets import load_dataset
|
| 73 |
+
dataset = load_dataset("jolma_domains.py", split="all")
|