Datasets:

DOI:
License:
etrop commited on
Commit
edc9e3d
1 Parent(s): 7c458e8

Update plant-genomic-benchmark.py

Browse files
Files changed (1) hide show
  1. plant-genomic-benchmark.py +31 -8
plant-genomic-benchmark.py CHANGED
@@ -4,7 +4,6 @@
4
 
5
  import os
6
  from typing import List
7
- from Bio import SeqIO
8
  import datasets
9
 
10
 
@@ -69,6 +68,25 @@ _TASK_INFO = {'poly_a':{'type': 'binary', 'val_set':False},
69
  'pro_seq':{'type':'binary','val_set':True}
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  class AgroNtTasksConfig(datasets.BuilderConfig):
73
  """BuilderConfig for the Agro NT supervised learning tasks dataset."""
74
 
@@ -167,24 +185,29 @@ class AgroNtTasks(datasets.GeneratorBasedBuilder):
167
 
168
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
169
  def _generate_examples(self, filepath):
170
- with open(filepath, 'r') as f:
171
- key = 0
172
- for record in SeqIO.parse(f,'fasta'):
173
- # Yields examples as (key, example) tuples
174
 
175
- split_name = record.name.split("|")
 
 
 
 
 
 
 
176
  name = split_name[0]
177
  labels = split_name[1:]
178
 
179
  if 'multi' in self.config.task_type:
180
  yield key, {
181
- "sequence": str(record.seq),
182
  "name": name,
183
  "labels": labels
184
  }
185
  else:
186
  yield key, {
187
- "sequence": str(record.seq),
188
  "name": name,
189
  "label": labels[0],
190
  }
 
4
 
5
  import os
6
  from typing import List
 
7
  import datasets
8
 
9
 
 
68
  'pro_seq':{'type':'binary','val_set':True}
69
  }
70
 
71
+
72
+ # This function is a basic reimplementation of SeqIO's parse method. This allows the
73
+ # dataset viewer to work as it does not require an external package.
74
+ def parse_fasta(fp):
75
+ name, seq = None, []
76
+ for line in fp:
77
+ line = line.rstrip()
78
+ if line.startswith(">"):
79
+ if name:
80
+ # Slice to remove '>'
81
+ yield (name[1:], "".join(seq))
82
+ name, seq = line, []
83
+ else:
84
+ seq.append(line)
85
+ if name:
86
+ # Slice to remove '>'
87
+ yield (name[1:], "".join(seq))
88
+
89
+
90
  class AgroNtTasksConfig(datasets.BuilderConfig):
91
  """BuilderConfig for the Agro NT supervised learning tasks dataset."""
92
 
 
185
 
186
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
187
  def _generate_examples(self, filepath):
188
+
189
+ key = 0
 
 
190
 
191
+ with open(file, "rt") as f:
192
+ fasta_sequences = parse_fasta(f)
193
+
194
+ for name, seq in fasta_sequences:
195
+ # Yields examples as (key, example) tuples
196
+ sequence, name = str(seq), str(name)
197
+
198
+ split_name = name.split("|")
199
  name = split_name[0]
200
  labels = split_name[1:]
201
 
202
  if 'multi' in self.config.task_type:
203
  yield key, {
204
+ "sequence": sequence,
205
  "name": name,
206
  "labels": labels
207
  }
208
  else:
209
  yield key, {
210
+ "sequence": sequence,
211
  "name": name,
212
  "label": labels[0],
213
  }