1 /*	dispn.c	associated subroutines for matching sequences */
2 /* 	modified for Tek4014 terminal, not 4027 */
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <time.h>
8 
9 #define XTERNAL
10 #include "upam.gbl"
11 
12 #define TRUE 1
13 #define FALSE 0
14 extern FILE *outfd;
15 
16 extern int have_stats;
17 extern int iscore, gscore;
18 extern char name0[], ltitle[],ttitle[];
19 /*extern int colflg;*/
20 
21 /* black blue cyan green lt_green */
22 float rlincol[]={0.0,0.0,0.0,0.45,0.0};
23 float glincol[]={0.0,0.0,0.5,0.30,1.0};
24 float blincol[]={0.0,0.8,0.5,0.15,0.0};
25 
26 int *linarr;
27 int nlinarr=5;
28 
29 extern char lvstr[];
30 
31 double elinval[4]={1e-4,1e-2,1.0,100.0};
32 int ilinval[4]={200,100,50,25};
33 
34 extern int dnaseq;
35 
36 extern int smin0,smin1;
37 extern long loffset;
38 extern int revflg;
39 extern int pmirror;
40 
41 #define DIAG 1
42 #define INS0 2
43 #define INS1 4
44 
45 long pminx, pmaxx, pminy, pmaxy;
46 int max_x=540, max_y=540;
47 
48 double fxscal, fyscal, fxoff, fyoff;
49 #define SX(x) (int)((double)(x)*fxscal+fxoff+24)
50 #define SY(y) (int)((double)(y)*fyscal+fyoff+48)
51 
52 void xaxis(long, int);
53 void yaxis(long, int);
54 void legend();
55 void linetype(int);
56 void closeplt();
57 void opnline(long x, long y, int s, double e_val, double percent, int nc);
58 void newline();
59 void clsline();
60 void move(int, int);
61 void draw(int, int);
62 void drawtitle(char *);
63 void drawstr(char *);
64 
65 
66 void
discons(char * seqc0,char * seqc1,int nc)67 discons(char *seqc0, char *seqc1, int nc)
68 {
69   long x0, x1, y0, y1;
70   int direct, ii;
71 
72   x1 = x0 = smin1 + loffset;
73   if (!revflg) y1 = y0 = smin0;
74   else {
75     if (!pmirror) y1 = y0 = smin0 + nc;
76     else {y1 = y0 = smin0;
77 	  x1 = x0 = smin1 + nc;
78     }
79   }
80 
81   direct = DIAG;
82 
83   move(SX(x0),SY(y0));
84 
85   for (ii=0; ii<nc; ii++) {
86     if (seqc0[ii]==' ' || seqc1[ii]==' ') continue;
87     if (seqc0[ii]!='-'&&seqc1[ii]!='-') {
88       if (direct!=DIAG) {
89 	draw(SX(x1),SY(y1));
90 	x0 = x1; y0 = y1;
91 	direct = DIAG;
92       }
93       if (!revflg) {x1++; y1++;}
94       else {
95 	if (!pmirror) {x1++; y1--;}
96 	else {x1--; y1++;}
97       }
98     }
99     else if (seqc0[ii]=='-') {
100       if (direct!=INS0) {
101 	draw(SX(x1),SY(y1));
102 	x0 = x1; y0 = y1;
103 	direct = INS0;
104       }
105       if (revflg && pmirror) x1--;
106       else x1++;
107     }
108     else if (seqc1[ii]=='-') {
109       if (direct!=INS1) {
110 	draw(SX(x1),SY(y1));
111 	x0 = x1; y0 = y1;
112 	direct = INS1;
113       }
114       if (revflg && !pmirror) y1--;
115       else y1++;
116     }
117   }
118 
119   draw(SX(x1),SY(y1));
120 
121 }
122 
123 void
disgraph(int n0,int n1,float percent,int score,int min0,int min1,int max0,int max1)124 disgraph(int n0, int n1, float percent, int score,
125 	 int min0, int min1, int max0, int max1) {}
126 
127 void
aancpy(to,from,count)128 aancpy(to,from,count)
129      char *to, *from;
130      int count;
131 {
132   char *tp;
133   tp=to;
134   while (count-- && *from >= 0) {
135     if (*from<nsq) *tp++ = sq[*(from++)];
136     else *tp++ = *from++;
137   }
138   *tp=0;
139 }
140 
141 void
openplt(long n0,long n1,int sq0off,int sq1off)142 openplt(long n0, long n1, int sq0off, int sq1off)
143 {
144   char *getenv(), *sptr;
145   char tstr[32];
146   time_t tt;
147 
148   tt = time(NULL);
149 
150   if (strlen(lvstr)>0) {
151     sscanf(lvstr,"%lg %lg %lg",&elinval[0],&elinval[1],&elinval[2]);
152   }
153   else if ((sptr=getenv("LINEVAL"))!=NULL && strlen(sptr)>0) {
154     sscanf(sptr,"%lg %lg %lg",&elinval[0],&elinval[1],&elinval[2]);
155   }
156 
157   printf("%%!PS-Adobe-2.0\n");
158   printf("%%%%Creator: plalign\n");
159   printf("%%%%CreationDate: %s",ctime(&tt));
160   printf("%%%%DocumentFonts: Courier\n");
161   printf("%%%%Pages: 1\n");
162   printf("%%%%BoundingBox: 18 18 564 588\n");
163   printf("%%%%EndComments\n");
164   printf("%%%%EndProlog\n");
165   printf("%%%%Page: 1 1\n");
166   printf("/Courier findfont 14 scalefont setfont\n");
167   printf("/vcprint { gsave 90 rotate dup stringwidth pop 2 div neg 0 rmoveto\n");
168   printf("show newpath stroke grestore } def\n");
169   printf("/hcprint { gsave dup stringwidth pop 2 div neg 0 rmoveto\n");
170   printf("show newpath stroke grestore } def\n");
171   printf("/hrprint { gsave dup stringwidth pop neg 0 rmoveto\n");
172   printf("show newpath stroke grestore } def\n");
173   printf("/hprint { gsave show newpath stroke grestore } def\n");
174 
175   pmaxx = n1;
176   pmaxy = n0;
177 
178   fxscal = (double)(max_x-1)/(double)(n1);
179   fyscal = (double)(max_y-1)/(double)(n0);
180 
181   if (fxscal > fyscal) fxscal = fyscal;
182   else fyscal = fxscal;
183 
184   if (fyscal * n0 < (double)max_y/5.0)
185     fyscal = (double)(max_y-1)/((double)(n0)*5.0);
186 
187   fxscal *= 0.9; fxoff = (double)(max_x-1)/11.0;
188   fyscal *= 0.9; fyoff = (double)(max_y-1)/11.0;
189 
190   linetype(0);
191   printf("gsave\n");
192   printf("currentlinewidth 1.5 mul setlinewidth\n");
193   newline();
194   move(SX(0),SY(0));
195   draw(SX(0),SY(n0));
196   draw(SX(n1),SY(n0));
197   draw(SX(n1),SY(0));
198   draw(SX(0),SY(0));
199   clsline(n0,n1,100000);
200   printf("grestore\n");
201   xaxis(n1,sq1off);
202   yaxis(n0,sq0off);
203   legend();
204 }
205 
206 void
drawdiag(n0,n1)207 drawdiag(n0,n1)
208 	long n0, n1;
209 {
210 
211 	linetype(0);
212 	printf("gsave\n");
213 	printf("currentlinewidth 1.5 mul setlinewidth\n");
214 	newline();
215 	move(SX(0),SY(0));
216 	draw(SX(n0),SY(n1));
217 	clsline(n0,n1,10000);
218 	printf("grestore\n");
219 }
220 
221 /* tick array - values */
222 int tarr[] = {10,20,50,100,200,500,1000,2000,5000};
223 int ntarr = sizeof(tarr);
224 
225 void
xaxis(long n,int offset)226 xaxis(long n, int offset)
227 {
228   int i, jm, tick;
229   long js, jo, jl;
230   char numstr[20],*bp;
231 
232   tick = 6;
233 
234   /* search for the correct increment for the tick array */
235   for (i=0; i<ntarr; i++) {
236     /* seek to divide into 20 or fewer divisions */
237     if ((jm = n/tarr[i])<21) goto found;
238   }
239   jm = n/5000l;
240   i=ntarr-1;
241  found:
242   /* js is the start of the value - modify to accomodate offset */
243   js = tarr[i];
244 
245   /* jo is the offset */
246   jo = offset%tarr[i];	/* figure out offset in tarr[i] increments */
247 
248   /* jl is the label */
249   jl = offset/tarr[i];	/* figure out offset in tarr[i] increments */
250   jl *= tarr[i];
251 
252   newline();
253   for (i=1; i<=jm; i++) {
254     move(SX((long)i*js - jo),SY(0));
255     draw(SX((long)i*js - jo),SY(0)-tick);
256   }
257   clsline(n,n,10000);
258 
259   sprintf(numstr,"%ld",js + jl );
260   printf("newpath\n");
261   move(SX(js-jo),SY(0)-tick-16);
262   printf("(%s) hcprint\n",numstr);
263 
264   printf("newpath\n");
265   sprintf(numstr,"%ld",jm*js+jl);
266   move(SX((long)jm*js-jo),SY(0)-tick-16);
267   printf("(%s) hcprint\n",numstr);
268 
269   printf("newpath\n");
270   move(SX(n/2),SY(0)-tick-30);
271 
272   for (bp = strchr(ltitle,'('); (bp!=NULL); bp = strchr(bp+1,'(')) *bp=' ';
273   for (bp = strchr(ltitle,')'); (bp!=NULL); bp = strchr(bp+1,')')) *bp=' ';
274   printf("(%s) hcprint\n",ltitle);
275 }
276 
277 void
yaxis(long n,int offset)278 yaxis(long n, int offset)
279 {
280   int i, jm, tick;
281   long js, jo, jl;
282   char numstr[20],*bp;
283 
284   tick = 6;
285 
286   for (i=0; i<ntarr; i++) {
287     if ((jm = n/tarr[i])<21) goto found;
288   }
289   jm = n/5000l;
290   i=ntarr-1;
291 
292  found:
293   js = (long)tarr[i];
294 
295   /* jo is the offset */
296   jo = offset%tarr[i];	/* figure out offset in tarr[i] increments */
297   /* jl is the label */
298   jl = offset/tarr[i];	/* figure out offset in tarr[i] increments */
299   jl *= tarr[i];
300 
301   newline();
302   for (i=1; i<=jm; i++) {
303     move(SX(0),SY((long)i*js-jo));
304     draw(SX(0)-tick,SY((long)i*js-jo));
305   }
306   clsline(n,n,10000);
307   sprintf(numstr,"%ld",js+jl);
308   move(SX(0)-tick-4,SY(js-jo)-4);
309   printf("(%s) hrprint\n",numstr);
310   sprintf(numstr,"%ld",(long)jm*js+jl);
311   move(SX(0)-tick-4,SY((long)jm*js-jo)-4);
312   printf("(%s) hrprint\n",numstr);
313 
314   move(SX(0)-tick-24,SY(n/2));
315   for (bp = strchr(ttitle,'('); (bp!=NULL); bp = strchr(bp+1,'(')) *bp=' ';
316   for (bp = strchr(ttitle,')'); (bp!=NULL); bp = strchr(bp+1,')')) *bp=' ';
317   printf("(%s) vcprint\n",ttitle);
318 
319 }
320 
321 void
legend()322 legend()
323 {
324   int i, last, del;
325   int ixp, iyp;
326   char numstr[10];
327   int xpos[]={144,144,288,288,432};
328   int ypos[]={36,18,36,18,27};
329 
330   if (have_stats) last = 5;
331   else last = 4;
332 
333   del = 10;
334   for (i=0; i<last ; i++) {
335     printf("gsave currentlinewidth 1.5 mul setlinewidth\n");
336     newline();
337     linetype(i);
338     move(xpos[i],ypos[i]);
339     draw(xpos[i]+60,ypos[i]);
340     clsline(1000,1000,10000);
341     printf("grestore\n");
342     move(xpos[i]+72,ypos[i]-4);
343     if (have_stats) {
344       if (i==4) sprintf(numstr,">%.1g",elinval[3]);
345       else sprintf(numstr,"<%.1g",elinval[i]);
346     }
347     else {
348       if (i==3) sprintf(numstr,"<%d",ilinval[3]);
349       else sprintf(numstr,">%d",ilinval[i]);
350     }
351     printf("(%s) hprint\n",numstr);
352   }
353 }
354 
355 void
linetype(type)356 linetype(type)
357      int type;
358 {
359   printf("%5.3f %5.3f %5.3f setrgbcolor\n",
360 	 rlincol[type],glincol[type],blincol[type]);
361 }
362 
363 void
closeplt()364 closeplt()
365 {
366   printf("%%%%Trailer\n");
367   printf("showpage\n");
368   printf("%%%%EOF\n");
369 }
370 
371 void
opnline(long x,long y,int s,double e_val,double percent,int nc)372 opnline(long x, long y, int s, double e_val, double percent, int nc)
373 {
374   if (have_stats) {
375     if (e_val< elinval[0]) linetype(0);
376     else if (e_val < elinval[1]) linetype(1);
377     else if (e_val < elinval[2]) linetype(2);
378     else if (e_val < elinval[3]) linetype(3);
379     else linetype(4);
380   }
381   else {
382     if (s > ilinval[0]) linetype(0);
383     else if (s> ilinval[1]) linetype(1);
384     else if (s> ilinval[2]) linetype(2);
385     else linetype(3);
386   }
387 
388   printf("newpath\n");
389 }
390 
391 void
newline()392 newline()
393 {
394   printf("0 0 0 setrgbcolor\n newpath\n");
395 }
396 
397 void
clsline(x,y,s)398 clsline(x,y,s)
399      long x, y;
400      int s;
401 {
402   printf("stroke\n");
403 }
404 
405 void
move(x,y)406 move(x,y)
407      int x, y;
408 {
409   printf("%d %d moveto\n",x,y);
410 }
411 
412 void
draw(x,y)413 draw(x,y)
414 	int x, y;
415 {
416   printf("%d %d lineto\n",x,y);
417 }
418 
419 void
drawstr(str)420 drawstr(str)
421      char *str;
422 {
423   char *bp;
424 
425   for (bp = strchr(str,'('); (bp!=NULL); bp = strchr(bp+1,'(')) *bp=' ';
426   for (bp = strchr(str,')'); (bp!=NULL); bp = strchr(bp+1,')')) *bp=' ';
427 
428   printf("(%s) show\n",str);
429 }
430 
cal_coord(int n0,int n1,long * a_start0,long * a_stop0,long * a_start1,long * a_stop1)431 void cal_coord(int n0, int n1,
432 	       long *a_start0, long *a_stop0, long *a_start1, long *a_stop1 )
433 {}
434