#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) set v = 'version = 2.14 of mkpetals 2007 Feb 26' # 2007 Feb 26, 2.14: protect against div by zero for no sites. # 2006 Jun 07, 2.13: allow edges instead of fill # 2005 Dec 29, 2.12: date correction # 2005 Dec 22, 2.11: default is to have no edge around the petal, el = -1 # 2005 Feb 7, 2.10: blue petals to make all bases visible: basecolor # 2004 Sep 27, 2.09: gs conversion imbedded into code # 2004 Sep 27, 2.08: tell rgb values of the petals (functional) # 2004 Sep 27, 2.07: refuse to add petal features if they are in features. # 2004 Aug 12, 2.06: put blank line in start of features # 2004 Aug 12, 2.05: give name of this routine in output # 2004 Jul 28, 2.04: give -help if no features # 2004 Jul 22, 2.03: thickness control becomes spare variable # 2004 Jul 21, 2.02: fix thickness control # 2004 Jul 21, 2.01: implement new arguments # 2004 Jul 21, 2.00: absorb mkcrf # 2004 Jul 19, 1.00: origin of mkpetals # 2004 Jul 16, 1.09: documentation; below here is mkcrf history # 2004 Jul 16, 1.08: scale can be non-integer # 2004 Jul 15, 1.07: make sure 'ribl' is on the start of a feature line # 2004 Jul 14, 1.06: -scale flag # 2004 Jul 14, 1.05: allow Ri scale control # 2004 Jul 14, 1.04: saturation is a function of Rs/consensus # 2004 Jul 14, 1.03: improve output # 2004 Jul 14, 1.02: the program generates a colorrectanglefeatures # file if one does not exist. # 2004 Jul 14, 1.01: documentation # 2004 Jul 14, 1.00: origin # make sequence walker colored rectangles: petals echo "${v}" # setting debugging to true causes mkpetals to write a postscript # program to /tmp. The program, $pstest, displays the # rgb colors and the hsb colors as pairs of squares next to # each other (horizontally). Their colors will match if the # conversion was correct. set debugging = true set debugging = false set intro1 = 'usage: mkpetals [-help] [-f file] [-scale value] [-basecolor value] [-edge width]' set intro2 = 'Make Color Rectangle Features on lister maps: petals' # defaults: set target = features set scale = 1 set basecolor = 000 # default is no edge: set edgewidth = -1 set argcount = 1 while ($argcount <= $#argv) switch ("$argv[$argcount]") # **************************************************************************** # if (('$#argv' == 1) && ("$1" == '-help')) then case '-help' echo "$intro1" echo "$intro2" echo echo 'Summary: make colored rectangles (petals) behind sequence' echo 'walkers.' echo echo This script is to be used in conjunction with the echo lister program, part of the Delila system. echo echo Given a feature file in the current directory, echo the script will locate all ribl matrices. echo It then assigns to each matrix a unique pastel hue echo and adds these assignments to the end of the feature list. echo The saturation of the color will vary by the infromation echo content of the binding site. echo echo Use is very simple: build your features echo file as normal. Then call mkpetals followed by lister: echo ' (build features file)' echo ' mkpetals' echo ' lister' echo "That's all\!" # echo The most useful and simple form is to call the script as: # echo " mkpetals" echo "This will attach the results to the features file" echo "with a scale of 1." echo echo Without the -f flag, the petal features echo will be appended to the end of the features file. echo With the -f flag, the petal features echo will be appended to the file you specify. echo echo With the -scale flag, the color saturation will be scaled echo by the given value. echo echo With the -basecolor flag, the hue starts with the value given. echo The hue must be multiplied by 1000. For example, to start with echo a hue of 0.6, use 600. echo echo With the -edge flag, the edge is determined instead of a fill. echo "Give the width of the edge in points (1/72 inch - sorry," echo "that's how PostScript works)." # echo # echo With the -a flag any petalfeatures file in the # echo current directory will be ignored. # echo Copies of the information used are placed in /tmp. # echo If you want to use your own petalfeatures file, # echo do not use the -a and -scale flags. echo echo "The form" echo " mkpetals -f petals -scale 2" echo "will append the results to the petals file with a scale 2." echo echo For further information see: echo http://www.lecb.ncifcrf.gov/~toms/delila/lister.html echo echo 'Dr. Thomas D. Schneider' echo 'National Cancer Institute' echo 'Laboratory of Experimental and Computational Biology' echo 'Frederick, Maryland 21702-1201' echo 'toms@ncifcrf.gov' echo 'permanent email: toms@alum.mit.edu (use only if first address fails)' echo 'http://www.lecb.ncifcrf.gov/~toms/' exit breaksw # **************************************************************************** case '-file' @ argcount ++ set target = "$argv[$argcount]" echo setting target file to "$target" breaksw case '-scale' @ argcount ++ set scale = "$argv[$argcount]" echo setting color scale to "$scale" set scalenodecimal = `echo "$scale" | sed -e 's/\.//'` # echo "scalenodecimal is '"$scalenodecimal"'" if ($scalenodecimal <= 0) then echo ERROR: the scale value cannot be negative. exit endif breaksw case '-basecolor' @ argcount ++ set basecolor = "$argv[$argcount]" echo setting base color to "$basecolor" if ("$basecolor" <= 0) then echo 'ERROR: the basecolor value cannot be negative.' exit endif if ("$basecolor" > 1000) then echo 'ERROR: the basecolor value cannot be > 1000' exit endif @ basecolor = $basecolor breaksw case '-edge' @ argcount ++ set edgewidth = "$argv[$argcount]" echo setting edge width to "$edgewidth" if ("$edgewidth" <= 0) then echo 'ERROR: the edgewidth value cannot be negative.' exit endif if ("$edgewidth" > 1000) then echo 'ERROR: the edgewidth value cannot be > 1000' exit endif @ edgewidth = $edgewidth breaksw default: echo "$intro1" echo "$intro2" echo 'for more help type:' echo ' mkpetals -help' breaksw endsw @ argcount++ end # **************************************************************************** # Determine if GhostScript is available. If it is, we can use it to # compute the rgb color from the hsb color. set gs = `which gs` set notfoundGS = `echo "$gs" | grep not` if ("$notfoundGS" != "") then echo 'Ghostscript (gs) was not found.' echo "If you make it available it will be" echo "used to convert from HSB to RGB." set convertHSBtoRGB = false else echo "Ghostscript (gs) is at $gs." echo "It is being used to convert from HSB to RGB." set convertHSBtoRGB = true # set hsb = "0.6 1 1" # echo $hsb # The PostScript program to convert from hsb to rgb: set GSprg = "sethsbcolor currentrgbcolor exch 3 -1 roll pstack quit" # sethsbcolor read in 3 numbers as hsb # currentrgbcolor convert to rgb and put on the stack # # At this point we have a reversed color, bgr. # exch now we have gbr # 3 -1 roll now we have rgb # pstack show the stack # quit we are done # The commandt to control GhostScript: set GScommands = '-dNODISPLAY -q - -sOutputFile=|' # -dNODISPLAY # Suppresses the normal initialization of the output device. # # -q Quiet startup: suppress normal startup messages, and # also do the equivalent of -dQUIET. # # - This is not really a switch, but indicates to # Ghostscript that standard input is coming from a file # or a pipe and not interactively from the command line. # # -sOutputFile=| send output to standard output for piping # echo multiline ----- # printf "%10s $prg \n" "$hsb" |\ # $gs \ # -dNODISPLAY \ # -q \ # - \ # -sOutputFile=- # echo oneline ----- # printf "%10s $prg \n" "$hsb" | $gs -dNODISPLAY -q - -sOutputFile=- # echo -----===== done oneline # zzz for testing # set GScommands = '-dNODISPLAY -q - -sOutputFile=|' # set rgb = `printf "%10s $prg \n" "$hsb" | $gs $GScommands | cat` # echo hsb is "$hsb" # echo rgb is "$rgb" set pstest = "/tmp/`whoami`-mkpetal.ps" if ($debugging == true) then cat > $pstest << EOF %! $pstest /square{ 0 0 moveto 10 0 lineto 10 10 lineto 0 10 lineto 0 0 lineto closepath fill } def /shift { 0 20 translate } def /dohsb { shift 0 0 moveto sethsbcolor square } def /dorgb { setrgbcolor % shift gsave 12 0 translate square grestore } def EOF endif endif # **************************************************************************** if !(-f features) then echo There is no features file is in this directory. echo "I'll run 'mkpetals -help' for you:" echo mkpetals -help exit endif # check that mkpetals was not run before set previous = "`grep mkpetals features`" echo $previous if ("$previous" != "") then echo '********************************************************' echo '* ERROR: mkpetals was run on this feature file before! *' echo '* Program halted to avoid duplicate petal features. *' echo '********************************************************' # beep at the user echo '' exit endif echo Ri scale factor: $scale echo target file is: $target set t1 = /tmp/`whoami`.`tomdate`.1.petals set t2 = /tmp/`whoami`.`tomdate`.2.petals set t3 = /tmp/`whoami`.`tomdate`.3.petals set t4 = /tmp/`whoami`.petals cp features $t1 # grep "ribl" $t1 grep "^ribl" "$t1" |\ grep -v "^*" |\ sed -e 's/ribl/petal/' |\ cat > $t2 # echo BUBBA ------------------ BUBBA ------------------ # cat $t2 # echo set p1 = ' 1 h 1.0 0.0 1.0 ' # saturation a function of Ri/consensus: set p2 = " -${scale} 1.0" set n = `cat $t2 | wc -l` echo $n Ribl types if ($n <= 0) then echo "No petals made because there are no sites." exit endif # multiply by 100 to get some resolution @ n100 = 100 * $n set maxjump = 100000 @ jump = $maxjump / $n100 # echo $n100 # echo jump is $jump echo -n "" > $t3 echo "" >> $t3 echo '* petalfeatures: color rectangle features for the lister program'>>$t3 echo "* ${v}" >> $t3 echo '* format:' >> $t3 cat >> $t3 << EOF * el: integer; (* edgelinewidth: edge linewidth (integer) *) * c : char; (* color kind: how color is defined: r for RGB, h for HSB *) * (* ---------------------------------------------- *) * eh: real; (* edgeh: edge hue OR red *) * es: real; (* edges: edge saturation OR blue *) * eb: real; (* edgeb: edge brightness OR green *) * (* ---------------------------------------------- *) * fh: real; (* fillh: fill hue OR red *) * fs: real; (* fills: fill saturation OR blue *) * fb: real; (* fillb: fill brightness OR green *) * (* ---------------------------------------------- *) * spare: real; (* spare *) EOF #echo '* "ribl_name" el c eh es eb fh fs fb spare'>>$t3 # printf "%s %4s %1s %4s %4s %4s %4s %2s %4s %4s \n" \ set sizestring = "%10s %3s %3s %8s %4s %4s %8s %4s %4s %8s \n" printf "$sizestring" \ '* "name"'\ "el"\ "c"\ "eh"\ "es"\ "eb"\ "fh"\ "fs"\ "fb"\ "spare"\ >>$t3 # 2005 Dec 22: no edge is now the default # set el negative to make the edge disappear: # set el = 1 # set el = 30 # functional: # set el = -1 set el = $edgewidth # fs or es may be redetermined below set c = h set eh = 1.0 set es = 0.0 set eb = 1.0 set fh = 1.0 set fs = 1.0 set fb = 1.0 set th = 0.0 # starting basecolor: set decimals = $basecolor foreach name ("`cat $t2`") # echo $name # echo "${name}"${p1}0.${decimals}$p2 >> $t3 if ($el <= 0) then set fh = "0.${decimals}" set fs = "-${scale}" else set eh = "0.${decimals}" set es = "-${scale}" # eliminate the fill color: set fs = 0 endif # note that $c == 'h' if ($convertHSBtoRGB == true) then # zzz for testing echo "*" >> $t3 echo "* Determine rgb for full saturation:" >> $t3 set hsb = "${fh} 1 ${fb}" set rgb = `printf "%10s $GSprg \n" "$hsb" | $gs $GScommands | cat` echo "* hsb is $hsb" >> $t3 echo "* rgb is $rgb" >> $t3 if ($debugging == true) then echo "" >> $pstest echo "$hsb dohsb" >> $pstest echo "$rgb dorgb" >> $pstest endif endif # printf "%s %4s %1s %4s %4s %4s %4s %2s %4s %4s \n" \ printf "$sizestring" \ "${name}" \ "${el}" \ "${c}" \ "${eh}" \ "${es}" \ "${eb}" \ "${fh}" \ "${fs}" \ "${fb}" \ "${th}" \ >> $t3 #" ${el}" \ #" ${c}" \ #"0.${decimals}" \ # echo -=----------------------------- # printf "%s %3s \n" \ # "${name}" \ # "${el}" \ # cat # echo -=----------------------------- # exit # > $t3 # exit @ decimals = $decimals + $jump if ($decimals > 1000) then @ decimals = 0 endif end cp $t3 $t4 if ($debugging == true) then # echo "quit" | gs $pstest cat $pstest ghostview -bg white $pstest & endif echo RESULTS: echo cat $t3 echo echo "THESE RESULTS ARE IN TWO /tmp FILES:" echo "$t3" echo "$t4" if (-f $target) then echo "A COPY IS APPENDED TO FILE $target" cat $t3 >> $target else echo "THE $target FILE HAS NOT BEEN DISTURBED" endif # if ($#argv > 0) then # if ("$1" == "-a") then # cat $t3 >> features # echo "mkpetals: THE $t3" # echo " FILE HAS BEEN ATTACHED TO THE END OF THE features" # endif # endif exit # example file. The one below was made by hand. * petalfeatures: color rectangle features for the lister program * 2004 July 21 * format: * petal "ribl_name" el c eh es eb fh fs fb spare petal "crp" 1 h 1.0 0.0 0.0 0.8 0.1 1.0 1.00 petal "Fis" 1 h 1.0 0.0 0.0 0.3 0.1 1.0 1.00 petal "p35" 1 h 1.0 0.0 1.0 0.5 0.1 1.0 1.00 petal "p10" 1 h 1.0 0.0 1.0 0.5 0.1 1.0 1.00 petal "sd" 1 h 1.0 0.0 1.0 0.2 0.1 1.0 1.00 petal "ir" 1 h 1.0 0.0 1.0 0.2 0.1 1.0 1.00