This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to convert a meta-analysis file from PLINK (.meta) to a .csv or.txt to be read into R?

Hi,

I'm encountering issues with reading .meta files into R. I am assuming the file needs to be reformatted to a .csv or a .txt. Does anyone have any idea of how to convert the PLINK output for meta-analysis (plink.meta) to a file format readable by R?

Thanks!

plink r

I suggest you provide some more details: Is the .meta file a text file? Pasting the first few lines of the .meta file might increase your chances of getting an answer.

its the default output of plink meta-analysis which is plink.meta (text file). When I try to import it into R it can't differentiate the columns.

CHR          BP            SNP  A1  A2   N           P        P(R)    BETA BETA(R)       Q       I

   1      751343     rs28544273   T   A   2      0.9359      0.6009 -0.0026 -0.0400  0.1193   58.80
   1      751488    rs200141114   D   I   1          NA          NA      NA      NA      NA      NA
   1      751756    rs143225517   T   C   2      0.9346      0.6014 -0.0026 -0.0397  0.1195   58.74
   1      752566      rs3094315   G   A   2      0.9665      0.6312  0.0012  0.0306  0.1445   53.03

Thanks

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

2 answers

See the comments on converting spaces to tabs under https://www.cog-genomics.org/plink/1.9/other#tabspace .

Please post the code you are using to read the meta file and R is failing, also add error/warning messages. Plink output is Fixed Width Format, which should be easily read using below commands:

read.table("meta.txt", header = TRUE)

Or using data.table, for faster reading:

data.table::fread("meta.txt")

If above fails, then maybe try to use read as fixed width file using read.fwf function, see below StackOverflow post for more info:

Log in to answer this question.