Update Genome_database.py
Browse files- Genome_database.py +17 -2
Genome_database.py
CHANGED
|
@@ -6,8 +6,14 @@ import os
|
|
| 6 |
import gzip
|
| 7 |
import re
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
class GenomeDataset(datasets.GeneratorBasedBuilder):
|
| 10 |
VERSION = datasets.Version("1.1.0")
|
|
|
|
| 11 |
|
| 12 |
def _info(self):
|
| 13 |
return datasets.DatasetInfo(
|
|
@@ -26,11 +32,20 @@ class GenomeDataset(datasets.GeneratorBasedBuilder):
|
|
| 26 |
})
|
| 27 |
)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 30 |
urls_filepath = dl_manager.download_and_extract('urlfile.txt')
|
| 31 |
with open(urls_filepath) as urls_file:
|
| 32 |
downloaded_files = [line.rstrip() for line in urls_file]
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
train_files = downloaded_files[:int(len(downloaded_files) * 0.8)] # first 80% for training
|
| 35 |
test_files = downloaded_files[int(len(downloaded_files) * 0.8):] # last 20% for testing
|
| 36 |
|
|
@@ -79,8 +94,8 @@ class GenomeDataset(datasets.GeneratorBasedBuilder):
|
|
| 79 |
elif feature.type == 'gene':
|
| 80 |
continue
|
| 81 |
else:
|
| 82 |
-
if
|
| 83 |
-
product = feature.qualifiers.get('product'
|
| 84 |
region_type = 'coding'
|
| 85 |
specific_class = feature.type
|
| 86 |
else:
|
|
|
|
| 6 |
import gzip
|
| 7 |
import re
|
| 8 |
|
| 9 |
+
class GenomeDatasetConfig(datasets.BuilderConfig):
|
| 10 |
+
def __init__(self, num_urls=None, **kwargs):
|
| 11 |
+
super(GenomeDatasetConfig, self).__init__(**kwargs)
|
| 12 |
+
self.num_urls = num_urls
|
| 13 |
+
|
| 14 |
class GenomeDataset(datasets.GeneratorBasedBuilder):
|
| 15 |
VERSION = datasets.Version("1.1.0")
|
| 16 |
+
BUILDER_CONFIG_CLASS = GenomeDatasetConfig
|
| 17 |
|
| 18 |
def _info(self):
|
| 19 |
return datasets.DatasetInfo(
|
|
|
|
| 32 |
})
|
| 33 |
)
|
| 34 |
|
| 35 |
+
def load_genome_dataset(num_urls=None):
|
| 36 |
+
builder_kwargs = {}
|
| 37 |
+
if num_urls is not None:
|
| 38 |
+
builder_kwargs['config'] = GenomeDatasetConfig(num_urls=num_urls)
|
| 39 |
+
return load_dataset("GenomeDataset", builder_kwargs=builder_kwargs)
|
| 40 |
+
|
| 41 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 42 |
urls_filepath = dl_manager.download_and_extract('urlfile.txt')
|
| 43 |
with open(urls_filepath) as urls_file:
|
| 44 |
downloaded_files = [line.rstrip() for line in urls_file]
|
| 45 |
|
| 46 |
+
num_urls = self.config.num_urls or len(downloaded_files)
|
| 47 |
+
downloaded_files = downloaded_files[:num_urls]
|
| 48 |
+
|
| 49 |
train_files = downloaded_files[:int(len(downloaded_files) * 0.8)] # first 80% for training
|
| 50 |
test_files = downloaded_files[int(len(downloaded_files) * 0.8):] # last 20% for testing
|
| 51 |
|
|
|
|
| 94 |
elif feature.type == 'gene':
|
| 95 |
continue
|
| 96 |
else:
|
| 97 |
+
if 'product' in feature.qualifiers:
|
| 98 |
+
product = feature.qualifiers.get('product')[0]
|
| 99 |
region_type = 'coding'
|
| 100 |
specific_class = feature.type
|
| 101 |
else:
|