|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/demo/cnsgnv.c |
source navigation diff markup identifier search freetext search file search |
1 /*
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: cnsgnv.c
27 *
28 * Author(s): John Kuzio
29 *
30 * Version Creation Date: 98-01-01
31 *
32 * $Revision: 6.10 $
33 *
34 * File Description: consign - codon biased orf assignment
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * --------------------------------------------------------------------------
40 * $Log: cnsgnv.c,v $
41 * Revision 6.10 1999/03/13 03:43:16 kuzio
42 * cast
43 *
44 * Revision 6.9 1998/10/13 17:15:26 kuzio
45 * colored graph opt
46 *
47 * Revision 6.8 1998/10/01 16:43:54 kuzio
48 * rewrite framing
49 *
50 * Revision 6.7 1998/09/30 19:09:39 kuzio
51 * more strand frame fixes
52 *
53 * Revision 6.6 1998/09/28 16:42:20 kuzio
54 * no met orf check
55 *
56 * Revision 6.5 1998/09/22 02:29:40 kuzio
57 * orf find patch; frameshift fix
58 *
59 * Revision 6.4 1998/09/16 18:40:34 kuzio
60 * cvs logging
61 *
62 * ==========================================================================
63 */
64
65 #include <ncbi.h>
66 #include <vibrant.h>
67 #include <accentr.h>
68 #include <gather.h>
69 #include <tofasta.h>
70 #include <toasn3.h>
71 #include <tfuns.h>
72 #include <urkutil.h>
73 #include <urkbias.h>
74 #include <urkcnsrt.h>
75 #include <urkptpf.h>
76 #include <seqscrl.h>
77 #include <gphdraw.h>
78
79 #define TOP_ERROR 1
80 static char _this_module[] = "cnsgnv";
81 #undef THIS_MODULE
82 #define THIS_MODULE _this_module
83 static char _this_file[] = __FILE__;
84 #undef THIS_FILE
85 #define THIS_FILE _this_file
86
87 Uint1 AAForCodon (Uint1Ptr cdn, CharPtr gcode);
88
89 typedef struct xtrins
90 {
91 SegmenT picture;
92 SeqGraphPtr sgp;
93 } XIS, PNTR XISPtr;
94
95 typedef struct xtrobj
96 {
97 Boolean flagParamWindow;
98 Int4 gi;
99 CharPtr filename;
100 GatherScopePtr gsp;
101 SeqEntryPtr sep;
102 BioseqPtr bsp;
103 CharPtr pattern_file;
104 CharPtr gcd, gcdi;
105 Int4 orfcut;
106 Int4 cutoff, cutoffmin, cutoffmax;
107 Int4 window, windowmin, windowmax;
108 ValNodePtr orflist;
109 SeqLocPtr slpa, slpb, slps, slpk;
110 FloatHi probcut;
111 Int4 clustmin;
112 Int4 findmin;
113 Int4 minimumseed;
114 } XOS, PNTR XOSPtr;
115
116 /* common */
117
118 static void CleanUpXOS (XOSPtr xosp)
119 {
120 SeqLocPtr slp, slpn;
121 SeqIdPtr id;
122
123 if (xosp != NULL)
124 {
125 xosp->gsp = NULL; /* is static */
126 xosp->filename = (CharPtr) MemFree (xosp->filename);
127 xosp->sep = SeqEntryFree (xosp->sep);
128 xosp->bsp = NULL; /* should be in seqentry */
129 xosp->gcd = NULL;
130 xosp->gcdi = NULL;
131 slp = xosp->slpa;
132 while (slp != NULL)
133 {
134 slpn = slp->next;
135 id = SeqLocId (slp);
136 if (id != NULL)
137 id->next = SeqIdSetFree (id->next);
138 SeqLocFree (slp);
139 slp = slpn;
140 }
141 xosp->slpa = slp;
142 slp = xosp->slpb;
143 while (slp != NULL)
144 {
145 slpn = slp->next;
146 id = SeqLocId (slp);
147 if (id != NULL)
148 id->next = SeqIdSetFree (id->next);
149 SeqLocFree (slp);
150 slp = slpn;
151 }
152 xosp->slpb = slp;
153 slp = xosp->slps;
154 while (slp != NULL)
155 {
156 slpn = slp->next;
157 id = SeqLocId (slp);
158 if (id != NULL)
159 id->next = SeqIdSetFree (id->next);
160 SeqLocFree (slp);
161 slp = slpn;
162 }
163 xosp->slps = slp;
164 slp = xosp->slpk;
165 while (slp != NULL)
166 {
167 slpn = slp->next;
168 id = SeqLocId (slp);
169 if (id != NULL)
170 id->next = SeqIdSetFree (id->next);
171 SeqLocFree (slp);
172 slp = slpn;
173 }
174 xosp->slpk = slp;
175 }
176 return;
177 }
178
179 static Boolean GatherKnownOrfs (GatherContextPtr gcp)
180 {
181 XOSPtr xosp;
182 SeqAnnotPtr sap;
183 SeqFeatPtr sfp;
184 SeqLocPtr slp;
185
186 if (gcp == NULL)
187 return FALSE;
188 if ((xosp = (XOSPtr) gcp->userdata) == NULL)
189 return FALSE;
190 if (gcp->thistype != OBJ_SEQANNOT)
191 return TRUE;
192 if ((sap = (SeqAnnotPtr) (gcp->thisitem)) == NULL)
193 return TRUE;
194
195 while (sap != NULL)
196 {
197 sfp = (SeqFeatPtr) sap->data;
198 while (sfp != NULL)
199 {
200 if (sfp->data.choice == SEQFEAT_CDREGION)
201 {
202 slp = sfp->location;
203 SeqLocLink (&(xosp->slpk), SeqLocDup (slp));
204 }
205 sfp = sfp->next;
206 }
207 sap = sap->next;
208 }
209 return TRUE;
210 }
211
212 static void AddBioSourceToSeqEntry (SeqEntryPtr sep)
213 {
214 BioseqPtr bsp;
215 ValNodePtr descorp;
216 BioSourcePtr biop;
217 OrgNamePtr onp;
218 OrgRefPtr orp;
219
220 if (sep == NULL)
221 return;
222 if ((bsp = sep->data.ptrvalue) == NULL)
223 return;
224
225 descorp = ValNodeNew (bsp->descr);
226 descorp->choice = Seq_descr_source;
227 biop = BioSourceNew ();
228 descorp->data.ptrvalue = biop;
229 orp = OrgRefNew ();
230 biop->org = orp;
231 onp = OrgNameNew ();
232 orp->orgname = onp;
233 biop->genome = 1;
234 onp->gcode = 1;
235 onp->mgcode = 1;
236
237 if (bsp->descr == NULL)
238 bsp->descr = descorp;
239
240 return;
241 }
242
243 static Boolean GetBioseq (GatherContextPtr gcp)
244 {
245 XOSPtr xosp;
246 BioseqPtr bsp;
247 Int4 entrezgi;
248
249 if (gcp == NULL)
250 return FALSE;
251 if ((xosp = (XOSPtr) gcp->userdata) == NULL)
252 return FALSE;
253 if (xosp->bsp != NULL)
254 return TRUE;
255
256 if (gcp->thistype != OBJ_BIOSEQ)
257 return TRUE;
258 if ((bsp = (BioseqPtr) (gcp->thisitem)) == NULL)
259 return TRUE;
260 if (xosp->gi > 0)
261 {
262 entrezgi = GetGIForSeqId (bsp->id);
263 if (xosp->gi == entrezgi)
264 xosp->bsp = bsp;
265 return TRUE;
266 }
267 if (xosp->filename != NULL)
268 {
269 xosp->bsp = bsp;
270 return TRUE;
271 }
272 return TRUE;
273 }
274
275 static void GetThisBioseq (XOSPtr xosp)
276 {
277 GatherScopePtr gsp;
278 CharPtr filename;
279 Int4 gi;
280 FILE *fiop;
281 Boolean flagHaveNet;
282 SeqEntryPtr sep;
283 ValNodePtr vnp;
284 Int2 gcode;
285 GeneticCodePtr gcp;
286 SeqLocPtr slp, slpn;
287 SeqIdPtr id;
288
289 gsp = xosp->gsp;
290
291 fiop = NULL;
292 filename = xosp->filename;
293 gi = xosp->gi;
294 xosp->sep = SeqEntryFree (xosp->sep);
295
296 if (gi > 0)
297 {
298 if (!EntrezInit ("cnsgnv", FALSE, &flagHaveNet))
299 {
300 ErrPostEx (SEV_ERROR, TOP_ERROR, 102,
301 "Entrez init failed");
302 ErrShow ();
303 return;
304 }
305 }
306
307 if (gi > 0)
308 {
309 sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_NUC_PROT);
310 }
311 else if (filename != NULL)
312 {
313 if ((fiop = FileOpen (filename, "r")) == NULL)
314 {
315 ErrPostEx (SEV_ERROR, TOP_ERROR, 103,
316 "Failed to open FastA file");
317 ErrShow ();
318 return;
319 }
320 sep = FastaToSeqEntry (fiop, TRUE);
321 AddBioSourceToSeqEntry (sep);
322 }
323 else
324 {
325 sep = NULL;
326 }
327
328 if (sep == NULL)
329 {
330 ErrPostEx (SEV_ERROR, TOP_ERROR, 104,
331 "No SeqEntry");
332 ErrShow ();
333 }
334 else
335 {
336 CleanUpXOS (xosp);
337 xosp->sep = sep;
338 xosp->gi = gi;
339 xosp->filename = StringSave (filename);
340 GatherSeqEntry (sep, (Pointer) xosp, GetBioseq, (Pointer) gsp);
341 }
342
343 if (xosp->bsp != NULL)
344 {
345 vnp = xosp->bsp->descr;
346 gcode = 0;
347 while (vnp != NULL)
348 {
349 if (vnp->choice == Seq_descr_source)
350 {
351 gcode = BioSourceToGeneticCode ((BioSourcePtr) vnp->data.ptrvalue);
352 break;
353 }
354 vnp = vnp->next;
355 }
356 if (gcode == 0 && sep->choice == 2)
357 {
358 vnp = ((BioseqSetPtr) (sep->data.ptrvalue))->descr;
359 while (vnp != NULL)
360 {
361 if (vnp->choice == Seq_descr_source)
362 {
363 gcode = BioSourceToGeneticCode ((BioSourcePtr) vnp->data.ptrvalue);
364 break;
365 }
366 vnp = vnp->next;
367 }
368 }
369 if (gcode == 0)
370 gcode = 1; /* standard */
371 gcp = GeneticCodeFind (gcode, NULL);
372 if (gcp != NULL)
373 {
374 xosp->gcd = xosp->gcdi = NULL;
375 vnp = (ValNodePtr) gcp->data.ptrvalue;
376 while (vnp != NULL)
377 {
378 if (vnp->choice == 6) /* sncbieaa */
379 xosp->gcdi = (CharPtr) vnp->data.ptrvalue;
380 else if (vnp->choice == 3) /* ncbieaa */
381 xosp->gcd = (CharPtr) vnp->data.ptrvalue;
382 vnp = vnp->next;
383 }
384 }
385 if (xosp->gcdi == NULL)
386 xosp->gcdi = xosp->gcd;
387 if (xosp->gcdi == NULL)
388 {
389 ErrPostEx (SEV_ERROR, TOP_ERROR, 105,
390 "Could not get genetic code for translation");
391 ErrShow ();
392 xosp->bsp = NULL;
393 }
394 }
395
396 if (gi > 0)
397 {
398 slp = xosp->slpk;
399 while (slp != NULL)
400 {
401 slpn = slp->next;
402 id = SeqLocId (slp);
403 if (id != NULL)
404 id->next = SeqIdSetFree (id->next);
405 SeqLocFree (slp);
406 slp = slpn;
407 }
408 xosp->slpk = slp;
409 GatherSeqEntry (sep, (Pointer) xosp, GatherKnownOrfs, (Pointer) gsp);
410 }
411
412 if (gi > 0)
413 EntrezFini ();
414 else
415 FileClose (fiop);
416
417 if (xosp->bsp != NULL)
418 {
419 if (!ISA_na (xosp->bsp->mol))
420 {
421 xosp->sep = SeqEntryFree (xosp->sep);
422 xosp->bsp = NULL;
423 xosp->filename = (CharPtr) MemFree (xosp->filename);
424 xosp->gi = 0;
425 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Not nucleic acid Bioseq");
426 ErrShow ();
427 }
428 }
429 else
430 {
431 xosp->sep = SeqEntryFree (xosp->sep);
432 xosp->filename = (CharPtr) MemFree (xosp->filename);
433 xosp->gi = 0;
434 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Bioseq");
435 ErrShow ();
436 }
437 return;
438 }
439
440 /* button 1 */
441
442 static void CloseGIWindowProc (WindoW w)
443 {
444 Remove (w);
445 return;
446 }
447
448 static void SetGIProc (ButtoN b)
449 {
450 TexT pc;
451 XOSPtr xosp;
452 Char buf[16];
453
454 if ((pc = (TexT) GetObjectExtra (b)) != NULL)
455 {
456 if ((xosp = (XOSPtr) GetObjectExtra (pc)) != NULL)
457 {
458 GetTitle (pc, buf, sizeof (buf));
459 xosp->gi = atol (buf);
460 xosp->filename = (CharPtr) MemFree (xosp->filename);
461 GetThisBioseq (xosp);
462 }
463 }
464 CloseGIWindowProc (ParentWindow (b));
465 return;
466 }
467
468 static void ReadGIProc (ButtoN b)
469 {
470 WindoW w;
471 GrouP h, g;
472 ButtoN bt;
473 TexT pc;
474 CharPtr winprmt = "Entrez GI";
475 XOSPtr xosp;
476
477 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
478 {
479 w = MovableModalWindow (-60, -33, -10, -10, winprmt, CloseGIWindowProc);
480 h = HiddenGroup (w, 1, 0, NULL);
481 StaticPrompt (h, winprmt, StringWidth (winprmt),
482 dialogTextHeight, NULL, 'c');
483 g = HiddenGroup (h, 2, 0, NULL);
484 pc = DialogText (g, "", 8, NULL);
485 bt = PushButton (h, " Okay ", SetGIProc);
486 SetObjectExtra (pc, xosp, NULL);
487 SetObjectExtra (bt, pc, NULL);
488 Show (w);
489 Select (w);
490 }
491 return;
492 }
493
494 /* button 2 */
495
496 static void ReadFileProc (ButtoN b)
497 {
498 XOSPtr xosp;
499 Char filename[PATH_MAX];
500
501 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
502 {
503 if (!GetInputFileName (filename, PATH_MAX, "", "TEXT"))
504 {
505 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Could not read directory");
506 ErrShow ();
507 }
508 else
509 {
510 MemFree (xosp->filename);
511 xosp->filename = StringSave (filename);
512 xosp->gi = 0;
513 GetThisBioseq (xosp);
514 }
515 }
516 return;
517 }
518
519 /* button 3 */
520
521 static void CloseParamWindowProc (WindoW w)
522 {
523 SeqScrollDataPtr ssdp;
524
525 if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
526 SeqScrollDataFree (ssdp);
527 Remove (w);
528 return;
529 }
530
531 static void ApplyParams (ButtoN b)
532 {
533 WindoW w;
534 XOSPtr xosp;
535
536 SeqScrollDataPtr ssdp;
537
538 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
539 {
540 w = ParentWindow (b);
541 if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
542 {
543 xosp->cutoff = (Int4) ssdp->curval;
544 ssdp = ssdp->next;
545 xosp->window = (Int4) ssdp->curval;
546 }
547 }
548 return;
549 }
550
551 static void ClearWindowFlag (ButtoN b)
552 {
553 XOSPtr xosp;
554
555 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
556 xosp->flagParamWindow = FALSE;
557 return;
558 }
559
560 static void AcceptParamProc (ButtoN b)
561 {
562 ApplyParams (b);
563 CloseParamWindowProc (ParentWindow (b));
564 ClearWindowFlag (b);
565 return;
566 }
567
568 static void UpdateParamProc (ButtoN b)
569 {
570 ApplyParams (b);
571 return;
572 }
573
574 static void CancelParamProc (ButtoN b)
575 {
576 CloseParamWindowProc (ParentWindow (b));
577 ClearWindowFlag (b);
578 return;
579 }
580
581 static void ConsignParamProc (ButtoN b)
582 {
583 WindoW w;
584 GrouP h, h1, g, g1;
585 ButtoN b1, b2, b3;
586 XOSPtr xosp;
587
588 SeqScrollDataPtr ssdp = NULL;
589
590 if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
591 return;
592 if (xosp->flagParamWindow)
593 return;
594
595 w = FixedWindow (-75, -10, -10, -10,
596 "Consign Parameters", CloseParamWindowProc);
597 h = HiddenGroup (w, 1, 0, NULL);
598 h1 = HiddenGroup (h, 2, 0, NULL);
599
600 g1 = HiddenGroup (h1, 1, 0, NULL);
601 g = HiddenGroup (g1, 1, 0, NULL);
602 StaticPrompt (g, "CU cut", StringWidth ("12345678"), dialogTextHeight,
603 NULL, 'c');
604 g = HiddenGroup (g1, 2, 0, NULL);
605 AddScrollControl (&ssdp, g, (Int2) xosp->cutoff,
606 (Int2) xosp->cutoffmin, (Int2) xosp->cutoffmax, 24);
607
608 g1 = HiddenGroup (h1, 1, 0, NULL);
609 g = HiddenGroup (g1, 1, 0, NULL);
610 StaticPrompt (g, "CU win", StringWidth ("12345678"), dialogTextHeight,
611 NULL, 'c');
612 g = HiddenGroup (g1, 2, 0, NULL);
613 AddScrollControl (&ssdp, g, (Int2) xosp->window,
614 (Int2) xosp->windowmin, (Int2) xosp->windowmax, 24);
615 SetObjectExtra (w, ssdp, NULL);
616
617 h1 = HiddenGroup (h, 3, 0, NULL);
618 b1 = PushButton (h1, "Accept", AcceptParamProc);
619 SetObjectExtra (b1, xosp, NULL);
620 b2 = PushButton (h1, "Apply ", UpdateParamProc);
621 SetObjectExtra (b2, xosp, NULL);
622 b3 = PushButton (h1, "Cancel", CancelParamProc);
623 SetObjectExtra (b3, xosp, NULL);
624
625 Show (w);
626 Select (w);
627 xosp->flagParamWindow = TRUE;
628 return;
629 }
630
631 /* button 4 */
632
633 static void CleanUpGraphWindow (GraphiC g, VoidPtr data)
634 {
635 XISPtr xisp;
636 SeqGraphPtr sgp, sgpn;
637
638 if ((xisp = (XISPtr) data) != NULL)
639 {
640 DeletePicture (xisp->picture);
641 xisp->picture = NULL;
642 sgp = xisp->sgp;
643 while (sgp != NULL)
644 {
645 sgpn = sgp->next;
646 SeqGraphFree (sgp);
647 sgp = sgpn;
648 }
649 xisp->sgp = NULL;
650 }
651 StdCleanupExtraProc (g, data);
652 }
653
654 static void CloseGraphWindowProc (WindoW w)
655 {
656 Remove (w);
657 return;
658 }
659
660 static void CloseGraphWindowButton (ButtoN b)
661 {
662 CloseGraphWindowProc (ParentWindow (b));
663 return;
664 }
665
666 static void AddOrfClass (SeqLocPtr slp, SegmenT seg,
667 Int4Ptr orftop, Int4 iframe,
668 Int4 frame, Int4 shift, Uint1 strand,
669 Uint1Ptr orfcolor, Uint1 orfwidth)
670 {
671 SeqLocPtr slpThis, slpHead;
672 Uint1 strandThis;
673 Int4 start, stop, startorig, startthis, stopthis;
674 Int4 len, runlen, extraframe;
675 Int4 top, topold, startold, stopold;
676 Int4 framethis;
677 Boolean flagRTL;
678
679 while (slp != NULL)
680 {
681 if (slp->choice == SEQLOC_MIX)
682 slpThis = (SeqLocPtr) slp->data.ptrvalue;
683 else
684 slpThis = slp;
685 strandThis = SeqLocStrand (slpThis);
686 if (strandThis == strand ||
687 (strandThis == Seq_strand_unknown && strand == Seq_strand_plus))
688 {
689 flagRTL = TRUE;
690 runlen = 0;
691 startold = -1;
692 stopold = -1;
693 topold = -1;
694 slpHead = slpThis;
695 if (strandThis != Seq_strand_plus &&
696 strandThis != Seq_strand_unknown)
697 {
698 if (slp->choice == SEQLOC_MIX)
699 {
700 if (slpHead->next != NULL)
701 {
702 if (SeqLocStart (slpHead->next) > SeqLocStart (slpHead))
703 {
704 flagRTL = FALSE;
705 while (slpHead->next != NULL)
706 slpHead = slpHead->next;
707 }
708 }
709 }
710 }
711 if (strandThis != Seq_strand_plus &&
712 strandThis != Seq_strand_unknown)
713 startorig = SeqLocStop (slpHead) - 2;
714 else
715 startorig = SeqLocStart (slpHead);
716 if (startorig > 0 && startorig%3 == frame)
717 {
718 while (slpThis != NULL)
719 {
720 start = SeqLocStart (slpThis);
721 stop = SeqLocStop (slpThis);
722 if (strandThis != Seq_strand_plus &&
723 strandThis != Seq_strand_unknown)
724 {
725 startthis = SeqLocStop (slpThis) - 2;
726 stopthis = SeqLocStart (slpThis) - 2;
727 }
728 else
729 {
730 startthis = SeqLocStart (slpThis);
731 stopthis = SeqLocStop (slpThis);
732 }
733 framethis = startthis % 3;
734 extraframe = runlen % 3;
735 framethis += extraframe;
736 framethis %= 3;
737 if (iframe > 2)
738 framethis = 3 + framethis;
739 top = orftop[framethis] - shift;
740
741 len = stopthis - startthis;
742 if (len < 0)
743 len *= -1;
744 len += 1;
745 runlen += len;
746
747 if (stopold >= 0)
748 {
749 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
750 orfcolor, SOLID_LINE, SOLID_SHADING,
751 STD_PEN_WIDTH, 0);
752 if (strand == Seq_strand_minus && flagRTL)
753 AddLine (seg, startold, topold, stop, top, FALSE, 0);
754 else
755 AddLine (seg, stopold, topold, start, top, FALSE, 0);
756 }
757 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
758 orfcolor, SOLID_LINE, SOLID_SHADING,
759 orfwidth, 0);
760 AddLine (seg, start, top, stop, top, FALSE, 0);
761 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
762 BLACK_COLOR, SOLID_LINE, SOLID_SHADING,
763 STD_PEN_WIDTH, 0);
764 startold = start;
765 stopold = stop;
766 topold = top;
767 if (slp->choice != SEQLOC_MIX)
768 break;
769 slpThis = slpThis->next;
770 }
771 }
772 }
773 slp = slp->next;
774 }
775 return;
776 }
777
778 static void ConsignProc (ButtoN b)
779 {
780 XOSPtr xosp;
781 XISPtr xisp;
782
783 ComPatPtr cpp, cpph;
784 ValNodePtr orflist;
785 SeqLocPtr slp, slpn;
786 Int4 start, stop;
787 Uint1 strand;
788 SeqPortPtr spp;
789 Uint1Ptr aaseq;
790 Int4 ntpos, aapos;
791 Uint1 cdn[3];
792
793 SeqAlignPtr sap, sapn;
794
795 FloatHi probcut;
796 Int4 clustmin, findmin;
797
798 Int4 i, n, endpos, XLength, XScale, shift;
799 Int4 iframe, frame, top, orftop[6];
800 FloatHiPtr score, expandscore;
801 FloatHi maxscore;
802 Int4Ptr tableGlobal;
803
804 SeqGraphPtr sgp, sgpn;
805 WindoW w;
806 VieweR v;
807 GrouP g;
808 SegmenT seg;
809 GraphSentPtr gsp;
810 Char numberbuffer[32];
811
812 if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
813 return;
814
815 if (xosp->bsp == NULL)
816 {
817 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Bioseq");
818 ErrShow ();
819 return;
820 }
821
822 WatchCursor ();
823 cpph = cpp = ReadPrositePattern (xosp->pattern_file, TRUE, -1, NULL, NULL);
824 if (cpph == NULL)
825 {
826 ErrPostEx (SEV_ERROR, TOP_ERROR, 101,
827 "read failed %s", xosp->pattern_file);
828 ErrShow ();
829 ArrowCursor ();
830 return;
831 }
832
833 xosp->orflist = GetOrfList (xosp->bsp, (Int2) (xosp->orfcut));
834 xosp->orflist = ClearNonMetOrfs (xosp->orflist);
835 orflist = xosp->orflist;
836 while (orflist != NULL)
837 {
838 slp = (SeqLocPtr) orflist->data.ptrvalue;
839 if (slp->choice == 0)
840 {
841 orflist = orflist->next;
842 continue;
843 }
844 if (slp->choice == SEQLOC_MIX)
845 slp = (SeqLocPtr) slp->data.ptrvalue;
846 start = SeqLocStart (slp);
847 stop = SeqLocStop (slp);
848 strand = SeqLocStrand (slp);
849 if (strand != Seq_strand_both)
850 strand = Seq_strand_both;
851 if (stop - start + 1 >= xosp->minimumseed)
852 {
853 spp = SeqPortNew (xosp->bsp, start, stop, strand, Seq_code_ncbi4na);
854 aaseq = (Uint1Ptr) MemNew ((size_t)
855 (sizeof (Uint1) * (((stop-start)/3)+2)));
856 ntpos = start;
857 aapos = 0;
858 while (ntpos < start+3)
859 {
860 cdn[0] = SeqPortGetResidue (spp);
861 ntpos++;
862 cdn[1] = SeqPortGetResidue (spp);
863 ntpos++;
864 cdn[2] = SeqPortGetResidue (spp);
865 ntpos++;
866 aaseq[aapos] = AAForCodon (cdn, xosp->gcdi);
867 aapos++;
868 }
869 while (ntpos <= stop)
870 {
871 cdn[0] = SeqPortGetResidue (spp);
872 ntpos++;
873 cdn[1] = SeqPortGetResidue (spp);
874 ntpos++;
875 cdn[2] = SeqPortGetResidue (spp);
876 ntpos++;
877 aaseq[aapos] = AAForCodon (cdn, xosp->gcd);
878 aapos++;
879 }
880 SeqPortFree (spp);
881 aaseq[aapos] = 0;
882 cpp = cpph;
883 while (cpp != NULL)
884 {
885 sap = PatternMatch (aaseq, 0, Seq_strand_plus, SeqLocId (slp),
886 cpp, 0, Seq_strand_unknown, FALSE);
887 if (sap != NULL)
888 break;
889 cpp = cpp->nextpattern;
890 }
891 MemFree (aaseq);
892 if (sap != NULL)
893 {
894 SeqLocLink (&(xosp->slps), SeqLocDup (slp));
895 }
896 while (sap != NULL)
897 {
898 sapn = sap->next;
899 SeqAlignFree (sap);
900 sap = sapn;
901 }
902 }
903 orflist = orflist->next;
904 }
905 ComPatFree (cpph);
906
907 orflist = xosp->orflist;
908 while (orflist != NULL)
909 {
910 slp = (SeqLocPtr) orflist->data.ptrvalue;
911 if (slp->choice > 0)
912 SeqLocLink (&(xosp->slpa), SeqLocDup (slp));
913 while (slp != NULL)
914 {
915 slpn = slp->next;
916 SeqLocFree (slp);
917 slp = slpn;
918 }
919 orflist->data.ptrvalue = NULL;
920 orflist = orflist->next;
921 }
922 xosp->orflist = ValNodeFree (xosp->orflist);
923
924 probcut = xosp->probcut;
925 clustmin = xosp->clustmin;
926 findmin = xosp->findmin;
927
928 xosp->slpb = FindSimilarBiasOrfs (xosp->sep, probcut, clustmin, findmin,
929 xosp->slps, xosp->slpa);
930
931 tableGlobal = CodonTableFromSeqLoc (xosp->bsp, xosp->slpb);
932 seg = NULL;
933 top = 0;
934 xisp = (XISPtr) MemNew (sizeof (XIS));
935 frame = 0;
936 for (iframe = 0; iframe < 6; iframe++)
937 {
938 endpos = (xosp->bsp->length + 3 - frame - xosp->window) / 3;
939 if (iframe < 3)
940 score = BiasScoreBioseq (xosp->bsp, tableGlobal, xosp->window,
941 frame, Seq_strand_plus);
942 else
943 score = BiasScoreBioseq (xosp->bsp, tableGlobal, xosp->window,
944 frame, Seq_strand_minus);
945 maxscore = 0.0;
946 for (i = 0; i < endpos; i++)
947 if (score[i] > maxscore)
948 maxscore = score[i];
949 expandscore = (FloatHiPtr) MemNew (sizeof (FloatHi) * xosp->bsp->length);
950 for (i = 0; i < xosp->window/2; i++)
951 expandscore[i] = maxscore;
952 n = 0;
953 while (i < xosp->bsp->length)
954 {
955 if (n < endpos)
956 expandscore[i] = score[n];
957 else
958 expandscore[i] = maxscore;
959 i++;
960 if (i%3 == 0)
961 n++;
962 }
963 MemFree (score);
964 score = expandscore;
965 sgp = SeqGraphNew ();
966 if (xisp->sgp == NULL)
967 {
968 xisp->sgp = sgp;
969 }
970 else
971 {
972 sgpn = xisp->sgp;
973 while (sgpn->next != NULL)
974 sgpn = sgpn->next;
975 sgpn->next = sgp;
976 }
977 XLength = xosp->bsp->length;
978 if (XLength > 1200)
979 XLength = 1200;
980 XScale = xosp->bsp->length / XLength;
981 if (xosp->bsp->length % XLength != 0)
982 XScale++;
983 sgp->loc = SeqLocIntNew (0, xosp->bsp->length-1, xosp->bsp->strand,
984 xosp->bsp->id);
985 sgp->flags[2] = 1;
986 sgp->numval = xosp->bsp->length;
987 sgp->values = (Pointer) score;
988 sgp->max.realvalue = maxscore;
989 sgp->min.realvalue = 0.0;
990 sgp->flags[1] = 1;
991 sgp->a = 4.0;
992 sgp->b = 0.0;
993 if (seg == NULL)
994 seg = CreatePicture ();
995 if ((gsp = AddGraphSentinelToPicture (sgp, xosp->bsp, seg, 0,
996 top, 0, NULL)) != NULL)
997 {
998 sprintf (numberbuffer, "%ld", 1L);
999 AddLabel (seg, gsp->box.left, gsp->bottom-20,
1000 numberbuffer, SMALL_TEXT, 0, MIDDLE_CENTER, 0);
1001 sprintf (numberbuffer, "%ld", (long) xosp->bsp->length);
1002 AddLabel (seg, gsp->box.left+xosp->bsp->length, gsp->bottom-20,
1003 numberbuffer, SMALL_TEXT, 0, MIDDLE_CENTER, 0);
1004 }
1005 shift = (Int4) (maxscore*sgp->a);
1006 orftop[iframe] = top - shift - 38;
1007 top -= (shift+56);
1008 frame++;
1009 if (frame == 3)
1010 {
1011 top -= 24;
1012 frame = 0;
1013 }
1014 }
1015 frame = 0;
1016 for (iframe = 0; iframe < 6; iframe++)
1017 {
1018 if (iframe < 3)
1019 strand = Seq_strand_plus;
1020 else
1021 strand = Seq_strand_minus;
1022 shift = 0;
1023 if (xosp->slpa != NULL)
1024 {
1025 AddOrfClass (xosp->slpa, seg, orftop, iframe, frame,
1026 shift, strand, YELLOW_COLOR, 5);
1027 shift += 4;
1028 }
1029 if (xosp->slpk != NULL)
1030 {
1031 AddOrfClass (xosp->slpk, seg, orftop, iframe, frame,
1032 shift, strand, GREEN_COLOR, 5);
1033 shift += 4;
1034 }
1035 if (xosp->slpb != NULL)
1036 {
1037 AddOrfClass (xosp->slpb, seg, orftop, iframe, frame,
1038 shift, strand, BLUE_COLOR, 5);
1039 shift += 4;
1040 }
1041 if (xosp->slps != NULL)
1042 {
1043 AddOrfClass (xosp->slps, seg, orftop, iframe, frame,
1044 shift, strand, RED_COLOR, 5);
1045 }
1046 frame++;
1047 if (frame == 3)
1048 frame = 0;
1049 }
1050 MemFree (tableGlobal);
1051
1052 start = 20;
1053 stop = 20 + (50*XScale);
1054 top = orftop[5] - 40;
1055 if (xosp->slpa != NULL)
1056 {
1057 top -= 12;
1058 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1059 YELLOW_COLOR, SOLID_LINE, SOLID_SHADING, 5,
1060 0);
1061 AddLine (seg, start, top, stop, top, FALSE, 0);
1062 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1063 BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH,
1064 0);
1065 AddLabel (seg, stop+(20*XScale), top,
1066 "All Met-init'd ORFs equal to or greater than 50 codons",
1067 SMALL_TEXT, 0, MIDDLE_RIGHT, 0);
1068 }
1069 if (xosp->slpk != NULL)
1070 {
1071 top -= 12;
1072 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1073 GREEN_COLOR, SOLID_LINE, SOLID_SHADING, 5,
1074 0);
1075 AddLine (seg, start, top, stop, top, FALSE, 0);
1076 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1077 BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH,
1078 0);
1079 AddLabel (seg, stop+(20*XScale), top, "Annotated (reported) ORFs",
1080 SMALL_TEXT, 0, MIDDLE_RIGHT, 0);
1081 }
1082 if (xosp->slpb != NULL)
1083 {
1084 top -= 12;
1085 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1086 BLUE_COLOR, SOLID_LINE, SOLID_SHADING, 5,
1087 0);
1088 AddLine (seg, start, top, stop, top, FALSE, 0);
1089 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1090 BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH,
1091 0);
1092 AddLabel (seg, stop+(20*XScale), top, "Similar codon usage bias ORFs to seed ORFs",
1093 SMALL_TEXT, 0, MIDDLE_RIGHT, 0);
1094 }
1095 if (xosp->slps != NULL)
1096 {
1097 top -= 12;
1098 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1099 RED_COLOR, SOLID_LINE, SOLID_SHADING, 5,
1100 0);
1101 AddLine (seg, start, top, stop, top, FALSE, 0);
1102 AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT),
1103 BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH,
1104 0);
1105 AddLabel (seg, stop+(20*XScale), top, "Pattern match seed ORFs",
1106 SMALL_TEXT, 0, MIDDLE_RIGHT, 0);
1107 }
1108
1109 xisp->picture = seg;
1110
1111 w = FixedWindow (10, 10, 640, 720, "Consign", CloseGraphWindowProc);
1112 SetObjectExtra (w, xisp, CleanUpGraphWindow);
1113 g = HiddenGroup (w, -1, 0, NULL);
1114 v = CreateViewer (g, 560, 640, TRUE, TRUE);
1115 AttachPicture (v, seg, INT4_MIN, INT4_MAX, UPPER_LEFT, XScale, 1, NULL);
1116 PushButton (g, "Close", CloseGraphWindowButton);
1117 RealizeWindow (w);
1118 ArrowCursor ();
1119 Show (w);
1120
1121 return;
1122 }
1123
1124 /* button 5 */
1125
1126 static void CloseConsignParentProc (WindoW w)
1127 {
1128 XOSPtr xosp;
1129
1130 if ((xosp = (XOSPtr) GetObjectExtra (w)) != NULL)
1131 {
1132 CleanUpXOS (xosp);
1133 MemFree (xosp->pattern_file);
1134 MemFree (xosp);
1135 }
1136 Remove (w);
1137 QuitProgram ();
1138 return;
1139 }
1140
1141 static void EndProg (ButtoN b)
1142 {
1143 CloseConsignParentProc (ParentWindow (b));
1144 return;
1145 }
1146
1147 /* parent */
1148
1149 static XOSPtr SetUp (void)
1150 {
1151 static GatherScope gs;
1152 GatherScopePtr gsp;
1153 XOSPtr xosp;
1154
1155 gsp = &gs;
1156 MemSet ((Pointer) gsp, 0, sizeof (GatherScope));
1157 MemSet ((Pointer) gsp->ignore, (int) (TRUE),
1158 (size_t) (OBJ_MAX * sizeof (Boolean)));
1159 gsp->ignore[OBJ_BIOSEQ] = FALSE;
1160 gsp->ignore[OBJ_SEQANNOT] = FALSE;
1161
1162 xosp = MemNew (sizeof (XOS));
1163
1164 xosp->flagParamWindow = FALSE;
1165 xosp->gi = 0;
1166 xosp->filename = NULL;
1167 xosp->gsp = gsp;
1168 xosp->sep = NULL;
1169 xosp->bsp = NULL;
1170
1171 xosp->pattern_file = StringSave ("ncbipros.dat");
1172 xosp->gcd = NULL;
1173 xosp->gcdi = NULL;
1174
1175 xosp->orfcut = 150;
1176 xosp->cutoff = 18;
1177 xosp->cutoffmin = 0;
1178 xosp->cutoffmax = 100;
1179 xosp->window = 360;
1180 xosp->windowmin = 150;
1181 xosp->windowmax = 3000;
1182
1183 xosp->orflist = NULL;
1184 xosp->slpa = NULL;
1185 xosp->slpb = NULL;
1186 xosp->slps = NULL;
1187 xosp->slpk = NULL;
1188
1189 xosp->probcut = 0.5;
1190 xosp->clustmin = 2;
1191 xosp->findmin = 4;
1192 xosp->minimumseed = 1800;
1193
1194 return xosp;
1195 }
1196
1197 Int2 Main (void)
1198 {
1199 WindoW w;
1200 GrouP g;
1201 ButtoN b1, b2, b3, b4, b5;
1202 XOSPtr xosp;
1203
1204 ProcessUpdatesFirst (FALSE);
1205
1206 xosp = SetUp ();
1207
1208 w = FixedWindow (-50, -33, -10, -10,
1209 "Consign", CloseConsignParentProc);
1210 g = HiddenGroup (w, 7, 0, NULL);
1211 b1 = PushButton (g, " Input GI ", ReadGIProc);
1212 b2 = PushButton (g, "Input FastA", ReadFileProc);
1213 b3 = PushButton (g, " Parameters", ConsignParamProc);
1214 b4 = PushButton (g, " Consign ", ConsignProc);
1215 b5 = PushButton (g, " Finish ", EndProg);
1216
1217 SetObjectExtra (w, xosp, NULL);
1218 SetObjectExtra (b1, xosp, NULL);
1219 SetObjectExtra (b2, xosp, NULL);
1220 SetObjectExtra (b3, xosp, NULL);
1221 SetObjectExtra (b4, xosp, NULL);
1222 SetObjectExtra (b5, xosp, NULL);
1223
1224 Show (w);
1225 ProcessEvents ();
1226 return 0;
1227 }
1228 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |