Stupid awk tricks

From Rizzo_Lab
Revision as of 17:17, 5 January 2010 by Sudipto (talk | contribs)
Jump to: navigation, search

Grep out the wallclock time from the namd out files, convert to hours and adds them together.

grep "WallClock:" *.out | awk '{sum+=$2/3600} END {print "Hours="sum}'

Same thing, but now also does mean and sd

awk '{sum+=$2/3600; n+=1; sumsq+=($2/3600)^2} END {print "SD="sqrt(sum^2-sumsq)/(n+1),"Mean="sum/n}'


awk -F, '{mean+=$94/5000; n+=1; meansq+=(($94^2)/5000)} END {print "SD="sqrt(meansq - mean^2),"Mean="mean}'

Theoretical success rate i.e. at least one pose in mol2 file with RMSD<=2

awk '/RMSD:/{if($3<=2.0)ths=1}END{print ths}' scored.mol2 

Return lowest EMSD in mol2 file

awk 'BEGIN{lrm=99}/RMSD:/{if($3<=lrm)lrm=$3}END{printf"%.2f",lrm}' mol2file

Lowest DOCK RMSD in MOL2 output

grep RMSD mol_scored.mol2 | awk '{print $3}' | sort -n | head 

Using a shell variable

Here we use the shell variable rmsdcut to set a different RMSD cutoff for success rate when calculating the theoretical success rate in the multi-mol2 file of docked poses. This prints 1 if any of the poses in the mol2 file have an RMSD <= $rmsdcut.

awk 'BEGIN{ths=0}/RMSD:/{if($3<='$rmsdcut')ths=1}END{print ths}' $mol2file

Formal charge of a LIG mol2 file

This will only work on lines where the residue name is LIG

awk '/  LIG  /{sum+=$9}END{print sum}' lig.mol2  

Average # of rotatable bonds from dock.out

awk 'BEGIN{tot=0;sum=0}/Number of rotatable bonds/{sum+=$6;tot+=1}END{print tot,sum/tot}' rot.out

Average size of a whole bunch of files

du ????/003_grid/$spacing/????.rec.nrg | awk '{sum+=$1;n+=1}END{print sum/n,n}'


awk Tutorial