#!/usr/local/bin/gawk -f # SYNTAX: # # qual-col.awk [ options ] # # Written by: Eiso AB # #@ purpose: color residues according to whatcheck bad/poor scores. #@ creates molmol macros # # Example: # - Submit file.pdb to http://swift.cmbi.kun.nl/WIWWWI/modcheck.html # - Save check.db # - sh> qual-col.awk check.db # - sh> molmol -r 10-85 -f color-BBCCHK.mac file.pdb # # WARNING: qual-col.awk might be unreliable for WHATIF VERSIONS !=6.0 # you should be able to use: # http://swift.cmbi.ru.nl/servers/html/index.html # BEGIN { stderr="/dev/stderr" defaultcolor = "0 1 0 " # green defaultcolor = "0 0.4 0 " # black poorcolor = "1 0 0" # red badcolor = "1 1 0" # yellow? progname="qual-col.awk" #for ( i in ARGV ) if (ARGV[i]=="help") help=1 if ( ARGV[1]~/^([-][h]|[-][-][h](elp)?|help)$/ || help!="" ) { print ARGV[0] # because of the which command, help is only available if # this script is in the PATH system("gawk '/^#/{print}/^BEGIN/{exit}' `which "progname"`") help=1 exit } } #/^ *[0-9]+ +[A-Z]+ +[(] +[0-9]+ +[)] +[A]?( +[0-9]+)? +[0-9]+[.][0-9]+ +[0-9]+[.][0-9]+$/{ # print "bfac res",$4,$2,"model",$(NF-2),85-$NF #} {print model+0,resnum+0,$0 > "qq"} /^[/][/] / { model=0 next } $1=="CheckID" { nbad=0; if (checkid!="" && checkid in badcount) nbad = badcount[checkid] npoor=0; if (checkid!="" && checkid in poorcount) npoor = poorcount[checkid] if (nbad>0||npoor>0) { printf " poor:%i bad: %i",npoor,nbad } #if (valstr!="") print valstr > "xvg.xvg" checkid=$3 ; model=0 ; poorop=badop=resnum=valstr="" printf "\n%s models:",checkid >stderr next } $1=="Program" { program=$0 ; sub(/ *Program +: */,"",program) } $1=="Version" { version=$0; sub(/ *Version +: */,"",version) #print "version","["version"]","==",version+0 if (program=="WHAT IF" && version+0<6) { print "WARNING: qual-col.awk might be unreliable for WHATIF VERSIONS !=6.0" print " this is ["$0"]" print " you should be able to use:" print " http://swift.cmbi.kun.nl/WIWWWI/modcheck.html" } } $1=="Level" { level=$3 ; next } # RESIDUE|ATOM $1=="Type" { type=$3 ; next } # TEXT|FLOAT $1=="Poor" { poor=$4 ; poorop=$3 ; next } $1=="Bad" { bad=$4 ; badop=$3 ; next } $1=="Name" { if (level=="RESIDUE") newresnum=$NF+0 else if (level=="ATOM") newresnum=$(NF-1)+0 rex="Name +[:] ([A-Z ][-][0-9]*)? +([0-9]+[-][A-Z][A-Z]+[-]?[ ]?[0-9A-Z]+)? +[-] +([0-9]+) *$" # 111111111111111 2222222222222222222222222222222222222 333333 #print "match",$0~rex if ( match($0,rex,rrr) ) { chain=rrr[1] #print "new style" if (rrr[3]!=model) { model=rrr[3] nmodels = ( nmodels=""||model>nmodels ? model : nmodels) if (valstr!="") valstr=valstr"\n&" printf " %s",model > stderr } if (level=="RESIDUE") newresnum=rrr[2]+0 else if (level=="ATOM") newresnum=rrr[2]+0 resnum=newresnum thisid=rrr[2] #print model,chain,resnum,resnam,"["thisid"]",$0 } else { if (resnum=="" || newresnumnmodels ? model : nmodels) if (valstr!="") valstr=valstr"\n&" printf " %s",model > stderr } resnum=newresnum if (level=="RESIDUE") { resnam=$0;sub(/^ +Name +: +/,"",resnam) thisid=resnam } else if (level=="ATOM") { atnam=$0;sub(/^ +Name +: +/,"",resnam) thisid=atnam } } } $1=="Value" { if (type=="FLOAT") { id=checkid SUBSEP model SUBSEP thisid nid=split(thisid,iii) if (nid==1) iii2=iii[1] if (nid==2) iii2=iii[2] if (nid==3) iii2=iii[1] thisval=value[id]=$3 valstr=valstr"\n"thisval print thisval,badop,poor"/"bad,iii2,"["thisid"]",nid > "qq" if ((badop=="<" && thisval-bad < 0 ) || (badop==">" && thisval-bad > 0 )) { status[id]="bad" selstr[checkid,model,"bad"]=selstr[checkid,model,"bad"]"," iii2+0 print checkid,"bad",thisid,iii2,iii[2]+0,$0,"("badop bad")">"bad" badcount[checkid]++ } else if ((poorop=="<" && thisval-poor < 0) || (poorop==">" && thisval-poor > 0)) { status[id]="poor" selstr[checkid,model,"poor"]= selstr[checkid,model,"poor"]"," iii2+0 print checkid,"poor",thisid,iii2,iii[2]+0,$0,"("poorop poor")">"poor" poorcount[checkid]++ } else { status[id]="ok" } #if (checkid~/BBCCHK/) print id,value[id],status[id],poorop poor,badop bad } else if (type=="TXT") { } next } END { print "" > stderr print "MODELS",nmodels> stderr for (m=1;m<=nmodels;m++) { for ( s in selstr) { split(s,ii,SUBSEP) outfile="color-"ii[1]".mac" if (!(outfile in printed)) { print "#",m > outfile print "\nSelectAtom ''\nColorAtom "defaultcolor"\nStyleBond half_line" > outfile printed[outfile]++ } if (ii[2]==m) { printed[outfile]++ ss=selstr[s]; sub(/^,/,"",ss) ; ss="#"ii[2]":"ss print "\n# model",ii[2],ii[3] > outfile print "SelectAtom '" ss "'" > outfile if (ii[3]=="bad") print "ColorAtom "badcolor > outfile else if (ii[3]=="poor") print "ColorAtom "poorcolor > outfile #for (i=1;i<=nmodels;i++) { # #} } } } # for (outfile in printed) { # print # } exit for ( id in value ) { split(id,ii,SUBSEP) print ii[1],ii[2],ii[3],value[id],(id in status ? status[id] : "ok" ) split(ii[3],iii) model=ii[2]+0 resnum=iii[2]+0 if (out="molmol") { outfile="color-"ii[1]".mac" printf "SelectBond '#%i:%i'\n",ii[2],iii[2] > outfile if (status[id]=="poor") print "ColorAtom "poorcolor > outfile else if (status[id]=="bad") print "ColorAtom "badcolor > outfile #else if (status[id]=="ok") print "ColorAtom "defaultcolor > outfile } } }