In the below bash
there are 6
.txt files in /home/cmccabe/Desktop/comparison/ref_val/
that are being updated from the 6
.vcf files in /home/cmccabe/Desktop/comparison/validation/files/*.vcf
. The awk
in the post updates the files with the information, however the files are not being updated so the awk
stalls. Each filename will have the portion before the _
that matches between /home/cmccabe/Desktop/comparison/ref_val/*.txt
and /home/cmccabe/Desktop/comparison/validation/files/*.vcf
Example of file in /home/cmccabe/Desktop/comparison/ref_val/*.txt
F13_epilepsy_filtered_comparison.txt
this file is updated from /home/cmccabe/Desktop/comparison/validation/files/*.vcf
F13_epilepsy_filtered.vcf
FN= /home/cmccabe/Desktop/comparison/ref_val/*.txt
matching files used to update FN
/home/cmccabe/Desktop/comparison/validation/files/*.vcf
example of vcf file from (this is the file that update FN
)
/home/cmccabe/Desktop/comparison/validation/files/*.vcf
chr1 43395635 43395635 C T exonic SLC2A1 . synonymous SNV SLC2A1:NM_006516:exon5:c.588G>A:p.P196P rs2229682 0.23 0.12 0.024 0.21 0.08 0.19 0.15 0.18 0.044 0.19 0.074 0.23 0.21 0.19 0.19 0.15 0.049 0.2 0.12 -0.1558 -0.594 . . . . . . . . . . . . Benign not_specified RCV000081436.5 MedGen CN169374 GOOD 399 het 19
example of text file from (this is the file being updated)
/home/cmccabe/Desktop/comparison/ref_val/*.txt
Bash
#!/bin/bash
for FN in /home/cmccabe/Desktop/comparison/ref_val/*.txt; do
awk '
BEGIN {FS = OFS = "\t"
}
NR == 1 {
outfile = FILENAME
}
FNR == NR {
o[i[++ic] = $1 OFS $2 OFS $3] = $0
}
{if($2 OFS $4 OFS $5 in o)
o[$2 OFS $4 OFS $5] = $1 OFS $2 OFS $4 OFS $5 OFS $6 OFS $7 OFS $50 OFS $51 OFS $52 OFS $53
}
END {for(j = 1; j <= ic; j++)
print o[i[j]] > outfile
}' $FN ${FN%%_*}/home/cmccabe/Desktop/comparison/validation/files/*.vcf
done
desired output (this is FN before updating)
Match:
9943666 C T
161281245 T C
138662273 G A
64142859 C T
this is FN after updating
Match:
chr16 9943666 C T exonic GRIN2A GOOD 343 het 18
chr5 161281245 T C exonic GABRA1 GOOD 197 het 13
chr9 138662273 G A exonic KCNT1 GOOD 275 het 15
chr3 64142859 C T exonic PRICKLE2 GOOD 355 het 23
If no match is found in /home/cmccabe/Desktop/comparison/validation/files/*.vcf
to update FN
, then it it skipped and the next line is processed. I hope I have included everything and thank you :).