This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How does plink read bed files?

plink bed files uses 2 bits for each genotype data point, which is most efficient in terms of storage space, but not so convenient for numerical analysis. I am wondering how does plink read these bits into a matrix of int/double for linear algebra operations?

plink

Have you gone through the source code?

I am trying to, but I am not that good at C. Could you tell what functions are involved so that I can focus on these?

I'd search the source code for fopen and fread, since those will give you a clue where to start.

1 answer

The short answer is that it usually doesn't. Whenever possible, PLINK 1.9 never unpacks the data; instead it uses bitwise operations and population count to perform computation directly on the 2-bit representation.

Log in to answer this question.