comparison weblogolib/template.eps @ 4:4d47ab2b7bcc

Uploaded
author davidmurphy
date Fri, 13 Jan 2012 07:18:19 -0500
parents c55bdc2fb9fa
children 5149eb3a89c2
comparison
equal deleted inserted replaced
3:09d2dac9ef73 4:4d47ab2b7bcc
1 %!PS-Adobe-3.0 EPSF-3.0
2 %%Title: Sequence Logo: ${logo_title}
3 %%Creator: ${creator_text}
4 %%CreationDate: ${creation_date}
5 %%BoundingBox: 0 0 ${logo_width} ${logo_height}
6 %%Pages: 0
7 %%DocumentFonts:
8 %%EndComments
9
10
11 % ---- VARIABLES ----
12
13 /True true def
14 /False false def
15
16 /debug ${debug} def
17
18 /logo_height ${logo_height} def
19 /logo_width ${logo_width} def
20 /logo_title (${logo_title}) def
21 /show_title ${show_title} def
22
23 /logo_margin ${logo_margin} def
24 /xaxis_label_height ${xaxis_label_height} def
25 /title_height ${title_height} def
26 /stroke_width ${stroke_width} def
27 /tic_length ${tic_length} def
28
29 /lines_per_logo ${lines_per_logo} def
30 /line_width ${line_width} def
31 /line_height ${line_height} def
32 /line_margin_left ${line_margin_left} def
33 /line_margin_right ${line_margin_right} def
34 /line_margin_bottom ${line_margin_bottom} def
35 /line_margin_top ${line_margin_top} def
36
37 /stack_width ${stack_width} def
38 /stack_height ${stack_height} def
39 /stacks_per_line ${stacks_per_line} def
40 /stack_margin ${stack_margin} def
41
42 /show_yaxis ${show_yaxis} def
43 /show_yaxis_label ${show_yaxis_label} def
44 /yaxis_label (${yaxis_label}) def
45 /yaxis_scale ${yaxis_scale} def % height in units
46 /yaxis_tic_interval ${yaxis_tic_interval} def % in units
47 /yaxis_minor_tic_interval ${yaxis_minor_tic_interval} def % in units
48
49 /show_xaxis_label ${show_xaxis_label} def % True or False
50 /show_xaxis ${show_xaxis} def % True or False
51 /xaxis_label (${xaxis_label}) def
52 /xaxis_tic_interval ${xaxis_tic_interval} def
53 /rotate_numbers ${rotate_numbers} def % True or False
54 /number_interval ${number_interval} def
55 /show_ends ${show_ends} def
56 /end_type (${end_type}) def % d: DNA, p: PROTEIN, -: none
57
58 /show_fineprint ${show_fineprint} def
59 /fineprint (${fineprint}) def
60 /logo_label (${logo_label}) def
61
62 /show_boxes ${show_boxes} def % True or False
63 /shrink ${shrink} def % True or False
64 /shrink_fraction ${shrink_fraction} def
65
66 /show_errorbars ${show_errorbars} def % True or False
67 /errorbar_fraction ${errorbar_fraction} def
68 /errorbar_width_fraction ${errorbar_width_fraction} def
69 /errorbar_gray ${errorbar_gray} def
70
71 /fontsize ${fontsize} def
72 /small_fontsize ${small_fontsize} def
73 /title_fontsize ${title_fontsize} def
74 /number_fontsize ${number_fontsize} def
75
76
77 /UseCIEColor true def % Fix for issue 4
78 /default_color ${default_color} def
79 /color_dict <<
80 ${color_dict}
81 >> def
82
83
84
85 % ---- DERIVED PARAMETERS ----
86
87 /char_width stack_width 2 stack_margin mul sub def
88 /char_width2 char_width 2 div def
89 /char_width4 char_width 4 div def
90
91 % movements to place 5'/N and 3'/C symbols
92 /leftEndDeltaX fontsize neg def
93 /leftEndDeltaY fontsize 1.25 mul neg def
94 /rightEndDeltaX fontsize 0.25 mul def
95 /rightEndDeltaY leftEndDeltaY def
96
97
98 % ---- PROCEDURES ----
99
100
101 /SetTitleFont {/${title_font} findfont title_fontsize scalefont setfont} bind def
102 /SetLogoFont {/${logo_font} findfont char_width scalefont setfont} bind def
103 /SetStringFont{/${text_font} findfont fontsize scalefont setfont} bind def
104 /SetPrimeFont {/Symbol findfont fontsize scalefont setfont} bind def
105 /SetSmallFont {/${text_font} findfont small_fontsize scalefont setfont} bind def
106 /SetNumberFont {/${text_font} findfont number_fontsize scalefont setfont} bind def
107
108 /DrawBox { % width height
109 /hh exch def
110 /ww exch def
111 gsave
112 0.2 setlinewidth
113 %0.5 setgray
114
115 %0 0 moveto
116 hh 0 rlineto
117 0 ww rlineto
118 hh neg 0 rlineto
119 0 ww neg rlineto
120 stroke
121 grestore
122 } bind def
123
124
125 /StartLogo {
126 %save
127 gsave
128
129
130 debug {
131 logo_margin logo_margin moveto
132 logo_height logo_margin 2 mul sub
133 logo_width logo_margin 2 mul sub
134 DrawBox } if
135
136 show_title { DrawTitle } if
137 show_xaxis_label { DrawXaxisLable } if
138 show_fineprint { DrawFineprint } if
139 DrawLogoLabel
140
141
142 MoveToFirstLine
143 } bind def
144
145
146 /DrawLogoLabel {
147 gsave
148 SetTitleFont
149
150 logo_margin
151 logo_height title_fontsize sub logo_margin sub
152 moveto
153
154 debug { title_fontsize logo_label stringwidth pop DrawBox } if
155 0 title_fontsize 4 div rmoveto % Move up to baseline (approximatly)
156 logo_label show
157
158 grestore
159 } bind def
160
161 /DrawTitle {
162 gsave
163 SetTitleFont
164
165 logo_width 2 div logo_title stringwidth pop 2 div sub
166 logo_height title_fontsize sub logo_margin sub
167 moveto
168
169 debug { title_fontsize logo_title stringwidth pop DrawBox } if
170
171 0 title_fontsize 4 div rmoveto % Move up to baseline (approximatly)
172 logo_title show
173
174 grestore
175 } bind def
176
177 /DrawXaxisLable {
178 % Print X-axis label, bottom center
179 gsave
180 SetStringFont
181
182 logo_width 2 div xaxis_label stringwidth pop 2 div sub
183 xaxis_label_height logo_margin add fontsize sub
184 moveto
185 %fontsize 3 div
186
187 debug { fontsize xaxis_label stringwidth pop DrawBox } if
188
189 xaxis_label show
190
191 grestore
192 } bind def
193
194
195 /DrawFineprint {
196 gsave
197
198 SetSmallFont
199
200 logo_width fineprint stringwidth pop sub
201 logo_margin sub line_margin_right sub
202 logo_margin
203 moveto
204
205 debug { small_fontsize fineprint stringwidth pop DrawBox } if
206
207 fineprint show
208 grestore
209 } bind def
210
211 /MoveToFirstLine {
212 logo_margin
213 logo_height logo_margin sub title_height sub line_height sub
214 moveto
215 } bind def
216
217 /EndLogo {
218 grestore
219 %showpage
220 %restore
221 } bind def
222
223
224 /StartLine{
225 gsave
226
227 % Draw outer box
228 debug { line_height line_width DrawBox } if
229
230 % Move to lower left corner of content area
231 line_margin_left line_margin_bottom rmoveto
232
233 % Draw inner content box
234 debug {
235 line_height line_margin_bottom sub line_margin_top sub
236 line_width line_margin_left sub line_margin_right sub
237 DrawBox
238 } if
239
240 show_yaxis { DrawYaxis } if
241 show_xaxis { DrawLeftEnd } if
242
243 } bind def
244
245 /EndLine{
246 show_xaxis { DrawRightEnd } if
247 grestore
248 0 line_height neg rmoveto
249 } bind def
250
251
252 /DrawYaxis {
253 gsave
254 stack_margin neg 0 translate
255 DrawYaxisBar
256 DrawYaxisLabel
257 grestore
258 } bind def
259
260
261 /DrawYaxisBar {
262 gsave
263 stack_margin neg 0 rmoveto
264
265 SetNumberFont
266 stroke_width setlinewidth
267
268 /str 10 string def % string to hold number
269 /smallgap stack_margin def
270
271 % Draw first tic and bar
272 gsave
273 tic_length neg 0 rmoveto
274 tic_length 0 rlineto
275 0 stack_height rlineto
276 stroke
277 grestore
278
279 % Draw the tics
280 % initial increment limit proc for
281 0 yaxis_tic_interval yaxis_scale abs
282 {/loopnumber exch def
283
284 % convert the number coming from the loop to a string
285 % and find its width
286 loopnumber 10 str cvrs
287 /stringnumber exch def % string representing the number
288
289 stringnumber stringwidth pop
290 /numberwidth exch def % width of number to show
291
292 /halfnumberheight
293 stringnumber CharBoxHeight 2 div
294 def
295
296 gsave
297 numberwidth % move back width of number
298 neg loopnumber stack_height yaxis_scale div mul % shift on y axis
299 halfnumberheight sub % down half the digit
300 rmoveto % move back the width of the string
301
302 tic_length neg smallgap sub % Move back a bit more
303 0 rmoveto % move back the width of the tic
304
305 stringnumber show
306 smallgap 0 rmoveto % Make a small gap
307
308 % now show the tic mark
309 0 halfnumberheight rmoveto % shift up again
310 tic_length 0 rlineto
311 stroke
312 grestore
313 } for
314
315 % Draw the minor tics
316 % initial increment limit proc for
317 0 yaxis_minor_tic_interval yaxis_scale abs
318 {/loopnumber2 exch def
319 gsave
320 0
321 loopnumber2 stack_height yaxis_scale div mul
322 rmoveto
323
324 tic_length 2 div neg 0 rlineto
325 stroke
326 grestore
327 } for
328
329 grestore
330 } bind def
331
332 /DrawYaxisLabel {
333 gsave
334 SetStringFont
335
336 % How far we move left depends on the size of
337 % the tic labels.
338 /str 10 string def % string to hold number
339 yaxis_scale yaxis_tic_interval div cvi yaxis_tic_interval mul
340 str cvs stringwidth pop
341 tic_length 1.25 mul add neg
342
343 stack_height
344 yaxis_label stringwidth pop
345 sub 2 div
346
347 rmoveto
348 90 rotate
349
350 yaxis_label show
351 grestore
352 } bind def
353
354
355 %Take a single character and return the bounding box
356 /CharBox { % <char> CharBox <lx> <ly> <ux> <uy>
357 gsave
358 newpath
359 0 0 moveto
360 % take the character off the stack and use it here:
361 true charpath
362 flattenpath
363 pathbbox % compute bounding box of 1 pt. char => lx ly ux uy
364 % the path is here, but toss it away ...
365 grestore
366 } bind def
367
368
369 % The height of a characters bounding box
370 /CharBoxHeight { % <char> CharBoxHeight <num>
371 CharBox
372 exch pop sub neg exch pop
373 } bind def
374
375
376 % The width of a characters bounding box
377 /CharBoxWidth { % <char> CharBoxHeight <num>
378 CharBox
379 pop exch pop sub neg
380 } bind def
381
382
383 /DrawLeftEnd {
384 gsave
385 SetStringFont
386 leftEndDeltaX leftEndDeltaY rmoveto
387
388 show_ends {
389 debug { leftEndDeltaY neg leftEndDeltaX neg DrawBox } if
390 end_type (d) eq {(5) show DrawPrime} if
391 end_type (p) eq {(N) show} if
392 } if
393 grestore
394 } bind def
395
396 /DrawRightEnd {
397 gsave
398 SetStringFont
399 rightEndDeltaX rightEndDeltaY rmoveto
400
401 show_ends {
402 debug { rightEndDeltaY neg leftEndDeltaX neg DrawBox } if
403 end_type (d) eq {(3) show DrawPrime} if
404 end_type (p) eq {(C) show} if
405 } if
406 grestore
407 } bind def
408
409 /DrawPrime {
410 gsave
411 SetPrimeFont
412 (\242) show
413 grestore
414 } bind def
415
416
417 /StartStack { % <stackNumber> startstack
418 show_xaxis {DrawNumber}{pop} ifelse
419 gsave
420 debug { stack_height stack_width DrawBox } if
421
422 } bind def
423
424 /EndStack {
425 grestore
426 stack_width 0 rmoveto
427 } bind def
428
429
430 /DrawNumber { % number MakeNumber
431 /n exch def
432
433
434 gsave
435 %0 stack_margin neg rmoveto
436 stroke_width setlinewidth
437 stack_width 0 rlineto
438 stack_width 2 div neg 0 rmoveto
439
440 n () eq
441 { 0 tic_length 4 div neg rlineto }
442 { 0 tic_length 2 div neg rlineto }
443 ifelse
444
445 stroke
446 grestore
447
448
449
450 gsave
451 n
452 SetNumberFont
453 stack_width 2 div tic_length 2 div neg rmoveto
454
455 rotate_numbers {
456 90 rotate
457 dup stringwidth pop neg % find the length of the number
458 stack_margin sub % Move down a bit
459 (0) CharBoxHeight 2 div neg % left half height of numbers
460 rmoveto
461 show
462 } {
463 dup stringwidth pop neg 2 div number_fontsize neg rmoveto
464 show
465 } ifelse
466
467
468
469 grestore
470 } bind def
471
472
473
474 % Draw a character whose height is proportional to symbol bits
475 /ShowSymbol{ % interval character ShowSymbol
476 /char exch def
477 /interval exch def
478 /fraction_width exch def
479
480 /char_height
481 interval yaxis_scale div stack_height mul
482 stack_margin sub
483 dup
484 % if char_height is negative or very small replace with zero
485 % BUG FIX: This used to be '0.0 gt' but it seems that DrawHeight
486 % has a finite, non-zero minimum, which results in a rangecheck error
487 0.001 gt {}{pop 0.0} ifelse
488 def
489
490 char_height 0.0 gt {
491 show_boxes {
492 gsave
493 /ww char_height stack_margin add def
494 /hh stack_width def
495 stroke_width setlinewidth
496 hh 0 rlineto
497 0 ww rlineto
498 hh neg 0 rlineto
499 0 ww neg rlineto
500 stroke
501 grestore
502 } if
503
504 gsave
505 stack_margin stack_margin rmoveto
506 debug { char_height char_width DrawBox } if
507 1 fraction_width sub char_width mul 2 div 0 rmoveto
508 fraction_width char_width mul char_height char DrawChar
509 grestore
510
511 } if
512 0 interval yaxis_scale div stack_height mul rmoveto
513 } bind def
514
515
516 /DrawChar { % <width> <height> <char> ShowChar
517 /tc exch def % The character
518 /ysize exch def % the y size of the character
519 /xsize exch def % the x size of the character
520 /xmulfactor 1 def
521 /ymulfactor 1 def
522
523 gsave
524 SetLogoFont
525 tc SetColor
526
527 % IReplacementHack
528 % Deal with the lack of bars on the letter 'I' in Arial and Helvetica
529 % by replacing with 'I' from Courier.
530 tc (I) eq {
531 /Courier findfont char_width scalefont setfont
532 } if
533
534
535 shrink {
536 xsize 1 shrink_fraction sub 2 div mul
537 ysize 1 shrink_fraction sub 2 div mul rmoveto
538 shrink_fraction shrink_fraction scale
539 } if
540
541 % Calculate the font scaling factors
542 % Loop twice to catch small correction due to first scaling
543 2 {
544 gsave
545 xmulfactor ymulfactor scale
546
547 ysize % desired size of character in points
548 tc CharBoxHeight
549 dup 0.0 ne {
550 div % factor by which to scale up the character
551 /ymulfactor exch def
552 } {pop pop} ifelse
553
554 xsize % desired size of character in points
555 tc CharBoxWidth
556 dup 0.0 ne {
557 div % factor by which to scale up the character
558 /xmulfactor exch def
559 } {pop pop} ifelse
560 grestore
561 } repeat
562
563
564
565 % Draw the character
566 xmulfactor ymulfactor scale
567 % Move lower left corner of character to start point
568 tc CharBox pop pop % llx lly : Lower left corner
569 exch neg exch neg
570 rmoveto
571
572 tc show
573
574 grestore
575 } bind def
576
577 /SetColor{ % <char> SetColor
578 dup color_dict exch known {
579 color_dict exch get aload pop setrgbcolor
580 } {
581 pop
582 default_color aload pop setrgbcolor
583 } ifelse
584 } bind def
585
586
587 /DrawErrorbar{ % interval_down interval_up DrawErrorbar
588
589 gsave
590 /points_per_unit stack_height yaxis_scale div def
591 /height_up exch points_per_unit mul def
592 /height_down exch points_per_unit mul def
593
594 show_errorbars {
595
596 stroke_width setlinewidth
597 errorbar_gray setgray
598 stack_width 2 div 0 rmoveto
599
600 /errorbar_width char_width errorbar_width_fraction mul def
601 /errorbar_width2 errorbar_width 2 div def
602
603 gsave
604 0 height_down neg rmoveto
605 errorbar_width2 neg 0 rlineto
606 errorbar_width 0 rlineto
607 errorbar_width2 neg 0 rlineto
608 0 height_down errorbar_fraction mul rlineto
609 stroke
610 grestore
611
612 gsave
613 0 height_up rmoveto
614 errorbar_width2 neg 0 rlineto
615 errorbar_width 0 rlineto
616 errorbar_width2 neg 0 rlineto
617 0 height_up neg errorbar_fraction mul rlineto
618 stroke
619 grestore
620 } if
621
622 grestore
623
624 } bind def
625
626 /DrawErrorbarFirst{ % interval_down interval_up center DrawErrorbarFirst
627 gsave
628 /points_per_unit stack_height yaxis_scale div def
629 /center exch points_per_unit mul def
630
631 0 center rmoveto
632 DrawErrorbar
633 grestore
634 } bind def
635
636 %%EndProlog
637
638 %%Page: 1 1
639
640 % Example Data
641 %StartLogo
642 % StartLine
643 % (1) StartStack
644 % 1.2 (C) ShowSymbol
645 % 2.2 (I) ShowSymbol
646 % 0.5 0.5 DrawErrorbar
647 % EndStack
648 % (2) StartStack
649 % 0.5 (I) ShowSymbol
650 % 0.9 (L) ShowSymbol
651 % 1.0 (G) ShowSymbol
652 %
653 % 0.5 0.5 DrawErrorbar
654 % EndStack
655 % (234) StartStack
656 % EndStack
657 % (235) StartStack
658 % EndStack
659 % EndLine
660 %EndLogo
661
662 StartLogo
663
664 ${logo_data}
665
666 EndLogo
667
668
669 %%EOF