| import json |
|
|
| import datasets |
|
|
| _CITATION = """\ |
| """ |
| _DESCRIPTION = """\ |
| SwissIPG dataset containing three subsets: GO, IPR, and IPR_GO, |
| each with training and test sets. |
| """ |
|
|
|
|
| class SwissProtIPG(datasets.GeneratorBasedBuilder): |
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig( |
| name="GO", |
| version=datasets.Version("1.0.0"), |
| description="GO subset", |
| ), |
| datasets.BuilderConfig( |
| name="IPR", |
| version=datasets.Version("1.0.0"), |
| description="IPR subset", |
| ), |
| datasets.BuilderConfig( |
| name="IPR_GO", |
| version=datasets.Version("1.0.0"), |
| description="IPR+GO subset", |
| ), |
| ] |
|
|
| def _info(self): |
| if self.config.name == "GO": |
| features = datasets.Features( |
| { |
| "Gene Ontology (molecular function)": datasets.Sequence( |
| { |
| "GO-ID": datasets.Value("string"), |
| "GO-Name": datasets.Value("string"), |
| } |
| ), |
| "sequence": datasets.Value("string"), |
| "instruction": datasets.Value("string"), |
| } |
| ) |
| elif self.config.name == "IPR": |
| features = datasets.Features( |
| { |
| "InterPro": datasets.Sequence( |
| { |
| "InterPro-ID": datasets.Value("string"), |
| "InterPro-Name": datasets.Value("string"), |
| "InterPro-Type": datasets.Value("string"), |
| "Beg": datasets.Value("int32"), |
| "End": datasets.Value("int32"), |
| } |
| ), |
| "sequence": datasets.Value("string"), |
| "instruction": datasets.Value("string"), |
| } |
| ) |
| else: |
| features = datasets.Features( |
| { |
| "Gene Ontology (molecular function)": datasets.Sequence( |
| { |
| "GO-ID": datasets.Value("string"), |
| "GO-Name": datasets.Value("string"), |
| } |
| ), |
| "InterPro": datasets.Sequence( |
| { |
| "InterPro-ID": datasets.Value("string"), |
| "InterPro-Name": datasets.Value("string"), |
| "InterPro-Type": datasets.Value("string"), |
| "Beg": datasets.Value("int32"), |
| "End": datasets.Value("int32"), |
| } |
| ), |
| "sequence": datasets.Value("string"), |
| "instruction": datasets.Value("string"), |
| } |
| ) |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| supervised_keys=None, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| if self.config.name == "GO": |
| train_file = dl_manager.download_and_extract("go_train.json") |
| test_file = dl_manager.download_and_extract("go_test.json") |
| elif self.config.name == "IPR": |
| train_file = dl_manager.download_and_extract("ipr_train.json") |
| test_file = dl_manager.download_and_extract("ipr_test.json") |
| elif self.config.name == "IPR_GO": |
| train_file = dl_manager.download_and_extract("ipr_go_train.json") |
| test_file = dl_manager.download_and_extract("ipr_go_test.json") |
| else: |
| raise ValueError(f"Invalid config: {self.config.name}") |
|
|
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={"filepath": train_file}, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={"filepath": test_file}, |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath): |
| with open(filepath, encoding="utf-8") as f: |
| data = json.load(f) |
| for i, row in enumerate(data): |
| yield i, row |
|
|