Update simulation.py
Browse files- simulation.py +17 -15
simulation.py
CHANGED
|
@@ -153,7 +153,7 @@ DATA_FILES = {"multiple-666": {"train": "https://huggingface.co/datasets/thewall
|
|
| 153 |
}
|
| 154 |
|
| 155 |
class SimulationConfig(datasets.BuilderConfig):
|
| 156 |
-
def __init__(self, n_seq, num_motifs=1, motif_length=10, error_rate=0.0, seed=0, add_primer=False, **kwargs):
|
| 157 |
super(SimulationConfig, self).__init__(**kwargs)
|
| 158 |
self.n_seq = n_seq
|
| 159 |
self.num_motifs = num_motifs
|
|
@@ -161,19 +161,20 @@ class SimulationConfig(datasets.BuilderConfig):
|
|
| 161 |
self.error_rate = error_rate
|
| 162 |
self.seed = seed
|
| 163 |
self.add_primer = add_primer
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
class Simulation(datasets.GeneratorBasedBuilder):
|
| 171 |
|
| 172 |
BUILDER_CONFIGS = [
|
| 173 |
SimulationConfig(name="multiple", num_motifs=10, error_rate=0.1, n_seq=10000, seed=0),
|
| 174 |
-
SimulationConfig(name="paired", n_seq=5000, seed=0),
|
| 175 |
SimulationConfig(name="multiple-666", num_motifs=10, error_rate=0.1, n_seq=10000, seed=0),
|
| 176 |
-
SimulationConfig(name="paired-666", n_seq=5000, seed=0),
|
| 177 |
]
|
| 178 |
|
| 179 |
DEFAULT_CONFIG_NAME = "multiple-666"
|
|
@@ -209,22 +210,23 @@ class Simulation(datasets.GeneratorBasedBuilder):
|
|
| 209 |
]
|
| 210 |
else:
|
| 211 |
kwargs = {"num_motifs": self.config.num_motifs,
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
|
|
|
| 218 |
iterator = self._sample(**kwargs)
|
| 219 |
|
| 220 |
return [
|
| 221 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"iterator_fn": iterator}),
|
| 222 |
]
|
| 223 |
|
| 224 |
-
def _sample(self, num_motifs, motif_length, error_rate, seed, add_primer, sample_num):
|
| 225 |
simulator = SequenceGenerator(num_motifs=num_motifs, motif_length=motif_length,
|
| 226 |
error_rate=error_rate, seed=seed,
|
| 227 |
-
add_primer=add_primer)
|
| 228 |
data = simulator.sample(sample_num)
|
| 229 |
motifs = simulator.motifs
|
| 230 |
for key, (seq, mask, motif_ids, label) in enumerate(zip(data[0], data[1], data[2], data[-1])):
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
class SimulationConfig(datasets.BuilderConfig):
|
| 156 |
+
def __init__(self, n_seq, num_motifs=1, motif_length=10, error_rate=0.0, seed=0, add_primer=False, paired=False, **kwargs):
|
| 157 |
super(SimulationConfig, self).__init__(**kwargs)
|
| 158 |
self.n_seq = n_seq
|
| 159 |
self.num_motifs = num_motifs
|
|
|
|
| 161 |
self.error_rate = error_rate
|
| 162 |
self.seed = seed
|
| 163 |
self.add_primer = add_primer
|
| 164 |
+
self.paired = paired
|
| 165 |
+
# if "paired" in kwargs['name']:
|
| 166 |
+
# self.paired = True
|
| 167 |
+
# else:
|
| 168 |
+
# self.paired = False
|
| 169 |
|
| 170 |
|
| 171 |
class Simulation(datasets.GeneratorBasedBuilder):
|
| 172 |
|
| 173 |
BUILDER_CONFIGS = [
|
| 174 |
SimulationConfig(name="multiple", num_motifs=10, error_rate=0.1, n_seq=10000, seed=0),
|
| 175 |
+
SimulationConfig(name="paired", n_seq=5000, seed=0, paired=True),
|
| 176 |
SimulationConfig(name="multiple-666", num_motifs=10, error_rate=0.1, n_seq=10000, seed=0),
|
| 177 |
+
SimulationConfig(name="paired-666", n_seq=5000, seed=0, paired=True),
|
| 178 |
]
|
| 179 |
|
| 180 |
DEFAULT_CONFIG_NAME = "multiple-666"
|
|
|
|
| 210 |
]
|
| 211 |
else:
|
| 212 |
kwargs = {"num_motifs": self.config.num_motifs,
|
| 213 |
+
"motif_length": self.config.motif_length,
|
| 214 |
+
"error_rate": self.config.error_rate,
|
| 215 |
+
"seed": self.config.seed,
|
| 216 |
+
"add_primer": self.config.add_primer,
|
| 217 |
+
"sample_num": self.config.n_seq,
|
| 218 |
+
"paired": self.config.paired
|
| 219 |
+
}
|
| 220 |
iterator = self._sample(**kwargs)
|
| 221 |
|
| 222 |
return [
|
| 223 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"iterator_fn": iterator}),
|
| 224 |
]
|
| 225 |
|
| 226 |
+
def _sample(self, num_motifs, motif_length, error_rate, seed, add_primer, sample_num, paired):
|
| 227 |
simulator = SequenceGenerator(num_motifs=num_motifs, motif_length=motif_length,
|
| 228 |
error_rate=error_rate, seed=seed,
|
| 229 |
+
add_primer=add_primer, paired=paired)
|
| 230 |
data = simulator.sample(sample_num)
|
| 231 |
motifs = simulator.motifs
|
| 232 |
for key, (seq, mask, motif_ids, label) in enumerate(zip(data[0], data[1], data[2], data[-1])):
|