1 /* dotvibrant.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
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 do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: dotvibrant.c
27 *
28 * Author: Fasika Aklilu
29 *
30 * Version Creation Date: 8/8/01
31 *
32 * $Revision: 6.18 $
33 *
34 * File Description: mouse management, graphic engine of the sequence viewer
35 * part of this code is also used for the WWW Entrez viewer
36 * (WWW_UDV define)
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * $Log: dotvibrant.c,v $
40 * Revision 6.18 2011/12/19 18:36:34 gouriano
41 * Corrected printf formatting. NOJIRA
42 *
43 * Revision 6.17 2006/07/13 17:13:17 bollin
44 * use Uint4 instead of Uint2 for itemID values
45 *
46 * Revision 6.16 2004/03/03 13:38:57 kans
47 * removed unused end: labels
48 *
49 * Revision 6.15 2003/05/05 12:34:47 rsmith
50 * type of DOTVibDataPtr displayOpts1 is Nlm_Handle, not HANDLE. Needed to compile under Codewarrior for Win32
51 *
52 * Revision 6.14 2002/08/07 18:14:23 kans
53 * itemID is Uint4, minor cleanup
54 *
55 * Revision 6.13 2001/10/15 18:18:37 wheelan
56 * adapted to new alignment manager
57 *
58 * Revision 6.12 2001/08/08 22:41:31 aklilu
59 * added revision
60 *
61 * Revision 6.11 2000/10/31 22:39:14 vakatov
62 * Get rid of the erroneous casts to HANDLE in the Nlm_Enable/Disable calls
63 *
64 * Revision 6.10 2000/08/07 16:34:51 kans
65 * added public domain notice
66 *
67 Revision 6.9 2000/08/07 13:46:59 sicotte
68 added revision
69
70 Revision 6.8 2000/08/07 13:46:34 sicotte
71 added revision
72
73 Revision 6.7 2000/08/07 13:46:05 sicotte
74 added Version logging
75
76 Revision 6.6 2000/08/07 13:45:22 sicotte
77 fixed (long) cast in sprintf and fprintf
78 *
79 *
80 * ==========================================================================
81 */
82 /* dotvibrant.c */
83
84 #include <dotviewer.h>
85 #include <alignmgr2.h>
86
87
88 /****************************************************************************
89
90 DEFINES
91 ***************************************************************************/
92
93 #define MAXZOOMSCALEVAL 23
94 #define BLOCK_SIZE 10
95 #define VIS_LEN 100
96
97 #define dot_SEQVIEW 1
98 #define dot_FEATVIEW 2
99 #define dotaln_BEST 1
100 #define dotaln_OUTLYING_LARGE 2
101 #define dotaln_OUTLYING_SMALL 3
102 #define dotaln_GENERAL 4
103 #define dot_plot 1
104 #define align_plot 2
105
106
107 #define SHOW_MATCHES 1
108 #define SHOW_MISMATCHES 2
109
110 /****************************************************************************
111
112 GLOBAL VARIABLES
113 ***************************************************************************/
114
115 static CharPtr na_names[] = {"A", "C", "G", "T", "-"};
116 static CharPtr aa_names [] = {"-", "A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W","X", "Y", "Z", "U" , "*"};
117 static Int4 zoomScaleVal [MAXZOOMSCALEVAL] = {
118 1L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 20L,
119 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 200L, 500L, 1000L
120 };
121
122 Uint2 prev_primID = 0;
123
124 /****************************************************************************
125
126 FUNCTION DECLARATIONS
127 ***************************************************************************/
128
129 static void DOT_DrawXAxis(SegmenT seg2, RecT r, Int4 height, Int4 xstart,Int4 xstop, Int4 scale, SeqIdPtr sip);
130 static void DOT_DrawYAxis(SegmenT seg2, RecT r, Int4 height, Int4 ystart, Int4 ystop, Int4 scale, Int4 Fh, SeqIdPtr sip);
131 static void DOT_VCrossHairs (RecT rcP, DOTVibDataPtr vdp, Int4 VFrom,Int4 HFrom);
132 static void DOT_HCrossHairs (RecT rcP, DOTVibDataPtr vdp, Int4 VFrom,Int4 HFrom);
133 static void DOT_QViewerClickProc(VieweR v, SegmenT seg, PoinT pt);
134 static void DOT_SViewerClickProc(VieweR v, SegmenT seg, PoinT pt);
135 static void DOT_ExitAlign(DOTAlignInfoPtr alp);
136 static DOTAlnPtr DOT_FindAlignment(DOTVibDataPtr vdp, Uint2 primID);
137 static Uint1Ptr DOT_GetNthSeqFromAlign (SeqAlignPtr sap, Int4 n);
138 static void DOT_SetColor(SegmenT seg1, Int1 code, Boolean is_autopanel);
139
140 /* scoop declarations */
141 extern void SCP_OrganizeAlnsInSet(SeqAlignPtr sap, Int4 fuzz, SCP_ResultPtr scp, Int4 n);
142 static int LIBCALLBACK SCP_CompareSpins(VoidPtr ptr1, VoidPtr ptr2);
143 static void SCP_GetNthSeqRangeInSASet(SeqAlignPtr PNTR saparray, Int4 numsaps, Int4 n, Int4Ptr start, Int4Ptr stop);
144
145 /*_________________________________________(DOT_Compression)_____
146
147 Purpose : Calculate sequence compression for window1
148
149 ____________________________________________________________________*/
150
DOT_Compression(Int4 len,Int4 viewersize)151 Int4 DOT_Compression (Int4 len, Int4 viewersize)
152 {
153 Int4 cmpfactor;
154 double f;
155
156
157
158 f = (double)(len/viewersize);
159 if (f <= 1)
160 cmpfactor = 1;
161 else
162 cmpfactor = (Int4)ceil(f);
163
164 return cmpfactor;
165
166 }
167
168 /*_______________________________(DOT_SetupMenus)____________
169
170 Purpose : Setup menus function for window1.
171
172 ____________________________________________________________________*/
DOT_SetupMenus()173 void DOT_SetupMenus ()
174
175 {
176 #ifdef WIN_MAC
177 MenU m;
178
179 m = AppleMenu (NULL);
180 DeskAccGroup (m);
181 #endif
182
183 }
184
185
186
187 /*________________________________(DOT_DrawXGrids)____________________
188
189
190 Purpose : Draw x-axis for DisplayHits, window1.
191
192 ____________________________________________________________________*/
DOT_DrawXGrids(RecT rupdate,RecT rcP,DOTVibDataPtr vdp,Int4 VFrom,Int4 HFrom,Int4 HTo,Int4 comp,Boolean GRID)193 void DOT_DrawXGrids (RecT rupdate, RecT rcP, DOTVibDataPtr vdp, Int4 VFrom, Int4 HFrom, Int4 HTo, Int4 comp, Boolean GRID)
194 {
195 Int4 x, y, y2, offset=0;
196 Int4 scale_pos, pos, Hseq_pos;
197 Char scale_buf[15] = {""}; /*scale value*/
198
199
200 offset=vdp->xstart;
201
202 /* draw the axis no matter how short the length */
203 /* if (vdp->curr_qlen <50) */
204 /* return; */
205
206 pos = 100;
207 /* select the font type */
208 SelectFont(vdp->Fnt);
209
210 Black(); /* X axis */
211 MoveTo (rcP.left,rcP.top-10);
212 LineTo (rcP.left+ HTo,rcP.top-10);
213
214
215 /* write sequence length */
216 if ( vdp->curr_qlen - HFrom == HTo)
217 {
218
219 Red();
220 sprintf(scale_buf, "%d", vdp->xstop);
221 MoveTo (rcP.left+ HTo +10 ,rcP.top-5);
222 PaintString (scale_buf);
223 }
224
225 HTo += HFrom;
226
227
228 for (scale_pos = HFrom+1; scale_pos <= HTo+1; scale_pos++)
229 {
230
231 /* draw 0 on axis */
232 if (scale_pos == 1)
233 {
234 Black();
235 x = rcP.left;
236 y = rcP.top;
237 MoveTo (x, y-10);
238 LineTo (x,y-20);
239 Blue();
240 MoveTo(x,y -25);
241 sprintf(scale_buf, "%d", offset);
242 PaintString (scale_buf);
243
244
245 }
246 else
247 {
248 if (!(scale_pos % pos))
249 {
250 Hseq_pos = (scale_pos*comp)+offset;
251
252 x = rcP.left + scale_pos-HFrom;
253 y = MAX(rupdate.top, rcP.top);
254 y2 = MIN(rupdate.bottom, rcP.top+vdp->curr_slen-VFrom);
255
256 if ((!(HTo<rcP.left))&& (y<y2) && GRID)
257 {
258 LtGray();
259 Dotted();
260 MoveTo (x, y);
261 LineTo (x,y2);
262 }
263
264 /* add scale values */
265 Black();
266 Solid();
267 y = rcP.top-10;
268 MoveTo (x, y);
269 LineTo (x,y-10);
270 sprintf(scale_buf, "%d", Hseq_pos);
271 x = rcP.left + scale_pos -HFrom - (StringWidth(scale_buf)/2);
272 y = rcP.top -25;
273 if (x>rcP.left)
274 {
275 Blue();
276 MoveTo(x,y);
277 PaintString (scale_buf);
278 }
279 }
280 else if (!(scale_pos % (pos/2)))
281 {
282 x = rcP.left + scale_pos -HFrom;
283 y = rcP.top-10;
284 MoveTo (x, y);
285 LineTo (x,y-7);
286
287 }
288 else if (!(scale_pos % (pos/10)))
289 {
290 Black();
291 x = rcP.left + scale_pos -HFrom;
292 y = rcP.top-10;
293 MoveTo (x, y);
294 LineTo (x,y-5);
295
296 }
297 }
298 }
299
300
301 Black();
302
303
304 }
305
306 /*________________________________(DOT_DrawYGrids)____________________
307
308 Purpose : Draw y-axis for DisplayHits, window1.
309
310 ____________________________________________________________________*/
DOT_DrawYGrids(RecT rupdate,RecT rcP,DOTVibDataPtr vdp,Int4 VFrom,Int4 HFrom,Int4 VTo,Int4 comp,Boolean GRID)311 static void DOT_DrawYGrids (RecT rupdate, RecT rcP, DOTVibDataPtr vdp, Int4 VFrom, Int4 HFrom, Int4 VTo, Int4 comp, Boolean GRID)
312 {
313 Int4 x, y, x2, offset=0;
314 Int4 scale_pos, pos, Vseq_pos;
315 Char scale_buf[15] = {""}; /*scale value*/
316 Int4 fh;
317 Boolean Decrement = FALSE;
318
319 offset=vdp->ystart;
320
321 /* draw the axis no matter how short the length */
322 /* if (vdp->curr_slen <50) */
323 /* return; */
324
325 pos = 100;
326
327 SelectFont(vdp->Fnt);
328 fh = FontHeight();
329
330 Black();
331 MoveTo (rcP.left-10,rcP.top);
332 LineTo (rcP.left-10,rcP.top+ VTo);
333
334
335 if (vdp->curr_slen - VFrom == VTo)
336 {
337 /* write the sequence length */
338 Red();
339 sprintf(scale_buf, "%d", vdp->ystop);
340 MoveTo (rcP.left-10 -(StringWidth(scale_buf)/2),rcP.top+ VTo +10 + (fh/2));
341 PaintString (scale_buf);
342 }
343
344 VTo += VFrom;
345
346 for (scale_pos = VFrom+1; scale_pos <= VTo+1; scale_pos++)
347 {
348 if (scale_pos == 1)
349 {
350 Black();
351 x = rcP.left-10;
352 y = rcP.top;
353 MoveTo (x, y);
354 LineTo (x-10,y);
355 Blue();
356 sprintf(scale_buf, "%d", offset);
357 MoveTo(rcP.left-25-StringWidth(scale_buf),y+fh-4);
358 PaintString (scale_buf);
359 }
360 else if (!(scale_pos % pos))
361 {
362 Vseq_pos = (!Decrement)?((scale_pos)*comp)+offset: offset - ((scale_pos)*comp);
363
364 x = MAX(rupdate.left, rcP.left);
365 x2 = MIN(rupdate.right, rcP.left+vdp->curr_qlen-HFrom);
366 y = rcP.top -VFrom + scale_pos;
367
368 /* draw vertical grid */
369 if ((scale_pos != 0) && (x<x2) && GRID)
370 {
371 LtGray();
372 Dotted();
373 MoveTo (x, y);
374 LineTo (x2,y);
375 }
376 /* add scale values */
377 Black();
378 Solid();
379 x = rcP.left -10;
380 MoveTo (x, y);
381 LineTo (x-10,y);
382 sprintf(scale_buf, "%d", Vseq_pos);
383 x = rcP.left -25 - StringWidth(scale_buf);
384 y = rcP.top-VFrom + scale_pos+ (fh/2);
385
386 if (y-fh > rcP.top)
387 {
388 Blue();
389 MoveTo(x,y);
390 PaintString (scale_buf);
391 }
392
393 }
394 else if (!(scale_pos % (pos/2)))
395 {
396 Black();
397 x = rcP.left - 10;
398 y = rcP.top - VFrom + scale_pos;
399 MoveTo (x, y);
400 LineTo (x-7,y);
401 }
402 else if (!(scale_pos % (pos/10)))
403 {
404 Black();
405 x = rcP.left - 10;
406 y = rcP.top - VFrom + scale_pos;
407 MoveTo (x, y);
408 LineTo (x-5,y);
409 }
410 }
411 Black();
412 }
413
414
415 /*_______________________________________________(DOT_UpdateLRBT)________________
416
417 Purpose : Computes Left, Right, Bottom and Top values for DisplayHits.
418
419 ____________________________________________________________________*/
DOT_UpdateLRBT(RecT r,RecT rcP,Int4Ptr Left,Int4Ptr Right,Int4Ptr Bottom,Int4Ptr Top)420 void DOT_UpdateLRBT (RecT r, RecT rcP, Int4Ptr Left, Int4Ptr Right, Int4Ptr Bottom, Int4Ptr Top)
421 {
422
423 if (r.left > rcP.left)
424 *Left = r.left;
425 else
426 *Left = rcP.left;
427
428 if (r.right < rcP.right)
429 *Right = r.right;
430 else
431 *Right = rcP.right;
432
433 if (r.bottom < rcP.bottom)
434 *Bottom = r.bottom;
435 else
436 *Bottom = rcP.bottom;
437
438 if (r.top > rcP.top)
439 *Top = r.top;
440 else
441 *Top = rcP.top;
442
443 return;
444 }
445 /*________________________________________(DOT_AddRectMargins)_____________
446
447 Purpose : Add horizontal and vertical margins to rect, window1.
448
449 ____________________________________________________________________*/
DOT_AddRectMargins(RectPtr r,DOTVibDataPtr vdp)450 static void DOT_AddRectMargins (RectPtr r, DOTVibDataPtr vdp)
451 {
452 r->left += vdp->HORZ_MARGIN;
453 r->top += vdp->VERT_MARGIN;
454
455 return;
456 }
457
458 /*____________________________________________(DOT_ChangeMainViewerCutoff)______
459
460 Purpose : Change cutoff function for threshold-ramp, window1.
461
462 ____________________________________________________________________*/
DOT_ChangeMainViewerCutoff(BaR b,GraphiC g,Int2 new,Int2 old)463 static void DOT_ChangeMainViewerCutoff (BaR b, GraphiC g, Int2 new, Int2 old)
464 {
465 DOTVibDataPtr vdp;
466 WindoW w, temport;
467 RecT rcP;
468
469 vdp = (DOTVibDataPtr) GetObjectExtra (b);
470
471 Select(vdp->panel);
472 ObjectRect(vdp->panel, &rcP);
473 InsetRect(&rcP,4,4);
474
475 w = (WindoW)ParentWindow(vdp->panel);
476 temport = SavePort(w);
477
478 vdp->sdp.TrampPos = new+20;
479
480 DOT_AddRectMargins(&rcP, vdp);
481 InvalRect (&rcP);
482 RestorePort (temport);
483 Update();
484
485 }
486
487 static PoinT curpnt;
488 static PoinT fstpnt;
489
490 /*________________________________________(DOT_RectOverlpRect)_____________
491
492 Purpose : Find overlapping region between two rects.
493
494 ____________________________________________________________________*/
DOT_RectOverlpRect(RectPtr r1,RectPtr r2)495 static Boolean DOT_RectOverlpRect (RectPtr r1, RectPtr r2)
496 {
497 if (r1->left <r2->left)
498 r1->left = r2->left;
499 if (r1->right >r2->right)
500 r1->right = r2->right;
501 if (r1->top < r2->top)
502 r1->top = r2->top;
503 if (r1->bottom > r2->bottom)
504 r1->bottom = r2->bottom;
505
506 return TRUE;
507 }
508
509 /*________________________________________(DOT_RectIntsRect)_____________
510
511 Purpose : Checks if selected rect is in selectable rect, window1.
512
513 ____________________________________________________________________*/
DOT_RectIntsRect(RectPtr r1,RectPtr r2)514 static Boolean DOT_RectIntsRect (RectPtr r1, RectPtr r2)
515 {
516
517 if (r1->top > r2->bottom || r1->bottom < r2->top || r1->left > r2->right || r1->right < r2->left)
518 return FALSE;
519 else
520 return TRUE;
521 }
522
523 /*________________________________________(DOT_LoopStop)_____________
524
525 Purpose : calculate stop value in score_array for threshold-ramp.
526
527 ____________________________________________________________________*/
DOT_LoopStop(DOTVibDataPtr vdp)528 static Int4 DOT_LoopStop (DOTVibDataPtr vdp)
529 {
530 Int4 stop;
531 Int4 pos;
532
533 pos=(Int4)ceil((double)(vdp->sdp.TrampPos*vdp->mip->unique)/100);
534
535 if (pos>=vdp->mip->unique)
536 return vdp->mip->index;
537 else
538 stop=vdp->mip->score_array[pos]+1;
539
540 return stop;
541 }
542
543
544 /*_______________________________________________(DOT_DisplayHits)_________
545
546 Purpose : Draw function for window1.
547
548 ____________________________________________________________________*/
549
DOT_DisplayHits(PaneL p)550 static void DOT_DisplayHits (PaneL p)
551 {
552
553 Int4 i, x, y, x2, y2;
554 RecT rcP, rupd, rcS, rcs, dr, rcR, rcP_off;
555 Int4 comp, stop;
556 DOTVibDataPtr vdp=NULL;
557 DOTMainDataPtr mip=NULL;
558 DOTSelDataPtr data;
559 WindoW w;
560 Int4 VFrom, HFrom, VTo, HTo;
561 Boolean query_on_minus = FALSE;
562 Boolean q_hitonplus, s_hitonplus;
563 Int4 q_start, s_start, length;
564 Int4 ycomp, xcomp;
565 DOTDiagPtr PNTR hitlist;
566 Int4 Left, Right, Bottom, Top;
567 Int2 dx, dy;
568 DOTAlnPtr PNTR alnL;
569 DOTAlnPtr aln;
570 Int4 q_left, q_right;
571 Int4 s_top, s_bottom;
572
573
574 w = (WindoW)ParentWindow(p);
575 rupd = updateRect;
576 ObjectRect(p, &rcP);
577 InsetRect(&rcP,4,4);
578 ClipRect(&rcP);
579
580 if (!(vdp = (DOTVibDataPtr)GetObjectExtra(w))) return;
581
582 VFrom = vdp->sdp.VFrom;
583 HFrom = vdp->sdp.HFrom;
584 VTo = (MIN (vdp->sdp.PgLen+VFrom, vdp->curr_slen-VFrom));
585 HTo = (MIN (vdp->sdp.PgWdth+HFrom, vdp->curr_qlen-HFrom));
586
587 comp = vdp->comp;
588
589 DOT_AddRectMargins (&rcP, vdp);
590 DOT_UpdateLRBT (rupd, rcP, &Left, &Right, &Bottom, &Top);
591 mip = vdp->mip;
592 data = (DOTSelDataPtr)vdp->data;
593 if (vdp->selectMode == dot_FEATVIEW)
594 {
595 if(data->selected)
596 {
597 DOT_VCrossHairs (rcP, vdp, VFrom, HFrom);
598 DOT_HCrossHairs (rcP, vdp, VFrom, HFrom);
599 }
600 }
601 else
602 {
603 if (data->selected)
604 {
605 rcs=data->rcS;
606
607 dx=HFrom-data->H_pos;
608 dy=VFrom-data->V_pos;
609
610 xcomp=vdp->originalcomp-comp;
611 ycomp=xcomp;
612
613 rcS.left=rcs.left-dx;
614 rcS.right=rcs.right-dx;
615 rcS.top=rcs.top-dy;
616 rcS.bottom=rcs.bottom-dy;
617
618 rcR.left = Left;
619 rcR.right = Right;
620 rcR.top = Top;
621 rcR.bottom = Bottom;
622
623 if (DOT_RectIntsRect(&rcS, &rcR))
624 {
625 rcP_off = rcP;
626 DOT_RectOverlpRect(&rcS, &rcR);
627 SectRect (&rcS, &rcP_off, &dr);
628 Yellow();
629 PaintRect (&dr);
630 Black();
631 }
632 }
633 }
634 DOT_DrawXGrids(rupd, rcP, vdp, VFrom, HFrom, HTo, comp, vdp->showGrid);
635 DOT_DrawYGrids(rupd, rcP, vdp, VFrom, HFrom, VTo, comp, vdp->showGrid);
636
637 if (vdp->showDotPlot && mip)
638 {
639 hitlist = mip->hitlist;
640 if (mip->unique<=1)
641 stop = mip->index;
642 else
643 stop = DOT_LoopStop (vdp);
644
645 if (vdp->strand1 == Seq_strand_minus)
646 query_on_minus = TRUE;
647
648 for (i = 0; i<stop ; i++)
649 {
650 length = hitlist[i]->length;
651
652 if (query_on_minus)
653 q_start = mip->q_stop - hitlist[i]->q_start;
654 else
655 q_start = hitlist[i]->q_start - mip->q_start;
656 s_start = hitlist[i]->s_start - mip->s_start;
657 q_start = ((int)q_start/comp)-HFrom;
658 s_start = ((int)s_start/comp)-VFrom;
659 length = (int)length/comp;
660
661 if (query_on_minus){
662 x = rcP.left + q_start;
663 x2 = x - length;
664 q_left = x2;
665 q_right = x;
666 }
667 else {
668 x = rcP.left + q_start;
669 x2 = x + length;
670 q_left = x;
671 q_right = x2;
672 }
673
674 y = rcP.top + s_start;
675 y2 = y + length;
676
677 if (y > Bottom || y2 < Top || q_left > Right || q_right < Left)
678 continue; /* outside of drawing Rgn */
679
680 if (query_on_minus){
681 if (q_left < rcP.left)
682 {
683 y2 = y2 - (rcP.left - q_left);
684 q_left = rcP.left;
685 }
686 }
687 else {
688 if (q_left < rcP.left) {
689 y = y - (rcP.left - q_left);
690 q_left = rcP.left;
691 }
692 }
693
694 if (y < rcP.top) {
695 q_left = q_left - (rcP.top - y);
696 y = rcP.top;
697 }
698
699 if (y < rcP.top)
700 {
701 q_left = q_left + (rcP.top-y);
702 y = rcP.top;
703 }
704
705 if (q_left < rcP.left)
706 {
707 y = y+(rcP.left-q_left);
708 q_left = rcP.left;
709 }
710
711 if (query_on_minus)
712 x2 = q_left;
713 else
714 x = q_left;
715
716 MoveTo(x, y);
717 LineTo(x2, y2);
718
719 }
720 }
721
722 if (vdp->showALIGN && vdp->alp) /* overlay Blast hits */
723 {
724 Red();
725 alnL = vdp->alp->Alnlist;
726 stop = vdp->alp->index;
727 for (i = 0; i<stop; i++)
728 {
729 aln = alnL[i];
730
731 q_start=ABS(vdp->xstart - aln->q_start);
732 s_start=ABS(vdp->ystart - aln->s_start);
733 q_start=q_start/comp - HFrom;
734 s_start=s_start/comp - VFrom;
735 length = ABS(aln->q_stop - aln->q_start)+1;
736 length = length/comp;
737
738 if (vdp->strand1==Seq_strand_minus){
739 q_hitonplus=FALSE;
740 x = rcP.left + q_start;
741 x2 = x - length;
742 q_left = x2;
743 q_right = x;
744 }
745 else{
746 q_hitonplus=TRUE;
747 x = rcP.left + q_start;
748 x2 = x + length;
749 q_left = x;
750 q_right = x2;
751 }
752
753 if (vdp->strand2==Seq_strand_minus){
754 s_hitonplus=FALSE;
755 y = rcP.top + s_start;
756 y2 = y - length;
757 s_top = y2;
758 s_bottom = y;
759 }
760 else {
761 s_hitonplus=TRUE;
762 y=rcP.top+s_start;
763 y2=y+length;
764 s_top = y;
765 s_bottom = y2;
766 }
767
768 if (q_left > Right || q_right < Left ||
769 s_top > Bottom || s_bottom < Top)
770 continue;
771
772 if (q_hitonplus==s_hitonplus){
773 if (x<rcP.left)
774 {
775 y=y+(rcP.left-x);
776 x=rcP.left;
777 }
778 if (y < rcP.top)
779 {
780 x = x+(rcP.top-y);
781 y=rcP.top;
782 }
783 }
784 else{
785 if (q_hitonplus){ /* s is minus */
786 if (x< rcP.left)
787 {
788 y = y-(rcP.left-x);
789 x = rcP.left;
790 }
791 }
792 else { /* q is on minus strand */
793 if (x2< rcP.left)
794 {
795 y2=y2-(rcP.left-x2);
796 x2 = rcP.left;
797 }
798 }
799 if (s_hitonplus){ /* q is minus */
800 if (y < rcP.top)
801 {
802 x = x-(rcP.top-y);
803 y=rcP.top;
804 }
805 }
806 else {/* s is on minus strand */
807 if (y2 < rcP.top)
808 {
809 x2=x2-(rcP.top-y2);
810 y2=rcP.top;
811 }
812 }
813 }
814 DOT_SetColor(NULL, aln->class, TRUE);
815 MoveTo(x, y);
816 LineTo(x2, y2);
817 }
818 Black();
819 }
820
821 ResetClip();
822 return;
823 }
824
825
826 /*________________________________________(DOT_SetCurrSeqlen)_____________
827
828
829 Purpose : Update displayed seq-length after reduce/enlarge functions.
830
831 ____________________________________________________________________*/
832 /*set the current size of the sequence display */
DOT_SetCurrSeqlen(DOTVibDataPtr vdp)833 static void DOT_SetCurrSeqlen (DOTVibDataPtr vdp)
834 {
835 Int4 comp;
836
837 comp = vdp->comp;
838
839 vdp->curr_slen = (vdp->ylen)/comp;
840 vdp->curr_qlen = (vdp->xlen)/comp;
841
842 }
843
844
845 /*________________________________________(DOT_VScrlUpdate)_____________
846
847 Purpose : Update function for vertical scroll proc, window1.
848
849 ____________________________________________________________________*/
850
DOT_VScrlUpdate(DOTVibDataPtr vdp,BaR vsb,Int4 VCurPos)851 static void DOT_VScrlUpdate(DOTVibDataPtr vdp, BaR vsb, Int4 VCurPos)
852 {
853
854 VCurPos = VCurPos*vdp->sdp.UnitY;
855
856 /*set cursor position to new Units */
857 VCurPos = VCurPos/vdp->sdp.UnitY;
858
859 if (VCurPos<0) VCurPos=0;
860
861 if (VCurPos >= vdp->sdp.YScrlMax)
862 vdp->sdp.YScrlPos = vdp->sdp.YScrlMax;
863 else
864 vdp->sdp.YScrlPos = VCurPos;
865
866 vdp->sdp.VFrom=vdp->sdp.YScrlPos*vdp->sdp.UnitY;
867
868 /*update scroll*/
869 CorrectBarMax(vsb, vdp->sdp.YScrlMax);
870 CorrectBarValue(vsb, vdp->sdp.YScrlPos);
871 CorrectBarPage(vsb, vdp->sdp.YScrlPage, vdp->sdp.YScrlPage);
872
873 }
874
875
876 /*________________________________________(DOT_HScrlUpdate)_____________
877
878 Purpose : Update function for horizontal scroll proc.
879
880 ____________________________________________________________________*/
881
DOT_HScrlUpdate(DOTVibDataPtr vdp,BaR hsb,Int4 HCurPos)882 static void DOT_HScrlUpdate(DOTVibDataPtr vdp, BaR hsb, Int4 HCurPos)
883 {
884 HCurPos = HCurPos*vdp->sdp.UnitX;
885
886 /*set cursor position to new Units */
887 HCurPos = HCurPos/vdp->sdp.UnitX;
888
889 if (HCurPos<0) HCurPos=0;
890
891 if (HCurPos >= vdp->sdp.XScrlMax)
892 vdp->sdp.XScrlPos = vdp->sdp.XScrlMax;
893 else
894 vdp->sdp.XScrlPos = HCurPos;
895
896 vdp->sdp.HFrom=vdp->sdp.XScrlPos*vdp->sdp.UnitX;
897
898 /*update scroll*/
899 CorrectBarMax(hsb, vdp->sdp.XScrlMax);
900 CorrectBarValue(hsb, vdp->sdp.XScrlPos);
901 CorrectBarPage(hsb, vdp->sdp.XScrlPage, vdp->sdp.XScrlPage);
902
903 }
904
905
906
907 /*________________________________________________(DOT_VscrlProc)_____________
908
909 Purpose : Vertical Scroll proc, window1.
910
911 ____________________________________________________________________*/
DOT_VscrlProc(BaR vsb,SlatE s,Int2 newval,Int2 oldval)912 static void DOT_VscrlProc (BaR vsb, SlatE s, Int2 newval, Int2 oldval)
913 {
914 WindoW temport, w;
915 DOTVibDataPtr vdp;
916 RecT rcP;
917 Int2 dy, offset;
918 Int2 visLines, vmargin, hmargin;
919 PaneL p;
920
921
922 w = (WindoW)ParentWindow((PaneL)s);
923 vdp = (DOTVibDataPtr)GetObjectExtra (w);
924 p = vdp->panel;
925
926 offset=vdp->sdp.HFrom;
927 vmargin=vdp->VERT_MARGIN;
928 hmargin=vdp->HORZ_MARGIN;
929
930 temport = SavePort (w);
931
932 Select(p);
933 ObjectRect(p, &rcP);
934 InsetRect(&rcP, 4, 4);
935 ClipRect(&rcP);
936
937 vdp->sdp.YScrlPos = newval;
938 visLines = vdp->sdp.YScrlPage;
939 vdp->sdp.VFrom=newval*vdp->sdp.UnitY;
940
941 rcP.right = (MIN (rcP.left+hmargin+vdp->curr_qlen-offset, rcP.right));
942 rcP.top += vmargin;
943
944 dy = newval- oldval;
945 if (ABS(dy) < vdp->sdp.YScrlPage)
946 {
947 ScrollRect(&rcP, 0, (Int2)((-dy)*vdp->sdp.UnitY));
948 }
949 else
950 {
951 InsetRect(&rcP, -1, -1);
952 InvalRect(&rcP);
953 }
954 ResetClip();
955 RestorePort(temport);
956 /* Update(); */
957
958 }
959
960
961
962 /*________________________________________________(DOT_HscrlProc)_____________
963
964 Purpose : Horizontal scroll proc, window1.
965
966 ____________________________________________________________________*/
DOT_HscrlProc(BaR Hsb,SlatE s,Int2 newval,Int2 oldval)967 static void DOT_HscrlProc (BaR Hsb, SlatE s, Int2 newval, Int2 oldval)
968 {
969 WindoW temport, w;
970 DOTVibDataPtr vdp;
971 RecT rcP;
972 Int2 dx, visLines, offset, hmargin, vmargin;
973
974
975 w = (WindoW)ParentWindow((PaneL)s);
976 vdp = (DOTVibDataPtr)GetObjectExtra (w);
977
978 temport = SavePort (w);
979 Select(vdp->panel);
980 ObjectRect(vdp->panel, &rcP);
981 InsetRect(&rcP, 4, 4);
982 ClipRect (&rcP);
983
984 offset=vdp->sdp.VFrom;
985 hmargin=vdp->HORZ_MARGIN;
986 vmargin=vdp->VERT_MARGIN;
987
988 rcP.bottom = (MIN (rcP.top+vmargin+vdp->curr_slen-offset, rcP.bottom));
989 rcP.left += hmargin;
990
991 vdp->sdp.XScrlPos = newval;
992 visLines = vdp->sdp.XScrlPage;
993 vdp->sdp.HFrom=newval*vdp->sdp.UnitX;
994
995 dx = newval - oldval;
996
997 if (ABS(dx) < vdp->sdp.XScrlPage)
998 {
999 ScrollRect(&rcP, (Int2)((-dx)*vdp->sdp.UnitX) , 0);
1000 }
1001 else
1002 {
1003 InsetRect(&rcP, -1, -1);
1004 InvalRect(&rcP);
1005 }
1006
1007 ResetClip();
1008 RestorePort(temport);
1009 /* Update(); */
1010
1011 }
1012
1013
1014 /*________________________________________(DOT_UpdateMainPanel)_____________
1015
1016 Purpose : Update selection for window1.
1017
1018 ____________________________________________________________________*/
1019
DOT_UpdateMainPanel(DOTVibDataPtr vdp,Boolean update_all)1020 static void DOT_UpdateMainPanel(DOTVibDataPtr vdp, Boolean update_all)
1021 {
1022 WindoW temport;
1023 RecT rc;
1024 DOTSelDataPtr data;
1025 Int4 dx, dy;
1026
1027 data=(DOTSelDataPtr)vdp->data;
1028
1029 temport = SavePort((WindoW)ParentWindow(vdp->panel));
1030 Select(vdp->panel);
1031 ObjectRect(vdp->panel, &rc);
1032 ClipRect(&rc);
1033
1034 if (!update_all)
1035 {
1036 if (data->rm_lastselected)
1037 {
1038 InsetRect(&data->old_rcS, -1, -1);
1039 InvalRect(&data->old_rcS);
1040 data->rm_lastselected=FALSE;
1041 }
1042 dx=data->H_pos-vdp->sdp.HFrom;
1043 dy=data->V_pos-vdp->sdp.VFrom;
1044 rc.left=data->rcS.left-dx;
1045 rc.right=data->rcS.right-dx;
1046 rc.top=data->rcS.top-dy;
1047 rc.bottom=data->rcS.bottom-dy;
1048 InsetRect(&rc, -1, -1);
1049 InvalRect (&rc);
1050 }
1051 else
1052 {
1053 InsetRect(&rc, -1, -1);
1054 InvalRect(&rc);
1055 }
1056
1057 ResetClip();
1058 RestorePort(temport);
1059 Update();
1060
1061 }
1062
1063
1064 /*______________________________________(DOT_VScroll)___________
1065
1066 Purpose : Correct vertical scroll bar values, window1.
1067
1068 ____________________________________________________________________*/
DOT_VScroll(DOTVibDataPtr vdp,BaR vsb)1069 static void DOT_VScroll (DOTVibDataPtr vdp, BaR vsb)
1070 {
1071
1072 CorrectBarMax(vsb,vdp->sdp.YScrlMax);
1073 CorrectBarValue(vsb,vdp->sdp.YScrlPos);
1074 CorrectBarPage(vsb, vdp->sdp.YScrlPage, vdp->sdp.YScrlPage);
1075
1076 }
1077 /*______________________________________(DOT_HScroll)___________
1078
1079 Purpose : Correct horizontal scroll bar values, window1.
1080
1081 ____________________________________________________________________*/
DOT_HScroll(DOTVibDataPtr vdp,BaR hsb)1082 static void DOT_HScroll (DOTVibDataPtr vdp, BaR hsb)
1083 {
1084
1085 CorrectBarMax(hsb,vdp->sdp.XScrlMax);
1086 CorrectBarValue(hsb,vdp->sdp.XScrlPos);
1087 CorrectBarPage(hsb,vdp->sdp.XScrlPage, vdp->sdp.XScrlPage);
1088
1089 }
1090 /*________________________________________(DOT_ComputePanelSize)_____________
1091
1092 Purpose : Calculate panel size for scrolling functions, window1.
1093
1094 ____________________________________________________________________*/
DOT_ComputePanelSize(RecT rcP,DOTVibDataPtr vdp,Int4Ptr PgWdth,Int4Ptr PgLen)1095 static void DOT_ComputePanelSize (RecT rcP, DOTVibDataPtr vdp, Int4Ptr PgWdth, Int4Ptr PgLen)
1096 {
1097
1098 InsetRect(&rcP, 4, 4);
1099 rcP.left += vdp->HORZ_MARGIN;
1100 rcP.top += vdp->VERT_MARGIN;
1101
1102 *PgWdth =rcP.right-rcP.left;
1103 *PgLen =rcP.bottom-rcP.top;
1104
1105 }
1106
1107 /*________________________________________(DOT_SetScrlVals)_____________
1108
1109 Purpose : Set scroll values for window1.
1110
1111 ____________________________________________________________________*/
DOT_SetScrlVals(DOTVibDataPtr vdp)1112 static void DOT_SetScrlVals (DOTVibDataPtr vdp)
1113 {
1114 /* Int4 scrollfctr = 40; */
1115
1116 /* vdp->sdp.UnitY = vdp->sdp.PgLen/scrollfctr; */
1117 vdp->sdp.UnitY = 16; /* constant value*/
1118 vdp->sdp.TotUnitsY = vdp->curr_slen/vdp->sdp.UnitY;
1119 vdp->sdp.YScrlPage = vdp->sdp.PgLen/vdp->sdp.UnitY;
1120 vdp->sdp.YScrlMax = vdp->sdp.TotUnitsY-(vdp->sdp.YScrlPage - vdp->VERT_MARGIN/vdp->sdp.UnitY);
1121
1122 /* vdp->sdp.UnitX = vdp->sdp.PgWdth/scrollfctr; */
1123 vdp->sdp.UnitX = 16;/* constant value*/
1124 vdp->sdp.TotUnitsX = vdp->curr_qlen/vdp->sdp.UnitY;
1125 vdp->sdp.XScrlPage = vdp->sdp.PgWdth/vdp->sdp.UnitX;
1126 vdp->sdp.XScrlMax = vdp->sdp.TotUnitsX-(vdp->sdp.XScrlPage - vdp->HORZ_MARGIN/vdp->sdp.UnitX);
1127
1128 /* image is smaller than page size */
1129 if ((vdp->sdp.YScrlPage + vdp->HORZ_MARGIN/vdp->sdp.UnitX) > vdp->sdp.TotUnitsY)
1130 {
1131 vdp->sdp.YScrlMax = 0;
1132 vdp->sdp.YScrlPage = 0;
1133 vdp->sdp.YScrlPos = 0;
1134 }
1135 if (vdp->sdp.XScrlPage>vdp->sdp.TotUnitsX)
1136 {
1137 vdp->sdp.XScrlMax = 0;
1138 vdp->sdp.XScrlPage = 0;
1139 vdp->sdp.XScrlPos = 0;
1140 }
1141
1142 }
1143
1144 /*______________________________________(DOT_SetUpWin)___________
1145
1146 Purpose : Scrolling info setup function for window1.
1147
1148 ____________________________________________________________________*/
DOT_SetUpWin(WindoW w,PaneL p,DOTVibDataPtr vdp)1149 static void DOT_SetUpWin(WindoW w, PaneL p, DOTVibDataPtr vdp)
1150 {
1151
1152 Int4 height, width, viewersize, len;
1153 Int4 gap, lmargin, vsbWidth, hsbHeight;
1154 BaR vsb, hsb;
1155 WindoW temport;
1156 RecT rcP, rcW, rcHsb, rcVsb;
1157
1158
1159
1160 temport = SavePort (w);
1161 Select(p);
1162 ObjectRect(p, &rcP);
1163
1164 /* Reset Panel Parameters */
1165 ObjectRect(w, &rcW);
1166 width = rcW.right-rcW.left;
1167 height = rcW.bottom-rcW.top;
1168 vsb = GetSlateVScrollBar ((SlatE) p);
1169 hsb = GetSlateHScrollBar ((SlatE) p);
1170
1171 GetPosition(vsb,&rcVsb);
1172 GetPosition(hsb,&rcHsb);
1173
1174 gap=2;
1175 lmargin=10;
1176 vsbWidth=rcVsb.right-rcVsb.left;
1177 hsbHeight=rcHsb.bottom-rcHsb.top;
1178
1179 rcP.right = width - vsbWidth - gap;
1180 rcP.bottom = height - hsbHeight - gap;
1181 rcP.left=lmargin;
1182
1183 SetPosition (vdp->panel, &rcP);
1184 AdjustPrnt (vdp->panel, &rcP, FALSE);
1185
1186 viewersize=MIN(rcP.right-rcP.left,rcP.bottom-rcP.top)-vdp->HORZ_MARGIN;
1187 len=MAX(vdp->xlen, vdp->ylen);
1188 vdp->comp=DOT_Compression(len, viewersize);
1189 vdp->originalcomp=vdp->comp;
1190
1191
1192 vdp->sdp.YScrlPos = 0;
1193 vdp->sdp.XScrlPos = 0;
1194
1195 DOT_SetCurrSeqlen (vdp);
1196 DOT_ComputePanelSize(rcP, vdp, &(vdp->sdp.PgWdth), &(vdp->sdp.PgLen));
1197 DOT_SetScrlVals(vdp);
1198
1199 DOT_VScroll (vdp, vsb);
1200 DOT_HScroll (vdp, hsb);
1201
1202 RestorePort(temport);
1203
1204 }
1205
1206
1207
1208
1209 /*________________________________________(DOT_CloseSequenceWindow)_____________
1210
1211 Purpose : Close function for Sequence Window.
1212
1213 ____________________________________________________________________*/
DOT_CloseSequenceWindow(ButtoN b)1214 static void DOT_CloseSequenceWindow (ButtoN b)
1215 {
1216
1217 DOTVibDataPtr vdp2, vdp;
1218 DOTSelDataPtr data;
1219
1220 vdp2=(DOTVibDataPtr)GetObjectExtra(ParentWindow(b));
1221
1222 data=(DOTSelDataPtr)vdp2->data;
1223 data->selected=FALSE;
1224 vdp=data->vdp;
1225 SetTitle(vdp->Infopanel, vdp->iInfo);
1226
1227 DOT_UpdateMainPanel(vdp, FALSE);
1228
1229 vdp2->sv->pict1=DeletePicture(vdp2->sv->pict1);
1230 vdp2->sv->pict2=DeletePicture(vdp2->sv->pict2);
1231
1232 if (vdp2->sv->salp)
1233 MemFree(vdp2->sv->salp);
1234 if (vdp2->sv) MemFree(vdp2->sv);
1235 if (vdp2->mip){
1236 DOT_FreeMainInfo(vdp2->mip);
1237 if (vdp2->mip) MemFree(vdp2->mip);
1238 }
1239 if (vdp2) MemFree(vdp2);
1240 Remove (vdp->ChildWin);
1241 vdp->ChildWin=NULL;
1242
1243 prev_primID = 0;
1244 }
1245
1246
1247
1248 /*_____________________________________________________________________
1249
1250 Purpose : Remove feature linked list
1251
1252 ____________________________________________________________________*/
DOT_FreeFeatPointers(DOTRowPtr drp)1253 static void DOT_FreeFeatPointers(DOTRowPtr drp)
1254 {
1255 DOTFeatPtr dfp_temp=NULL, dfp=NULL;
1256
1257 dfp=drp->dfp;
1258 if (dfp == NULL) return;
1259 dfp_temp=dfp;
1260 dfp=dfp->next;
1261 while(dfp != NULL)
1262 {
1263 dfp_temp=MemFree(dfp_temp);
1264 dfp_temp = dfp;
1265 dfp = dfp->next;
1266 }
1267 if (dfp_temp!=NULL) MemFree(dfp_temp);
1268
1269 }
1270
1271 /*________________________________________(DOT_CloseFeatWindow)_____________
1272
1273 Purpose : Close function for Feature Window.
1274
1275 ____________________________________________________________________*/
DOT_CloseFeatWindow(IteM i)1276 static void DOT_CloseFeatWindow (IteM i)
1277 {
1278 DOTFeatListPtr flp;
1279 DOTSelDataPtr data;
1280
1281
1282 flp=(DOTFeatListPtr)GetObjectExtra(ParentWindow(i));
1283 if (!flp) return;
1284
1285 data=(DOTSelDataPtr)flp->data;
1286 data->selected=FALSE;
1287 DOT_UpdateMainPanel(data->vdp, TRUE);
1288
1289 flp->segQuery=DeletePicture(flp->segQuery);
1290 flp->segSubject=DeletePicture(flp->segSubject);
1291 DOT_FreeFeatPointers(flp->query_drp);
1292 DOT_FreeFeatPointers(flp->subject_drp);
1293 if (flp->featindex) flp->featindex=MemFree(flp->featindex);
1294 if (flp->query_drp) flp->query_drp=MemFree(flp->query_drp);
1295 if (flp->subject_drp)flp->subject_drp=MemFree(flp->subject_drp);
1296 if (flp->FeatWin) flp->FeatWin=Remove (flp->FeatWin);
1297 data->vdp->ChildWin=NULL;
1298 if (flp) flp=MemFree(flp);
1299
1300 }
1301
1302 /*_____________________________________________________________________
1303
1304 Purpose : Remove 'sequence' or 'feature' window
1305
1306 ____________________________________________________________________*/
1307
DOT_ClearLastWindow(WindoW w,Boolean is_sequence)1308 static WindoW DOT_ClearLastWindow(WindoW w, Boolean is_sequence)
1309 {
1310 DOTVibDataPtr vdp;
1311 DOTFeatListPtr flp;
1312 DOTSelDataPtr data;
1313
1314 if (!w) return w;
1315
1316 if (is_sequence)
1317 {
1318 vdp=(DOTVibDataPtr)GetObjectExtra(w);
1319 if (!vdp) return w;
1320
1321 data=(DOTSelDataPtr)vdp->data;
1322 data->selected=FALSE;
1323
1324 if(vdp->sv->v1) DeleteViewer(vdp->sv->v1);
1325 if(vdp->sv->v2) DeleteViewer(vdp->sv->v2);
1326 if(vdp->sv->pict1) DeletePicture(vdp->sv->pict1);
1327 if(vdp->sv->pict2) DeletePicture(vdp->sv->pict2);
1328 vdp->sv=MemFree(vdp->sv);
1329
1330 /* if (vdp->mip) */
1331 /* { */
1332 /* DOT_FreeMainInfo(vdp->mip); */
1333 /* MemFree(vdp->mip); */
1334 /* } */
1335
1336 }
1337 else
1338 {
1339 flp=(DOTFeatListPtr)GetObjectExtra(w);
1340 if (!flp) return w;
1341
1342 data=(DOTSelDataPtr)flp->data;
1343 data->selected=FALSE;
1344
1345 DeletePicture(flp->segQuery);
1346 DeletePicture(flp->segSubject);
1347 /* DOT_FreeFeatPointers(flp->query_drp); */
1348 /* DOT_FreeFeatPointers(flp->subject_drp); */
1349 /* MemFree(flp->query_drp); */
1350 /* MemFree(flp->subject_drp); */
1351 MemFree(flp);
1352 }
1353
1354 DOT_UpdateMainPanel(data->vdp, TRUE);
1355
1356 w=Remove(w);
1357
1358 return NULL;
1359
1360 }
1361 /*_____________________________________________________________________
1362
1363 Purpose : New set of function to show features on dotviewer
1364
1365 ____________________________________________________________________*/
1366
DOT_ModeProc(ChoicE i)1367 static void DOT_ModeProc(ChoicE i)
1368 {
1369 WindoW w, temport;
1370 RecT rcP;
1371 DOTVibDataPtr vdp;
1372 DOTSelDataPtr data;
1373
1374
1375 w = (WindoW)ParentWindow(i);
1376 temport=SavePort(w);
1377 vdp = (DOTVibDataPtr)GetObjectExtra (w);
1378 if (!vdp) return;
1379
1380 if (vdp->ChildWin !=NULL)
1381 {
1382 if (vdp->selectMode == 1)
1383 vdp->ChildWin=DOT_ClearLastWindow(vdp->ChildWin, TRUE);
1384 else
1385 vdp->ChildWin=DOT_ClearLastWindow(vdp->ChildWin, FALSE);
1386 }
1387
1388 vdp->selectMode = GetValue(i);
1389 data=(DOTSelDataPtr)vdp->data;
1390 data->selected=FALSE;
1391 ObjectRect(vdp->panel, &rcP);
1392 Select(vdp->panel);
1393 InvalRect(&rcP);
1394 RestorePort(temport);
1395 Update();
1396
1397 }
1398
DOT_VCrossHairs(RecT rcP,DOTVibDataPtr vdp,Int4 VFrom,Int4 HFrom)1399 static void DOT_VCrossHairs (RecT rcP, DOTVibDataPtr vdp, Int4 VFrom,Int4 HFrom)
1400 {
1401 Int4 y, y2, x, x2;
1402 Int4 cursor_size =15;
1403 /* SelectPtr c_data; */
1404
1405 /* c_data = cip->data; */
1406
1407 /* vertical line */
1408 y = rcP.top-vdp->VERT_MARGIN+20;
1409 y2= rcP.bottom-1/* MIN(rcP.bottom - 1 , VTo) */;
1410 x2 = x = curpnt.x/* +HFrom */;
1411 /* x2 = x = rcP.left +c_h.x -cip->HORZ_MARGIN - cursor_size; */
1412 if (x>=rcP.left)
1413 {
1414 Magenta();
1415 MoveTo (x, y);
1416 LineTo (x2, y2);
1417
1418 }
1419 Black();
1420 return;
1421
1422 }
1423
DOT_HCrossHairs(RecT rcP,DOTVibDataPtr vdp,Int4 VFrom,Int4 HFrom)1424 static void DOT_HCrossHairs (RecT rcP, DOTVibDataPtr vdp, Int4 VFrom,Int4 HFrom)
1425 {
1426 Int4 y, y2, x, x2;
1427 Int4 cursor_size = 15;
1428 /* SelectPtr c_data; */
1429
1430 /* data = vdp->data; */
1431
1432 /* horizontal line */
1433 y2 = y = curpnt.y /* + VFrom */;
1434 /* y2 = y = rcP.top + c_h.y -cip->VERT_MARGIN - cursor_size; */
1435 x = rcP.left-vdp->HORZ_MARGIN+20;
1436 x2 = rcP.right-1/* MIN(rcP.right -1, HTo) */;
1437 if (y>=rcP.top)
1438 {
1439 Magenta ();
1440 MoveTo(x, y);
1441 LineTo (x2, y2);
1442 }
1443 Black();
1444 return;
1445
1446 }
1447
1448
DOT_MoveCrossHairs(RecT rcP,DOTVibDataPtr vdp)1449 static void DOT_MoveCrossHairs (RecT rcP, DOTVibDataPtr vdp)
1450 {
1451 Int4 y, y2, x, x2;
1452 Int4 cursor_size = 15;
1453 DOTSelDataPtr data;
1454
1455 SelectFont(vdp->Fnt);
1456
1457 data = (DOTSelDataPtr) vdp->data;
1458 DOT_AddRectMargins(&rcP, vdp);
1459
1460 /* vertical line */
1461 y = rcP.top-vdp->VERT_MARGIN+20;
1462 y2= rcP.bottom-1;
1463 x2 = x = curpnt.x;
1464 if (x>rcP.left)
1465 {
1466 MoveTo (x, y);
1467 LineTo (x2, y2);
1468 }
1469
1470 /* horizontal line */
1471 y2 = y = curpnt.y;
1472 x = rcP.left-vdp->HORZ_MARGIN +20;
1473 x2 = rcP.right-1;
1474 if (y>rcP.top)
1475 {
1476 MoveTo(x, y);
1477 LineTo (x2, y2);
1478
1479 }
1480
1481 Black();
1482
1483
1484 return;
1485
1486 }
1487
1488
DOT_SelectLineProc(PaneL p)1489 static void DOT_SelectLineProc (PaneL p)
1490
1491 {
1492 RecT rcP;
1493 DOTVibDataPtr vdp;
1494
1495 vdp = (DOTVibDataPtr) GetObjectExtra (ParentWindow(p));
1496 Dotted ();
1497 ObjectRect (p, &rcP);
1498 InsetRect (&rcP, 4, 4);
1499 DOT_MoveCrossHairs (rcP, vdp);
1500 }
1501
1502
1503 /*________________________________________(DOT_SelectFrameProc)_____________
1504
1505 Purpose : select frame for click and drag functions of window1.
1506
1507 ____________________________________________________________________*/
DOT_SelectFrameProc(PaneL p)1508 static void DOT_SelectFrameProc (PaneL p)
1509
1510 {
1511 RecT dr;
1512 RecT or;
1513 RecT r;
1514
1515 Dotted ();
1516 ObjectRect (p, &or);
1517 InsetRect (&or, 2, 2);
1518 LoadRect (&r, fstpnt.x, fstpnt.y, curpnt.x, curpnt.y);
1519 SectRect (&r, &or, &dr);
1520 FrameRect (&dr);
1521
1522 }
1523
1524 /*________________________________________(DOT_DrawXAxis)_____________
1525
1526 Purpose : Draw x-axis function for viewer1, window2.
1527
1528 ____________________________________________________________________*/
DOT_DrawXAxis(SegmenT seg2,RecT r,Int4 height,Int4 xstart,Int4 xstop,Int4 scale,SeqIdPtr sip)1529 void DOT_DrawXAxis(SegmenT seg2, RecT r, Int4 height, Int4 xstart,Int4 xstop, Int4 scale, SeqIdPtr sip)
1530 {
1531 Int4 pos, xlen, x, y, scale_pos, i, j, bigtick, midtick, smalltick;
1532 Char scale_buf[15] = {""}, title[50]={""}; /*scale value*/
1533 Boolean Decrement=FALSE;
1534
1535
1536 if (xstart>xstop)
1537 Decrement=TRUE;
1538
1539 if (scale==0)
1540 scale=1;
1541
1542 pos=100*scale;
1543 bigtick=10*scale;
1544 midtick=7*scale;
1545 smalltick=5*scale;
1546
1547
1548 xlen=ABS(xstop-xstart);
1549
1550 /* axis label */
1551 /* SeqIdWrite(sip, title ,PRINTID_TEXTID_ACCESSION, 41); */
1552 /* AddLabel(seg2,r.left+xlen/2, height+25, title, SMALL_TEXT, 0, UPPER_CENTER, 0); */
1553
1554 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1555 AddLine(seg2, r.left, height+10, r.left+xlen, height+10, FALSE,0);
1556 /* AddLine(seg2, r.left, height-ylen, r.left+xlen, height-ylen, FALSE, -1); */
1557 sprintf(scale_buf, "%d", xstop);
1558 AddAttribute(seg2, COLOR_ATT, RED_COLOR, 0,0,0,0);
1559 AddLabel(seg2, r.left+xlen+10*scale, height+5, scale_buf, SMALL_TEXT, 0, MIDDLE_RIGHT, 0);
1560
1561 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1562 if (!Decrement)
1563 {
1564 for (scale_pos = xstart, i=0; scale_pos <= xstop; scale_pos++, i++)
1565 {
1566
1567 if (!(scale_pos % pos))
1568 {
1569 x = r.left + i;
1570 y = height+10;
1571 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1572 AddLine(seg2, x, y, x, y+bigtick, FALSE,-1);
1573 sprintf(scale_buf, "%d", scale_pos);
1574 AddAttribute(seg2, COLOR_ATT, BLUE_COLOR, 0,0,0,0);
1575 AddLabel(seg2, x, y+15*scale, scale_buf, SMALL_TEXT, 0, UPPER_CENTER, 0);
1576
1577 }
1578 else if (!(scale_pos % (pos/2)))
1579 {
1580 x = r.left + i;
1581 y = height+10;
1582 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1583 AddLine(seg2, x, y, x, y+midtick, FALSE,0);
1584
1585 }
1586 else if (!(scale_pos % (pos/10)))
1587 {
1588 x = r.left + i;
1589 y = height+10;
1590 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1591 AddLine(seg2, x, y, x, y+smalltick, FALSE,0);
1592 }
1593 }
1594 }
1595 else
1596 {
1597 for (scale_pos = xstop, i=0, j=xstart; scale_pos <= xstart; scale_pos++, i++, j--)
1598 {
1599
1600 if (!(scale_pos % pos))
1601 {
1602 x = r.left + i;
1603 y = height+10;
1604 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1605 AddLine(seg2, x, y, x, y+bigtick, FALSE,0);
1606 sprintf(scale_buf, "%d", j);
1607 AddAttribute(seg2, COLOR_ATT, BLUE_COLOR, 0,0,0,0);
1608 AddLabel(seg2, x, y+15*scale, scale_buf, SMALL_TEXT, 0, UPPER_CENTER, 0);
1609
1610 }
1611 else if (!(scale_pos % (pos/2)))
1612 {
1613 x = r.left + i;
1614 y = height+10;
1615 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1616 AddLine(seg2, x, y, x, y+midtick, FALSE,0);
1617
1618 }
1619 else if (!(scale_pos % (pos/10)))
1620 {
1621 x = r.left + i;
1622 y = height+10;
1623 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1624 AddLine(seg2, x, y, x, y+smalltick, FALSE,0);
1625 }
1626 }
1627 }
1628
1629 }
1630
1631
1632 /*________________________________________(DOT_DrawYAxis)_____________
1633
1634
1635 Purpose : Draw y-axis function for viewer1, window2.
1636
1637 ____________________________________________________________________*/
DOT_DrawYAxis(SegmenT seg2,RecT r,Int4 height,Int4 ystart,Int4 ystop,Int4 scale,Int4 Fh,SeqIdPtr sip)1638 void DOT_DrawYAxis(SegmenT seg2, RecT r, Int4 height, Int4 ystart, Int4 ystop, Int4 scale, Int4 Fh, SeqIdPtr sip)
1639 {
1640 Int4 smalltick, midtick, bigtick;
1641 Int4 pos, ylen, x, y, scale_pos, i, j, Fh_2,Fh_4;
1642 Char scale_buf[15] = {""}, title[50]={""}; /*scale value*/
1643 Boolean Decrement = FALSE;
1644
1645
1646 if (ystart>ystop)
1647 Decrement=TRUE;
1648
1649 if (scale==0)
1650 scale=1;
1651
1652 pos=100*scale;
1653 smalltick=5*scale;
1654 midtick=7*scale;
1655 bigtick=10*scale;
1656
1657 Fh_2=Fh/2;
1658 Fh_4=Fh/4;
1659
1660
1661 ylen=ABS(ystop-ystart);
1662
1663 /* SeqIdWrite(sip, title ,PRINTID_TEXTID_ACCESSION, 41); */
1664 /* AddLabel(seg2, height - ylen/2, r.left - 20, title, SMALL_TEXT, 0, MIDDLE_CENTER, 0); */
1665
1666 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1667 AddLine(seg2, r.left-10, height, r.left-10, height-ylen, FALSE, 0);
1668
1669 sprintf(scale_buf, "%d", ystop);
1670 AddAttribute(seg2, COLOR_ATT, RED_COLOR, 0,0,0,0);
1671 AddLabel(seg2, r.left-10, height-ylen-10*scale, scale_buf, SMALL_TEXT, 0, MIDDLE_CENTER, 0);
1672
1673
1674 if (!Decrement)
1675 {
1676 for (scale_pos = ystart, i=0; scale_pos <= ystop; scale_pos++, i++)
1677 {
1678 if (!(scale_pos % pos))
1679 {
1680 x = r.left-10;
1681 y = height-i/* +VFrom */;
1682 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1683 AddLine(seg2, x, y, x-bigtick, y, FALSE, 0);
1684
1685 sprintf(scale_buf, "%d", scale_pos);
1686 y = y-Fh_2;
1687 AddAttribute(seg2, COLOR_ATT, BLUE_COLOR, 0,0,0,0);
1688 AddLabel(seg2, x-15*scale, y, scale_buf, SMALL_TEXT, 0, MIDDLE_LEFT, 0);
1689
1690 }
1691 else if (!(scale_pos % (pos/2)))
1692 {
1693 x = r.left-10;
1694 y = height-i/* +VFrom */;
1695 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1696 AddLine(seg2, x, y, x-midtick, y, FALSE,0);
1697
1698 }
1699 else if (!(scale_pos % (pos/10)))
1700 {
1701 x = r.left-10;
1702 y = height-i/* +VFrom */;
1703 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1704 AddLine(seg2, x, y, x-smalltick, y, FALSE,0);
1705 }
1706
1707 }
1708 }
1709 else
1710 {
1711
1712 for (scale_pos = ystop, i=0, j=ystart; scale_pos <= ystart; scale_pos++, i++, j--)
1713 {
1714 if (!(scale_pos % pos))
1715 {
1716 x = r.left-10;
1717 y = height-i/* +VFrom */;
1718 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1719 AddLine(seg2, x, y, x-bigtick, y, FALSE,0);
1720
1721 sprintf(scale_buf, "%d", j);
1722 y = y-Fh_2;
1723 AddAttribute(seg2, COLOR_ATT, BLUE_COLOR, 0,0,0,0);
1724 AddLabel(seg2, x-15*scale, y, scale_buf, SMALL_TEXT, 0, MIDDLE_LEFT, 0);
1725
1726 }
1727 else if (!(scale_pos % (pos/2)))
1728 {
1729 x = r.left-10;
1730 y = height-i/* +VFrom */;
1731 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1732 AddLine(seg2, x, y, x-midtick, y, FALSE,0);
1733
1734 }
1735 else if (!(scale_pos % (pos/10)))
1736 {
1737 x = r.left-10;
1738 y = height-i/* +VFrom */;
1739 AddAttribute(seg2, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
1740 AddLine(seg2, x, y, x-smalltick, y, FALSE,0);
1741 }
1742 }
1743 }
1744 }
1745
1746
1747 /*________________________________________(DOT_DisplayDiags)_____________
1748
1749
1750 Purpose : Draw function for viewer1, window2.
1751
1752 ____________________________________________________________________*/
1753
DOT_SVDisplayDiags(DOTVibDataPtr vdp2,DOTSelDataPtr data)1754 static Boolean DOT_SVDisplayDiags(DOTVibDataPtr vdp2, DOTSelDataPtr data)
1755 {
1756 RecT rcP;
1757 DOTDiagPtr PNTR hitlist;
1758 DOTVibDataPtr vdp;
1759 VieweR v;
1760 SegmenT seg1, seg2, seg3, seg4;
1761 PrimitivE prim;
1762 Int4 stop, cutoff=0, q_start, s_start, length;
1763 Int4 x, y, x2, y2;
1764 Int4 i, j;
1765 Int4 p_VFrom, p_HFrom;
1766 Int4 width, height;
1767 Int4 x_start, y_start;
1768 Int4 Right, Left, Top, Bottom;
1769 Int4 right_end, bottom_end;
1770 Int4 diag, aln_diag;
1771 Int4 q_left, q_right;
1772 Int4 s_top, s_bottom;
1773 Boolean q_hitonplus=FALSE, s_hitonplus=FALSE;
1774 Boolean lt_fixed=FALSE, rb_fixed=FALSE;
1775 Boolean lb_fixed=FALSE, rt_fixed=FALSE;
1776 Boolean query_on_minus = FALSE;
1777 DOTAlnPtr PNTR alnL, aln;
1778
1779 seg1=CreateSegment(vdp2->sv->pict1, 1, 0); /* diags */
1780 seg2=CreateSegment(vdp2->sv->pict1, 2, 0); /* axis */
1781 seg3=CreateSegment(vdp2->sv->pict1, 3, 0); /* diag coordinates */
1782 v=vdp2->sv->v1;
1783
1784 GetPosition(v, &rcP);
1785 InsetRect(&rcP, 4, 4);
1786 vdp = data->vdp;
1787 width = rcP.right-rcP.left;
1788 height = rcP.bottom-rcP.top-2*(vdp2->VERT_MARGIN*vdp2->sv->scaleValue);
1789 p_VFrom=vdp->sdp.VFrom;
1790 p_HFrom=vdp->sdp.HFrom;
1791 /* Rect Parameters */
1792 rcP.left+=2*(vdp2->HORZ_MARGIN*vdp2->sv->scaleValue);
1793 DOT_DrawXAxis(seg2, rcP, height, data->q_start, data->q_stop, vdp2->sv->scaleValue, (vdp2->mip?vdp2->mip->qbsp->id:vdp2->alp->sip));
1794 DOT_DrawYAxis(seg2, rcP, height, data->s_start, data->s_stop, vdp2->sv->scaleValue, vdp2->Fh, (vdp2->mip?vdp2->mip->sbsp->id:vdp2->alp->sip->next));
1795 AddAttribute(seg1, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
1796
1797
1798 Left=MIN(data->q_start, data->q_stop);
1799 Right=MAX(data->q_start, data->q_stop);
1800 Top=MIN(data->s_start, data->s_stop);
1801 Bottom=MAX(data->s_start, data->s_stop);
1802 right_end=rcP.left+(Right-Left);
1803 bottom_end=height-(Bottom-Top);
1804
1805 if (vdp2->mip && vdp2->showDotPlot){
1806 hitlist = vdp2->mip->hitlist;
1807 if (vdp2->mip->unique<=1)
1808 stop=vdp2->mip->index;
1809 else
1810 stop=DOT_LoopStop (vdp2);
1811
1812 if (vdp2->strand1 == Seq_strand_minus)
1813 query_on_minus = TRUE;
1814
1815 for (i = 0; i<stop ; i++)
1816 {
1817 length = hitlist[i]->length-1;
1818 if (query_on_minus)
1819 x_start = data->q_stop - hitlist[i]->q_start;
1820 else
1821 x_start = hitlist[i]->q_start - data->q_start;
1822 y_start = ABS(data->s_start- hitlist[i]->s_start);
1823 if (query_on_minus){
1824 x = rcP.left + x_start;
1825 x2 = x - length;
1826 }
1827 else {
1828 x = rcP.left + x_start;
1829 x2 = x + length;
1830 }
1831
1832 /* in dot matrix subject is always on plus */
1833 y = height- y_start;
1834 y2 = y - length;
1835
1836 prim = AddLine(seg1, x, y, x2, y2, FALSE,(Uint2)i + 1);
1837 if (prev_primID == (i + 1))
1838 HighlightPrimitive(v, seg1, prim, FRAME_PRIMITIVE);
1839 }
1840 }
1841
1842 if (vdp2->alp && vdp2->showALIGN){
1843 seg4=seg1;
1844 AddAttribute(seg4, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
1845
1846 alnL=vdp2->alp->Alnlist;
1847 stop = vdp2->alp->index;
1848 for (j = 0; j<stop; j++)
1849 {
1850 aln = alnL[j];
1851 q_start=aln->q_start-Left;
1852 s_start=aln->s_start-Top;
1853 length=aln->q_stop-aln->q_start;
1854
1855 if (vdp2->strand1 == Seq_strand_minus){
1856 q_hitonplus=FALSE;
1857 x = rcP.left+q_start;
1858 x2 = x - length;
1859 q_left = x2;
1860 q_right = x;
1861 }
1862 else{
1863 q_hitonplus=TRUE;
1864 x = rcP.left + q_start;
1865 x2 = x + length;
1866 q_left = x;
1867 q_right = x2;
1868 }
1869
1870 if (vdp2->strand2 == Seq_strand_minus){
1871 s_hitonplus=FALSE;
1872 y = height - s_start;
1873 y2 = y + length;
1874 s_top = y2;
1875 s_bottom = y;
1876 }
1877 else{
1878 s_hitonplus=TRUE;
1879 y = height - s_start;
1880 y2 = y - length;
1881 s_top = y;
1882 s_bottom = y2;
1883 }
1884
1885 lt_fixed = rb_fixed = lb_fixed = rt_fixed = FALSE;
1886 if (q_left > right_end || q_right < rcP.left ||
1887 s_top < bottom_end || s_bottom > height)
1888 continue;
1889
1890 if (q_hitonplus==s_hitonplus){
1891 diag=Bottom-Right;
1892 aln_diag=s_start-q_start;
1893 if (x<rcP.left){
1894 if (y>height){
1895 if (rcP.left-x < y-height/* aln_diag < diag */){
1896 x=x+(y-height);
1897 y=height;
1898 }
1899 else{
1900 y=y-(rcP.left-x);
1901 x=rcP.left;
1902 }
1903 }
1904 else{
1905 y=y-(rcP.left-x);
1906 x=rcP.left;
1907 }
1908 lt_fixed=TRUE;
1909 }
1910 if (x2>right_end){
1911 if (y2<bottom_end){
1912 if (x2-right_end < bottom_end-y2/* aln_diag > diag */){
1913 x2=x2-(bottom_end-y2);
1914 y2=bottom_end;
1915 }
1916 else{
1917 y2=y2+(x2-right_end);
1918 x2=right_end;
1919 }
1920 }
1921 else {
1922 y2=y2+(x2-right_end);
1923 x2=right_end;
1924 }
1925 rb_fixed=TRUE;
1926 }
1927
1928 if (y>height && !lt_fixed){
1929 x=x+(y-height);
1930 y=height;
1931 }
1932 if (y2<bottom_end && !rb_fixed){
1933 x2=x2-(bottom_end-y2);
1934 y2=bottom_end;
1935 }
1936 }
1937 else{
1938 if (q_hitonplus){/* s must be minus */
1939 /* if ( x > right_end || x2 < rcP.left || y2 <bottom_end || y>height) */
1940 /* continue; */
1941 diag=Bottom-Left;
1942 aln_diag=s_start-q_start;
1943 if (x<rcP.left){
1944 if (y<bottom_end){
1945 if (rcP.left-x < bottom_end-y/* aln_diag < diag */){
1946 x=x+(bottom_end-y);
1947 y=bottom_end;
1948 }
1949 else{
1950 y=y+(rcP.left-x);
1951 x=rcP.left;
1952 }
1953 }
1954 else{
1955 y=y+(rcP.left-x);
1956 x=rcP.left;
1957 }
1958 lb_fixed=TRUE;
1959 }
1960 if (x2>right_end){
1961 if (y2>height){
1962 if (x2-right_end < y2-height/* aln_diag > diag */){
1963 x2=x2-(y2-height);
1964 y2=height;
1965 }
1966 else{
1967 y2=y2-(x2-right_end);
1968 x2=right_end;
1969 }
1970 }
1971 else{
1972 y2=y2-(x2-right_end);
1973 x2=right_end;
1974 }
1975 rt_fixed=TRUE;
1976 }
1977 if (y<bottom_end && !lb_fixed){
1978 x=x+(bottom_end-y);
1979 y=bottom_end;
1980 }
1981 if (y2>height && !rt_fixed){
1982 x2=x2-(y2-height);
1983 y2=height;
1984 }
1985 }
1986 else if (s_hitonplus){/* q must be minus*/
1987 /* if (y2 >height || y <bottom_end || x2<rcP.left || x>right_end) */
1988 /* continue; */
1989 diag=Bottom-Left;
1990 aln_diag=s_start-q_start;
1991 if (x> right_end){
1992 if (y>height){
1993 if (x-right_end < y-height/* aln_diag < diag */){
1994 x=x-(y-height);
1995 y=height;
1996 }
1997 else{
1998 y=y-(x-right_end);
1999 x=right_end;
2000 }
2001 }
2002 else{
2003 y=y-(x-right_end);
2004 x=right_end;
2005 }
2006 lt_fixed=TRUE;
2007 }
2008 if(x2<rcP.left){
2009 if (y2<bottom_end){
2010 if (rcP.left-x2 < bottom_end-y2/* aln_diag > diag */){
2011 x2=x2+(bottom_end-y2);
2012 y2=bottom_end;
2013 }
2014 else{
2015 y2=y2+(rcP.left-x2);
2016 x2=rcP.left;
2017 }
2018 }
2019 else {
2020 y2=y2+(rcP.left-x2);
2021 x2=rcP.left;
2022 }
2023 rb_fixed=TRUE;
2024 }
2025 if (y>height && !lt_fixed){
2026 x=x-(y-height);
2027 y=height;
2028 }
2029 if (y2<bottom_end && !rb_fixed){
2030 x2=x2+(bottom_end-y2);
2031 y2=bottom_end;
2032 }
2033
2034 }
2035 }
2036 DOT_SetColor(seg4, aln->class, FALSE);
2037 prim=AddLine(seg4, x, y, x2, y2, FALSE, 0);
2038 SetPrimitiveIDs(prim,aln->entityID,aln->itemID, OBJ_SEQALIGN, aln->primID);
2039 if (prev_primID == aln->primID)
2040 HighlightPrimitive(v, seg1, prim, FRAME_PRIMITIVE);
2041 }
2042 }
2043
2044 return TRUE;
2045 }
2046
2047 /*________________________________________(DOT_WorldtoScreen)_____________
2048
2049 Purpose : calculate sequence coordinates from screen coords.
2050
2051 ____________________________________________________________________*/
DOT_WorldtoScreen(Int4 wPos,Int4 chw_2)2052 static Int4 DOT_WorldtoScreen(Int4 wPos, Int4 chw_2)
2053 {
2054 Int4 sPos;
2055
2056 sPos=wPos*chw_2;
2057
2058 return sPos;
2059 }
2060
2061 /*________________________________________(DOT_DrawScale)_____________
2062
2063 Purpose : Draw scale of aligned seqs, viewer2, window2.
2064
2065 ____________________________________________________________________*/
DOT_DrawScale(SegmenT sbSeg,Uint1 strand1,Uint1 strand2,RecT r,Int4 margin,Int4 res_cnt,Int4 bloc_cnt,Int4 Fh,Int4 q_pos,Int4 s_pos,Int4 chw_2,Int4 chw_4)2066 void DOT_DrawScale (SegmenT sbSeg, Uint1 strand1, Uint1 strand2, RecT r, Int4 margin,Int4 res_cnt, Int4 bloc_cnt, Int4 Fh, Int4 q_pos, Int4 s_pos, Int4 chw_2, Int4 chw_4)
2067 {
2068 Char Buf[15]={""};
2069 Int4 x, x2,y1, y2, y3, y4, y5, y6;
2070 Int4 pos, col;
2071
2072
2073 col =DOT_WorldtoScreen(res_cnt+bloc_cnt, chw_2);
2074
2075 x = r.left+margin+col-chw_4;
2076 y1=7*Fh;
2077 y2=y1-Fh/2;
2078 y3=y2-Fh/2;
2079 AddAttribute(sbSeg, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
2080 AddLine(sbSeg, x, y2, x, y3, FALSE, 0);
2081
2082 pos=(strand1==Seq_strand_plus)?res_cnt+q_pos:ABS(q_pos-res_cnt);
2083 sprintf(Buf,"%d",pos);
2084 x2=x-StringWidth(Buf)/2;
2085
2086 AddAttribute(sbSeg, COLOR_ATT, BLUE_COLOR, 0,0,0,0);
2087 AddLabel(sbSeg, x2,y1, Buf, SMALL_TEXT, 0, UPPER_RIGHT, 0);
2088
2089 y4=2*Fh;
2090 y5=y4+Fh+Fh/2;
2091 y6=y5+Fh/2;
2092 AddAttribute(sbSeg, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
2093 AddLine(sbSeg, x, y6, x, y5, FALSE, 0);
2094
2095 pos=(strand2==Seq_strand_plus)?res_cnt+s_pos:ABS(s_pos-res_cnt);
2096 sprintf(Buf,"%d",pos);
2097 x-=StringWidth(Buf)/2;
2098
2099 AddAttribute(sbSeg, COLOR_ATT, BLUE_COLOR, 0,0,0,0);
2100 AddLabel(sbSeg, x2,y4, Buf, SMALL_TEXT, 0, UPPER_RIGHT, 0);
2101
2102 }
2103
2104 /*________________________________________(DOT_HlSeq)_____________
2105
2106 Purpose : Draw line to show hit in alignment, viewer2, window2.
2107
2108 ____________________________________________________________________*/
DOT_HlSeq(SegmenT sbSeg,RecT rcP,Int4 margin,Int4 wPos,Int4 bloc_pos,Int4 hit_start,Int4 hit_stop,Int4 Fh,Int4 chw_2)2109 static void DOT_HlSeq(SegmenT sbSeg, RecT rcP, Int4 margin, Int4 wPos, Int4 bloc_pos, Int4 hit_start, Int4 hit_stop, Int4 Fh, Int4 chw_2)
2110 {
2111 Int4 xpos, len, bloc_beg, begin, end;
2112 Int4 x1, x2, y1;
2113
2114
2115 bloc_beg = wPos-bloc_pos;
2116 begin = MAX(bloc_beg, hit_start);
2117
2118 end = MIN(wPos,hit_stop);
2119 len = end - begin + 1;
2120 xpos = DOT_WorldtoScreen(begin, chw_2);
2121
2122 x1= rcP.left + margin + xpos;
2123 x2= x1 + len * chw_2;
2124 y1 = 5 * Fh;
2125
2126 AddAttribute(sbSeg, COLOR_ATT, RED_COLOR, 0,0,0,0);
2127 AddLine(sbSeg, x1, y1, x2, y1, FALSE,0);
2128
2129 }
2130
2131 /*________________________________________(DOT_Highlight)_____________
2132
2133 Purpose : Highlight matched residues, viewer2, window2.
2134
2135 ____________________________________________________________________
2136 */
DOT_Highlight(SegmenT sbSeg,RecT rcP,Int4 margin,Int4 wPos,Int4 Fh,Int4 chw_2,Boolean match)2137 static void DOT_Highlight(SegmenT sbSeg, RecT rcP, Int4 margin, Int4 wPos, Int4 Fh, Int4 chw_2, Boolean match)
2138 {
2139 Int4 xpos, x1, x2, y1, y2;
2140
2141 xpos=DOT_WorldtoScreen(wPos, chw_2);
2142
2143 x1= rcP.left+margin+xpos;
2144 x2= x1+chw_2;
2145 y1 = 6*Fh;
2146 y2 = 4*Fh;
2147
2148 if (match)
2149 AddAttribute(sbSeg, COLOR_ATT, YELLOW_COLOR,0,0,0,0);
2150 else
2151 AddAttribute(sbSeg, COLOR_ATT, CYAN_COLOR, 0,0,0,0);
2152 AddRectangle (sbSeg, x1, y1, x2, y2, 0, TRUE, 0);
2153 }
2154
2155
2156 /*________________________________________(DOT_UpdatePt)_____________
2157
2158 Purpose : corrects clicked points for click/drag/release procs of window1.
2159
2160 ____________________________________________________________________*/
2161
DOT_UpdatePt(void)2162 static void DOT_UpdatePt (void)
2163 {
2164 Int4 temp;
2165
2166 if (curpnt.x < fstpnt.x)
2167 {
2168 temp = curpnt.x;
2169 curpnt.x = fstpnt.x;
2170 fstpnt.x = temp;
2171 }
2172
2173 if (curpnt.y < fstpnt.y)
2174 {
2175 temp = curpnt.y;
2176 curpnt.y = fstpnt.y;
2177 fstpnt.y = temp;
2178 }
2179
2180 return;
2181
2182 }
2183
2184 /*________________________________________(DOT_FillNewSeqBufs)_____________
2185
2186 Purpose : Fill seq buffers for window2.
2187
2188 ____________________________________________________________________*/
DOT_FillNewSeqBufs(DOTVibDataPtr vdp,DOTVibDataPtr vdp2,Boolean is_zoom)2189 static void DOT_FillNewSeqBufs (DOTVibDataPtr vdp, DOTVibDataPtr vdp2, Boolean is_zoom)
2190 {
2191 Int4 qlen, slen, i;
2192 Int4 q_start, s_start;
2193 Int4 q_left, q_right;
2194 Uint1Ptr qseq=NULL, sseq=NULL, q=NULL, s=NULL, qBuf=NULL, sBuf=NULL;
2195 DOTSelDataPtr data=NULL;
2196 DOTMainDataPtr mip1=NULL, mip2=NULL;
2197 DOTAlignInfoPtr alp=NULL;
2198
2199
2200 data=(DOTSelDataPtr)vdp->data;
2201 mip1 = vdp->mip;
2202 mip2 = vdp2->mip;
2203
2204 qlen=mip2->qlen;
2205 slen=mip2->slen;
2206 qseq = mip1->qseq;
2207 sseq = mip1->sseq;
2208 q_left=mip1->q_start;
2209 q_right = mip1->q_start + mip1->qlen - 1;
2210 s_start = mip1->s_start;
2211 if (is_zoom)
2212 {
2213 mip2->sseq=MemFree(mip2->sseq);
2214 mip2->qseq=MemFree(mip2->qseq);
2215 }
2216
2217
2218 /* get sequence position relative to the vdp sequence buffer */
2219 if (vdp2->strand1 == Seq_strand_minus)
2220 q_start = ABS(q_right - data->q_stop)/* + q_left */;
2221 else
2222 q_start = ABS(q_left - data->q_start);
2223
2224 q = qseq+ q_start;
2225 s = sseq+ ABS(s_start - data->s_start);
2226
2227
2228 if (!(qBuf = (Uint1Ptr) MemNew (sizeof(Uint1)*(qlen)))) return;
2229 if (!(sBuf = (Uint1Ptr) MemNew (sizeof(Uint1)*(slen)))) return;
2230 mip2->sseq=sBuf;
2231 mip2->qseq=qBuf;
2232 i=0;
2233 while(i< qlen)
2234 {
2235 *qBuf=*q;
2236 i++;
2237 q++;
2238 qBuf++;
2239 }
2240 i=0;
2241 while(i< slen)
2242 {
2243 *sBuf=*s;
2244 i++;
2245 s++;
2246 sBuf++;
2247 }
2248 }
2249
2250 /*________________________________________(DOT_InitCInfo)_____________
2251
2252 Purpose : Initialize vdp2 (DOTVibDataPtr for window2).
2253
2254 ____________________________________________________________________*/
2255
DOT_InitCInfo(DOTVibDataPtr vdp,DOTVibDataPtr vdp2,DOTSelDataPtr data)2256 static void DOT_InitCInfo(DOTVibDataPtr vdp, DOTVibDataPtr vdp2, DOTSelDataPtr data)
2257 {
2258 Char colBuf[12]={""};
2259 DOTMainDataPtr mip1=NULL, mip2=NULL;
2260 BioseqPtr qbsp, sbsp;
2261
2262
2263 /* set up second window parameters */
2264 vdp2->sv=(DOTSeqViewrPtr)MemNew(sizeof(DOTSeqViewr));
2265 vdp2->Fnt = vdp->Fnt;
2266 vdp2->HORZ_MARGIN=vdp->HORZ_MARGIN;
2267 vdp2->VERT_MARGIN=vdp->VERT_MARGIN;
2268 vdp2->alp=vdp->alp;
2269
2270 mip1 = vdp->mip;
2271 if (mip1){
2272 qbsp = mip1->qbsp;
2273 sbsp = mip1->sbsp;
2274 mip2=(DOTMainDataPtr) MemNew (sizeof(DOTMainData));
2275 mip2=DOT_InitMainInfo (mip2, qbsp, sbsp, mip1->word_size, mip1->tree_limit, data->q_start, data->q_stop, data->s_start, data->s_stop);
2276 if (mip2->qslp)
2277 SeqLocFree(mip2->qslp);
2278 mip2->qslp = SeqLocIntNew(data->q_start, data->q_stop, vdp->strand1, qbsp->id);
2279 if (mip2->sslp)
2280 SeqLocFree(mip2->sslp);
2281 mip2->sslp = SeqLocIntNew(data->s_start, data->s_start, vdp->strand2, sbsp->id);
2282 mip2->qlen=data->qlen;
2283 mip2->slen=data->slen;
2284 vdp2->sdp.TrampPos=75;
2285 mip2->matrix = mip1->matrix;
2286 mip2->qstrand = mip1->qstrand;
2287 vdp2->mip= mip2;
2288 }
2289 else {
2290 vdp2->mip=NULL;
2291 }
2292 vdp2->xstart=data->q_start;
2293 vdp2->ystart=data->s_start;
2294 vdp2->xstop=data->q_stop;
2295 vdp2->ystop=data->s_stop;
2296 vdp2->xlen=data->qlen;
2297 vdp2->ylen=data->slen;
2298 vdp2->strand1=vdp->strand1;
2299 vdp2->strand2=vdp->strand2;
2300 vdp2->xname=vdp->xname;
2301 vdp2->yname=vdp->yname;
2302 /* sequence viewer initiatize */
2303
2304 vdp2->sv->do_scale=TRUE;
2305 vdp2->sv->scaleValue=0;
2306 vdp2->sv->showLabels=FALSE;
2307 vdp2->sv->old_primID=-1;
2308
2309
2310 vdp2->curr_slen=data->slen;
2311 vdp2->curr_qlen=data->qlen;
2312 vdp2->data=data;
2313
2314 /* hits info */
2315
2316 vdp2->Fh=vdp->Fh;
2317 vdp2->charw=vdp->charw;
2318 }
2319
2320
2321 /*________________________________________(Init_bufs)_____________
2322
2323 Purpose : Initialize sequence buffers to NULL.
2324
2325 ____________________________________________________________________*/
2326
Init_bufs(CharPtr qBuf,CharPtr sBuf,Int4 size)2327 static void Init_bufs(CharPtr qBuf, CharPtr sBuf, Int4 size)
2328 {
2329 Int4 i;
2330
2331 for (i = 0; i<size; i++)
2332 {
2333 qBuf[i]= '\0';
2334 sBuf[i]= '\0';
2335 }
2336 }
2337
2338
2339 /*________________________________________(DOT_SVDisplaySequence)_____________
2340
2341 Purpose : Draw function for viewer2 of second window.
2342
2343 ____________________________________________________________________*/
2344
DOT_SVDisplaySequence(DOTVibDataPtr vdp2,DOTAlnPtr salp)2345 static void DOT_SVDisplaySequence(DOTVibDataPtr vdp2, DOTAlnPtr salp)
2346 {
2347 RecT rc;
2348 DOTVibDataPtr vdp;
2349 DOTSelDataPtr data;
2350 DOTMainDataPtr mip1, mip2;
2351 SegmenT pict2;
2352 SegmenT nmSeg;
2353 SegmenT clSeg;
2354 SegmenT sbSeg;
2355 Boolean match=FALSE;
2356 Uint1Ptr q;
2357 Uint1Ptr s;
2358 Uint1Ptr end;
2359 Uint1Ptr seq_aln1=NULL, seq_aln2=NULL;
2360 Int4 a,b,c, pos;
2361 Boolean ambig=FALSE, is_na;
2362 Boolean get_barposition=TRUE;
2363 Int4 i, k, spaces;
2364 Int4 prot_threshold=0, bloc_cntr;
2365 Int4 res_cnt, bloc_size;
2366 Int4 x, y, x2, y2;
2367 Int4 vis_2, buf_len;
2368 Int4 bufsize, sglen;
2369 Int4 xstart, xstop, ystart, ystop;
2370 Int4 hit_start, hit_stop, q_pos, s_pos;
2371 Int4 Fh, margin;
2372 Int4 xdiff_left,xdiff_right;
2373 Int4 ydiff_left,ydiff_right;
2374 Int4 width,height;
2375 Int4 chw_2, chw_4;
2376 CharPtr qBuf;
2377 CharPtr sBuf;
2378 CharPtr PNTR residue_names;
2379 Int4Ptr PNTR matrix;
2380 Uint1 strand1, strand2;
2381 Int4 num_cls, num_segs, seg_len;
2382 Int4 q_start, q_stop, s_start, s_stop;
2383 Boolean query_on_minus = FALSE;
2384 Uint2 highlight;
2385
2386
2387 data=(DOTSelDataPtr)vdp2->data;
2388 if (data==NULL) return;
2389 vdp=data->vdp;
2390 if (vdp==NULL) return;
2391 mip1= vdp->mip;
2392 mip2= vdp2->mip;
2393 margin=MAX((StringWidth(vdp2->xname)), (StringWidth(vdp2->yname)))+10;
2394 GetPosition(vdp2->sv->v2, &rc);
2395 Fh=vdp2->Fh;
2396 vis_2=VIS_LEN/2;
2397
2398 highlight = vdp2->sv->highlight;
2399
2400 if (vdp2->strand1 == Seq_strand_minus)
2401 query_on_minus = TRUE;
2402
2403 x = rc.left;
2404 y = 5*Fh; /* on top -cartesian */
2405 y2 = y -Fh;
2406 x2 = x + margin;
2407 chw_2=vdp2->charw/2;
2408 chw_4=vdp2->charw/4;
2409 pict2=vdp2->sv->pict2;
2410 width=ABS(data->q_stop-data->q_start);
2411 height=ABS(data->s_stop-data->s_start);
2412
2413 /* in selected region coordinates */
2414 if (salp->show == dot_plot){
2415 matrix=mip1->matrix;
2416 is_na=mip1->is_na;
2417 if (mip1->is_na)
2418 residue_names=na_names;
2419 else
2420 residue_names=aa_names;
2421
2422 strand1=mip1->qstrand;
2423 strand2=mip1->sstrand;
2424
2425 if (query_on_minus) {
2426 q_start = data->q_stop - salp->q_start;
2427 q_stop = data->q_stop - salp->q_stop;
2428 }
2429 else {
2430 q_start = salp->q_start - data->q_start;
2431 q_stop = salp->q_stop - data->q_start;
2432 }
2433 s_start = ABS(data->s_start - salp->s_start);
2434 s_stop = ABS(data->s_start - salp->s_stop);
2435
2436 xdiff_left = MIN(q_start, q_stop);
2437 xdiff_right = width - MAX(q_stop, q_start);
2438 ydiff_left = s_start;
2439 ydiff_right = height-s_stop;
2440 if (xdiff_left<ydiff_left)
2441 {
2442 xstart=0;
2443 ystart=ydiff_left-xdiff_left;
2444 }
2445 else
2446 {
2447 ystart=0;
2448 xstart=xdiff_left-ydiff_left;
2449 }
2450
2451 if (xdiff_right<ydiff_right)
2452 {
2453 xstop= MAX(q_stop, q_start)+xdiff_right;
2454 ystop=s_stop+xdiff_right;
2455 }
2456 else
2457 {
2458 xstop=MAX(q_stop, q_start)+ydiff_right;
2459 ystop=s_stop+ydiff_right;
2460 }
2461
2462 if ((xstop-xstart)!=(ystop-ystart))/* these should be equal*/
2463 return;
2464
2465 data->xstart=xstart;
2466 data->xstop=xstop;
2467 data->ystart=ystart;
2468 data->ystop=ystop;
2469
2470 buf_len=xstop-xstart+1;
2471 hit_start=q_start-xstart;
2472 hit_start+=hit_start/10;
2473 hit_stop=q_stop-xstart;
2474 if (query_on_minus)
2475 q_pos = data->q_stop - xstart;
2476 else
2477 q_pos = data->q_start + xstart;
2478 s_pos = data->s_start + ystart;
2479 s=vdp2->mip->qseq + xstart;
2480 q=vdp2->mip->sseq + ystart;
2481 }
2482 else if (salp->show == align_plot){
2483 matrix=vdp2->alp->matrix;
2484 is_na=vdp2->alp->is_na;
2485 if (vdp2->alp->is_na)
2486 residue_names=na_names;
2487 else
2488 residue_names=aa_names;
2489 strand1=AlnMgr2GetNthStrand(salp->sap, 1);
2490 strand2=AlnMgr2GetNthStrand(salp->sap, 2);
2491 q_pos=salp->q_start + 1;
2492 s_pos=salp->s_start + 1;
2493 hit_start=0;
2494 hit_stop=ABS(salp->q_stop-salp->q_start);
2495 seq_aln1=DOT_GetNthSeqFromAlign(salp->sap, 1);
2496 seq_aln2=DOT_GetNthSeqFromAlign(salp->sap, 2);
2497 if (seq_aln1==NULL || seq_aln2==NULL)
2498 return;
2499 q=seq_aln1;
2500 s=seq_aln2;
2501 buf_len=ABS(salp->q_stop-salp->q_start)+1;
2502 }
2503 end=s+buf_len-1;
2504 hit_stop+=hit_stop/10;
2505 seg_len=(rc.right-rc.left)/vdp2->charw;
2506 num_segs=buf_len/seg_len;
2507 if (seg_len%buf_len)
2508 num_segs++;
2509 if (num_segs==0)
2510 num_segs=1;
2511 num_cls=num_segs/5;
2512 if (5%num_segs)
2513 num_cls++;
2514 if (num_cls==0)
2515 num_cls=1;
2516 bufsize=seg_len+(seg_len/10)+2;
2517 qBuf=(CharPtr)MemNew(sizeof(Char)*bufsize);
2518 sBuf=(CharPtr)MemNew(sizeof(Char)*bufsize);
2519 i=0;
2520 a=0;b=0;c=0;
2521 spaces=0;res_cnt=0;bloc_cntr=0;bloc_size=1;
2522 k=1;
2523 for (a=0; a<num_cls; a++)
2524 {
2525 clSeg=CreateSegment(pict2,a+1,0);
2526 for(b=0; b<num_segs; b++)
2527 {
2528 sglen=seg_len;
2529 sbSeg=CreateSegment(clSeg,b+1,0);
2530 Init_bufs(qBuf,sBuf,seg_len);
2531 for(c=0; c<sglen;c++)
2532 {
2533 if (!(i<buf_len))
2534 {
2535 a=num_cls;
2536 b=num_segs;
2537 sglen=c;
2538 if (hit_start<=i && i<=(hit_stop+bloc_size))
2539 {
2540 DOT_HlSeq(sbSeg, rc, margin, i+1, bloc_size, hit_start, hit_stop, Fh,chw_2);
2541 }
2542 goto end;
2543 }
2544
2545 if (is_na)
2546 {
2547 if (*q > 3 || *s > 3)
2548 ambig=TRUE;
2549 }
2550 else
2551 {
2552 if (*q >24 || *s >24 || *q<1 || *s<1 )
2553 ambig=TRUE;
2554 }
2555
2556 if (ambig)
2557 {
2558 if (s<end) /* not end */
2559 {
2560 qBuf[c]=*residue_names[(int)*q];
2561 sBuf[c]=*residue_names[(int)*s];
2562 ambig=FALSE;
2563 goto skip; /* continue */
2564 }
2565 else
2566 {
2567 a=num_cls;
2568 b=num_segs;
2569 sglen=c;
2570 if (hit_start<=i && i<=(hit_stop+bloc_size))
2571 {
2572 DOT_HlSeq(sbSeg, rc, margin, i+1, bloc_size, hit_start, hit_stop, Fh,chw_2);
2573 }
2574 goto end;
2575 }
2576 }
2577
2578 if (*s == *q)
2579 match=TRUE;
2580
2581
2582 qBuf[c]=*residue_names[(int)*q];
2583 sBuf[c]=*residue_names[(int)*s];
2584
2585 if (match == TRUE)
2586 {
2587 if (highlight == SHOW_MATCHES)
2588 DOT_Highlight(sbSeg, rc, margin, i, Fh, chw_2, match);
2589 match=FALSE;
2590 }
2591 else if (highlight == SHOW_MISMATCHES)
2592 DOT_Highlight(sbSeg, rc, margin, i, Fh, chw_2, match);
2593
2594 skip:
2595
2596 if (!(k % BLOCK_SIZE))
2597 {
2598 c++;
2599 sglen++;
2600 i++;
2601 buf_len++;
2602 bloc_size=0;
2603
2604 qBuf[c] = ' ';
2605 sBuf[c] = ' ';
2606 if(match)
2607 spaces++;
2608
2609 bloc_cntr++;
2610 res_cnt=i-bloc_cntr;
2611 DOT_DrawScale(sbSeg, strand1, strand2, rc, margin, res_cnt, bloc_cntr, Fh, q_pos, s_pos, chw_2, chw_4);
2612 if (hit_start<=i && i<(hit_stop+BLOCK_SIZE))
2613 {
2614 DOT_HlSeq(sbSeg, rc, margin, i, BLOCK_SIZE, hit_start, hit_stop, Fh, chw_2);
2615 if (get_barposition)
2616 {
2617 pos=DOT_WorldtoScreen(i,chw_2);
2618 vdp2->sv->barp=pos+rc.left+margin;
2619 get_barposition=FALSE;
2620 }
2621 }
2622 }
2623
2624 i++;
2625 k++;
2626 q++;
2627 s++;
2628 bloc_size++;
2629
2630 }
2631 end:
2632
2633 /* attach buffer */
2634
2635 pos=DOT_WorldtoScreen(i-sglen, chw_2);
2636 AddAttribute(sbSeg, COLOR_ATT, RED_COLOR, 0,0,0,0);
2637 AddLabel(sbSeg, x2+pos, y, qBuf , SMALL_TEXT, 0, UPPER_RIGHT, 0);
2638 AddAttribute(sbSeg, COLOR_ATT, BLACK_COLOR, 0,0,0,0);
2639 AddLabel(sbSeg, x2+pos, y2, sBuf , SMALL_TEXT, 0, UPPER_RIGHT, 0);
2640 }
2641 }
2642
2643 /*write seq names */
2644
2645 nmSeg=CreateSegment(pict2, num_cls+1, 0);
2646 AddAttribute(nmSeg, COLOR_ATT, MAGENTA_COLOR, 0,0,0,0);
2647 AddLabel(nmSeg, x, y, vdp2->xname, SMALL_TEXT, 0, UPPER_RIGHT, 0);
2648 AddLabel(nmSeg, x, y2, vdp2->yname, SMALL_TEXT, 0, UPPER_RIGHT, 0);
2649
2650
2651 MemFree(qBuf);
2652 MemFree(sBuf);
2653 if (seq_aln1)
2654 MemFree(seq_aln1);
2655 if (seq_aln2)
2656 MemFree(seq_aln2);
2657 return;
2658
2659 }
2660
2661 /*________________________________________(DOT_SVPopulateSequenceViewer)______
2662
2663 Purpose : Calls draw function for viewer2 of second window.
2664
2665 ____________________________________________________________________*/
DOT_SVPopulateSequenceViewer(DOTVibDataPtr vdp2)2666 static Boolean DOT_SVPopulateSequenceViewer(DOTVibDataPtr vdp2)
2667 {
2668 RecT rc;
2669 Char infoBuf[255];
2670 DOTSelDataPtr data;
2671 DOTAlnPtr salp;
2672
2673 data=(DOTSelDataPtr)vdp2->data;
2674 if (data==NULL) return FALSE;
2675
2676 ResetViewer(vdp2->sv->v2);
2677 vdp2->sv->pict2=DeletePicture(vdp2->sv->pict2);
2678 Update();
2679
2680 vdp2->sv->pict2=CreatePicture();
2681 GetPosition(vdp2->sv->v2, &rc);
2682
2683 salp=vdp2->sv->salp;
2684 if (salp==NULL)
2685 {
2686 AddAttribute(vdp2->sv->pict2, COLOR_ATT, RED_COLOR, 0,0,0,0);
2687 AddLabel(vdp2->sv->pict2, rc.left, rc.bottom-rc.top, "- CLICK on a diagonal to view the aligned sequence -", SMALL_TEXT, 0, UPPER_RIGHT, 0);
2688
2689 /*reset infopanel2 title*/
2690 SetTitle(vdp2->Infopanel, vdp2->iInfo);
2691 Disable(vdp2->Ggoto);
2692 }
2693 else
2694 {
2695 DOT_SVDisplaySequence(vdp2, salp);
2696
2697 /*reset infopanel2 title*/
2698 sprintf(infoBuf, "Selected.. %s(x-axis) [%d..%d] vs. %s(y-axis) [%d..%d]", vdp2->xname, salp->q_start + 1, salp->q_stop + 1, vdp2->yname, salp->s_start + 1, salp->s_stop + 1);
2699
2700 SetTitle(vdp2->Infopanel,infoBuf);
2701 Enable(vdp2->Ggoto);
2702 }
2703
2704
2705 AttachPicture(vdp2->sv->v2, vdp2->sv->pict2, vdp2->sv->barp, INT4_MIN, UPPER_CENTER, 1, 1, NULL);
2706 ArrowCursor();
2707 return TRUE;
2708
2709 }
2710
2711
2712 /*________________________________________(DOT_SVFindHit)_____________
2713
2714 Purpose : gets sequence coordinates of clicked diag (viewer2, window2)..
2715
2716 ____________________________________________________________________*/
DOT_SVFindHit(DOTVibDataPtr vdp2,Int4 primID)2717 DOTAlnPtr DOT_SVFindHit(DOTVibDataPtr vdp2, Int4 primID)
2718 {
2719 DOTAlnPtr salp;
2720 Int4 index, s_start, q_start, len;
2721 Boolean query_on_minus = FALSE;
2722
2723
2724 if (primID<1 || primID>vdp2->mip->index)
2725 return NULL;
2726
2727 salp=(DOTAlnPtr)MemNew(sizeof(DOTAln));
2728 salp->show=dot_plot;
2729 index=primID-1;
2730 q_start=vdp2->mip->hitlist[index]->q_start;
2731 s_start=vdp2->mip->hitlist[index]->s_start;
2732 len=vdp2->mip->hitlist[index]->length-1;
2733 if (vdp2->strand1 == Seq_strand_minus)
2734 query_on_minus = TRUE;
2735
2736 if (query_on_minus) {
2737 salp->q_start = vdp2->xstart + ABS(vdp2->xstop - q_start);
2738 salp->q_stop = salp->q_start - len;
2739 }
2740 else {
2741 salp->q_start = q_start;
2742 salp->q_stop = q_start + len;
2743 }
2744
2745 salp->s_start = s_start;
2746 salp->s_stop = s_start + len;
2747 salp->primID = (Uint2)primID;
2748
2749 return salp;
2750 }
2751
2752
2753
2754 /*________________________________________(DOT_SVGetDiag)_____________
2755
2756 Purpose : Calls func to get sequence coordinates of clicked diag (viewer2, window2).
2757
2758 ____________________________________________________________________*/
2759
DOT_SVGetDiag(Uint2 segID,Uint2 primID,VoidPtr userdata)2760 static Boolean DOT_SVGetDiag (Uint2 segID, Uint2 primID, VoidPtr userdata)
2761
2762 {
2763 DOTVibDataPtr vdp2;
2764 DOTAlnPtr salp;
2765
2766 vdp2 = (DOTVibDataPtr) userdata;
2767 if (vdp2 == NULL || segID !=1)
2768 return FALSE;
2769
2770 salp=DOT_SVFindHit(vdp2, primID);
2771 userdata=(Pointer)salp;
2772 return TRUE;
2773 }
2774 /*________________________________________(DOT_DeSelectAll)_____________
2775
2776 Purpose : Deselect all primitives.
2777
2778 ____________________________________________________________________*/
DOT_DeSelectAll(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)2779 static Boolean DOT_DeSelectAll(SegmenT seg, PrimitivE prim, Uint2 segID, Uint2 primID, Uint2 primCt, VoidPtr userdata)
2780 {
2781 Int1 highlight;
2782 VieweR v;
2783
2784 if (primID) {
2785 v = (VieweR) userdata;
2786 GetPrimDrawAttribute (prim, NULL, NULL, NULL, NULL, NULL, &highlight);
2787 if (highlight != PLAIN_PRIMITIVE)
2788 HighlightPrimitive (v, seg, prim, PLAIN_PRIMITIVE);
2789 }
2790
2791 return TRUE;
2792 }
2793
2794
2795 /*________________________________________(DOT_SVClickProc)_____________
2796
2797 Purpose : Click proc for viewer1 of second window.
2798
2799 ____________________________________________________________________*/
DOT_SVClickProc(VieweR v,SegmenT seg,PoinT pt)2800 static void DOT_SVClickProc(VieweR v, SegmenT seg, PoinT pt)
2801 {
2802 DOTVibDataPtr vdp2;
2803 PrimitivE prim=NULL;
2804 Uint2 primID = 0, entityID=0, itemtype=0;
2805 Uint4 itemID=0;
2806 Int1 highlight=0;
2807 Int2 handled=0;
2808 DOTAlnPtr salp=NULL;
2809 SegmenT seg1 = NULL;
2810
2811 vdp2=(DOTVibDataPtr)GetObjectExtra((WindoW)ParentWindow(v));
2812 if(!vdp2) return;
2813 seg1 = FindSegPrim(v, pt, NULL, NULL, &prim);
2814 if (seg1 != NULL)
2815 {
2816 GetPrimitiveIDs(prim, &entityID, &itemID, &itemtype, &primID);
2817 if (primID != 0)
2818 {
2819 GetPrimDrawAttribute (prim, NULL, NULL, NULL, NULL, NULL, &highlight);
2820 if (highlight == PLAIN_PRIMITIVE) {
2821 ExploreSegment (seg1, (Pointer)v, DOT_DeSelectAll);
2822 HighlightPrimitive (v, seg, prim, FRAME_PRIMITIVE);
2823
2824 if (entityID && itemID && itemtype) { /* alignment */
2825 salp=DOT_FindAlignment(vdp2, primID);
2826 }
2827 else { /* dot matrix hit */
2828 salp = DOT_SVFindHit(vdp2, primID);
2829 }
2830 prev_primID = primID;
2831 }
2832 else {
2833 ExploreSegment (seg1, (Pointer)v, DOT_DeSelectAll);
2834 salp = NULL;
2835 prev_primID = 0;
2836 }
2837 }
2838 }
2839 else {
2840 ExploreSegment (seg, (Pointer)v, DOT_DeSelectAll);
2841 salp = NULL;
2842 prev_primID = 0;
2843 }
2844 if (vdp2->sv->salp)
2845 MemFree(vdp2->sv->salp);
2846 vdp2->sv->salp=salp;
2847 DOT_SVPopulateSequenceViewer (vdp2);
2848 }
2849
2850
2851
2852 /*________________________________________(DOT_SVPopulateDiagViewer)_____________
2853
2854 Purpose : Calls draw function for diags.
2855
2856 ____________________________________________________________________*/
DOT_SVPopulateDiagViewer(DOTVibDataPtr vdp2)2857 static Boolean DOT_SVPopulateDiagViewer(DOTVibDataPtr vdp2)
2858 {
2859 Int4 index;
2860 Char str[16];
2861 DOTSelDataPtr data;
2862
2863
2864 data=(DOTSelDataPtr)vdp2->data;
2865
2866 ResetViewer(vdp2->sv->v1);
2867 vdp2->sv->pict1=DeletePicture(vdp2->sv->pict1);
2868 Update();
2869
2870 vdp2->sv->pict1=CreatePicture();
2871
2872 if (DOT_SVDisplayDiags(vdp2, data)==FALSE)
2873 return FALSE;
2874
2875 if (vdp2->sv->do_scale)
2876 {
2877 for (index=1; index<MAXZOOMSCALEVAL; index++)
2878 {
2879 sprintf (str, "%d", (zoomScaleVal [index]));
2880 PopupItem (vdp2->sv->scale, str);
2881 }
2882 SetValue (vdp2->sv->scale, vdp2->sv->scaleIndex);
2883 vdp2->sv->do_scale = FALSE;
2884
2885 }
2886
2887 SafeShow(vdp2->sv->scale);
2888
2889
2890 AttachPicture(vdp2->sv->v1, vdp2->sv->pict1, INT4_MIN, INT4_MAX, LOWER_RIGHT, vdp2->sv->scaleValue , vdp2->sv->scaleValue , NULL);
2891 if (vdp2->showDotPlot && vdp2->showALIGN){/* not clickable*/
2892 ArrowCursor();
2893 return TRUE;
2894 }
2895 SetViewerProcs (vdp2->sv->v1, DOT_SVClickProc, NULL, NULL, NULL);
2896 ArrowCursor();
2897 return TRUE;
2898
2899 }
2900
2901
2902 /*____________________________________________(DOT_ChangeSequenceWindowCutoff)______
2903
2904 Purpose : Change threshold for diag using threshold ramp.
2905
2906 ____________________________________________________________________*/
DOT_ChangeSequenceViewerCutoff(BaR b,GraphiC g,Int2 new,Int2 old)2907 static void DOT_ChangeSequenceViewerCutoff (BaR b, GraphiC g, Int2 new, Int2 old)
2908 {
2909 DOTVibDataPtr vdp2;
2910 WindoW w;
2911
2912 w=(WindoW)ParentWindow(b);
2913 vdp2 = (DOTVibDataPtr) GetObjectExtra (w);
2914
2915 vdp2->sdp.TrampPos = new+20;
2916 DOT_SVPopulateDiagViewer(vdp2);
2917
2918 }
2919
2920 /*________________________________________(DOT_SVChangeScale)_____________
2921
2922 Purpose : Change scale.
2923
2924 ____________________________________________________________________*/
DOT_SVChangeScale(PopuP p)2925 static void DOT_SVChangeScale (PopuP p)
2926
2927 {
2928 DOTVibDataPtr vdp2;
2929 Int4 index;
2930
2931 vdp2 = (DOTVibDataPtr) GetObjectExtra (p);
2932 if (vdp2 != NULL)
2933 {
2934 index = GetValue (vdp2->sv->scale);
2935 if (index <= MAXZOOMSCALEVAL && index > 0)
2936 {
2937 vdp2->sv->scaleValue = zoomScaleVal [index];
2938 }
2939 else
2940 {
2941 vdp2->sv->scaleValue = 1;
2942 }
2943
2944 /* AttachPicture(vdp2->sv->v1, vdp2->sv->pict1, INT4_MIN, INT4_MAX, LOWER_RIGHT, vdp2->sv->scaleValue , vdp2->sv->scaleValue , NULL); */
2945 /* SetViewerProcs (vdp2->sv->v1, DOT_SVClickProc, NULL, NULL, NULL); */
2946 DOT_SVPopulateDiagViewer (vdp2);
2947 }
2948 }
2949 /*________________________________________(DOT_SVChangeLabels)_____________
2950
2951 Purpose : Show or Hide coordinate labels for diags.
2952
2953 ____________________________________________________________________*/
DOT_SVChangeLabels(GrouP g)2954 static void DOT_SVChangeLabels (GrouP g)
2955
2956 {
2957 DOTVibDataPtr vdp2;
2958
2959 vdp2 = (DOTVibDataPtr) GetObjectExtra (g);
2960 if (vdp2 != NULL)
2961 {
2962 vdp2->sv->showLabels=(Boolean)(GetValue(vdp2->sv->Labels)==1);
2963 DOT_SVPopulateDiagViewer (vdp2);
2964 }
2965 }
2966
2967 /*________________________________________(DOT_SVCalculateScaling)_____________
2968
2969 Purpose : Estimates size of picture.
2970
2971 ____________________________________________________________________*/
DOT_SVCalculateScaling(DOTVibDataPtr vdp2)2972 static void DOT_SVCalculateScaling (DOTVibDataPtr vdp2)
2973
2974 {
2975 RecT r;
2976 Int4 index, r_hgt, r_wdt;
2977 double w_hgt, w_wdt, scale;
2978 double f1, f2;
2979
2980 w_hgt=vdp2->ylen+(vdp2->ylen*0.15);
2981 w_wdt=vdp2->xlen+(vdp2->xlen*0.15);
2982
2983 GetPosition(vdp2->sv->v1, &r);
2984 r_hgt=r.bottom-r.top;
2985 r_wdt=r.right-r.left;
2986
2987 f1=(float)w_hgt/r_hgt;
2988 f2=(float)w_wdt/r_wdt;
2989
2990 scale=MAX(ceil(f1), ceil(f2));
2991
2992 for (index=1; index<MAXZOOMSCALEVAL; index++)
2993 {
2994 if (zoomScaleVal [index]>= scale)
2995 {
2996 vdp2->sv->scaleValue=zoomScaleVal[index];
2997 vdp2->sv->scaleIndex=index;
2998 return;
2999 }
3000 }
3001
3002 vdp2->sv->scaleValue=zoomScaleVal[MAXZOOMSCALEVAL-1];
3003 vdp2->sv->scaleIndex=MAXZOOMSCALEVAL-1;
3004
3005 }
3006
3007 /*________________________________________(DOT_ResizeFeatWindow)_____________
3008
3009 Purpose : Resize function for window2.
3010
3011 ____________________________________________________________________*/
3012
DOT_ResizeFeatWindow(WindoW w)3013 static void DOT_ResizeFeatWindow(WindoW w)
3014 {
3015 RecT rcDlg,rcQry,rcSub, rcVsb,rcHsb, rcQi, rcSi;
3016 Int2 height,width,vsbWidth,in,gap,hsbHeight,QueryHeight,SubjectHeight, halfw;
3017 BaR vsb,hsb;
3018 DOTFeatListPtr flp;
3019 WindoW temport;
3020
3021
3022 flp=(DOTFeatListPtr)GetObjectExtra(w);
3023 temport=SavePort(w);
3024
3025 ObjectRect(w,&rcDlg);
3026 width= rcDlg.right-rcDlg.left;
3027 halfw=width/2;
3028 height= rcDlg.bottom-rcDlg.top;
3029
3030 SafeHide(flp->Query);
3031 SafeHide(flp->Subject);
3032 SafeHide(flp->QInfo);
3033 SafeHide(flp->SInfo);
3034 Update();
3035
3036 vsb = GetSlateVScrollBar ((SlatE) flp->Query);
3037 hsb = GetSlateHScrollBar ((SlatE) flp->Subject);
3038
3039 GetPosition(flp->Query,&rcQry);
3040 GetPosition(flp->Subject,&rcSub);
3041 GetPosition(flp->QInfo, &rcQi);
3042 GetPosition(flp->SInfo, &rcSi);
3043 GetPosition(vsb,&rcVsb);
3044 GetPosition(hsb,&rcHsb);
3045
3046 in=2;
3047 gap=10;
3048 vsbWidth=rcVsb.right-rcVsb.left;
3049 hsbHeight=rcHsb.bottom-rcHsb.top;
3050 QueryHeight=rcQry.bottom-rcQry.top;
3051 SubjectHeight=rcSub.bottom-rcSub.top;
3052
3053 /*new sizes for the viewers*/
3054 rcSub.right=width-in-vsbWidth;
3055 rcSub.bottom=height-in-hsbHeight;
3056 rcSub.left=halfw+in;
3057 rcSi.left=rcSub.left;
3058 rcQry.right=halfw-in-vsbWidth;
3059 rcQry.bottom=height-in-hsbHeight;
3060
3061
3062
3063 /*set the new sizes*/
3064 SetPosition(flp->Query,&rcQry);
3065 AdjustPrnt (flp->Query, &rcQry, FALSE);
3066 SetPosition(flp->Subject,&rcSub);
3067 AdjustPrnt (flp->Subject, &rcSub, FALSE);
3068 SetPosition(flp->SInfo,&rcSi);
3069 AdjustPrnt (flp->SInfo, &rcSi, FALSE);
3070
3071 AttachPicture (flp->Query,flp->segQuery, INT4_MIN, flp->vert_Qpos, UPPER_LEFT,1 , 1, NULL);
3072 SetViewerProcs (flp->Query, DOT_QViewerClickProc, NULL, NULL, NULL);
3073
3074 AttachPicture (flp->Subject,flp->segSubject, INT4_MIN, flp->vert_Spos, UPPER_LEFT,1 , 1, NULL);
3075 SetViewerProcs (flp->Subject, DOT_SViewerClickProc, NULL, NULL, NULL);
3076
3077 SafeShow(flp->QInfo);
3078 SafeShow(flp->SInfo);
3079 SafeShow(flp->Query);
3080 SafeShow(flp->Subject);
3081 RestorePort(temport);
3082 Update();
3083 }
3084
3085 /*________________________________________(DOT_ResizeSequenceWindow)_____________
3086
3087 Purpose : Resize function for window2.
3088
3089 ____________________________________________________________________*/
3090
DOT_ResizeSequenceWindow(WindoW w)3091 static void DOT_ResizeSequenceWindow(WindoW w)
3092 {
3093 Int4 lmargin;
3094 RecT rcDlg,rcV1,rcV2, rcVsb,rcHsb, rcGoto;
3095 Int2 height,width,gap,vsbWidth,in,hsbHeight,V1Height,V2Height, goHeight;
3096 BaR vsb,hsb;
3097 DOTVibDataPtr vdp2;
3098 Boolean is_visible1, is_visible2;
3099 WindoW temport;
3100
3101
3102 vdp2=(DOTVibDataPtr)GetObjectExtra(w);
3103 temport=SavePort(w);
3104 ObjectRect(w,&rcDlg);
3105 width= rcDlg.right-rcDlg.left;
3106 height= rcDlg.bottom-rcDlg.top;
3107
3108 SafeHide(vdp2->sv->v1);
3109 SafeHide(vdp2->sv->v2);
3110 SafeHide(vdp2->Infopanel);
3111 SafeHide(vdp2->Ggoto);
3112 Update();
3113
3114 vsb = GetSlateVScrollBar ((SlatE) vdp2->sv->v1);
3115 hsb = GetSlateHScrollBar ((SlatE) vdp2->sv->v1);
3116
3117 GetPosition(vdp2->sv->v1,&rcV1);
3118 GetPosition(vdp2->sv->v2,&rcV2);
3119 GetPosition(vsb,&rcVsb);
3120 GetPosition(hsb,&rcHsb);
3121 GetPosition(vdp2->Ggoto, &rcGoto);
3122
3123
3124 gap=2;
3125 in=vdp2->Fh;
3126 lmargin=10;
3127 vsbWidth=rcVsb.right-rcVsb.left;
3128 hsbHeight=rcHsb.bottom-rcHsb.top;
3129 V1Height=rcV1.bottom-rcV1.top;
3130 V2Height=9*vdp2->Fh;
3131 goHeight= rcGoto.bottom-rcGoto.top;
3132
3133 /*new sizes for the viewers*/
3134 rcV1.left=lmargin;
3135 rcV1.right=width-gap-vsbWidth-rcV1.left;
3136 rcV2.bottom=height-gap-in-hsbHeight;
3137 rcV2.top=rcV2.bottom-V2Height;
3138 rcGoto.bottom=rcV2.top-gap;
3139 rcGoto.top=rcGoto.bottom-goHeight;
3140 rcV1.bottom=rcGoto.top-gap-hsbHeight;
3141 rcV2.left=lmargin;
3142 rcV2.right=width-gap-vsbWidth-rcV2.left;
3143
3144 /*set the new sizes*/
3145 SetPosition(vdp2->sv->v1,&rcV1);
3146 AdjustPrnt (vdp2->sv->v1, &rcV1, FALSE);
3147
3148 SetPosition(vdp2->sv->v2,&rcV2);
3149 AdjustPrnt (vdp2->sv->v2, &rcV2, FALSE);
3150
3151 SetPosition(vdp2->Ggoto, &rcGoto);
3152 AdjustPrnt(vdp2->Ggoto, &rcGoto, FALSE);
3153
3154 if ((rcV1.left<rcV1.right)&&(rcV1.top<rcV1.bottom))
3155 is_visible1=TRUE;
3156 if ((rcV2.left<rcV2.right)&&(rcV2.top<rcV2.bottom))
3157 is_visible2=TRUE;
3158
3159 /*update viewers*/
3160 if (Visible (vdp2->sv->v1) && AllParentsVisible (vdp2->sv->v1))
3161 ViewerWasResized(vdp2->sv->v1);
3162 if (Visible (vdp2->sv->v2) && AllParentsVisible (vdp2->sv->v2))
3163 ViewerWasResized(vdp2->sv->v2);
3164
3165 if (vdp2->sv->do_scale!=TRUE) /* window resized */
3166 {
3167 DOT_SVPopulateDiagViewer(vdp2);
3168 DOT_SVPopulateSequenceViewer(vdp2);
3169 }
3170
3171 SafeShow(vdp2->sv->v1);
3172 SafeShow(vdp2->sv->v2);
3173 SafeShow(vdp2->Infopanel);
3174 SafeShow(vdp2->Ggoto);
3175 ArrowCursor();
3176 RestorePort(temport);
3177 Update();
3178 }
3179
DOT_DeleteCursorPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3180 static Boolean DOT_DeleteCursorPrim (SegmenT seg, PrimitivE prim, Uint2 segID,
3181 Uint2 primID, Uint2 primCt, VoidPtr userdata)
3182 {
3183 DeletePrim(seg,prim);
3184 return TRUE;
3185 }
3186
3187
DOT_PointCursorOnFeature(SegmenT seg,DOTSelFeatPtr feat_list,Int2 fontHt,Boolean found)3188 static Int4 DOT_PointCursorOnFeature(SegmenT seg, DOTSelFeatPtr feat_list, Int2 fontHt, Boolean found)
3189 {
3190 Int4 yBase, cursorHt;
3191 Boolean is_first =TRUE;
3192 Int4 vertbar_pos;
3193
3194 cursorHt=fontHt/4;
3195
3196 if (!found)
3197 {
3198 AddAttribute(seg, COLOR_ATT, BLUE_COLOR, 0, 0, 0, 0);
3199 yBase = (-1)*(feat_list->feat_num*(fontHt)-cursorHt);
3200 vertbar_pos=yBase+3*fontHt;
3201 AddRectangle(seg, 0,yBase, 2,yBase-2*cursorHt,RIGHT_ARROW,TRUE,0);
3202 }
3203 else
3204 {
3205 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
3206 while (feat_list)
3207 {
3208 yBase = (-1)*((feat_list->feat_num-1)*fontHt+cursorHt);
3209 if (is_first)
3210 {
3211 vertbar_pos=yBase+3*fontHt;
3212 is_first=FALSE;
3213 }
3214 AddRectangle(seg, 0,yBase, 2,yBase-2*cursorHt,RIGHT_ARROW,TRUE,0);
3215 feat_list=feat_list->next;
3216 }
3217 }
3218 return (vertbar_pos);
3219 }
3220
DOT_FindNextDfp(DOTFeatIndexPtr fdindex,DOTFeatPtr dfp,Boolean use_first)3221 static DOTFeatPtr DOT_FindNextDfp(DOTFeatIndexPtr fdindex, DOTFeatPtr dfp, Boolean use_first)
3222 {
3223 if (!use_first)
3224 dfp=dfp->next;
3225 while (dfp != NULL)
3226 {
3227 if (fdindex[dfp->type].show)
3228 return dfp;
3229 dfp=dfp->next;
3230 }
3231 return NULL;
3232 }
3233
3234
DOT_FindFeatureInViewer(DOTFeatIndexPtr fdindex,DOTRowPtr drp,Int4 cursor_pos)3235 static DOTSelFeatPtr DOT_FindFeatureInViewer(DOTFeatIndexPtr fdindex, DOTRowPtr drp, Int4 cursor_pos)
3236 {
3237 DOTFeatPtr dfp_head;
3238 DOTSelFeatPtr feat_list=NULL;
3239 Int4 i;
3240
3241 /* fix this so that it also works for minus strand */
3242 i=1;
3243 dfp_head = DOT_FindNextDfp(fdindex, drp->dfp, TRUE);
3244 while (dfp_head != NULL)
3245 {
3246 if (dfp_head->left<= cursor_pos && dfp_head->right >= cursor_pos)
3247 {
3248 if (!feat_list)
3249 {
3250 feat_list=(DOTSelFeatPtr)MemNew(sizeof(DOTSelFeat));
3251 }
3252 else
3253 {
3254 feat_list->next=(DOTSelFeatPtr)MemNew(sizeof(DOTSelFeat));
3255 feat_list=feat_list->next;
3256 }
3257 feat_list->feat_num = i;
3258 }
3259 if (dfp_head->right > cursor_pos)
3260 {
3261 if (feat_list)
3262 return feat_list;
3263 else
3264 return NULL;
3265 }
3266 i++;
3267 dfp_head=DOT_FindNextDfp(fdindex, dfp_head, FALSE);
3268 }
3269 return NULL;
3270 }
3271
3272
3273
DOT_FindBetweenFeats(DOTFeatIndexPtr fdindex,DOTRowPtr drp,Int4 cursor_pos)3274 static DOTSelFeatPtr DOT_FindBetweenFeats(DOTFeatIndexPtr fdindex, DOTRowPtr drp, Int4 cursor_pos)
3275 {
3276 DOTFeatPtr dfp1;
3277 DOTSelFeatPtr feat_list=NULL;
3278 Int4 i;
3279
3280 /* fix this so that it also works for minus strand */
3281 i=1;
3282 dfp1 = DOT_FindNextDfp(fdindex, drp->dfp, TRUE);
3283 if (!dfp1) goto end;
3284 /* dfp2 = DOT_FindNextDfp(fdindex, dfp1, FALSE); */
3285 /* if (!dfp2) goto end; */
3286
3287 while (dfp1 != NULL /* && dfp2 != NULL */)
3288 {
3289 if (dfp1->left > cursor_pos)
3290 {
3291 if (!feat_list)
3292 {
3293 feat_list=(DOTSelFeatPtr)MemNew(sizeof(DOTSelFeat));
3294 feat_list->feat_num = i-1;
3295 return (feat_list);
3296 }
3297 }
3298
3299 i++;
3300 dfp1=DOT_FindNextDfp(fdindex, dfp1, FALSE);
3301 /* dfp2=DOT_FindNextDfp(fdindex, dfp1, FALSE); */
3302 }
3303
3304 end:
3305 feat_list=(DOTSelFeatPtr)MemNew(sizeof(DOTSelFeat));
3306 feat_list->next=NULL;
3307 feat_list->feat_num = MAX(i-1, 1);
3308 return (feat_list);
3309
3310 }
3311 /*******************************************************************************
3312
3313 Function : DOT_AddFeatureToSegment()
3314
3315 Purpose : analyse one feature and add it to the Feature Viewer
3316
3317 *******************************************************************************/
DOT_AddFeatureToSegment(SeqMgrFeatContextPtr context,DOTPopFeatPtr pfp)3318 static void DOT_AddFeatureToSegment(SeqMgrFeatContextPtr context,
3319 DOTPopFeatPtr pfp)
3320 {
3321 PrimitivE prim;
3322 Int4 yBase, xMargin;
3323 Char str[50];
3324
3325
3326 sprintf(str, "%s (%d - %d)", pfp->dfp_cur->label, pfp->dfp_cur->left, pfp->dfp_cur->right);
3327 AddAttribute(pfp->TopParentSeg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3328 yBase = (-1)*pfp->nfeats*pfp->fontHeight;
3329 xMargin=5;
3330
3331 if (context->numivals==1){
3332
3333 prim = AddLabel(pfp->TopParentSeg, xMargin, yBase, str, SMALL_TEXT, 0, UPPER_RIGHT, 0);
3334 SetPrimitiveIDs(prim,context->entityID,context->itemID,OBJ_SEQFEAT, 0);
3335 }
3336 /*
3337 else{
3338 DOT_AddSegmentedFeature(pfp->TopParentSeg,context->numivals,context->ivals, context->strand,context->entityID,context->itemID,yBase);
3339 }
3340 */
3341 }
3342
3343 /*******************************************************************************
3344
3345 Function : DOT_AddFeaturesToViewer()
3346
3347 Purpose : callback called by SeqMgr (see also DOT_PopFeatureViewers(), below)
3348
3349 *******************************************************************************/
DOT_AddFeaturesToViewer(SeqFeatPtr sfp,SeqMgrFeatContextPtr context)3350 static Boolean LIBCALLBACK DOT_AddFeaturesToViewer(SeqFeatPtr sfp,
3351 SeqMgrFeatContextPtr context)
3352 {
3353 DOTFeatPtr dfp_new=NULL;
3354 DOTRowPtr drp=NULL;
3355 DOTFeatIndexPtr fdindex=NULL;
3356 DOTPopFeatPtr pfp=NULL;
3357
3358
3359 pfp = (DOTPopFeatPtr) context->userdata;
3360
3361 if (pfp==NULL){
3362 return(FALSE);
3363 }
3364
3365
3366 drp=pfp->drp;
3367
3368 if (pfp->dfp_cur == NULL)
3369 {
3370 drp->dfp=(DOTFeatPtr)MemNew(sizeof(DOTFeat));
3371 pfp->dfp_cur=drp->dfp;
3372 dfp_new = drp->dfp;
3373 }
3374 else
3375 {
3376 if(!(pfp->dfp_cur->next=(DOTFeatPtr)MemNew(sizeof(DOTFeat)))) return(FALSE);
3377 pfp->dfp_cur=pfp->dfp_cur->next;
3378 dfp_new = pfp->dfp_cur;
3379 }
3380
3381 if (!dfp_new) return(FALSE);
3382
3383
3384 if (context->strand>Seq_strand_minus ||
3385 context->strand==Seq_strand_unknown)
3386 {
3387 pfp->dfp_cur->strand=Seq_strand_plus;
3388 }
3389
3390 dfp_new->label=(CharPtr)FeatDefTypeLabel(sfp);
3391 dfp_new->left=context->left;
3392 dfp_new->right=context->right;
3393 dfp_new->type=context->featdeftype;
3394
3395 /*add a feature to the viewer*/
3396 /* DOT_AddFeatureToSegment(context,pfp); */
3397
3398
3399 pfp->nfeats++;
3400 fdindex = pfp->featindex;
3401
3402 if (!fdindex[context->featdeftype].present)
3403 {
3404 fdindex[context->featdeftype].present=TRUE;
3405 fdindex[context->featdeftype].show=TRUE;
3406 fdindex[context->featdeftype].label=dfp_new->label;
3407
3408 }
3409
3410 return(TRUE);
3411 }
3412
3413
DOT_DeletePrims(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3414 static Boolean DOT_DeletePrims(SegmenT seg, PrimitivE prim, Uint2 segID,
3415 Uint2 primID, Uint2 primCt, VoidPtr userdata)
3416 {
3417
3418 DeletePrim(seg, prim);
3419 return TRUE;
3420
3421 }
3422
DOT_PlaceCursors(VieweR viewer,SegmenT seg,SegmenT segCursor,DOTFeatIndexPtr fdindex,DOTRowPtr drp,Int4 seqpos,Int2 fontHt,Int4Ptr ypos,Boolean from_click,Int4 fpos)3423 static void DOT_PlaceCursors(VieweR viewer, SegmenT seg, SegmenT segCursor, DOTFeatIndexPtr fdindex, DOTRowPtr drp, Int4 seqpos, Int2 fontHt, Int4Ptr ypos, Boolean from_click, Int4 fpos)
3424 {
3425 Boolean found;
3426 DOTSelFeatPtr foundfeats;
3427 Int4 Y_pos;
3428 WindoW temport;
3429 RecT rcP;
3430
3431 if (!from_click)
3432 {
3433 foundfeats=DOT_FindFeatureInViewer(fdindex, drp, seqpos);
3434 if (!foundfeats)
3435 {
3436 foundfeats=DOT_FindBetweenFeats(fdindex, drp, seqpos);
3437 found=FALSE;
3438 }
3439 else
3440 found=TRUE;
3441 }
3442 else
3443 {
3444 foundfeats=(DOTSelFeatPtr)MemNew(sizeof(DOTSelFeat));
3445 foundfeats->feat_num=fpos;
3446 foundfeats->next=NULL;
3447 found=TRUE;
3448 }
3449 ExploreSegment (segCursor, NULL, DOT_DeleteCursorPrim);
3450 Y_pos=DOT_PointCursorOnFeature(segCursor, foundfeats, fontHt, found);
3451 *ypos=Y_pos;
3452
3453 /* if (from_main_viewer) */
3454 /* { */
3455 /* bar=GetSlateHScrollBar((SlatE) viewer); */
3456 /* Y_pos=GetBarValue(bar); */
3457 /* } */
3458 /* else */
3459 /* SetBarValue(GetSlateHScrollBar((SlatE) viewer), Y_pos); */
3460
3461 MemFree(foundfeats); /* fix this !!*/
3462 if (from_click)
3463 {
3464 temport = SavePort(ParentWindow(viewer));
3465 Select(viewer);
3466 GetPosition(viewer, &rcP);
3467 InsetRect(&rcP, -1, -1);
3468 InvalRect(&rcP);
3469 RestorePort(temport);
3470 Update();
3471 }
3472 else
3473 {
3474 AttachPicture (viewer, seg, INT4_MIN, Y_pos, UPPER_LEFT,1 , 1, NULL);
3475 }
3476
3477
3478 }
3479
3480
DOT_QViewerClickProc(VieweR v,SegmenT seg,PoinT pt)3481 static void DOT_QViewerClickProc(VieweR v, SegmenT seg, PoinT pt)
3482 {
3483 DOTFeatListPtr flp;
3484 DOTFeatPtr dfp;
3485 DOTSelDataPtr data;
3486 Int4 i, xmidPt, comp;
3487 Uint2 segID, primID, primCT;
3488 PrimitivE prim;
3489 RecT rc;
3490 Char infoBuf[255];
3491
3492 flp=(DOTFeatListPtr)GetObjectExtra((WindoW)ParentWindow(v));
3493 if (!flp) return;
3494
3495 if (FindSegPrim(v, pt, NULL, NULL, &prim))
3496 {
3497 FindSegment(v, pt, &segID, &primID, &primCT);
3498 if (segID==1)
3499 dfp=flp->query_drp->dfp;
3500 else
3501 return;
3502 i=1;
3503 dfp=DOT_FindNextDfp(flp->featindex, dfp, TRUE);
3504 if (primID!=1)
3505 {
3506 for (; i<primID; i++)
3507 {
3508 dfp=DOT_FindNextDfp(flp->featindex, dfp, FALSE);
3509 if (dfp==NULL) return;
3510 }
3511 }
3512
3513
3514 if (dfp==NULL) return;
3515
3516 data=(DOTSelDataPtr)flp->data;
3517 xmidPt=ABS(dfp->right+dfp->left)/2;
3518 data->q_start=xmidPt;
3519 GetPosition(data->vdp->panel, &rc);
3520 DOT_AddRectMargins(&rc, data->vdp);
3521 comp=data->vdp->comp;
3522 xmidPt=ABS(xmidPt-flp->mip->q_start);
3523 curpnt.x=MIN(rc.left+(xmidPt/comp), rc.right);
3524
3525 DOT_PlaceCursors(v, seg, flp->segQCursor, flp->featindex, flp->query_drp, dfp->left, flp->fontHt, &(flp->vert_Qpos), TRUE, i);
3526 SetViewerProcs (v, DOT_QViewerClickProc, NULL, NULL, NULL);
3527 sprintf(infoBuf, "Hairs .. %s (x-axis)[%d] vs. %s (y-axis)[%d]", flp->mip->qname, data->q_start, flp->mip->sname, data->s_start);
3528 SetTitle(data->vdp->Infopanel,infoBuf);
3529 DOT_UpdateMainPanel(data->vdp, TRUE);
3530 }
3531 }
3532
DOT_SViewerClickProc(VieweR v,SegmenT seg,PoinT pt)3533 static void DOT_SViewerClickProc(VieweR v, SegmenT seg, PoinT pt)
3534 {
3535 DOTFeatListPtr flp;
3536 DOTFeatPtr dfp;
3537 DOTSelDataPtr data;
3538 Char infoBuf[255];
3539 RecT rc;
3540 Int4 i, ymidPt, comp;
3541 Uint2 segID, primID, primCT;
3542 PrimitivE prim;
3543
3544
3545 flp=(DOTFeatListPtr)GetObjectExtra((WindoW)ParentWindow(v));
3546 if (!flp) return;
3547
3548 if (FindSegPrim(v, pt, NULL, NULL, &prim))
3549 {
3550 FindSegment(v, pt, &segID, &primID, &primCT);
3551 if (segID==1)
3552 dfp=flp->subject_drp->dfp;
3553 else
3554 return;
3555 i=1;
3556 dfp=DOT_FindNextDfp(flp->featindex, dfp, TRUE);
3557 if (primID!=1)
3558 {
3559 for (; i<primID; i++)
3560 {
3561 dfp=DOT_FindNextDfp(flp->featindex, dfp, FALSE);
3562 if (dfp==NULL) return;
3563 }
3564 }
3565
3566
3567 if (dfp==NULL) return;
3568
3569 data=(DOTSelDataPtr)flp->data;
3570 ymidPt = ABS(dfp->right+dfp->left)/2;
3571 data->s_start=ymidPt;
3572 GetPosition(data->vdp->panel, &rc);
3573 DOT_AddRectMargins(&rc, data->vdp);
3574 ymidPt=ABS(ymidPt -flp->mip->s_start);
3575 comp=data->vdp->comp;
3576 curpnt.y=MIN(rc.top+(ymidPt/comp), rc.bottom);
3577
3578 DOT_PlaceCursors(v, seg, flp->segSCursor, flp->featindex, flp->subject_drp, dfp->left, flp->fontHt, &(flp->vert_Spos), TRUE, i);
3579 SetViewerProcs (v, DOT_SViewerClickProc, NULL, NULL, NULL);
3580 sprintf(infoBuf, "Hairs .. %s (x-axis)[%d] vs. %s (y-axis)[%d]", flp->mip->qname, data->q_start, flp->mip->sname, data->s_start);
3581 SetTitle(data->vdp->Infopanel,infoBuf);
3582 DOT_UpdateMainPanel(data->vdp, TRUE);
3583 }
3584 }
3585
3586
3587
3588
DOT_PlaceFeat(DOTFeatListPtr flp,SegmenT seg,Int4 yBase,DOTFeatPtr dfp,Int4 primID)3589 static void DOT_PlaceFeat(DOTFeatListPtr flp, SegmenT seg, Int4 yBase, DOTFeatPtr dfp, Int4 primID)
3590 {
3591 Char str[50];
3592 Int4 xMargin;
3593
3594 sprintf(str, "%s (%d,%d,%d)", dfp->label, dfp->left, dfp->right, ABS(dfp->right-dfp->left));
3595 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3596 xMargin=5;
3597
3598 AddLabel(seg, xMargin, yBase, str, SMALL_TEXT, 0, UPPER_RIGHT, primID);
3599
3600 }
3601
3602
3603
DOT_UpdateFeatViewer(DOTFeatListPtr flp,VieweR viewer,SegmenT seg,SegmenT segName,SegmenT segCursor,VwrClckProc click,DOTRowPtr drp,Int4 cur_pos,Int4Ptr vert_pos)3604 static void DOT_UpdateFeatViewer (DOTFeatListPtr flp, VieweR viewer, SegmenT seg, SegmenT segName, SegmenT segCursor, VwrClckProc click, DOTRowPtr drp, Int4 cur_pos, Int4Ptr vert_pos)
3605 {
3606 Int4 i;
3607 DOTFeatPtr dfeatp;
3608 DOTFeatIndexPtr fdindex;
3609
3610 ExploreSegment(seg, NULL, DOT_DeletePrims);
3611 dfeatp=drp->dfp;
3612 fdindex=flp->featindex;
3613
3614 i = 1;
3615
3616 while (dfeatp != NULL)
3617 {
3618 if (fdindex[dfeatp->type].show)
3619 {
3620 DOT_PlaceFeat(flp, segName, (-1)*i*flp->fontHt, dfeatp, i);
3621 i++;
3622 }
3623 dfeatp=dfeatp->next;
3624 }
3625 if (i>1)
3626 {
3627 DOT_PlaceCursors(viewer, seg, segCursor, flp->featindex, drp, cur_pos, flp->fontHt, vert_pos, FALSE, 0);
3628 SetViewerProcs (viewer, click, NULL, NULL, NULL);
3629
3630 }
3631 else
3632 {
3633 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0,0,0,0);
3634 AddLabel(seg, 0, 0, "- no features -", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3635 AttachPicture (viewer, seg, INT4_MIN, INT4_MAX, UPPER_LEFT,1 , 1, NULL);
3636 }
3637 }
3638 /*_________________________________________________________________
3639
3640 Function : DOT_PopFeatureViewers()
3641
3642 Purpose : populate the Feature Viewer with the features.
3643
3644 ___________________________________________________________________*/
DOT_PopFeatureViewers(DOTFeatListPtr flp)3645 static void DOT_PopFeatureViewers(DOTFeatListPtr flp)
3646 {
3647 BioseqPtr query_bsp, subject_bsp;
3648 DOTPopFeat dpf;
3649 DOTRowPtr drp1, drp2;
3650 Int2 fontH;
3651 DOTMainDataPtr mip;
3652
3653 mip=flp->mip;
3654 if (!mip) return;
3655 drp1 = (DOTRowPtr)MemNew(sizeof(DOTRow));
3656 flp->query_drp=drp1;
3657 drp2=(DOTRowPtr)MemNew(sizeof(DOTRow));
3658 flp->subject_drp=drp2;
3659
3660 fontH = FontHeight();
3661 flp->fontHt = fontH;
3662 /* seqmgrexplorefeatures goes through features in order left->right*/
3663 query_bsp=mip->qbsp;
3664 memset(&dpf, 0, sizeof(dpf));
3665 dpf.TopParentView=flp->Query;
3666 dpf.TopParentSeg= CreateSegment(flp->segQuery, 1, 0);
3667 dpf.nfeats = 1;
3668 dpf.fontHeight=fontH;
3669 dpf.drp=flp->query_drp;
3670 dpf.dfp_cur=NULL;
3671 dpf.featindex=flp->featindex;
3672 flp->qFeatscount=SeqMgrExploreFeatures (query_bsp, (Pointer) &dpf, DOT_AddFeaturesToViewer, NULL, NULL, NULL);
3673
3674 subject_bsp=mip->sbsp;
3675 memset(&dpf, 0, sizeof(dpf));
3676 dpf.TopParentView=flp->Subject;
3677 dpf.TopParentSeg= CreateSegment(flp->segSubject, 1, 0) ;
3678 dpf.nfeats = 1;
3679 dpf.fontHeight=fontH;
3680 dpf.drp=flp->subject_drp;
3681 dpf.drp->dfp=NULL;
3682 dpf.dfp_cur=NULL;
3683 dpf.featindex=flp->featindex;
3684 flp->sFeatscount=SeqMgrExploreFeatures (subject_bsp, (Pointer)&dpf,
3685 DOT_AddFeaturesToViewer, NULL, NULL, NULL);
3686 }
3687
DOT_HideAcceptProc(ButtoN b)3688 static void DOT_HideAcceptProc(ButtoN b)
3689 {
3690
3691 }
3692
DOT_HideFeatList(ButtoN b)3693 static void DOT_HideFeatList(ButtoN b)
3694 {
3695 WindoW hHideDlg;
3696 DOTFeatListPtr flp;
3697 Int4 i, numrows;
3698 DOTFeatIndexPtr fdindex;
3699
3700 hHideDlg = (WindoW)ParentWindow(b);
3701 if(hHideDlg == NULL) return;
3702 flp = (DOTFeatListPtr) GetObjectExtra(hHideDlg);
3703 if(flp == NULL) return;
3704 numrows = flp->numrows;
3705 fdindex = flp->featindex;
3706
3707 for(i = 1; i <= numrows; i++)
3708 {
3709 if(!GetItemStatus(flp->featList, i))
3710 {
3711 fdindex[fdindex[i].deref].show=FALSE;
3712 }
3713 else
3714 fdindex[fdindex[i].deref].show=TRUE;
3715 }
3716 DOT_UpdateFeatViewer(flp, flp->Query, flp->segQuery, flp->segQName, flp->segQCursor, DOT_QViewerClickProc, flp->query_drp, ((DOTSelDataPtr)flp->data)->q_start, &(flp->vert_Qpos));
3717 DOT_UpdateFeatViewer(flp, flp->Subject, flp->segSubject, flp->segSName, flp->segSCursor, DOT_SViewerClickProc, flp->subject_drp, ((DOTSelDataPtr)flp->data)->s_start, &(flp->vert_Spos));
3718
3719 Remove(hHideDlg);
3720 }
3721
DOT_SetHideList(DOTFeatListPtr flp)3722 static void DOT_SetHideList(DOTFeatListPtr flp)
3723 {
3724 Int4 i;
3725 DOTFeatIndexPtr fdindex;
3726
3727 fdindex=flp->featindex;
3728
3729 for(i = 1; i <= FEATDEF_MAX; i++)
3730 {
3731 if (fdindex[fdindex[i].deref].present)
3732 {
3733 if (fdindex[fdindex[i].deref].show)
3734 SetItemStatus(flp->featList, i, TRUE);
3735 else
3736 SetItemStatus(flp->featList, i, FALSE);
3737 }
3738 }
3739 }
3740
DOT_HideFeatDlg(DOTFeatListPtr flp)3741 static void DOT_HideFeatDlg(DOTFeatListPtr flp)
3742 {
3743 Int4 i, numrows;
3744 GrouP g, hg;
3745 ButtoN b;
3746 DOTFeatIndexPtr fdindex;
3747
3748 if (flp==NULL) return;
3749 flp->hFeatDlg=NULL;
3750
3751 flp->hFeatDlg = MovableModalWindow(-50, -20, -10, -10, "Hide/Show Features", NULL);
3752 if (flp->hFeatDlg==NULL) return;
3753
3754 SetObjectExtra (flp->hFeatDlg, (void *)flp, NULL);
3755
3756
3757 hg = HiddenGroup(flp->hFeatDlg, 1, 2, NULL);
3758 g = NormalGroup(hg, 1, 2, "Choose Features to show:", systemFont, NULL);
3759
3760 fdindex = flp->featindex;
3761 flp->featList = MultiList(g,20, 6, NULL);
3762 numrows=1;
3763 for(i = 1; i < FEATDEF_MAX; i++)
3764 {
3765 if (fdindex[i].present)
3766 {
3767 ListItem(flp->featList, fdindex[i].label);
3768 fdindex[numrows].deref=i;
3769 numrows++;
3770 }
3771 }
3772 DOT_SetHideList(flp);
3773
3774 flp->numrows=numrows-1;
3775 g = HiddenGroup(hg, 2, 1, NULL);
3776 SetGroupSpacing(g, 15, 15);
3777 b = DefaultButton(g, "OK", (BtnActnProc) DOT_HideFeatList);
3778
3779 Show(flp->hFeatDlg);
3780 return;
3781 }
3782
DOT_HideFeatDlgItem(IteM i)3783 static void DOT_HideFeatDlgItem(IteM i)
3784 {
3785 DOTFeatListPtr flp;
3786 WindoW FeatWin;
3787
3788 FeatWin=(WindoW)ParentWindow(i);
3789 if (FeatWin==NULL)return;
3790
3791 flp=(DOTFeatListPtr)GetObjectExtra(FeatWin);
3792 DOT_HideFeatDlg(flp);
3793 }
3794
3795 /*________________________________________(DOT_BuildFeatGUI)_____________
3796
3797 Purpose : Creates viewers for Features.
3798
3799 ____________________________________________________________________*/
3800
DOT_BuildFeatGUI(DOTFeatListPtr flp)3801 static WindoW DOT_BuildFeatGUI (DOTFeatListPtr flp)
3802 {
3803 WindoW FeatWin;
3804 DOTMainDataPtr mip;
3805 MenU m1;
3806 VieweR v1, v2;
3807 SegmenT seg1, seg2;
3808 GrouP subg1, subg2, g;
3809 Int2 Margins;
3810 Char str[255];
3811
3812 if (!flp) return(NULL);
3813
3814 Margins=10*stdCharWidth;
3815 FeatWin = DocumentWindow(Margins,Margins ,-10, -10,"Features", NULL, DOT_ResizeFeatWindow);
3816 if (!FeatWin) return(NULL);
3817 SetObjectExtra (FeatWin, (Pointer) flp, NULL);
3818
3819 flp->FeatWin=FeatWin;
3820
3821 m1 = PulldownMenu (FeatWin, "Options");
3822 CommandItem(m1, "Hide ..", DOT_HideFeatDlgItem);
3823 CommandItem(m1, "Close", DOT_CloseFeatWindow);
3824
3825 mip= flp->mip;
3826
3827
3828 g=HiddenGroup(FeatWin,2,0,NULL);
3829
3830 subg1=HiddenGroup(g, 0, 2, NULL);
3831 sprintf(str, "%s(x-axis)", mip->qname);
3832 flp->QInfo=StaticPrompt (subg1, str , 0, 0 , systemFont, 'l');
3833 v1=CreateViewer(subg1, 150 , 200, TRUE, TRUE);
3834 seg1=CreatePicture();
3835
3836 /* AlignObjects(ALIGN_JUSTIFY, (HANDLE) pr1, (HANDLE) v1, NULL, NULL); */
3837
3838 /*viewer for close up of features*/
3839 subg2=HiddenGroup(g, 0, 2, NULL);
3840 sprintf(str, "%s(y-axis)", mip->sname);
3841 flp->SInfo= StaticPrompt (subg2, str , 0, 0, systemFont, 'l');
3842 v2 = CreateViewer(subg2, 150,200,TRUE,TRUE);
3843 seg2 = CreatePicture();
3844
3845 flp->Query=v1;
3846 flp->segQuery=seg1;
3847 flp->Subject=v2; /* lines on the control panel*/
3848 flp->segSubject=seg2;
3849 flp->segQName =CreateSegment(flp->segQuery, 1, 0);
3850 flp->segSName=CreateSegment(flp->segSubject, 1, 0);
3851 flp->segQCursor=CreateSegment(flp->segQuery, 2, 0);
3852 flp->segSCursor=CreateSegment(flp->segSubject, 2, 0);
3853
3854 /* AlignObjects(ALIGN_JUSTIFY, (HANDLE) pr2, (HANDLE) v2, NULL, NULL); */
3855
3856 RealizeWindow(FeatWin);
3857 DOT_ResizeFeatWindow(FeatWin);
3858
3859 return(FeatWin);
3860 }
3861
3862 typedef struct dot_goto{
3863 TexT txt;
3864 ButtoN highlight;
3865 } DOTGoto, PNTR DOTGotoPtr;
3866
DOT_GotoProc(ButtoN b,TexT txt,Int4 value)3867 static void DOT_GotoProc(ButtoN b, TexT txt, Int4 value)
3868 {
3869 DOTSelDataPtr data;
3870 DOTVibDataPtr vdp2=NULL;
3871 Int4 pos=0, margin, q_start, s_start;
3872 Int4 xstart, xstop, ystart, ystop;
3873 Int4 Qstart, Sstart;
3874 RecT rc;
3875 DOTAlnPtr salp;
3876
3877
3878 vdp2=(DOTVibDataPtr)GetObjectExtra(ParentWindow(b));
3879 if(!vdp2) return;
3880 data= vdp2->data;
3881 salp = vdp2->sv->salp;
3882 if (salp->show == dot_plot){
3883 xstart = data->q_start+data->xstart;
3884 xstop = data->q_start+data->xstop;
3885 ystart = data->s_start+data->ystart;
3886 ystop = data->s_start+data->ystop;
3887 Qstart = data->q_start;
3888 Sstart = data->s_start;
3889 }
3890 else {
3891 xstart = salp->q_start;
3892 xstop = salp->q_stop;
3893 ystart = salp->s_start;
3894 ystop = salp->s_stop;
3895 Qstart = salp->q_start;
3896 Sstart = salp->s_start;
3897 }
3898
3899 pos=DOT_GetValue(txt);
3900 if (1 == value){
3901 if (pos<xstart)
3902 pos=xstart;
3903 if (pos>xstop)
3904 pos=xstop;
3905 q_start=pos-Qstart;
3906 q_start=q_start+q_start/10;
3907 pos=DOT_WorldtoScreen(q_start,vdp2->charw/2);
3908 }
3909 else if (2 == value){
3910 if (pos<ystart)
3911 pos=ystart;
3912 if (pos>ystop)
3913 pos=ystop;
3914 s_start=pos-Sstart;
3915 s_start=s_start+s_start/10;
3916 pos=DOT_WorldtoScreen(s_start,vdp2->charw/2);
3917 }
3918
3919 GetPosition(vdp2->sv->v2, &rc);
3920 margin=MAX((StringWidth(vdp2->xname)), (StringWidth(vdp2->yname)))+10;
3921 vdp2->sv->barp=pos+rc.left+margin;
3922 AttachPicture(vdp2->sv->v2, vdp2->sv->pict2, vdp2->sv->barp, INT4_MIN, UPPER_CENTER, 1, 1, NULL);
3923 }
3924
DOT_TopProc(ButtoN b)3925 static void DOT_TopProc(ButtoN b)
3926 {
3927 DOTGotoPtr gtp;
3928
3929 gtp = (DOTGotoPtr)GetObjectExtra(b);
3930 DOT_GotoProc(b, gtp->txt, 1);
3931 }
3932
DOT_BottomProc(ButtoN b)3933 static void DOT_BottomProc(ButtoN b)
3934 {
3935 DOTGotoPtr gtp;
3936
3937 gtp = (DOTGotoPtr)GetObjectExtra(b);
3938 DOT_GotoProc(b, gtp->txt, 2);
3939 }
3940
3941 /*_______________________________________________(DOT_SVSwitchDisplay)___
3942
3943 Purpose : Change Display between Dotplot and Blast hits
3944
3945 ____________________________________________________________________*/
3946
3947
DOT_SVSwitchDisplay(PopuP p)3948 static void DOT_SVSwitchDisplay(PopuP p)
3949
3950 {
3951 DOTVibDataPtr vdp2=NULL;
3952 WindoW w;
3953 Int4 value;
3954 DOTGotoPtr gtp=NULL;
3955
3956
3957 gtp = (DOTGotoPtr) GetObjectExtra(p);
3958 w=(WindoW)ParentWindow(p);
3959 vdp2=(DOTVibDataPtr)GetObjectExtra(w);
3960 if (!vdp2 || !vdp2->alp) return;
3961
3962 SetTitle(gtp->txt, "");
3963 value=GetValue(p);
3964
3965 if (value==1) /* dot plot */
3966 {
3967 vdp2->showDotPlot=TRUE;
3968 vdp2->showALIGN=FALSE;
3969 }
3970 else if (value==2) /* blast aligns */
3971 {
3972 vdp2->showDotPlot=FALSE;
3973 vdp2->showALIGN=TRUE;
3974 }
3975 else if (value==3) /* both */
3976 {
3977 vdp2->showDotPlot=TRUE;
3978 vdp2->showALIGN=TRUE;
3979 }
3980
3981 DOT_SVPopulateDiagViewer(vdp2);
3982 if (vdp2->sv->salp){
3983 MemFree(vdp2->sv->salp);
3984 vdp2->sv->salp=NULL;
3985 }
3986 DOT_SVPopulateSequenceViewer(vdp2);
3987
3988 }
3989
DOT_HighlightProc(ButtoN b)3990 static void DOT_HighlightProc(ButtoN b)
3991 {
3992 DOTVibDataPtr vdp2 = NULL;
3993 DOTGotoPtr gtp = NULL;
3994
3995 gtp = (DOTGotoPtr) GetObjectExtra(b);
3996 vdp2 = (DOTVibDataPtr)GetObjectExtra(ParentWindow(b));
3997 if (!vdp2 || !gtp) return;
3998
3999 if (vdp2->sv->highlight == SHOW_MISMATCHES) {
4000 vdp2->sv->highlight = SHOW_MATCHES;
4001 SetTitle (gtp->highlight, "Show Mismatches");
4002 }
4003 else {
4004 vdp2->sv->highlight = SHOW_MISMATCHES;
4005 SetTitle (gtp->highlight, "Show Matches");
4006 }
4007 DOT_SVPopulateSequenceViewer(vdp2);
4008
4009 }
4010
4011
4012 /*________________________________________(DOT_SVBuildDiagViewer)_____________
4013
4014 Purpose : Creates viewers for second window.
4015
4016 ____________________________________________________________________*/
4017
DOT_SVBuildDiagViewer(DOTVibDataPtr vdp2)4018 static WindoW DOT_SVBuildDiagViewer(DOTVibDataPtr vdp2)
4019 {
4020 WindoW wSequence;
4021 GrouP g, g2, s, s2, s3, s4;
4022 PrompT pr1, pr2;
4023 VieweR v1,v2;
4024 ButtoN b;
4025 RecT rc;
4026 SegmenT pict1,pict2;
4027 Int2 Margins, pixwidth;
4028 Char zoombuf[]={"Decrease scale to zoom in .."};
4029 Char str1[41]={""}, str2[41]={""};
4030 DOTGotoPtr gtp;
4031 DOTMainDataPtr mip;
4032 Char title[60]={""};
4033
4034 if (!vdp2) return(NULL);
4035
4036 Margins=10*stdCharWidth;
4037 sprintf(title, "%s", vdp2->xname);
4038 StringCat(title, " vs. ");
4039 StringCat(title, vdp2->yname);
4040 wSequence = DocumentWindow(Margins,Margins ,-10, -10, title, NULL, DOT_ResizeSequenceWindow);
4041 if (!wSequence) return(NULL);
4042 GetPosition (wSequence,&rc);
4043 pixwidth=1200; /* some approximate value */
4044 /* first top group */
4045 s = HiddenGroup (wSequence,1, 4, NULL);
4046 /*threshold bar*/
4047 s3 = HiddenGroup (s,5, 0, NULL);
4048 pr2=StaticPrompt (s3, "Threshold-Ramp:", 0, 3*vdp2->Fh/2,vdp2->Fnt, 'l');
4049 pr1=StaticPrompt (s3, " 20%", 0, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4050 vdp2->sdp.ScrollBar = ScrollBar (s3, 15, 5, DOT_ChangeSequenceViewerCutoff);
4051 pr1=StaticPrompt (s3, "100%", 0, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4052 PushButton(s3, "Close", DOT_CloseSequenceWindow);
4053 SetObjectExtra(vdp2->sdp.ScrollBar, vdp2, NULL);
4054 CorrectBarMax (vdp2->sdp.ScrollBar, 80); /* 100% */
4055 CorrectBarValue (vdp2->sdp.ScrollBar, 60);/* 100% */
4056 /* second top group */
4057 s2 = HiddenGroup (s, 0, 2, NULL);
4058 if (vdp2->mip && vdp2->alp){
4059 s4=HiddenGroup (s2, 4, 0, NULL);
4060
4061 }
4062 else{
4063 s4=HiddenGroup(s2, 2, 0, NULL);
4064 }
4065 SetGroupMargins(s4, 10, 10);
4066 SetGroupSpacing(s4, 10,10);
4067
4068 pr1 = StaticPrompt (s4, zoombuf, StringWidth(zoombuf)+10 , popupMenuHeight, vdp2->Fnt, 'l');
4069 #ifdef WIN_MAC
4070 vdp2->sv->scale = PopupList (s4, TRUE, DOT_SVChangeScale);
4071 #endif
4072
4073 #ifndef WIN_MAC
4074 vdp2->sv->scale = PopupList (s4, FALSE, DOT_SVChangeScale);
4075 #endif
4076 if (vdp2->mip)
4077 vdp2->showDotPlot=TRUE;
4078 if (vdp2->alp){
4079 vdp2->showALIGN=TRUE;
4080 }
4081 if (vdp2->mip && vdp2->alp){
4082 /* pr1 = StaticPrompt (s4, "", StringWidth(zoombuf)+10 , popupMenuHeight, vdp2->Fnt, 'l'); */
4083 vdp2->sv->showp=PopupList (s4, FALSE, DOT_SVSwitchDisplay);
4084 PopupItem (vdp2->sv->showp, "- dot plot -");
4085 PopupItem (vdp2->sv->showp, "- blast -");
4086 PopupItem (vdp2->sv->showp, "- both -");
4087 SetValue (vdp2->sv->showp, 1);
4088 }
4089 sprintf(vdp2->iInfo,"Diag not selected");
4090 vdp2->Infopanel= StaticPrompt (s2, vdp2->iInfo, pixwidth, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4091 SetObjectExtra (vdp2->sv->scale, vdp2, NULL);
4092 v1=CreateViewer(s,600,500,TRUE,TRUE);
4093 pict1=CreatePicture();
4094 /* bottom group */
4095 g=HiddenGroup(wSequence,0,2,NULL);
4096 g2=HiddenGroup(g, 8, 0, NULL);
4097 SetGroupMargins(g2, 10, 10);
4098 SetGroupSpacing(g2, 10, 10);
4099 gtp=(DOTGotoPtr)MemNew(sizeof(DOTGoto));
4100 SetObjectExtra (vdp2->sv->showp, (Pointer) gtp, NULL);
4101 vdp2->Ggoto=g2;
4102 mip=vdp2->mip;
4103 StaticPrompt (g2, " -Goto-", 0, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4104 gtp->txt = DialogText (g2, "", (Int2)4, NULL);
4105 StaticPrompt (g2, " on ", 0, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4106 MemSet((Pointer)title, '\0', sizeof(title));
4107 sprintf(title, " Top ");
4108 b=PushButton (g2, title, DOT_TopProc);
4109 StaticPrompt (g2, " or ", 0, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4110 SetObjectExtra(b, (Pointer)gtp, StdCleanupExtraProc);
4111
4112 MemSet((Pointer)title, '\0', sizeof(title));
4113 sprintf(title, " Bottom ");
4114 b=PushButton (g2, title, DOT_BottomProc);
4115 SetObjectExtra(b, (Pointer)gtp, NULL);
4116 StaticPrompt (g2, " sequence ", 0, 3*vdp2->Fh/2, vdp2->Fnt, 'l');
4117 gtp->highlight = PushButton (g2, "Show Mismatches", DOT_HighlightProc);
4118 vdp2->sv->highlight = SHOW_MATCHES;
4119 SetObjectExtra(gtp->highlight, (Pointer)gtp, NULL);
4120 Disable(g2);
4121
4122 v2=CreateViewer(g,600,150,FALSE,TRUE);
4123 pict2=CreatePicture();
4124
4125 vdp2->sv->w=wSequence;
4126 vdp2->sv->v1=v1;
4127 vdp2->sv->pict1=pict1;
4128 vdp2->sv->v2=v2;
4129 vdp2->sv->pict2=pict2;
4130
4131 SetObjectExtra (vdp2->sv->w, (Pointer) vdp2, NULL);
4132 AlignObjects(ALIGN_JUSTIFY, (HANDLE) v2, (HANDLE)g, NULL, NULL);
4133 SetColorCell((GraphiC)vdp2->sv->v1, 0,0,255,192);
4134
4135 RealizeWindow(wSequence);
4136 DOT_ResizeSequenceWindow(wSequence);
4137
4138 /* calculate initial scale */
4139 DOT_SVCalculateScaling(vdp2);
4140
4141 /*populate the viewer : hits*/
4142 if (DOT_SVPopulateDiagViewer(vdp2)==FALSE)
4143 goto end;
4144
4145 if (DOT_SVPopulateSequenceViewer(vdp2)==FALSE)
4146 goto end;
4147
4148 return(wSequence);
4149
4150 end:
4151
4152 ErrPostEx (SEV_WARNING, 0, 0, "%s", "Display functions failed");
4153 return NULL;
4154
4155 }
4156
4157 /*________________________________________(DOT_UpdateDataRects)_____________
4158
4159 Purpose : Updates main window rect params in data struct.
4160
4161 ____________________________________________________________________
4162 */
DOT_UpdateDataRects(DOTSelDataPtr data,RecT rc,DOTVibDataPtr vdp,Boolean updateSelectedRect)4163 static void DOT_UpdateDataRects (DOTSelDataPtr data, RecT rc, DOTVibDataPtr vdp, Boolean updateSelectedRect)
4164 {
4165 Int4 width, height, VFrom=vdp->sdp.VFrom, HFrom=vdp->sdp.HFrom;
4166 Int4 comp, dx, dy, xstart, ystart;
4167
4168
4169 DOT_AddRectMargins(&rc, vdp);
4170
4171 /* update the limits of selectable region of parent window */
4172 width=MIN (rc.right-rc.left, vdp->curr_qlen - HFrom );
4173 height=MIN (rc.bottom-rc.top, vdp->curr_slen - VFrom );
4174
4175 data->rcP.left=rc.left;
4176 data->rcP.top=rc.top;
4177 data->rcP.right=rc.left+width+2;
4178 data->rcP.bottom=rc.top+height+2;
4179
4180 /* update the size of selected rect */
4181 if (updateSelectedRect)
4182 {
4183 xstart=ABS(data->q_start-vdp->xstart);
4184 ystart=ABS(data->s_start-vdp->ystart);
4185 comp=vdp->comp;
4186 dx=data->H_pos-HFrom;
4187 dy=data->V_pos-VFrom;
4188 width=ABS(data->q_stop-data->q_start)/comp;
4189 height=ABS(data->s_stop-data->s_start)/comp;
4190
4191 data->rcS.left=rc.left+((xstart)/comp)/* -HFrom */;
4192 data->rcS.right=data->rcS.left+width;
4193 data->rcS.top=rc.top+((ystart)/comp)/* -VFrom */;
4194 data->rcS.bottom=data->rcS.top+height;
4195 }
4196 }
4197
DOT_InitFeatIndex(DOTFeatIndexPtr fdindex)4198 static void DOT_InitFeatIndex(DOTFeatIndexPtr fdindex)
4199 {
4200 Int4 i;
4201
4202 for(i=1; i<FEATDEF_MAX; i++)
4203 {
4204 fdindex[i].show=TRUE;
4205 }
4206 }
4207
4208 /*________________________________________(DOT_MsgFunc)_____________
4209
4210 Purpose : Message Callback for the 2nd window.
4211
4212 ____________________________________________________________________*/
DOT_MsgFunc(OMMsgStructPtr ommsp)4213 static Int2 LIBCALLBACK DOT_MsgFunc (OMMsgStructPtr ommsp)
4214 {
4215 DOTVibDataPtr vdp2 = NULL;
4216 OMUserDataPtr omudp;
4217
4218
4219
4220 omudp = (OMUserDataPtr)(ommsp->omuserdata);
4221 vdp2 = (DOTVibDataPtr)omudp->userdata.ptrvalue;
4222
4223 switch (ommsp->message)
4224 {
4225 case OM_MSG_DEL:
4226 break;
4227 case OM_MSG_CREATE:
4228 break;
4229 case OM_MSG_UPDATE:
4230 break;
4231 case OM_MSG_SELECT:
4232
4233 break;
4234 case OM_MSG_DESELECT:
4235 break;
4236 case OM_MSG_CACHED:
4237 break;
4238 case OM_MSG_UNCACHED:
4239 break;
4240 case OM_MSG_TO_CLIPBOARD:
4241 break;
4242 case OM_MSG_SETCOLOR:
4243 break;
4244 case OM_MSG_FLUSH:
4245 break;
4246 default:
4247 break;
4248 }
4249
4250 return OM_MSG_RET_OK;
4251
4252 }
4253
4254
4255 /*________________________________________(DOT_ClickProc)_____________
4256
4257 Purpose : Click proc for main window - no action.
4258
4259 ____________________________________________________________________*/
DOT_ClickProc(PaneL p,PoinT pt)4260 static void DOT_ClickProc (PaneL p, PoinT pt)
4261 {
4262 DOTSelDataPtr data;
4263 RecT rc, prc;
4264 DOTVibDataPtr vdp;
4265
4266
4267 ObjectRect(p, &prc);
4268 /* data = (DOTSelDataPtr) GetObjectExtra (p); */
4269 vdp = (DOTVibDataPtr)GetObjectExtra(ParentWindow(p));
4270 if(vdp==NULL) return;
4271 data=(DOTSelDataPtr)vdp->data;
4272 if (!data) return;
4273
4274 /* specify clickable region */
4275 DOT_UpdateDataRects(data, prc, vdp, FALSE);
4276
4277
4278 rc = data->rcP;
4279
4280 if (!PtInRect (pt, &rc))
4281 {
4282 if (pt.y < rc.top) pt.y = rc.top;
4283 if (pt.y > rc.bottom) pt.y = rc.bottom;
4284 if (pt.x < rc.left) pt.x = rc.left;
4285 if (pt.x > rc.right) pt.x = rc.right;
4286 }
4287
4288 fstpnt = pt;
4289 curpnt = pt;
4290
4291 InvertMode();
4292 if (vdp->selectMode==dot_SEQVIEW)
4293 DOT_SelectFrameProc (p);
4294 else
4295 DOT_SelectLineProc(p);
4296
4297 if (data->selected)
4298 data->rm_lastselected=TRUE;
4299 else
4300 data->selected=TRUE;
4301
4302 SetObjectExtra(p, data, NULL);
4303
4304 }
4305
4306 /*________________________________________(DOT_DragProc)_____________
4307
4308 Purpose : Drag proc for main window - no action.
4309
4310 ____________________________________________________________________*/
DOT_DragProc(PaneL p,PoinT pt)4311 static void DOT_DragProc (PaneL p, PoinT pt)
4312 {
4313 DOTSelDataPtr data;
4314 RecT rc;
4315 DOTVibDataPtr vdp;
4316
4317 vdp=(DOTVibDataPtr)GetObjectExtra(ParentWindow(p));
4318 if (vdp==NULL) return;
4319 data = (DOTSelDataPtr) GetObjectExtra (p);
4320
4321
4322
4323 InvertMode();
4324 if (vdp->selectMode == dot_SEQVIEW)
4325 DOT_SelectFrameProc(p);
4326 else
4327 DOT_SelectLineProc(p);
4328
4329 rc=data->rcP;
4330
4331
4332 if (!PtInRect (pt, &rc))
4333 {
4334 if (pt.y < rc.top) pt.y = rc.top;
4335 if (pt.y > rc.bottom) pt.y = rc.bottom;
4336 if (pt.x < rc.left) pt.x = rc.left;
4337 if (pt.x > rc.right) pt.x = rc.right;
4338 }
4339
4340 curpnt = pt;
4341
4342 if (vdp->selectMode==dot_SEQVIEW)
4343 DOT_SelectFrameProc(p);
4344 else
4345 DOT_SelectLineProc(p);
4346
4347
4348 if (data->selected)
4349 {
4350 data->rm_lastselected=TRUE;
4351 }
4352 else
4353 data->selected = TRUE;
4354
4355 SetObjectExtra(p, data, NULL);
4356
4357 }
4358
4359
4360 /*__________________________(DOT_ReleaseProc)_____________
4361
4362 Purpose : Release Proc for main window - calls up second window.
4363
4364 ________________________________________________________*/
DOT_ReleaseProc(PaneL p,PoinT pt)4365 static void DOT_ReleaseProc(PaneL p, PoinT pt)
4366 {
4367 DOTSelDataPtr data;
4368 Int4 VFrom, HFrom;
4369 DOTVibDataPtr vdp2=NULL, vdp=NULL;
4370 DOTMainDataPtr mip1=NULL;
4371 DOTAlignInfoPtr alp=NULL;
4372 DOTFeatListPtr flp;
4373 Boolean xaxis_incr=TRUE, yaxis_incr=TRUE;
4374 RecT rc;
4375 Int2 dx, dy;
4376 Char infoBuf[255];
4377
4378
4379
4380 vdp = (DOTVibDataPtr)GetObjectExtra(ParentWindow(p));
4381 if (!vdp) return;
4382
4383 data = (DOTSelDataPtr) vdp->data;
4384
4385 if (!data->selected) return;
4386
4387 rc = data->rcP;
4388
4389 if (!PtInRect (pt, &rc))
4390 {
4391 if (pt.y < rc.top) pt.y = rc.top;
4392 if (pt.y > rc.bottom) pt.y = rc.bottom;
4393 if (pt.x < rc.left) pt.x = rc.left;
4394 if (pt.x > rc.right) pt.x = rc.right;
4395 }
4396 curpnt = pt;
4397 mip1 = vdp->mip;
4398 alp=vdp->alp;
4399
4400 VFrom = vdp->sdp.VFrom;
4401 HFrom = vdp->sdp.HFrom;
4402
4403
4404
4405 if (vdp->selectMode == dot_SEQVIEW)
4406 {
4407 DOT_UpdatePt();
4408 if (vdp->ChildWin==NULL)
4409 vdp2=(DOTVibDataPtr) MemNew (sizeof(DOTVibData));
4410 else
4411 {
4412 vdp2 = (DOTVibDataPtr)GetObjectExtra(vdp->ChildWin);
4413 vdp->ChildWin=DOT_ClearLastWindow(vdp->ChildWin, TRUE);
4414 }
4415 /* if (vdp2==NULL) return; */
4416
4417 InvertMode();
4418 DOT_SelectFrameProc(p);
4419
4420 dx=HFrom-data->H_pos;
4421 dy=VFrom-data->V_pos;
4422
4423 /* previous rect coordinates */
4424 data->old_rcS.left=data->rcS.left-dx;
4425 data->old_rcS.right=data->rcS.right-dx;
4426 data->old_rcS.top=data->rcS.top-dy;
4427 data->old_rcS.bottom=data->rcS.bottom-dy;
4428 /* new rect coordinates on parent window */
4429 data->rcS.left = fstpnt.x;
4430 data->rcS.top = fstpnt.y;
4431 data->rcS.right = curpnt.x;
4432 data->rcS.bottom = curpnt.y;
4433 data->H_pos=HFrom;
4434 data->V_pos=VFrom;
4435 /* map selected region to sequence(world) coordinates
4436 plus or minus one to account for errors when rounding off */
4437
4438 data->q_start = MAX((fstpnt.x - rc.left + HFrom - 1)*vdp->comp, 0) + vdp->xstart;
4439 data->q_stop = MIN(((curpnt.x - rc.left +(HFrom+1))*vdp->comp)+vdp->xstart, vdp->xstop);
4440
4441 data->s_start = MAX((fstpnt.y - rc.top + (VFrom-1))*vdp->comp, 0) + vdp->ystart;
4442 data->s_stop = MIN(((curpnt.y - rc.top +(VFrom+1))*vdp->comp)+vdp->ystart, vdp->ystop);
4443
4444 data->qlen=ABS(data->q_stop-data->q_start)+1;
4445 data->slen=ABS(data->s_stop-data->s_start)+1;
4446
4447 /* create new sequence buffers */
4448 DOT_InitCInfo(vdp, vdp2, data);
4449
4450 if (vdp2->mip){
4451 DOT_FillNewSeqBufs(vdp, vdp2, FALSE);
4452 /* DOT_GetSeqs(vdp2->mip, TRUE); */
4453 if (DOT_BuildHitList(vdp2->mip, TRUE, TRUE)<0)
4454 {
4455 data->selected=FALSE;
4456 data->rm_lastselected =TRUE;
4457 SetTitle(vdp->Infopanel, vdp->iInfo);
4458 DOT_UpdateMainPanel(vdp, FALSE);
4459 Beep();
4460 return;/* no hits */
4461 }
4462 }
4463 /*reset infopanel*/
4464
4465 sprintf(infoBuf, "Selected .. %s (horizontal) [%d..%d] vs. %s (vertical) [%d..%d]", vdp->xname, data->q_start, data->q_stop, vdp->yname, data->s_start, data->s_stop);
4466 SetTitle(vdp->Infopanel,infoBuf);
4467 DOT_UpdateMainPanel(vdp, FALSE);
4468
4469 /* create second window */
4470
4471 vdp->ChildWin=DOT_SVBuildDiagViewer(vdp2);
4472
4473 }
4474 else if (vdp->selectMode == dot_FEATVIEW && vdp->mip)
4475 {
4476 InvertMode();
4477 DOT_SelectLineProc(p);
4478 dx=HFrom-data->H_pos;
4479 dy=VFrom-data->V_pos;
4480 /* previous hair coordinates */
4481 data->old_rcS.left=data->rcS.left-dx;
4482 data->old_rcS.right=data->rcS.right-dx;
4483 data->old_rcS.top=data->rcS.top-dy;
4484 data->old_rcS.bottom=data->rcS.bottom-dy;
4485 /* new hair coordinates on parent window */
4486 data->rcS.left = curpnt.x;
4487 data->rcS.top = curpnt.y;
4488 data->rcS.right = curpnt.x;
4489 data->rcS.bottom = curpnt.y;
4490 data->H_pos=HFrom;
4491 data->V_pos=VFrom;
4492 if (vdp->strand1 == Seq_strand_plus)
4493 {
4494 data->q_start = MIN(MAX((curpnt.x - rc.left +(HFrom))*vdp->comp, 0)+vdp->xstart, vdp->xstop);
4495 }
4496 else
4497 {
4498 data->q_start = MAX(vdp->xstart-((curpnt.x - rc.left +(HFrom))*vdp->comp), vdp->xstop);
4499 }
4500
4501 if (vdp->strand2==Seq_strand_plus)
4502 {
4503 data->s_start = MIN(MAX((curpnt.y - rc.top +(VFrom))*vdp->comp, 0)+ vdp->ystart, vdp->ystop);
4504 }
4505 else
4506 {
4507 data->s_start = MAX(vdp->ystart-((curpnt.y - rc.top + (VFrom))*vdp->comp), vdp->ystop);
4508 }
4509
4510 DOT_UpdateMainPanel(vdp, TRUE);
4511 /* look for features in selected region */
4512
4513 if (vdp->ChildWin !=NULL)
4514 {
4515 flp=(DOTFeatListPtr)GetObjectExtra(vdp->ChildWin);
4516 }
4517 else /* first pass */
4518 {
4519 flp=(DOTFeatListPtr)MemNew(sizeof(DOTFeatList));
4520 flp->data=vdp->data;
4521 flp->mip=vdp->mip;
4522 flp->featindex=(DOTFeatIndexPtr) MemNew(sizeof(DOTFeatIndex)*FEATDEF_MAX);
4523 DOT_InitFeatIndex(flp->featindex);
4524 vdp->ChildWin=DOT_BuildFeatGUI(flp);
4525 if (!vdp->ChildWin) return;
4526 DOT_PopFeatureViewers(flp);
4527 if (flp->qFeatscount==0 && flp->sFeatscount==0)
4528 {
4529 data->selected=FALSE;
4530 DOT_UpdateMainPanel(vdp, TRUE);
4531 MemFree(flp);
4532 ErrPostEx(SEV_WARNING, 0, 0, "no features on bioseqs");
4533 return;
4534 }
4535 }
4536
4537 DOT_UpdateFeatViewer(flp, flp->Query, flp->segQuery, flp->segQName, flp->segQCursor, DOT_QViewerClickProc, flp->query_drp, ((DOTSelDataPtr)flp->data)->q_start, &(flp->vert_Qpos));
4538 DOT_UpdateFeatViewer(flp, flp->Subject, flp->segSubject, flp->segSName, flp->segSCursor, DOT_SViewerClickProc, flp->subject_drp, ((DOTSelDataPtr)flp->data)->s_start, &(flp->vert_Spos));
4539 sprintf(infoBuf, "Hairs .. X-axis (%s) [%d] vs. Y-axis (%s) [%d]", vdp->xname, data->q_start, vdp->yname, data->s_start);
4540 SetTitle(vdp->Infopanel,infoBuf);
4541
4542 }
4543
4544 Show(vdp->ChildWin);
4545 }
4546
4547 /*________________________________________(DOT_InitDataStruct)_____________
4548
4549 Purpose : Initialize data structure.
4550
4551 ____________________________________________________________________*/
DOT_InitDataStruct(DOTVibDataPtr vdp)4552 static void DOT_InitDataStruct (DOTVibDataPtr vdp)
4553 {
4554 DOTSelDataPtr data;
4555 RecT rc;
4556
4557
4558 ObjectRect(vdp->panel, &rc);
4559 InsetRect(&rc, 4, 4);
4560
4561 data = (DOTSelDataPtr) MemNew (sizeof (DOTSelData));
4562 data->selected = FALSE;
4563 data->q_start = 0;
4564 data->q_stop = 0;
4565 data->s_start = 0;
4566 data->s_stop = 0;
4567 data->V_pos=0;
4568 data->H_pos=0;
4569 data->vdp = vdp;
4570 DOT_UpdateDataRects(data, rc, vdp, FALSE);
4571 /* initialize document left and top parameters */
4572
4573
4574 vdp->data = (VoidPtr)data;
4575 if (vdp->panel != NULL)
4576 SetObjectExtra (vdp->panel, data, NULL);
4577 else
4578 return;
4579 }
4580 /*________________________________________(DOT_ReducesizeProc)_____________
4581
4582 Purpose : Increase compression of main window display.
4583
4584 ____________________________________________________________________*/
4585
DOT_ReduceSizeProc(IteM i)4586 static void DOT_ReduceSizeProc (IteM i)
4587 {
4588 WindoW w, temport;
4589 RecT rcP;
4590 DOTVibDataPtr vdp;
4591 DOTSelDataPtr data;
4592 Int4 VCurPos, HCurPos;
4593 BaR vsb, hsb;
4594
4595
4596
4597 w = (WindoW)ParentWindow(i);
4598 temport = SavePort(w);
4599
4600 vdp = (DOTVibDataPtr)GetObjectExtra (w);
4601 if (vdp==NULL) return;
4602
4603 data=(DOTSelDataPtr)vdp->data;
4604
4605 Select(vdp->panel);
4606 ObjectRect(vdp->panel, &rcP);
4607
4608 vdp->comp *=2;
4609
4610 DOT_SetCurrSeqlen (vdp);
4611 DOT_SetScrlVals (vdp);
4612
4613 vdp->sdp.XScrlPos = (vdp->sdp.XScrlPos*vdp->sdp.UnitX/2)/vdp->sdp.UnitX;
4614 vdp->sdp.YScrlPos = (vdp->sdp.YScrlPos*vdp->sdp.UnitY/2)/vdp->sdp.UnitY;
4615
4616 /*current scroll status*/
4617 vsb = GetSlateVScrollBar ((SlatE) vdp->panel);
4618 VCurPos=GetBarValue(vsb);
4619 hsb = GetSlateHScrollBar ((SlatE) vdp->panel);
4620 HCurPos=GetBarValue(hsb);
4621
4622 /* update scroll values*/
4623 DOT_VScrlUpdate(vdp, vsb, VCurPos);
4624 DOT_HScrlUpdate(vdp, hsb, HCurPos);
4625
4626 DOT_UpdateDataRects(data, rcP, vdp, TRUE);
4627
4628 InsetRect(&rcP, -1, -1);
4629 InvalRect (&rcP);
4630 RestorePort (temport);
4631 Update();
4632
4633 }
4634
4635 /*________________________________________(DOT_EnlargeSizeProc)_____________
4636 Purpose : Reduce compression of main window display.
4637
4638 ____________________________________________________________________*/
DOT_EnlargeSizeProc(IteM i)4639 static void DOT_EnlargeSizeProc (IteM i)
4640 {
4641 WindoW w, temport;
4642 RecT rcP;
4643 DOTVibDataPtr vdp;
4644 DOTSelDataPtr data;
4645 Int4 VCurPos, HCurPos;
4646 BaR vsb, hsb;
4647
4648 w = (WindoW)ParentWindow(i);
4649 temport = SavePort(w);
4650
4651 vdp = (DOTVibDataPtr)GetObjectExtra (w);
4652 if (vdp==NULL) return;
4653
4654 data=(DOTSelDataPtr)vdp->data;
4655
4656 Select(vdp->panel);
4657 ObjectRect(vdp->panel, &rcP);
4658 if (vdp->comp >= 2)
4659 {
4660 vdp->comp/= 2;
4661 }
4662
4663 DOT_SetCurrSeqlen(vdp);
4664 DOT_SetScrlVals (vdp);
4665 DOT_UpdateDataRects(data, rcP, vdp, TRUE);
4666
4667 vdp->sdp.XScrlPos = (vdp->sdp.XScrlPos*vdp->sdp.UnitX*2)/vdp->sdp.UnitX;
4668 vdp->sdp.YScrlPos = (vdp->sdp.YScrlPos*vdp->sdp.UnitY*2)/vdp->sdp.UnitY;
4669
4670 /*current scroll status*/
4671 vsb = GetSlateVScrollBar ((SlatE) vdp->panel);
4672 VCurPos=GetBarValue(vsb);
4673 hsb = GetSlateHScrollBar ((SlatE) vdp->panel);
4674 HCurPos=GetBarValue(hsb);
4675
4676 /* update scroll values*/
4677 DOT_VScrlUpdate(vdp, vsb, VCurPos);
4678 DOT_HScrlUpdate(vdp, hsb, HCurPos);
4679
4680 InsetRect(&rcP, -1, -1);
4681 InvalRect (&rcP);
4682 RestorePort (temport);
4683 Update();
4684
4685 }
4686
DOT_ImageSizeHasChanged(DOTVibDataPtr vdp)4687 static void DOT_ImageSizeHasChanged(DOTVibDataPtr vdp)
4688 {
4689 BaR vsb, hsb;
4690 Int4 HCurPos, VCurPos;
4691
4692 DOT_SetCurrSeqlen(vdp);
4693 DOT_SetScrlVals (vdp);
4694
4695 /*current scroll status*/
4696 vsb = GetSlateVScrollBar ((SlatE) vdp->panel);
4697 VCurPos=GetBarValue(vsb);
4698 hsb = GetSlateHScrollBar ((SlatE) vdp->panel);
4699 HCurPos=GetBarValue(hsb);
4700
4701 /* update scroll values*/
4702 DOT_VScrlUpdate(vdp, vsb, VCurPos);
4703 DOT_HScrlUpdate(vdp, hsb, HCurPos);
4704
4705 }
4706
4707 /*________________________________________(DOT_OriginalSizeProc)_____________
4708
4709 Purpose : Resize the main window display to the original size.
4710
4711 ____________________________________________________________________*/
DOT_OriginalSizeProc(IteM i)4712 static void DOT_OriginalSizeProc (IteM i)
4713 {
4714 WindoW w, temport;
4715 RecT rcP;
4716 DOTVibDataPtr vdp;
4717 DOTSelDataPtr data;
4718
4719 w = (WindoW)ParentWindow(i);
4720 temport = SavePort(w);
4721
4722 vdp = (DOTVibDataPtr)GetObjectExtra (w);
4723 if (vdp==NULL) return;
4724
4725 data=(DOTSelDataPtr)vdp->data;
4726
4727 Select(vdp->panel);
4728 ObjectRect(vdp->panel, &rcP);
4729
4730 vdp->comp = vdp->originalcomp;
4731
4732 DOT_ImageSizeHasChanged(vdp);
4733 DOT_UpdateDataRects(data, rcP, vdp, TRUE);
4734
4735
4736 InsetRect(&rcP, -1, -1);
4737 InvalRect (&rcP);
4738 RestorePort (temport);
4739 Update();
4740
4741 }
4742
4743 /*_______________________________________________(DOT_GetInfoProc)___
4744
4745 Purpose : 'About' information on software features.
4746
4747 ____________________________________________________________________*/
4748
DOT_GetInfoProc(IteM i)4749 static void DOT_GetInfoProc (IteM i)
4750
4751 {
4752 WindoW w;
4753
4754 w = FixedWindow(-50, -1, -1, -1, "Info", StdCloseWindowProc);
4755 StaticPrompt (w, "Dot plotter..", 0, popupMenuHeight, programFont, 'l');
4756
4757 RealizeWindow(w);
4758 Show (w);
4759 }
4760
4761 /*_______________________________________________(DOT_FeatAnalysisProc)____
4762
4763
4764 Purpose : Bring up Feature analysis selection window.
4765
4766 ____________________________________________________________________*/
DOT_FeatAnalysisProc(ButtoN b)4767 static void DOT_FeatAnalysisProc(ButtoN b)
4768 {
4769 WindoW w;
4770 GrouP g, g2;
4771
4772
4773 w = FixedWindow(-50, -1, -1, -1, "ACUTE", StdCloseWindowProc);
4774
4775 g = HiddenGroup(w, 0, 2, NULL);
4776 g2 = HiddenGroup(g, 0, 2, NULL);
4777 RadioButton(g2, "Coils");
4778 RadioButton(g2, "SEG");
4779
4780 RealizeWindow(w);
4781 Show (w);
4782 }
4783
4784
4785 /*_______________________________________________(DOT_GetValue)________
4786
4787 Purpose: Get int value of input TexT
4788
4789 _______________________________________________________________________*/
DOT_GetValue(TexT t)4790 extern Int4 DOT_GetValue (TexT t)
4791 {
4792 Char str[20];
4793 Int4 val;
4794
4795 GetTitle (t, str, sizeof(str));
4796 if (StringHasNoText(str))
4797 {
4798 ErrPostEx (SEV_WARNING, 0, 0, "%s", "missing parameter(s)");
4799 return -1;
4800 }
4801
4802 val=atoi(str);
4803
4804 return val;
4805 }
4806
4807
4808 /*_______________________________________________(DOT_DoParams)___
4809
4810 Purpose : Recalculate dot plot with new parameters.
4811
4812 ____________________________________________________________________*/
4813
DOT_DoParams(ButtoN b)4814 void DOT_DoParams(ButtoN b)
4815 {
4816 WindoW w;
4817 DOTparamsinfoPtr pip;
4818 DOTVibDataPtr vdp;
4819 DOTMainDataPtr mip;
4820
4821 WatchCursor();
4822 w=(WindoW)ParentWindow(b);
4823 if (!(pip=(DOTparamsinfoPtr)GetObjectExtra(b))) return;
4824 if (!(vdp=(DOTVibDataPtr)GetObjectExtra(w))) return;
4825 mip=vdp->mip;
4826
4827 DOT_FreeHitsArray(mip->hitlist, mip->index);
4828
4829 mip->word_size = DOT_GetValue(pip->word_size);
4830 mip->tree_limit = DOT_GetValue(pip->tree_limit);
4831 mip->first_pass=TRUE;
4832 mip->cutoff_score=0;
4833
4834 if (pip) MemFree(pip);
4835
4836 if (DOT_BuildHitList(mip, TRUE, TRUE)<0)
4837 {
4838 Message(MSG_ERROR, "DOT- No hits");
4839 return; /* no hits */
4840 }
4841
4842 DOT_UpdateMainPanel(vdp, TRUE);
4843 ArrowCursor();
4844 Remove(w);
4845 }
4846
DOT_CancelParams(ButtoN b)4847 void DOT_CancelParams(ButtoN b)
4848 {
4849
4850 WindoW w;
4851 DOTparamsinfoPtr pip;
4852
4853 w=ParentWindow(b);
4854 pip=(DOTparamsinfoPtr)GetObjectExtra(b);
4855 if (pip) MemFree(pip);
4856 Remove(w);
4857 }
4858
4859
DOT_QuitProg(ButtoN b)4860 void DOT_QuitProg(ButtoN b)
4861 {
4862
4863 WindoW w;
4864 DOTparamsinfoPtr pip;
4865 DOTVibDataPtr vdp2;
4866
4867 w=ParentWindow(b);
4868 pip=(DOTparamsinfoPtr)GetObjectExtra(b);
4869 vdp2=(DOTVibDataPtr)GetObjectExtra(w);
4870 if (vdp2->mip){
4871 DOT_FreeMainInfo(vdp2->mip);
4872 if (vdp2->mip) MemFree(vdp2->mip);
4873 }
4874 if (vdp2) MemFree(vdp2);
4875 if (pip) MemFree(pip);
4876 Remove(w);
4877 QuitProgram();
4878 }
4879
4880 /*____________________________________________(DOT_StartDOTPLOT)_____________
4881
4882
4883 Purpose : Starts Dot Plot with user parameters.
4884
4885 ____________________________________________________________________*/
4886
DOT_StartDOTPLOT(ButtoN b)4887 void DOT_StartDOTPLOT(ButtoN b)
4888 {
4889 WindoW w;
4890 DOTparamsinfoPtr pip;
4891 DOTVibDataPtr vdp;
4892 DOTMainDataPtr mip;
4893 BioseqPtr qbsp, sbsp;
4894
4895
4896 WatchCursor();
4897 w=(WindoW)ParentWindow(b);
4898 pip=(DOTparamsinfoPtr)GetObjectExtra(b);
4899 vdp=(DOTVibDataPtr)GetObjectExtra(w);
4900 mip=(DOTMainDataPtr)MemNew(sizeof(DOTMainData));
4901 /* DOT_FreeHitsArray(mip->hitlist, mip->index); */
4902
4903 mip->q_start= DOT_GetValue(pip->xstart);
4904 mip->q_stop=DOT_GetValue(pip->xstop);
4905 mip->s_start=DOT_GetValue(pip->ystart);
4906 mip->s_stop=DOT_GetValue(pip->ystop);
4907 mip->qlen = (mip->q_stop-mip->q_start) + 1;
4908 mip->slen = (mip->s_stop-mip->s_start) + 1;
4909 mip->word_size = DOT_GetValue(pip->word_size);
4910 mip->tree_limit = DOT_GetValue(pip->tree_limit);
4911 mip->first_pass=TRUE;
4912 mip->cutoff_score=0;
4913 if (pip) MemFree(pip);
4914
4915 qbsp=mip->qbsp;
4916 sbsp=mip->sbsp;
4917 Remove(w);
4918
4919 DOT_CreateAndStore(mip, qbsp, sbsp, mip->q_start, mip->q_stop, mip->s_start, mip->s_stop, mip->word_size, mip->tree_limit, FALSE);
4920
4921 }
4922
4923
4924
DOT_SetupParamsWindow(DOTVibDataPtr vdp,Boolean is_startup,Boolean is_nuc)4925 void DOT_SetupParamsWindow(DOTVibDataPtr vdp, Boolean is_startup, Boolean is_nuc)
4926 {
4927 GrouP g, g1, g2,p1, p2;
4928 GrouP mainzoomg, zoomg1, zoomg2;
4929 ButtoN b1, b2;
4930 DOTparamsinfoPtr pip;
4931 DOTMainDataPtr mip;
4932 WindoW w;
4933 Char str1[20], str2[20], str3[20], str4[20];
4934
4935
4936 ArrowCursor();
4937
4938 pip=(DOTparamsinfoPtr)MemNew(sizeof(DOTparamsinfo));
4939 mip=vdp->mip;
4940
4941 w = FixedWindow(-50, -25, -1, -1, "Parameters", StdCloseWindowProc);
4942 SetObjectExtra(w, (Pointer)vdp, NULL);
4943
4944 if (is_startup)
4945 {
4946 g=HiddenGroup(w, 1, 3, NULL);
4947 mainzoomg = NormalGroup(g, 1, 2, "Zoom Parameters", systemFont, NULL);
4948 sprintf(str1, "%d", mip->q_start);
4949 sprintf(str2, "%d", mip->s_start);
4950 sprintf(str3, "%d", mip->q_stop);
4951 sprintf(str4, "%d", mip->s_stop);
4952 zoomg1=HiddenGroup(mainzoomg, 3, 1, NULL);
4953 StaticPrompt(zoomg1, "x-axis:", 0, 0, systemFont, 'l');
4954 pip->xstart = DialogText(zoomg1, str1, 5, NULL);
4955 pip->xstop = DialogText(zoomg1, str3, 5, NULL);
4956 zoomg2=HiddenGroup(mainzoomg, 3, 1, NULL);
4957 StaticPrompt(zoomg2, "y-axis:", 0, 0, systemFont, 'l');
4958 pip->ystart = DialogText(zoomg2, str2, 5, NULL);
4959 pip->ystop = DialogText(zoomg2, str4, 5, NULL);
4960 }
4961 else
4962 g=HiddenGroup(w, 1, 2, NULL);
4963
4964 g1 = NormalGroup(g, 1, 2, "Parameters", systemFont, NULL);
4965 sprintf(str1, "%d", mip->word_size);
4966 sprintf(str2, "%d", mip->tree_limit);
4967 if (is_nuc)
4968 sprintf(str3, "(4 - 11):" /*, NULL*/);
4969 else
4970 sprintf(str3, "(1, 2 or 3):" /*, NULL*/);
4971
4972 p1=HiddenGroup(g1, 3, 1, NULL);
4973 StaticPrompt(p1, "Word size ", 0, 0, systemFont, 'l');
4974 StaticPrompt(p1, str3, 0, 0, systemFont, 'l');
4975 pip->word_size = DialogText(p1, str1, 5, NULL);
4976
4977 p2=HiddenGroup(g1, 2, 1, NULL);
4978 StaticPrompt(p2, "Max number of hits:", 0, 0, systemFont, 'l');
4979 pip->tree_limit = DialogText(p2, str2, 5, NULL);
4980
4981 if (!is_startup)
4982 {
4983 g2=HiddenGroup(g, 2, 1, NULL);
4984 b1 =PushButton(g2, "Accept", DOT_DoParams);
4985 b2 =PushButton(g2, "Cancel", DOT_CancelParams);
4986 SetObjectExtra(b1, (Pointer)pip, StdCleanupExtraProc);
4987 SetObjectExtra(b2, (Pointer)pip, StdCleanupExtraProc);
4988 }
4989 else
4990 {
4991 g2=HiddenGroup(g, 2, 1, NULL);
4992 b1 =PushButton(g2, "Accept", DOT_StartDOTPLOT);
4993 b2 =PushButton(g2, "Cancel", DOT_QuitProg);
4994 SetObjectExtra(b1, (Pointer)pip, StdCleanupExtraProc);
4995 SetObjectExtra(b2, (Pointer)pip, StdCleanupExtraProc);
4996 }
4997
4998 Show(w);
4999
5000 }
5001
5002
DOT_ParametersProc(IteM i)5003 static void DOT_ParametersProc (IteM i)
5004 {
5005 DOTVibDataPtr vdp;
5006 WindoW temport, w;
5007 RecT rc;
5008
5009 w= (WindoW)ParentWindow(i);
5010 temport=SavePort(w);
5011 vdp=(DOTVibDataPtr)GetObjectExtra(w);
5012
5013 if (vdp==NULL) return;
5014
5015 DOT_SetupParamsWindow(vdp, FALSE, FALSE);
5016
5017 Select(vdp->panel);
5018 ObjectRect(vdp->panel, &rc);
5019
5020 InsetRect(&rc, -1, -1);
5021 InvalRect (&rc);
5022 RestorePort (temport);
5023 Update();
5024
5025 }
5026
5027
5028 /*_________________________________________(DOT_GetNthSeqFromAlign)_____
5029
5030 Purpose : Fill nucleotide sequence buffers.
5031
5032 ____________________________________________________________________*/
5033
DOT_GetNthSeqFromAlign(SeqAlignPtr sap,Int4 n)5034 static Uint1Ptr DOT_GetNthSeqFromAlign (SeqAlignPtr sap, Int4 n)
5035 {
5036 BioseqPtr bsp=NULL;
5037 SeqIdPtr sip=NULL;
5038 SeqPortPtr spp;
5039 Uint1Ptr seq, temp_seq;
5040 Uint1 strand;
5041 Int4 start=0, stop=0;
5042 Int4 len, buf_len;
5043 Int2 ctr, i;
5044 Uint1Ptr buffer;
5045
5046 sip=AlnMgr2GetNthSeqIdPtr(sap, n);
5047 bsp=BioseqLockById(sip);
5048 strand=AlnMgr2GetNthStrand(sap, n);
5049 AlnMgr2GetNthSeqRangeInSA(sap, n, &start, &stop);
5050 len=AlnMgr2GetAlnLength(sap, FALSE);
5051 /* initialize buffers */
5052 buffer=(Uint1Ptr) MemNew (sizeof(Uint1)*101);
5053 MemSet((Pointer)buffer, '\0', sizeof(Char)*101);
5054 temp_seq = NULL;
5055 if (!(seq = (Uint1Ptr) MemNew (sizeof(Uint1)*(len)))) goto error;
5056 if (ISA_aa (bsp->mol))
5057 {
5058 spp = SeqPortNew (bsp, start, stop, strand, Seq_code_ncbi2na);
5059 }
5060 else if (ISA_na(bsp->mol))
5061 {
5062 spp = SeqPortNew (bsp, start, stop, strand, Seq_code_ncbistdaa);
5063 }
5064 if (spp == NULL)
5065 {
5066 ErrPostEx (SEV_ERROR, 0, 0, "%s", "DOT- Failed on SeqPortNew");
5067 goto error;
5068 }
5069 temp_seq = seq;
5070 do
5071 {
5072 ctr = SeqPortRead(spp, buffer, 100);
5073
5074 if (ctr > 0)
5075 {
5076 i = 0;
5077 buf_len = ctr;
5078 while (buf_len > 0)
5079 {
5080 *temp_seq = (Uint1)buffer[i];
5081 temp_seq++;
5082 i++;
5083 buf_len--;
5084 }
5085 }
5086 } while (ctr != SEQPORT_EOF * -1);
5087 SeqPortFree(spp);
5088 if (buffer) MemFree(buffer);
5089 BioseqUnlock(bsp);
5090 return seq;
5091 error:
5092 BioseqUnlock(bsp);
5093 return NULL;
5094 }
5095 /*_______________________________________________(DOT_DoZoom)___
5096
5097 Purpose : Zoom into a specific region of sequence.
5098
5099 ____________________________________________________________________*/
5100
DOT_DoZoom(ButtoN b)5101 void DOT_DoZoom(ButtoN b)
5102 {
5103 WindoW w;
5104 DOTparamsinfoPtr zip;
5105 DOTVibDataPtr vdp;
5106 DOTSelDataPtr data;
5107 DOTMainDataPtr mip;
5108 Int4 viewersize, newLen;
5109 RecT rc;
5110
5111
5112 w=(WindoW)ParentWindow(b);
5113 if (!(zip=(DOTparamsinfoPtr)GetObjectExtra(b))) return;
5114 if (!(vdp=(DOTVibDataPtr)GetObjectExtra(w))) return;
5115 mip=vdp->mip;
5116 data=vdp->data;
5117 Remove(w);
5118
5119 DOT_FreeHitsArray(mip->hitlist, mip->index);
5120
5121
5122 mip->q_start= DOT_GetValue(zip->xstart);
5123 mip->q_stop=DOT_GetValue(zip->xstop);
5124 mip->s_start=DOT_GetValue(zip->ystart);
5125 mip->s_stop=DOT_GetValue(zip->ystop);
5126 mip->qlen=mip->q_stop-mip->q_start + 1;
5127 mip->slen=mip->s_stop-mip->s_start + 1;
5128 mip->first_pass = TRUE;
5129 mip->cutoff_score=0;
5130
5131 DOT_GetSeqs(mip, TRUE);
5132 if (DOT_BuildHitList(mip, TRUE, TRUE)<0)
5133 {
5134 Message(MSG_ERROR, "DOT- No hits");
5135 return; /* no hits */
5136 }
5137
5138 ObjectRect(vdp->panel, &rc);
5139 viewersize=MIN(rc.right-rc.left,rc.bottom-rc.top)-vdp->HORZ_MARGIN;
5140 newLen=MAX(mip->qlen, mip->slen);
5141 vdp->comp=DOT_Compression(newLen, viewersize);
5142
5143 DOT_ImageSizeHasChanged(vdp);
5144
5145 DOT_UpdateMainPanel(vdp, TRUE);
5146
5147 if (zip) MemFree(zip);
5148
5149 }
5150
5151
5152
DOT_CancelZoom(ButtoN b)5153 static void DOT_CancelZoom (ButtoN b)
5154 {
5155 WindoW w;
5156 DOTparamsinfoPtr zip;
5157
5158 w=ParentWindow(b);
5159 zip=(DOTparamsinfoPtr)GetObjectExtra(b);
5160 if (zip) MemFree(zip);
5161 Remove(w);
5162 }
5163
5164
DOT_SetupZoomWindow(DOTVibDataPtr vdp)5165 void DOT_SetupZoomWindow(DOTVibDataPtr vdp)
5166 {
5167 GrouP g, zoomg, bottomg, maingroup;
5168 ButtoN b1, b2;
5169 DOTparamsinfoPtr zip;
5170 DOTMainDataPtr mip;
5171 WindoW w;
5172 Char str1[20], str2[20], str3[20], str4[20];
5173
5174 if (!(zip=(DOTparamsinfoPtr)MemNew(sizeof(DOTparamsinfo)))) return;
5175 mip=vdp->mip;
5176 w = FixedWindow(-50, -25, -1, -1, "Zoom", StdCloseWindowProc);
5177 SetObjectExtra(w, (Pointer)vdp, NULL);
5178 maingroup=HiddenGroup(w, -1, 2, NULL);
5179 g = NormalGroup(maingroup, 1, 2, "Zoom Parameters", systemFont, NULL);
5180 sprintf(str1, "%d", mip->q_start);
5181 sprintf(str2, "%d", mip->s_start);
5182 sprintf(str3, "%d", mip->q_stop);
5183 sprintf(str4, "%d", mip->s_stop);
5184 zoomg=HiddenGroup(g, 3, 2, NULL);
5185 StaticPrompt(zoomg, "x-axis:", 0, 0, systemFont, 'l');
5186 zip->xstart = DialogText(zoomg, str1, 5, NULL);
5187 zip->xstop = DialogText(zoomg, str3, 5, NULL);
5188 StaticPrompt(zoomg, "y-axis:", 0, 0, systemFont, 'l');
5189 zip->ystart = DialogText(zoomg, str2, 5, NULL);
5190 zip->ystop = DialogText(zoomg, str4, 5, NULL);
5191
5192 bottomg=HiddenGroup(maingroup, 2, 1, NULL);
5193 b1 =PushButton (bottomg, "Accept", DOT_DoZoom);
5194 b2 =PushButton(bottomg, "Cancel", DOT_CancelZoom);
5195 SetObjectExtra(b1, (Pointer)zip, StdCleanupExtraProc);
5196 SetObjectExtra(b2, (Pointer)zip, StdCleanupExtraProc);
5197
5198 Show(w);
5199 }
5200
DOT_ZoomProc(IteM i)5201 static void DOT_ZoomProc (IteM i)
5202 {
5203 DOTVibDataPtr vdp;
5204 WindoW temport, w;
5205
5206 w= (WindoW)ParentWindow(i);
5207 temport=SavePort(w);
5208 vdp=(DOTVibDataPtr)GetObjectExtra(w);
5209 if (vdp==NULL) return;
5210
5211 DOT_SetupZoomWindow(vdp);
5212
5213 }
5214
5215
5216 /*_______________________________________________(DOT_DoDisplayOpts)___
5217
5218 Purpose : Update Display
5219
5220 ____________________________________________________________________*/
5221
5222
DOT_DisplayOptsProc(ChoicE i)5223 static void DOT_DisplayOptsProc(ChoicE i)
5224
5225 {
5226 DOTVibDataPtr vdp;
5227 WindoW w;
5228 Int4 value;
5229
5230
5231 w=(WindoW)ParentWindow(i);
5232 vdp=(DOTVibDataPtr)GetObjectExtra(w);
5233
5234 value=GetValue(i);
5235
5236 if (value==1)
5237 {
5238 vdp->showDotPlot=TRUE;
5239 vdp->showALIGN=FALSE;
5240 }
5241 else if (value==2)
5242 {
5243 vdp->showDotPlot=TRUE;
5244 vdp->showALIGN=TRUE;
5245 }
5246 else if (value==3)
5247 {
5248 vdp->showDotPlot=FALSE;
5249 vdp->showALIGN=TRUE;
5250 }
5251
5252 DOT_UpdateMainPanel(vdp, TRUE);
5253
5254 }
5255
5256
5257 /*____________________________________________(DOT_AlignInfoNew)_____________
5258
5259
5260 Purpose : Initialize DOTAlignInfoPtr.
5261
5262 ____________________________________________________________________*/
DOT_AlignInfoNew(void)5263 extern DOTAlignInfoPtr DOT_AlignInfoNew (void)
5264 {
5265 DOTAlignInfoPtr alp;
5266
5267 alp=(DOTAlignInfoPtr)MemNew(sizeof(DOTAlignInfo));
5268 alp->VERT_MARGIN=50;
5269 alp->HORZ_MARGIN=80;
5270 alp->do_scale=TRUE;
5271 alp->showLabels=FALSE;
5272 alp->Fh=FontHeight();
5273 return alp;
5274 }
5275 /*___________________________(AlnMgr2GetNextLine)_______
5276
5277
5278 Purpose : Get starts and stops for a seq_align.
5279
5280 ____________________________________________________________________*/
AlnMgr2GetNextLine(SeqAlignPtr sap,AlnMsg2Ptr amp1,AlnMsg2Ptr amp2,Int4Ptr x1,Int4Ptr y1,Int4Ptr x2,Int4Ptr y2,Int4Ptr n)5281 static Boolean AlnMgr2GetNextLine(SeqAlignPtr sap, AlnMsg2Ptr amp1, AlnMsg2Ptr amp2, Int4Ptr x1, Int4Ptr y1, Int4Ptr x2, Int4Ptr y2, Int4Ptr n)
5282 {
5283 Boolean retval;
5284
5285 if (sap == NULL || amp1 == NULL || amp2 == NULL || x1 == NULL || y1 == NULL || x2 == NULL || y2 == NULL ||n == NULL)
5286 return FALSE;
5287 amp1->row_num = 1;
5288 retval = AlnMgr2GetNextAlnBit(sap, amp1);
5289 if (retval == FALSE)
5290 return FALSE;
5291 if (amp1->type == AM_SEQ)
5292 {
5293 *x1 = amp1->from_row;
5294 *x2 = amp1->to_row;
5295 } else
5296 {
5297 if (*x2 == 0)
5298 AlnMgr2GetNthSeqRangeInSA(sap, 1, x2, NULL);
5299 *x1 = *x2;
5300 }
5301 amp2->row_num = 2;
5302 retval = AlnMgr2GetNextAlnBit(sap, amp2);
5303 if (retval == FALSE)
5304 return FALSE;
5305 if (amp2->type == AM_SEQ)
5306 {
5307 *y1 = amp2->from_row;
5308 *y2 = amp2->to_row;
5309 } else
5310 {
5311 if (*y2 == 0)
5312 AlnMgr2GetNthSeqRangeInSA(sap, 2, y2, NULL);
5313 *y1 = *y2;
5314 }
5315 *n++;
5316 return TRUE;
5317 }
5318
5319 /*____________________________________________(DOT_GetAlign)___________
5320
5321
5322 Purpose : Get seq_align coordinates, store as DOTAlnList array.
5323
5324 ____________________________________________________________________*/
DOT_GetAlign(DOTAlignInfoPtr alp)5325 static Boolean DOT_GetAlign (DOTAlignInfoPtr alp)
5326 {
5327 AlnMsg2Ptr amp1, amp2;
5328 BioseqPtr bsp1, bsp2;
5329 SeqAlignPtr sap=NULL, salp=NULL, sap_tmp=NULL;
5330 DOTAlnPtr Aln;
5331 Boolean saved=FALSE;
5332 Int4 x1, y1, x2, y2, numlines=0, n=0, i=0;
5333 Int4 xlen=0, ylen=0;
5334 Uint1 q_strand, s_strand;
5335
5336 if (alp==NULL || alp->sap==NULL)
5337 {
5338 ArrowCursor();
5339 return(FALSE);
5340 }
5341 sap=alp->sap;
5342
5343 if (sap->segtype==SAS_DISC)
5344 {
5345 salp=(SeqAlignPtr)sap->segs;
5346 }
5347 else
5348 {
5349 salp=sap;
5350 }
5351 alp->sip=AlnMgr2GetNthSeqIdPtr(salp, 1);
5352 alp->sip->next=AlnMgr2GetNthSeqIdPtr(salp, 2);
5353 alp->title = NULL;
5354 sap_tmp=salp;
5355 while (sap_tmp){
5356 numlines +=AlnMgr2GetNumSegs(sap_tmp);
5357 sap_tmp=sap_tmp->next;
5358 }
5359 amp1 = AlnMsgNew2();
5360 amp2 = AlnMsgNew2();
5361 amp1->from_aln = amp2->from_aln = 0;
5362 amp1->to_aln = amp2->to_aln = -1;
5363 amp1->row_num = 1;
5364 amp2->row_num = 2;
5365 alp->Alnlist=(DOTAlnPtr PNTR) MemNew(sizeof(DOTAlnPtr)*numlines);
5366 n = x1 = x2 = y1 = y2 = i =xlen=ylen=0;
5367 while (salp)
5368 {
5369 q_strand = AlnMgr2GetNthStrand(salp, 1);
5370 s_strand = AlnMgr2GetNthStrand(salp, 2);
5371 while (AlnMgr2GetNextAlnBit(salp, amp1) && AlnMgr2GetNextAlnBit(salp, amp2))
5372 {
5373 if (amp1->type == AM_SEQ && amp2->type == AM_SEQ){
5374 saved=TRUE;
5375 Aln=(DOTAlnPtr)MemNew(sizeof(DOTAln));
5376 Aln->sap=salp;
5377
5378 if (q_strand == Seq_strand_minus){
5379 Aln->q_start = x2;
5380 Aln->q_stop = x1;
5381 }
5382 else {
5383 Aln->q_start=x1;
5384 Aln->q_stop=x2;
5385 }
5386 if (s_strand == Seq_strand_minus){
5387 Aln->s_start = y2;
5388 Aln->s_stop = y1;
5389 }
5390 else {
5391 Aln->s_start=y1;
5392 Aln->s_stop=y2;
5393 }
5394 Aln->primID=i+1;
5395 Aln->entityID=salp->idx.entityID;
5396 Aln->itemID=salp->idx.itemID;
5397 Aln->class=dotaln_GENERAL;
5398 alp->Alnlist[i]=Aln;
5399 i++;
5400 }
5401 }
5402 AlnMsgReNew2(amp1);
5403 AlnMsgReNew2(amp2);
5404 amp1->to_aln = amp2->to_aln = -1;
5405 salp=salp->next;
5406 }
5407
5408 if (!saved)
5409 {
5410 ErrPostEx(SEV_ERROR, 0, 0, "no alignments found");
5411 return (FALSE);
5412 }
5413 alp->index=i;
5414 AlnMsgFree2(amp1);
5415 AlnMsgFree2(amp2);
5416
5417 bsp1=BioseqLockById(alp->sip);
5418 bsp2=BioseqLockById(alp->sip->next);
5419 alp->xstart=0;
5420 alp->xlen=bsp1->length;
5421 alp->ystart=0;
5422 alp->ylen=bsp2->length;
5423 BioseqUnlock(bsp1);
5424 BioseqUnlock(bsp2);
5425 return (TRUE);
5426 }
5427
5428 /*___________________________(DOT_FillEachAlign)___________
5429
5430
5431 Purpose : Fill Align structure from SeqAlignPtr PNTR
5432
5433 __________________________________________________________*/
DOT_FillEachAlign(DOTAlnPtr aln_list,SeqAlignPtr PNTR saps,Int4Ptr start,Int4 numsaps,Int4 class)5434 static DOTAlnPtr DOT_FillEachAlign(DOTAlnPtr aln_list, SeqAlignPtr PNTR saps, Int4Ptr start, Int4 numsaps, Int4 class)
5435 {
5436 Int4 i = 0;
5437 Int4 j = 0;
5438 AlnMsg2Ptr amp1, amp2;
5439 DOTAlnPtr Aln = NULL, Aln_head = NULL, aln_end = NULL, Aln_next = NULL;
5440 Uint1 q_strand, s_strand;
5441
5442
5443 amp1 = AlnMsgNew2();
5444 amp2 = AlnMsgNew2();
5445 amp1->from_aln = amp2->from_aln = 0;
5446 amp1->to_aln = amp2->to_aln = -1;
5447 amp1->row_num = 1;
5448 amp2->row_num = 2;
5449 numsaps+=*start;
5450 if (aln_list){
5451 aln_end=aln_list;
5452 while (aln_end->next != NULL)
5453 aln_end=aln_end->next;
5454 }
5455
5456 if (numsaps > 0)
5457 {
5458 for(i=*start; i<numsaps; i++){
5459 q_strand = AlnMgr2GetNthStrand(saps[i-*start], 1);
5460 s_strand = AlnMgr2GetNthStrand(saps[i-*start], 2);
5461 while(AlnMgr2GetNextAlnBit(saps[i-*start], amp1) && AlnMgr2GetNextAlnBit(saps[i-*start], amp2))
5462 {
5463 if (amp1->type == AM_SEQ && amp2->type == AM_SEQ) {
5464 Aln=(DOTAlnPtr)MemNew(sizeof(DOTAln));
5465 Aln->sap=saps[i-*start];
5466 if (q_strand == Seq_strand_minus) {
5467 Aln->q_start = amp1->to_row;
5468 Aln->q_stop = amp1->from_row;
5469 }
5470 else {
5471 Aln->q_start = amp1->from_row;
5472 Aln->q_stop = amp1->to_row;
5473 }
5474 if (s_strand == Seq_strand_minus) {
5475 Aln->s_start = amp2->to_row;
5476 Aln->s_stop = amp2->from_row;
5477 }
5478 else {
5479 Aln->s_start = amp2->from_row;
5480 Aln->s_stop = amp2->to_row;
5481 }
5482 Aln->primID=j+1;
5483 Aln->entityID=saps[i-*start]->idx.entityID;
5484 Aln->itemID=saps[i-*start]->idx.itemID;
5485 Aln->class=class;
5486 if (Aln_head){
5487 Aln_next->next=Aln;
5488 Aln_next=Aln_next->next;
5489 }
5490 else {
5491 Aln_head=Aln_next=Aln;
5492 }
5493 j++;
5494 }
5495 }
5496
5497 AlnMsgReNew2(amp1);
5498 AlnMsgReNew2(amp2);
5499 amp1->row_num = 1;
5500 amp2->row_num = 2;
5501 }
5502 }
5503
5504 AlnMsgFree2(amp1);
5505 AlnMsgFree2(amp2);
5506
5507 *start+=j;
5508
5509 if (aln_list)
5510 aln_end->next=Aln_head;
5511 else
5512 aln_list=Aln_head;
5513
5514 return aln_list;
5515 }
5516 /*____________________________________________(DOT_IndexAlnlist)___________
5517
5518
5519 Purpose : index linked list of alignment coordinates into an array
5520
5521 ____________________________________________________________________*/
DOT_IndexAlnlist(DOTAlnPtr aln_head,Int4Ptr index)5522 static DOTAlnPtr PNTR DOT_IndexAlnlist(DOTAlnPtr aln_head, Int4Ptr index)
5523 {
5524 DOTAlnPtr PNTR Alnlist=NULL;
5525 Int4 i=0;
5526
5527 if (!aln_head || !index)
5528 return NULL;
5529
5530 if(!(Alnlist=(DOTAlnPtr PNTR) MemNew(sizeof(DOTAlnPtr)* (*index)))){
5531 return NULL;
5532 }
5533 if (*index == 0 && aln_head) {
5534 i = 0;
5535 while (aln_head) {
5536 Alnlist[i] = aln_head;
5537 aln_head = aln_head->next;
5538 i++;
5539 }
5540 *index = i;
5541 return Alnlist;
5542 }
5543
5544 for (i=0; i<*index; i++){
5545 Alnlist[i]=aln_head;
5546 aln_head=aln_head->next;
5547 }
5548 return Alnlist;
5549 }
5550 /*____________________________________________(DOT_FillAlignInfoPointer)___________
5551
5552
5553 Purpose : Get seq_align coordinates, store as DOTAlnList array.
5554
5555 ____________________________________________________________________*/
DOT_FillAlignInfoPointer(DOTAlignInfoPtr alp)5556 extern Boolean DOT_FillAlignInfoPointer (DOTAlignInfoPtr alp)
5557 {
5558 AlnMsg2Ptr amp1, amp2;
5559 DOTAlnPtr PNTR Alnlist=NULL;
5560 DOTAlnPtr aln_list=NULL;
5561 BioseqPtr bsp1, bsp2;
5562 SeqAlignPtr sap=NULL, salp=NULL, sap_tmp=NULL;
5563 Boolean saved=FALSE;
5564 Int4 numsaps = 0, numlines = 0;
5565 Int4 i=0, n=0;
5566 Int4 xstart=0, xstop=0;
5567 Int4 ystart=0, ystop=0;
5568 Char q_idbuf[42]={""}, s_idbuf[42]={""};
5569 AMAlignIndex2Ptr amaip=NULL;
5570 Int4 alncount=0;
5571
5572 if (alp==NULL){
5573 ArrowCursor();
5574 return(FALSE);
5575 }
5576 sap=alp->sap;
5577 if (!sap) return FALSE;
5578 if (sap->saip != NULL && sap->saip->indextype == INDEX_PARENT){
5579 amaip=(AMAlignIndex2Ptr)sap->saip;
5580 if (!amaip) return FALSE;
5581 salp=(SeqAlignPtr)sap->segs;
5582 }
5583 else {
5584 amaip=NULL;
5585 salp=sap;
5586 }
5587
5588 n = AlnMgr2GetNumRows(salp);
5589 if (n <= 0){
5590 ArrowCursor();
5591 return(FALSE);
5592 }
5593 if (n > 2){
5594 ErrPostEx(SEV_ERROR, 0, 0, "alignment contains greater than two rows");
5595 SeqIdSetFree(alp->sip);
5596 ArrowCursor();
5597 return FALSE;
5598 }
5599 alp->sip=AlnMgr2GetNthSeqIdPtr(salp, 1);
5600 alp->sip->next=AlnMgr2GetNthSeqIdPtr(salp, 2);
5601
5602 SeqIdWrite(alp->sip, q_idbuf,PRINTID_FASTA_SHORT, 41);
5603 SeqIdWrite(alp->sip->next, s_idbuf,PRINTID_FASTA_SHORT, 41);
5604 alp->name1=StringSave(q_idbuf);
5605 alp->name2=StringSave(s_idbuf);
5606 bsp1=BioseqLockById(alp->sip);
5607 bsp2=BioseqLockById(alp->sip->next);
5608
5609 if (ISA_aa (bsp1->mol) && ISA_aa (bsp2->mol))
5610 {
5611 alp->is_na = FALSE;
5612 }
5613 else if (ISA_na(bsp1->mol) && ISA_na (bsp2->mol))
5614 {
5615 alp->is_na = TRUE;
5616 alp->matrix=(Int4Ptr PNTR)DOT_DNAScoringMatrix(-3, 1, 4);
5617 }
5618 else
5619 goto error;
5620
5621 sap_tmp=salp;
5622 while (sap_tmp){
5623 sap_tmp=sap_tmp->next;
5624 numsaps++;
5625 }
5626
5627 amp1 = AlnMsgNew2();
5628 amp2 = AlnMsgNew2();
5629 amp1->to_aln = amp2->to_aln = -1;
5630 if (amaip){
5631 aln_list = DOT_FillEachAlign(aln_list, amaip->saps, &alncount, numsaps, 1);
5632 saved=TRUE;
5633 }
5634 else {
5635 aln_list = DOT_FillEachAlign(aln_list, &salp, &alncount, numsaps, 1);
5636 saved=TRUE;
5637 }
5638
5639 if (!saved)
5640 {
5641 ErrPostEx(SEV_WARNING, 0, 0, "Invalid SeqAlign format");
5642 return (FALSE);
5643 }
5644 numlines = alncount;
5645 Alnlist = DOT_IndexAlnlist(aln_list, &numlines);
5646 if (!Alnlist) goto error;
5647 alp->Alnlist=Alnlist;
5648 AlnMgr2GetNthSeqRangeInSA(salp, 1, &xstart, &xstop);
5649 AlnMgr2GetNthSeqRangeInSA(salp, 2, &ystart, &ystop);
5650 alp->xstart=xstart;
5651 alp->xlen=xstop-xstart+1;
5652 alp->ystart=ystart;
5653 alp->ylen=ystop-ystart+1;
5654 alp->index=numlines;
5655
5656 ArrowCursor();
5657 BioseqUnlock(bsp1);
5658 BioseqUnlock(bsp2);
5659 return TRUE;
5660 error:
5661 BioseqUnlock(bsp1);
5662 BioseqUnlock(bsp2);
5663 return FALSE;
5664 }
5665
5666 /*____________________________________________(DOT_FillAlignInfoPointer)___________
5667
5668
5669 Purpose : Get seq_align coordinates, store as DOTAlnList array.
5670
5671 ____________________________________________________________________*/
DOT_Prob_FillAlignInfoPointer(DOTAlignInfoPtr alp)5672 extern Boolean DOT_Prob_FillAlignInfoPointer (DOTAlignInfoPtr alp)
5673 {
5674 AlnMsg2Ptr amp1, amp2;
5675 DOTAlnPtr PNTR Alnlist=NULL;
5676 DOTAlnPtr aln_list=NULL;
5677 BioseqPtr bsp1, bsp2;
5678 SeqAlignPtr sap=NULL, salp=NULL, sap_tmp=NULL;
5679 Boolean saved=FALSE;
5680 Int4 numsaps = 0, numlines = 0;
5681 Int4 i=0, n=0;
5682 Int4 xstart=0, xstop=0;
5683 Int4 ystart=0, ystop=0;
5684 Char q_idbuf[42]={""}, s_idbuf[42]={""};
5685 AMAlignIndex2Ptr amaip=NULL;
5686 Int4 alncount=0;
5687
5688 if (alp==NULL){
5689 ArrowCursor();
5690 return(FALSE);
5691 }
5692 sap=alp->sap;
5693 if (!sap) return FALSE;
5694
5695 if (sap->segtype==SAS_DISC){
5696 salp=(SeqAlignPtr)sap->segs;
5697 }
5698 else {
5699 salp=sap;
5700 }
5701 if (sap->saip == NULL)
5702 AlnMgr2IndexLite(sap);
5703 amaip = (AMAlignIndex2Ptr)sap->saip;
5704
5705 n = AlnMgr2GetNumRows(salp);
5706 if (n <= 0){
5707 ArrowCursor();
5708 return(FALSE);
5709 }
5710 if (n > 2){
5711 ErrPostEx(SEV_ERROR, 0, 0, "alignment contains greater than two rows");
5712 SeqIdSetFree(alp->sip);
5713 ArrowCursor();
5714 return FALSE;
5715 }
5716 alp->sip=AlnMgr2GetNthSeqIdPtr(amaip->saps[0], 1);
5717 alp->sip->next=AlnMgr2GetNthSeqIdPtr(amaip->saps[0], 2);
5718
5719 SeqIdWrite(alp->sip, q_idbuf,PRINTID_FASTA_SHORT, 41);
5720 SeqIdWrite(alp->sip->next, s_idbuf,PRINTID_FASTA_SHORT, 41);
5721 alp->name1=StringSave(q_idbuf);
5722 alp->name2=StringSave(s_idbuf);
5723 bsp1=BioseqLockById(alp->sip);
5724 bsp2=BioseqLockById(alp->sip->next);
5725 if (bsp2 == NULL){
5726 if (bsp1 != NULL)
5727 BioseqUnlock(bsp1);
5728 }
5729 if (ISA_aa (bsp1->mol) && ISA_aa (bsp2->mol))
5730 {
5731 alp->is_na = FALSE;
5732 }
5733 else if (ISA_na(bsp1->mol) && ISA_na (bsp2->mol))
5734 {
5735 alp->is_na = TRUE;
5736 alp->matrix=(Int4Ptr PNTR)DOT_DNAScoringMatrix(-3, 1, 4);
5737 }
5738 else
5739 goto error;
5740
5741 amp1 = AlnMsgNew2();
5742 amp2 = AlnMsgNew2();
5743 amp1->to_aln = amp2->to_aln = -1;
5744 if (amaip){
5745 aln_list = DOT_FillEachAlign(aln_list, amaip->saps, &alncount, amaip->numsaps, 1);
5746 saved=TRUE;
5747 }
5748
5749 if (!saved)
5750 {
5751 ErrPostEx(SEV_WARNING, 0, 0, "no alignments saved");
5752 return (FALSE);
5753 }
5754 numlines = alncount;
5755 Alnlist = DOT_IndexAlnlist(aln_list, &numlines);
5756 if (!Alnlist) goto error;
5757 alp->Alnlist=Alnlist;
5758 alp->index=numlines;
5759
5760 if (sap->segtype == SAS_DISC){
5761 alp->xstart = 1;
5762 alp->xlen = bsp1->length;
5763 alp->ystart = 1;
5764 alp->ylen = bsp2->length;
5765 }
5766 else {
5767 AlnMgr2GetNthSeqRangeInSA(salp, 1, &xstart, &xstop);
5768 AlnMgr2GetNthSeqRangeInSA(salp, 2, &ystart, &ystop);
5769 alp->xstart=xstart;
5770 alp->xlen=xstop-xstart+1;
5771 alp->ystart=ystart;
5772 alp->ylen=ystop-ystart+1;
5773 }
5774
5775 ArrowCursor();
5776 BioseqUnlock(bsp1);
5777 BioseqUnlock(bsp2);
5778 return TRUE;
5779 error:
5780 BioseqUnlock(bsp1);
5781 BioseqUnlock(bsp2);
5782 return FALSE;
5783 }
5784
DOT_GetNthSeqIdFromScp(SCP_ResultPtr scp,Int2 n)5785 static SeqIdPtr DOT_GetNthSeqIdFromScp(SCP_ResultPtr scp, Int2 n)
5786 {
5787 SeqAlignPtr PNTR saps;
5788
5789
5790 if (scp->saps != NULL)
5791 saps=scp->saps;
5792 else if (scp->large_outliers !=NULL)
5793 saps=scp->large_outliers;
5794 else if (scp->small_outliers !=NULL)
5795 saps=scp->small_outliers;
5796 else
5797 return NULL;
5798
5799 return(AlnMgr2GetNthSeqIdPtr(saps[0], n));
5800
5801 }
5802
5803
5804 /*____________________________________________(DOT_FillFromScp)___________
5805
5806
5807 Purpose : Get seq_align coordinates, store as DOTAlnList array.
5808
5809 ____________________________________________________________________*/
DOT_FillFromScp(DOTAlignInfoPtr alp,SCP_ResultPtr scp)5810 static Boolean DOT_FillFromScp (DOTAlignInfoPtr alp, SCP_ResultPtr scp)
5811 {
5812 BioseqPtr bsp1=NULL, bsp2=NULL;
5813 DOTAlnPtr PNTR Alnlist=NULL;
5814 DOTAlnPtr aln_list =NULL;
5815 Int4 start=0;
5816 Boolean saved=FALSE;
5817 Char q_idbuf[42]={""}, s_idbuf[42]={""};
5818
5819 if (alp==NULL)
5820 {
5821 ArrowCursor();
5822 return(FALSE);
5823 }
5824 if (scp->saps == NULL && scp->small_outliers ==NULL && scp->large_outliers==NULL) return (FALSE);
5825
5826 alp->sip = DOT_GetNthSeqIdFromScp(scp, 1);
5827 alp->sip->next = DOT_GetNthSeqIdFromScp(scp, 2);
5828 SeqIdWrite(alp->sip, q_idbuf,PRINTID_FASTA_SHORT, 41);
5829 SeqIdWrite(alp->sip->next, s_idbuf,PRINTID_FASTA_SHORT, 41);
5830 alp->name1=StringSave(q_idbuf);
5831 alp->name2=StringSave(s_idbuf);
5832 bsp1=BioseqLockById(alp->sip);
5833 bsp2=BioseqLockById(alp->sip->next);
5834
5835 if (bsp2 == NULL){
5836 if (bsp1 != NULL)
5837 BioseqUnlock(bsp1);
5838 }
5839
5840 if (ISA_aa (bsp1->mol) && ISA_aa (bsp2->mol))
5841 {
5842 alp->is_na = FALSE;
5843 }
5844 else if (ISA_na(bsp1->mol) && ISA_na (bsp2->mol))
5845 {
5846 alp->is_na = TRUE;
5847 alp->matrix=(Int4Ptr PNTR)DOT_DNAScoringMatrix(-3, 1, 4);
5848 }
5849 else
5850 goto error;
5851
5852 if (scp->saps){
5853 aln_list = DOT_FillEachAlign(aln_list, scp->saps, &start, scp->numsaps, 1);
5854 saved=TRUE;
5855 }
5856 if (scp->large_outliers){
5857 /* start= scp->numsaps; */
5858 aln_list = DOT_FillEachAlign(aln_list, scp->large_outliers, &start, scp->numlarge_outliers, 2);
5859 saved=TRUE;
5860 }
5861 if (scp->small_outliers){
5862 /* start= scp->numsaps+scp->numlarge_outliers; */
5863 aln_list = DOT_FillEachAlign(aln_list, scp->small_outliers, &start, scp->numsmall_outliers, 3);
5864 saved=TRUE;
5865 }
5866 if (!saved)
5867 {
5868 ErrPostEx(SEV_WARNING, 0, 0, "no alignments saved");
5869 goto error;
5870 }
5871 Alnlist = DOT_IndexAlnlist(aln_list, &start);
5872 if (!Alnlist) goto error;
5873 alp->Alnlist=Alnlist;
5874 alp->xstart=1;
5875 alp->xlen=scp->len1;
5876 alp->ystart=1;
5877 alp->ylen=scp->len2;
5878 alp->index=start;
5879 ArrowCursor();
5880 BioseqUnlock(bsp1);
5881 BioseqUnlock(bsp2);
5882 return TRUE;
5883 error:
5884 BioseqUnlock(bsp1);
5885 BioseqUnlock(bsp2);
5886 return (FALSE);
5887 }
5888 /*_______________________________________________(DOT_DoBlast)___
5889
5890 Purpose : Calls Blast2Seq.
5891
5892 ____________________________________________________________________*/
5893
DOT_get_eval(Int4 exp)5894 static FloatHi DOT_get_eval(Int4 exp)
5895 {
5896 FloatHi eval;
5897 Int4 i;
5898
5899 eval = 1;
5900 for (i=1; i<=exp; i++)
5901 {
5902 eval = eval/10;
5903 }
5904 return eval;
5905 }
5906
DOT_DoBlast(ButtoN b)5907 static void DOT_DoBlast (ButtoN b)
5908 {
5909 DOTVibDataPtr vdp;
5910 WindoW w;
5911 DOTblastinfoPtr bip;
5912 BioseqPtr bsp1, bsp2;
5913 Int2 i;
5914 Int2 progval;
5915 Uint2 entityID=0;
5916 CharPtr text=NULL;
5917 Boolean is_local;
5918 Char eval[11]={""};
5919 Char str[20]={""};
5920 SCP_ResultPtr scp=NULL;
5921 DOTMainDataPtr mip=NULL;
5922
5923
5924 WatchCursor();
5925 w = (WindoW)ParentWindow(b);
5926 vdp = (DOTVibDataPtr)GetObjectExtra(w);
5927 if (vdp == NULL) goto end;
5928 mip = vdp->mip;
5929 if (mip == NULL) goto end;
5930
5931 Remove(w);
5932
5933 bip = (DOTblastinfoPtr)GetObjectExtra(b);
5934 if (bip == NULL || bip->bsp1 == NULL || bip->bsp2 == NULL)
5935 goto end;
5936 bsp1 = bip->bsp1;
5937 bsp2 = bip->bsp2;
5938
5939 progval = GetValue (bip->progname);
5940 if (progval == 1)
5941 StringCpy(str, "blastn");
5942 else
5943 StringCpy(str, "blastp");
5944
5945 i = GetValue(bip->localorglobal);
5946 if (i == 1)
5947 is_local = TRUE;
5948 else
5949 is_local = FALSE;
5950
5951 if (vdp->alp){ /* previous alignment*/
5952 vdp->alp->pict = NULL;
5953 DOT_ExitAlign(vdp->alp);
5954 vdp->showALIGN = FALSE;
5955 }
5956
5957 scp = SCP_CompareOrderOrganizeBioseqs(bsp1, bsp2, mip->qslp, mip->sslp, str, mip->word_size, mip->tree_limit);
5958 Remove(w);
5959 vdp->showALIGN=TRUE;
5960 SetValue(vdp->displayOpts2, 2);
5961 vdp->alp=DOT_AlignInfoNew();
5962 vdp->alp->sap=NULL;
5963 vdp->alp->entityID=scp->saps[0]->idx.entityID;
5964 vdp->alp->itemID=scp->saps[0]->idx.itemID;
5965 if (!DOT_FillFromScp(vdp->alp, scp))
5966 {
5967 vdp->alp->pict=NULL;
5968 DOT_ExitAlign(vdp->alp);
5969 vdp->showALIGN=FALSE;
5970 }
5971
5972 DOT_UpdateMainPanel(vdp, TRUE);
5973 end:
5974 if (text) MemFree(text);
5975 ArrowCursor();
5976 return;
5977 }
5978
5979
DOT_CancelBlast(ButtoN b)5980 static void DOT_CancelBlast (ButtoN b)
5981 {
5982 WindoW w;
5983 DOTblastinfoPtr bip;
5984
5985 w=ParentWindow(b);
5986 bip=(DOTblastinfoPtr)GetObjectExtra(b);
5987 if (bip) MemFree(bip);
5988 Remove(w);
5989 }
5990
5991
DOT_SetupBlastWindow(DOTVibDataPtr vdp)5992 void DOT_SetupBlastWindow(DOTVibDataPtr vdp)
5993 {
5994 DOTblastinfoPtr bip;
5995 DOTMainDataPtr mip;
5996 ButtoN b;
5997 ButtoN b1;
5998 GrouP maingroup, topg, localg, eANDwg;
5999 GrouP submitg, blastg, bottomg, g3;
6000 Char title[255]={""};
6001 WindoW w;
6002
6003
6004
6005 if (!(bip = (DOTblastinfoPtr)MemNew(sizeof(DOTblastinfo)))) return;
6006 mip=vdp->mip;
6007
6008 bip->bsp1 = mip->qbsp;
6009 bip->bsp2 = mip->sbsp;
6010 StringCat(title, mip->qname);
6011 StringCat(title, " vs. ");
6012 StringCat(title, mip->sname);
6013 w = FixedWindow(-50, -25, -1, -1, title, StdCloseWindowProc);
6014 SetObjectExtra(w, vdp, NULL);
6015
6016 maingroup = HiddenGroup(w, 1, 4, NULL);
6017 StaticPrompt(maingroup, "Blast2Seqs Options ..", 0, popupMenuHeight, systemFont, 'l');
6018 topg = HiddenGroup (maingroup, -1, 2, NULL);
6019 blastg = NormalGroup(topg, 1,1, "Blast Program", systemFont,NULL);
6020 bip->progname = HiddenGroup(blastg, 5, 0, NULL);
6021 RadioButton(bip->progname, "blastn");
6022 RadioButton(bip->progname, "blastp");
6023 /* RadioButton(bip->progname, "blastx"); */
6024 /* RadioButton(bip->progname, "tblastn"); */
6025 /* RadioButton(bip->progname, "tblastx"); */
6026 SetValue(bip->progname, 1);
6027
6028 /*
6029 globalg = NormalGroup(topg,1, 1, "Alignment Type", systemFont,NULL);
6030 bip->localorglobal = HiddenGroup(globalg, 2, 1, NULL);
6031 RadioButton(bip->localorglobal, "Local");
6032 RadioButton(bip->localorglobal, "Global");
6033 SetValue(bip->localorglobal, 1);
6034
6035 bottomg=HiddenGroup(maingroup, 1, 2, NULL);
6036 localg = NormalGroup(bottomg, 1, 3, "Local Alignment Options", systemFont, NULL);
6037 g1 = NormalGroup(localg, 1,1, "", systemFont,NULL);
6038 gapsg = HiddenGroup(g1, 3, 2, NULL);
6039 bip->gapped = HiddenGroup(gapsg, 0, 2, NULL);
6040 RadioButton(bip->gapped, "gapped");
6041 RadioButton(bip->gapped, "ungapped");
6042 SetValue(bip->gapped, 1);
6043
6044 g2 = NormalGroup(localg, 1,1, "", systemFont,NULL);
6045 maskg=HiddenGroup(g2, 0, 2, NULL);
6046 bip->maskrep = CheckBox(maskg, "Mask Repeats", NULL);
6047 SetStatus(bip->maskrep, FALSE);
6048 bip->masksimple = CheckBox(maskg, "Mask Simple Sequence", NULL);
6049 SetStatus(bip->masksimple, TRUE);
6050 */
6051
6052 bottomg=HiddenGroup(maingroup, 1, 2, NULL);
6053
6054 localg = NormalGroup(bottomg, 1, 3, "Local Alignment Options", systemFont, NULL);
6055
6056 g3 = NormalGroup(localg, 1,1, "", systemFont,NULL);
6057 eANDwg = HiddenGroup(g3, 2, 2, NULL);
6058 StaticPrompt(eANDwg, "hitlist: e-", 0, 0, systemFont, 'l');
6059 bip->eval = DialogText(eANDwg, "10", 5, NULL);
6060 StaticPrompt(eANDwg, "wordsize:", 0, 0, systemFont, 'l');
6061 bip->wordsize = DialogText(eANDwg, "11", 5, NULL);
6062
6063
6064 submitg=HiddenGroup(bottomg, 2, 0, NULL);
6065 b = PushButton(submitg, "BLAST", DOT_DoBlast);
6066 b1 = PushButton(submitg, "Cancel", DOT_CancelBlast);
6067 SetObjectExtra(b1, (Pointer)bip, StdCleanupExtraProc);
6068 SetObjectExtra(b, (Pointer)bip, StdCleanupExtraProc);
6069 Show(w);
6070
6071 return;
6072
6073
6074 }
6075
6076
DOT_Blast2SeqProc(IteM i)6077 static void DOT_Blast2SeqProc (IteM i)
6078
6079 {
6080 DOTVibDataPtr vdp;
6081 WindoW w;
6082
6083 w= (WindoW)ParentWindow(i);
6084 vdp=(DOTVibDataPtr)GetObjectExtra(w);
6085 if (vdp==NULL) return;
6086 Enable(vdp->displayOpts1);
6087 DOT_SetupBlastWindow(vdp);
6088 }
6089
6090 /*________________________________________(DOT_FreeAlnList)_____________
6091
6092
6093 Purpose : Free list of alignments in align list, then free ptr.
6094
6095 ____________________________________________________________________*/
DOT_FreeAlnList(DOTAlignInfoPtr alp)6096 static void DOT_FreeAlnList(DOTAlignInfoPtr alp)
6097 {
6098 Int4 j, index;
6099 DOTAlnPtr PNTR alnL, aln;
6100
6101 if (alp->Alnlist)
6102 {
6103 alnL=alp->Alnlist;
6104 index=alp->index;
6105
6106 for(j = 0; j < index; j++)
6107 {
6108 aln=alnL[j];
6109 if (aln) MemFree(aln);
6110 }
6111
6112 if (alnL) MemFree(alnL);
6113 }
6114 }
6115 /*____________________________________________(DOT_ExitAlign)___________
6116
6117
6118 Purpose : Clears alignment structure
6119
6120 ____________________________________________________________________*/
DOT_ExitAlign(DOTAlignInfoPtr alp)6121 static void DOT_ExitAlign(DOTAlignInfoPtr alp){
6122
6123
6124 if (alp->Alnlist)
6125 DOT_FreeAlnList(alp);
6126
6127 if (alp->pict)
6128 DeletePicture(alp->pict);
6129 if (alp->is_na && alp->matrix)
6130 Free(alp->matrix);
6131
6132 if (alp) MemFree(alp);
6133
6134 }
6135 /*_______________________________________________(DOT_QuitMainWindow)___
6136
6137 Purpose : Quit Main window.
6138
6139 ____________________________________________________________________*/
6140
DOT_CloseMainWindow(IteM i)6141 static void DOT_CloseMainWindow (IteM i)
6142
6143 {
6144 WindoW w;
6145 DOTVibDataPtr vdp;
6146 DOTSelDataPtr data;
6147
6148 w=(WindoW)ParentWindow(i);
6149 vdp=(DOTVibDataPtr)GetObjectExtra(w);
6150 data=(DOTSelDataPtr)vdp->data;
6151 if (data) MemFree(data);
6152
6153 if (vdp->xname) MemFree(vdp->xname);
6154 if (vdp->yname) MemFree(vdp->yname);
6155 if (vdp->mip)
6156 DOT_FreeMainInfoPtrEx(vdp->mip);
6157
6158 if (vdp->alp)
6159 {
6160 if (vdp->alp->Alnlist)
6161 DOT_FreeAlnList(vdp->alp);
6162 if (vdp->alp) MemFree(vdp->alp);
6163 }
6164 if (vdp) MemFree(vdp);
6165
6166 Remove(w);
6167 }
6168
DOT_ExitProgram(IteM i)6169 static void DOT_ExitProgram(IteM i)
6170 {
6171 DOT_CloseMainWindow(i);
6172 QuitProgram();
6173 }
6174 /*________________________________________(DOT_GridProc)_____________
6175
6176 Purpose : Show or Hide the grid on Main window.
6177
6178 ____________________________________________________________________*/
6179
DOT_GridProc(ChoicE i)6180 static void DOT_GridProc (ChoicE i)
6181 {
6182 WindoW w;
6183 DOTVibDataPtr vdp;
6184 Int4 value;
6185
6186
6187 w = (WindoW)ParentWindow(i);
6188 vdp = (DOTVibDataPtr)GetObjectExtra (w);
6189
6190 value = GetValue(i);
6191 if (value==1)
6192 vdp->showGrid = TRUE;
6193 else
6194 vdp->showGrid = FALSE;
6195
6196 DOT_UpdateMainPanel(vdp, TRUE);
6197
6198 }
6199
6200 /*________________________________________(DOT_CreateWindowDetails)____
6201
6202 Purpose : Create buttons on the main window.
6203
6204 */
DOT_CreateWindowDetails(WindoW w,DOTVibDataPtr vdp)6205 static void DOT_CreateWindowDetails (WindoW w, DOTVibDataPtr vdp)
6206 {
6207 GrouP g, g1, g2;
6208 Char PNTR qname, PNTR sname;
6209 Int4 q_start, q_stop, s_start, s_stop;
6210 RecT rc;
6211 Int4 Xpixels, Ypixels, pixwidth;
6212 DOTMainDataPtr mip=NULL;
6213 DOTAlignInfoPtr alp=NULL;
6214 PrompT pr1, pr2;
6215
6216
6217 if (vdp->mip)
6218 mip=vdp->mip;
6219 if (vdp->alp)
6220 alp=vdp->alp;
6221 ObjectRect(w, &rc);
6222 pixwidth=rc.right-rc.left-10;
6223 g=HiddenGroup(w, 0, 3, NULL);
6224 SetGroupSpacing(g, 10, 20);
6225 g1=HiddenGroup(g, 7, 0, NULL);
6226 g2=HiddenGroup (g,4, 0, NULL);
6227 SetGroupSpacing(g2, 3, 0);
6228 pr2=StaticPrompt (g2, "Threshold-Ramp:", 0, 3*vdp->Fh/2, vdp->Fnt, 'l');
6229 pr1=StaticPrompt (g2, " 20%", 0, 3*vdp->Fh/2, vdp->Fnt, 'l');
6230 vdp->sdp.ScrollBar = ScrollBar (g2, 15, 5, DOT_ChangeMainViewerCutoff);
6231 pr1=StaticPrompt (g2, "100%", 0, 3*vdp->Fh/2, vdp->Fnt, 'l');
6232 if(mip){
6233 qname=mip->qname;
6234 sname=mip->sname;
6235 q_start=mip->q_start;
6236 s_start=mip->s_start;
6237 q_stop=mip->q_stop;
6238 s_stop=mip->s_start;
6239 }
6240 else if (alp){
6241 qname=alp->name1;
6242 sname=alp->name2;
6243 q_start=1;
6244 s_start=1;
6245 q_stop=alp->xlen;
6246 s_stop=alp->ylen;
6247 }
6248 sprintf(vdp->iInfo, "%s (x-axis)[%d..%d] vs. %s (y-axis)[%d..%d]", qname, q_start, q_stop, sname, s_start, s_stop);
6249 vdp->Infopanel= StaticPrompt (g, vdp->iInfo, pixwidth, popupMenuHeight, vdp->Fnt, 'l');
6250 SetObjectExtra(vdp->sdp.ScrollBar, vdp, NULL);
6251 CorrectBarMax (vdp->sdp.ScrollBar, 80); /* 100% */
6252 CorrectBarValue (vdp->sdp.ScrollBar, 60);/* 100% */
6253 /* Main Panel*/
6254 Xpixels = 600;
6255 Ypixels = 600;
6256 vdp->panel = AutonomousPanel (w, Xpixels, Ypixels, DOT_DisplayHits, DOT_VscrlProc, DOT_HscrlProc , 0, NULL, NULL);
6257 DOT_SetUpWin (w, vdp->panel, vdp);
6258 DOT_InitDataStruct(vdp);
6259 SetPanelClick (vdp->panel, DOT_ClickProc, DOT_DragProc, NULL, DOT_ReleaseProc);
6260
6261 }
6262
6263 /*________________________________________(DOT_ResizeMainWindow)_____________
6264
6265 Purpose : Resize function for main window.
6266
6267 ____________________________________________________________________*/
DOT_ResizeMainWindow(WindoW w)6268 static void DOT_ResizeMainWindow (WindoW w)
6269 {
6270 RecT rcP, rcW, rcHsb, rcVsb;
6271 DOTVibDataPtr vdp;
6272 WindoW temport;
6273 Int2 height, width, in , gap;
6274 Int4 VCurPos, HCurPos, vsbWidth, hsbHeight;
6275 PaneL p;
6276 BaR vsb, hsb;
6277 DOTSelDataPtr data;
6278
6279
6280 vdp = (DOTVibDataPtr) GetObjectExtra (w);
6281 if (vdp == NULL) return;
6282 p = vdp->panel;
6283
6284 if (p == NULL) return;
6285
6286 ObjectRect (w, &rcW);
6287 width = rcW.right - rcW.left;
6288 height = rcW.bottom - rcW.top;
6289 vsb = GetSlateVScrollBar ((SlatE) p);
6290 hsb = GetSlateHScrollBar ((SlatE) p);
6291
6292 SafeHide(vdp->Infopanel);
6293 SafeHide(p);
6294 Update();
6295
6296 GetPosition(vsb,&rcVsb);
6297 GetPosition(hsb,&rcHsb);
6298 GetPosition (p, &rcP);
6299
6300 in=2;
6301 gap=10;
6302 vsbWidth=rcVsb.right-rcVsb.left;
6303 hsbHeight=rcHsb.bottom-rcHsb.top;
6304
6305
6306 rcP.right = width - vsbWidth - in;
6307 rcP.bottom = height - hsbHeight -in;
6308
6309 SetPosition (p, &rcP);
6310 AdjustPrnt (p, &rcP, FALSE);
6311 /* Update(); */
6312
6313
6314 ObjectRect(p ,&rcP);
6315 temport=SavePort((WindoW)ParentWindow(p));
6316 Select(p);
6317
6318 DOT_ComputePanelSize(rcP, vdp, &(vdp->sdp.PgWdth), &(vdp->sdp.PgLen));
6319 DOT_SetScrlVals (vdp);
6320 if (vdp->data)
6321 {
6322 data=(DOTSelDataPtr)vdp->data;
6323 DOT_UpdateDataRects(data, rcP, vdp, FALSE);
6324 }
6325
6326 /*update scroll status*/
6327 VCurPos=GetBarValue(vsb);
6328 HCurPos=GetBarValue(hsb);
6329 DOT_VScrlUpdate(vdp, vsb, VCurPos);
6330 DOT_HScrlUpdate(vdp, hsb, HCurPos);
6331
6332 /* InvalRect(&rcP); */
6333 RestorePort(temport);
6334 SafeShow(vdp->Infopanel);
6335 SafeShow(vdp->panel);
6336 Update();
6337
6338 }
6339
6340 /*_______________________________________________(DOT_NewAnalysis)___
6341
6342
6343 Purpose : Close old windows, begin new analysis.
6344
6345 ____________________________________________________________________*/
DOT_NewAnalysis(ButtoN b)6346 static void DOT_NewAnalysis (ButtoN b)
6347 {
6348 WindoW w;
6349 DOTVibDataPtr vdp;
6350 DOTSelDataPtr data;
6351
6352 w = (WindoW)ParentWindow (b);
6353
6354 if (w!= NULL)
6355 {
6356 vdp = (DOTVibDataPtr)GetObjectExtra(w);
6357 data=(DOTSelDataPtr)vdp->data;
6358 if (data)
6359 MemFree(data);
6360 if (vdp)
6361 {
6362 if (vdp->mip)
6363 DOT_FreeMainInfoPtrEx(vdp->mip);
6364 MemFree(vdp);
6365 }
6366 Remove(w);
6367 }
6368
6369 if (vdp->ChildWin!= NULL)
6370 {
6371 DOT_CloseSequenceWindow(b);
6372 }
6373
6374 }
6375
6376
6377 /*____________________________________________(DOT_InitFont)_____________
6378
6379
6380 Purpose : Get font.
6381
6382 ____________________________________________________________________*/
6383
DOT_InitFont(DOTVibDataPtr vdp)6384 static void DOT_InitFont (DOTVibDataPtr vdp)
6385 {
6386 #ifdef WIN_MAC
6387 vdp->Fnt = ParseFont ("Monaco, 9");
6388 #endif
6389
6390 #ifdef WIN_MSWIN
6391 vdp->Fnt = ParseFont ("Courier, 7");
6392 #endif
6393
6394 #ifdef WIN_MOTIF
6395 vdp->Fnt = ParseFont ("fixed, 12");
6396 #endif
6397
6398 return;
6399
6400 }
6401
6402 /*____________________________________________(DOT_InitVibData)____________
6403
6404
6405 Purpose : Initialize DOTVibDataPtr for main window.
6406
6407 ____________________________________________________________________*/
6408
DOT_InitVibData(DOTVibDataPtr vdp)6409 static void DOT_InitVibData(DOTVibDataPtr vdp)
6410 {
6411
6412
6413 vdp->sdp.TrampPos=75;
6414 vdp->showGrid=TRUE;
6415 vdp->showDotPlot=TRUE;
6416
6417 DOT_InitFont(vdp);
6418 SelectFont(vdp->Fnt);
6419 /* vdp->charw=MaxCharWidth(); */
6420 /* vdp->Fh=FontHeight(); */
6421 /* temporarily while being called from ingenue */
6422 vdp->charw = 15;
6423 vdp->Fh = 17;
6424 vdp->VERT_MARGIN = 50;
6425 vdp->HORZ_MARGIN = 80;
6426 vdp->selectMode = 1;
6427
6428 }
6429 /*________________________________________(DOT_OpenSeqAnnotFile)_____________
6430
6431
6432 Purpose : Open a seqannot file with a seqalign and update the viewer.
6433
6434 ____________________________________________________________________*/
DOT_OpenSeqAnnotFile(IteM i)6435 static void DOT_OpenSeqAnnotFile(IteM i)
6436 {
6437 DOTVibDataPtr vdp;
6438 FILE* afile;
6439 Char path [PATH_MAX];
6440 Pointer dataptr=NULL;
6441 Uint2 datatype;
6442 SeqAnnotPtr sanp=NULL;
6443 SeqAlignPtr sap=NULL;
6444 DOTAlignInfoPtr alp;
6445
6446
6447 vdp=(DOTVibDataPtr)GetObjectExtra(ParentWindow(i));
6448
6449 if (GetInputFileName(path, sizeof(path), "", "TEXT"))
6450 {
6451 if (path != NULL)
6452 {
6453 if (!(afile = FileOpen(path, "r"))){
6454 ErrPostEx(SEV_FATAL, 0, 0, "file not found");
6455 return;
6456 }
6457 dataptr = ReadAsnFastaOrFlatFile (afile, &datatype, NULL, FALSE, FALSE, TRUE, FALSE);
6458 if (!dataptr){
6459 ErrPostEx(SEV_FATAL, 0, 0, "bad seqannot file");
6460 goto end;
6461 }
6462 sanp = (SeqAnnotPtr)(dataptr);
6463 sap = (SeqAlignPtr)(sanp->data);
6464 if (!sap){
6465 ErrPostEx(SEV_FATAL, 0, 0, "bad seqannot file");
6466 goto end;
6467 }
6468 if (sap->saip != NULL)
6469 AMAlignIndex2Free2(sap);
6470 sap->saip=NULL;
6471 AlnMgr2IndexLite(sap);
6472 AlnMgr2SortAlnSetByNthRowPos(sap, 1);
6473
6474 Enable((Nlm_Handle)vdp->displayOpts1);
6475 if (vdp->alp){ /* discard previous alignment*/
6476 vdp->alp->pict=NULL;
6477 DOT_ExitAlign(vdp->alp);
6478 }
6479 alp=DOT_AlignInfoNew();
6480 alp->sap = sap;
6481 if (!DOT_FillAlignInfoPointer(alp)){
6482 vdp->showALIGN=FALSE;
6483 goto end;
6484 }
6485 vdp->alp=alp;
6486 vdp->showALIGN=TRUE;
6487 SetValue(vdp->displayOpts2, 2);
6488 }
6489
6490 end:
6491 DOT_UpdateMainPanel(vdp, TRUE);
6492 fclose(afile);
6493 }
6494
6495 return;
6496 }
6497
6498 /*________________________________________(DOT_MakeMainViewer)_____________
6499
6500
6501 Purpose : Create main window.
6502
6503 ____________________________________________________________________*/
6504
DOT_MakeMainViewer(DOTMainDataPtr mip,DOTAlignInfoPtr alp)6505 NLM_EXTERN Boolean DOT_MakeMainViewer (DOTMainDataPtr mip, DOTAlignInfoPtr alp)
6506 {
6507 WindoW w;
6508 Int2 margins;
6509 MenU m1, m2, m3, m4, s1, s2;
6510 IteM i;
6511 ChoicE ch;
6512 DOTVibDataPtr vdp;
6513 SeqAlignPtr sap=NULL;
6514 Char title[60]={""};
6515
6516 if (!mip && !alp) return FALSE;
6517 vdp=(DOTVibDataPtr)MemNew(sizeof(DOTVibData));
6518 if (!vdp) return FALSE;
6519 DOT_InitVibData(vdp);
6520 margins = 4*stdCharWidth;
6521 if (mip){
6522 vdp->mip=mip;
6523 vdp->xlen=mip->qlen;
6524 vdp->ylen=mip->slen;
6525 vdp->xstart=mip->q_start;
6526 vdp->ystart=mip->s_start;
6527 vdp->xstop=mip->q_stop;
6528 vdp->ystop=mip->s_stop;
6529 vdp->xname=mip->qname;
6530 vdp->yname=mip->sname;
6531 vdp->strand1=mip->qstrand;
6532 vdp->strand2=mip->sstrand;
6533 vdp->showDotPlot=TRUE;
6534 } else if (alp){
6535 sap=alp->sap;
6536 vdp->alp=alp;
6537 if(!mip){
6538 vdp->xlen=alp->xlen;
6539 vdp->ylen=alp->ylen;
6540 vdp->xstart=alp->xstart;
6541 vdp->ystart=alp->ystart;
6542 vdp->xstop=alp->xstart+alp->xlen-1;
6543 vdp->ystop=alp->ystart+alp->ylen-1;
6544 vdp->xname=alp->name1;
6545 vdp->yname=alp->name2;
6546 vdp->strand1=AlnMgr2GetNthStrand(alp->sap, 1);
6547 vdp->strand2=AlnMgr2GetNthStrand(alp->sap, 2);
6548 }
6549 vdp->showALIGN=TRUE;
6550 }
6551 sprintf(title, "%s", vdp->xname);
6552 StringCat(title, " vs. ");
6553 StringCat(title, vdp->yname);
6554 #ifdef WIN_MAC
6555 DOT_SetupMenus ();
6556 #endif
6557 w = DocumentWindow (margins, margins, 800, 800, title, StdCloseWindowProc, DOT_ResizeMainWindow);
6558 #ifndef WIN_MAC
6559 DOT_SetupMenus ();
6560 #endif
6561 SetObjectExtra(w, (Pointer)vdp, NULL);
6562 m1 = PulldownMenu (w, "File");
6563 /* CommandItem (m1, "New analysis", DOT_NewAnalysis); */
6564 i=CommandItem(m1, "Alignment (SeqAnnot) File...", DOT_OpenSeqAnnotFile);
6565 Disable(i);
6566 CommandItem (m1, "Close",DOT_CloseMainWindow);
6567 SeparatorItem(m1);
6568 i = CommandItem (m1, "Exit",DOT_ExitProgram);
6569 #ifndef DOT_STANDALONE
6570 Disable(i);
6571 #endif
6572 m2 = PulldownMenu (w, "Options");
6573 vdp->displayOpts1=SubMenu(m2,"Display");
6574 if (!sap) Disable((Nlm_Handle)vdp->displayOpts1);
6575 vdp->displayOpts2=ChoiceGroup (vdp->displayOpts1, DOT_DisplayOptsProc);
6576 ChoiceItem (vdp->displayOpts2, "Dots ONLY");
6577 ChoiceItem (vdp->displayOpts2, "Dots & Aligns");
6578 ChoiceItem (vdp->displayOpts2, "Aligns ONLY");
6579 SetValue(vdp->displayOpts2,2);
6580 SeparatorItem(m2);
6581 s1=SubMenu(m2,"Grid");
6582 ch=ChoiceGroup (s1, DOT_GridProc);
6583 ChoiceItem (ch, "show");
6584 ChoiceItem (ch, "hide");
6585 SeparatorItem(m2);
6586 s2=SubMenu(m2,"Select Mode");
6587 Disable(s2);
6588 ch=ChoiceGroup (s2, DOT_ModeProc);
6589 ChoiceItem (ch, "Sequence");
6590 ChoiceItem (ch, "Features");
6591 SetValue(ch, 1);
6592 SeparatorItem(m2);
6593 i = CommandItem (m2, "Parameters ..", DOT_ParametersProc);
6594 SetObjectExtra(i, vdp, NULL);
6595 Disable(i);
6596 m3 = PulldownMenu(w, "Resize");
6597 i = CommandItem (m3, "Reduce", DOT_ReduceSizeProc);
6598 i = CommandItem (m3, "Enlarge", DOT_EnlargeSizeProc);
6599 i = CommandItem (m3, "Original", DOT_OriginalSizeProc);
6600 i = CommandItem (m3, "Zoom into region..", DOT_ZoomProc);
6601 SetObjectExtra(i, vdp, NULL);
6602 m4 = PulldownMenu (w, "Analysis");
6603 i = CommandItem(m4, "Blast2Seq ..", DOT_Blast2SeqProc);
6604 if (!mip && alp)
6605 Disable(i);
6606 vdp->MainWin = w;
6607 DOT_CreateWindowDetails(w, vdp);
6608 RealizeWindow(w);
6609 Show (w);
6610 ProcessEvents();
6611 return TRUE;
6612 }
6613
6614
DOT_SetColor(SegmenT seg1,Int1 code,Boolean is_autopanel)6615 static void DOT_SetColor(SegmenT seg1, Int1 code, Boolean is_autopanel)
6616 {
6617
6618 if (!is_autopanel){
6619 if (code==dotaln_BEST)
6620 AddAttribute(seg1, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
6621 if (code==dotaln_OUTLYING_LARGE)
6622 AddAttribute(seg1, COLOR_ATT, BLUE_COLOR, 0, 0, 0, 0);
6623 if (code==dotaln_OUTLYING_SMALL)
6624 AddAttribute(seg1, COLOR_ATT, GREEN_COLOR, 0, 0, 0, 0);
6625 if (code==dotaln_GENERAL)
6626 AddAttribute(seg1, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
6627 }
6628 else{
6629 if (code==dotaln_BEST)
6630 Red();
6631 if (code==dotaln_OUTLYING_LARGE)
6632 Blue();
6633 if (code==dotaln_OUTLYING_SMALL)
6634 Green();
6635 if (code==dotaln_GENERAL)
6636 Black();
6637 }
6638
6639 }
6640
6641
DOT_DeselectPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)6642 static Boolean DOT_DeselectPrim (SegmenT seg, PrimitivE prim, Uint2 segID,Uint2 primID, Uint2 primCt, VoidPtr userdata)
6643
6644 {
6645
6646 Int1 highlight;
6647 VieweR v;
6648
6649 v = (VieweR)userdata;
6650 GetPrimDrawAttribute (prim, NULL, NULL, NULL, NULL, NULL, &highlight);
6651 if (highlight != PLAIN_PRIMITIVE)
6652 HighlightPrimitive (v, seg, prim, PLAIN_PRIMITIVE);
6653
6654 return TRUE;
6655 }
6656
DOT_FindAlignment(DOTVibDataPtr vdp2,Uint2 primID)6657 static DOTAlnPtr DOT_FindAlignment(DOTVibDataPtr vdp2, Uint2 primID)
6658 {
6659 DOTAlnPtr aln, salp;
6660 DOTAlnPtr PNTR alnL;
6661 DOTSelDataPtr data;
6662 Boolean lt_fixed=FALSE, rb_fixed=FALSE;
6663
6664
6665 if (!vdp2->alp && !vdp2->alp->Alnlist) return NULL;
6666 salp=(DOTAlnPtr)MemNew(sizeof(DOTAln));
6667 salp->show=align_plot;
6668 data=vdp2->data;
6669 alnL=vdp2->alp->Alnlist;
6670 aln=alnL[primID-1];
6671 salp->sap=aln->sap;
6672 salp->q_start=aln->q_start;
6673 salp->q_stop=aln->q_stop;
6674 salp->s_start=aln->s_start;
6675 salp->s_stop=aln->s_stop;
6676 salp->primID=(Uint2)primID;
6677
6678 return salp;
6679 }
6680
6681
6682 /*____________________________________________(DOT_AlignPlotGivenSeqAlign)_____________
6683
6684
6685 Purpose : Run alignment display given seqalignpointer
6686
6687 ____________________________________________________________________*/
DOT_AlignPlotGivenSeqAlign(SeqAlignPtr sap)6688 NLM_EXTERN Boolean DOT_AlignPlotGivenSeqAlign(SeqAlignPtr sap)
6689 {
6690 DOTAlignInfoPtr alp;
6691
6692 alp=DOT_AlignInfoNew();
6693 alp->sap = sap;
6694 alp->entityID = sap->idx.entityID;
6695 if (!DOT_FillAlignInfoPointer(alp)){
6696 MemFree(alp);
6697 return FALSE;
6698 }
6699
6700 if (!DOT_MakeMainViewer(NULL, alp))
6701 return FALSE;
6702 return TRUE;
6703 }
6704 /*____________________________________________(DOT_AlignPlotGivenScp)_____________
6705
6706
6707 Purpose : Run alignment display given seqalignpointer
6708
6709 ____________________________________________________________________*/
DOT_AlignPlotGivenScp(SCP_ResultPtr scp)6710 NLM_EXTERN Boolean DOT_AlignPlotGivenScp(SCP_ResultPtr scp)
6711 {
6712 DOTAlignInfoPtr alp;
6713
6714 alp=DOT_AlignInfoNew();
6715 alp->sap=NULL;
6716 alp->entityID=scp->saps[0]->idx.entityID;
6717 alp->itemID=1;
6718 if (!DOT_FillFromScp(alp, scp)){
6719 MemFree(alp);
6720 return FALSE;
6721 /* QuitProgram(); */
6722 }
6723 if (!DOT_MakeMainViewer(NULL, alp))
6724 return FALSE;
6725 return TRUE;
6726 }
6727
6728 /*_______________________________(DOT_RegDiagsDisplay)_____
6729
6730
6731 Purpose : Registered function for Dot Diag display.
6732
6733 _________________________________________________________*/
6734
DOT_RegDiagsDisplay(Pointer data)6735 NLM_EXTERN Int2 LIBCALLBACK DOT_RegDiagsDisplay(Pointer data)
6736 {
6737 OMProcControlPtr ompcp = NULL;
6738 SeqAlignPtr sap = NULL;
6739
6740 ompcp = (OMProcControlPtr) data;
6741 if (ompcp == NULL || ompcp->proc == NULL) {
6742 ErrPostEx (SEV_ERROR, 0, 0, "Data NULL [1]");
6743 return OM_MSG_RET_ERROR;
6744 }
6745
6746 switch (ompcp->input_itemtype) {
6747 case OBJ_SEQALIGN :
6748 sap = (SeqAlignPtr) ompcp->input_data;
6749 break;
6750 case 0 :
6751 return OM_MSG_RET_ERROR;
6752 default :
6753 return OM_MSG_RET_ERROR;
6754 }
6755
6756 if (sap == NULL) {
6757 ErrPostEx (SEV_ERROR, 0, 0, "Input Data is NULL or is not a seqalign");
6758 return OM_MSG_RET_ERROR;
6759 }
6760
6761 if (!DOT_AlignPlotGivenSeqAlign(sap))
6762 return OM_MSG_RET_ERROR;
6763 else
6764 return OM_MSG_RET_DONE;
6765
6766 }
6767
6768
6769 /*_______________________________(Scoop Functions)_____
6770
6771
6772 Purpose : Run Blast 2 Seqs and sort results into high scoring, large outlying and small outlying alignments.
6773
6774 _________________________________________________________*/
6775
6776
SCP_CompareOrderOrganizeBioseqs(BioseqPtr bsp1,BioseqPtr bsp2,SeqLocPtr slp1,SeqLocPtr slp2,CharPtr progname,Int4 wordsize,Int4 hitlist_size)6777 NLM_EXTERN SCP_ResultPtr SCP_CompareOrderOrganizeBioseqs(BioseqPtr bsp1, BioseqPtr bsp2, SeqLocPtr slp1, SeqLocPtr slp2, CharPtr progname, Int4 wordsize, Int4 hitlist_size)
6778 {
6779 Int4 i;
6780 BLAST_OptionsBlkPtr options;
6781 SeqAlignPtr sap;
6782 SeqAlignPtr sap_head;
6783 SeqAlignPtr sap_prev;
6784 SCP_ResultPtr scp;
6785 SCP_ResultPtr scp_large;
6786 SCP_ResultPtr scp_small;
6787 Int4 start;
6788 Int4 stop;
6789 SeqAnnotPtr sanp;
6790 SeqEntryPtr sep;
6791 Uint2 entityID=0;
6792 Uint4 itemID=0;
6793
6794 if (bsp1 == NULL || bsp2 == NULL)
6795 return NULL;
6796 options = BLASTOptionNew(progname, FALSE);
6797 options->filter_string = StringSave("m L;R");
6798 options->expect_value = 10;
6799 /* Fasika's changes */
6800
6801 options->hitlist_size = hitlist_size;
6802 options->wordsize = wordsize;
6803 if (slp1 !=NULL && slp2 !=NULL){
6804 sap = BlastTwoSequencesByLoc(slp1, slp2, progname, options);
6805 }
6806 else {
6807 sap = BlastTwoSequences(bsp1, bsp2, progname, options);
6808 }
6809
6810 sep = SeqMgrGetSeqEntryForData (bsp1);
6811 entityID = ObjMgrGetEntityIDForChoice(sep);
6812 sanp = SeqAnnotForSeqAlign (sap);
6813 if (sanp == NULL) return NULL;
6814 entityID =DOT_AttachSeqAnnotToSeqEntry(entityID, sanp, bsp1);
6815 SeqMgrIndexFeatures (entityID, (Pointer)bsp1);
6816 itemID =GatherItemIDByData(entityID, OBJ_BIOSEQ, (Pointer)bsp1);
6817 /* end of Fasika's changes */
6818
6819 AlnMgr2IndexLite(sap);
6820 scp = (SCP_ResultPtr)MemNew(sizeof(SCP_Result));
6821 scp->len1=bsp1->length;
6822 scp->len2=bsp2->length;
6823 SCP_OrganizeAlnsInSet(sap, SCP_FUZZ, scp, 1);
6824 BLASTOptionDelete(options);
6825 fprintf(stdout, "Sequence 1 length: %d\n", bsp1->length);
6826 fprintf(stdout, "Sequence 2 length: %d\n", bsp2->length);
6827 SCP_GetNthSeqRangeInSASet(scp->saps, scp->numsaps, 1, &start, &stop);
6828 fprintf(stdout, "The best alignments cover from %d to %d of sequence 1\n", start, stop);
6829 scp_large = scp_small = NULL;
6830 if (scp->numlarge_outliers > 0)
6831 {
6832 sap_head = sap_prev = scp->large_outliers[0];
6833 for (i=1; i<scp->numlarge_outliers; i++)
6834 {
6835 sap_prev->next = scp->large_outliers[i];
6836 sap_prev = sap_prev->next;
6837 }
6838 sap = SeqAlignNew();
6839 sap->segtype = SAS_DISC;
6840 sap->segs = (Pointer)(sap_head);
6841 AlnMgr2IndexLite(sap);
6842 scp_large = (SCP_ResultPtr)MemNew(sizeof(SCP_Result));
6843 SCP_OrganizeAlnsInSet(sap, SCP_FUZZ, scp_large, 1);
6844 SCP_GetNthSeqRangeInSASet(scp_large->saps, scp_large->numsaps, 1, &start, &stop);
6845 fprintf(stdout, "Large repeats cover from %d to %d of sequence 1\n", start, stop);
6846 }
6847 if (scp->numsmall_outliers > 0)
6848 {
6849 sap_head = sap_prev = scp->small_outliers[0];
6850 for (i=1; i<scp->numsmall_outliers; i++)
6851 {
6852 sap_prev->next = scp->small_outliers[i];
6853 sap_prev = sap_prev->next;
6854 }
6855 sap = SeqAlignNew();
6856 sap->segtype = SAS_DISC;
6857 sap->segs = (Pointer)(sap_head);
6858 AlnMgr2IndexLite(sap);
6859 scp_small = (SCP_ResultPtr)MemNew(sizeof(SCP_Result));
6860 SCP_OrganizeAlnsInSet(sap, SCP_FUZZ, scp_small, 1);
6861 SCP_GetNthSeqRangeInSASet(scp_small->saps, scp_small->numsaps, 1, &start, &stop);
6862 fprintf(stdout, "Small repeats cover from %d to %d of sequence 1\n", start, stop);
6863 }
6864 return scp;
6865 }
6866
SCP_OrganizeAlnsInSet(SeqAlignPtr sap,Int4 fuzz,SCP_ResultPtr scp,Int4 n)6867 extern void SCP_OrganizeAlnsInSet(SeqAlignPtr sap, Int4 fuzz, SCP_ResultPtr scp, Int4 n)
6868 {
6869 AMAlignIndex2Ptr amaip;
6870 Boolean conflict;
6871 Int4 curr;
6872 Int4 i;
6873 Int4 indextype;
6874 SeqAlignPtr large=NULL;
6875 SeqAlignPtr large_outliers=NULL;
6876 SeqAlignPtr keep=NULL;
6877 SeqAlignPtr keepers=NULL;
6878 SeqAlignPtr salp=NULL;
6879 SeqAlignPtr salp_head=NULL;
6880 SeqAlignPtr salp_prev=NULL;
6881 SeqAlignPtr small=NULL;
6882 SeqAlignPtr small_outliers=NULL;
6883 SCP_nPtr PNTR spin=NULL;
6884 Int4 start;
6885 Int4 stop;
6886 Int4 strand;
6887
6888 if (sap == NULL || sap->saip == NULL || sap->saip->indextype != INDEX_PARENT)
6889 return;
6890 if (n > 2)
6891 return;
6892 amaip = (AMAlignIndex2Ptr)(sap->saip);
6893 indextype = amaip->alnstyle;
6894 /* make sure that everything is on the plus strand of the nth sequence */
6895 for (i=0; i<amaip->numsaps; i++)
6896 {
6897 salp = amaip->saps[i];
6898 AssignIDsInEntity(1, OBJ_SEQALIGN, (Pointer)salp);
6899 strand = AlnMgr2GetNthStrand(salp, n);
6900 if (strand == Seq_strand_minus)
6901 {
6902 SAIndex2Free2(salp->saip);
6903 salp->saip = NULL;
6904 salp->next = NULL;
6905 SeqAlignListReverseStrand(salp);
6906 AlnMgr2IndexSingleChildSeqAlign(salp);
6907 }
6908 }
6909 /* spin structure: n1 = which alignment, n2 = start on first row, n3 =
6910 alignment length on 1st row, n4 = start on 2nd row, n5 = 2nd strand */
6911 spin = (SCP_nPtr PNTR)MemNew((amaip->numsaps)*sizeof(SCP_nPtr));
6912 for (i=0; i<amaip->numsaps; i++)
6913 {
6914 spin[i] = (SCP_nPtr)MemNew(sizeof(SCP_n));
6915 salp = amaip->saps[i];
6916 spin[i]->n1 = i;
6917 AlnMgr2GetNthSeqRangeInSA(salp, n, &start, &stop);
6918 spin[i]->n3 = stop - start;
6919 spin[i]->n2 = start;
6920 AlnMgr2GetNthSeqRangeInSA(salp, 3-n, &start, &stop);
6921 spin[i]->n4 = start;
6922 strand = AlnMgr2GetNthStrand(salp, 3-n);
6923 if (strand == Seq_strand_minus)
6924 spin[i]->n5 = -1;
6925 else
6926 spin[i]->n5 = 1;
6927 }
6928 HeapSort((Pointer)spin, (size_t)(amaip->numsaps), sizeof(SCP_nPtr), SCP_CompareSpins);
6929 strand = spin[0]->n5;
6930 for (i=1; i<amaip->numsaps; i++)
6931 {
6932 if (spin[i]->n5 != strand)
6933 {
6934 salp = amaip->saps[spin[i]->n1];
6935 salp->next = NULL;
6936 SeqAlignFree(salp);
6937 amaip->saps[spin[i]->n1] = NULL;
6938 spin[i]->n1 = -1;
6939 }
6940 }
6941 large_outliers = small_outliers = keepers = NULL;
6942 scp->numsaps++;
6943 salp = amaip->saps[spin[0]->n1];
6944 salp->next = NULL;
6945 keepers = keep = salp;
6946 for (curr=0; curr<amaip->numsaps; curr++)
6947 {
6948 if (spin[curr]->n1 != -1)
6949 {
6950 for (i=curr+1; i<amaip->numsaps; i++)
6951 {
6952 if (spin[i]->n1 != -1)
6953 {
6954 conflict = FALSE;
6955 /* check first for conflict on first row */
6956 if (spin[i]->n2 + spin[i]->n3 - 1 > spin[curr]->n2 + fuzz)
6957 {
6958 if (spin[i]->n2 < spin[curr]->n2)
6959 conflict = TRUE;
6960 }
6961 if (spin[i]->n2 < spin[curr]->n2 + spin[curr]->n3 - 1 - fuzz)
6962 {
6963 if (spin[i]->n2 + spin[i]->n3 - 1 > spin[curr]->n2 + spin[curr]->n3 - 1)
6964 conflict = TRUE;
6965 }
6966 if (spin[i]->n2 >= spin[curr]->n2)
6967 {
6968 if (spin[i]->n2 + spin[i]->n3 - 1 <= spin[curr]->n2 + spin[curr]->n3 - 1)
6969 conflict = TRUE;
6970 }
6971 /* then check for conflict and consistency on second row */
6972 if (spin[i]->n2 + spin[i]->n3 - 1 < spin[curr]->n2 + fuzz)
6973 {
6974 if (strand == 1)
6975 {
6976 if (spin[i]->n4 + spin[i]->n3 - 1 > spin[curr]->n4 + fuzz)
6977 conflict = TRUE;
6978 } else if (strand == -1)
6979 {
6980 if (spin[curr]->n4 + spin[curr]->n3 - 1 - fuzz > spin[i]->n4)
6981 conflict = TRUE;
6982 }
6983 } else
6984 {
6985 if (strand == 1)
6986 {
6987 if (spin[i]->n4 < spin[curr]->n4 + spin[curr]->n3 - fuzz)
6988 conflict = TRUE;
6989 } else if (strand == -1)
6990 {
6991 if (spin[i]->n4 + spin[i]->n3 - 1 - fuzz > spin[curr]->n4)
6992 conflict = TRUE;
6993 }
6994 }
6995 if (conflict)
6996 {
6997 salp = amaip->saps[spin[i]->n1];
6998 salp->next = NULL;
6999 if (spin[i]->n3 >= SCP_LARGE)
7000 {
7001 scp->numlarge_outliers++;
7002 if (large_outliers != NULL)
7003 {
7004 large->next = salp;
7005 large = salp;
7006 } else
7007 large_outliers = large = salp;
7008 } else
7009 {
7010 scp->numsmall_outliers++;
7011 if (small_outliers != NULL)
7012 {
7013 small->next = salp;
7014 small = salp;
7015 } else
7016 small_outliers = small = salp;
7017 }
7018 amaip->saps[spin[i]->n1] = NULL;
7019 spin[i]->n1 = -1;
7020 }
7021 }
7022 }
7023 }
7024 }
7025 for (i=1; i<amaip->numsaps; i++)
7026 {
7027 if (spin[i]->n1 != -1)
7028 {
7029 scp->numsaps++;
7030 salp = amaip->saps[spin[i]->n1];
7031 salp->next = NULL;
7032 if (keepers == NULL)
7033 keepers = keep = salp;
7034 else
7035 {
7036 keep->next = salp;
7037 keep = salp;
7038 }
7039 }
7040 }
7041 scp->small_outliers = (SeqAlignPtr PNTR)MemNew((scp->numsmall_outliers)*sizeof(SeqAlignPtr));
7042 small = small_outliers;
7043 i = 0;
7044 while (small != NULL)
7045 {
7046 scp->small_outliers[i] = small;
7047 i++;
7048 small = small->next;
7049 }
7050 scp->large_outliers = (SeqAlignPtr PNTR)MemNew((scp->numlarge_outliers)*sizeof(SeqAlignPtr));
7051 large = large_outliers;
7052 i = 0;
7053 while (large != NULL)
7054 {
7055 scp->large_outliers[i] = large;
7056 i++;
7057 large = large->next;
7058 }
7059 scp->saps = (SeqAlignPtr PNTR)MemNew((scp->numsaps)*sizeof(SeqAlignPtr));
7060 keep = keepers;
7061 i = 0;
7062 while (keep != NULL)
7063 {
7064 scp->saps[i] = keep;
7065 i++;
7066 keep = keep->next;
7067 }
7068
7069 salp_head = salp_prev = NULL;
7070 for (i=0; i<amaip->numsaps; i++)
7071 {
7072 MemFree(spin[i]);
7073 if (amaip->saps[i] != NULL)
7074 {
7075 amaip->saps[i]->next = NULL;
7076 if (salp_prev != NULL)
7077 {
7078 salp_prev->next = amaip->saps[i];
7079 salp_prev = salp_prev->next;
7080 } else
7081 salp_head = salp_prev = amaip->saps[i];
7082 }
7083 }
7084 sap->segs = (Pointer)(salp_head);
7085 AMAlignIndexFree(sap->saip);
7086 sap->saip = NULL;
7087 AlnMgrIndexLite(sap);
7088 MemFree(spin);
7089 }
7090
SCP_CompareSpins(VoidPtr ptr1,VoidPtr ptr2)7091 static int LIBCALLBACK SCP_CompareSpins(VoidPtr ptr1, VoidPtr ptr2)
7092 {
7093 SCP_nPtr spin1;
7094 SCP_nPtr spin2;
7095
7096 spin1 = *((SCP_nPtr PNTR) ptr1);
7097 spin2 = *((SCP_nPtr PNTR) ptr2);
7098 if (spin1 == NULL || spin2 == NULL)
7099 return 0;
7100 if (spin1->n3 > spin2->n3)
7101 return -1;
7102 if (spin1->n3 < spin2->n3)
7103 return 1;
7104 if (spin1->n2 < spin2->n2)
7105 return -1;
7106 if (spin1->n2 > spin2->n2)
7107 return 1;
7108 return 0;
7109 }
7110
SCP_GetNthSeqRangeInSASet(SeqAlignPtr PNTR saparray,Int4 numsaps,Int4 n,Int4Ptr start,Int4Ptr stop)7111 static void SCP_GetNthSeqRangeInSASet(SeqAlignPtr PNTR saparray, Int4 numsaps, Int4 n, Int4Ptr start, Int4Ptr stop)
7112 {
7113 Int4 i;
7114 SeqAlignPtr salp;
7115 Int4 start_tmp;
7116 Int4 stop_tmp;
7117 Int4 tmp1;
7118 Int4 tmp2;
7119
7120 start_tmp = stop_tmp = -1;
7121 for (i=0; i<numsaps; i++)
7122 {
7123 salp = saparray[i];
7124 if (n > salp->dim)
7125 {
7126 if (start)
7127 *start = -1;
7128 if (stop)
7129 *stop = -1;
7130 return;
7131 }
7132 AlnMgrGetNthSeqRangeInSA(salp, n, &tmp1, &tmp2);
7133 if (tmp1 < start_tmp || start_tmp == -1)
7134 start_tmp = tmp1;
7135 if (tmp2 > stop_tmp)
7136 stop_tmp = tmp2;
7137 }
7138 if (start)
7139 *start = start_tmp;
7140 if (stop)
7141 *stop = stop_tmp;
7142 }
7143