How to read a ".ld.bin" file produced by PLINK
2
1
Entering edit mode
6.5 years ago

I have a .ld.bin file produced by PLINK (cannot remember now how it was produced) which I want to plot. This .bin file is about 160Mbytes so I guess it could be really bigger if uncompressed as .ld (I have read that .ld format is just a table).

I cannot find any documentation in PLINK website about .bin file variant. However I found an R function which could help here:

ldMatrix <- readBin("myfile-chr25.ld.bin", what = "raw")

Although the function doesn't fail, generates an empty "what" object. The what parameter didn't worked for any of the supported types: int, numeric, character, etc. The UNIX file command just returns "data".

Any idea?

PLINK LD R • 3.3k views
ADD COMMENT
0
Entering edit mode
6.5 years ago
zx8754 12k

First argument of readBin is con, connection object, not a filename string. Try:

myFile <- file("myfile-chr25.ld.bin", "rb")
ldMatrix <- readBin(myFile, what = "raw")
close(myFile)

Not sure about "raw" bit. Here is a good tutorial on how to read write files with column names.

ADD COMMENT
0
Entering edit mode
4.8 years ago
lenore.pipes ▴ 20

I'm not sure why this isn't documented better. But this is what I tried. number_of_entries = p^2 for a p x p matrix

myFile <- file("myfile-chr25.ld.bin","rb")
ldMatrix <- readBin(myFile,what="double",endian="little",size=8,n=number_of_entries)
close(myFile)
ADD COMMENT
1
Entering edit mode

I have added a link under the .ld file format documentation to a sample readBin() call; let me know if this is still insufficient.

ADD REPLY

Login before adding your answer.

Traffic: 2225 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6