aflajolet commited on
Commit
2f4b74c
1 Parent(s): 24c68f9

Make it possible to override overlap between consecutive DNA chunks

Browse files
Files changed (1) hide show
  1. multi_species_genomes.py +6 -5
multi_species_genomes.py CHANGED
@@ -49,7 +49,6 @@ _HOMEPAGE = "https://www.ncbi.nlm.nih.gov/"
49
  _LICENSE = "https://www.ncbi.nlm.nih.gov/home/about/policies/"
50
 
51
  _CHUNK_LENGTHS = [6000, 12000]
52
- _OVERLAP = 100
53
 
54
 
55
  def filter_fn(char: str) -> str:
@@ -76,10 +75,11 @@ def clean_sequence(seq: str) -> str:
76
  class MultiSpeciesGenomesConfig(datasets.BuilderConfig):
77
  """BuilderConfig for The Human Reference Genome."""
78
 
79
- def __init__(self, *args, chunk_length: int, **kwargs):
80
  """BuilderConfig for the multi species genomes.
81
  Args:
82
  chunk_length (:obj:`int`): Chunk length.
 
83
  **kwargs: keyword arguments forwarded to super.
84
  """
85
  num_kbp = int(chunk_length/1000)
@@ -89,6 +89,7 @@ class MultiSpeciesGenomesConfig(datasets.BuilderConfig):
89
  **kwargs,
90
  )
91
  self.chunk_length = chunk_length
 
92
 
93
 
94
  class MultiSpeciesGenomes(datasets.GeneratorBasedBuilder):
@@ -162,18 +163,18 @@ class MultiSpeciesGenomes(datasets.GeneratorBasedBuilder):
162
  seq_length = len(sequence)
163
 
164
  # split into chunks
165
- num_chunks = (seq_length - 2 * _OVERLAP) // chunk_length
166
 
167
  if num_chunks < 1:
168
  continue
169
 
170
- sequence = sequence[:(chunk_length * num_chunks + 2 * _OVERLAP)]
171
  seq_length = len(sequence)
172
 
173
  for i in range(num_chunks):
174
  # get chunk
175
  start_pos = i * chunk_length
176
- end_pos = min(seq_length, (i+1) * chunk_length + 2 * _OVERLAP)
177
  chunk_sequence = sequence[start_pos:end_pos]
178
 
179
  # yield chunk
 
49
  _LICENSE = "https://www.ncbi.nlm.nih.gov/home/about/policies/"
50
 
51
  _CHUNK_LENGTHS = [6000, 12000]
 
52
 
53
 
54
  def filter_fn(char: str) -> str:
 
75
  class MultiSpeciesGenomesConfig(datasets.BuilderConfig):
76
  """BuilderConfig for The Human Reference Genome."""
77
 
78
+ def __init__(self, *args, chunk_length: int, overlap: int = 100, **kwargs):
79
  """BuilderConfig for the multi species genomes.
80
  Args:
81
  chunk_length (:obj:`int`): Chunk length.
82
+ overlap: (:obj:`int`): Overlap in base pairs for two consecutive chunks (defaults to 100).
83
  **kwargs: keyword arguments forwarded to super.
84
  """
85
  num_kbp = int(chunk_length/1000)
 
89
  **kwargs,
90
  )
91
  self.chunk_length = chunk_length
92
+ self.overlap = overlap
93
 
94
 
95
  class MultiSpeciesGenomes(datasets.GeneratorBasedBuilder):
 
163
  seq_length = len(sequence)
164
 
165
  # split into chunks
166
+ num_chunks = (seq_length - 2 * self.config.overlap) // chunk_length
167
 
168
  if num_chunks < 1:
169
  continue
170
 
171
+ sequence = sequence[:(chunk_length * num_chunks + 2 * self.config.overlap)]
172
  seq_length = len(sequence)
173
 
174
  for i in range(num_chunks):
175
  # get chunk
176
  start_pos = i * chunk_length
177
+ end_pos = min(seq_length, (i+1) * chunk_length + 2 * self.config.overlap)
178
  chunk_sequence = sequence[start_pos:end_pos]
179
 
180
  # yield chunk