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