|
|
|
|
|
|
|
"""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 = "" |
|
|
|
_TASKS = ['poly_a', |
|
'splice_site' |
|
'lncrna', |
|
'chromatin_access' |
|
'promoter_strength', |
|
'gene_expression', |
|
] |
|
|
|
|
|
class AgroNtTasksConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for the Agro NT supervised learning tasks 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 AgroNtTasks(datasets.GeneratorBasedBuilder): |
|
"""GeneratorBasedBuilder for the Agro NT supervised learning tasks dataset.""" |
|
|
|
BUILDER_CONFIGS = [AgroNtTasksConfig(task=TASK) for TASK in _TASKS] |
|
|
|
DEFAULT_CONFIG_NAME = _TASKS[0] |
|
|
|
def _info(self): |
|
|
|
features = datasets.Features( |
|
{ |
|
"sequence": datasets.Value("string"), |
|
"name": datasets.Value("string"), |
|
"labels": 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(self.config.task + "/train.fa") |
|
test_file = dl_manager.download_and_extract(self.config.task + "/test.fa") |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": train_file, |
|
"split": "train", |
|
}, |
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": test_file, |
|
"split": "test" |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
key = 0 |
|
with open(filepath, 'r') as f: |
|
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, |
|
} |