NCBI C Toolkit Cross Reference

C/demo/cnsrtv.c


  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: cnsrtv.c
 27 *
 28 * Author(s): John Kuzio
 29 *
 30 * Version Creation Date: 98-01-01
 31 *
 32 * $Revision: 6.2 $
 33 *
 34 * File Description: consort - codon usage/bias tree
 35 *
 36 * Modifications:
 37 * --------------------------------------------------------------------------
 38 * Date       Name        Description of modification
 39 * --------------------------------------------------------------------------
 40 * $Log: cnsrtv.c,v $
 41 * Revision 6.2  1998/09/16 18:40:34  kuzio
 42 * cvs logging
 43 *
 44 * ==========================================================================
 45 */
 46 
 47 #include <ncbi.h>
 48 #include <vibrant.h>
 49 #include <accentr.h>
 50 #include <gather.h>
 51 #include <tofasta.h>
 52 #include <urkutil.h>
 53 #include <urkcnsrt.h>
 54 #include <urktree.h>
 55 #include <gtrdraw.h>
 56 #include <seqscrl.h>
 57 
 58 #define TOP_ERROR 1
 59 static char _this_module[] = "cnsrtv";
 60 #undef  THIS_MODULE
 61 #define THIS_MODULE _this_module
 62 static char _this_file[] = __FILE__;
 63 #undef  THIS_FILE
 64 #define THIS_FILE _this_file
 65 
 66 typedef struct xtrins
 67 {
 68   Int4           Xscale, Yscale, Xdelta;
 69   SegmenT        picture;
 70 } XIS, PNTR XISPtr;
 71 
 72 typedef struct xtrobj
 73 {
 74   Boolean        flagParamWindow;
 75   Int4           gi;
 76   CharPtr        filename;
 77   GatherScopePtr gsp;
 78   SeqEntryPtr    sep;
 79   BioseqPtr      bsp;
 80   Int4           xdeltaval, xdeltamin, xdeltamax;
 81   Int4           ydeltaval, ydeltamin, ydeltamax;
 82   Int4           treestyle;
 83   GrouP          gstyle;
 84 } XOS, PNTR XOSPtr;
 85 
 86 /* common */
 87 
 88 static Boolean GetBioseq (GatherContextPtr gcp)
 89 {
 90   XOSPtr         xosp;
 91   BioseqPtr      bsp;
 92   Int4           entrezgi;
 93 
 94   if (gcp == NULL)
 95     return FALSE;
 96   if ((xosp = (XOSPtr) gcp->userdata) == NULL)
 97     return FALSE;
 98   if (xosp->bsp != NULL)
 99     return TRUE;
100 
101   if (gcp->thistype != OBJ_BIOSEQ)
102     return TRUE;
103   if ((bsp = (BioseqPtr) (gcp->thisitem)) == NULL)
104     return TRUE;
105   if (xosp->gi > 0)
106   {
107     entrezgi = GetGIForSeqId (bsp->id);
108     if (xosp->gi == entrezgi)
109       xosp->bsp = bsp;
110     return TRUE;
111   }
112   if (xosp->filename != NULL)
113   {
114     xosp->bsp = bsp;
115     return TRUE;
116   }
117   return TRUE;
118 }
119 
120 static void GetThisBioseq (XOSPtr xosp)
121 {
122   GatherScopePtr  gsp;
123   CharPtr         asnseqentfile;
124   Int4            gi;
125   AsnIoPtr        aiop;
126   Boolean         flagHaveNet;
127   SeqEntryPtr     sep;
128 
129   gsp = xosp->gsp;
130 
131   aiop = NULL;
132   asnseqentfile = xosp->filename;
133   gi = xosp->gi;
134   xosp->sep = SeqEntryFree (xosp->sep);
135 
136   if (gi > 0)
137   {
138     if (!EntrezInit ("twopv", FALSE, &flagHaveNet))
139     {
140       ErrPostEx (SEV_ERROR, TOP_ERROR, 102,
141                  "Entrez init failed");
142       ErrShow ();
143       return;
144     }
145   }
146 
147   if (gi > 0)
148   {
149     sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_BIOSEQ);
150   }
151   else if (asnseqentfile != NULL)
152   {
153     if ((aiop = AsnIoOpen (asnseqentfile, "r")) == NULL)
154     {
155       Message (MSG_ERROR, "Failed to open: %s", asnseqentfile);
156     }
157     sep = SeqEntryAsnRead (aiop, NULL);
158   }
159   else
160   {
161     sep = NULL;
162   }
163 
164   if (sep == NULL)
165   {
166     ErrPostEx (SEV_ERROR, TOP_ERROR, 104,
167                "No SeqEntry");
168     ErrShow ();
169   }
170   else
171   {
172     xosp->sep = sep;
173     xosp->bsp = NULL;
174     xosp->gi = gi;
175     GatherSeqEntry (sep, (Pointer) xosp, GetBioseq, (Pointer) gsp);
176   }
177 
178   if (gi > 0)
179     EntrezFini ();
180   else
181     AsnIoClose (aiop);
182 
183   if (xosp->bsp != NULL)
184   {
185     if (!ISA_na (xosp->bsp->mol))
186     {
187       xosp->sep = SeqEntryFree (xosp->sep);
188       xosp->bsp = NULL;
189       xosp->filename = (CharPtr) MemFree (xosp->filename);
190       xosp->gi = 0;
191       ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Not nucleic acid Bioseq");
192       ErrShow ();
193     }
194   }
195   else
196   {
197     xosp->sep = SeqEntryFree (xosp->sep);
198     xosp->filename = (CharPtr) MemFree (xosp->filename);
199     xosp->gi = 0;
200     ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Bioseq");
201     ErrShow ();
202   }
203   return;
204 }
205 
206 /* button 1 */
207 
208 static void CloseGIWindowProc (WindoW w)
209 {
210   Remove (w);
211   return;
212 }
213 
214 static void SetGIProc (ButtoN b)
215 {
216   TexT     pc;
217   XOSPtr   xosp;
218   Char     buf[16];
219 
220   if ((pc = (TexT) GetObjectExtra (b)) != NULL)
221   {
222     if ((xosp = (XOSPtr) GetObjectExtra (pc)) != NULL)
223     {
224       GetTitle (pc, buf, sizeof (buf));
225       xosp->gi = atol (buf);
226       xosp->filename = (CharPtr) MemFree (xosp->filename);
227       GetThisBioseq (xosp);
228     }
229   }
230   CloseGIWindowProc (ParentWindow (b));
231   return;
232 }
233 
234 static void ReadGIProc (ButtoN b)
235 {
236   WindoW   w;
237   GrouP    h, g;
238   ButtoN   bt;
239   TexT     pc;
240   CharPtr  winprmt = "Entrez GI";
241   XOSPtr   xosp;
242 
243   if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
244   {
245     w = MovableModalWindow (-60, -33, -10, -10, winprmt, CloseGIWindowProc);
246     h = HiddenGroup (w, 1, 0, NULL);
247     StaticPrompt (h, winprmt, StringWidth (winprmt),
248                   dialogTextHeight, NULL, 'c');
249     g = HiddenGroup (h, 2, 0, NULL);
250     pc = DialogText (g, "", 8, NULL);
251     bt = PushButton (h, "  Okay  ", SetGIProc);
252     SetObjectExtra (pc, xosp, NULL);
253     SetObjectExtra (bt, pc, NULL);
254     Show (w);
255     Select (w);
256   }
257   return;
258 }
259 
260 /* button 2 */
261 
262 static void ReadFileProc (ButtoN b)
263 {
264   XOSPtr  xosp;
265   Char    filename[PATH_MAX];
266 
267   if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
268   {
269     if (!GetInputFileName (filename, PATH_MAX, "", "TEXT"))
270     {
271       ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Could not read directory");
272       ErrShow ();
273     }
274     else
275     {
276       MemFree (xosp->filename);
277       xosp->filename = StringSave (filename);
278       xosp->gi = 0;
279       GetThisBioseq (xosp);
280     }
281   }
282   return;
283 }
284 
285 /* button 3 */
286 
287 static void CloseParamWindowProc (WindoW w)
288 {
289   SeqScrollDataPtr ssdp;
290 
291   if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
292     SeqScrollDataFree (ssdp);
293   Remove (w);
294   return;
295 }
296 
297 static void ApplyParams (ButtoN b)
298 {
299   WindoW  w;
300   XOSPtr  xosp;
301 
302   SeqScrollDataPtr ssdp;
303 
304   if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
305   {
306     w = ParentWindow (b);
307     if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
308     {
309       xosp->xdeltaval = (Int4) ssdp->curval;
310       ssdp = ssdp->next;
311       xosp->ydeltaval = (Int4) ssdp->curval;
312     }
313     xosp->treestyle = (Int4) GetValue (xosp->gstyle);
314     xosp->treestyle -= 1;
315   }
316   return;
317 }
318 
319 static void ClearWindowFlag (ButtoN b)
320 {
321   XOSPtr  xosp;
322 
323   if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
324     xosp->flagParamWindow = FALSE;
325   return;
326 }
327 
328 static void AcceptParamProc (ButtoN b)
329 {
330   ApplyParams (b);
331   CloseParamWindowProc (ParentWindow (b));
332   ClearWindowFlag (b);
333   return;
334 }
335 
336 static void UpdateParamProc (ButtoN b)
337 {
338   ApplyParams (b);
339   return;
340 }
341 
342 static void CancelParamProc (ButtoN b)
343 {
344   CloseParamWindowProc (ParentWindow (b));
345   ClearWindowFlag (b);
346   return;
347 }
348 
349 static void ConsortParamProc (ButtoN b)
350 {
351   WindoW           w;
352   GrouP            h, h1, g, g1;
353   ButtoN           b1, b2, b3;
354   XOSPtr           xosp;
355 
356   SeqScrollDataPtr ssdp = NULL;
357 
358   if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
359     return;
360   if (xosp->flagParamWindow)
361     return;
362 
363   w = FixedWindow (-75, -10, -10, -10,
364                    "Consort Parameters", CloseParamWindowProc);
365   h = HiddenGroup (w, 1, 0, NULL);
366   h1 = HiddenGroup (h, 2, 0, NULL);
367 
368   g1 = HiddenGroup (h1, 1, 0, NULL);
369   g = HiddenGroup (g1, 1, 0, NULL);
370   StaticPrompt (g, "xdelta", StringWidth ("1234567890"), dialogTextHeight,
371                 NULL, 'c');
372   g = HiddenGroup (g1, 2, 0, NULL);
373   AddScrollControl (&ssdp, g, (Int2) xosp->xdeltaval,
374                     (Int2) xosp->xdeltamin, (Int2) xosp->xdeltamax, 24);
375 
376   g1 = HiddenGroup (h1, 1, 0, NULL);
377   g = HiddenGroup (g1, 1, 0, NULL);
378   StaticPrompt (g, "ydelta", StringWidth ("1234567890"), dialogTextHeight,
379                 NULL, 'c');
380   g = HiddenGroup (g1, 2, 0, NULL);
381   AddScrollControl (&ssdp, g, (Int2) xosp->ydeltaval,
382                     (Int2) xosp->ydeltamin, (Int2) xosp->ydeltamax, 24);
383 
384   SetObjectExtra (w, ssdp, NULL);
385 
386   h1 = HiddenGroup (h, 1, 0, NULL);
387   StaticPrompt (h1, "tree style", 0, dialogTextHeight, NULL, 'l');
388   g = HiddenGroup (h1, 1, 0, NULL);
389   RadioButton (g, "LR");
390   RadioButton (g, "TB");
391   SetValue (g, 1);
392   xosp->gstyle = g;
393 
394   h1 = HiddenGroup (h, 3, 0, NULL);
395   b1 = PushButton (h1, "Accept", AcceptParamProc);
396   SetObjectExtra (b1, xosp, NULL);
397   b2 = PushButton (h1, "Apply ", UpdateParamProc);
398   SetObjectExtra (b2, xosp, NULL);
399   b3 = PushButton (h1, "Cancel", CancelParamProc);
400   SetObjectExtra (b3, xosp, NULL);
401 
402   Show (w);
403   Select (w);
404   xosp->flagParamWindow = TRUE;
405   return;
406 }
407 
408 /* button 4 */
409 
410 static void CleanUpGraphWindow (GraphiC g, VoidPtr data)
411 {
412   XISPtr  xisp;
413 
414   if ((xisp = (XISPtr) data) != NULL)
415   {
416     DeletePicture (xisp->picture);
417   }
418   StdCleanupExtraProc (g, data);
419 }
420 
421 static void CloseGraphWindowProc (WindoW w)
422 {
423   Remove (w);
424   return;
425 }
426 
427 static void CloseGraphWindowButton (ButtoN b)
428 {
429   CloseGraphWindowProc (ParentWindow (b));
430   return;
431 }
432 
433 static void ConsortProc (ButtoN b)
434 {
435   XOSPtr         xosp;
436   XISPtr         xisp;
437   TreeNodePtr    ptrNode;
438 
439   WindoW      w;
440   VieweR      v;
441   GrouP       g;
442   SegmenT     seg;
443   Int4        xmax, xmin;
444   Int4        xoffset, yoffset;
445 
446   if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
447     return;
448 
449   if (xosp->sep == NULL)
450   {
451     ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No SeqEntry");
452     ErrShow ();
453     return;
454   }
455 
456   WatchCursor ();
457 
458   xoffset = xosp->xdeltaval;
459   yoffset = xosp->ydeltaval;
460 
461   ptrNode = ConsortSeqEntry (xosp->sep);
462   SetAllLeftRightRootedTreeNeighbors (ptrNode);
463   SetAllPivotNodes (ptrNode);
464   switch (xosp->treestyle)
465   {
466    default:
467    case 0:
468     SetAllTheoreticalCoordinates (ptrNode, 300, 50);
469     AdjustAllTheoreticalCoordinates (ptrNode, 300);
470     ChangeTreeScale (ptrNode, 300, 50, (FloatHi) xoffset, (FloatHi) yoffset);
471     break;
472    case 1:
473     SetAllCoordinates (ptrNode, 300, 50, xoffset, yoffset);
474     break;
475   }
476   xmin = GetMinimumTreeXcoord (ptrNode);
477   if (xmin-50 > 0)
478     ShiftTree (ptrNode, (-1*(xmin-50)), 0);
479   if (xmin < 0)
480     ShiftTree (ptrNode, ((-1*xmin)+50), 0);
481 
482   xmin = GetMinimumTreeXcoord (ptrNode);
483   xmax = GetMaximumTreeXcoord (ptrNode);
484   if (xmin < 0)
485     xmin *= -1;
486   if (xmax < 0)
487     xmax *= -1;
488   xisp = (XISPtr) MemNew (sizeof (XIS));
489   if (xmax > xmin)
490     xisp->Xdelta = (2*(xmax+100)) + 10;
491   else
492     xisp->Xdelta = (2*(xmin+100)) + 10;
493   seg = DrawTree (ptrNode);
494   xisp->picture = seg;
495 
496   w = FixedWindow (10, 10, 640, 640, "Consort", CloseGraphWindowProc);
497   SetObjectExtra (w, xisp, CleanUpGraphWindow);
498   g = HiddenGroup (w, -1, 0, NULL);
499   v = CreateViewer (g, 560, 560, TRUE, TRUE);
500   AttachPicture (v, seg, INT4_MIN, INT4_MAX, UPPER_LEFT, 1, 1, NULL);
501   PushButton (g, "Close", CloseGraphWindowButton);
502   RealizeWindow (w);
503   ArrowCursor ();
504   Show (w);
505 
506   return;
507 }
508 
509 /* button 5 */
510 
511 static void CloseConsortParentProc (WindoW w)
512 {
513   XOSPtr  xosp;
514 
515   if ((xosp = (XOSPtr) GetObjectExtra (w)) != NULL)
516   {
517     xosp->gsp  = NULL;          /* is static */
518     MemFree (xosp->filename);
519     xosp->sep = SeqEntryFree (xosp->sep);
520     xosp->bsp = NULL;           /* should be in seqentry */
521     MemFree (xosp);
522   }
523   Remove (w);
524   QuitProgram ();
525   return;
526 }
527 
528 static void EndProg (ButtoN b)
529 {
530   CloseConsortParentProc (ParentWindow (b));
531   return;
532 }
533 
534 /* parent */
535 
536 static XOSPtr SetUp (void)
537 {
538   static GatherScope  gs;
539   GatherScopePtr      gsp;
540   XOSPtr              xosp;
541 
542   gsp = &gs;
543   MemSet ((Pointer) gsp, 0, sizeof (GatherScope));
544   MemSet ((Pointer) gsp->ignore, (int) (TRUE),
545           (size_t) (OBJ_MAX * sizeof (Boolean)));
546   gsp->ignore[OBJ_BIOSEQ] = FALSE;
547 
548   xosp = MemNew (sizeof (XOS));
549 
550   xosp->flagParamWindow = FALSE;
551   xosp->gi = 0;
552   xosp->filename = NULL;
553   xosp->gsp = gsp;
554   xosp->sep = NULL;
555   xosp->bsp = NULL;
556   xosp->xdeltamin = 1;
557   xosp->xdeltamax = 64;
558   xosp->xdeltaval = 20;
559   xosp->ydeltamin = 1;
560   xosp->ydeltamax = 64;
561   xosp->ydeltaval = 20;
562   xosp->treestyle = 0;
563 
564   return xosp;
565 }
566 
567 Int2 Main (void)
568 {
569   WindoW  w;
570   GrouP   g;
571   ButtoN  b1, b2, b3, b4, b5;
572   XOSPtr  xosp;
573 
574   ProcessUpdatesFirst (FALSE);
575 
576   xosp = SetUp ();
577 
578   w = FixedWindow (-50, -33, -10, -10,
579                    "Consort", CloseConsortParentProc);
580   g = HiddenGroup (w, 7, 0, NULL);
581   b1 = PushButton (g, " Input GI ", ReadGIProc);
582   b2 = PushButton (g, " Input ASN", ReadFileProc);
583   b3 = PushButton (g, "Parameters", ConsortParamProc);
584   b4 = PushButton (g, "  Consort ", ConsortProc);
585   b5 = PushButton (g, "  Finish  ", EndProg);
586 
587   SetObjectExtra (w,  xosp, NULL);
588   SetObjectExtra (b1, xosp, NULL);
589   SetObjectExtra (b2, xosp, NULL);
590   SetObjectExtra (b3, xosp, NULL);
591   SetObjectExtra (b4, xosp, NULL);
592   SetObjectExtra (b5, xosp, NULL);
593 
594   Show (w);
595   ProcessEvents ();
596   return 0;
597 }
598 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.