Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add empty! in read! method #18

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FormatSpecimens = "3372ea36-2a1a-11e9-3eb7-996970b6ffbd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"

[targets]
test = ["BioSequences", "Documenter", "FormatSpecimens", "Test"]
test = ["BioSequences", "Documenter", "FormatSpecimens", "Test", "CodecZlib"]
1 change: 0 additions & 1 deletion docs/src/man/gff3.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ record = GFF3.Record()

# Iterate over records.
while !eof(reader)
empty!(record)
read!(reader, record)
# do something
end
Expand Down
1 change: 1 addition & 0 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function Base.close(reader::Reader)
end

function Base.read!(reader::Reader, record::Record)
empty!(record)
return readrecord!(reader.state.stream, reader, record)
end

Expand Down
54 changes: 44 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using BioGenerics
using FASTX.FASTA
using FormatSpecimens
using GenomicFeatures
using CodecZlib

import BioSequences: @dna_str

Expand Down Expand Up @@ -74,9 +75,11 @@ import BioGenerics.Exceptions: MissingFieldException
# in-place parsing
stream = open(GFF3.Reader, filename)
entry = eltype(stream)()
records = GFF3.Record[]
while !eof(stream)
try
read!(stream, entry)
push!(records, copy(entry))
catch ex
if isa(ex, EOFError)
break
Expand All @@ -86,36 +89,67 @@ import BioGenerics.Exceptions: MissingFieldException
close(stream)

# copy
records = GFF3.Record[]
records2 = GFF3.Record[]
reader = open(GFF3.Reader, filename)
output = IOBuffer()
writer = GFF3.Writer(output)
for record in reader
write(writer, record)
push!(records, record)
push!(records2, record)
end
close(reader)
flush(writer)

records2 = GFF3.Record[]
records3 = GFF3.Record[]
for record in GFF3.Reader(IOBuffer(take!(output)))
push!(records3, record)
end
return records == records2 == records3
end

function check_gff3_parse_gzip(filename)

# in-place parsing
stream = GFF3.Reader(GzipDecompressorStream(open(filename)))
record = GFF3.Record()
records = GFF3.Record[]
while !eof(stream)
read!(stream, record)
push!(records, copy(record))
end
close(stream)

# copy
records2 = GFF3.Record[]
reader = GFF3.Reader(GzipDecompressorStream(open(filename)))

output = IOBuffer()
writer = GFF3.Writer(output)
for record in reader
write(writer, record)
push!(records2, record)
end
return records == records2
close(reader)
flush(writer)

records3 = GFF3.Record[]
for record in GFF3.Reader(IOBuffer(take!(output)))
push!(records3, record)
end
return records == records2 == records3
end

dir_gff3 = path_of_format("GFF3")

for specimen in list_valid_specimens("GFF3")

if hastag(specimen, "gzip")
# skip compressed files
continue
end

filepath = joinpath(dir_gff3, filename(specimen))

@test check_gff3_parse(filepath)
if hastag(specimen, "gzip")
@test check_gff3_parse_gzip(filepath)
else
@test check_gff3_parse(filepath)
end

end

Expand Down
Loading