I have a file with genotype data. The second column has both alleles for a particular genetic variant concatenated, as below.
rs969931 CA 1.000 2.000 2.000 2.000 2.000 2.000 1.000 1.000
rs2745406 CT 0.000 2.000 2.000 1.000 1.000 2.000 1.000 1.000
rs6939431 AG 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0.000
rs1233427 AG 1.000 2.000 2.000 2.000 2.000 1.000 1.000 1.000
rs1233426 AG 1.000 2.000 2.000 2.000 2.000 1.000 1.000 1.000
rs1233425 GC 1.000 1.999 1.999 2.000 2.000 2.000 1.000 1.000
rs362546 GA 1.000 2.000 2.000 2.000 2.000 1.000 1.000 1.000
rs909968 AG 0.000 2.000 2.000 1.000 1.000 1.000 1.000 1.000
rs909967 GA 1.000 2.000 2.000 2.000 2.000 2.000 1.000 1.000
rs886381 AG 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000
I need to create a new file with the alleles as two separate columns, i.e. splitting the second column into two columns. Desired output below. Is there a way to specify multiple field separators in awk to achieve this?
rs969931 C A 1.000 2.000 2.000 2.000 2.000 2.000 1.000 1.000
rs2745406 C T 0.000 2.000 2.000 1.000 1.000 2.000 1.000 1.000
rs6939431 A G 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0.000
rs1233427 A G 1.000 2.000 2.000 2.000 2.000 1.000 1.000 1.000
rs1233426 A G 1.000 2.000 2.000 2.000 2.000 1.000 1.000 1.000
rs1233425 G C 1.000 1.999 1.999 2.000 2.000 2.000 1.000 1.000
rs362546 G A 1.000 2.000 2.000 2.000 2.000 1.000 1.000 1.000
rs909968 A G 0.000 2.000 2.000 1.000 1.000 1.000 1.000 1.000
rs909967 G A 1.000 2.000 2.000 2.000 2.000 2.000 1.000 1.000
rs886381 A G 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000
Best Answer
You can do it using the
sub
function inawk
:If you want tab-separated output, you can use:
Or in a variety of other tools:
Perl
Or, for tab-separated output:
GNU
sed
Other
sed
Shell