|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
|
|
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', |
|
'lncrna.m_esculenta', |
|
'lncrna.z_mays', |
|
'lncrna.g_max', |
|
'lncrna.s_lycopersicum', |
|
'lncrna.t_aestivum', |
|
'lncrna.s_bicolor', |
|
'promoter_strength.leaf', |
|
'promoter_strength.protoplast', |
|
'gene_exp.glycine_max', |
|
'gene_exp.oryza_sativa', |
|
'gene_exp.solanum_lycopersicum', |
|
'gene_exp.zea_mays', |
|
'gene_exp.arabidopsis_thaliana', |
|
'chromatin_access.oryza_sativa_MH63_RS2', |
|
'chromatin_access.setaria_italica', |
|
'chromatin_access.oryza_sativa_ZS97_RS2', |
|
'chromatin_access.arabidopis_thaliana', |
|
'chromatin_access.brachypodium_distachyon', |
|
'chromatin_access.sorghum_bicolor', |
|
'chromatin_access.zea_mays', |
|
'pro_seq.m_esculenta'] |
|
|
|
|
|
_TASK_INFO = {'poly_a':{'type': 'binary', 'val_set':False}, |
|
'splicing':{'type': 'binary', 'val_set':False}, |
|
'lncrna':{'type': 'binary', 'val_set':False}, |
|
'promoter_strength': {'type': 'regression', 'val_set': True}, |
|
'gene_exp':{'type':'multi_regression','val_set':True}, |
|
'chromatin_access':{'type':'multi_label','val_set':True}, |
|
'pro_seq':{'type':'binary','val_set':True} |
|
} |
|
|
|
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_INFO[self.task]['type'] |
|
self.val_set = _TASK_INFO[self.task]['val_set'] |
|
|
|
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): |
|
|
|
feature_dit = {"sequence": datasets.Value("string"), |
|
"name": datasets.Value("string")} |
|
|
|
if self.config.task_type == 'binary': |
|
feature_dit["label"] = datasets.Value("int8") |
|
elif self.config.task_type == 'regression': |
|
feature_dit["label"] = datasets.Value("float32") |
|
elif self.config.task_type == 'multi_regression': |
|
feature_dit['labels'] = [datasets.Value("float32")] |
|
elif self.config.task_type == 'multi_label': |
|
feature_dit['labels'] = [datasets.Value("int8")] |
|
|
|
features = datasets.Features(feature_dit) |
|
|
|
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")) |
|
|
|
generator_list = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": train_file, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": test_file, |
|
}, |
|
), |
|
] |
|
|
|
if self.config.val_set: |
|
validation_file = dl_manager.download_and_extract( |
|
os.path.join(self.config.task, self.config.sub_task + "_validation.fa")) |
|
|
|
generator_list += datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": validation_file, |
|
}, |
|
), |
|
|
|
return generator_list |
|
|
|
|
|
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:] |
|
|
|
if 'multi' in self.config.task_type: |
|
yield key, { |
|
"sequence": str(record.seq), |
|
"name": name, |
|
"labels": labels |
|
} |
|
else: |
|
yield key, { |
|
"sequence": str(record.seq), |
|
"name": name, |
|
"label": labels[0], |
|
} |
|
key += 1 |