Skip to content

Commit 4cf33a7

Browse files
committed
fixing BCF tests
1 parent 0df96ba commit 4cf33a7

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

src/bcf/bcf.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ module BCF
1212
import GeneticVariation.VCF
1313
import BGZFStreams
1414
import TranscodingStreams
15-
import BioGenerics.IO: AbstractReader, AbstractWriter, stream
15+
using BioGenerics
16+
import BioGenerics: BioGenerics, isfilled
17+
import BioGenerics.Exceptions: MissingFieldException, missingerror
18+
19+
function parsehex(str)
20+
return map(x -> parse(UInt8, x, base=16), split(str, ' '))
21+
end
1622

1723
include("record.jl")
1824
include("reader.jl")

src/bcf/reader.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# This file is a part of BioJulia.
77
# License is MIT: https://github.com/BioJulia/GeneticVariation.jl/blob/master/LICENSE
8-
struct Reader{T<:IO} <: AbstractReader
8+
struct Reader{T<:IO} <: BioGenerics.IO.AbstractReader
99
version::Tuple{UInt8,UInt8} # (major, minor)
1010
header::VCF.Header
1111
stream::BGZFStreams.BGZFStream{T}
@@ -38,7 +38,7 @@ function Reader(input::IO)
3838
data = read(stream, l_header)
3939

4040
# parse VCF header
41-
vcfreader = VCF.Reader(BufferedStreams.BufferedInputStream(data))
41+
vcfreader = VCF.Reader(IOBuffer(data))
4242

4343
return Reader((major, minor), vcfreader.header, stream)
4444
end
@@ -55,9 +55,15 @@ end
5555
header(reader::BCF.Reader)::VCF.Header
5656
Get the header of `reader`.
5757
"""
58-
5958
function header(reader::Reader)
60-
return header(reader)
59+
return reader.header
60+
end
61+
62+
function Base.close(reader::Reader)
63+
if reader.stream isa IO
64+
close(reader.stream)
65+
end
66+
return nothing
6167
end
6268

6369
function Base.read!(reader::Reader, record::Record)

src/bcf/writer.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# This file is a part of BioJulia.
77
# License is MIT: https://github.com/BioJulia/GeneticVariation.jl/blob/master/LICENSE
88

9-
struct Writer{T<:IO} <: AbstractWriter
9+
struct Writer{T<:IO} <: BioGenerics.IO.AbstractWriter
1010
stream::BGZFStreams.BGZFStream{T}
1111
end
1212

@@ -43,3 +43,10 @@ function Base.write(writer::Writer, record::Record)
4343
n += write(writer.stream, record.data)
4444
return n
4545
end
46+
47+
function Base.close(writer::Writer)
48+
if writer.stream isa IO
49+
close(writer.stream)
50+
end
51+
return nothing
52+
end

src/vcf/reader.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ function Base.read!(rdr::Reader, record::Record)
111111

112112
rdr.state.state = cs
113113
rdr.state.linenum = ln
114-
@info rdr.state.stream, "Line $(ln)"
115114
rdr.state.filled = found
116115

117116
if found

test/bcf.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
record.sharedlen = 0x1c
99
record.indivlen = 0x00
1010
# generated from bcftools 1.3.1 (htslib 1.3.1)
11-
record.data = parsehex("00 00 00 00 ff ff ff ff 01 00 00 00 01 00 80 7f 00 00 01 00 00 00 00 00 07 17 2e 00")
11+
record.data = BCF.parsehex("00 00 00 00 ff ff ff ff 01 00 00 00 01 00 80 7f 00 00 01 00 00 00 00 00 07 17 2e 00")
1212
record.filled = 1:lastindex(record.data)
1313
@test BCF.chrom(record) == 1
1414
record = BCF.Record(record)
@@ -35,7 +35,7 @@
3535

3636
bcfdir = path_of_format("BCF")
3737
reader = BCF.Reader(open(joinpath(bcfdir, "example.bcf")))
38-
let header = header(reader)
38+
let header = BCF.header(reader)
3939
@test length(findall(header, "fileformat")) == 1
4040
@test findall(header, "fileformat")[1] == VCF.MetaInfo("##fileformat=VCFv4.2")
4141
@test length(findall(header, "FORMAT")) == 4
@@ -62,12 +62,14 @@
6262
close(reader)
6363

6464
# round-trip test
65-
for specimen in YAML.load_file(joinpath(bcfdir, "index.yml"))
65+
bcfdir = path_of_format("BCF")
66+
data = TOML.parsefile(joinpath(bcfdir, "index.toml"))
67+
for specimen in data["valid"]
6668
filepath = joinpath(bcfdir, specimen["filename"])
6769
records = BCF.Record[]
6870
reader = open(BCF.Reader, filepath)
6971
output = IOBuffer()
70-
writer = BCF.Writer(output, header(reader))
72+
writer = BCF.Writer(output, BCF.header(reader))
7173
for record in reader
7274
write(writer, record)
7375
push!(records, record)

test/vcf.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@
252252

253253
# round-trip test
254254
vcfdir = path_of_format("VCF")
255-
# Parse the TOML file; the file should define an array of tables under the key "specimen"
256-
# Parse the TOML file. The file now consists of an array of tables under the key "valid".
257255
data = TOML.parsefile(joinpath(vcfdir, "index.toml"))
258256

259257
for specimen in data["valid"]
@@ -277,7 +275,3 @@
277275
@test records == records2
278276
end
279277
end
280-
281-
function parsehex(str)
282-
return map(x -> parse(UInt8, x, base = 16), split(str, ' '))
283-
end

0 commit comments

Comments
 (0)