|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Script for the dataset containing the 18 downstream tasks from the Nucleotide |
|
Transformer paper.""" |
|
|
|
from typing import List |
|
|
|
import datasets |
|
from datasets.utils import logging |
|
|
|
datasets.logging.set_verbosity(datasets.logging.WARNING) |
|
logger = logging.get_logger("datasets") |
|
|
|
|
|
|
|
|
|
|
|
def parse_fasta(fp): |
|
name, seq = None, [] |
|
for line in fp: |
|
line = line.rstrip() |
|
if line.startswith(">"): |
|
if name: |
|
|
|
yield (name[1:], "".join(seq)) |
|
name, seq = line, [] |
|
else: |
|
seq.append(line) |
|
if name: |
|
|
|
yield (name[1:], "".join(seq)) |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@article{dalla2023nucleotide, |
|
title={The Nucleotide Transformer: Building and Evaluating Robust Foundation Models for Human Genomics}, |
|
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}, |
|
journal={bioRxiv}, |
|
pages={2023--01}, |
|
year={2023}, |
|
publisher={Cold Spring Harbor Laboratory} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
The 18 classification downstream tasks from the Nucleotide Transformer paper. Each task |
|
corresponds to a dataset configuration. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/instadeepai/nucleotide-transformer" |
|
|
|
_LICENSE = "https://github.com/instadeepai/nucleotide-transformer/LICENSE.md" |
|
|
|
_TASKS = [ |
|
"H4ac", |
|
"H3K36me3", |
|
"splice_sites_donors", |
|
"splice_sites_acceptors", |
|
"H3", |
|
"H4", |
|
"H3K4me3", |
|
"splice_sites_all", |
|
"H3K4me1", |
|
"H3K14ac", |
|
"enhancers_types", |
|
"promoter_no_tata", |
|
"H3K79me3", |
|
"H3K4me2", |
|
"promoter_tata", |
|
"enhancers", |
|
"H3K9ac", |
|
"promoter_all", |
|
] |
|
|
|
|
|
class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for The Nucleotide Transformer downstream taks dataset.""" |
|
|
|
def __init__(self, *args, task: str, **kwargs): |
|
"""BuilderConfig downstream tasks dataset. |
|
Args: |
|
task (:obj:`str`): Task name. |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super().__init__( |
|
*args, |
|
name=f"{task}", |
|
**kwargs, |
|
) |
|
self.task = task |
|
|
|
|
|
|
|
class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.1.0") |
|
BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig |
|
BUILDER_CONFIGS = [ |
|
NucleotideTransformerDownstreamTasksConfig(task=task) for task in _TASKS |
|
] |
|
DEFAULT_CONFIG_NAME = "enhancers" |
|
|
|
def _info(self): |
|
|
|
features = datasets.Features( |
|
{ |
|
"sequence": datasets.Value("string"), |
|
"name": datasets.Value("string"), |
|
"label": datasets.Value("int32"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators( |
|
self, dl_manager: datasets.DownloadManager |
|
) -> List[datasets.SplitGenerator]: |
|
|
|
|
|
train_file = dl_manager.download_and_extract(self.config.task + "/train.fna") |
|
test_file = dl_manager.download_and_extract(self.config.task + "/test.fna") |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, gen_kwargs={"file": train_file} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, gen_kwargs={"file": test_file} |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, file): |
|
|
|
logger.warning(""" |
|
|
|
WARNING: Please note that the Nucleotide Transformer benchmark datasets have been revised |
|
during the per-review process. This version is deprecated and the new datasets are available at |
|
InstaDeepAI/nucleotide_transformer_downstream_tasks_revised. |
|
|
|
""") |
|
key = 0 |
|
with open(file, "rt") as f: |
|
fasta_sequences = parse_fasta(f) |
|
|
|
for name, seq in fasta_sequences: |
|
|
|
|
|
sequence, name = str(seq), str(name) |
|
label = int(name.split("|")[-1]) |
|
|
|
|
|
yield key, { |
|
"sequence": sequence, |
|
"name": name, |
|
"label": label, |
|
} |
|
key += 1 |
|
|