我正在分析一些基因组测序数据,我正在尝试使用我的脚本来寻找起始线#chr'然后获取第1,2,4和5列中的值,然后搜索对应于RO和AO的数字,并通过AO /(AO + RO)计算等位基因变异的频率。
当我回去并通过计算AO /(AO + RO)手动检查时,我的脚本大部分时间都有效。但有时候喜欢以下阅读它会失败。
对于以下内容,我的脚本计算出AO /(AO + RO)为0.214286,但我将其计算为3 /(3 + 7757)= 0.000387。如果有人能够理解为什么会这样,我会很感激。
chr4 110541280 . G A 0 . AB=0;ABP=0;AC=0;AF=0;AN=2;AO=3;CIGAR=1X;DP=7760;DPB=7760;DPRA=0;EPP=9.52472;EPPR=16838.4;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=60;NS=1;NUMALT=1;ODDS=10694.5;PAIRED=0;PAIREDR=0;PAO=0;PQA=0;PQR=0;PRO=0;QA=111;QR=280123;RO=7757;RPP=9.52472;RPPR=16838.4;RUN=1;SAF=3;SAP=9.52472;SAR=0;SRF=7757;SRP=16847.1;SRR=0;TYPE=snp GT:DP:RO:QR:AO:QA:GL 0/0:7760:7757:280123:3:111:0,-10,-10
我的awk声明:
awk 'v {
ro=gensub(/^.*;RO=([0-9]*).*$/, "\\1", "1");
printf "%s %f\n", f, (ao/(ao + ro)); v=0
}
/^chr/ {ao=gensub(/^.*;AO=([0-9]*).*$/,"\\1", "1");
v=1;
f=$1 FS $2 FS $4 FS $5
}' $VCFDIR/$currentfile.vcf >> $VCFDIR/totalvariants.txt #output all to single file
awk '{print $5}' $VCFDIR/totalvariants.txt > $VCFDIR/allelefreqs.txt
对于Ref,这是我使用Karakfa的答案运行的整个脚本。
currentfile=finalOutput.bam
VCFDIR=/dir
awk '/^chr/{match($0,/;AO=([^;]*);.*;RO=([^;]*);/,v);
print $1,$2,$4,$5,v[1]/(v[1]+v[2])}' $VCFDIR/$currentfile.vcf >> $VCFDIR/totalvariants.txt #output all to single file
awk '{print $5}' $VCFDIR/totalvariants.txt > $VCFDIR/allelefreqs.txt
答案 0 :(得分:2)
要求救援!
awk '/^chr/{match($0,/;AO=([^;]*);.*;RO=([^;]*);/,v);
print $1,$2,$4,$5,v[1]/(v[1]+v[2])}'
预计AO会出现在RO
之前使用测试数据dna
chr4 110541280 . G A 0 . AB=0;ABP=0;AC=0;AF=0;AN=2;AO=3;CIGAR=1X;DP=7760;DPB=7760;DPRA=0;EPP=9.52472;EPPR=16838.4;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=60;NS=1;NUMALT=1;ODDS=10694.5;PAIRED=0;PAIREDR=0;PAO=0;PQA=0;PQR=0;PRO=0;QA=111;QR=280123;RO=7757;RPP=9.52472;RPPR=16838.4;RUN=1;SAF=3;SAP=9.52472;SAR=0;SRF=7757;SRP=16847.1;SRR=0;TYPE=snp GT:DP:RO:QR:AO:QA:GL 0/0:7760:7757:280123:3:111:0,-10,-10
chr17 17474586 . C G 197.853 . AB=0;ABP=0;AC=2;AF=1;AN=2;AO=8;CIGAR=1X;DP=8;DPB=8;DPRA=0;EPP=20.3821;EPPR=0;GTI..=0;LEN=1;MEANALT=1;MQM=60;MQMR=0;NS=1;NUMALT=1;ODDS=15.6955;PAIRED=0;PAIREDR=0;PA..O=0;PQA=0;PQR=0;PRO=0;QA=296;QR=0;RO=0;RPP=20.3821;RPPR=0;RUN=1;SAF=0;SAP=20.3821..;SAR=8;SRF=0;SRP=0;SRR=0;TYPE=snp GT:DP:RO:QR:AO:QA:GL 1/1:8:0:0:8:296:-10,-2.40824,0
chr1 58910197 . T G 52.2409 . AB=0;ABP=0;AC=2;AF=1;AN=2;AO=2;CIGAR=1X;DP=2;DPB=2;DPRA=0;EPP=7.35324;EPPR=0;GTI..=0;LEN=1;MEANALT=1;MQM=60;MQMR=0;NS=1;NUMALT=1;ODDS=7.37776;PAIRED=0;PAIREDR=0;PA..O=0;PQA=0;PQR=0;PRO=0;QA=74;QR=0;RO=0;RPP=7.35324;RPPR=0;RUN=1;SAF=2;SAP=7.35324;..SAR=0;SRF=0;SRP=0;SRR=0;TYPE=snp GT:DP:RO:QR:AO:QA:GL 1/1:2:0:0:2:74:-7.03,-0.60206,0
我得到了这个输出
chr4 110541280 G A 0.000386598
chr17 17474586 C G 1
chr1 58910197 T G 1
检查完使用情况后,您也可以取消第二次awk
来电
awk '/^chr/{match($0,/;AO=([^;]*);.*;RO=([^;]*);/,v);
r=v[1]/(v[1]+v[2]);
print $1,$2,$4,$5,r;
print r > "$VCFDIR/allelefreqs.txt"}'
答案 1 :(得分:1)
你可以尝试
awk '
/^chr/ {
nrecords = split($8, records, ";") # "AB=0" "ABP=0" "AC=0" ...
for(i=1; i<=nrecords; i++){
split(records[i], record, "="); # dict["AB"]="0" ...
dict[record[1]] = record[2]; # store each record in column 8
}
frequency_allele = dict["AO"]/(dict["AO"]+dict["RO"]);
print $1,$2,$4,$5,frequency_allele;
}' file
带输入
chr4 110541280 . G A 0 . AB=0;ABP=0;AC=0;AF=0;AN=2;AO=3;CIGAR=1X;DP=7760;DPB=7760;DPRA=0;EPP=9.52472;EPPR=16838.4;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=60;NS=1;NUMALT=1;ODDS=10694.5;PAIRED=0;PAIREDR=0;PAO=0;PQA=0;PQR=0;PRO=0;QA=111;QR=280123;RO=7757;RPP=9.52472;RPPR=16838.4;RUN=1;SAF=3;SAP=9.52472;SAR=0;SRF=7757;SRP=16847.1;SRR=0;TYPE=snp GT:DP:RO:QR:AO:QA:GL 0/0:7760:7757:280123:3:111:0,-10,-10 chr17 17474586 . C G 197.853 . AB=0;ABP=0;AC=2;AF=1;AN=2;AO=8;CIGAR=1X;DP=8;DPB=8;DPRA=0;EPP=20.3821;EPPR=0;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=0;NS=1;NUMALT=1;ODDS=15.6955;PAIRED=0;PAIREDR=0;PAO=0;PQA=0;PQR=0;PRO=0;QA=296;QR=0;RO=0;RPP=20.3821;RPPR=0;RUN=1;SAF=0;SAP=20.3821;SAR=8;SRF=0;SRP=0;SRR=0;TYPE=snp GT:DP:RO:QR:AO:QA:GL 1/1:8:0:0:8:296:-10,-2.40824,0
你得到了
chr4 110541280 G A 0.000386598 chr17 17474586 C G 1
答案 2 :(得分:1)
$ cat tst.awk
BEGIN { FS="[ =;]+" }
/^chr/ {
for (i=1;i<=NF;i++)
a[$i] = $(i+1)
print a["AO"]/(a["AO"]+a["RO"])
}
$ awk -f tst.awk file
0.000386598