Datasets:

DOI:
License:
File size: 8,102 Bytes
aa368ec
 
 
 
 
d09ca16
aa368ec
 
 
7c458e8
 
 
 
 
 
 
 
 
 
aa368ec
 
d09ca16
 
 
 
aa368ec
 
 
7c458e8
aa368ec
7b16ac4
 
 
 
 
28ad444
 
80d022d
 
 
 
 
 
09b0610
 
1fa8db8
80dbee5
 
1fa8db8
 
 
 
16c544d
 
 
03a1ac1
 
 
 
3becf23
 
d9a5c5b
 
2264fac
 
 
 
80dbee5
6292cb9
3becf23
 
2264fac
d09ca16
edc9e3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d09ca16
 
 
d9a5c5b
d09ca16
 
 
 
 
890bc32
28ad444
1fa8db8
da8a9f3
 
890bc32
d09ca16
 
d9a5c5b
d09ca16
 
d9a5c5b
aa368ec
d09ca16
 
aa368ec
7221e0e
e4c92fb
7221e0e
d9a5c5b
 
aa368ec
d09ca16
aa368ec
6292cb9
 
 
0d4bbc0
6292cb9
2264fac
6292cb9
1fa8db8
6292cb9
03a1ac1
 
1fa8db8
6292cb9
16c544d
aa368ec
 
 
 
d09ca16
aa368ec
 
 
 
 
 
d09ca16
 
d9a5c5b
28ad444
d9a5c5b
28ad444
aa368ec
2264fac
aa368ec
 
 
 
d09ca16
aa368ec
 
 
 
 
 
d09ca16
aa368ec
 
 
 
2264fac
 
 
 
 
 
 
 
 
 
 
 
 
 
aa368ec
28ad444
edc9e3d
 
d09ca16
b1a8e77
edc9e3d
 
 
 
 
 
 
e32ab64
debf5c6
 
 
 
edc9e3d
debf5c6
474b727
debf5c6
 
 
edc9e3d
debf5c6
 
 
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# See the License for the specific language governing permissions and
# limitations under the License.


import os
from typing import List
import datasets


_CITATION = '''\
@article{mendoza2023foundational,
  title={A Foundational Large Language Model for Edible Plant Genomes},
  author={Mendoza-Revilla, Javier and Trop, Evan and Gonzalez, Liam and Roller, Masa and Dalla-Torre, Hugo and de Almeida, Bernardo P and Richard, Guillaume and Caton, Jonathan and Lopez Carranza, Nicolas and Skwark, Marcin and others},
  journal={bioRxiv},
  pages={2023--10},
  year={2023},
  publisher={Cold Spring Harbor Laboratory}
}
'''

_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 = "https://huggingface.co/datasets/InstaDeepAI/plant-genomic-benchmark/blob/main/LICENSE.md"

_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',
                'terminator_strength.leaf',
                'terminator_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},
              'terminator_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}
              }


# This function is a basic reimplementation of SeqIO's parse method. This allows the
# dataset viewer to work as it does not require an external package.
def parse_fasta(fp):
    name, seq = None, []
    for line in fp:
        line = line.rstrip()
        if line.startswith(">"):
            if name:
                # Slice to remove '>'
                yield (name[1:], "".join(seq))
            name, seq = line, []
        else:
            seq.append(line)
    if name:
        # Slice to remove '>'
        yield (name[1:], "".join(seq))
        

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(
            # 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.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,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": train_file,
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                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,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": validation_file,
                },
            ),

        return generator_list

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath):
        
        key = 0

        with open(filepath, "rt") as f:
            fasta_sequences = parse_fasta(f)
        
            for name, seq in fasta_sequences:
                # Yields examples as (key, example) tuples
                sequence, name = str(seq), str(name)
                
                split_name = name.split("|")
                name = split_name[0]
                labels = split_name[1:]

                if 'multi' in self.config.task_type:
                    yield key, {
                        "sequence": sequence,
                        "name": name,
                        "labels": labels
                    }
                else:
                    yield key, {
                        "sequence": sequence,
                        "name": name,
                        "label": labels[0],
                    }
                key += 1