hdallatorre commited on
Commit
dc18376
·
1 Parent(s): cb8f4a1

feat: change labels are handled

Browse files
deepstarr/test.fna DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:40fbc405ea0041cabd82946fb6486f6b2835e3f75246b8a9c9225a3fffb84d73
3
- size 16498412
 
 
 
 
deepstarr/train.fna DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:afdd362a17bae77f1d7e4ba87a8b8fe2bb7a533b2bce14a67c153ac991d8e80c
3
- size 160497156
 
 
 
 
nucleotide_transformer_downstream_tasks_multilabel.py CHANGED
@@ -45,24 +45,26 @@ _LICENSE = "https://github.com/instadeepai/nucleotide-transformer/LICENSE.md"
45
  # with 5 samples in both the train and test fasta files. It is notably used in order to
46
  # test the scripts.
47
  _TASKS_NUM_LABELS_DTYPE = [
48
- ("deepstarr", 6, "float32"),
49
  ("toy_classification", 2, "int32"),
50
  ("toy_regression", 2, "float32"),
51
  ]
52
 
53
- _SPLIT_SIZES = {
54
- "deepstarr": {"train": 402034, "test": 41184},
55
- "toy_classification": {"train": 35, "test": 35},
56
- "toy_regression": {"train": 25, "test": 15},
 
 
 
 
 
57
  }
58
 
59
 
60
  class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
61
  """BuilderConfig for The Nucleotide Transformer downstream taks dataset."""
62
 
63
- def __init__(
64
- self, *args, task: str, num_labels=int, dtype: str = "int32", **kwargs
65
- ):
66
  """BuilderConfig downstream tasks dataset.
67
  Args:
68
  task (:obj:`str`): Task name.
@@ -74,33 +76,29 @@ class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
74
  **kwargs,
75
  )
76
  self.task = task
77
- self.num_labels = num_labels
78
- self.dtype = dtype
79
- self.dataset_size = _SPLIT_SIZES[task]
80
 
81
 
82
  class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
83
  VERSION = datasets.Version("1.1.0")
84
  BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig
85
  BUILDER_CONFIGS = [
86
- NucleotideTransformerDownstreamTasksConfig(
87
- task=task, num_labels=num_labels, dtype=dtype
88
- )
89
- for (task, num_labels, dtype) in _TASKS_NUM_LABELS_DTYPE
90
  ]
91
- DEFAULT_CONFIG_NAME = "deepstarr"
92
 
93
  def _info(self):
94
- features_dict = {
95
  "sequence": datasets.Value("string"),
96
  "name": datasets.Value("string"),
97
  }
98
- labels_dict = {
99
- f"label_{i}": datasets.Value(self.config.dtype)
100
- for i in range(self.config.num_labels)
101
- }
102
- features_dict.update(labels_dict)
103
- features = datasets.Features(features_dict)
 
104
 
105
  return datasets.DatasetInfo(
106
  # This is the description that will appear on the datasets page.
@@ -113,8 +111,6 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
113
  license=_LICENSE,
114
  # Citation for the dataset
115
  citation=_CITATION,
116
- # Number of sequences
117
- dataset_size=self.config.dataset_size,
118
  )
119
 
120
  def _split_generators(
@@ -134,25 +130,15 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
134
 
135
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
136
  def _generate_examples(self, file):
137
- key = 0
138
- with open(file, "rt") as f:
139
- fasta_sequences = SeqIO.parse(f, "fasta")
140
-
141
- for record in fasta_sequences:
142
-
143
- # parse descriptions in the fasta file
144
- sequence, name = str(record.seq), str(record.name)
145
- labels = [float(label) for label in name.split("|")[1:]]
146
-
147
- sequence_name_dict = {
148
- "sequence": sequence,
149
- "name": name,
150
- }
151
-
152
- labels_dict = {
153
- f"label_{i}": labels[i] for i in range(self.config.num_labels)
154
- }
155
- sequence_name_dict.update(labels_dict)
156
- # yield example
157
- yield key, sequence_name_dict
158
  key += 1
 
45
  # with 5 samples in both the train and test fasta files. It is notably used in order to
46
  # test the scripts.
47
  _TASKS_NUM_LABELS_DTYPE = [
 
48
  ("toy_classification", 2, "int32"),
49
  ("toy_regression", 2, "float32"),
50
  ]
51
 
52
+ _TASK_NAMES = [
53
+ "toy_classification",
54
+ "toy_regression",
55
+ ]
56
+
57
+
58
+ _TASK_INFO = {
59
+ "toy_classification": {"type": "binary"},
60
+ "toy_regression": {"type": "regression"},
61
  }
62
 
63
 
64
  class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
65
  """BuilderConfig for The Nucleotide Transformer downstream taks dataset."""
66
 
67
+ def __init__(self, *args, task: str, **kwargs):
 
 
68
  """BuilderConfig downstream tasks dataset.
69
  Args:
70
  task (:obj:`str`): Task name.
 
76
  **kwargs,
77
  )
78
  self.task = task
79
+ self.task_type = _TASK_INFO[self.task]["type"]
 
 
80
 
81
 
82
  class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
83
  VERSION = datasets.Version("1.1.0")
84
  BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig
85
  BUILDER_CONFIGS = [
86
+ NucleotideTransformerDownstreamTasksConfig(task=task) for task in _TASK_NAMES
 
 
 
87
  ]
88
+ DEFAULT_CONFIG_NAME = "toy_classification"
89
 
90
  def _info(self):
91
+ feature_dit = {
92
  "sequence": datasets.Value("string"),
93
  "name": datasets.Value("string"),
94
  }
95
+
96
+ if self.config.task_type == "regression":
97
+ feature_dit["labels"] = [datasets.Value("float32")]
98
+ elif self.config.task_type == "binary":
99
+ feature_dit["labels"] = [datasets.Value("int8")]
100
+
101
+ features = datasets.Features(feature_dit)
102
 
103
  return datasets.DatasetInfo(
104
  # This is the description that will appear on the datasets page.
 
111
  license=_LICENSE,
112
  # Citation for the dataset
113
  citation=_CITATION,
 
 
114
  )
115
 
116
  def _split_generators(
 
130
 
131
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
132
  def _generate_examples(self, file):
133
+ with open(file, "r") as f:
134
+ key = 0
135
+ for record in SeqIO.parse(f, "fasta"):
136
+ # Yields examples as (key, example) tuples
137
+
138
+ split_name = record.name.split("|")
139
+ name = split_name[0]
140
+ labels = split_name[1:]
141
+
142
+ yield key, {"sequence": str(record.seq), "name": name, "labels": labels}
143
+
 
 
 
 
 
 
 
 
 
 
144
  key += 1