File size: 5,616 Bytes
bc4013d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a2c4c5
bc4013d
f0542de
bc4013d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91e178f
bc4013d
 
 
 
f0542de
 
5bb01b2
f0542de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc4013d
0ac491c
 
f0542de
 
 
 
 
 
 
 
 
 
bc4013d
0ac491c
f0542de
 
0ac491c
 
 
bc4013d
c13bce6
0ac491c
 
bc4013d
0ac491c
 
bc4013d
f0542de
 
bc4013d
 
0ac491c
 
 
 
 
 
 
 
 
f0542de
0ac491c
 
 
 
bc4013d
0ac491c
 
 
 
bc4013d
 
0ac491c
bc4013d
 
 
0ac491c
 
 
 
 
 
 
 
 
f0542de
bc4013d
0ac491c
 
 
f0542de
c13bce6
 
0ac491c
 
 
 
 
8a2c4c5
7f5e337
c13bce6
0ac491c
 
293a235
0ac491c
 
 
f0542de
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
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import json

import datasets
from datasets import BuilderConfig

# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@article{duan2024boosting,
  title={Boosting the Predictive Power of Protein Representations with a Corpus of Text Annotations},
  author={Duan, Haonan and Skreta, Marta and Cotta, Leonardo and Rajaonson, Ella Miray and Dhawan, Nikita and Aspuru-Guzik, Alán and Maddison, Chris J},
  journal={bioRxiv},
  pages={2024--07},
  year={2024},
  publisher={Cold Spring Harbor Laboratory}
}
"""

_DESCRIPTION = """\
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
"""

# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = ""

# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URLS = {
    "first_domain": "https://huggingface.co/datasets/mskrt/PAIR/raw/main/test.json",
}


# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
annotation2type = {
    "names": datasets.Value("string"),
    "function": datasets.Value("string"),
    "EC": datasets.Sequence(datasets.Value("string")),
}


class CustomConfig(datasets.BuilderConfig):
    """CustomConfig."""

    def __init__(self, **kwargs):
        """__init__.

        Parameters
        ----------
        kwargs :
            kwargs
        """
        self.annotation_type = kwargs.pop("annotation_type", "function")
        super(CustomConfig, self).__init__(**kwargs)


class PAIRDataset(datasets.GeneratorBasedBuilder):
    """PAIRDataset."""

    BUILDER_CONFIGS = [
        CustomConfig(
            name="custom_config",
            version="1.0.0",
            description="your description",
        ),
    ]  # Configs initialization
    BUILDER_CONFIG_CLASS = CustomConfig  # Must specify this to use custom config

    def _info(self):
        """_info."""
        self.annotation_type = self.config_kwargs["annotation_type"]
        # Confirm annotation_type is set before continuing
        return datasets.DatasetInfo(
            description="My custom dataset.",
            features=datasets.Features(
                {
                    self.annotation_type: annotation2type[self.annotation_type],
                    "sequence": datasets.Value("string"),
                    "pid": datasets.Value("string"),
                }
            ),
            supervised_keys=None,
        )
        # "annotation_type": datasets.Value("string"),
        # "annotation": datasets.Value("string"),

    def _split_generators(self, dl_manager):
        """_split_generators.

        Parameters
        ----------
        dl_manager :
            dl_manager
        """
        # Implement logic to download and extract data files
        # For simplicity, assume data_files is a dict with paths to your data
        print("in generator self.annotation", self.annotation_type)
        data_files = {
            "train": "train.json",
            "test": "test.json",
        }
        return [
            # datasets.SplitGenerator(
            #    name=datasets.Split.TRAIN,
            #    gen_kwargs={'filepath': data_files['train']},
            # ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"filepath": data_files["test"]},
            ),
        ]

    def _generate_examples(self, filepath):
        """_generate_examples.

        Parameters
        ----------
        filepath :
            filepath
        """
        # Implement your data reading logic here
        print("in generator 2 self.annotation", self.annotation_type)
        with open(filepath, encoding="utf-8") as f:
            data = json.load(f)
            counter = 0
            for idx, annotation_type in enumerate(data.keys()):
                print(annotation_type, self.annotation_type)
                if annotation_type != self.annotation_type:
                    continue
                # Parse your line into the appropriate fields
                samples = data[annotation_type]
                for idx_2, elem in enumerate(samples):
                    # example = parse_line_to_example(line)
                    if elem["content"] != [None]:
                        content = elem["content"][0]
                        # print(literal_eval(content), "done")
                        yield counter, {
                            "sequence": elem["seq"],
                            "pid": elem["pid"],
                            annotation_type: content,
                        }
                        counter += 1

                        # "annotation_type": annotation_type,