plink2 king.bin matrix to kin0 table?

178 views
Skip to first unread message

Salvatore Loguercio

unread,
Aug 6, 2022, 12:32:36 PM8/6/22
to plink2-users
Hello, Plink2 users,

I generated a large kinship matrix in king.bin format and was wondering if could be converted in tabular kin0 format (--make-king-table output, without having to re-run this one).

Alternatively, could the binary king.bin matrix be loaded in R for analysis?

Thank you!

Christopher Chang

unread,
Aug 7, 2022, 12:24:52 PM8/7/22
to plink2-users
The default .kin0 tabular format contains additional information not in the .king.bin file, so direct conversion is not possible unless you're willing to lose some fields.

The R command for loading .bin output is documented under https://www.cog-genomics.org/plink/2.0/distance#make_rel .  (Remove the "size=4" part unless you specified a single-precision file with 'bin4'.)

Salvatore Loguercio

unread,
Aug 7, 2022, 12:33:34 PM8/7/22
to plink2-users
Great, thank you very much!

Salvatore Loguercio

unread,
Aug 7, 2022, 1:05:34 PM8/7/22
to plink2-users
I tried the readBin R command mentioned in https://www.cog-genomics.org/plink/2.0/distance#make_rel. My understanding is that it will load all values of the matrix in a single continuous numeric vector, right? Then I will have to reconstitute the original matrix shape with row/column names etc.

Trying the get_grm function from the R package genio for this task, but it is really demanding in terms of memory. If there are valid alternatives out there for this task (=rebuilding the kinship matrix in R from plink bin output) would be really useful to know.

Thanks!

Christopher Chang

unread,
Aug 7, 2022, 1:09:13 PM8/7/22
to plink2-users
Yes, readBin loads into a single numeric vector.  It should be straightforward to set the matrix shape and load row/column names from the .king.id file?

Salvatore Loguercio

unread,
Aug 7, 2022, 1:52:42 PM8/7/22
to plink2-users
I see. then something like
matrix(bin_kin_vector,nrow = length(king.id),ncol = length(king.id))
will do.

Thanks for the clarification!

Reply all
Reply to author
Forward
0 new messages