lundi 10 décembre 2018

AWK if else condition not printing correctly

I have the following testfile.txt:

CHROM   POS     REF     ALT     DP      POS     N_ALLELES       N_CHR   {REF}   {ALT}
chr1    16495   G       C       252     16495   2               2       0.5     0.5
chr1    16719   T       A       189     16719   2               2       0.5     0.5
chr1    16841   G       T       521     16841   2               2       0.5     0.5
chr1    17626   G       A       124     17626   2               2       0.5     0.5
chr1    17697   G       C       63      17697   2               2       0.5     0.5
chr1    19004   A       G       13      19004   2               2       0.5     0.5
chr1    69270   A       G       20      69270   2               2       0       1
chr1    69511   A       G       240     69511   2               2       0       1
chr1    69897   T       C       28      69897   2               2       0       1

I am trying to execute an awk command to add a new column based on the information from the text file but the following code is only working on the first conditions:

awk '{
    if ($9 == 0.5 && $10 == 0.5 && $7 == 2) {
        print $0"\thet";
    } else if (($9 == 0 && $10 == 0.5 && $7 == 3) || ($9 == 0.5 && $10 == 0 && $7 == 3)) {
        print $0"\t"het2;
    } else if (($9 == 0 && $10 == 1 && $7 == 2) || ($9 == 1 && $10 == 0 && $7 == 2)){
        print $0"\t"hom;
    }
}' testfile.txt 

And the output that I am obtaining is the following:

chr1    16495   G       C       252     16495   2       2       0.5     0.5     het
chr1    16719   T       A       189     16719   2       2       0.5     0.5     het
chr1    16841   G       T       521     16841   2       2       0.5     0.5     het
chr1    17626   G       A       124     17626   2       2       0.5     0.5     het
chr1    17697   G       C       63      17697   2       2       0.5     0.5     het
chr1    19004   A       G       13      19004   2       2       0.5     0.5     het
chr1    69270   A       G       20      69270   2       2       0       1
chr1    69511   A       G       240     69511   2       2       0       1
chr1    69897   T       C       28      69897   2       2       0       1
chr1    120983  C       T       35      120983  2       2       0.5     0.5     het

Can someone please explain me why my awk command is not working ?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire