DveloperY0115 commited on
Commit
786657e
·
verified ·
1 Parent(s): 8c44e56

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .gitattributes +0 -1
  2. README.md +71 -3
  3. ten_species.py +147 -0
  4. ten_species_urls.csv +10 -0
.gitattributes CHANGED
@@ -9,7 +9,6 @@
9
  *.joblib filter=lfs diff=lfs merge=lfs -text
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
  *.lz4 filter=lfs diff=lfs merge=lfs -text
12
- *.mds filter=lfs diff=lfs merge=lfs -text
13
  *.mlmodel filter=lfs diff=lfs merge=lfs -text
14
  *.model filter=lfs diff=lfs merge=lfs -text
15
  *.msgpack filter=lfs diff=lfs merge=lfs -text
 
9
  *.joblib filter=lfs diff=lfs merge=lfs -text
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
  *.lz4 filter=lfs diff=lfs merge=lfs -text
 
12
  *.mlmodel filter=lfs diff=lfs merge=lfs -text
13
  *.model filter=lfs diff=lfs merge=lfs -text
14
  *.msgpack filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,71 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ ## Overview
6
+ This dataset consists of reference genomes for 10 species:
7
+
8
+ | Species | Assembly Accession |
9
+ |--------------------------|-----------------------------------------------------|
10
+ | *Arabidopsis thaliana* | `GCF_000001735.4_TAIR10.1` |
11
+ | *Caenorhabditis elegans* | `GCF_000002985.6_WBcel235` |
12
+ | *Danio rerio* | `GCF_000002035.6_GRCz11` |
13
+ | *Drosophila melanogaster*| `GCF_000001215.4_Release_6_plus_ISO1_MT` |
14
+ | *Felis catus* | `GCF_018350175.1_F.catus_Fca126_mat1.0` |
15
+ | *Gallus gallus* | `GCF_016699485.2_bGalGal1.mat.broiler.GRCg7b` |
16
+ | *Gorilla gorilla* | `GCF_029281585.2_NHGRI_mGorGor1-v2.0_pri` |
17
+ | *Homo sapiens* | `GCF_000001405.40_GRCh38.p14` |
18
+ | *Mus musculus* | `GCF_000001635.27_GRCm39` |
19
+ | *Salmo trutta* | `GCF_901001165.1_fSalTru1.1` |
20
+
21
+ Each item in the dataset contains the following fields:
22
+ ```
23
+ "sequence": datasets.Value("string"),
24
+ "species_label": datasets.ClassLabel() # See below
25
+ "description": datasets.Value("string"),
26
+ "start_pos": datasets.Value("int32"),
27
+ "end_pos": datasets.Value("int32"),
28
+ "fasta_url": datasets.Value("string")
29
+ ```
30
+
31
+ The class labels are as follows:
32
+ | Class | Label |
33
+ |-----------------------------|-------|
34
+ | `'Homo_sapiens'` | 0 |
35
+ | `'Mus_musculus'` | 1 |
36
+ | `'Drosophila_melanogaster'` | 2 |
37
+ | `'Danio_rerio'` | 3 |
38
+ | `'Caenorhabditis_elegans'` | 4 |
39
+ | `'Gallus_gallus'` | 5 |
40
+ | `'Gorilla_gorilla'` | 6 |
41
+ | `'Felis_catus'` | 7 |
42
+ | `'Salmo_trutta'` | 8 |
43
+ | `'Arabidopsis_thaliana'` | 9 |
44
+
45
+
46
+ ## Usage
47
+ To use this dataset, set the `chunk_length` (length of each sequence, in base-pairs) and the `overlap` (amount each sequence overlaps, in base-pairs).
48
+ The dataset only contains a `train` split.
49
+ We recommend randomly splitting the dataset to create validation/test sets.
50
+ See below for example usage:
51
+
52
+ ```python
53
+ import datasets
54
+
55
+ max_length = 32_768
56
+ overlap = 0
57
+
58
+ dataset = datasets.load_dataset(
59
+ 'yairschiff/ten_species',
60
+ split='train', # original dataset only has `train` split
61
+ chunk_length=max_length,
62
+ overlap=overlap,
63
+ trust_remote_code=True
64
+ )
65
+ train_validation_splits = dataset.train_test_split(
66
+ test_size=0.05, seed=42)
67
+ ```
68
+
69
+
70
+ ## Acknowledgments
71
+ Code for dataset processing is derived from https://huggingface.co/datasets/InstaDeepAI/multi_species_genomes.
ten_species.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+ import datasets
3
+ import pandas as pd
4
+ from Bio import SeqIO
5
+
6
+ _CHUNK_LENGTHS = [16384, 32768]
7
+
8
+
9
+ def filter_fn(char: str) -> str:
10
+ """
11
+ Transforms any letter different from a base nucleotide into an 'N'.
12
+ """
13
+ if char in {'A', 'T', 'C', 'G'}:
14
+ return char
15
+ else:
16
+ return 'N'
17
+
18
+
19
+ def clean_sequence(seq: str) -> str:
20
+ """
21
+ Process a chunk of DNA to have all letters in upper and restricted to
22
+ A, T, C, G and N.
23
+ """
24
+ seq = seq.upper()
25
+ seq = map(filter_fn, seq)
26
+ seq = ''.join(list(seq))
27
+ return seq
28
+
29
+
30
+ class TenSpeciesGenomesConfig(datasets.BuilderConfig):
31
+ """BuilderConfig for The Human Reference Genome."""
32
+
33
+ def __init__(self, *args, chunk_length: int, overlap: int = 0, **kwargs):
34
+ """BuilderConfig for the multi species genomes.
35
+ Args:
36
+ chunk_length (:obj:`int`): Chunk length.
37
+ overlap: (:obj:`int`): Overlap in base pairs for two consecutive chunks (defaults to 0).
38
+ **kwargs: keyword arguments forwarded to super.
39
+ """
40
+ super().__init__(
41
+ *args,
42
+ name=f'{chunk_length}bp',
43
+ **kwargs,
44
+ )
45
+ self.chunk_length = chunk_length
46
+ self.overlap = overlap
47
+
48
+
49
+ class TenSpeciesGenomes(datasets.GeneratorBasedBuilder):
50
+ """Genomes from 10 species, filtered and split into chunks of consecutive nucleotides.
51
+
52
+ Species include:
53
+ - Homo_sapiens
54
+ - Mus_musculus
55
+ - Drosophila_melanogaster
56
+ - Danio_rerio
57
+ - Caenorhabditis_elegans
58
+ - Gallus_gallus
59
+ - Gorilla_gorilla
60
+ - Felis_catus
61
+ - Salmo_trutta
62
+ - Arabidopsis_thaliana
63
+ """
64
+
65
+ VERSION = datasets.Version("1.0.0")
66
+ BUILDER_CONFIG_CLASS = TenSpeciesGenomesConfig
67
+ BUILDER_CONFIGS = [TenSpeciesGenomesConfig(chunk_length=chunk_length) for chunk_length in _CHUNK_LENGTHS]
68
+ DEFAULT_CONFIG_NAME = "32768bp"
69
+
70
+ def _info(self):
71
+
72
+ features = datasets.Features(
73
+ {
74
+ "sequence": datasets.Value("string"),
75
+ "species_label": datasets.ClassLabel(
76
+ num_classes=10,
77
+ names=['Homo_sapiens', 'Mus_musculus', 'Drosophila_melanogaster', 'Danio_rerio',
78
+ 'Caenorhabditis_elegans', 'Gallus_gallus', 'Gorilla_gorilla', 'Felis_catus',
79
+ 'Salmo_trutta', 'Arabidopsis_thaliana']),
80
+ "description": datasets.Value("string"),
81
+ "start_pos": datasets.Value("int32"),
82
+ "end_pos": datasets.Value("int32"),
83
+ "fasta_url": datasets.Value("string")
84
+ }
85
+ )
86
+ return datasets.DatasetInfo(
87
+ # This defines the different columns of the dataset and their types
88
+ features=features,
89
+ )
90
+
91
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
92
+
93
+ urls_filepath = dl_manager.download_and_extract('ten_species_urls.csv')
94
+ with open(urls_filepath) as urls_file:
95
+ all_species = [line.rstrip().split(',')[0] for line in urls_file]
96
+ with open(urls_filepath) as urls_file:
97
+ urls = [line.rstrip().split(',')[-1] for line in urls_file]
98
+ all_species = tuple(all_species)
99
+ downloaded_files = dl_manager.download_and_extract(urls)
100
+
101
+ return [
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.TRAIN,
104
+ gen_kwargs={"all_species": all_species, "files": downloaded_files,
105
+ "chunk_length": self.config.chunk_length, "overlap": self.config.overlap}
106
+ ),
107
+ ]
108
+
109
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
110
+ def _generate_examples(self, all_species, files, chunk_length, overlap):
111
+ key = 0
112
+ for species, file in zip(all_species, files):
113
+ with open(file, 'rt') as f:
114
+ fasta_sequences = SeqIO.parse(f, 'fasta')
115
+
116
+ for record in fasta_sequences:
117
+ # parse descriptions in the fasta file
118
+ sequence, description = str(record.seq), record.description
119
+
120
+ # clean chromosome sequence
121
+ sequence = clean_sequence(sequence)
122
+ seq_length = len(sequence)
123
+
124
+ # split into chunks
125
+ num_chunks = (seq_length - 2 * overlap) // chunk_length
126
+
127
+ if num_chunks < 1:
128
+ continue
129
+
130
+ sequence = sequence[:(chunk_length * num_chunks + 2 * overlap)]
131
+ seq_length = len(sequence)
132
+
133
+ for i in range(num_chunks):
134
+ # get chunk
135
+ start_pos = i * chunk_length
136
+ end_pos = min(seq_length, (i+1) * chunk_length + 2 * overlap)
137
+ chunk_sequence = sequence[start_pos:end_pos]
138
+
139
+ # yield chunk
140
+ yield key, {
141
+ 'sequence': chunk_sequence,
142
+ 'species_label': species,
143
+ 'start_pos': start_pos,
144
+ 'end_pos': end_pos,
145
+ 'fasta_url': file.split('::')[-1]
146
+ }
147
+ key += 1
ten_species_urls.csv ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ Homo_sapiens,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_mammalian/Homo_sapiens/latest_assembly_versions/GCF_000001405.40_GRCh38.p14/GCF_000001405.40_GRCh38.p14_genomic.fna.gz
2
+ Mus_musculus,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_mammalian/Mus_musculus/latest_assembly_versions/GCF_000001635.27_GRCm39/GCF_000001635.27_GRCm39_genomic.fna.gz
3
+ Drosophila_melanogaster,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/invertebrate/Drosophila_melanogaster/latest_assembly_versions/GCF_000001215.4_Release_6_plus_ISO1_MT/GCF_000001215.4_Release_6_plus_ISO1_MT_genomic.fna.gz
4
+ Danio_rerio,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_other/Danio_rerio/latest_assembly_versions/GCF_049306965.1_GRCz12tu/GCF_049306965.1_GRCz12tu_genomic.fna.gz
5
+ Caenorhabditis_elegans,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/invertebrate/Caenorhabditis_elegans/latest_assembly_versions/GCF_000002985.6_WBcel235/GCF_000002985.6_WBcel235_genomic.fna.gz
6
+ Gallus_gallus,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_other/Gallus_gallus/latest_assembly_versions/GCF_016699485.2_bGalGal1.mat.broiler.GRCg7b/GCF_016699485.2_bGalGal1.mat.broiler.GRCg7b_genomic.fna.gz
7
+ Gorilla_gorilla,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_mammalian/Gorilla_gorilla/latest_assembly_versions/GCF_029281585.2_NHGRI_mGorGor1-v2.1_pri/GCF_029281585.2_NHGRI_mGorGor1-v2.1_pri_genomic.fna.gz
8
+ Felis_catus,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_mammalian/Felis_catus/latest_assembly_versions/GCF_018350175.1_F.catus_Fca126_mat1.0/GCF_018350175.1_F.catus_Fca126_mat1.0_genomic.fna.gz
9
+ Salmo_trutta,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/vertebrate_other/Salmo_trutta/latest_assembly_versions/GCF_901001165.1_fSalTru1.1/GCF_901001165.1_fSalTru1.1_genomic.fna.gz
10
+ Arabidopsis_thaliana,https://ftp.ncbi.nlm.nih.gov/genomes/refseq/plant/Arabidopsis_thaliana/latest_assembly_versions/GCF_000001735.4_TAIR10.1/GCF_000001735.4_TAIR10.1_genomic.fna.gz