Skip to content

Commit

Permalink
more rigorous tests for multiple calls for dosage
Browse files Browse the repository at this point in the history
  • Loading branch information
kose-y committed May 3, 2023
1 parent 787e0a1 commit 758d453
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/genotypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ function second_dosage!(data::Vector{<:AbstractFloat}, p::Preamble)
@inbounds for n in (p.n_samples - p.n_samples % 8 + 1):p.n_samples
data[n] = 2.0 - data[n]
end

end

"""
Expand Down Expand Up @@ -561,6 +562,7 @@ function first_allele_dosage!(b::Bgen, v::Variant;
if genotypes.minor_allele_dosage && genotypes.minor_idx != 1
second_dosage!(genotypes.dose, p)
end
genotypes.minor_allele_dosage = (genotypes.minor_idx == 1)
return v.genotypes.dose
end
if (decompressed !== nothing && !is_decompressed) ||
Expand Down Expand Up @@ -610,6 +612,7 @@ function first_allele_dosage!(b::Bgen, v::Variant;
if clear_decompressed
clear_decompressed!(genotypes)
end
genotypes.minor_allele_dosage = (genotypes.minor_idx == 1)
return data
end

Expand Down
11 changes: 11 additions & 0 deletions test/test_minor_allele_dosage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,22 @@ b = Bgen(
v = variant_by_rsid(b, "RSID_110")
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.9621725f0)
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.9621725f0)
@test isapprox(mean(first_allele_dosage!(b, v)), 2 - 0.9621725f0)
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.9621725f0)
clear!(v)
@test isapprox(mean(first_allele_dosage!(b, v)), 2 - 0.9621725f0)
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.9621725f0)


# first allele minor
v = variant_by_rsid(b, "RSID_198")
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.48411763f0)
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.48411763f0)
@test isapprox(mean(first_allele_dosage!(b, v)), 0.48411763f0)
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.48411763f0)
clear!(v)
@test isapprox(mean(first_allele_dosage!(b, v)), 0.48411763f0)
@test isapprox(mean(minor_allele_dosage!(b, v)), 0.48411763f0)
end

@testset "mean_impute" begin
Expand Down

0 comments on commit 758d453

Please sign in to comment.