fm4bio-ning
commited on
Upload GUE.py
Browse files
GUE.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Script for the dataset containing the 28 downstream tasks from the DNABertv2 paper."""
|
2 |
+
|
3 |
+
from typing import List
|
4 |
+
import csv
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
|
8 |
+
# This function is a basic reimplementation of SeqIO's parse method. This allows the
|
9 |
+
# dataset viewer to work as it does not require an external package.
|
10 |
+
|
11 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
12 |
+
_CITATION = ''
|
13 |
+
|
14 |
+
# You can copy an official description
|
15 |
+
_DESCRIPTION = ''
|
16 |
+
|
17 |
+
_HOMEPAGE = ""
|
18 |
+
|
19 |
+
_LICENSE = ""
|
20 |
+
|
21 |
+
_TASKS = [
|
22 |
+
"splice/reconstructed",
|
23 |
+
"mouse/0",
|
24 |
+
"mouse/1"
|
25 |
+
]
|
26 |
+
|
27 |
+
|
28 |
+
class GUEConfig(datasets.BuilderConfig):
|
29 |
+
"""BuilderConfig for GUE taks dataset."""
|
30 |
+
|
31 |
+
def __init__(self, *args, task: str, **kwargs):
|
32 |
+
"""BuilderConfig downstream tasks dataset.
|
33 |
+
Args:
|
34 |
+
task (:obj:`str`): Task name.
|
35 |
+
**kwargs: keyword arguments forwarded to super.
|
36 |
+
"""
|
37 |
+
super().__init__(
|
38 |
+
*args,
|
39 |
+
name=f"{task}",
|
40 |
+
**kwargs,
|
41 |
+
)
|
42 |
+
self.task = task
|
43 |
+
|
44 |
+
|
45 |
+
class GUEDownstreamTasks(datasets.GeneratorBasedBuilder):
|
46 |
+
VERSION = datasets.Version("1.1.0")
|
47 |
+
BUILDER_CONFIG_CLASS = GUEConfig
|
48 |
+
BUILDER_CONFIGS = [
|
49 |
+
GUEConfig(task=task) for task in _TASKS
|
50 |
+
]
|
51 |
+
DEFAULT_CONFIG_NAME = "reconstructed"
|
52 |
+
|
53 |
+
def _info(self):
|
54 |
+
|
55 |
+
features = datasets.Features(
|
56 |
+
{
|
57 |
+
"sequence": datasets.Value("string"),
|
58 |
+
"label": datasets.Value("int32"),
|
59 |
+
}
|
60 |
+
)
|
61 |
+
return datasets.DatasetInfo(
|
62 |
+
# This is the description that will appear on the datasets page.
|
63 |
+
description=_DESCRIPTION,
|
64 |
+
# This defines the different columns of the dataset and their types
|
65 |
+
features=features,
|
66 |
+
# Homepage of the dataset for documentation
|
67 |
+
homepage=_HOMEPAGE,
|
68 |
+
# License for the dataset if available
|
69 |
+
license=_LICENSE,
|
70 |
+
# Citation for the dataset
|
71 |
+
citation=_CITATION,
|
72 |
+
)
|
73 |
+
|
74 |
+
def _split_generators(
|
75 |
+
self, dl_manager: datasets.DownloadManager
|
76 |
+
) -> List[datasets.SplitGenerator]:
|
77 |
+
|
78 |
+
train_file = dl_manager.download_and_extract(self.config.task + "/train.csv")
|
79 |
+
valid_file = dl_manager.download_and_extract(self.config.task + "/dev.csv")
|
80 |
+
test_file = dl_manager.download_and_extract(self.config.task + "/test.csv")
|
81 |
+
|
82 |
+
return [
|
83 |
+
datasets.SplitGenerator(
|
84 |
+
name=datasets.Split.TRAIN, gen_kwargs={"file": train_file}
|
85 |
+
),
|
86 |
+
datasets.SplitGenerator(
|
87 |
+
name=datasets.Split.VALIDATION, gen_kwargs={"file": valid_file}
|
88 |
+
),
|
89 |
+
datasets.SplitGenerator(
|
90 |
+
name=datasets.Split.TEST, gen_kwargs={"file": test_file}
|
91 |
+
),
|
92 |
+
]
|
93 |
+
|
94 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
95 |
+
def _generate_examples(self, file):
|
96 |
+
key = 0
|
97 |
+
with open(file, "rt") as f:
|
98 |
+
csv_reader = csv.reader(f)
|
99 |
+
head = next(csv_reader)
|
100 |
+
for sequence, label in csv_reader:
|
101 |
+
# yield example
|
102 |
+
yield key, {
|
103 |
+
"sequence": sequence,
|
104 |
+
"label": label,
|
105 |
+
}
|
106 |
+
key += 1
|
107 |
+
|