1 /*
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: twopv.c
27 *
28 * Author(s): John Kuzio
29 *
30 * Version Creation Date: 98-01-01
31 *
32 * $Revision: 6.6 $
33 *
34 * File Description: region of best blast identity
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * --------------------------------------------------------------------------
40 * $Log: twopv.c,v $
41 * Revision 6.6 1998/12/18 16:24:58 kuzio
42 * big GIs
43 *
44 * Revision 6.5 1998/09/16 18:40:36 kuzio
45 * cvs logging
46 *
47 * ==========================================================================
48 */
49
50 #include <ncbi.h>
51 #include <vibrant.h>
52 #include <accentr.h>
53 #include <gather.h>
54 #include <tofasta.h>
55 #include <blast.h>
56 #include <urkutil.h>
57 #include <urkptpf.h>
58 #include <seqscrl.h>
59 #include <gxydraw.h>
60 #include <picture.h>
61
62 #define TOP_ERROR 1
63 static char _this_module[] = "twopv";
64 #undef THIS_MODULE
65 #define THIS_MODULE _this_module
66 static char _this_file[] = __FILE__;
67 #undef THIS_FILE
68 #define THIS_FILE _this_file
69
70 typedef struct xtrins
71 {
72 Int4 Xscale, Yscale;
73 SegmenT picture;
74 } XIS, PNTR XISPtr;
75
76 typedef struct xtrobj
77 {
78 Boolean flagParamWindow;
79 GrouP gpostblast;
80 Boolean flagPattern;
81 ButtoN bTG, bPG, bTF, bPF, bThis;
82 Int4 giT, giP;
83 GatherScopePtr gsp;
84 CharPtr filenameT, filenameP;
85 SeqEntryPtr sepT, sepP;
86 BioseqPtr bspT, bspP;
87 Int4 dotcutoff, dotcutoffmin, dotcutoffmax;
88 } XOS, PNTR XOSPtr;
89
90 static void CloseParamWindowProc (WindoW w);
91
GetBioseq(GatherContextPtr gcp)92 static Boolean GetBioseq (GatherContextPtr gcp)
93 {
94 XOSPtr xosp;
95 BioseqPtr bsp;
96 Int4 entrezgi;
97
98 if (gcp == NULL)
99 return FALSE;
100 if ((xosp = (XOSPtr) gcp->userdata) == NULL)
101 return FALSE;
102
103 if (xosp->bTG == xosp->bThis || xosp->bTF == xosp->bThis)
104 {
105 if (xosp->bspT != NULL)
106 return TRUE;
107 }
108 else
109 {
110 if (xosp->bspP != NULL)
111 return TRUE;
112 }
113
114 if (gcp->thistype != OBJ_BIOSEQ)
115 return TRUE;
116 if ((bsp = (BioseqPtr) (gcp->thisitem)) == NULL)
117 return TRUE;
118
119 if (xosp->giT > 0 && xosp->bTG == xosp->bThis)
120 {
121 entrezgi = GetGIForSeqId (bsp->id);
122 if (xosp->giT == entrezgi)
123 xosp->bspT = bsp;
124 return TRUE;
125 }
126 if (xosp->filenameT != NULL && xosp->bTF == xosp->bThis)
127 {
128 xosp->bspT = bsp;
129 return TRUE;
130 }
131 if (xosp->giP > 0 && xosp->bPG == xosp->bThis)
132 {
133 entrezgi = GetGIForSeqId (bsp->id);
134 if (xosp->giP == entrezgi)
135 xosp->bspP = bsp;
136 return TRUE;
137 }
138 if (xosp->filenameP != NULL && xosp->bPF == xosp->bThis)
139 {
140 xosp->bspP = bsp;
141 return TRUE;
142 }
143 return TRUE;
144 }
145
GetThisBioseq(XOSPtr xosp)146 static void GetThisBioseq (XOSPtr xosp)
147 {
148 GatherScopePtr gsp;
149 CharPtr fastafile;
150 Int4 gi;
151 FILE *fiop;
152 Boolean flagHaveNet;
153 SeqEntryPtr sep;
154
155 gsp = xosp->gsp;
156
157 if (xosp->bTG == xosp->bThis || xosp->bTF == xosp->bThis)
158 {
159 fastafile = xosp->filenameT;
160 gi = xosp->giT;
161 xosp->sepT = SeqEntryFree (xosp->sepT);
162 }
163 else
164 {
165 fastafile = xosp->filenameP;
166 gi = xosp->giP;
167 xosp->sepP = SeqEntryFree (xosp->sepP);
168 }
169
170 if (gi > 0)
171 {
172 if (!EntrezInit ("twopv", FALSE, &flagHaveNet))
173 {
174 ErrPostEx (SEV_ERROR, TOP_ERROR, 102,
175 "Entrez init failed");
176 ErrShow ();
177 return;
178 }
179 sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_BIOSEQ);
180 }
181 else if (fastafile != NULL)
182 {
183 if ((fiop = FileOpen (fastafile, "r")) == NULL)
184 {
185 ErrPostEx (SEV_ERROR, TOP_ERROR, 103,
186 "Failed to open FastA file");
187 ErrShow ();
188 return;
189 }
190 sep = FastaToSeqEntry (fiop, FALSE);
191 }
192 else
193 {
194 sep = NULL;
195 }
196
197 if (sep == NULL)
198 {
199 ErrPostEx (SEV_ERROR, TOP_ERROR, 104,
200 "No SeqEntry");
201 ErrShow ();
202 }
203 else
204 {
205 if (xosp->bTG == xosp->bThis || xosp->bTF == xosp->bThis)
206 {
207 xosp->sepT = sep;
208 xosp->bspT = NULL;
209 xosp->giT = gi;
210 }
211 else
212 {
213 xosp->sepP = sep;
214 xosp->bspP = NULL;
215 xosp->giP = gi;
216 }
217 GatherSeqEntry (sep, (Pointer) xosp, GetBioseq, (Pointer) gsp);
218 }
219
220 if (gi > 0)
221 EntrezFini ();
222 else
223 FileClose (fiop);
224
225 return;
226 }
227
228 /* button 1 & 2 */
229
CloseGIWindowProc(WindoW w)230 static void CloseGIWindowProc (WindoW w)
231 {
232 Remove (w);
233 return;
234 }
235
SetGIProc(ButtoN b)236 static void SetGIProc (ButtoN b)
237 {
238 TexT pc;
239 XOSPtr xosp;
240 Char buf[16];
241
242 if ((pc = (TexT) GetObjectExtra (b)) != NULL)
243 {
244 if ((xosp = (XOSPtr) GetObjectExtra (pc)) != NULL)
245 {
246 GetTitle (pc, buf, sizeof (buf));
247 if (xosp->bTG == xosp->bThis)
248 {
249 xosp->giT = atol (buf);
250 xosp->filenameT = (CharPtr) MemFree (xosp->filenameT);
251 }
252 else
253 {
254 xosp->giP = atol (buf);
255 xosp->filenameP = (CharPtr) MemFree (xosp->filenameP);
256 }
257 GetThisBioseq (xosp);
258 }
259 }
260 CloseGIWindowProc (ParentWindow (b));
261 xosp->bThis = NULL;
262 return;
263 }
264
ReadGIProc(ButtoN b)265 static void ReadGIProc (ButtoN b)
266 {
267 WindoW w;
268 GrouP h, g;
269 ButtoN bt;
270 TexT pc;
271 CharPtr winprmt = "Entrez GI";
272 XOSPtr xosp;
273
274 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
275 {
276 xosp->bThis = b;
277 w = MovableModalWindow (-60, -33, -10, -10, winprmt, CloseGIWindowProc);
278 h = HiddenGroup (w, 1, 0, NULL);
279 StaticPrompt (h, winprmt, StringWidth (winprmt),
280 dialogTextHeight, NULL, 'c');
281 g = HiddenGroup (h, 2, 0, NULL);
282 pc = DialogText (g, "", 8, NULL);
283 bt = PushButton (h, " Okay ", SetGIProc);
284 SetObjectExtra (pc, xosp, NULL);
285 SetObjectExtra (bt, pc, NULL);
286 Show (w);
287 Select (w);
288 }
289 return;
290 }
291
292 /* button 3 & 4 */
293
ReadFileProc(ButtoN b)294 static void ReadFileProc (ButtoN b)
295 {
296 XOSPtr xosp;
297 Char filename[PATH_MAX];
298
299 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
300 {
301 if (!GetInputFileName (filename, PATH_MAX, "", "TEXT"))
302 {
303 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Could not read directory");
304 ErrShow ();
305 }
306 else
307 {
308 if (xosp->bTF == b)
309 {
310 MemFree (xosp->filenameT);
311 xosp->filenameT = StringSave (filename);
312 xosp->giT = 0;
313 }
314 else
315 {
316 MemFree (xosp->filenameP);
317 xosp->filenameP = StringSave (filename);
318 xosp->giP = 0;
319 }
320 xosp->bThis = b;
321 GetThisBioseq (xosp);
322 xosp->bThis = NULL;
323 }
324 }
325 return;
326 }
327
328 /* button 5 */
329
CloseParamWindowProc(WindoW w)330 static void CloseParamWindowProc (WindoW w)
331 {
332 SeqScrollDataPtr ssdp;
333
334 if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
335 SeqScrollDataFree (ssdp);
336 Remove (w);
337 return;
338 }
339
ApplyParams(ButtoN b)340 static void ApplyParams (ButtoN b)
341 {
342 WindoW w;
343 XOSPtr xosp;
344
345 SeqScrollDataPtr ssdp;
346
347 w = ParentWindow (b);
348 if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
349 {
350 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
351 {
352 xosp->dotcutoff = (Int4) ssdp->curval;
353 }
354 xosp->flagPattern = (Boolean) GetValue (xosp->gpostblast);
355 }
356 return;
357 }
358
ClearWindowFlag(ButtoN b)359 static void ClearWindowFlag (ButtoN b)
360 {
361 XOSPtr xosp;
362
363 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
364 xosp->flagParamWindow = FALSE;
365 return;
366 }
367
AcceptParamProc(ButtoN b)368 static void AcceptParamProc (ButtoN b)
369 {
370 ApplyParams (b);
371 CloseParamWindowProc (ParentWindow (b));
372 ClearWindowFlag (b);
373 return;
374 }
375
UpdateParamProc(ButtoN b)376 static void UpdateParamProc (ButtoN b)
377 {
378 ApplyParams (b);
379 return;
380 }
381
CancelParamProc(ButtoN b)382 static void CancelParamProc (ButtoN b)
383 {
384 CloseParamWindowProc (ParentWindow (b));
385 ClearWindowFlag (b);
386 return;
387 }
388
TwopParamProc(ButtoN b)389 static void TwopParamProc (ButtoN b)
390 {
391 WindoW w;
392 GrouP h, h1, g, g1;
393 ButtoN b1, b2, b3;
394 XOSPtr xosp;
395
396 SeqScrollDataPtr ssdp = NULL;
397
398 if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
399 return;
400 if (xosp->flagParamWindow)
401 return;
402
403 w = FixedWindow (-75, -10, -10, -10,
404 "Blast 2 Proteins Parameters", CloseParamWindowProc);
405 h = HiddenGroup (w, 1, 0, NULL);
406 h1 = HiddenGroup (h, 2, 0, NULL);
407 g1 = HiddenGroup (h1, 1, 0, NULL);
408 g = HiddenGroup (g1, 1, 0, NULL);
409 StaticPrompt (g, "win cut", StringWidth ("12345678"), dialogTextHeight,
410 NULL, 'c');
411 g = HiddenGroup (g1, 2, 0, NULL);
412 AddScrollControl (&ssdp, g, (Int2) xosp->dotcutoff,
413 (Int2) xosp->dotcutoffmin, (Int2) xosp->dotcutoffmax, 24);
414
415 SetObjectExtra (w, ssdp, NULL);
416
417 h1 = HiddenGroup (h, 1, 0, NULL);
418 g = HiddenGroup (h1, 1, 0, NULL);
419 CheckBox (g, "Post Blast stringent pattern match", NULL);
420 SetValue (g, 0);
421 xosp->gpostblast = g;
422
423 h1 = HiddenGroup (h, 3, 0, NULL);
424 b1 = PushButton (h1, "Accept", AcceptParamProc);
425 SetObjectExtra (b1, xosp, NULL);
426 b2 = PushButton (h1, "Apply ", UpdateParamProc);
427 SetObjectExtra (b2, xosp, NULL);
428 b3 = PushButton (h1, "Cancel", CancelParamProc);
429 SetObjectExtra (b3, xosp, NULL);
430
431 Show (w);
432 Select (w);
433 xosp->flagParamWindow = TRUE;
434 return;
435 }
436
437 /* button 6 */
438
CleanUpGraphWindow(GraphiC g,VoidPtr data)439 static void CleanUpGraphWindow (GraphiC g, VoidPtr data)
440 {
441 XISPtr xisp;
442
443 if ((xisp = (XISPtr) data) != NULL)
444 {
445 DeletePicture (xisp->picture);
446 }
447 StdCleanupExtraProc (g, data);
448 }
449
CloseGraphWindowProc(WindoW w)450 static void CloseGraphWindowProc (WindoW w)
451 {
452 Remove (w);
453 return;
454 }
455
CloseGraphWindowButton(ButtoN b)456 static void CloseGraphWindowButton (ButtoN b)
457 {
458 CloseGraphWindowProc (ParentWindow (b));
459 return;
460 }
461
SapCount(SeqAlignPtr sap)462 static Int4 SapCount (SeqAlignPtr sap)
463 {
464 Int4 count;
465
466 count = 0;
467 while (sap != NULL)
468 {
469 count++;
470 sap = sap->next;
471 }
472 return count;
473 }
474
TwopProc(ButtoN b)475 static void TwopProc (ButtoN b)
476 {
477 Boolean flagError;
478 XOSPtr xosp;
479 XISPtr xisp;
480
481 BioseqPtr bspT, bspP;
482 SeqLocPtr slpT, slpP;
483 BLAST_OptionsBlkPtr blstopt;
484
485 Int4 i, loop, cutoff;
486 Int4 startT, startP, stopT, stopP;
487 SeqAlignPtr sap, sapn, sapkeep;
488 DenseSegPtr dsp;
489 SeqPortPtr sppT, sppP;
490 Uint1 seqT, seqP;
491 Int4 effective_length, eff_len_max, seq_identity, seq_id_max;
492 Char infobuf[512];
493 CharPtr titleT, titleP;
494 CharPtr cptr;
495 Int4 keepAlign, keepAlignCount;
496
497 CharPtr pattern_file = "ncbipros.dat";
498 ComPatPtr cpp, cpph;
499 SeqAlignPtr sapT, sapP, sapTt, sapPt, sappattern, sapnew;
500 SeqLocPtr slp;
501 StdSegPtr ssp;
502 Int4 lenT, lenP, countT, countP;
503 Int4Ptr starts, lens;
504 Boolean flagID;
505 ValNodePtr vnphead, vnpname;
506
507 WindoW w;
508 VieweR v;
509 GrouP g;
510 SegmenT seg;
511 Int4 top;
512
513 flagError = FALSE;
514 if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
515 return;
516
517 bspT = xosp->bspT;
518 bspP = xosp->bspP;
519 cutoff = xosp->dotcutoff;
520
521 if (bspT == NULL)
522 {
523 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Target Bioseq");
524 ErrShow ();
525 flagError = TRUE;
526 }
527 if (bspP == NULL)
528 {
529 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Probe Bioseq");
530 ErrShow ();
531 flagError = TRUE;
532 }
533 if (flagError)
534 return;
535
536 if (!ISA_aa (bspT->mol))
537 {
538 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Target not amino acid Bioseq");
539 ErrShow ();
540 flagError = TRUE;
541 }
542 if (!ISA_aa (bspP->mol))
543 {
544 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Probe not amino acid Bioseq");
545 ErrShow ();
546 flagError = TRUE;
547 }
548 if (flagError)
549 return;
550
551 WatchCursor ();
552 if (xosp->flagPattern)
553 cpph = ReadPrositePattern (pattern_file, FALSE, 25, NULL, NULL);
554 else
555 cpph = NULL;
556
557 blstopt = BLASTOptionNew ("blastp", TRUE);
558 blstopt->wordsize = 2;
559 blstopt->expect_value = 10.0;
560 blstopt->filter = 0;
561 blstopt->gap_open = 9;
562 blstopt->gap_extend = 2;
563 blstopt->gap_x_dropoff = 50;
564 blstopt->threshold_second = 9;
565 blstopt->two_pass_method = FALSE;
566 blstopt->multiple_hits_only = FALSE;
567
568 slpT = SeqLocIntNew (0, bspT->length-1, Seq_strand_unknown, bspT->id);
569 slpP = SeqLocIntNew (0, bspP->length-1, Seq_strand_unknown, bspP->id);
570
571 sapn = sap = BlastTwoSequencesByLoc (slpT, slpP, "blastp", blstopt);
572
573 BLASTOptionDelete (blstopt);
574
575 seq_id_max = 0;
576 eff_len_max = 0;
577 keepAlign = keepAlignCount = 0;
578 while (sap != NULL)
579 {
580 keepAlignCount++;
581 effective_length = 0;
582 seq_identity = 0;
583 if (sap->segtype == 2) /* DenseSeg gapped search */
584 {
585 sppT = SeqPortNew (bspT, 0, bspT->length-1, 0, Seq_code_iupacaa);
586 sppP = SeqPortNew (bspP, 0, bspP->length-1, 0, Seq_code_iupacaa);
587 dsp = sap->segs;
588 for (loop = 0; loop < (Int4) dsp->numseg; loop++)
589 {
590 if (dsp->starts[loop*2] == -1 || dsp->starts[(loop*2)+1] == -1)
591 {
592 effective_length += dsp->lens[loop];
593 }
594 else
595 {
596 effective_length += dsp->lens[loop];
597 startT = dsp->starts[loop*2];
598 startP = dsp->starts[(loop*2)+1];
599 SeqPortSeek (sppT, startT, SEEK_SET);
600 SeqPortSeek (sppP, startP, SEEK_SET);
601 for (i = 0; i < dsp->lens[loop]; i++)
602 {
603 seqT = SeqPortGetResidue (sppT);
604 seqP = SeqPortGetResidue (sppP);
605 if (seqT == seqP)
606 seq_identity++;
607 }
608 }
609 }
610 SeqPortFree (sppT);
611 SeqPortFree (sppP);
612 }
613 if (effective_length > eff_len_max)
614 {
615 seq_id_max = seq_identity;
616 eff_len_max = effective_length;
617 keepAlign = keepAlignCount;
618 }
619 sap = sap->next;
620 }
621 sap = sapn;
622 sapkeep = NULL;
623 keepAlignCount = 0;
624 while (sap != NULL)
625 {
626 keepAlignCount++;
627 sapn = sap->next;
628 if (keepAlign == keepAlignCount)
629 {
630 sapkeep = sap;
631 sapkeep->next = NULL;
632 }
633 else
634 {
635 SeqAlignFree (sap);
636 }
637 sap = sapn;
638 }
639
640 if (bspT->length == bspP->length && bspT->length == seq_identity)
641 flagID = TRUE;
642 else
643 flagID = FALSE;
644
645 vnphead = NULL;
646 sappattern = NULL;
647 cpp = cpph;
648 while (cpp != NULL)
649 {
650 sapT = PatternMatchBioseq (bspT, cpp, 0);
651 sapP = PatternMatchBioseq (bspP, cpp, 0);
652 if (sapT != NULL && sapP != NULL)
653 {
654 vnpname = ValNodeNew (vnphead);
655 if (vnphead == NULL)
656 vnphead = vnpname;
657 vnpname->data.ptrvalue = (Pointer) StringSave (cpp->name);
658 if ((sapnew = SeqAlignNew ()) != NULL)
659 {
660 sapnew->type = 3;
661 sapnew->segtype = 2;
662 sapnew->dim = 2;
663 dsp = DenseSegNew ();
664 sapnew->segs = dsp;
665 countT = SapCount (sapT);
666 countP = SapCount (sapP);
667 if (flagID)
668 dsp->numseg = (Int2) (countT * countP * 2);
669 else
670 dsp->numseg = (Int2) (countT * countP);
671 dsp->starts = (Int4Ptr) MemNew (sizeof (Int4) * dsp->numseg * 2);
672 dsp->lens = (Int4Ptr) MemNew (sizeof (Int4) * dsp->numseg);
673 starts = dsp->starts;
674 lens = dsp->lens;
675 sapTt = sapT;
676 sapPt = sapP;
677 while (sapTt != NULL)
678 {
679 ssp = (StdSegPtr) sapTt->segs;
680 slp = ssp->loc;
681 startT = SeqLocStart (slp);
682 lenT = SeqLocLen (slp);
683 while (sapPt != NULL)
684 {
685 ssp = (StdSegPtr) sapPt->segs;
686 slp = ssp->loc;
687 startP = SeqLocStart (slp);
688 lenP = SeqLocLen (slp);
689 *starts = startT;
690 starts++;
691 *starts = startP;
692 starts++;
693 *lens = (lenT+lenP)/2;
694 lens++;
695 if (flagID)
696 {
697 *starts = startP;
698 starts++;
699 *starts = startT;
700 starts++;
701 *lens = (lenT+lenP)/2;
702 lens++;
703 }
704 sapPt = sapPt->next;
705 }
706 sapTt = sapTt->next;
707 }
708 }
709 if (sappattern == NULL)
710 {
711 sappattern = sapnew;
712 }
713 else
714 {
715 sap = sappattern;
716 while (sap->next != NULL)
717 sap = sap->next;
718 sap->next = sapnew;
719 }
720 }
721 sap = sapT;
722 while (sap != NULL)
723 {
724 sapn = sap->next;
725 SeqAlignFree (sap);
726 sap = sapn;
727 }
728 sap = sapP;
729 while (sap != NULL)
730 {
731 sapn = sap->next;
732 SeqAlignFree (sap);
733 sap = sapn;
734 }
735 cpp = cpp->nextpattern;
736 }
737
738 titleT = FastaTitle (bspT, ">", NULL);
739 titleP = FastaTitle (bspP, ">", NULL);
740
741 cptr = titleT;
742 while (*cptr != '\0')
743 {
744 if (*cptr == ' ')
745 break;
746 cptr++;
747 }
748 *cptr = '\0';
749 if (StrLen (titleT) > 16)
750 titleT[16] = '\0';
751 cptr = titleP;
752 while (*cptr != '\0')
753 {
754 if (*cptr == ' ')
755 break;
756 cptr++;
757 }
758 *cptr = '\0';
759 if (StrLen (titleP) > 16)
760 titleP[16] = '\0';
761
762 xisp = (XISPtr) MemNew (sizeof (XIS));
763 startT = SeqLocStart (slpT);
764 stopT = SeqLocStop (slpT);
765 startP = SeqLocStart (slpP);
766 stopP = SeqLocStart (slpP);
767 xisp->Xscale = ScalePlot (stopT - startT + 1, stopP - startP + 1, 400);
768 xisp->Yscale = xisp->Xscale;
769
770 seg = NULL;
771 seg = DotXYPlot (bspT, bspP, cutoff, xisp->Xscale, xisp->Yscale, seg, FALSE);
772 seg = XYPlot (bspT, bspP, sapkeep, xisp->Xscale, xisp->Yscale,
773 BLUE_COLOR, seg, TRUE);
774 seg = XYPlot (bspT, bspP, sappattern, xisp->Xscale, xisp->Yscale,
775 GREEN_COLOR, seg, TRUE);
776 if (seg == NULL)
777 {
778 ErrPostEx (SEV_ERROR, TOP_ERROR, 501, "Failed to create picture");
779 ErrShow ();
780 ArrowCursor ();
781 return;
782 }
783 xisp->picture = seg;
784
785 vnpname = vnphead;
786 if (vnpname != NULL)
787 {
788 sap = sappattern;
789 while (sap != NULL)
790 {
791 if (vnpname != NULL)
792 {
793 dsp = (DenseSegPtr) sap->segs;
794 AddLabel (seg, 25 + (dsp->starts[0]/xisp->Xscale),
795 390 - (dsp->starts[1]/xisp->Yscale),
796 (CharPtr) vnpname->data.ptrvalue,
797 SMALL_TEXT, 5, LOWER_RIGHT, 0);
798 vnpname = vnpname->next;
799 }
800 sap = sap->next;
801 }
802 }
803 ValNodeFreeData (vnphead);
804
805 if (eff_len_max > 0)
806 {
807 sprintf (infobuf,
808 "X:TwoP%s %ld - Y:TwoP%s %ld - %6.2f identity - %ld residues",
809 titleT, (long) bspT->length, titleP, (long) bspP->length,
810 (FloatHi) seq_id_max / (FloatHi) eff_len_max * 100.0,
811 (long) eff_len_max);
812 }
813 else
814 {
815 sprintf (infobuf,
816 "X:TwoP%s %ld - Y:TwoP%s %ld - %6.2f identity",
817 titleT, (long) bspT->length, titleP, (long) bspP->length, 0.0);
818 }
819 top = -10;
820 AddLabel (seg, 0, top, infobuf, SMALL_TEXT, 5, MIDDLE_RIGHT, 0);
821
822 w = FixedWindow (10, 10, -10, -10, "2 Proteins", CloseGraphWindowProc);
823 SetObjectExtra (w, xisp, CleanUpGraphWindow);
824 g = HiddenGroup (w, -1, 0, NULL);
825 v = CreateViewer (g, 600, 500, TRUE, TRUE);
826 AttachPicture (v, seg, INT4_MIN, INT4_MAX, UPPER_LEFT, 1, 1, NULL);
827 PushButton (g, "Close", CloseGraphWindowButton);
828 RealizeWindow (w);
829 Show (w);
830
831 ComPatFree (cpph);
832 sap = sappattern;
833 while (sap != NULL)
834 {
835 sapn = sap->next;
836 SeqAlignFree (sap);
837 sap = sapn;
838 }
839 SeqAlignFree (sapkeep);
840 SeqLocFree (slpT);
841 SeqLocFree (slpP);
842 MemFree (titleT);
843 MemFree (titleP);
844
845 ArrowCursor ();
846 return;
847 }
848
849 /* button 7 */
850
CloseTwopParentProc(WindoW w)851 static void CloseTwopParentProc (WindoW w)
852 {
853 XOSPtr xosp;
854
855 if ((xosp = (XOSPtr) GetObjectExtra (w)) != NULL)
856 {
857 xosp->gsp = NULL; /* is static */
858 MemFree (xosp->filenameT);
859 MemFree (xosp->filenameP);
860 xosp->sepT = SeqEntryFree (xosp->sepT);
861 xosp->sepP = SeqEntryFree (xosp->sepP);
862 xosp->bspT = NULL; /* should be in seqentry */
863 xosp->bspP = NULL; /* should be in seqentry */
864 MemFree (xosp);
865 }
866 Remove (w);
867 QuitProgram ();
868 return;
869 }
870
EndProg(ButtoN b)871 static void EndProg (ButtoN b)
872 {
873 CloseTwopParentProc (ParentWindow (b));
874 return;
875 }
876
877 /* parent */
878
SetUp(void)879 static XOSPtr SetUp (void)
880 {
881 static GatherScope gs;
882 GatherScopePtr gsp;
883 XOSPtr xosp;
884
885 gsp = &gs;
886 MemSet ((Pointer) gsp, 0, sizeof (GatherScope));
887 MemSet ((Pointer) gsp->ignore, (int) (TRUE),
888 (size_t) (OBJ_MAX * sizeof (Boolean)));
889 gsp->ignore[OBJ_BIOSEQ] = FALSE;
890
891 xosp = MemNew (sizeof (XOS));
892
893 xosp->flagParamWindow = FALSE;
894 xosp->gpostblast = NULL;
895 xosp->flagPattern = FALSE;
896 xosp->bTG = NULL;
897 xosp->bPG = NULL;
898 xosp->bTF = NULL;
899 xosp->bPF = NULL;
900 xosp->bThis = NULL;
901 xosp->giT = 0;
902 xosp->giP = 0;
903 xosp->filenameT = NULL;
904 xosp->filenameP = NULL;
905 xosp->gsp = gsp;
906 xosp->sepT = NULL;
907 xosp->sepP = NULL;
908 xosp->bspT = NULL;
909 xosp->bspP = NULL;
910 xosp->dotcutoff = 6;
911 xosp->dotcutoffmin = 0;
912 xosp->dotcutoffmax = 8;
913
914 return xosp;
915 }
916
Main(void)917 Int2 Main (void)
918 {
919 WindoW w;
920 GrouP g;
921 ButtoN b1, b2, b3, b4, b5, b6, b7;
922
923 XOSPtr xosp;
924
925 ProcessUpdatesFirst (FALSE);
926
927 xosp = SetUp ();
928
929 w = FixedWindow (-50, -33, -10, -10,
930 "Two Protein Blast", CloseTwopParentProc);
931 g = HiddenGroup (w, 7, 0, NULL);
932 b1 = PushButton (g, " Target GI ", ReadGIProc);
933 b2 = PushButton (g, " Probe GI ", ReadGIProc);
934 b3 = PushButton (g, "Target FastA", ReadFileProc);
935 b4 = PushButton (g, " Probe FastA", ReadFileProc);
936 b5 = PushButton (g, " Parameters ", TwopParamProc);
937 b6 = PushButton (g, "Blast 2 Prot", TwopProc);
938 b7 = PushButton (g, " Finish ", EndProg);
939
940 xosp->bTG = b1;
941 xosp->bPG = b2;
942 xosp->bTF = b3;
943 xosp->bPF = b4;
944
945 SetObjectExtra (w, xosp, NULL);
946 SetObjectExtra (b1, xosp, NULL);
947 SetObjectExtra (b2, xosp, NULL);
948 SetObjectExtra (b3, xosp, NULL);
949 SetObjectExtra (b4, xosp, NULL);
950 SetObjectExtra (b5, xosp, NULL);
951 SetObjectExtra (b6, xosp, NULL);
952 SetObjectExtra (b7, xosp, NULL);
953
954 Show (w);
955 ProcessEvents ();
956 return 0;
957 }
958