Skip to content

Commit

Permalink
Merge branch 'hotfix/seek'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Feb 27, 2019
2 parents bfc8cda + 1dce339 commit 4b7fa4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Bedgraph"
uuid = "0bcc2ff6-69eb-520d-bede-0374fc5bd2fd"
authors = ["Ciarán O'Mara <[email protected]>"]
version = "1.0.4"
version = "1.0.5"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
5 changes: 3 additions & 2 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ end


function seekNextRecord(io::IO) :: Nothing
seekstart(io)

pos = position(io)
initial = pos == 0 ? -1 : pos # Note: Allows for the fist line of headerless bedGraph file to be read.
line = ""

while !eof(io) && !isLikeRecord(line)
while !eof(io) && (!isLikeRecord(line) || pos == initial)
pos = position(io)
line = readline(io)
end
Expand Down Expand Up @@ -57,6 +57,7 @@ function readRecord(io::IO) :: Union{Nothing, Record}
end

function readRecords(io::IO) :: Vector{Record}
seekstart(io)
seekNextRecord(io)

records = Vector{Record}()
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ end

# Check things for headerless Bag.files.
open(Bag.file_headerless, "r") do io

# Check that the first record of a headerless bedGraph file can be sought.
Bedgraph.seekNextRecord(io)
@test position(io) == 0
@test readline(io) == Bag.line1
@test readline(io) == Bag.line1 # IO position is at the start of line 2.

# Check behaviour of consecutive calls to Bedgraph.seekNextRecord(io).
Bedgraph.seekNextRecord(io) # Skip to start of line 3.
Bedgraph.seekNextRecord(io) # Skip to start of line 4.
@test readline(io) == Bag.line4

end


Expand Down

0 comments on commit 4b7fa4a

Please sign in to comment.