Download oas-paired-sequence-data.py from bloyal/oas-paired-sequence-data: direct link, hf CLI and curl.
- Browser
- Download file 4.39 kB
-
https://huggingface.co/datasets/bloyal/oas-paired-sequence-data/resolve/387dcad1082e2d40cb7bf8775430595c36035070/oas-paired-sequence-data.py
- Command line
-
hf download hf://datasets/bloyal/oas-paired-sequence-data@387dcad1082e2d40cb7bf8775430595c36035070/oas-paired-sequence-data.py
-
curl -L -o oas-paired-sequence-data.py https://huggingface.co/datasets/bloyal/oas-paired-sequence-data/resolve/387dcad1082e2d40cb7bf8775430595c36035070/oas-paired-sequence-data.py
4.39 kB
| #!/usr/bin/env python | |
| # coding=utf-8 | |
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
| # SPDX-License-Identifier: MIT-0 | |
| """Paired sequences from the Observed Antibody Space database""" | |
| import csv | |
| import datasets | |
| import os | |
| _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" | |
| _BASE_URL = "https://aws-hcls-ml.s3.amazonaws.com/oas-paired-sequence-data/" | |
| _URLS = { | |
| "human": _BASE_URL + "human.zip", | |
| "rat_SD": _BASE_URL + "rat_SD.zip", | |
| "mouse_BALB_c": _BASE_URL + "mouse_BALB_c.zip", | |
| "mouse_C57BL_6": _BASE_URL + "mouse_C57BL_6.zip", | |
| } | |
| _FEATURES = datasets.Features( | |
| { | |
| "pair_id": datasets.Value("string"), | |
| "sequence_alignment_aa_heavy": datasets.Value("string"), | |
| "sequence_alignment_aa_light": datasets.Value("string"), | |
| "cdr1_aa_heavy_start": datasets.Value("int16"), | |
| "cdr1_aa_heavy_end": datasets.Value("int16"), | |
| "cdr1_aa_light_start": datasets.Value("int16"), | |
| "cdr1_aa_light_end": datasets.Value("int16"), | |
| "cdr2_aa_heavy_start": datasets.Value("int16"), | |
| "cdr2_aa_heavy_end": datasets.Value("int16"), | |
| "cdr2_aa_light_start": datasets.Value("int16"), | |
| "cdr2_aa_light_end": datasets.Value("int16"), | |
| "cdr3_aa_heavy_start": datasets.Value("int16"), | |
| "cdr3_aa_heavy_end": datasets.Value("int16"), | |
| "cdr3_aa_light_start": datasets.Value("int16"), | |
| "cdr3_aa_light_end": datasets.Value("int16"), | |
| } | |
| ) | |
| class OasPairedSequenceData(datasets.GeneratorBasedBuilder): | |
| """OAS paired sequence data.""" | |
| VERSION = datasets.Version("1.1.0") | |
| 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): | |
| urls = _URLS[self.config.name] | |
| data_dir = dl_manager.download_and_extract(urls) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={ | |
| "filepath": os.path.join(data_dir, "train.csv"), | |
| "split": "train", | |
| }, | |
| ), | |
| ] | |
| def _generate_examples(self, filepath, split): | |
| with open(filepath, newline="") as f: | |
| reader = csv.reader(f, delimiter=",") | |
| for key, row in enumerate(reader): | |
| if key == 0: | |
| continue | |
| yield key, { | |
| "pair_id": row[0], | |
| "sequence_alignment_aa_heavy": row[1], | |
| "sequence_alignment_aa_light": row[2], | |
| "cdr1_aa_heavy_start": row[3], | |
| "cdr1_aa_heavy_end": row[4], | |
| "cdr1_aa_light_start": row[5], | |
| "cdr1_aa_light_end": row[6], | |
| "cdr2_aa_heavy_start": row[7], | |
| "cdr2_aa_heavy_end": row[8], | |
| "cdr2_aa_light_start": row[9], | |
| "cdr2_aa_light_end": row[10], | |
| "cdr3_aa_heavy_start": row[11], | |
| "cdr3_aa_heavy_end": row[12], | |
| "cdr3_aa_light_start": row[13], | |
| "cdr3_aa_light_end": row[14], | |
| } | |