Delete nucleotide_transformer_downstream_tasks.py
Browse files
nucleotide_transformer_downstream_tasks.py
DELETED
@@ -1,181 +0,0 @@
|
|
1 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script
|
2 |
-
# contributor.
|
3 |
-
#
|
4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
# you may not use this file except in compliance with the License.
|
6 |
-
# You may obtain a copy of the License at
|
7 |
-
#
|
8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
#
|
10 |
-
# Unless required by applicable law or agreed to in writing, software
|
11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
# See the License for the specific language governing permissions and
|
14 |
-
# limitations under the License.
|
15 |
-
"""Script for the dataset containing the 18 downstream tasks from the Nucleotide
|
16 |
-
Transformer paper."""
|
17 |
-
|
18 |
-
from typing import List
|
19 |
-
|
20 |
-
import datasets
|
21 |
-
from datasets.utils import logging
|
22 |
-
|
23 |
-
datasets.logging.set_verbosity(datasets.logging.WARNING)
|
24 |
-
logger = logging.get_logger("datasets")
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
# This function is a basic reimplementation of SeqIO's parse method. This allows the
|
29 |
-
# dataset viewer to work as it does not require an external package.
|
30 |
-
def parse_fasta(fp):
|
31 |
-
name, seq = None, []
|
32 |
-
for line in fp:
|
33 |
-
line = line.rstrip()
|
34 |
-
if line.startswith(">"):
|
35 |
-
if name:
|
36 |
-
# Slice to remove '>'
|
37 |
-
yield (name[1:], "".join(seq))
|
38 |
-
name, seq = line, []
|
39 |
-
else:
|
40 |
-
seq.append(line)
|
41 |
-
if name:
|
42 |
-
# Slice to remove '>'
|
43 |
-
yield (name[1:], "".join(seq))
|
44 |
-
|
45 |
-
|
46 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
47 |
-
_CITATION = """\
|
48 |
-
@article{dalla2023nucleotide,
|
49 |
-
title={The Nucleotide Transformer: Building and Evaluating Robust Foundation Models for Human Genomics},
|
50 |
-
author={Dalla-Torre, Hugo and Gonzalez, Liam and Mendoza-Revilla, Javier and Carranza, Nicolas Lopez and Grzywaczewski, Adam Henryk and Oteri, Francesco and Dallago, Christian and Trop, Evan and Sirelkhatim, Hassan and Richard, Guillaume and others},
|
51 |
-
journal={bioRxiv},
|
52 |
-
pages={2023--01},
|
53 |
-
year={2023},
|
54 |
-
publisher={Cold Spring Harbor Laboratory}
|
55 |
-
}
|
56 |
-
"""
|
57 |
-
|
58 |
-
# You can copy an official description
|
59 |
-
_DESCRIPTION = """\
|
60 |
-
The 18 classification downstream tasks from the Nucleotide Transformer paper. Each task
|
61 |
-
corresponds to a dataset configuration.
|
62 |
-
"""
|
63 |
-
|
64 |
-
_HOMEPAGE = "https://github.com/instadeepai/nucleotide-transformer"
|
65 |
-
|
66 |
-
_LICENSE = "https://github.com/instadeepai/nucleotide-transformer/LICENSE.md"
|
67 |
-
|
68 |
-
_TASKS = [
|
69 |
-
"H4ac",
|
70 |
-
"H3K36me3",
|
71 |
-
"splice_sites_donors",
|
72 |
-
"splice_sites_acceptors",
|
73 |
-
"H3",
|
74 |
-
"H4",
|
75 |
-
"H3K4me3",
|
76 |
-
"splice_sites_all",
|
77 |
-
"H3K4me1",
|
78 |
-
"H3K14ac",
|
79 |
-
"enhancers_types",
|
80 |
-
"promoter_no_tata",
|
81 |
-
"H3K79me3",
|
82 |
-
"H3K4me2",
|
83 |
-
"promoter_tata",
|
84 |
-
"enhancers",
|
85 |
-
"H3K9ac",
|
86 |
-
"promoter_all",
|
87 |
-
]
|
88 |
-
|
89 |
-
|
90 |
-
class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
|
91 |
-
"""BuilderConfig for The Nucleotide Transformer downstream taks dataset."""
|
92 |
-
|
93 |
-
def __init__(self, *args, task: str, **kwargs):
|
94 |
-
"""BuilderConfig downstream tasks dataset.
|
95 |
-
Args:
|
96 |
-
task (:obj:`str`): Task name.
|
97 |
-
**kwargs: keyword arguments forwarded to super.
|
98 |
-
"""
|
99 |
-
super().__init__(
|
100 |
-
*args,
|
101 |
-
name=f"{task}",
|
102 |
-
**kwargs,
|
103 |
-
)
|
104 |
-
self.task = task
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
|
109 |
-
VERSION = datasets.Version("1.1.0")
|
110 |
-
BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig
|
111 |
-
BUILDER_CONFIGS = [
|
112 |
-
NucleotideTransformerDownstreamTasksConfig(task=task) for task in _TASKS
|
113 |
-
]
|
114 |
-
DEFAULT_CONFIG_NAME = "enhancers"
|
115 |
-
|
116 |
-
def _info(self):
|
117 |
-
|
118 |
-
features = datasets.Features(
|
119 |
-
{
|
120 |
-
"sequence": datasets.Value("string"),
|
121 |
-
"name": datasets.Value("string"),
|
122 |
-
"label": datasets.Value("int32"),
|
123 |
-
}
|
124 |
-
)
|
125 |
-
return datasets.DatasetInfo(
|
126 |
-
# This is the description that will appear on the datasets page.
|
127 |
-
description=_DESCRIPTION,
|
128 |
-
# This defines the different columns of the dataset and their types
|
129 |
-
features=features,
|
130 |
-
# Homepage of the dataset for documentation
|
131 |
-
homepage=_HOMEPAGE,
|
132 |
-
# License for the dataset if available
|
133 |
-
license=_LICENSE,
|
134 |
-
# Citation for the dataset
|
135 |
-
citation=_CITATION,
|
136 |
-
)
|
137 |
-
|
138 |
-
def _split_generators(
|
139 |
-
self, dl_manager: datasets.DownloadManager
|
140 |
-
) -> List[datasets.SplitGenerator]:
|
141 |
-
|
142 |
-
|
143 |
-
train_file = dl_manager.download_and_extract(self.config.task + "/train.fna")
|
144 |
-
test_file = dl_manager.download_and_extract(self.config.task + "/test.fna")
|
145 |
-
|
146 |
-
return [
|
147 |
-
datasets.SplitGenerator(
|
148 |
-
name=datasets.Split.TRAIN, gen_kwargs={"file": train_file}
|
149 |
-
),
|
150 |
-
datasets.SplitGenerator(
|
151 |
-
name=datasets.Split.TEST, gen_kwargs={"file": test_file}
|
152 |
-
),
|
153 |
-
]
|
154 |
-
|
155 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
156 |
-
def _generate_examples(self, file):
|
157 |
-
|
158 |
-
logger.warning("""
|
159 |
-
|
160 |
-
WARNING: Please note that the Nucleotide Transformer benchmark datasets have been revised
|
161 |
-
during the per-review process. This version is deprecated and the new datasets are available at
|
162 |
-
InstaDeepAI/nucleotide_transformer_downstream_tasks_revised.
|
163 |
-
|
164 |
-
""")
|
165 |
-
key = 0
|
166 |
-
with open(file, "rt") as f:
|
167 |
-
fasta_sequences = parse_fasta(f)
|
168 |
-
|
169 |
-
for name, seq in fasta_sequences:
|
170 |
-
|
171 |
-
# parse descriptions in the fasta file
|
172 |
-
sequence, name = str(seq), str(name)
|
173 |
-
label = int(name.split("|")[-1])
|
174 |
-
|
175 |
-
# yield example
|
176 |
-
yield key, {
|
177 |
-
"sequence": sequence,
|
178 |
-
"name": name,
|
179 |
-
"label": label,
|
180 |
-
}
|
181 |
-
key += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|