I'd like to calculate using value in second column. The value needs to be created using a formula, that employs exp (that is e raise to the power).
awk '{
if(FNR==1){
##if first line than print as is and add third column
print $0,"weight"
}
else{
if($2<=0.01){
##if MAF less than 0.01
print $0, exp((1-$2)*25)/(1+exp((1-$2)*25))
}
else{
print $0, exp((0.5-$2)*0.5)/(1+exp((0.5-$2)*0.5))
} } }' merged_allCHRs_headers > merged_allCHRs_weights
I get the same results as you do applying your script to your sample data. But, not knowing WHAT formula to apply under which conditions, I can't tell "what (you're) ... doing is right." And, I'm afraid, nobody without a profound background in genetics can.
Aside, your code might benefit (improved readability and understandability, ease of maintenance) from some structuring and, mayhap, simplification. Like e.g.
Assuming your formula is correct, checked longhand in Python 3.8.0 using the math library:
Last login: Fri Nov 15 17:16:16 on ttys000
AMIGA:amiga~> python3.8
Python 3.8.0rc1 (v3.8.0rc1:34214de6ab, Oct 1 2019, 12:56:49)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>>
>>> math.exp((0.5-0.013)*0.5)/(1.0+math.exp((0.5-0.013)*0.5))
0.5605759881403045
>>> math.exp((0.5-0.01125)*0.5)/(1.0+math.exp((0.5-0.01125)*0.5))
0.5607915159336736
>>> math.exp((0.5-0.3581)*0.5)/(1.0+math.exp((0.5-0.3581)*0.5))
0.5177300630065548
>>> math.exp((1.0-0.005268)*25)/(1.0+math.exp((1.0-0.005268)*25))
0.9999999999841571
>>> _
So your rounded values seem OK.
Again this assumes that your formula is correct.