# check_offset Usage: check_offset filenames # If you download this from my web page, it is important to # use the SOURCE FILE. DON'T mouse it off the screen # because many of the characters will not be visible. # Note to myself: remember to maintain the link # ln check_offset /usr/njas/wwwfiles/sequences/check_offset.txt # Call this file check_offset (not check_offset.txt) if [ "$#" -eq 0 ] then echo "Incorrect no of arguments. Usage: check_offset file(s) " echo "Checks offsets in named files" echo "Error message indicating empty offset may be caused by blank line in sequence." echo "Results will be in report_offset." exit 1 fi # choose version of awk to use AWK=/bin/gawk echo "Checking offsets in $*. Results will be in report_offset." cat $* | $AWK ' BEGIN { RS = ""; FS = "\n" type[ 2]="%A" #type[ 3]="%B" #type[ 4]="%C" type[ 5]="%F" type[ 6]="%I" type[ 7]="%K" type[ 8]="%N" type[ 9]="%O" type[10]="%r" type[11]="%R" type[12]="%S" type[13]="%T" type[14]="%U" type[15]="%W" type[16]="%Y" type[17]="%Z" # clear numbers of all possible types for (i in type) have[type[i]]=0; # END OF BEGIN } # START PROCESSING NEXT SEQUENCE: { # left 0 seq = "" seq2 = "" seq3 = "" name = "" ref = "" offset = "" cross = "" memo = "" formula = "" callfor = "" for (i = 1; i <= NF; i++) { # left 1 if ($i ~ /^%I/) id = substr( $i, 4, 10 ) if ($i ~ /^%S/) { seq = $i ; sub( /.........../, "", seq ) } if ($i ~ /^%T/) { seq2 = $i ; sub( /.........../, "", seq2 ); seq = seq seq2 } if ($i ~ /^%U/) { seq3 = $i ; sub( /.........../, "", seq3 ); seq = seq seq3 } if ($i ~ /^%N/) { name = $i ; sub( /.........../, "", name ) } if ($i ~ /^%R/) ref = $i if ($i ~ /^%O/) { offset = $i ; sub( /.........../, "", offset ) } if ($i ~ /^%Y/) { cross = $i ; sub( /.........../, "", cross ) } if ($i ~ /^%Z/) { memo = $i ; sub( /.........../, "", memo ) } if ($i ~ /^%F/) { formula = $i ; sub( /.........../, "", formula ) } for (j in type ) { if ($i ~ type[j]) ++have[type[j]] }; }; # right 1 # ACTION TO BE TAKEN ON SEQUENCE { # print "Seq" # print seq # print offset if ( offset !~ /,/ ) { print "Error, no comma in offset in", id, ". %O is", offset } else { # left A split( offset, oo, "," ); o = oo["2"]; # print "good %O", o # now check that claimed offset, o, is correct! # i will be true offset (k = 0 indicates all terms <= 1) k = 0 nnn = split( seq, sequence, "," ) for ( i = 1; i <= nnn; i++) if ( sequence[i] > 1 ) { k = 1; break} if ( k == 0 ) i = 1 if ( i != o ) { print "Error in offset at", id, ". True, claimed = ", i, o } } # right A # print " " } } # right 0 ' >report_offset