OpenMendel / BGEN.jl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

minor_allele_dosage!'s outputs oscillates for some variants

olivierlabayle opened this issue · comments

Hi,

I am quite surprised to see that minor_allele_dosage! does not yield the same result when called multiple times for some variants. Could you please explain what exactly it represents and why it is the case?

using BGEN

b = Bgen(
    BGEN.datadir("example.8bits.bgen"); 
    sample_path=BGEN.datadir("example.sample"), 
    idx_path=BGEN.datadir("example.8bits.bgen.bgi")
    )
# Not reproducible
v = variant_by_rsid(b, "RSID_110")
mean(minor_allele_dosage!(b, v)) == 0.9621725f0
mean(minor_allele_dosage!(b, v)) == 1.0378275f0

# Reproducible
v = variant_by_rsid(b, "RSID_198")
mean(minor_allele_dosage!(b, v)) == 0.48411763f0
mean(minor_allele_dosage!(b, v)) == 0.48411763f0

Thank you for the report. It indeed is a bug. I did not test the case when someone runs the function twice on the same variant. If the minor allele is the second allele, it computes the first allele dosage and then "flips" the value (2 - first allele dosage). The values are cached. When called again, it flips the cached value, resulting in incorrect values. There is no flipping when the first allele is the minor allele, so you don't see this happening. I will fix the bug later today.

The minor allele in this package is whichever is less frequent between the first and the second allele, and the mean dosage must be below 1.0.

fixed in v0.1.16.