Home > Awk, QTL-detection, Shell, SNP > Learning by examples (3) : Creating a map

Learning by examples (3) : Creating a map

Although  not important for several kind of analysis, we may need a map file to describe the simulated data.

So we need to create a map file containing as many line as marker, a meaningful name for each SNP, the number of  the chromosome and a position in cM. This can be done with this tiny code :

#Enumerate the possible chromosome
for i in `seq 1 5`
#for each chromosome (1 to 5) write for each SNP one line in the corresponding map file
gawk -v BTA=$i 'END{for (i=1;i<=(NF-1)/2;i++){printf "%6i M%1i%10.10i %2i %5.2f\n",i,BTA,i,BTA,(i-1)*0.05}}' typ$i >map$i

Explanations :

Line 2, we use a for loop with the seq command delimited by to inverted apostrophe (alt gr +7), this will basically execute seq which will write number from 1 to 5, all this output will be redirected to the variable i.

Line 5, gawk is called with the -v argument, we pass one variable within the executed awk code. While processing the data gawk will consider that variable BTA exist and have the value passed through -v , i.e. $i, the chromosome beeing processed. Don’t be  confused here with, as instance, the variable “i”, normally any variable defined within the shell is  unknown by awk. Variable used by awk (i in the for instruction as instance) have nothing in common with the one used by the shell (they are private within awk ).

We use awk in a somehow very particular way, here all the line are read (even if it’s not mentionned), but the code that will be executed appear only once we’ve been through the entire file. Here the reading step helped to know the number of fields in the file. We then divide by two (as there are always two allele per SNP) to get the number of line to be written in the map file.

We extensively use the printf for the output. The format description follow the C format description style.

We are now ready for Phasing and QTL detection !

Categories: Awk, QTL-detection, Shell, SNP
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: