File size: 4,869 Bytes
aa368ec
 
 
 
 
 
 
 
 
d09ca16
 
aa368ec
 
 
 
 
d09ca16
 
 
 
 
 
 
 
 
aa368ec
 
d09ca16
 
 
 
aa368ec
 
 
 
 
 
f0ff2ca
 
 
 
 
 
d9a5c5b
 
 
 
 
d09ca16
 
 
 
 
d9a5c5b
d09ca16
 
 
 
 
 
 
d9a5c5b
d09ca16
 
f0ff2ca
d9a5c5b
 
aa368ec
d09ca16
 
aa368ec
d9a5c5b
 
aa368ec
d9a5c5b
aa368ec
d09ca16
aa368ec
0d4bbc0
d9a5c5b
 
 
 
 
 
 
aa368ec
 
 
 
 
d09ca16
aa368ec
 
 
 
 
 
d09ca16
 
d9a5c5b
 
 
 
aa368ec
 
 
 
 
 
d09ca16
aa368ec
 
 
d09ca16
 
 
 
 
 
 
 
aa368ec
 
 
 
d09ca16
aa368ec
 
 
 
 
 
 
d09ca16
e32ab64
d09ca16
aa368ec
d09ca16
e32ab64
 
 
d09ca16
e32ab64
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: Address all TODOs and remove all explanatory comments
"""TODO: Add a description here."""


import csv
import json
import os
from typing import List
from Bio import SeqIO

import datasets


# TODO: Add BibTeX citation
_CITATION = ''
# """\
# @InProceedings{huggingface:dataset,
# title = {A great new dataset},
# author={huggingface, Inc.
# },
# year={2020}
# }
# """

_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.
"""


# TODO: Add the licence for the dataset here if you can find it
_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']


_TASK_NAME_TO_TYPE = {'poly_a':'binary',
                      'lncrna':'binary',
                      'splice_site':'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.
        """
        super().__init__(
            *args,
            name=f"{task_name}",
            **kwargs,
        )
        self.task,self.name = task_name.split(".")
        self.task_type = _TASK_NAME_TO_TYPE[self.task]


class AgroNtTasks(datasets.GeneratorBasedBuilder):
    """GeneratorBasedBuilder for the Agro NT supervised learning tasks dataset."""

    BUILDER_CONFIGS = [AgroNtTasksConfig(task_name=TASK_NAME) for TASK_NAME
                       in _TASK_NAMES]

    DEFAULT_CONFIG_NAME = _TASK_NAMES[0]

    def _info(self):

        if self.config.task_type == 'binary':
            features = datasets.Features(
                {
                    "sequence": datasets.Value("string"),
                    "name": datasets.Value("string"),
                    "labels": datasets.Value("int8"),
                }
            )

        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            features=features,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            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.name + "_train.fa"))
        test_file = dl_manager.download_and_extract(
            os.path.join(self.config.task, self.config.name + "_test.fa"))

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": train_file,
                    "split": "train",
                },
            ),
            # datasets.SplitGenerator(
            #     name=datasets.Split.VALIDATION,
            #     # These kwargs will be passed to _generate_examples
            #     gen_kwargs={
            #         "filepath": test_file,
            #         "split": "dev",
            #     },
            # ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": test_file,
                    "split": "test"
                },
            ),
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath, split):
        with open(filepath, 'r') as f:
            key = 0
            for record in SeqIO.parse(f,'fasta'):
                    # Yields examples as (key, example) tuples

                split_name = record.name.split("|")
                name = split_name[0]
                labels = split_name[1]

                yield key, {
                    "sequence": str(record.seq),
                    "name": name,
                    "labels": labels,
                }
                key += 1