@@ -209,12 +209,6 @@ function Base.write(io::IO, index::Index)
209209 n
210210end
211211
212- function Base. print (io:: IO , index:: Index )
213- buffer = IOBuffer ()
214- write (buffer, index)
215- String (take! (buffer))
216- end
217-
218212index_fasta_actions = Dict (
219213 :mark => :(@mark ),
220214 :countline => :(linenum += 1 ),
@@ -226,15 +220,9 @@ index_fasta_actions = Dict(
226220 :description => quote
227221 uses_rn_newline = byte == UInt8 (' \r ' )
228222 no_more_seqlines = false
229-
230- # Disturbingly, there is no API to get the absolute position of
231- # an Automa machine operating on a stream. We ought to fix this.
232- # This workaround works ONLY for a NoopStream,
233- # and relies on abusing the internals.
234- buffer_offset = buffer. transcoded - buffer. marginpos + 1
235-
236- # We want 0-indexed, p is one-indexed, and we need the offset of first sequence
237- offset = buffer_offset + p + uses_rn_newline
223+ # +1 for > symbol, +1 for newline, +1 if \r is used
224+ offset += p - @markpos () + uses_rn_newline + 2
225+ last_offset = offset
238226 end ,
239227 :seqline => quote
240228 # Validate line terminator is same, i.e. no seq have have both \r\n and \n
@@ -254,6 +242,7 @@ index_fasta_actions = Dict(
254242 elseif current_seqwidth < seqwidth
255243 no_more_seqlines = true
256244 end
245+ offset += current_seqwidth + 1 + uses_rn_newline
257246 seqlen += current_seqwidth
258247 end
259248 end ,
@@ -262,7 +251,7 @@ index_fasta_actions = Dict(
262251
263252 names[identifier] = record_count
264253 push! (lengths, seqlen)
265- push! (offsets, offset )
254+ push! (offsets, last_offset )
266255 enc_linebases = (seqwidth % UInt)
267256 enc_linebases |= ifelse (uses_rn_newline, typemin (Int) % UInt, UInt (0 ))
268257 push! (encoded_linebases, enc_linebases)
@@ -278,6 +267,8 @@ initcode = quote
278267 offsets = Int[]
279268 encoded_linebases = UInt[]
280269
270+ offset = 0
271+ last_offset = 0
281272 seqwidth = - 1
282273 seqlen = 0
283274 linenum = 1
0 commit comments