hdallatorre
commited on
Commit
•
2657c8e
1
Parent(s):
3550519
feat: Use python builtins instead of seqio
Browse files
nucleotide_transformer_downstream_tasks.py
CHANGED
@@ -18,7 +18,25 @@ Transformer paper."""
|
|
18 |
from typing import List
|
19 |
|
20 |
import datasets
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
24 |
_CITATION = """\
|
@@ -131,12 +149,12 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
|
|
131 |
def _generate_examples(self, file):
|
132 |
key = 0
|
133 |
with open(file, "rt") as f:
|
134 |
-
fasta_sequences =
|
135 |
|
136 |
-
for
|
137 |
|
138 |
# parse descriptions in the fasta file
|
139 |
-
sequence, name = str(
|
140 |
label = int(name.split("|")[-1])
|
141 |
|
142 |
# yield example
|
|
|
18 |
from typing import List
|
19 |
|
20 |
import datasets
|
21 |
+
|
22 |
+
|
23 |
+
# This function is a basic reimplementation of SeqIO's parse method. This allows the
|
24 |
+
# dataset viewer to work as it does not require an external package.
|
25 |
+
def parse_fasta(fp):
|
26 |
+
name, seq = None, []
|
27 |
+
for line in fp:
|
28 |
+
line = line.rstrip()
|
29 |
+
if line.startswith(">"):
|
30 |
+
if name:
|
31 |
+
# Slice to remove '>'
|
32 |
+
yield (name[1:], "".join(seq))
|
33 |
+
name, seq = line, []
|
34 |
+
else:
|
35 |
+
seq.append(line)
|
36 |
+
if name:
|
37 |
+
# Slice to remove '>'
|
38 |
+
yield (name[1:], "".join(seq))
|
39 |
+
|
40 |
|
41 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
42 |
_CITATION = """\
|
|
|
149 |
def _generate_examples(self, file):
|
150 |
key = 0
|
151 |
with open(file, "rt") as f:
|
152 |
+
fasta_sequences = parse_fasta(f)
|
153 |
|
154 |
+
for name, seq in fasta_sequences:
|
155 |
|
156 |
# parse descriptions in the fasta file
|
157 |
+
sequence, name = str(seq), str(name)
|
158 |
label = int(name.split("|")[-1])
|
159 |
|
160 |
# yield example
|