Pages

Convert PLINK output to CSV Revisited

A while back, Stephen wrote a very nice post about converting PLINK output to a CSV file. If you are like me, you have used this a thousand times -- enough to get tired of typing lots of SED commands.

I just crafted a little BASH script that accomplishes the same effect with a single easy to type command. Insert the following text into your .bashrc file. This file is generally hidden in your UNIX home directory (you can see it if you type 'ls -al').

This version converts the infile to a tab-delimited output.

function cleanplink
{
sed -r 's/\s+/\t/g' $1 | sed -r 's/^\t//g' | sed -r 's/NA/\\N/g' > $1.txt
}

And this version converts to a CSV file.


function cleanplink
{
sed -r 's/\s+/,/g' $1 | sed -r 's/^,//g' | sed -r 's/NA/\\N/g' > $1.csv
}


I also converted the "NA" to a Null value for easy loading into MySQL, however you can remove that bit if you'd like:

function cleanplink
{
sed -r 's/\s+/,/g' $1 | sed -r 's/^,//g' > $1.csv
}


You use this function as follows:

bush@queso:~$ cleanplink plinkresults.assoc

and it produces a file with the same name, but with a ".csv" or a ".txt" on the end.