我尝试将此计算从第41列到行尾:
awk '{ { split($10,a,":") } { split( a[4], b ,",") } {print b[1]+b[2]}}' filename
我知道如何只在一列上执行此操作,但是当我尝试执行循环时,它会失败:
awk '{for (i=10;i<=NF;i++) {split($i,a,":")} {split(a[4],b,",")} {print ( b[1]+b[2])}}' filename
目的是分割每一列并对这些数字求和:
./:0:,,。。的 0,0 :0,0
以下是我的文件:
Contig POS ID REF ALT QUAL FILTER INFO FORMAT S155 S158 S168 S173 S175 S178 S180 S188 S189 S191 S193 S194 S196 S201 S205 S206 S208 S209 S210
NODE_14985_length_2800_cov_1.38384 67 999978 A C . PASS Ty=SNP;Rk=1;UL=19;UR=31;CL=.;CR=.;Genome=A;Sd=1 GT:DP:PL:AD:HQ ./.:8:.,.,.:8,0:71,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0 ./.:0:.,.,.:0,0:0,0
这是我的实际输出:
awk '{for (i=10;i<=NF;i++) {split($i,a,":")} {split(a[4],b,",")} {print b[1]+b[2]}}' file.vcf | head
0
0
0
0
0
我想为每列提供一个计算矩阵:
0 0 0 0
1 2 0 6
2 0 0 8
...
提前感谢您的帮助
答案 0 :(得分:0)
修改后的代码:
awk 'NR > 1 {
for( i=41; i<=NF; i++) {
split( $i, a, ":" )
#print NF ":" i "[" $i "] a[4]:" a[4]
split( a[4], b, ",")
#print i ": " b[1] " + " b[2] " : " b[1] + b[2]
printf( "%d ", b[1] + b[2])
}
print ""
}' YourFile