Skip to content

Commit

Permalink
remove unnecessary tests in write_PGEN, rid BGEN warning
Browse files Browse the repository at this point in the history
  • Loading branch information
biona001 committed Sep 2, 2022
1 parent e11c805 commit 09e0b33
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end
g_pgen_ld = similar(g_pgen)
d_pgen = Array{Float64}(undef, p.header.n_samples)
for (v_bgen, v_pgen) in zip(BGEN.iterator(b), PGENFiles.iterator(p)) #
d_bgen = BGEN.ref_allele_dosage!(b, v_bgen)
d_bgen = BGEN.first_allele_dosage!(b, v_bgen)
PGENFiles.alt_allele_dosage!(d_pgen, g_pgen, p, v_pgen)
@test all(isapprox.(d_bgen, d_pgen; atol=5e-5, nans=true))
PGENFiles.alt_allele_dosage!(d_pgen, g_pgen, p, v_pgen; genoldbuf=g_pgen_ld)
Expand All @@ -149,46 +149,17 @@ end

@testset "write PGEN" begin
# bitstring2byte function
@test bitstring2byte("01110001") == 0x71
@test bitstring2byte("11111111") == 0xff
@test PGENFiles.bitstring2byte("01110001") == 0x71
@test PGENFiles.bitstring2byte("11111111") == 0xff

# bytes function (example at 2.2.6)
@test PGENFiles.bytes(99325313, len=8) == [0x81, 0x95, 0xeb, 0x05, 0x00, 0x00, 0x00, 0x00]
@test PGENFiles.int2bytes(99325313, len=8) == [0x81, 0x95, 0xeb, 0x05, 0x00, 0x00, 0x00, 0x00]

# dosage_to_uint16 function (example at end of 2.3.5)
ploidy = 2
@test PGENFiles.dosage_to_uint16(0.75, ploidy) == [0x00, 0x30]
@test PGENFiles.dosage_to_uint16(1.5, ploidy) == [0x00, 0x60]

# write_variant_record function (example at end of 2.3.5, modified so all samples have dosages)
N = 488377
xj = fill(0.75, N)
xj[10000] = 1.5
open("test_io_file", "w") do io
b = PGENFiles.write_variant_record(io, xj)
end
result = open("test_io_file") do io
read(io)
end
rm("test_io_file", force=true)
@test result[1:61047] == fill(0xff, 61047)
@test result[61048] ==
for i in 1:9999
@test result[61049+2(i-1) : 61049+2(i-1)+1] == [0x00, 0x30]
end
@test result[61049+2(10000-1) : 61049+2(10000-1)+1] == [0x00, 0x60]
for i in 10001:N
@test result[61049+2(i-1) : 61049+2(i-1)+1] == [0x00, 0x30]
end

# write_variant_record function (test if each block have fixed number of bytes)
io = open("test_io_file", "w")
n_samples = 800
xj = 2rand(n_samples)
b = PGENFiles.write_variant_record(io, xi) # b is 1700
close(io); rm("test_io_file", force=true);
@test 2^16 * b == 111411200

# write_PGEN function
bfile = Bgen(PGENFiles.datadir("example.16bits.bgen"))
bgenG, nsamples, Gchr, Gpos, GsnpID, Gref, Galt = convert_gt(Float64, bfile)
Expand Down

0 comments on commit 09e0b33

Please sign in to comment.