EC2 Default User commited on
Commit ·
b85c835
1
Parent(s): 5e6d689
Update loading script
Browse files- oas-paired-sequence-data.py +68 -27
oas-paired-sequence-data.py
CHANGED
|
@@ -4,8 +4,11 @@
|
|
| 4 |
# SPDX-License-Identifier: MIT-0
|
| 5 |
"""Paired sequences from the Observed Antibody Space database"""
|
| 6 |
import datasets
|
| 7 |
-
import
|
|
|
|
|
|
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
_CITATION = """\
|
| 11 |
@article{Olsen_Boyles_Deane_2022,
|
|
@@ -23,14 +26,14 @@ Paired heavy and light chain antibody sequences for multiple species.
|
|
| 23 |
_HOMEPAGE = "https://opig.stats.ox.ac.uk/webapps/oas/"
|
| 24 |
|
| 25 |
_LICENSE = "cc-by-4.0"
|
| 26 |
-
_BASE_URL = "https://aws-hcls-ml.s3.amazonaws.com/oas-paired-sequence-data/
|
| 27 |
|
| 28 |
-
_URLS = {
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
}
|
| 34 |
_FEATURES = datasets.Features(
|
| 35 |
{
|
| 36 |
"sequence_alignment_aa_heavy": datasets.Value("string"),
|
|
@@ -50,7 +53,7 @@ class OasPairedSequenceData(datasets.GeneratorBasedBuilder):
|
|
| 50 |
|
| 51 |
VERSION = datasets.Version("1.2.0")
|
| 52 |
BUILDER_CONFIGS = [
|
| 53 |
-
datasets.BuilderConfig(name="human", version=VERSION, description="human"),
|
| 54 |
datasets.BuilderConfig(name="rat_SD", version=VERSION, description="rat_SD"),
|
| 55 |
datasets.BuilderConfig(
|
| 56 |
name="mouse_BALB_c", version=VERSION, description="mouse_BALB_c"
|
|
@@ -69,32 +72,70 @@ class OasPairedSequenceData(datasets.GeneratorBasedBuilder):
|
|
| 69 |
citation=_CITATION,
|
| 70 |
)
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def _split_generators(self, dl_manager):
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
return [
|
| 76 |
datasets.SplitGenerator(
|
| 77 |
name=datasets.Split.TRAIN,
|
| 78 |
gen_kwargs={
|
| 79 |
-
"filepath":
|
| 80 |
"split": "train",
|
| 81 |
},
|
| 82 |
),
|
| 83 |
]
|
| 84 |
|
| 85 |
-
def _generate_examples(self,
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
|
|
|
|
| 4 |
# SPDX-License-Identifier: MIT-0
|
| 5 |
"""Paired sequences from the Observed Antibody Space database"""
|
| 6 |
import datasets
|
| 7 |
+
import gzip
|
| 8 |
+
|
| 9 |
+
# import pandas as pd
|
| 10 |
import os
|
| 11 |
+
import csv
|
| 12 |
|
| 13 |
_CITATION = """\
|
| 14 |
@article{Olsen_Boyles_Deane_2022,
|
|
|
|
| 26 |
_HOMEPAGE = "https://opig.stats.ox.ac.uk/webapps/oas/"
|
| 27 |
|
| 28 |
_LICENSE = "cc-by-4.0"
|
| 29 |
+
_BASE_URL = "https://aws-hcls-ml.s3.amazonaws.com/oas-paired-sequence-data/raw/"
|
| 30 |
|
| 31 |
+
# _URLS = {
|
| 32 |
+
# "human": _BASE_URL + "human.tar.gz",
|
| 33 |
+
# "rat_SD": _BASE_URL + "rat_SD.tar.gz",
|
| 34 |
+
# "mouse_BALB_c": _BASE_URL + "mouse_BALB_c.tar.gz",
|
| 35 |
+
# "mouse_C57BL_6": _BASE_URL + "mouse_C57BL_6.tar.gz",
|
| 36 |
+
# }
|
| 37 |
_FEATURES = datasets.Features(
|
| 38 |
{
|
| 39 |
"sequence_alignment_aa_heavy": datasets.Value("string"),
|
|
|
|
| 53 |
|
| 54 |
VERSION = datasets.Version("1.2.0")
|
| 55 |
BUILDER_CONFIGS = [
|
| 56 |
+
# datasets.BuilderConfig(name="human", version=VERSION, description="human"),
|
| 57 |
datasets.BuilderConfig(name="rat_SD", version=VERSION, description="rat_SD"),
|
| 58 |
datasets.BuilderConfig(
|
| 59 |
name="mouse_BALB_c", version=VERSION, description="mouse_BALB_c"
|
|
|
|
| 72 |
citation=_CITATION,
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# def _split_generators(self, dl_manager):
|
| 76 |
+
# urls = _URLS[self.config.name]
|
| 77 |
+
# data_dir = dl_manager.download_and_extract(urls)
|
| 78 |
+
# return [
|
| 79 |
+
# datasets.SplitGenerator(
|
| 80 |
+
# name=datasets.Split.TRAIN,
|
| 81 |
+
# gen_kwargs={
|
| 82 |
+
# "filepath": os.path.join(data_dir),
|
| 83 |
+
# "split": "train",
|
| 84 |
+
# },
|
| 85 |
+
# ),
|
| 86 |
+
# ]
|
| 87 |
+
|
| 88 |
+
# def _generate_examples(self, filepath, split):
|
| 89 |
+
# table = pd.read_parquet(filepath)
|
| 90 |
+
# for key, row in enumerate(table.itertuples()):
|
| 91 |
+
# if key == 0:
|
| 92 |
+
# continue
|
| 93 |
+
# yield key, {
|
| 94 |
+
# "sequence_alignment_aa_heavy": row[1],
|
| 95 |
+
# "cdr1_aa_heavy": row[2],
|
| 96 |
+
# "cdr2_aa_heavy": row[3],
|
| 97 |
+
# "cdr3_aa_heavy": row[4],
|
| 98 |
+
# "sequence_alignment_aa_light": row[5],
|
| 99 |
+
# "cdr1_aa_light": row[6],
|
| 100 |
+
# "cdr2_aa_light": row[7],
|
| 101 |
+
# "cdr3_aa_light": row[8],
|
| 102 |
+
# }
|
| 103 |
+
|
| 104 |
def _split_generators(self, dl_manager):
|
| 105 |
+
data_unit_file = os.path.join(
|
| 106 |
+
os.getcwd(), "data_units", self.config.name + ".txt"
|
| 107 |
+
)
|
| 108 |
+
with open(data_unit_file, "r") as f:
|
| 109 |
+
urls = [
|
| 110 |
+
os.path.join(_BASE_URL, self.config.name, line.strip()) for line in f
|
| 111 |
+
]
|
| 112 |
+
data_files = dl_manager.download_and_extract(urls)
|
| 113 |
return [
|
| 114 |
datasets.SplitGenerator(
|
| 115 |
name=datasets.Split.TRAIN,
|
| 116 |
gen_kwargs={
|
| 117 |
+
"filepath": data_files,
|
| 118 |
"split": "train",
|
| 119 |
},
|
| 120 |
),
|
| 121 |
]
|
| 122 |
|
| 123 |
+
def _generate_examples(self, filepaths):
|
| 124 |
+
for filepath in filepaths:
|
| 125 |
+
with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
|
| 126 |
+
reader = csv.reader(f, delimiter=",")
|
| 127 |
+
for key, row in enumerate(reader):
|
| 128 |
+
if key == 0:
|
| 129 |
+
continue
|
| 130 |
+
else:
|
| 131 |
+
yield key - 1, {
|
| 132 |
+
"sequence_alignment_aa_heavy": row[10],
|
| 133 |
+
"cdr1_aa_heavy": row[35],
|
| 134 |
+
"cdr2_aa_heavy": row[39],
|
| 135 |
+
"cdr3_aa_heavy": row[43],
|
| 136 |
+
"sequence_alignment_aa_light": row[100],
|
| 137 |
+
"cdr1_aa_light": row[123],
|
| 138 |
+
"cdr2_aa_light": row[127],
|
| 139 |
+
"cdr3_aa_light": row[131],
|
| 140 |
+
}
|
| 141 |
|