bash - Awk does not recognize fields as integer values -
i'm trying filter 1 file based on 2 columns of one. problem awk
not differentiating, example, interval 70083 83083, position 7323573 (please see below). aim retrieve value file 1 in column 5 of file 2. file 1 has 1 position in column 3 ex: 51476, , file 2 has interval represented column 3 , 4. in end need file 1 respective values of column 5 (see output).
file 1
rs187298206 chr1 51476 0.0072 0.201426626822702 rs116400033 chr1 51479 0.2055 1.18445621536109 rs62637813 chr1 52058 0.0587 0.551216300225955 rs190291950 chr1 52144 -4e-04 0.036575951491895 rs150021059 chr1 52238 0.3325 1.70427928591544 rs140052487 chr1 54353 0.003 0.12778378962414 rs146477069 chr1 54421 0.1419 0.924336309646664 rs141149254 chr1 54490 0.1767 1.06786868821145 rs2462492 chr1 54676 0.0819 0.664355314594874 rs143174675 chr1 54753 0.026 0.356836206987615 rs3091274 chr1 55164 0.3548 1.80091078751368 rs10399749 chr1 55299 0.0309 0.389748348495465 rs182462964 chr1 55313 2e-04 0.0877969207975495 rs3107975 chr1 55326 0.0237 0.344080010917931 rs142800240 chr1 7323573 -6e-04 0.0361473609720785
file 2
51083_1 chr1 51083 56000 -0.177152387075888 0.172569306719619 57083_1 chr1 57083 60083 -0.0524335467819781 0.130497858911419 60083_1 chr1 70083 83083 -0.0332555672564894 0.124932838766226 525083_1 chr1 525083 528083 0.291406335374442 0.0577249392691202 528083_1 chr1 528083 531083 0.291406335374442 0.0577249392691202 531083_1 chr1 531083 534083 0.291406335374442 0.0577249392691202 534083_1 chr1 534083 537083 0.291406335374442 0.0577249392691202 534083_1 chr1 534083 537083 0.441406335374442 0.0577249392691202
what script:
awk ' nr == fnr {score[$3] = $1 fs $2 fs $3 fs $4; next} { (key in score) if (key > $3 && key < $4) print score[key], $5 } ' file1 file2 > output
output
rs140052487 chr1 54353 0.003 -0.177152387075888 rs150021059 chr1 52238 0.3325 -0.177152387075888 rs3107975 chr1 55326 0.0237 -0.177152387075888 rs3091274 chr1 55164 0.3548 -0.177152387075888 rs187298206 chr1 51476 0.0072 -0.177152387075888 rs116400033 chr1 51479 0.2055 -0.177152387075888 rs10399749 chr1 55299 0.0309 -0.177152387075888 rs146477069 chr1 54421 0.1419 -0.177152387075888 rs190291950 chr1 52144 -4e-04 -0.177152387075888 rs182462964 chr1 55313 2e-04 -0.177152387075888 rs141149254 chr1 54490 0.1767 -0.177152387075888 rs62637813 chr1 52058 0.0587 -0.177152387075888 rs143174675 chr1 54753 0.026 -0.177152387075888 rs2462492 chr1 54676 0.0819 -0.177152387075888 rs142800240 chr1 7323573 -6e-04 -0.0332555672564894 <- should not appear
awk ' nr == fnr {score[$3] = $1 fs $2 fs $3 fs $4; next} { (key in score) if (key+0 > $3 && key+0 < $4) print score[key], $5 } ' fst.txt tajima.txt > output
gives me
[/tmp]$ cat output rs182462964 chr1 55313 2e-04 -0.177152387075888 rs190291950 chr1 52144 -4e-04 -0.177152387075888 rs62637813 chr1 52058 0.0587 -0.177152387075888 rs146477069 chr1 54421 0.1419 -0.177152387075888 rs140052487 chr1 54353 0.003 -0.177152387075888 rs3107975 chr1 55326 0.0237 -0.177152387075888 rs187298206 chr1 51476 0.0072 -0.177152387075888 rs141149254 chr1 54490 0.1767 -0.177152387075888 rs10399749 chr1 55299 0.0309 -0.177152387075888 rs3091274 chr1 55164 0.3548 -0.177152387075888 rs143174675 chr1 54753 0.026 -0.177152387075888 rs2462492 chr1 54676 0.0819 -0.177152387075888 rs150021059 chr1 52238 0.3325 -0.177152387075888 rs116400033 chr1 51479 0.2055 -0.177152387075888
to force interpretation number, add 0 it. man page awk.
Comments
Post a Comment