thewall commited on
Commit
ab39bdb
1 Parent(s): ef3fb3e

Update jolma.py

Browse files

remove deepbindweight

Files changed (1) hide show
  1. jolma.py +28 -24
jolma.py CHANGED
@@ -3,7 +3,7 @@ import json
3
  import re
4
  import pandas as pd
5
  import datasets
6
-
7
 
8
  logger = datasets.logging.get_logger(__name__)
9
 
@@ -54,34 +54,26 @@ _URL = "ftp://ftp.sra.ebi.ac.uk/vol1/run/"
54
  # _REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA"
55
  # _DESIGN_LENGTH = 30
56
 
 
 
 
57
 
58
- config = datasets.load_dataset(path="thewall/deepbindweight", split="all")
59
- info = pd.read_excel(config['selex'][0], index_col=0)
60
-
61
- _URLS = {}
62
- _DESIGN_LENGTH = {}
63
  pattern = re.compile("(\d+)")
64
- for idx, row in info.iterrows():
65
- sra_id = idx
66
- file = row["file"]
67
- _URLS[sra_id] = "/".join([_URL, sra_id[:6], sra_id, file])
68
- _DESIGN_LENGTH[sra_id] = int(pattern.search(row["Ligand"]).group(0))
69
 
70
 
71
  class JolmaConfig(datasets.BuilderConfig):
72
- def __init__(self, url, sra_id="ERR173157", length_match=True, filter_N=True, design_length=None, file=None, **kwargs):
73
  super(JolmaConfig, self).__init__(**kwargs)
74
- self.url = url
75
- self.sra_id = sra_id
76
  self.length_match = length_match
77
- self.design_length = design_length
78
  self.filter_N = filter_N
79
- self.file = file
80
 
81
 
82
  class Jolma(datasets.GeneratorBasedBuilder):
 
 
 
83
  BUILDER_CONFIGS = [
84
- JolmaConfig(name=key, url=_URLS[key], design_length=_DESIGN_LENGTH[key], file=info.loc[key]['file']) for key in _URLS
85
  ]
86
 
87
  DEFAULT_CONFIG_NAME = "ERR173157"
@@ -101,15 +93,29 @@ class Jolma(datasets.GeneratorBasedBuilder):
101
  citation=_CITATION,
102
  )
103
 
 
 
 
 
 
 
 
 
 
104
  def _split_generators(self, dl_manager):
105
  downloaded_files = None
 
 
 
 
106
  if getattr(self.config, "data_dir") is not None:
107
- # downloaded_files = os.path.join(self.config.data_dir, self.config.sra_id, self.config.file)
108
- downloaded_files = dl_manager.extract(os.path.join(self.config.data_dir, self.config.sra_id, self.config.file))
109
  logger.info(f"Load from {downloaded_files}")
110
  if downloaded_files is None or not os.path.exists(downloaded_files):
111
- logger.info(f"Download from {self.config.url}")
112
- downloaded_files = dl_manager.download_and_extract(self.config.url)
 
113
  return [
114
  datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}),
115
  ]
@@ -134,7 +140,7 @@ class Jolma(datasets.GeneratorBasedBuilder):
134
 
135
  def filter_fn(self, example):
136
  seq = example["seq"]
137
- if self.config.length_match and len(seq)!=self.config.design_length:
138
  return False
139
  if self.config.filter_N and "N" in seq:
140
  return False
@@ -145,5 +151,3 @@ if __name__=="__main__":
145
  from datasets import load_dataset
146
  dataset = load_dataset("jolma.py", name="ERR173157", split="all")
147
  # dataset = load_dataset("jolma.py", name="ERR173157", split="all", data_dir="/root/autodl-fs/ERP001824-461")
148
-
149
-
 
3
  import re
4
  import pandas as pd
5
  import datasets
6
+ from functools import cached_property
7
 
8
  logger = datasets.logging.get_logger(__name__)
9
 
 
54
  # _REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA"
55
  # _DESIGN_LENGTH = 30
56
 
57
+ _DOWNLODE_MANAGER = datasets.DownloadManager()
58
+ _RESOURCE_URL = "https://huggingface.co/datasets/thewall/DeepBindWeight/resolve/main"
59
+ SELEX_INFO_FILE = _DOWNLODE_MANAGER.download(f"{_RESOURCE_URL}/ERP001824-deepbind.xlsx")
60
 
 
 
 
 
 
61
  pattern = re.compile("(\d+)")
 
 
 
 
 
62
 
63
 
64
  class JolmaConfig(datasets.BuilderConfig):
65
+ def __init__(self, length_match=True, filter_N=True, **kwargs):
66
  super(JolmaConfig, self).__init__(**kwargs)
 
 
67
  self.length_match = length_match
 
68
  self.filter_N = filter_N
 
69
 
70
 
71
  class Jolma(datasets.GeneratorBasedBuilder):
72
+
73
+ SELEX_INFO = pd.read_excel(SELEX_INFO_FILE, index_col=0)
74
+
75
  BUILDER_CONFIGS = [
76
+ JolmaConfig(name=index) for index in SELEX_INFO.index
77
  ]
78
 
79
  DEFAULT_CONFIG_NAME = "ERR173157"
 
93
  citation=_CITATION,
94
  )
95
 
96
+ @cached_property
97
+ def selex_info(self):
98
+ return self.SELEX_INFO.loc[self.config.name]
99
+
100
+ @cached_property
101
+ def design_length(self):
102
+ selex_info = self.selex_info
103
+ return int(pattern.search(selex_info["Ligand"]).group(0))
104
+
105
  def _split_generators(self, dl_manager):
106
  downloaded_files = None
107
+ sra_id = self.config.name
108
+ selex_info = self.selex_info
109
+ file = selex_info['file']
110
+
111
  if getattr(self.config, "data_dir") is not None:
112
+ path = os.path.join(self.config.data_dir, sra_id, file)
113
+ downloaded_files = dl_manager.extract(path)
114
  logger.info(f"Load from {downloaded_files}")
115
  if downloaded_files is None or not os.path.exists(downloaded_files):
116
+ downloaded_url = "/".join([_URL, sra_id[:6], sra_id, file])
117
+ logger.info(f"Download from {downloaded_url}")
118
+ downloaded_files = dl_manager.download_and_extract(downloaded_url)
119
  return [
120
  datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}),
121
  ]
 
140
 
141
  def filter_fn(self, example):
142
  seq = example["seq"]
143
+ if self.config.length_match and len(seq)!=self.design_length:
144
  return False
145
  if self.config.filter_N and "N" in seq:
146
  return False
 
151
  from datasets import load_dataset
152
  dataset = load_dataset("jolma.py", name="ERR173157", split="all")
153
  # dataset = load_dataset("jolma.py", name="ERR173157", split="all", data_dir="/root/autodl-fs/ERP001824-461")