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: ccpv.c
27 *
28 * Author(s): John Kuzio
29 *
30 * Version Creation Date: 98-01-01
31 *
32 * $Revision: 6.4 $
33 *
34 * File Description: coiled coil prediction
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * --------------------------------------------------------------------------
40 * $Log: ccpv.c,v $
41 * Revision 6.4 1998/09/16 18:40:33 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 <urkpcc.h>
54 #include <seqscrl.h>
55 #include <gphdraw.h>
56
57 #define TOP_ERROR 1
58 static char _this_module[] = "ccpv";
59 #undef THIS_MODULE
60 #define THIS_MODULE _this_module
61 static char _this_file[] = __FILE__;
62 #undef THIS_FILE
63 #define THIS_FILE _this_file
64
65 typedef struct xtrins
66 {
67 SeqGraphPtr sgp;
68 Int4 Xscale, Yscale;
69 Int4 Xaxislen, Yaxislen;
70 Int4 Xprelen, Xpostlen, Yprelen, Ypostlen;
71 RecT dr;
72 } XIS, PNTR XISPtr;
73
74 typedef struct xtrobj
75 {
76 Boolean flagParamWindow;
77 Int4 gi;
78 CharPtr filename;
79 GatherScopePtr gsp;
80 SeqEntryPtr sep;
81 BioseqPtr bsp;
82 PccDatPtr pccp;
83 } XOS, PNTR XOSPtr;
84
85 /* button 1 */
86
CloseGIWindowProc(WindoW w)87 static void CloseGIWindowProc (WindoW w)
88 {
89 Remove (w);
90 return;
91 }
92
SetGIProc(ButtoN b)93 static void SetGIProc (ButtoN b)
94 {
95 TexT pc;
96 XOSPtr xosp;
97 Char buf[16];
98
99 if ((pc = (TexT) GetObjectExtra (b)) != NULL)
100 {
101 if ((xosp = (XOSPtr) GetObjectExtra (pc)) != NULL)
102 {
103 GetTitle (pc, buf, sizeof (buf));
104 xosp->gi = atol (buf);
105 xosp->filename = (CharPtr) MemFree (xosp->filename);
106 }
107 }
108 CloseGIWindowProc (ParentWindow (b));
109 return;
110 }
111
ReadGIProc(ButtoN b)112 static void ReadGIProc (ButtoN b)
113 {
114 WindoW w;
115 GrouP h, g;
116 ButtoN bt;
117 TexT pc;
118 CharPtr winprmt = "Entrez GI";
119 XOSPtr xosp;
120
121 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
122 {
123 w = MovableModalWindow (-60, -33, -10, -10, winprmt, CloseGIWindowProc);
124 h = HiddenGroup (w, 1, 0, NULL);
125 StaticPrompt (h, winprmt, StringWidth (winprmt),
126 dialogTextHeight, NULL, 'c');
127 g = HiddenGroup (h, 2, 0, NULL);
128 pc = DialogText (g, "", 8, NULL);
129 bt = PushButton (h, " Okay ", SetGIProc);
130 SetObjectExtra (pc, xosp, NULL);
131 SetObjectExtra (bt, pc, NULL);
132 Show (w);
133 Select (w);
134 }
135 return;
136 }
137
138 /* button 2 */
139
ReadFileProc(ButtoN b)140 static void ReadFileProc (ButtoN b)
141 {
142 XOSPtr xosp;
143 Char filename[PATH_MAX];
144
145 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
146 {
147 if (!GetInputFileName (filename, PATH_MAX, "", "TEXT"))
148 {
149 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Could not read directory");
150 ErrShow ();
151 }
152 else
153 {
154 MemFree (xosp->filename);
155 xosp->filename = StringSave (filename);
156 xosp->gi = 0;
157 }
158 }
159 return;
160 }
161
162 /* button 3 */
163
CloseParamWindowProc(WindoW w)164 static void CloseParamWindowProc (WindoW w)
165 {
166 SeqScrollDataPtr ssdp;
167
168 if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
169 SeqScrollDataFree (ssdp);
170 Remove (w);
171 return;
172 }
173
ApplyParams(ButtoN b)174 static void ApplyParams (ButtoN b)
175 {
176 WindoW w;
177 XOSPtr xosp;
178
179 SeqScrollDataPtr ssdp;
180
181 w = ParentWindow (b);
182 if ((ssdp = (SeqScrollDataPtr) GetObjectExtra (w)) != NULL)
183 {
184 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
185 {
186 if (xosp->pccp != NULL)
187 {
188 xosp->pccp->window = (Int4) ssdp->curval;
189 ssdp = ssdp->next;
190 xosp->pccp->linker = (Int4) ssdp->curval;
191 }
192 }
193 }
194 return;
195 }
196
ClearWindowFlag(ButtoN b)197 static void ClearWindowFlag (ButtoN b)
198 {
199 XOSPtr xosp;
200
201 if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
202 xosp->flagParamWindow = FALSE;
203 return;
204 }
205
AcceptParamProc(ButtoN b)206 static void AcceptParamProc (ButtoN b)
207 {
208 ApplyParams (b);
209 CloseParamWindowProc (ParentWindow (b));
210 ClearWindowFlag (b);
211 return;
212 }
213
UpdateParamProc(ButtoN b)214 static void UpdateParamProc (ButtoN b)
215 {
216 ApplyParams (b);
217 return;
218 }
219
CancelParamProc(ButtoN b)220 static void CancelParamProc (ButtoN b)
221 {
222 CloseParamWindowProc (ParentWindow (b));
223 ClearWindowFlag (b);
224 return;
225 }
226
CcpParamProc(ButtoN b)227 static void CcpParamProc (ButtoN b)
228 {
229 WindoW w;
230 GrouP h, g, h1;
231 ButtoN b1, b2, b3;
232 XOSPtr xosp;
233
234 SeqScrollDataPtr ssdp_ccp = NULL;
235
236 if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
237 return;
238 if (xosp->flagParamWindow)
239 return;
240
241 w = FixedWindow (-50, -10, -10, -10,
242 "Ccp Parameters", CloseParamWindowProc);
243
244 h = HiddenGroup (w, 1, 0, NULL);
245 h1 = HiddenGroup (h, 2, 0, NULL);
246 StaticPrompt (h1, "window", StringWidth ("window"), dialogTextHeight,
247 NULL, 'c');
248 StaticPrompt (h1, "linker", StringWidth ("linker"), dialogTextHeight,
249 NULL, 'c');
250 h1 = HiddenGroup (h, 2, 0, NULL);
251 g = HiddenGroup (h1, 2, 0, NULL);
252 AddScrollControl (&ssdp_ccp, g, 22, 7, 42, 24);
253 g = HiddenGroup (h1, 2, 0, NULL);
254 AddScrollControl (&ssdp_ccp, g, 0, 0, 64, 24);
255 SetObjectExtra (w, ssdp_ccp, NULL);
256
257 h1 = HiddenGroup (h, 3, 0, NULL);
258 b1 = PushButton (h1, "Accept", AcceptParamProc);
259 SetObjectExtra (b1, xosp, NULL);
260 b2 = PushButton (h1, "Apply ", UpdateParamProc);
261 SetObjectExtra (b2, xosp, NULL);
262 b3 = PushButton (h1, "Cancel", CancelParamProc);
263 SetObjectExtra (b3, xosp, NULL);
264
265 Show (w);
266 Select (w);
267 xosp->flagParamWindow = TRUE;
268
269 return;
270 }
271
272 /* button 4 */
273
GetBioseq(GatherContextPtr gcp)274 static Boolean GetBioseq (GatherContextPtr gcp)
275 {
276 XOSPtr xosp;
277 BioseqPtr bsp;
278 Int4 gi, entrezgi;
279
280 if (gcp == NULL)
281 return FALSE;
282 if ((xosp = (XOSPtr) gcp->userdata) == NULL)
283 return FALSE;
284
285 if (xosp->bsp != NULL)
286 return TRUE;
287 if (gcp->thistype != OBJ_BIOSEQ)
288 return TRUE;
289 if ((bsp = (BioseqPtr) (gcp->thisitem)) == NULL)
290 return TRUE;
291
292 gi = xosp->gi;
293 if (gi > 0)
294 {
295 entrezgi = GetGIForSeqId (bsp->id);
296 if (gi == entrezgi)
297 xosp->bsp = bsp;
298 return TRUE;
299 }
300 else
301 {
302 xosp->bsp = bsp;
303 return TRUE;
304 }
305 }
306
CloseGraphWindowProc(WindoW w)307 static void CloseGraphWindowProc (WindoW w)
308 {
309 XISPtr xisp;
310
311 if ((xisp = (XISPtr) GetObjectExtra (w)) != NULL)
312 {
313 xisp->sgp = SeqGraphFree (xisp->sgp);
314 MemFree (xisp);
315 }
316 Remove (w);
317 return;
318 }
319
CloseGraphPanelProc(PaneL p,PoinT pt)320 static void CloseGraphPanelProc (PaneL p, PoinT pt)
321 {
322 CloseGraphWindowProc (ParentWindow (p));
323 return;
324 }
325
DrawGraph(PaneL p)326 static void DrawGraph (PaneL p)
327 {
328 XISPtr xisp;
329 WindoW w;
330 RecT r;
331 Int4 len;
332
333 w = ParentWindow (p);
334 if ((xisp = (XISPtr) GetObjectExtra (w)) == NULL)
335 return;
336
337 len = xisp->sgp->numval;
338
339 xisp->Xscale = len / xisp->Xaxislen;
340 if ((len % xisp->Xaxislen) != 0)
341 (xisp->Xscale)++;
342
343 ObjectRect (p, &r);
344 xisp->dr.left = r.left;
345 xisp->dr.top = r.top;
346 xisp->dr.right = r.right;
347 xisp->dr.bottom = r.bottom - (Int2) (xisp->Ypostlen);
348 DrawGraphToPanel (xisp->sgp, xisp->Xscale, xisp->Yscale,
349 xisp->Yaxislen, &(xisp->dr), 1,
350 xisp->sgp->numval);
351 return;
352 }
353
CcpProc(ButtoN b)354 static void CcpProc (ButtoN b)
355 {
356 Boolean flagHaveNet;
357
358 SeqEntryPtr sep;
359 Int4 i, gi;
360 CharPtr fastafile;
361 FILE *fiop;
362 CharPtr title;
363
364 GatherScopePtr gsp;
365 XOSPtr xosp;
366 XISPtr xisp;
367
368 FloatHi minscore, maxscore;
369 FloatHiPtr pcs, pccscr;
370 SeqGraphPtr sgp;
371
372 WindoW w;
373 PaneL p;
374
375 if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL)
376 return;
377
378 if (ReadPccData (xosp->pccp) == 0)
379 {
380 ErrPostEx (SEV_ERROR, TOP_ERROR, 101,
381 "Could not open or read %s data file", xosp->pccp->pccdatafile);
382 ErrShow ();
383 return;
384 }
385
386 gsp = xosp->gsp;
387 gi = xosp->gi;
388 fastafile = xosp->filename;
389
390 if (gi > 0)
391 {
392 if (!EntrezInit ("ccpv", FALSE, &flagHaveNet))
393 {
394 ErrPostEx (SEV_ERROR, TOP_ERROR, 102,
395 "Entrez init failed");
396 ErrShow ();
397 xosp->pccp->res = (CharPtr) MemFree (xosp->pccp->res);
398 return;
399 }
400 }
401
402 if (gi > 0)
403 {
404 sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_BIOSEQ);
405 }
406 else if (fastafile != NULL)
407 {
408 if ((fiop = FileOpen (fastafile, "r")) == NULL)
409 {
410 ErrPostEx (SEV_ERROR, TOP_ERROR, 103,
411 "Failed to open FastA file");
412 ErrShow ();
413 xosp->pccp->res = (CharPtr) MemFree (xosp->pccp->res);
414 return;
415 }
416 sep = FastaToSeqEntry (fiop, FALSE);
417 }
418 else
419 {
420 sep = NULL;
421 }
422
423 if (sep == NULL)
424 {
425 ErrPostEx (SEV_ERROR, TOP_ERROR, 104,
426 "No seqentry");
427 ErrShow ();
428 xosp->pccp->res = (CharPtr) MemFree (xosp->pccp->res);
429 return;
430 }
431 else
432 {
433 xosp->sep = sep;
434 xosp->bsp = NULL;
435 xosp->gi = gi;
436 GatherSeqEntry (sep, (Pointer) xosp, GetBioseq,
437 (Pointer) gsp);
438 if (xosp->bsp != NULL)
439 {
440 if (ISA_aa (xosp->bsp->mol))
441 {
442 pcs = pccscr = PredictCCBioseq (xosp->bsp, 0, xosp->bsp->length-1,
443 xosp->pccp);
444 xosp->pccp->res = (CharPtr) MemFree (xosp->pccp->res);
445 if (pccscr == NULL)
446 {
447 return;
448 }
449 for (i = 0; i < xosp->bsp->length; i++)
450 {
451 *pcs *= 100.0;
452 pcs++;
453 }
454 minscore = 0.0;
455 maxscore = 100.0;
456
457 title = FastaTitle (xosp->bsp, "CCP: >", NULL);
458
459 if ((sgp = SeqGraphNew ()) == NULL)
460 {
461 MemFree (pccscr);
462 MemFree (title);
463 return;
464 }
465
466 xisp = MemNew (sizeof (XIS));
467 xisp->sgp = sgp;
468 xisp->Xscale = 1;
469 xisp->Yscale = 1;
470 xisp->Xaxislen = 250;
471 xisp->Yaxislen = 100;
472 xisp->Xprelen = 0;
473 xisp->Yprelen = 50;
474 xisp->Xpostlen = 50;
475 xisp->Ypostlen = 50;
476 sgp->loc = SeqLocIntNew (0, xosp->bsp->length-1, xosp->bsp->strand,
477 xosp->bsp->id);
478 sgp->title = title;
479 sgp->flags[2] = 1;
480 sgp->numval = xosp->bsp->length;
481 sgp->max.realvalue = maxscore;
482 sgp->min.realvalue = minscore;
483 sgp->values = (Pointer) pccscr;
484
485 w = FixedWindow (-50, -50, -10, -10, "Ccp", CloseGraphWindowProc);
486 SetObjectExtra (w, xisp, NULL);
487 p = SimplePanel (w,
488 (Int2) (xisp->Xprelen+xisp->Xaxislen+xisp->Xpostlen),
489 (Int2) (xisp->Yprelen+xisp->Yaxislen+xisp->Ypostlen),
490 DrawGraph);
491 SetPanelClick (p, NULL, NULL, NULL, CloseGraphPanelProc);
492 RealizeWindow (w);
493 Show (w);
494 }
495 else
496 {
497 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Not an amino acid Bioseq");
498 ErrShow ();
499 }
500 }
501 else
502 {
503 ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Bioseq in SeqEntry");
504 ErrShow ();
505 }
506 xosp->sep = sep = SeqEntryFree (sep);
507 }
508
509 if (gi > 0)
510 EntrezFini ();
511 else
512 FileClose (fiop);
513 return;
514 }
515
516 /* button 5 */
517
CloseCcpParentProc(WindoW w)518 static void CloseCcpParentProc (WindoW w)
519 {
520 XOSPtr xosp;
521
522 if ((xosp = (XOSPtr) GetObjectExtra (w)) != NULL)
523 {
524 MemFree (xosp->filename);
525 xosp->gsp = NULL; /* is static */
526 xosp->sep = SeqEntryFree (xosp->sep);
527 xosp->bsp = NULL; /* should be in seqentry */
528 xosp->pccp = PccDatFree (xosp->pccp);
529 MemFree (xosp);
530 }
531 Remove (w);
532 QuitProgram ();
533 return;
534 }
535
EndProg(ButtoN b)536 static void EndProg (ButtoN b)
537 {
538 CloseCcpParentProc (ParentWindow (b));
539 return;
540 }
541
542 /* parent */
543
SetUp(void)544 static XOSPtr SetUp (void)
545 {
546 static GatherScope gs;
547 GatherScopePtr gsp;
548 XOSPtr xosp;
549
550 gsp = &gs;
551 MemSet ((Pointer) gsp, 0, sizeof (GatherScope));
552 MemSet ((Pointer) gsp->ignore, (int) (TRUE),
553 (size_t) (OBJ_MAX * sizeof (Boolean)));
554 gsp->ignore[OBJ_BIOSEQ] = FALSE;
555
556 xosp = MemNew (sizeof (XOS));
557
558 xosp->flagParamWindow = FALSE;
559 xosp->gi = 0;
560 xosp->filename = NULL;
561 xosp->gsp = gsp;
562 xosp->sep = NULL;
563 xosp->bsp = NULL;
564
565 xosp->pccp = PccDatNew ();
566
567 return xosp;
568 }
569
Main(void)570 Int2 Main (void)
571 {
572 WindoW w;
573 GrouP g;
574 ButtoN b1, b2, b3, b4, b5;
575
576 XOSPtr xosp;
577
578 ProcessUpdatesFirst (FALSE);
579
580 xosp = SetUp ();
581
582 w = FixedWindow (-50, -33, -10, -10,
583 "Coiled Coil Prediction", CloseCcpParentProc);
584 g = HiddenGroup (w, 5, 0, NULL);
585 b1 = PushButton (g, " Input GI ", ReadGIProc);
586 b2 = PushButton (g, "Input FastA", ReadFileProc);
587 b3 = PushButton (g, " Parameters", CcpParamProc);
588 b4 = PushButton (g, " Ccp ", CcpProc);
589 b5 = PushButton (g, " Finish ", EndProg);
590
591 SetObjectExtra (w, xosp, NULL);
592 SetObjectExtra (b1, xosp, NULL);
593 SetObjectExtra (b2, xosp, NULL);
594 SetObjectExtra (b3, xosp, NULL);
595 SetObjectExtra (b4, xosp, NULL);
596 SetObjectExtra (b5, xosp, NULL);
597
598 Show (w);
599 ProcessEvents ();
600 return 0;
601 }
602