Skip to content

Commit b82477a

Browse files
committed
Do not reach into TranscodingSteams internals
When computing a FASTA index, previously, FASTX used the private state of Buffer from TranscodingStreams. However, in this case, it can just as easily be computed using a local variable.
1 parent 868d702 commit b82477a

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FASTX"
22
uuid = "c2308a5c-f048-11e8-3e8a-31650f418d12"
33
authors = ["Sabrina J. Ward <sabrinajward@protonmail.com>", "Jakob N. Nissen <jakobnybonissen@gmail.com>"]
4-
version = "2.1.4"
4+
version = "2.1.5"
55

66
[weakdeps]
77
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"

src/fasta/index.jl

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,6 @@ function Base.write(io::IO, index::Index)
209209
n
210210
end
211211

212-
function Base.print(io::IO, index::Index)
213-
buffer = IOBuffer()
214-
write(buffer, index)
215-
String(take!(buffer))
216-
end
217-
218212
index_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

Comments
 (0)