|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
from typing import List |
|
from Bio import SeqIO |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
This dataset comprises the various supervised learning tasks considered in the agro-nt |
|
paper. The task types include binary classification,multi-label classification, |
|
regression,and multi-output regression. The actual underlying genomic tasks range from |
|
predicting regulatory features, RNA processing sites, and gene expression values. |
|
""" |
|
|
|
|
|
|
|
_LICENSE = "" |
|
|
|
_TASK_NAMES = ['poly_a.arabidopsis_thaliana', |
|
'poly_a.oryza_sativa_indica_group', |
|
'poly_a.trifolium_pratense', |
|
'poly_a.medicago_truncatula', |
|
'poly_a.chlamydomonas_reinhardtii', |
|
'poly_a.oryza_sativa_japonica_group', |
|
'splicing.arabidopsis_thaliana_donor', |
|
'splicing.arabidopsis_thaliana_acceptor' |
|
] |
|
|
|
|
|
_TASK_NAME_TO_TYPE = {'poly_a':'binary', |
|
'lncrna':'binary', |
|
'splicing':'binary',} |
|
|
|
|
|
class AgroNtTasksConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for the Agro NT supervised learning tasks dataset.""" |
|
|
|
def __init__(self, *args, task_name: str, **kwargs): |
|
"""BuilderConfig downstream tasks dataset. |
|
Args: |
|
task (:obj:`str`): Task name. |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
|
|
self.task,self.sub_task = task_name.split(".") |
|
self.task_type = _TASK_NAME_TO_TYPE[self.task] |
|
|
|
super().__init__( |
|
*args, |
|
name=f"{task_name}", |
|
**kwargs, |
|
) |
|
|
|
|
|
class AgroNtTasks(datasets.GeneratorBasedBuilder): |
|
"""GeneratorBasedBuilder for the Agro NT supervised learning tasks dataset.""" |
|
|
|
BUILDER_CONFIG_CLASS = AgroNtTasksConfig |
|
VERSION = datasets.Version("1.1.0") |
|
|
|
BUILDER_CONFIGS = [AgroNtTasksConfig(task_name=TASK_NAME) for TASK_NAME |
|
in _TASK_NAMES] |
|
|
|
def _info(self): |
|
|
|
if self.config.task_type == 'binary': |
|
features = datasets.Features( |
|
{ |
|
"sequence": datasets.Value("string"), |
|
"name": datasets.Value("string"), |
|
"label": datasets.Value("int8"), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]: |
|
|
|
train_file = dl_manager.download_and_extract( |
|
os.path.join(self.config.task, self.config.sub_task + "_train.fa")) |
|
test_file = dl_manager.download_and_extract( |
|
os.path.join(self.config.task, self.config.sub_task + "_test.fa")) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": train_file, |
|
}, |
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": test_file, |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath): |
|
with open(filepath, 'r') as f: |
|
key = 0 |
|
for record in SeqIO.parse(f,'fasta'): |
|
|
|
|
|
split_name = record.name.split("|") |
|
name = split_name[0] |
|
labels = split_name[1] |
|
|
|
yield key, { |
|
"sequence": str(record.seq), |
|
"name": name, |
|
"label": labels, |
|
} |
|
key += 1 |