I was wondering if anyone could help with my little issue in manipulating tsv files in order to calculate estimated coverage across many tsv files.
I have tsv files that look something like this:
ID Info Info2 x
M80428 info info 1000
T83241 info info 8400
E81292 info info 10200
I also have another tsv file with all possible IDs and a corresponding number like so:
ID y
M80428 27311
E11123 46531
P38163 14213
A34197 12892
T83241 37416
Q21345 27321
E81292 13101
x in the first tsv are estimated read counts and the y in the second is the genome length of each ID.
I would like to divide the "x" by the "y" in the second tsv that has the corresponding ID in order to get the estimated coverage of each hit. e.g. the first row would be 1000/27311, second row 8400/37416. I would then want this to be written to the fifth column of the tsv.
I am working in bash shell mostly here, and think that the way I would probably do this is with awk and by making the second tsv an associative array but I can't work out how exactly to do so. The python package dict seems like another option but my Python skills are practically zero.
Thanks for the help in advance!
echo $eachline| awk '{print $1}'
; div=echo $eachline| awk '{print $2}'
cat .tsv | awk -v div="$div" '{FS ="\t"} {OFS ="\t"} {print $1,$2,$3,$4,$4/div}' > new.tsv; done $\endgroup$