# 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. # TODO: Address all TODOs and remove all explanatory comments """Paired sequences from the Observed Antibody Space database""" import csv import json import os import datasets _CITATION = """\ @article{Olsen_Boyles_Deane_2022, title={Observed Antibody Space: A diverse database of cleaned, annotated, and translated unpaired and paired antibody sequences}, volume={31}, rights={© 2021 The Authors. Protein Science published by Wiley Periodicals LLC on behalf of The Protein Society.}, ISSN={1469-896X}, DOI={10.1002/pro.4205}, number={1}, journal={Protein Science}, author={Olsen, Tobias H. and Boyles, Fergus and Deane, Charlotte M.}, year={2022}, pages={141–146}, language={en} } """ _DESCRIPTION = """\ Paired heavy and light chain antibody sequences for multiple species. """ _HOMEPAGE = "https://opig.stats.ox.ac.uk/webapps/oas/" _LICENSE = "cc-by-4.0" _URL = "https://aws-hcls-ml.s3.amazonaws.com/oas-paired-sequence-data/" _URLS = { "human": _URL + "human.zip", "rat_SD": _URL + "rat_SD.zip", "mouse_BALB_c": _URL + "mouse_BALB_c.zip", "mouse_C57BL_6": _URL + "mouse_C57BL_6.zip", } _FEATURES = datasets.Features( { "sequence_id_heavy": datasets.Value("string"), "sequence_heavy": datasets.Value("string"), "locus_heavy": datasets.Value("string"), "stop_codon_heavy": datasets.Value("string"), "productive_heavy": datasets.Value("string"), "rev_comp_heavy": datasets.Value("string"), "sequence_alignment_aa_heavy": datasets.Value("string"), "fwr1_aa_heavy": datasets.Value("string"), "cdr1_aa_heavy": datasets.Value("string"), "fwr2_aa_heavy": datasets.Value("string"), "cdr2_aa_heavy": datasets.Value("string"), "fwr3_aa_heavy": datasets.Value("string"), "cdr3_aa_heavy": datasets.Value("string"), "junction_aa_heavy": datasets.Value("string"), "sequence_id_light": datasets.Value("string"), "sequence_light": datasets.Value("string"), "locus_light": datasets.Value("string"), "stop_codon_light": datasets.Value("string"), "productive_light": datasets.Value("string"), "rev_comp_light": datasets.Value("string"), "sequence_alignment_aa_light": datasets.Value("string"), "fwr1_aa_light": datasets.Value("string"), "cdr1_aa_light": datasets.Value("string"), "fwr2_aa_light": datasets.Value("string"), "cdr2_aa_light": datasets.Value("string"), "fwr3_aa_light": datasets.Value("string"), "cdr3_aa_light": datasets.Value("string"), "junction_aa_light": datasets.Value("string"), } ) class OasPairedSequenceData(datasets.GeneratorBasedBuilder): """OAS paired sequence data.""" VERSION = datasets.Version("1.1.0") # You will be able to load one or the other configurations in the following list with # data = datasets.load_dataset('my_dataset', 'first_domain') # data = datasets.load_dataset('my_dataset', 'second_domain') BUILDER_CONFIGS = [ datasets.BuilderConfig(name="human", version=VERSION, description="Human"), datasets.BuilderConfig(name="rat_SD", version=VERSION, description="rat_SD"), datasets.BuilderConfig( name="mouse_BALB_c", version=VERSION, description="mouse_BALB_c" ), datasets.BuilderConfig( name="mouse_C57BL_6", version=VERSION, description="mouse_C57BL_6" ), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=_FEATURES, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files. # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive urls = _URLS[self.config.name] data_dir = dl_manager.download_and_extract(urls) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ # "filepath": os.path.join(data_dir, "train.jsonl"), "filepath": data_dir, "split": "train", }, ), # datasets.SplitGenerator( # name=datasets.Split.VALIDATION, # # These kwargs will be passed to _generate_examples # gen_kwargs={ # "filepath": os.path.join(data_dir, "dev.jsonl"), # "split": "dev", # }, # ), # datasets.SplitGenerator( # name=datasets.Split.TEST, # # These kwargs will be passed to _generate_examples # gen_kwargs={ # "filepath": os.path.join(data_dir, "test.jsonl"), # "split": "test", # }, # ), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, filepath, split): # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset. # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. with open(filepath, encoding="utf-8") as f: for key, row in enumerate(f): data = json.loads(row) yield key, data # yield key, { # "sentence": data["sentence"], # "option2": data["option2"], # "second_domain_answer": "" # }