|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/desktop/gxydraw.c |
source navigation diff markup identifier search freetext search file search |
1 /*
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: dxydraw.c
27 *
28 * Author(s): John Kuzio
29 *
30 * Version Creation Date: 98-01-01
31 *
32 * $Revision: 6.6 $
33 *
34 * File Description: sentinel dot plots
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * --------------------------------------------------------------------------
40 * $Log: gxydraw.c,v $
41 * Revision 6.6 1999/10/04 17:46:23 kans
42 * include vibrant.h
43 *
44 * Revision 6.5 1998/09/16 19:00:37 kuzio
45 * cvs logs
46 *
47 * ==========================================================================
48 */
49
50 #include <vibrant.h>
51 #include <seqport.h>
52 #include <drawingp.h>
53 #include <gxydraw.h>
54
55 /* common */
56
57 static void CleanGSP (BigScalar calldata)
58 {
59 GraphXYSentPtr gsp;
60
61 if ((gsp = (GraphXYSentPtr) calldata) == NULL)
62 return;
63 MemFree (gsp->endpointarray);
64 MemFree (gsp->endpointvalues);
65 MemFree (gsp);
66 return;
67 }
68
69 static void TickLabel (Int4 tickvalue, Int2 xcoord, Int2 ycoord)
70 {
71 Char numberbuffer[32];
72
73 sprintf (numberbuffer, "%8ld", (long) tickvalue);
74 PaintStringEx (numberbuffer, xcoord, ycoord);
75
76 return;
77 }
78
79 /* dot plot */
80
81 static void PlotTheDotXYPlot (Int4Ptr epa, Int4 xaxis, Int4 yaxis,
82 Int4 xscale, Int4 yscale, Int4Ptr endpoints,
83 Int4 cutoff, AttPData PNTR curattrib,
84 Boolean flagIsGUI)
85 {
86 Int4 ix, iy;
87 PoinT point;
88 Int4 xoffset, yoffset, xcorrect, ycorrect;
89 Int4 loop, curcut;
90 Uint1 curR, curG, curB;
91 Int4 window;
92 Int4Ptr curepa;
93
94 xoffset = 50;
95 yoffset = 50;
96
97 curR = curattrib->color[0];
98 curG = curattrib->color[1];
99 curB = curattrib->color[2];
100
101 window = 8;
102 curepa = epa;
103 for (loop = 0; loop <= window; loop++)
104 {
105 if (loop >= cutoff)
106 {
107 epa = curepa;
108 curcut = loop * ((256/window) - 1);
109 curcut = 255 - curcut;
110 if (curcut < 0)
111 curcut = 0;
112 Nlm_SelectColor (255, (Uint1) curcut, 0);
113 for (iy = 0; iy < yaxis; iy++)
114 {
115 for (ix = 0; ix < xaxis; ix++)
116 {
117 if (*epa == loop)
118 {
119 point.x = (Int2) (ix + ((window-1)/xscale) + xoffset);
120 point.y = (Int2) (iy + ((window-1)/yscale) + yoffset);
121 DrawLine (point, point);
122 }
123 epa++;
124 }
125 }
126 }
127 }
128 Nlm_SelectColor (curR, curG, curB);
129
130 if (endpoints != NULL)
131 {
132 if (flagIsGUI)
133 {
134 xcorrect = 25;
135 ycorrect = 50;
136 }
137 else
138 {
139 xcorrect = 50;
140 ycorrect = 60;
141 }
142 TickLabel (endpoints[0], (Int2) (xoffset-xcorrect),
143 (Int2) (yoffset-10));
144 TickLabel (endpoints[1], (Int2) (xoffset-xcorrect+xaxis),
145 (Int2) (yoffset-10));
146 TickLabel (endpoints[2], (Int2) (xoffset-ycorrect),
147 (Int2) (yoffset+10));
148 TickLabel (endpoints[3], (Int2) (xoffset-ycorrect),
149 (Int2) (yoffset+yaxis));
150 }
151
152 return;
153 }
154
155 static void DotXYSentProc (BigScalar calldata, PrimDrawContext pdc)
156 {
157 GraphXYSentPtr gsp;
158 DrawInfoPtr dInfoPtr;
159
160 if ((gsp = (GraphXYSentPtr) calldata) == NULL)
161 return;
162 if (gsp->endpointarray == NULL)
163 return;
164
165 dInfoPtr = (DrawInfoPtr) pdc;
166 PlotTheDotXYPlot (gsp->endpointarray, gsp->xaxiscount, gsp->yaxiscount,
167 gsp->xscale, gsp->yscale, gsp->endpointvalues,
168 gsp->dotcutoff, &(dInfoPtr->curattrib),
169 gsp->flagIsGUI);
170 return;
171 }
172
173 static GraphXYSentPtr AddDotXYSentinelToPicture (BioseqPtr bspT,
174 BioseqPtr bspP,
175 SegmenT seg,
176 Int4 cutoff,
177 Int4 xscale,
178 Int4 yscale,
179 Boolean flagLabels)
180 {
181 GraphXYSentPtr gsp;
182 Int4 xaxiscount, yaxiscount;
183 Int4 i, imatch, ix, iy, xstop, ystop, ixs, iys;
184 Int4 window;
185 Int4Ptr epa, epap;
186 SeqPortPtr spp;
187 Uint1Ptr seqT, seqP, pseqT, pseqP;
188
189 if (bspT == NULL || bspP == NULL || seg == NULL)
190 return NULL;
191 if ((gsp = (GraphXYSentPtr) MemNew (sizeof (GraphXYSentData))) == NULL)
192 return NULL;
193 gsp->flagIsGUI = VibrantIsGUI ();
194
195 if ((epa = (Int4Ptr) MemNew (sizeof (Int4) * bspT->length * bspP->length))
196 == NULL)
197 {
198 MemFree (gsp);
199 return NULL;
200 }
201 gsp->endpointarray = epa;
202
203 seqT = (Uint1Ptr) MemNew (sizeof (Uint1) * (bspT->length + 1));
204 seqP = (Uint1Ptr) MemNew (sizeof (Uint1) * (bspP->length + 1));
205
206 spp = SeqPortNew (bspT, 0, bspT->length-1, 0, Seq_code_iupacaa);
207 SeqPortRead (spp, seqT, (Int2) bspT->length);
208 SeqPortFree (spp);
209 spp = SeqPortNew (bspP, 0, bspP->length-1, 0, Seq_code_iupacaa);
210 SeqPortRead (spp, seqP, (Int2) bspP->length);
211 SeqPortFree (spp);
212
213 window = 8;
214 xstop = bspT->length - window;
215 ystop = bspP->length - window;
216 yaxiscount = 0;
217 iy = 0;
218 while (iy < ystop)
219 {
220 epap = epa;
221 for (iys = 0; iys < yscale; iys++)
222 {
223 epa = epap;
224 xaxiscount = 0;
225 ix = 0;
226 while (ix < xstop)
227 {
228 for (ixs = 0; ixs < xscale; ixs++)
229 {
230 imatch = 0;
231 pseqT = &(seqT[ix]);
232 pseqP = &(seqP[iy]);
233 for (i = 0; i < window; i++)
234 {
235 if (*pseqT == *pseqP)
236 imatch++;
237 pseqT++;
238 pseqP++;
239 }
240 if (imatch > *epa)
241 *epa = imatch;
242 ix++;
243 if (ix >= xstop)
244 break;
245 }
246 epa++;
247 xaxiscount++;
248 }
249 iy++;
250 if (iy >= ystop)
251 break;
252 }
253 yaxiscount++;
254 }
255
256 MemFree (seqT);
257 MemFree (seqP);
258
259 gsp->xaxiscount = xaxiscount;
260 gsp->yaxiscount = yaxiscount;
261 gsp->dotcutoff = cutoff;
262 gsp->xscale = xscale;
263 gsp->yscale = yscale;
264 if (flagLabels)
265 {
266 gsp->endpointvalues = (Int4Ptr) MemNew (sizeof (Int4) * 4);
267 gsp->endpointvalues[0] = 0;
268 gsp->endpointvalues[1] = bspT->length;
269 gsp->endpointvalues[2] = 0;
270 gsp->endpointvalues[3] = bspP->length;
271 }
272 gsp->snt = AddSntRectangle (seg, 0, 0, 400, 400,
273 DotXYSentProc, (BigScalar) gsp,
274 CleanGSP, 0);
275 return gsp;
276 }
277
278 /* align */
279
280 static void PlotTheXYPlot (Int4Ptr epa, Int4 linenumber,
281 Int4 xaxis, Int4 yaxis, Int4Ptr endpoints,
282 AttPData PNTR curattrib, Boolean flagIsGUI,
283 Uint1Ptr color)
284 {
285 Int4 i;
286 Int4 startT, startP, stopT, stopP;
287 Int4 xoffset, yoffset, xcorrect, ycorrect;
288 Uint1 curR, curG, curB;
289 Int1 penW;
290
291 xoffset = 50;
292 yoffset = 50;
293
294 curR = curattrib->color[0];
295 curG = curattrib->color[1];
296 curB = curattrib->color[2];
297 penW = curattrib->penwidth;
298
299 Nlm_SelectColor (color[0], color[1], color[2]);
300 Nlm_WidePen (2);
301
302 for (i = 0; i < linenumber; i++)
303 {
304 startT = *epa++ + xoffset;
305 startP = *epa++ + yoffset;
306 stopT = *epa++ + xoffset;
307 stopP = *epa++ + yoffset;
308 MoveTo ((Int2) startT, (Int2) startP);
309 LineTo ((Int2) stopT, (Int2) stopP);
310 if (!flagIsGUI)
311 {
312 MoveTo ((Int2) (startT-1), (Int2) (startP+1));
313 LineTo ((Int2) (stopT-1), (Int2) (stopP+1));
314 MoveTo ((Int2) (startT+1), (Int2) (startP-1));
315 LineTo ((Int2) (stopT+1), (Int2) (stopP-1));
316 }
317 }
318
319 Nlm_SelectColor (curR, curG, curB);
320 Nlm_WidePen (penW);
321
322 if (endpoints != NULL)
323 {
324 if (flagIsGUI)
325 {
326 xcorrect = 25;
327 ycorrect = 50;
328 }
329 else
330 {
331 xcorrect = 50;
332 ycorrect = 60;
333 }
334 TickLabel (endpoints[0], (Int2) (xoffset-xcorrect),
335 (Int2) (yoffset-10));
336 TickLabel (endpoints[1], (Int2) (xoffset-xcorrect+xaxis),
337 (Int2) (yoffset-10));
338 TickLabel (endpoints[2], (Int2) (xoffset-ycorrect),
339 (Int2) (yoffset+10));
340 TickLabel (endpoints[3], (Int2) (xoffset-ycorrect),
341 (Int2) (yoffset+yaxis));
342 }
343
344 return;
345 }
346
347 static void XYSentProc (BigScalar calldata, PrimDrawContext pdc)
348 {
349 GraphXYSentPtr gsp;
350 DrawInfoPtr dInfoPtr;
351
352 if ((gsp = (GraphXYSentPtr) calldata) == NULL)
353 return;
354 if (gsp->endpointarray == NULL)
355 return;
356
357 dInfoPtr = (DrawInfoPtr) pdc;
358 PlotTheXYPlot (gsp->endpointarray, gsp->linenumber,
359 gsp->xaxiscount, gsp->yaxiscount, gsp->endpointvalues,
360 &(dInfoPtr->curattrib), gsp->flagIsGUI, gsp->color);
361 return;
362 }
363
364 static GraphXYSentPtr AddXYSentinelToPicture (BioseqPtr bspT, BioseqPtr bspP,
365 SeqAlignPtr saph, SegmenT seg,
366 Int4 xscale, Int4 yscale,
367 Uint1Ptr color,
368 Boolean flagLabels)
369 {
370 GraphXYSentPtr gsp;
371 Int4 linenumber;
372 Int4Ptr epa;
373 SeqAlignPtr sap;
374 DenseSegPtr dsp;
375 Int4 loop;
376 Int4 startT, stopT, startP, stopP;
377
378 if (bspT == NULL || bspP == NULL || saph == NULL || seg == NULL)
379 return NULL;
380 if ((gsp = (GraphXYSentPtr) MemNew (sizeof (GraphXYSentData))) == NULL)
381 return NULL;
382 gsp->flagIsGUI = VibrantIsGUI ();
383 gsp->color = color;
384
385 sap = saph;
386 linenumber = 0;
387 while (sap != NULL)
388 {
389 if (sap->segtype == 2) /* DenseSeg gapped search */
390 {
391 dsp = sap->segs;
392 for (loop = 0; loop < (Int4) dsp->numseg; loop++)
393 {
394 if (!(dsp->starts[loop*2] == -1 || dsp->starts[(loop*2)+1] == -1))
395 {
396 linenumber++;
397 }
398 }
399 }
400 sap = sap->next;
401 }
402
403 if ((epa = (Int4Ptr) MemNew (sizeof (Int4) * 4 * linenumber)) == NULL)
404 {
405 MemFree (gsp);
406 return NULL;
407 }
408
409 gsp->linenumber = linenumber;
410 gsp->endpointarray = epa;
411 gsp->xscale = xscale;
412 gsp->yscale = yscale;
413 gsp->xaxiscount = bspT->length / xscale;
414 gsp->yaxiscount = bspP->length / yscale;
415
416 sap = saph;
417 while (sap != NULL)
418 {
419 if (sap->segtype == 2) /* DenseSeg gapped search */
420 {
421 dsp = sap->segs;
422 for (loop = 0; loop < (Int4) dsp->numseg; loop++)
423 {
424 if (!(dsp->starts[loop*2] == -1 || dsp->starts[(loop*2)+1] == -1))
425 {
426 startT = dsp->starts[loop*2];
427 startP = dsp->starts[(loop*2)+1];
428 stopT = startT + dsp->lens[loop] - 1;
429 stopP = startP + dsp->lens[loop] - 1;
430 *epa++ = startT/xscale;
431 *epa++ = startP/yscale;
432 *epa++ = stopT/xscale;
433 *epa++ = stopP/yscale;
434 }
435 }
436 }
437 sap = sap->next;
438 }
439 if (flagLabels)
440 {
441 gsp->endpointvalues = (Int4Ptr) MemNew (sizeof (Int4) * 4);
442 gsp->endpointvalues[0] = 0;
443 gsp->endpointvalues[1] = bspT->length;
444 gsp->endpointvalues[2] = 0;
445 gsp->endpointvalues[3] = bspP->length;
446 }
447 gsp->snt = AddSntRectangle (seg, 0, 0, 400, 400,
448 XYSentProc, (BigScalar) gsp, CleanGSP, 0);
449 return gsp;
450 }
451
452 extern Int4 ScalePlot (Int4 xlen, Int4 ylen, Int4 maxlen)
453 {
454 Int4 scale, max, trim;
455
456 if (xlen > ylen)
457 max = xlen;
458 else
459 max = ylen;
460
461 scale = 1;
462 trim = max;
463 while (trim > maxlen)
464 {
465 scale++;
466 trim = max / scale;
467 }
468 return scale;
469 }
470
471 extern SegmenT DotXYPlot (BioseqPtr bspT, BioseqPtr bspP, Int4 cutoff,
472 Int4 xscale, Int4 yscale, SegmenT seg,
473 Boolean flagLabels)
474 {
475 if (bspT == NULL || bspP == NULL)
476 return seg;
477
478 if (seg == NULL)
479 seg = CreatePicture ();
480
481 AddDotXYSentinelToPicture (bspT, bspP, seg, cutoff, xscale, yscale,
482 flagLabels);
483 return seg;
484 }
485
486 extern SegmenT XYPlot (BioseqPtr bspT, BioseqPtr bspP, SeqAlignPtr sap,
487 Int4 xscale, Int4 yscale, Uint1Ptr color, SegmenT seg,
488 Boolean flagLabels)
489 {
490 if (bspT == NULL || bspP == NULL || sap == NULL)
491 return seg;
492
493 if (seg == NULL)
494 seg = CreatePicture ();
495
496 AddXYSentinelToPicture (bspT, bspP, sap, seg, xscale, yscale,
497 color, flagLabels);
498
499 return seg;
500 }
501 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |