0

I have tab delimited file, I want to extract "exonic" entries from 2nd column,"nonsynonymous SNV" entries from 3rd column and values which are less than (<1) and dot(.) from column 4th,5th,7th

Chr     Func.refGene    ExonicFunc.refGene  1000g2015aug_eas 1000g2015a avsnp147    ExAC_ALL
chr1    intergenic      synonymous SNV      .                .          .           .
chr1    exonic          nonsynonymous SNV   1.2              .          .           .
chr2    exonic          nonsynonymous SNV   0.246            .          rs2022      0.4061
chr2    intronic        synonymous SNV      .                0.7386     rs2289093   0.7275
chr2    exonic          nonsynonymous SNV   0.6131           0.7376     rs227       0.7167
chr2    intergenic      nonsynonymous SNV   .                0.231      .           .
chr3    exonic          synonymous SNV      0.2192           0.2376     rs230       0.2205
chr3    intergenic      nonsynonymous SNV   2.01             0.2376     rs230       0.2204

Expected output

chr2    exonic  nonsynonymous SNV   0.246   .       rs2289195   0.4061
chr2    exonic  nonsynonymous SNV   0.6131  0.7376  rs2276599   0.7167

Following is code which i have written awk -F'\t' '$2~/exonic/ && $3~/nonsynonymous SNV/ && $4~/^0/ && $5~/^0/ && $7~/^0/{print $0}' inputfile.txt >> outputfile.txt This extract entries start with zero (which is less than 1) from column 4,5 and 7 but I don't know how to extract entries which are less than 1 and dot(.)

2
  • why 0.2192(in 4th column) is skipped from the output? Apr 28, 2017 at 12:25
  • I want "exonic" and "nonsynonymous SNV" entries from 2nd & 3rd column respectively. In case of 0.2192 it has "synonymous" entry in 3rd column, that's why i skipped that from output Apr 29, 2017 at 5:41

1 Answer 1

2

Rather than regular expression tests, I'd suggest string comparisons for the strings, and numeric comparisons for the numerics i.e.

$2 == "exonic"

and

$4+0 < 1

(the +0 forces numeric rather than lexical comparison). Aside from that, it's just a matter of getting the logic right:

$ awk -F'\t' '$2 == "exonic" && $3 == "nonsynonymous SNV" && ($4+0 < 1 || $4 == ".") && ($5+0 < 1 || $5 == ".") && ($7+0 < 1 || $7 == ".")' inputfile.txt
chr2    exonic  nonsynonymous SNV   0.246   .   rs2022  0.4061
chr2    exonic  nonsynonymous SNV   0.6131  0.7376  rs227   0.7167
1
  • Yes, your code work properly. Apr 29, 2017 at 5:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .