Update jolma_subset.py
Browse filesremove deepbindweight
remove protein and aptamer prefix
- jolma_subset.py +42 -43
jolma_subset.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
-
import os
|
2 |
import re
|
3 |
import pandas as pd
|
4 |
-
import numpy as np
|
5 |
import datasets
|
6 |
-
|
7 |
|
8 |
logger = datasets.logging.get_logger(__name__)
|
9 |
|
@@ -54,32 +52,19 @@ _URL = "ftp://ftp.sra.ebi.ac.uk/vol1/run/"
|
|
54 |
# _REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA"
|
55 |
# _DESIGN_LENGTH = 30
|
56 |
|
57 |
-
import datasets
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
"min_count_3": ""}
|
64 |
-
_DESIGN_LENGTH = {"min_count_10": None,
|
65 |
-
"min_count_3": None}
|
66 |
pattern = re.compile("(\d+)")
|
67 |
-
for idx, row in info.iterrows():
|
68 |
-
sra_id = row["SRA ID"]
|
69 |
-
file = row["file"]
|
70 |
-
_URLS[sra_id] = "/".join([_URL, sra_id[:6], sra_id, file])
|
71 |
-
_DESIGN_LENGTH[sra_id] = int(pattern.search(row["Ligand"]).group(0))
|
72 |
-
|
73 |
URL = "https://huggingface.co/datasets/thewall/jolma_subset/resolve/main"
|
74 |
|
|
|
75 |
class JolmaSubsetConfig(datasets.BuilderConfig):
|
76 |
-
def __init__(self,
|
77 |
-
|
78 |
-
aptamer_prefix="[BOS]", aptamer_suffix="[EOS]", **kwargs):
|
79 |
super(JolmaSubsetConfig, self).__init__(**kwargs)
|
80 |
-
self.length_match = length_match
|
81 |
-
self.design_length = design_length
|
82 |
-
self.filter_N = filter_N
|
83 |
self.data_dir = kwargs.get("data_dir")
|
84 |
self.protein_prefix = protein_prefix
|
85 |
self.protein_suffix = protein_suffix
|
@@ -90,8 +75,12 @@ class JolmaSubsetConfig(datasets.BuilderConfig):
|
|
90 |
|
91 |
|
92 |
class JolmaSubset(datasets.GeneratorBasedBuilder):
|
|
|
|
|
|
|
|
|
93 |
BUILDER_CONFIGS = [
|
94 |
-
JolmaSubsetConfig(name=key
|
95 |
]
|
96 |
|
97 |
DEFAULT_CONFIG_NAME = "min_count_3"
|
@@ -114,11 +103,29 @@ class JolmaSubset(datasets.GeneratorBasedBuilder):
|
|
114 |
citation=_CITATION,
|
115 |
)
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
def _split_generators(self, dl_manager):
|
118 |
-
# downloaded_files = dl_manager.download_and_extract(self.config.url)
|
119 |
-
# logger.info(f"Download from {self.config.url}")
|
120 |
file = dl_manager.download(f"{URL}/{self.config.name}.gz.csv")
|
121 |
-
# file = os.path.join(filepath, os.listdir(filepath)[0])
|
122 |
return [
|
123 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": file}),
|
124 |
]
|
@@ -126,23 +133,24 @@ class JolmaSubset(datasets.GeneratorBasedBuilder):
|
|
126 |
def _generate_examples(self, filepath):
|
127 |
"""This function returns the examples in the raw (text) form."""
|
128 |
logger.info("generating examples from = %s", filepath)
|
129 |
-
proteins = protein_info["Sequence"]
|
130 |
-
protein_id = protein_info["Entry"]
|
131 |
-
gene_num = protein_info["Unique Gene"]
|
132 |
data = pd.read_csv(filepath)
|
133 |
for key, row in data.iterrows():
|
134 |
sra_id = row["identifier"].split(":")[0]
|
135 |
-
|
|
|
|
|
|
|
|
|
136 |
aptamer_seq = f'{self.config.aptamer_prefix}{row["seq"]}{self.config.aptamer_suffix}'
|
137 |
if len(protein_seq)>self.config.max_length:
|
138 |
continue
|
139 |
-
if gene_num
|
140 |
continue
|
141 |
-
if str(proteins
|
142 |
continue
|
143 |
ans = {"id": key,
|
144 |
"protein": protein_seq,
|
145 |
-
"protein_id": protein_id
|
146 |
"seq": aptamer_seq,
|
147 |
"identifier": row["identifier"],
|
148 |
"count": int(row["count"]),
|
@@ -150,15 +158,6 @@ class JolmaSubset(datasets.GeneratorBasedBuilder):
|
|
150 |
yield key, ans
|
151 |
|
152 |
|
153 |
-
def filter_fn(self, example):
|
154 |
-
seq = example["seq"]
|
155 |
-
if self.config.length_match and len(seq)!=self.config.design_length:
|
156 |
-
return False
|
157 |
-
if self.config.filter_N and "N" in seq:
|
158 |
-
return False
|
159 |
-
return True
|
160 |
-
|
161 |
-
|
162 |
if __name__=="__main__":
|
163 |
from datasets import load_dataset
|
164 |
dataset = load_dataset("jolma_subset.py", split="all")
|
|
|
|
|
1 |
import re
|
2 |
import pandas as pd
|
|
|
3 |
import datasets
|
4 |
+
from functools import cached_property, cache
|
5 |
|
6 |
logger = datasets.logging.get_logger(__name__)
|
7 |
|
|
|
52 |
# _REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA"
|
53 |
# _DESIGN_LENGTH = 30
|
54 |
|
|
|
55 |
|
56 |
+
_DOWNLODE_MANAGER = datasets.DownloadManager()
|
57 |
+
_RESOURCE_URL = "https://huggingface.co/datasets/thewall/DeepBindWeight/resolve/main"
|
58 |
+
SELEX_INFO_FILE = _DOWNLODE_MANAGER.download(f"{_RESOURCE_URL}/ERP001824-deepbind.xlsx")
|
59 |
+
PROTEIN_INFO_FILE = _DOWNLODE_MANAGER.download(f"{_RESOURCE_URL}/ERP001824-UniprotKB.xlsx")
|
|
|
|
|
|
|
60 |
pattern = re.compile("(\d+)")
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
URL = "https://huggingface.co/datasets/thewall/jolma_subset/resolve/main"
|
62 |
|
63 |
+
|
64 |
class JolmaSubsetConfig(datasets.BuilderConfig):
|
65 |
+
def __init__(self, protein_prefix="", protein_suffix="", max_length=1000, max_gene_num=1,
|
66 |
+
aptamer_prefix="", aptamer_suffix="", **kwargs):
|
|
|
67 |
super(JolmaSubsetConfig, self).__init__(**kwargs)
|
|
|
|
|
|
|
68 |
self.data_dir = kwargs.get("data_dir")
|
69 |
self.protein_prefix = protein_prefix
|
70 |
self.protein_suffix = protein_suffix
|
|
|
75 |
|
76 |
|
77 |
class JolmaSubset(datasets.GeneratorBasedBuilder):
|
78 |
+
|
79 |
+
SELEX_INFO = pd.read_excel(SELEX_INFO_FILE, index_col=0)
|
80 |
+
PROTEIN_INFO = pd.read_excel(PROTEIN_INFO_FILE, index_col=0)
|
81 |
+
|
82 |
BUILDER_CONFIGS = [
|
83 |
+
JolmaSubsetConfig(name=key) for key in ["min_count_3", "min_count_10"]
|
84 |
]
|
85 |
|
86 |
DEFAULT_CONFIG_NAME = "min_count_3"
|
|
|
103 |
citation=_CITATION,
|
104 |
)
|
105 |
|
106 |
+
@cached_property
|
107 |
+
def selex_info(self):
|
108 |
+
return self.SELEX_INFO.loc[self.config.name]
|
109 |
+
|
110 |
+
@cached_property
|
111 |
+
def protein_info(self):
|
112 |
+
return self.PROTEIN_INFO.loc[self.config.name]
|
113 |
+
|
114 |
+
def design_length(self):
|
115 |
+
return int(pattern.search(self.protein_info["Ligand"]).group(0))
|
116 |
+
|
117 |
+
def get_selex_info(self, sra_id):
|
118 |
+
return self.SELEX_INFO.loc[sra_id]
|
119 |
+
|
120 |
+
def get_protein_info(self, sra_id):
|
121 |
+
return self.PROTEIN_INFO.loc[sra_id]
|
122 |
+
|
123 |
+
@cache
|
124 |
+
def get_design_length(self, sra_id):
|
125 |
+
return int(pattern.search(self.get_protein_info(sra_id)["Ligand"]).group(0))
|
126 |
+
|
127 |
def _split_generators(self, dl_manager):
|
|
|
|
|
128 |
file = dl_manager.download(f"{URL}/{self.config.name}.gz.csv")
|
|
|
129 |
return [
|
130 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": file}),
|
131 |
]
|
|
|
133 |
def _generate_examples(self, filepath):
|
134 |
"""This function returns the examples in the raw (text) form."""
|
135 |
logger.info("generating examples from = %s", filepath)
|
|
|
|
|
|
|
136 |
data = pd.read_csv(filepath)
|
137 |
for key, row in data.iterrows():
|
138 |
sra_id = row["identifier"].split(":")[0]
|
139 |
+
protein_info = self.get_protein_info(sra_id)
|
140 |
+
proteins = protein_info["Sequence"]
|
141 |
+
gene_num = protein_info["Unique Gene"]
|
142 |
+
protein_id = protein_info["Entry"]
|
143 |
+
protein_seq = f"{self.config.protein_prefix}{proteins}{self.config.protein_suffix}"
|
144 |
aptamer_seq = f'{self.config.aptamer_prefix}{row["seq"]}{self.config.aptamer_suffix}'
|
145 |
if len(protein_seq)>self.config.max_length:
|
146 |
continue
|
147 |
+
if gene_num>self.config.max_gene_num:
|
148 |
continue
|
149 |
+
if str(proteins)=="nan" or len(str(proteins))==0:
|
150 |
continue
|
151 |
ans = {"id": key,
|
152 |
"protein": protein_seq,
|
153 |
+
"protein_id": protein_id,
|
154 |
"seq": aptamer_seq,
|
155 |
"identifier": row["identifier"],
|
156 |
"count": int(row["count"]),
|
|
|
158 |
yield key, ans
|
159 |
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
if __name__=="__main__":
|
162 |
from datasets import load_dataset
|
163 |
dataset = load_dataset("jolma_subset.py", split="all")
|