awk to print line(s) meeting condions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to print line(s) meeting condions
# 1  
Old 05-10-2017
awk to print line(s) meeting condions

In the awk below which executes, but the out is empty, I am trying to print the line that meets both conditions below:
Code:
1. $7 = PASS
2.AF= > .03 or 3%
3. function = nonsense or frameshift

In the file below in the second line'function'is not present in the line and AF= < 3%.

I am close I think, but not able to get the script to work as desired. Thank you Smilie.

file tab-delimited
Code:
chr10 89624278 . G T 62.8836 PASS AF=0.0785393;AO=297;DP=4155;FAO=157;FDP=1999;FR=.;FRO=1842;FSAF=77;FSAR=80;FSRF=908;FSRR=934;FWDB=0.0113997;FXX=4.99998E-4;HRUN=1;LEN=1;MLLD=117.237;OALT=T;OID=.;OMAPALT=T;OPOS=89624278;OREF=G;PB=.;PBP=.;QD=0.12583;RBI=0.040843;REFB=5.39678E-4;REVB=-0.0392199;RO=3844;SAF=150;SAR=147;SRF=1936;SRR=1908;SSEN=0;SSEP=0;SSSB=0.00159791;STB=0.502301;STBP=0.96;TYPE=snp;VARB=-0.00676678;FUNC=[{'origPos':'89624278','origRef':'G','normalizedRef':'G','gene':'PTEN','normalizedPos':'89624278','normalizedAlt':'T','gt':'pos','codon':'TAG','coding':'c.52G>T','transcript':'NM_000314.4','function':'nonsense','protein':'p.Glu18Ter','location':'exonic','origAlt':'T','exon':'1'}] GT:GQ:DP:FDP:RO:FRO:AO:FAO:AF:SAR:SAF:SRF:SRR:FSAR:FSAF:FSRF:FSRR:QT 0/1:62:4155:1999:3844:1842:297:157:0.0785393:147:150:1936:1908:80:77:908:934:1
chr10 89624293 COSM86051 T G 341.74 PASS AF=0;AO=1;DP=4145;FAO=0;FDP=1995;FR=.;FRO=1995;FSAF=0;FSAR=0;FSRF=1008;FSRR=987;FWDB=0.0136548;FXX=0.00249999;HRUN=2;LEN=1;MLLD=151.799;OALT=G,G;OID=COSM86051,COSM86051;OMAPALT=G,G;OPOS=89624293,89624293;OREF=T,T;PB=.;PBP=.;QD=0.685192;RBI=0.0172428;REFB=4.38663E-6;REVB=0.010529;RO=4136;SAF=0;SAR=1;SRF=2077;SRR=2059;SSEN=0;SSEP=0;SSSB=-0.00528832;STB=0.5;STBP=1;TYPE=snp;VARB=0;HS;FUNC=[{'transcript':'NM_000314.4','gene':'PTEN','location':'exonic','exon':'1'}] GT:GQ:DP:FDP:RO:FRO:AO:FAO:AF:SAR:SAF:SRF:SRR:FSAR:FSAF:FSRF:FSRR:QT 0/0:341:4145:1995:4136:1995:1:0:0:1:0:2077:2059:0:0:1008:987:0

awk
Code:
awk -F'\t' '{$7=="PASS" &&
                        if(/AF=[^;]*/+0 > .03 && "'function'" == "nonsense" || "'function'" == "frameshift"){
                                       print
      }
     }
' file > out

desired out tab-delimited --- only line that meets both conditions
Code:
chr10 89624278 . G T 62.8836 PASS AF=0.0785393;AO=297;DP=4155;FAO=157;FDP=1999;FR=.;FRO=1842;FSAF=77;FSAR=80;FSRF=908;FSRR=934;FWDB=0.0113997;FXX=4.99998E-4;HRUN=1;LEN=1;MLLD=117.237;OALT=T;OID=.;OMAPALT=T;OPOS=89624278;OREF=G;PB=.;PBP=.;QD=0.12583;RBI=0.040843;REFB=5.39678E-4;REVB=-0.0392199;RO=3844;SAF=150;SAR=147;SRF=1936;SRR=1908;SSEN=0;SSEP=0;SSSB=0.00159791;STB=0.502301;STBP=0.96;TYPE=snp;VARB=-0.00676678;FUNC=[{'origPos':'89624278','origRef':'G','normalizedRef':'G','gene':'PTEN','normalizedPos':'89624278','normalizedAlt':'T','gt':'pos','codon':'TAG','coding':'c.52G>T','transcript':'NM_000314.4','function':'nonsense','protein':'p.Glu18Ter','location':'exonic','origAlt':'T','exon':'1'}] GT:GQ:DP:FDP:RO:FRO:AO:FAO:AF:SAR:SAF:SRF:SRR:FSAR:FSAF:FSRF:FSRR:QT 0/1:62:4155:1999:3844:1842:297:157:0.0785393:147:150:1936:1908:80:77:908:934:1

# 2  
Old 05-10-2017
Hello cmccabe,

If your Input_file is same as shown sample Input_file then following may help you.
Code:
awk -F'[ ;=,:]' '$7=="PASS" && $9>.03 && $107 ~ /function/ && $108 ~ /nonsense/'   Input_file

In case your Input_file is NOT same as shown sample Input_file which means it's fields are NOT fixed then you need to traverse through the fields and check for these values like PASS,function etc etc and store their field number's value and then check your all conditions by using their field's values. I hope this helps.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 05-10-2017
Hi,
You can try this:
Code:
awk -F'\t' '$7 == "PASS" && /AF=([1-9]|[0-9]\.[1-9]|0\.0[3-9])/ && /'"'"'function'"'"':'"'"'(nonsense|frameshift)'"'"'/' file

Regards.
This User Gave Thanks to disedorgue For This Post:
# 4  
Old 05-11-2017
Thank you both very much Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

2. Shell Programming and Scripting

awk script -print line when $2 > $2 of previous line

Hi all, From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30. Input would be like ... AN237 010 193019 0502 1 CSU Amoxycillin AN237 080 ... (2 Replies)
Discussion started by: gafoleyo73
2 Replies

3. Shell Programming and Scripting

awk to print in a line

hi all, i have text file with sample text 01 02 .. abc .. def .. xyz .. x12 03 04 .. z123 .. x234 (6 Replies)
Discussion started by: posner
6 Replies

4. UNIX for Dummies Questions & Answers

awk...print first line...

hello all, I am trying to use the AWK cmd on unix and trying to figre out how i can only print the first line and now rest of the line...so for example... $ lsnrctl version|grep Version| awk '{print $5}'| awk -F. '{print $1}'|uniq 11 NT Adapter for but i only want 11 to print out there... (3 Replies)
Discussion started by: abdul.irfan2
3 Replies

5. Shell Programming and Scripting

awk to print on the same line

Hi all, I've a script that uses awk to parse the output of wget during a database update. The code I use is: wget -c ftp://ftpsite/file 2>&1 | awk '/0%/ {print}'But this spits out each progress line on a new line: 37250K .......... .......... .......... .......... .......... 80% 10.9M 1s ... (2 Replies)
Discussion started by: euval
2 Replies

6. Shell Programming and Scripting

awk - print new line

Hi! Could you pls help me with my problem? My task is to find the longest line in several files - that's not the problem the problem is, I want command bellow to be stored in array, but one result per line: set line = (`cat $file | awk '{print NR, length, $0, "\n"}' | grep "^* $longest"`) the... (3 Replies)
Discussion started by: laco42
3 Replies

7. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
Discussion started by: ajp7701
5 Replies

8. Shell Programming and Scripting

AWK print all in one line

Hello, I want to parse a vcal file with awk, and later import the specific output file into excel. I want everything on one line. -------- file testcal.ics ------------- BEGIN:VCALENDAR PRODID:-//WebCalendar-v1.0.5 VERSION:2.0 METHOD:PUBLISH BEGIN:VEVENT... (3 Replies)
Discussion started by: sdohn
3 Replies

9. Shell Programming and Scripting

print any required line by its line no using awk and its NR variable

how to print any required line by its line no using awk and its NR variable for eg: ------------ 121343 adfdafd 21213sds dafadfe432 adf.adf%adf --------------- requied o/p if give num=3 it print: 21213sds -------------------------------------- (2 Replies)
Discussion started by: RahulJoshi
2 Replies

10. UNIX for Dummies Questions & Answers

awk print line

Hi All, I know that i can print the lines from awk just using the print method, but i need to print stuff before it i.e: BEGIN { i=0 } { i++ print i ")" print } END { } Here the output is: (7 Replies)
Discussion started by: Chiefos
7 Replies
Login or Register to Ask a Question