我是这样归档的:
1 51710 . C A . clustered_events;contamination;germline_risk;read_position;t_lod DP=1;ECNT=6;POP_AF=1.000e-03;P_GERMLINE=-1.372e-02;TLOD=4.20 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:PGT:PID:SA_MAP_AF:SA_POST_PROB 0/1:0,1:1.000:1:0,0:0,1:26:0,136:43:2:0|1:51637_C_T:0.990,0.00,1.00:0.025,0.028,0.947
19 27733067 . A G,C . clustered_events;contamination;germline_risk;multiallelic DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB 0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
20 42199704 . GGT G,GGTGGGTGGGTGTGTGT . germline_risk DP=100;ECNT=2;POP_AF=0.112,0.024;P_GERMLINE=-2.964e-04,-8.826e-06;TLOD=3.76,9.83 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB 0/1/2:1,2,7:0.168,0.301:20:1,1,4:9,1,1:34,35:147,203,146:60,60:51,62:0.192,0.253,0.263:0.038,0.014,0.948
我想在两个步骤中对行进行 grep:
具有DP > 45
的行。然后,在最后一列中的第一个:
之后具有值的行> 2
因此,在第一行中,我们可以看到 DP 是 = 1,之后的第一个值是:在最后一列中 = 0
在第二行中,DP = 60,之后的第一个值:在最后一列中 = 5
从上面的示例输入文件中,首先我们应该得到:
19 27733067 . A G,C . clustered_events;contamination;germline_risk;multiallelic DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB 0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
20 42199704 . GGT G,GGTGGGTGGGTGTGTGT . germline_risk DP=100;ECNT=2;POP_AF=0.112,0.024;P_GERMLINE=-2.964e-04,-8.826e-06;TLOD=3.76,9.83 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB 0/1/2:1,2,7:0.168,0.301:20:1,1,4:9,1,1:34,35:147,203,146:60,60:51,62:0.192,0.253,0.263:0.038,0.014,0.948
在第二个之后,我们应该得到:
19 27733067 . A G,C . clustered_events;contamination;germline_risk;multiallelic DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB 0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
92,0.253,0.263:0.038,0.014,0.948
请提供任何帮助吗?
grep 是尝试比较数字以查看它们是否大于或小于的错误工具。
他是一个perl单行代码,打印符合两个条件的行:
perl -ane 'print if $F[7] =~ /DP=(d+)/ && $1 > 45 && $F[9] =~ /:(d+)/ && $1 > 2' input.txt
如果你坚持使用 grep,你可以通过以下方式获得 DP> 45
grep 'DP=(4[6-9]|[5-9][0-9]|[1-9][0-9]{2,})[^0-9]'
# | | |
# 46-49 | 100..∞
# 50-99
你能试试下面的吗?
awk '
{
split($8,array,"[;=]")
if(array[1]=="DP" && array[2]>45){
split($10,array1,"[:,]")
if(array1[2]>2){
print
}
}
}' Input_file
说明:现在为上述代码添加说明。
awk ' ##Starting awk program here.
{ ##Starting block for statements here.
split($8,array,"[;=]") ##Using awk out of box function split for splitting 8th field and saving it to array with delimiter ;=
if(array[1]=="DP" && array[2]>45){ ##Checking condition if 1st element of array is DP and 2nd element value is greater than 45 then:
split($10,array1,"[:,]") ##Splitting 10th field to array1 with delkimter : and , here.
if(array1[2]>2){ ##Checking condition if array1 2nd element if its value is greater than 2 then do following.
print ##Printing the current line value here.
} ##Closing block for above if condition here.
} ##Closing block for previous if condition here.
}' Input_file ##Mentioning Input_file name here.
使用 GNU awk 用于 3rd arg 匹配():
$ awk 'match($0,/ DP=([^;]+).* [^:]+:([^,]+)/,a) && (a[1] > 45) && (a[2] > 2)' file
19 27733067 . A G,C . clustered_events;contamination;germline_risk;multiallelic DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14 GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB 0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
为作业使用正确的工具,请参阅"bcftools 视图"选项 有关详细信息,如下所示的内容应该可以工作:
bcftools view -i 'INFO/DP > 45 & FORMAT/AD[0:0] > 2' myFile.vcf
bcftools手册中的更多选项:
INFO/AF[0] > 0.3 .. first AF value bigger than 0.3 FORMAT/AD[0:0] > 30 .. first AD value of the first sample bigger than 30 FORMAT/AD[0:1] .. first sample, second AD value FORMAT/AD[1:0] .. second sample, first AD value DP4[*] == 0 .. any DP4 value FORMAT/DP[0] > 30 .. DP of the first sample bigger than 30 FORMAT/DP[1-3] > 10 .. samples 2-4 FORMAT/DP[1-] < 7 .. all samples but the first FORMAT/DP[0,2-4] > 20 .. samples 1, 3-5 FORMAT/AD[0:1] .. first sample, second AD field FORMAT/AD[0:*], AD[0:] or AD[0] .. first sample, any AD field FORMAT/AD[*:1] or AD[:1] .. any sample, second AD field (DP4[0]+DP4[1])/(DP4[2]+DP4[3]) > 0.3 CSQ[*] ~ "missense_variant.*deleterious"