Back again! Finally the script seems to be working without a glitch and my coworkers seems pleased!
Thank you all for the help with this one! But, as always with efficiency, I want to be more efficient. I am also more lazy than the average person . So my question is this, in the modified version of this script below, where manual input for each analysis has been removed, is there a way to get AWK to spit out one "out1" and one "out2" file for each input if I run the script as:
./script.awk hb_results*
Using a wildcard to input all files at once? As it is now, I get one out1 and out2 named after the first file specified with the * AWK finds, though these two outputs contain the results from all the input files. I would like one out1 and one out2 for each file found with hb_results* (up to 30 or 40 files), named after each specific input found as specified in the script!
Is this possible?
Best regards
Gustaf
BEGIN{inp_num=10}
NR==1{out1="hb_%_occ_"FILENAME;out2="summary_"FILENAME;next}
NR==2{nr=(NF>8?12:8)}
NR<=nr{next}
{
gsub (/\(+|\)+|\:/," ")
}
{
if(NF>=15){
tott+=$15;++denom;tothb+=$10
printf "%10.2f %10.1f\n",$10,$15>out1
}
else if(NF>=11){
tothb+=$10;++denom
printf "%10.2f\n",$10>out1
}
}
END{
if(denom==0){
x="NO DATA POINTS IN INPUT => NO HYDROGEN BONDS DETECTED!"
print x>out1;print x>out2;exit
}
close(out1);
if(tott>0){
avglt=tott/denom
while((getline<out1)>0)tottsq+=(($2-avglt)^2)
avocc=tothb/inp_num
printf " Summary data for hbond analysis\n\n">out2
printf " Sum of Occupancy: %10.3f\n",tothb>out2
printf " Average Occupancy: %10.3f\n\n",avocc>out2
printf " Sum of lifetimes: %10.3f\n",tott>out2
printf " Average lifetime: %10.3f\n",avglt>out2
if(denom>1){
sd_lt=sqrt(tottsq/(denom-1));semlt=(tottsq/(denom-1))/(sqrt(denom))
printf " SD lifetime: %10.3f\n",sd_lt>out2
printf " SEM lifetime: %10.3f\n",semlt>out2
} else print " Single HBOND event, no SD or SEM calculation possible!">out2
}
if (tott==0){
avocc=tothb/inp_num
printf " Summary data for hbond analysis\n\n">out2
printf " Sum of Occupancy: %10.3f\n",tothb>out2
printf " Average Occupancy: %10.3f\n\n",avocc>out2
if(denom<1){ print " Single HBOND event, no SD or SEM calculation possible!">out2 }
}
}
Thank you all for the help with this one! But, as always with efficiency, I want to be more efficient. I am also more lazy than the average person . So my question is this, in the modified version of this script below, where manual input for each analysis has been removed, is there a way to get AWK to spit out one "out1" and one "out2" file for each input if I run the script as:
./script.awk hb_results*
Using a wildcard to input all files at once? As it is now, I get one out1 and out2 named after the first file specified with the * AWK finds, though these two outputs contain the results from all the input files. I would like one out1 and one out2 for each file found with hb_results* (up to 30 or 40 files), named after each specific input found as specified in the script!
Is this possible?
Best regards
Gustaf
BEGIN{inp_num=10}
NR==1{out1="hb_%_occ_"FILENAME;out2="summary_"FILENAME;next}
NR==2{nr=(NF>8?12:8)}
NR<=nr{next}
{
gsub (/\(+|\)+|\:/," ")
}
{
if(NF>=15){
tott+=$15;++denom;tothb+=$10
printf "%10.2f %10.1f\n",$10,$15>out1
}
else if(NF>=11){
tothb+=$10;++denom
printf "%10.2f\n",$10>out1
}
}
END{
if(denom==0){
x="NO DATA POINTS IN INPUT => NO HYDROGEN BONDS DETECTED!"
print x>out1;print x>out2;exit
}
close(out1);
if(tott>0){
avglt=tott/denom
while((getline<out1)>0)tottsq+=(($2-avglt)^2)
avocc=tothb/inp_num
printf " Summary data for hbond analysis\n\n">out2
printf " Sum of Occupancy: %10.3f\n",tothb>out2
printf " Average Occupancy: %10.3f\n\n",avocc>out2
printf " Sum of lifetimes: %10.3f\n",tott>out2
printf " Average lifetime: %10.3f\n",avglt>out2
if(denom>1){
sd_lt=sqrt(tottsq/(denom-1));semlt=(tottsq/(denom-1))/(sqrt(denom))
printf " SD lifetime: %10.3f\n",sd_lt>out2
printf " SEM lifetime: %10.3f\n",semlt>out2
} else print " Single HBOND event, no SD or SEM calculation possible!">out2
}
if (tott==0){
avocc=tothb/inp_num
printf " Summary data for hbond analysis\n\n">out2
printf " Sum of Occupancy: %10.3f\n",tothb>out2
printf " Average Occupancy: %10.3f\n\n",avocc>out2
if(denom<1){ print " Single HBOND event, no SD or SEM calculation possible!">out2 }
}
}