|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/desktop/ingenext.c |
source navigation diff markup identifier search freetext search file search |
1 /* ingenext.c
2
3 * ===========================================================================
4 *
5 * PUBLIC DOMAIN NOTICE
6 * National Center for Biotechnology Information (NCBI)
7 *
8 * This software/database is a "United States Government Work" under the
9 * terms of the United States Copyright Act. It was written as part of
10 * the author's official duties as a United States Government employee and
11 * thus cannot be copyrighted. This software/database is freely available
12 * to the public for use. The National Library of Medicine and the U.S.
13 * Government do not place any restriction on its use or reproduction.
14 * We would, however, appreciate having the NCBI and the author cited in
15 * any work or product based on this material
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * ===========================================================================
26 *
27 * File Name: ingenext.c
28 *
29 * Author: Fasika Aklilu
30 *
31 * Version Creation Date: 8/10/01
32 *
33 * $Revision: 6.9 $
34 *
35 * File Description: runs external programs for ingenue
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * Date Name Description of modification
40 * ------- ---------- -----------------------------------------------------
41 *
42 *
43 * ==========================================================================
44 */
45
46 #include <ingenext.h>
47
48
49
50 /************************************************
51
52 Function: Blast against database functions
53
54 Purpose: blast sequence in view against blastp or blastn database
55
56 ************************************************/
57 WindoW progressW = NULL;
58
59 static Boolean LIBCALLBACK Ing_BlastCallback (BlastResponse *brp,
60 Boolean *cancel)
61 {
62 BlastProgressPtr bpp;
63 Int4 completed = 0;
64
65 *cancel=FALSE;
66 switch (brp->choice) {
67 case BlastResponse_start:
68 bpp = (BlastProgressPtr) brp->data.ptrvalue;
69 if (bpp != NULL) {
70 completed = bpp->completed;
71 }
72 if (completed == 0) {
73 completed = 100;
74 }
75 return TRUE;
76 case BlastResponse_progress:
77 if (progressW != NULL) {
78 bpp = (BlastProgressPtr) brp->data.ptrvalue;
79 if (bpp != NULL) {
80 completed = bpp->completed;
81 }
82 Ing_WinTimerProc(progressW);
83 }
84 return TRUE;
85 case BlastResponse_queued:
86 if (progressW != NULL) {
87 bpp = (BlastProgressPtr) brp->data.ptrvalue;
88 if (bpp != NULL) {
89 completed = bpp->completed;
90 }
91 Ing_WinTimerProc(progressW);
92 }
93 return TRUE;
94 case BlastResponse_done:
95 return TRUE;
96 default:
97 break;
98 }
99 return FALSE;
100 }
101
102
103
104 static void Ing_MegaBlastDefaults(ButtoN b)
105 {
106 Ing_BlastDlgData * bddp;
107
108 bddp=(Ing_BlastDlgData *)GetObjectExtra(b);
109
110 if (GetStatus(b)){
111 SetStatus(bddp->bGap, TRUE);
112 SetTitle(bddp->wordsize, "28");
113 }
114 else {
115 SetTitle(bddp->wordsize, "11");
116 }
117 }
118
119
120 static void Ing_StdCancelProc(ButtoN b)
121 {
122 Remove(ParentWindow(b));
123 }
124
125
126 static QBQUEUE qbquerylist = NULL;
127 static QUEUE urlquerylist = NULL;
128 static Int4 pendingqueries = 0;
129 static Int4 querytimerlimit = 100;
130 static Int4 querytimercount = 0;
131 static Uint2 query_entityID = 0;
132 static Uint4 query_itemID = 0;
133 static Int2 max_tokeep = 20;
134
135 extern void IngenueCheckSocketsProc (WindoW w)
136
137 {
138 Int4 remaining;
139
140 remaining = QUERY_CheckQueue (&urlquerylist);
141 if (remaining < pendingqueries) {
142 Beep ();
143 pendingqueries--;
144 }
145 QBlastCheckQueue (&qbquerylist);
146
147 }
148
149
150 static void LIBCALLBACK Ing_QBlastAnnounce (CharPtr requestID, CharPtr seqID, Int2 estimatedSeconds)
151
152 {
153 if (StringHasNoText (requestID)) {
154 requestID = "?";
155 }
156 if (StringHasNoText (seqID)) {
157 seqID = "?";
158 }
159 Message (MSG_POST, "Queued rID %s, seqID %s, estimated seconds = %d",
160 requestID, seqID, (int) estimatedSeconds);
161 }
162
163 static SeqAlignPtr Ing_KeepTheBestAlignments(SeqAlignPtr sap)
164 {
165 SeqAlignPtr sap_new = NULL;
166 SeqAlignPtr salp_prev = NULL, salp_head = NULL;
167 AMAlignIndex2Ptr amaip = NULL;
168 SCP_ResultPtr scp;
169 SCP_ResultPtr scp_large;
170 SCP_ResultPtr scp_small;
171 Int4 i;
172 Int4 nkept = 0;
173
174 if (sap->saip != NULL)
175 AMAlignIndex2Free2(sap);
176 sap->saip = NULL;
177 AlnMgr2IndexLite(sap);
178 AlnMgr2SortAlnSetByNthRowPos(sap, 1);
179
180 amaip = (AMAlignIndex2Ptr)sap->saip;
181 scp = (SCP_ResultPtr) MemNew(sizeof(SCP_Result));
182 scp_large = (SCP_ResultPtr) MemNew(sizeof(SCP_Result));
183 scp_small = (SCP_ResultPtr) MemNew(sizeof(SCP_Result));
184
185 SCP_OrganizeAlnsInSet(sap, 50, scp, 1);
186 SCP_OrganizeAlnsInSet(sap, 50, scp_large, 1);
187 SCP_OrganizeAlnsInSet(sap, 50, scp_small, 1);
188
189 for (i=0; i<scp->numsaps; i++)
190 {
191 if (scp->saps[i] != NULL)
192 {
193 scp->saps[i]->next = NULL;
194 if (nkept <= max_tokeep){
195 if (salp_prev != NULL)
196 {
197 salp_prev->next = scp->saps[i];
198 salp_prev = salp_prev->next;
199 } else
200 salp_head = salp_prev = scp->saps[i];
201 nkept++;
202 }
203 else {
204 SeqAlignFree(scp->saps[i]);
205 }
206 }
207 }
208
209 for (i=0; i<scp->numlarge_outliers && nkept <= max_tokeep; i++){
210 if (scp->large_outliers[i] != NULL)
211 {
212 scp->large_outliers[i]->next = NULL;
213 if (nkept <= max_tokeep){
214 if (salp_prev != NULL)
215 {
216 salp_prev->next = scp->large_outliers[i];
217 salp_prev = salp_prev->next;
218 } else
219 salp_head = salp_prev = scp->large_outliers[i];
220 nkept++;
221 }
222 else {
223 SeqAlignFree(scp->large_outliers[i]);
224 }
225 }
226 }
227
228 for (i=0; i<scp->numsmall_outliers; i++){
229 if (scp->small_outliers[i] != NULL)
230 {
231 scp->small_outliers[i]->next = NULL;
232 if (nkept <= max_tokeep){
233 if (salp_prev != NULL)
234 {
235 salp_prev->next = scp->small_outliers[i];
236 salp_prev = salp_prev->next;
237 } else
238 salp_head = salp_prev = scp->small_outliers[i];
239 nkept++;
240 }
241 else {
242 SeqAlignFree(scp->small_outliers[i]);
243 }
244 }
245 }
246
247 sap_new = SeqAlignNew();
248 sap_new->segtype = SAS_DISC;
249 sap_new->segs = (Pointer)(salp_head);
250 sap_new->saip = NULL;
251 AlnMgr2IndexLite(sap_new);
252
253 return sap_new;
254 }
255
256 static Boolean Ing_HandleQBlastResults(CharPtr filename){
257 /* read in seqannot file */
258 FILE *fp;
259 SeqAnnotPtr sanp = NULL;
260 BioseqPtr bsp = NULL;
261 Pointer dataptr = NULL;
262 Uint2 datatype;
263 ValNodePtr vnp = NULL, head = NULL;
264 ValNodePtr vnp_cur = NULL;
265 SeqAlignPtr sap = NULL;
266 SeqAlignPtr sap_best = NULL;
267 Boolean bSaved = FALSE;
268
269 if (filename == NULL) return (FALSE);
270 fp = FileOpen(filename, "r");
271 if (fp == NULL) return (FALSE);
272 while (dataptr = ReadAsnFastaOrFlatFile(fp, &datatype, NULL, FALSE, TRUE, TRUE, TRUE)){
273 if (datatype != OBJ_SEQANNOT || dataptr != NULL){
274 if (head == NULL)
275 vnp_cur = ValNodeAddPointer(&head, datatype, dataptr);
276 else
277 vnp_cur = ValNodeAddPointer(&vnp_cur, datatype, dataptr);
278 }
279 }
280 for (vnp = head; vnp != NULL; vnp = vnp->next){
281 dataptr = (Pointer)vnp->data.ptrvalue;
282 if (vnp->choice == OBJ_SEQANNOT){
283 sanp = (SeqAnnotPtr)(dataptr);
284 sap = (SeqAlignPtr)sanp->data;
285 if (!sap) return (FALSE);
286
287 /* weed out low scoring hits */
288 sap_best = Ing_KeepTheBestAlignments(sap);
289 /* free old parent */
290 AMAlignIndex2Free2(sap);
291 sap->segs = NULL;
292 SeqAlignFree(sap);
293
294 sanp->data = (Pointer) sap_best;
295 sanp->name = StringSave("Blast vs. db");
296 bsp = (BioseqPtr)GetBioseqGivenIDs(query_entityID, query_itemID, OBJ_BIOSEQ);
297 Ing_AttachSeqAnnotToSeqEntry(query_entityID, sanp, bsp);
298 bSaved = TRUE;
299 }
300 }
301 if (query_entityID != 0 && bSaved){
302 ObjMgrSetDirtyFlag(query_entityID, TRUE);
303 ObjMgrSendMsg(OM_MSG_UPDATE, query_entityID, 0, 0);
304 }
305
306 FileClose(fp);
307 Beep();
308 if (bSaved)
309 Message (MSG_OK, "QBlast task is complete");
310 else
311 Message (MSG_OK, "QBlast task is complete -- no hits found");
312
313 return TRUE;
314 }
315
316
317 static Boolean LIBCALLBACK Ing_QBlastCallback (
318 CharPtr filename,
319 VoidPtr userdata,
320 CharPtr requestID,
321 CharPtr seqID,
322 Boolean success
323 )
324
325 {
326 if (StringHasNoText (requestID)) {
327 requestID = "?";
328 }
329 if (StringHasNoText (seqID)) {
330 seqID = "?";
331 }
332 if (success) {
333 Ing_HandleQBlastResults (filename);
334 } else {
335 Message (MSG_POST, "Failure of rID '%s', seqID %s", requestID, seqID);
336 }
337 return TRUE;
338 }
339
340
341 static void Ing_QBlastAccept(ButtoN g)
342 {
343 Ing_BlastDlgData *bddp;
344 Int2 value;
345 WindoW hOpenDlg;
346 Int4 i;
347 ValNodePtr pvn;
348 BioseqPtr bsp;
349 Char max[11]={""}, *program;
350 IngGenomeViewerPtr igvp=NULL;
351
352 hOpenDlg=(WindoW)ParentWindow(g);
353 if (!hOpenDlg) return;
354
355 Hide(hOpenDlg);
356 bddp=(Ing_BlastDlgData *)GetObjectExtra (g);
357 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(g));
358 if (bddp == NULL || igvp==NULL) {
359 ValNodeFree(bddp->pvnSips);
360 Remove(hOpenDlg);
361 return;
362 }
363
364
365 /* BlastInit("Ingenue", &bl3hp, &bl3rp); */
366 value = GetValue(bddp->bsp_list);
367
368 for(pvn = bddp->pvnSips, i = 1; i != value && pvn != NULL;
369 i++, pvn = pvn->next);
370
371 if(pvn == NULL) {
372 ValNodeFree(bddp->pvnSips);
373 Remove(hOpenDlg);
374 return;
375 }
376
377 bsp = BioseqLockById((SeqId *)pvn->data.ptrvalue);
378 query_entityID = igvp->entityID;
379 query_itemID = igvp->itemID;
380
381 if(bsp == NULL) {
382 ValNodeFree(bddp->pvnSips);
383 return;
384 }
385
386 if(ISA_aa(bsp->mol)) program = "blastp";
387 else program = "blastn";
388
389 GetTitle(bddp->tMax, max, 10);
390 max_tokeep = atoi(max);
391
392 value = GetValue(bddp->db_list);
393 QBlastAsynchronousRequest (ig_nucdbs[value-1], program, bsp, &qbquerylist, Ing_QBlastCallback, Ing_QBlastAnnounce, NULL);
394 Remove(hOpenDlg);
395 }
396
397
398
399 extern void Ing_QBlastProc(IteM t)
400 {
401 Ing_BlastDlgData *bddp;
402 GrouP h2,h,h1, h3, h4, h5, maskg;
403 WindoW d;
404 ButtoN b;
405 Char szName[31]={""};
406 IngGenomeViewerPtr igvp=NULL;
407 ValNode *pvn;
408 Int4 i;
409
410 bddp = (Ing_BlastDlgData *)MemNew(sizeof(Ing_BlastDlgData));
411 if (bddp == NULL) return;
412 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(t));
413 bddp->pvnSips = igvp->entity_list->Sips;
414 d = MovableModalWindow(-50, -33 ,-10, -10, "Blast", NULL);
415 if (d != NULL){
416 /*create some controls*/
417 h = HiddenGroup(d, 1, 5, NULL);
418 h1 = HiddenGroup(h, 1, 2, NULL);
419 StaticPrompt(h1,"Choose a sequence :",0,0,programFont,'l');
420
421 bddp->bsp_list = SingleList(h1,20,6,NULL);
422
423 h3 = HiddenGroup(h, 1, 1, NULL);
424 bddp->bGap = CheckBox(h3, "Gapped", NULL);
425 SetStatus(bddp->bGap, TRUE);
426
427 h4 = HiddenGroup(h, 2, 2, NULL);
428 StaticPrompt(h4,"Expectation value:",0,0,programFont,'l');
429 bddp->tExpect = DialogText(h4, "10", 8, (TxtActnProc) NULL);
430 /* StaticPrompt(h4,"Maximum # of hits:",0,0,programFont,'l'); */
431 /* bddp->tMax = DialogText(h4, "20", 5, (TxtActnProc) NULL); */
432 StaticPrompt(h4,"Wordsize:",0,0,programFont,'l');
433 bddp->wordsize = DialogText(h4, "11", 5, (TxtActnProc) NULL);
434 maskg=HiddenGroup(h4, 0, 2, NULL);
435 bddp->maskrep = CheckBox(maskg, "Mask Repeats", NULL);
436 SetStatus(bddp->maskrep, FALSE);
437 bddp->masksimple = CheckBox(maskg, "Mask Simple Sequence", NULL);
438 SetStatus(bddp->masksimple, TRUE);
439 bddp->megablast= CheckBox(h4, "Mega Blast", Ing_MegaBlastDefaults);
440 SetStatus(bddp->megablast, FALSE);
441 SetObjectExtra (bddp->megablast, (Pointer) bddp, NULL);
442 Disable(h4); /* until QBlast can take input parameters */
443
444 h4 = HiddenGroup (h, 2, 2, NULL);
445
446 StaticPrompt(h4,"# of hits to keep:",0,0,programFont,'l');
447 bddp->tMax = DialogText(h4, "20", 5, (TxtActnProc) NULL);
448
449 StaticPrompt (h4, "Choose Database:", 0, 0, programFont, 'c');
450
451 bddp->db_list = PopupList(h4, TRUE, NULL);
452
453 for (i = 0; i < Ing_NUM_DBS && ig_nucdbs [i] != NULL; i++)
454 PopupItem(bddp->db_list, ig_nucdbsnames[i]);
455 SetValue(bddp->db_list,1);
456
457 h2 = HiddenGroup(h, 2, 1, NULL);
458 b=DefaultButton(h2, "Accept", Ing_QBlastAccept);
459 Enable(b);
460 PushButton(h2, "Cancel", Ing_StdCancelProc);
461 SetObjectExtra (b, (Pointer) bddp, StdCleanupExtraProc);
462
463 h5 = HiddenGroup(h, 1, 1, NULL);
464 StaticPrompt(h5,"Warning: may take several minutes!",0,0,programFont,'l');
465
466 /*fill in the list box*/
467 for(pvn = bddp->pvnSips; pvn != NULL; pvn = pvn->next) {
468 SeqIdWrite((SeqId *)pvn->data.ptrvalue,szName,
469 PRINTID_FASTA_LONG,30);
470 ListItem(bddp->bsp_list, szName);
471 }
472 SetValue(bddp->bsp_list,1);
473
474 SetObjectExtra (d, (Pointer) igvp, NULL);
475 RealizeWindow(d);
476 Select(d);
477 Show(d);
478 }
479
480 }
481
482 /************************************************
483
484 Function: tRNAscan functions
485
486 Purpose: run tRNAscan (url), check for, and handle results
487
488 ************************************************/
489
490 typedef struct trsdata {
491 Boolean fastaNucOK;
492 Boolean fastaProtOK;
493 Boolean onlyBspTarget;
494 CharPtr host_machine;
495 Uint2 host_port;
496 CharPtr host_path;
497 Uint2 timeoutsec;
498 Int2 format;
499 ValNodePtr paramlist;
500 QueryResultProc resultproc;
501 CharPtr prefix;
502 CharPtr suffix;
503 CharPtr title;
504 GrouP controls;
505 IngGenomeViewerPtr igvp;
506 } tRSdata, PNTR tRSdataPtr;
507
508 typedef struct iurlparamdata {
509 Uint1 type; /* 1 = text, 2 = checkbox, 3 = popup, 4 = radio, 5 = list */
510 CharPtr param;
511 CharPtr prompt; /* if no prompt, use param */
512 CharPtr dfault;
513 CharPtr choices; /* choices if param is popup */
514 CharPtr group; /* used for grouping related controls */
515 CharPtr help;
516 } IUrlParamData, PNTR IUrlParamPtr;
517
518 static Uint2 urlquery_entityID = 0;
519 static Uint4 urlquery_itemID = 0;
520
521 static void Ing_HandleResults(CharPtr path)
522 {
523 FILE *fp;
524 SeqAnnotPtr sanp = NULL;
525 BioseqPtr bsp = NULL;
526 Pointer dataptr = NULL;
527 Uint2 datatype;
528 ValNodePtr vnp = NULL, head = NULL;
529 ValNodePtr vnp_cur = NULL;
530 Boolean bSaved = FALSE;
531
532 if (path == NULL) return;
533 fp = FileOpen(path, "r");
534 if (fp == NULL) return;
535 while (dataptr = ReadAsnFastaOrFlatFile(fp, &datatype, NULL, FALSE, TRUE, TRUE, TRUE)){
536 if (datatype != OBJ_SEQANNOT || dataptr != NULL){
537 if (head == NULL)
538 vnp_cur = ValNodeAddPointer(&head, datatype, dataptr);
539 else
540 vnp_cur = ValNodeAddPointer(&vnp_cur, datatype, dataptr);
541 }
542 }
543 for (vnp = head; vnp != NULL; vnp = vnp->next){
544 dataptr = (Pointer)vnp->data.ptrvalue;
545 if (vnp->choice == OBJ_SEQANNOT){
546 sanp = (SeqAnnotPtr)(dataptr);
547 sanp->name = (CharPtr)StringSave("tRNAscan-SE");
548 bsp = (BioseqPtr)GetBioseqGivenIDs(urlquery_entityID, urlquery_itemID, OBJ_BIOSEQ);
549 Ing_AttachSeqAnnotToSeqEntry(urlquery_entityID, sanp, bsp);
550 bSaved = TRUE;
551 }
552 }
553 if (urlquery_entityID != 0 && bSaved){
554 ObjMgrSetDirtyFlag(urlquery_entityID, TRUE);
555 ObjMgrSendMsg(OM_MSG_UPDATE, urlquery_entityID, 0, 0);
556 }
557
558 FileClose(fp);
559 }
560
561 static Boolean LIBCALLBACK Ing_HandletRNAscanResults (CONN conn, VoidPtr userdata, EIO_Status status)
562 {
563 FILE *fp;
564 Char path [PATH_MAX];
565
566 TmpNam (path);
567 fp = FileOpen (path, "w");
568 QUERY_CopyResultsToFile (conn, fp);
569 FileClose (fp);
570 Ing_HandleResults(path);
571 FileRemove (path);
572 return TRUE;
573
574 }
575
576 static void Ing_FinishURLProc (tRSdataPtr trs, CharPtr arguments, CharPtr path)
577 {
578 CONN conn;
579 FILE *fp;
580 Char progname [50]={"INGENUE"};
581
582 QueryResultProc resultproc;
583 EMIME_SubType subtype;
584
585
586 resultproc = trs->resultproc;
587
588 if (trs->format == 1) {
589 subtype = eMIME_Fasta;
590 } else if (trs->format == 2) {
591 subtype = eMIME_AsnText;
592 } else {
593 subtype = eMIME_Unknown;
594 }
595
596 conn = QUERY_OpenUrlQuery (trs->host_machine, trs->host_port,
597 trs->host_path, arguments,
598 progname, trs->timeoutsec,
599 eMIME_T_NcbiData, subtype, eENCOD_Url,
600 fHCC_UrlDecodeInput | fHCC_UrlEncodeOutput);
601 if (conn == NULL) return;
602
603 fp = FileOpen (path, "rb");
604 QUERY_CopyFileToQuery (conn, fp);
605 FileClose (fp);
606
607 QUERY_SendQuery (conn);
608 QUERY_AddToQueue (&urlquerylist, conn, resultproc, NULL, TRUE);
609 pendingqueries++;
610 FileRemove (path);
611 }
612
613 extern Boolean Ing_CanSaveFasta (IngGenomeViewerPtr igvp, Boolean nucs, Boolean prots, Boolean onlyTarget)
614 {
615 Uint2 entityID;
616 SeqEntryPtr sep;
617 BioseqPtr bsp;
618
619 if (igvp != NULL) {
620 bsp = igvp->bsp;
621 if (bsp == NULL) return FALSE;
622 sep = SeqMgrGetSeqEntryForData (bsp);
623 if (! onlyTarget) {
624 entityID = ObjMgrGetEntityIDForChoice (sep);
625 sep = GetTopSeqEntryForEntityID (entityID);
626 }
627 if (sep == NULL) return FALSE;
628 if (nucs && SeqEntryHasNucs (sep)) return TRUE;
629 if (prots && SeqEntryHasProts (sep)) return TRUE;
630 }
631 return FALSE;
632 }
633
634
635 extern Boolean Ing_ExportFasta (IngGenomeViewerPtr igvp, CharPtr filename, Boolean nucs, Boolean prots, Boolean onlyTarget)
636
637 {
638 BioseqPtr bsp;
639 Uint2 entityID;
640 FILE *fp;
641 Uint1 group_segs;
642 Char path [PATH_MAX];
643 SeqEntryPtr sep;
644
645 path [0] = '\0';
646 StringNCpy_0 (path, filename, sizeof (path));
647 bsp = igvp->bsp;
648 if (bsp == NULL) return FALSE;
649 sep = SeqMgrGetSeqEntryForData (bsp);
650 if (! onlyTarget) {
651 entityID = ObjMgrGetEntityIDForChoice (sep);
652 sep = GetTopSeqEntryForEntityID (entityID);
653 }
654 if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
655 #ifdef WIN_MAC
656 fp = FileOpen (path, "r");
657 if (fp != NULL) {
658 FileClose (fp);
659 } else {
660 FileCreate (path, "TEXT", "ttxt");
661 }
662 #endif
663 fp = FileOpen (path, "w");
664 if (fp != NULL) {
665 WatchCursor ();
666 Update ();
667 group_segs = 0;
668 if (bsp->repr == Seq_repr_seg) {
669 group_segs = 2;
670 }
671 if (nucs) {
672 SeqnSeqEntrysToFasta (sep, fp, TRUE, group_segs);
673 }
674 if (prots) {
675 SeqnSeqEntrysToFasta (sep, fp, FALSE, 0);
676 }
677 FileClose (fp);
678 ArrowCursor ();
679 Update ();
680 return TRUE;
681 }
682 }
683
684 return FALSE;
685 }
686
687 static void Ing_DoAnalysisProc(tRSdataPtr trs, CharPtr arguments)
688 {
689 BioseqPtr bsp;
690 Char path1[PATH_MAX];
691 SeqEntryPtr sep;
692 AsnIoPtr aop;
693 IngGenomeViewerPtr igvp = NULL;
694
695
696 igvp = trs->igvp;
697 if (Ing_CanSaveFasta (igvp, trs->fastaNucOK, trs->fastaProtOK, trs->onlyBspTarget)) {
698 TmpNam (path1);
699 switch (trs->format){
700 case 1:
701 Ing_ExportFasta (igvp , path1, trs->fastaNucOK, trs->fastaProtOK, trs->onlyBspTarget);
702 break;
703 case 2 :
704 sep = NULL;
705 if (trs->onlyBspTarget) {
706 bsp = GetBioseqGivenIDs (igvp->entityID, igvp->itemID, OBJ_BIOSEQ);
707 sep = SeqMgrGetSeqEntryForData (bsp);
708 } else {
709 sep = GetTopSeqEntryForEntityID (igvp->entityID);
710 }
711 if (sep != NULL) {
712 aop = AsnIoOpen (path1, "w");
713 SeqEntryAsnWrite (sep, aop, NULL);
714 AsnIoFlush (aop);
715 AsnIoClose (aop);
716 }
717 break;
718 default :
719 break;
720 }
721 urlquery_entityID = igvp->entityID;
722 urlquery_itemID = igvp->itemID;
723 Ing_FinishURLProc (trs, arguments, path1);
724
725 } else {
726 ErrPostEx (SEV_ERROR, 0, 0, "BioseqView cannot save fasta format");
727 ErrShow();
728 }
729 }
730
731
732 static void Ing_AccepttRNAargsProc(ButtoN b)
733 {
734 CharPtr args = NULL;
735 CharPtr arguments = NULL;
736 GrouP grp;
737 tRSdataPtr trs = NULL;
738 ValNodePtr head = NULL;
739 ValNodePtr paramlist = NULL;
740 ValNodePtr ppt;
741 ValNodePtr vnp = NULL;
742 Int2 val;
743 Int2 i;
744 Char ch;
745 Char cpy [256];
746 CharPtr last;
747 Int4 len;
748 Char tmp [256];
749 CharPtr itms;
750 CharPtr ptr;
751 Boolean notFirst = FALSE;
752 IUrlParamPtr upp = NULL;
753 WindoW w;
754
755
756 w = ParentWindow(b);
757 trs = (tRSdataPtr)GetObjectExtra(w);
758 if (!trs) return;
759 Hide(w);
760 if (! StringHasNoText (trs->prefix)) {
761 ValNodeCopyStr (&head, 0, trs->prefix);
762 }
763 ppt = trs->paramlist;
764 upp = (IUrlParamPtr) ppt->data.ptrvalue;
765
766 grp = trs->controls;
767 val = GetValue (grp);
768 if (val > 0) {
769 i = 0;
770 itms = upp->choices;
771 StringNCpy_0 (tmp, itms, sizeof (tmp));
772 last = tmp;
773 ptr = last;
774 ch = *ptr;
775 while (ch != '\0') {
776 if (ch == ',') {
777 *ptr = '\0';
778 i++;
779 if (val == i) {
780 sprintf (cpy, "%s=%s", upp->param, last);
781 ValNodeCopyStr (&head, 0, cpy);
782 }
783 ptr++;
784 last = ptr;
785 ch = *ptr;
786 } else {
787 ptr++;
788 ch = *ptr;
789 }
790 }
791 if (! StringHasNoText (last)) {
792 i++;
793 if (val == i) {
794 sprintf (cpy, "%s=%s", upp->param, last);
795 ValNodeCopyStr (&head, 0, cpy);
796 }
797 }
798 }
799 if (! StringHasNoText (trs->suffix)) {
800 ValNodeCopyStr (&head, 0, trs->suffix);
801 }
802 for (len = 0, vnp = head; vnp != NULL; vnp = vnp->next) {
803 len += StringLen ((CharPtr) vnp->data.ptrvalue) + 1;
804 }
805 if (len > 0) {
806 arguments = MemNew (len + 5);
807 if (arguments != NULL) {
808 vnp = head;
809 notFirst = FALSE;
810 while (vnp != NULL) {
811 if (notFirst) {
812 StringCat (arguments, "&");
813 }
814 StringCat (arguments, (CharPtr) vnp->data.ptrvalue);
815 notFirst = TRUE;
816 vnp = vnp->next;
817 }
818 }
819 }
820 args = StringSave (arguments);
821 MemFree (arguments);
822 Ing_DoAnalysisProc (trs, args);
823 MemFree (args);
824 Remove(w);
825 }
826
827 static ValNodePtr Ing_RearrangeParamList (ValNodePtr paramlist)
828
829 {
830 ValNodePtr curr;
831 CharPtr group;
832 ValNodePtr head = NULL;
833 ValNodePtr list;
834 ValNodePtr next;
835 ValNodePtr PNTR prev;
836 ValNodePtr ppt;
837 IUrlParamPtr upp;
838
839 ppt = paramlist;
840 while (ppt != NULL) {
841 list = ppt->next;
842 ppt->next = NULL;
843 ValNodeLink (&head, ppt);
844 upp = (IUrlParamPtr) ppt->data.ptrvalue;
845 if (upp == NULL) {
846 ppt = list;
847 continue;
848 }
849 group = upp->group;
850 curr = list;
851 prev = &list;
852 while (curr != NULL) {
853 next = curr->next;
854 upp = (IUrlParamPtr) curr->data.ptrvalue;
855 if (upp == NULL) {
856 prev = &(curr->next);
857 curr = next;
858 continue;
859 }
860 if (StringICmp (upp->group, group) == 0) {
861 *prev = next;
862 curr->next = NULL;
863 ValNodeLink (&head, curr);
864 } else {
865 prev = &(curr->next);
866 }
867 curr = next;
868 }
869 ppt = list;
870 }
871 return head;
872 }
873
874 static void Ing_ShowArgumentHelp (ButtoN b)
875
876 {
877 ValNodePtr ppt;
878 CharPtr str;
879 tRSdataPtr trs;
880 IUrlParamPtr upp;
881
882 trs = (tRSdataPtr) GetObjectExtra (ParentWindow(b));
883 if (trs == NULL) return;
884
885 ppt = trs->paramlist;
886 upp = (IUrlParamPtr) ppt->data.ptrvalue;
887 if (upp == NULL) return;
888 str = upp->help;
889 Message (MSG_OK, "%s", str);
890 return;
891
892 }
893
894 static void Ing_tRNAscanProc(IteM i)
895 {
896 CharPtr args = NULL;
897 tRSdataPtr trs = NULL;
898
899 trs = (tRSdataPtr) GetObjectExtra (i);
900 if (trs == NULL) return;
901 {{ /* build arguement form */
902 ButtoN b;
903 GrouP c;
904 Char ch;
905 CharPtr def;
906 TexT first = NULL;
907 GrouP g;
908 GrouP grp;
909 GrouP h;
910 Int2 i;
911 CharPtr itms;
912 CharPtr last;
913 CharPtr lastGroup = " ";
914 GrouP m;
915 ValNodePtr moveMe = NULL;
916 ValNodePtr ppt;
917 CharPtr ptr;
918 CharPtr str;
919 Char tmp [128];
920 IUrlParamPtr upp;
921 Int2 val;
922 WindoW w;
923
924
925 trs->paramlist = Ing_RearrangeParamList (trs->paramlist);
926
927 w = FixedWindow (-50, -33, -10, -10, "Arguments", NULL);
928 SetObjectExtra (w, trs, NULL);
929
930 m = HiddenGroup (w, 1, 0, NULL);
931
932 g = NULL;
933 for (ppt = trs->paramlist;
934 ppt != NULL;
935 ppt = ppt->next) {
936 upp = (IUrlParamPtr) ppt->data.ptrvalue;
937 if (upp == NULL) continue;
938 if (StringICmp (upp->group, lastGroup) != 0) {
939 if (StringHasNoText (upp->group)) {
940 if (StringHasNoText (lastGroup)) {
941 g = HiddenGroup (m, 3, 0, NULL);
942 } else {
943 g = NormalGroup (m, 3, 0, "", programFont, NULL);
944 }
945 } else {
946 g = NormalGroup (m, 3, 0, upp->group, programFont, NULL);
947 }
948 lastGroup = upp->group;
949 }
950 if (g == NULL) {
951 g = HiddenGroup (m, 3, 0, NULL);
952 }
953
954 str = upp->prompt;
955 StaticPrompt (g, str, 0, dialogTextHeight, programFont, 'l');
956 h = HiddenGroup (g, 1, 0, NULL);
957 grp = HiddenGroup (h, -3, 0, NULL);
958 def = upp->dfault;
959 val = 0;
960 i = 0;
961 itms = upp->choices;
962 StringNCpy_0 (tmp, itms, sizeof (tmp));
963 last = tmp;
964 ptr = last;
965 ch = *ptr;
966 while (ch != '\0') {
967 if (ch == ',') {
968 *ptr = '\0';
969 RadioButton (grp, last);
970 i++;
971 if (StringICmp (def, last) == 0) {
972 val = i;
973 }
974 ptr++;
975 last = ptr;
976 ch = *ptr;
977 } else {
978 ptr++;
979 ch = *ptr;
980 }
981 }
982 if (! StringHasNoText (last)) {
983 RadioButton (grp, last);
984 i++;
985 if (StringICmp (def, last) == 0) {
986 val = i;
987 }
988 }
989 if (val > 0) {
990 SetValue (grp, val);
991 }
992 trs->controls = grp;
993 }
994
995
996 b = PushButton (g, "?", Ing_ShowArgumentHelp);
997 c = HiddenGroup (w, 2, 0, NULL);
998 SetGroupSpacing (c, 10, 3);
999 b = PushButton (c, "Accept", Ing_AccepttRNAargsProc);
1000 PushButton (c, "Cancel", Ing_StdCancelProc);
1001
1002 AlignObjects (ALIGN_CENTER, (HANDLE) m, (HANDLE) c, NULL);
1003 RealizeWindow (w);
1004 Show (w);
1005 Select (w);
1006 }}
1007 }
1008
1009
1010 static void Ing_AddtRNAscanItem (MenU m, Boolean nucOK, Boolean protOK, Boolean onlyBspTarget, CharPtr host, Uint2 port, CharPtr path, CharPtr program, Uint2 timeoutsec, Int2 format, QueryResultProc resultproc, ValNodePtr paramlist,CharPtr prefix,CharPtr suffix,CharPtr title, ItmActnProc actn)
1011 {
1012 IteM i;
1013 tRSdataPtr trs = NULL;
1014 IngGenomeViewerPtr igvp = NULL;
1015 Int4 len;
1016 CharPtr tmp = NULL;
1017
1018 igvp = (IngGenomeViewerPtr)GetObjectExtra(ParentWindow(m));
1019 if (!igvp) return;
1020
1021 trs = (tRSdataPtr)MemNew(sizeof(tRSdata));
1022 trs->igvp = igvp;
1023 trs->resultproc = resultproc;
1024 trs->fastaNucOK = nucOK;
1025 trs->fastaProtOK = protOK;
1026 trs->onlyBspTarget = onlyBspTarget;
1027 trs->host_machine = StringSave(host);
1028 trs->host_port = port;
1029 len = StringLen(path);
1030 tmp = MemNew(len + StringLen(program) + 5);
1031 if (tmp != NULL){
1032 StringCpy(tmp, path);
1033 if (len > 1 && tmp[len-1] != '/'){
1034 StringCat(tmp, "/");
1035 }
1036 StringCat(tmp, program);
1037 }
1038 trs->host_path = StringSave(tmp);
1039 MemFree(tmp);
1040 trs->timeoutsec = timeoutsec;
1041 trs->format = format;
1042 trs->paramlist = paramlist;
1043 trs->prefix = StringSaveNoNull(prefix);
1044 trs->suffix = StringSaveNoNull(suffix);
1045
1046 i = CommandItem(m, title, actn);
1047 SetObjectExtra(i, (Pointer)trs, StdCleanupExtraProc);
1048
1049 }
1050
1051 static ValNodePtr Ing_GetConfigParams (CharPtr sect)
1052 {
1053
1054 Int2 i;
1055 ValNodePtr paramlist = NULL;
1056 Uint1 paramtype;
1057 Char title [512];
1058 Char tmp [32];
1059 IUrlParamPtr upp;
1060
1061 if (sect == NULL) return NULL;
1062 i = 1;
1063 sprintf (tmp, "PARAM_%d", (int) i);
1064 while (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1065 upp = (IUrlParamPtr) MemNew (sizeof (IUrlParamData));
1066 if (upp == NULL) continue;
1067 upp->param = StringSave (title);
1068 sprintf (tmp, "TYPE_%d", (int) i);
1069 paramtype = 1;
1070 if (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1071 if (StringICmp (title, "text") == 0) {
1072 paramtype = 1;
1073 } else if (StringICmp (title, "checkbox") == 0) {
1074 paramtype = 2;
1075 } else if (StringICmp (title, "popup") == 0) {
1076 paramtype = 3;
1077 } else if (StringICmp (title, "radio") == 0) {
1078 paramtype = 4;
1079 } else if (StringICmp (title, "list") == 0) {
1080 paramtype = 5;
1081 }
1082 }
1083 upp->type = paramtype;
1084 sprintf (tmp, "PROMPT_%d", (int) i);
1085 if (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1086 upp->prompt = StringSave (title);
1087 } else {
1088 upp->prompt = StringSave (upp->param);
1089 }
1090 sprintf (tmp, "DEFAULT_%d", (int) i);
1091 if (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1092 upp->dfault = StringSave (title);
1093 } else {
1094 upp->dfault = StringSave (" ");
1095 }
1096 sprintf (tmp, "CHOICES_%d", (int) i);
1097 if (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1098 upp->choices = StringSave (title);
1099 } else {
1100 upp->choices = StringSave (" ");
1101 }
1102 sprintf (tmp, "GROUP_%d", (int) i);
1103 if (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1104 upp->group = StringSave (title);
1105 } else {
1106 upp->group = StringSave (" ");
1107 }
1108 sprintf (tmp, "HELP_%d", (int) i);
1109 if (GetAppParam ("SEQNCGIS", sect, tmp, NULL, title, sizeof (title) - 1)) {
1110 upp->help = StringSave (title);
1111 } else {
1112 upp->help = StringSave (" ");
1113 }
1114 ValNodeAddPointer (¶mlist, i, (Pointer) upp);
1115 i++;
1116 sprintf (tmp, "PARAM_%d", (int) i);
1117 }
1118 return paramlist;
1119
1120 }
1121
1122
1123 static void Ing_ReadtRNAConfigFile(MenU m)
1124 {
1125 Boolean demomode = FALSE;
1126 Int2 format = 1;
1127 Char host [128];
1128 Boolean nucOK = FALSE;
1129 Boolean onlyBspTarget = FALSE;
1130 ValNodePtr paramlist = NULL;
1131 Char program [128];
1132 Char path [256];
1133 Uint2 port = 80;
1134 Char prefix [128];
1135 Boolean protOK = FALSE;
1136 Char sect[256];
1137 Char submenu [128];
1138 Char suffix [128];
1139 Uint2 timeoutsec = 30;
1140 Char title [128];
1141 Char tmp [32];
1142 Uint4 val;
1143
1144 if (! GetAppParam ("SEQNCGIS", "ORDER", "ORDER_1", NULL, sect, sizeof (sect) - 1)){
1145 return;
1146 }
1147 if (! GetAppParam ("SEQNCGIS", sect, "TITLE", NULL, title, sizeof (title) - 1)) {
1148 StringNCpy_0 (title, sect, sizeof (title));
1149 }
1150 if (GetAppParam ("SEQNCGIS", sect, "HOST", NULL, host, sizeof (host) - 1)) {
1151 if (GetAppParam ("SEQNCGIS", sect, "FLAGS", NULL, tmp, sizeof (tmp) - 1)) {
1152 if (StringStr (tmp, "NUC") != NULL) {
1153 nucOK = TRUE;
1154 }
1155 if (StringStr (tmp, "PRT") != NULL) {
1156 protOK = TRUE;
1157 }
1158 if (StringStr (tmp, "TRG") != NULL) {
1159 onlyBspTarget = TRUE;
1160 }
1161 }
1162
1163 if (GetAppParam ("SEQNCGIS", sect, "PORT", NULL, tmp, sizeof (tmp) - 1) &&
1164 sscanf (tmp, "%u", &val) == 1) {
1165 port = (Uint2) val;
1166 } else {
1167 port = 80;
1168 }
1169 if (GetAppParam ("SEQNCGIS", sect, "FORMATIN", NULL, tmp, sizeof (tmp) - 1)) {
1170 if (StringICmp (tmp, "FASTA") == 0) {
1171 format = 1;
1172 } else if (StringICmp (tmp, "ASN.1") == 0) {
1173 format = 2;
1174 }
1175 }
1176 if (GetAppParam ("SEQNCGIS", sect, "TIMEOUT", NULL, tmp, sizeof (tmp) - 1) &&
1177 sscanf (tmp, "%u", &val) == 1) {
1178 timeoutsec = (Uint2) val;
1179 } else {
1180 timeoutsec = 30;
1181 }
1182 submenu [0] = '\0';
1183 GetAppParam ("SEQNCGIS", sect, "SUBMENU", NULL, submenu, sizeof (submenu) - 1);
1184 if (GetAppParam ("SEQNCGIS", sect, "DEMO", NULL, tmp, sizeof (tmp) - 1)) {
1185 if (StringICmp (tmp, "TRUE") == 0) {
1186 demomode = TRUE;
1187 }
1188 }
1189
1190 if (GetAppParam ("SEQNCGIS", sect, "PATH", NULL, path, sizeof (path) - 1)) {
1191 if (GetAppParam ("SEQNCGIS", sect, "PROGRAM", NULL, program, sizeof (program) - 1)) {
1192 paramlist = Ing_GetConfigParams (sect);
1193 prefix [0] = '\0';
1194 GetAppParam ("SEQNCGIS", sect, "PREFIX", NULL, prefix, sizeof (prefix) - 1);
1195 suffix [0] = '\0';
1196 GetAppParam ("SEQNCGIS", sect, "SUFFIX", NULL, suffix, sizeof (suffix) - 1);
1197 Ing_AddtRNAscanItem (m,
1198 nucOK, protOK, onlyBspTarget,
1199 host, port, path, program, timeoutsec, format,
1200 Ing_HandletRNAscanResults, paramlist, prefix, suffix,
1201 title, Ing_tRNAscanProc);
1202 }
1203 }
1204 }
1205
1206 }
1207
1208 extern void Ing_tRNAscanMenu (MenU m)
1209 {
1210
1211 ValNodePtr head1 = NULL, head2 = NULL;
1212 size_t len;
1213 Char path1 [PATH_MAX];
1214 Char path2 [PATH_MAX];
1215 CharPtr ptr;
1216 Char sect [256];
1217
1218 ProgramPath (path1, sizeof (path1));
1219 ptr = StringRChr (path1, DIRDELIMCHR);
1220 if (ptr != NULL) {
1221 ptr++;
1222 *ptr = '\0';
1223 }
1224 FileBuildPath (path1, "services", NULL);
1225 head1 = DirCatalog (path1);
1226
1227 if (GetAppParam ("SEQNCGIS", "SERVICES", "PATH", NULL, path2, sizeof (path2) - 1)) {
1228 len = StringLen (path2);
1229 if (path2 [len - 1] != DIRDELIMCHR) {
1230 StringCat (path2, DIRDELIMSTR);
1231 }
1232 if (StringCmp (path1, path2) != 0) {
1233 head2 = DirCatalog (path2);
1234 }
1235 }
1236
1237 if (head1 == NULL && head2 == NULL) {
1238 if (! GetAppParam ("SEQNCGIS", "ORDER", NULL, NULL, sect, sizeof (sect) - 1)) {
1239 return;
1240 }
1241 }
1242 Ing_ReadtRNAConfigFile(m);
1243
1244 }
1245
1246 /***************************************************
1247
1248 Function : Blast 2 seqs Functions
1249
1250 Purpose : compare two bioseqs
1251
1252 ***************************************************/
1253
1254
1255 static FloatHi Ing_get_eval(Int4 exp)
1256 {
1257 FloatHi eval;
1258 Int4 i;
1259
1260 eval = 1;
1261 for (i=1; i<=exp; i++)
1262 {
1263 eval = eval/10;
1264 }
1265 return eval;
1266 }
1267
1268 static Boolean Ing_RunBlast2SeqsJob(SeqLocPtr slp1, Uint2 entityID, BioseqPtr bsp1, BioseqPtr bsp2, CharPtr text, BLAST_OptionsBlkPtr options)
1269 {
1270 SeqAlignPtr sap;
1271 SeqAnnotPtr sanp;
1272 SeqLocPtr slp2 = NULL;
1273
1274 if (slp1==NULL)
1275 sap = BlastTwoSequences(bsp1, bsp2, text, options);
1276 else {
1277 slp2 = SeqLocIntNew(0, bsp2->length-1, Seq_strand_plus, bsp2->id);
1278 sap = BlastTwoSequencesByLoc(slp1, slp2, text, options);
1279 }
1280 if (sap == NULL)
1281 {
1282 ErrPostEx(SEV_WARNING, 0, 0, "No BLAST hits found");
1283 ErrShow();
1284 return FALSE;
1285 }
1286
1287 sap->saip=NULL;
1288 AlnMgr2IndexLite(sap);
1289 sanp = SeqAnnotForSeqAlign (sap);
1290 sanp->name=StringSave("Blast 2 seqs");
1291 if (sanp == NULL) return FALSE;
1292 entityID=Ing_AttachSeqAnnotToSeqEntry(entityID, sanp, bsp1);
1293 SeqMgrIndexFeatures (entityID, NULL);
1294 return TRUE;
1295 }
1296
1297
1298
1299 static void Ing_DoBlast2Seqs (ButtoN b)
1300 {
1301 IngGenomeViewerPtr igvp=NULL;
1302 WindoW w;
1303 SeqEntryPtr sep;
1304 SeqLocPtr slp1=NULL;
1305 BioseqPtr bsp_2;
1306 Pointer dataptr;
1307 Uint2 datatype=0, entityID=0;
1308 IngBlast2InfoPtr bip=NULL;
1309 FILE * fp;
1310 CharPtr str, ptr;
1311 CharPtr text;
1312 Boolean is_local, first_bsp=TRUE;
1313 Char eval[8];
1314 BLAST_OptionsBlkPtr options;
1315 Int4 e;
1316 Int2 i;
1317 IngEntityPtr e_list, e_next, e_head, e_tmp;
1318 Int4 start, stop, temp;
1319
1320
1321 WatchCursor();
1322 w=(WindoW)ParentWindow(b);
1323
1324 bip = (IngBlast2InfoPtr)GetObjectExtra(b);
1325 if (bip == NULL || bip->bsp1 == NULL)
1326 goto end;
1327 igvp=(IngGenomeViewerPtr)GetObjectExtra(w);
1328 Ing_ProgressNew(igvp, "Running Blast 2 Sequences...");
1329
1330 if (igvp==NULL) goto end;
1331
1332 Hide(w);
1333
1334 i = GetValue(bip->localorglobal);
1335 if (i==1)
1336 is_local=TRUE;
1337 else
1338 is_local=FALSE;
1339
1340 text = StringSave("blastn"); /* can only do blastn for now */
1341
1342 options = BLASTOptionNew(text, TRUE);
1343
1344 i = GetValue(bip->gapped);
1345 if (i == 1)
1346 {
1347 options->gapped_calculation = TRUE;
1348 } else if (i == 2){
1349 options = BLASTOptionNew(text, FALSE);
1350 options->gapped_calculation = FALSE;
1351 } else
1352 goto end;
1353
1354 start = Ing_GetValue (bip->from);
1355 stop = Ing_GetValue (bip->to);
1356 if (start > stop){
1357 temp = stop;
1358 stop = start;
1359 start = temp;
1360 }
1361 if (start < 0)
1362 start = 0;
1363 if (stop > bip->bsp1->length-1)
1364 stop = bip->bsp1->length-1;
1365
1366 slp1= SeqLocIntNew(start, stop, 1, bip->bsp1->id);
1367
1368 GetTitle(bip->eval, eval, 14);
1369 if (eval != NULL)
1370 {
1371 e = atoi(eval);
1372 options->expect_value = Ing_get_eval(e);
1373 }
1374
1375 GetTitle(bip->wordsize, eval, 5);
1376 if (eval != NULL)
1377 options->wordsize = atoi(eval);
1378 if (GetStatus(bip->maskrep) == TRUE)
1379 {
1380 if (GetStatus(bip->masksimple) == TRUE)
1381 options->filter_string = StringSave("m L;R");
1382 else
1383 options->filter_string = StringSave("m R");
1384 } else if (GetStatus(bip->masksimple) == TRUE)
1385 options->filter_string = StringSave("m L");
1386 if (GetStatus(bip->megablast))
1387 options->is_megablast_search=TRUE;
1388
1389 e_list=NULL;
1390 if (bip->path){
1391
1392 if (!(fp = FileOpen(bip->path, "r"))) goto end;
1393
1394 while ((dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, &entityID, FALSE, FALSE, TRUE, FALSE)) != NULL)
1395 {
1396 if (datatype == OBJ_BIOSEQ)
1397 {
1398 bsp_2 = (BioseqPtr)dataptr;
1399 sep= GetTopSeqEntryForEntityID(entityID);
1400 e_next=(IngEntityPtr)MemNew(sizeof(IngEntity));
1401 e_next->Sips=SAM_ExtractSips(sep);
1402 if (first_bsp){
1403 e_list=e_next;
1404 e_head=e_next;
1405 first_bsp=FALSE;
1406 }
1407 else{
1408 e_list->next=e_next;
1409 e_list=e_list->next;
1410 }
1411 if (!bsp_2) goto end;
1412 if (bsp_2 && ISA_na(bsp_2->mol))
1413 {
1414 Ing_RunBlast2SeqsJob(slp1, igvp->entityID, bip->bsp1, bsp_2, text, options);
1415 }
1416 }
1417 }
1418 MemFree(bip->path);
1419 }
1420 else if (bip->GI_list){
1421 str=bip->GI_list;
1422
1423 ptr = strtok(str, " ");
1424 while(ptr != NULL)
1425 {
1426 bsp_2 = Ing_GetBspFromGIOrAcc(ptr);
1427 if (bsp_2 != NULL)
1428 {
1429 e_next=(IngEntityPtr)MemNew(sizeof(IngEntity));
1430 sep = SeqMgrGetSeqEntryForData (bsp_2);
1431 e_next->Sips=SAM_ExtractSips(sep);
1432 if (first_bsp){
1433 e_list=e_next;
1434 e_head=e_next;
1435 first_bsp=FALSE;
1436 }
1437 else{
1438 e_list->next=e_next;
1439 e_list=e_list->next;
1440 }
1441 if (!bsp_2) goto end;
1442 if (bsp_2 && ISA_na(bsp_2->mol))
1443 {
1444 Ing_RunBlast2SeqsJob(slp1, igvp->entityID, bip->bsp1, bsp_2, text, options);
1445 }
1446 }
1447 ptr = strtok(NULL, " ");
1448
1449 }
1450 MemFree(bip->GI_list);
1451 }
1452
1453 e_tmp=igvp->entity_list;
1454 if (e_tmp){
1455 while(e_tmp->next!=NULL)
1456 e_tmp=e_tmp->next;
1457 e_tmp->next=e_head;
1458 }
1459 else{
1460 igvp->entity_list=e_list;
1461 }
1462
1463 BLASTOptionDelete(options);
1464
1465 if (bip->path)
1466 MemFree(bip->path);
1467 else if (bip->GI_list)
1468 MemFree(bip->GI_list);
1469 SeqLocFree(slp1);
1470 Remove(w);
1471 Enable(igvp->d_Win->mrnaorexons);
1472 igvp->talign.update = TRUE;
1473 Ing_PopulateOverviewPage((Pointer)igvp, FALSE);
1474 Ing_PopulateDetailedPage((Pointer)igvp);
1475 end:
1476 ArrowCursor();
1477 Ing_ProgressEnd(igvp);
1478 return;
1479
1480 }
1481
1482
1483
1484 static void Ing_MegaBlast2Defaults(ButtoN b)
1485 {
1486 IngBlast2InfoPtr bip;
1487
1488 bip=(IngBlast2InfoPtr)GetObjectExtra(b);
1489
1490 if (GetStatus(b)){
1491 SetValue(bip->gapped, 1);
1492 SetTitle(bip->wordsize, "28");
1493 }
1494 else {
1495 SetTitle(bip->wordsize, "11");
1496 }
1497 }
1498
1499 extern void Ing_CreateBlast2SeqsForm(IngGenomeViewerPtr igvp, BioseqPtr bsp1, CharPtr path, CharPtr GI_list)
1500 {
1501 IngBlast2InfoPtr bip;
1502 ButtoN b;
1503 ButtoN b1;
1504 GrouP maingroup, globalg, localg, gapsg, eANDwg;
1505 GrouP submitg, maskg, g1, g2, g3;
1506 GrouP leng, g;
1507 WindoW w;
1508 Char lenbuf[40]={""}, szbuf[40]={""};
1509 Int4 start, stop;
1510
1511 if (!(bip = (IngBlast2InfoPtr)MemNew(sizeof(IngBlast2Info)))) return;
1512
1513 bip->bsp1 = bsp1;
1514 if (!StringHasNoText(path)){
1515 bip->path=StringSave(path);
1516 bip->GI_list=NULL;
1517 }
1518 else{
1519 bip->GI_list=StringSave(GI_list);
1520 bip->path=NULL;
1521 }
1522 w = MovableModalWindow(-50, -33 ,-10, -10, "Blast2Seqs", NULL);
1523 maingroup = HiddenGroup(w, 1, 7, NULL);
1524 SetGroupMargins(maingroup, 10, 10);
1525 SetGroupSpacing(maingroup, 10, 20);
1526
1527 MemSet((Pointer)lenbuf, '\0', sizeof(lenbuf));
1528 sprintf(lenbuf, "Query. length=%d", bsp1->length);
1529
1530 MemSet((Pointer)szbuf, '\0', sizeof(szbuf));
1531 SeqIdWrite(bsp1->id, szbuf, PRINTID_FASTA_SHORT,40);
1532
1533 leng = NormalGroup(maingroup,1, 2, lenbuf, NULL, NULL);
1534 SetGroupMargins(leng, 10, 10);
1535 SetGroupSpacing(leng, 10, 20);
1536
1537 StaticPrompt(leng, szbuf,0,0,programFont,'l');
1538
1539 g=HiddenGroup(leng, 4, 1, NULL);
1540 StaticPrompt(g, "from:", 0, 0, programFont, 'l');
1541 if (igvp->slp){
1542 start = SeqLocStart(igvp->slp);
1543 stop = SeqLocStop(igvp->slp);
1544 }
1545 else {
1546 start = 1;
1547 stop = bsp1->length;
1548 }
1549
1550 sprintf(szbuf, "%d", start);
1551 bip->from = DialogText(g, szbuf, 5, (TxtActnProc) NULL);
1552 StaticPrompt(g, " to:", 0, 0, programFont, 'l');
1553 sprintf(szbuf, "%d", stop);
1554 bip->to = DialogText(g, szbuf, 5, (TxtActnProc) NULL);
1555
1556 globalg = NormalGroup(maingroup,1, 1, "Alignment Type", programFont,NULL);
1557 bip->localorglobal = HiddenGroup(globalg, 2, 1, NULL);
1558 RadioButton(bip->localorglobal, "Local");
1559 RadioButton(bip->localorglobal, "Global");
1560 SetValue(bip->localorglobal, 1);
1561
1562 localg = NormalGroup(maingroup, 1, 3, "Local Alignment Options", programFont, NULL);
1563 g1 = NormalGroup(localg, 1,1, "", programFont,NULL);
1564 gapsg = HiddenGroup(g1, 3, 2, NULL);
1565 bip->gapped = HiddenGroup(gapsg, 0, 2, NULL);
1566 RadioButton(bip->gapped, "gapped");
1567 RadioButton(bip->gapped, "ungapped");
1568 SetValue(bip->gapped, 1);
1569
1570 g2 = NormalGroup(maingroup, 1,1, "Mask Regions", programFont,NULL);
1571 maskg=HiddenGroup(g2, 0, 2, NULL);
1572 bip->maskrep = CheckBox(maskg, "Mask Repeats", NULL);
1573 SetStatus(bip->maskrep, FALSE);
1574 bip->masksimple = CheckBox(maskg, "Mask Simple Sequence", NULL);
1575 SetStatus(bip->masksimple, TRUE);
1576 bip->megablast= CheckBox(maingroup, "Mega Blast", Ing_MegaBlast2Defaults);
1577 SetObjectExtra(bip->megablast, (Pointer)bip, NULL);
1578 SetStatus(bip->megablast, FALSE);
1579
1580 g3 = NormalGroup(maingroup, 1,1, "", programFont,NULL);
1581 eANDwg = HiddenGroup(g3, 2, 2, NULL);
1582 StaticPrompt(eANDwg, "E-value: e-", 0, 0, programFont, 'l');
1583 bip->eval = DialogText(eANDwg, "1", 5, NULL);
1584 StaticPrompt(eANDwg, "wordsize:", 0, 0, programFont, 'l');
1585 bip->wordsize = DialogText(eANDwg, "11", 5, NULL);
1586
1587
1588 submitg=HiddenGroup(maingroup, 2, 0, NULL);
1589 b = DefaultButton(submitg, "Accept", Ing_DoBlast2Seqs);
1590 Enable(b);
1591 b1 = PushButton(submitg, "Cancel", Ing_StdCancelProc);
1592 bip->igvp=igvp;
1593 SetObjectExtra(b1, (Pointer)bip, StdCleanupExtraProc);
1594 SetObjectExtra(b, (Pointer)bip, StdCleanupExtraProc);
1595 SetObjectExtra(w, (Pointer)igvp, NULL);
1596 Select(w);
1597 Show(w);
1598
1599 return;
1600
1601 }
1602
1603
1604 extern void Ing_Blast2SeqsProc(IteM i)
1605 {
1606 IngGenomeViewerPtr igvp;
1607
1608 igvp = GetObjectExtra (ParentWindow(i));
1609 if (igvp == NULL) return;
1610 igvp->filetype=ALIGN_BLAST2SEQ;
1611 Ing_OpenFromFileORNetwork(igvp);
1612 }
1613
1614 /***************************************************
1615
1616 Function : Dot Matrix/ Dot Diag Functions
1617
1618 Purpose : compare two bioseqs
1619
1620 Return value :
1621
1622 ***************************************************/
1623
1624 extern void Ing_DotDiagProc(IteM i)
1625 {
1626 Int2 ret;
1627 SeqAlignPtr sap=NULL;
1628 SelStructPtr ssp;
1629 IngGenomeViewerPtr igvp;
1630 ObjMgrPtr omp=NULL;
1631 OMProcControl ompc;
1632 ObjMgrProcPtr ompp=NULL;
1633
1634
1635 REGISTER_DiagsDisplay;
1636
1637 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(i));
1638 if (!igvp) {
1639 ArrowCursor();
1640 return;
1641 }
1642
1643 ssp = ObjMgrGetSelected();
1644 if (ssp == NULL){
1645 ArrowCursor();
1646 return;
1647 }
1648 if (ssp->itemtype != OBJ_SEQALIGN)
1649 {
1650 ErrPostEx(SEV_ERROR, 0, 0, "MUST select seqalign");
1651 ErrShow();
1652 ArrowCursor();
1653 return;
1654 }
1655 if (ssp)
1656 {
1657 sap = (SeqAlignPtr)GetPointerForIDs(ssp->entityID, ssp->itemID, OBJ_SEQALIGN);
1658 if (sap == NULL)
1659 {
1660 ErrPostEx(SEV_ERROR, 0, 0, "Error in copying seqalign");
1661 ErrShow();
1662 ArrowCursor();
1663 return;
1664 }
1665
1666 if (sap){
1667 omp = ObjMgrReadLock();
1668 ompp = ObjMgrProcFind(omp, 0, "DOT_DiagsDisplay", 0);
1669 ompc.input_itemtype = OBJ_SEQALIGN;
1670 ompc.input_data = (Pointer)sap;
1671 ompc.input_entityID = ssp->entityID;
1672 ompc.proc = ompp;
1673 ObjMgrUnlock();
1674 if (ompp != NULL)
1675 {
1676 ret = (*(ompp->func))((Pointer)&ompc);
1677 switch(ret)
1678 {
1679 case OM_MSG_RET_ERROR:
1680 ErrShow();
1681 break;
1682 default:
1683 break;
1684 }
1685 }
1686 /* DOT_AlignPlotGivenSeqAlign(sap); */
1687 }
1688
1689 igvp->update=FALSE;
1690 ObjMgrSetDirtyFlag (igvp->entityID, TRUE);
1691 ObjMgrSendMsg (OM_MSG_UPDATE, igvp->entityID, 0, 0);
1692 }
1693
1694 ArrowCursor();
1695 return;
1696
1697 }
1698
1699 static void Ing_DotMatrixAccept(ButtoN b)
1700 {
1701 DotInfo * dip;
1702 DOTMainDataPtr mip;
1703 Int4 wordsize=0, numhits=0, f1=0, f2=0, t1=0, t2=0;
1704 SeqLocPtr slp1=NULL, slp2=NULL;
1705 WindoW w;
1706 SeqAlignPtr sap = NULL, sap_tmp = NULL;
1707 IngGenomeViewerPtr igvp = NULL;
1708 DOTAlignInfoPtr alp;
1709
1710 w=ParentWindow(b);
1711 igvp=(IngGenomeViewerPtr)GetObjectExtra(w);
1712 if (!igvp) return;
1713
1714 Hide(w);
1715 dip=(DotInfo *)GetObjectExtra(b);
1716 wordsize=Ing_GetValue(dip->wordsize);
1717 numhits=Ing_GetValue(dip->numhits);
1718 f1=Ing_GetValue(dip->from1);
1719 f2=Ing_GetValue(dip->from2);
1720 t1=Ing_GetValue(dip->to1);
1721 t2=Ing_GetValue(dip->to2);
1722 if (Ing_GetValue(dip->strand)==Seq_strand_plus)
1723 slp1= SeqLocIntNew(f1, t1, 1, dip->sip1);
1724 else
1725 slp1= SeqLocIntNew(f1, t1, 2, dip->sip1);
1726 slp2 = SeqLocIntNew(f2, t2,1, dip->sip2);
1727
1728
1729 if (slp1==NULL || slp2==NULL || wordsize==0 || numhits==0 ||
1730 (f1==0 && t1==0) || (f2==0 && t2==0)){
1731 ErrPostEx(SEV_ERROR, 0, 0, "Missing values");
1732 ErrShow();
1733 Show(w);
1734 return;
1735 }
1736 sap=dip->sap;
1737 Remove(w);
1738 mip = DOT_CreateAndStorebyLoc (slp1, slp2, wordsize, numhits);
1739 if (mip){
1740 if (sap){
1741 sap_tmp=sap->next;
1742 sap->next=NULL;
1743 alp=DOT_AlignInfoNew();
1744 alp->sap=sap;
1745 DOT_FillAlignInfoPointer(alp);
1746 DOT_MakeMainViewer(mip, alp);
1747 sap->next=sap_tmp;
1748 }
1749 else
1750 DOT_MakeMainViewer(mip, NULL);
1751
1752 }
1753 }
1754
1755
1756
1757 extern void Ing_CreateDotMatrixForm(IngGenomeViewerPtr igvp, SeqAlignPtr sap, CharPtr path, CharPtr GI_list)
1758 {
1759 WindoW DlgW;
1760 SeqIdPtr sip1=NULL, sip2=NULL;
1761 Int4 start, stop;
1762 Char lenbuf[50]={""}, szbuf[41]={""};
1763 DotInfo * dip;
1764 FILE *fp = NULL;
1765 ButtoN b;
1766 GrouP g, d, g_top;
1767 BioseqPtr bsp1 = NULL, bsp2 = NULL;
1768 Pointer dataptr = NULL;
1769 Uint2 datatype = 0;
1770 CharPtr ptr = NULL;
1771 SeqEntryPtr sep = NULL;
1772 Uint1 strand;
1773
1774
1775 DlgW = MovableModalWindow(-50, -33 ,-10, -10, "Dot Matrix", NULL);
1776 dip=(DotInfo *)MemNew(sizeof(DotInfo));
1777
1778 if (sap != NULL){
1779 dip->sap=sap;
1780 strand = AlnMgr2GetNthStrand(sap, 2);
1781 sip1=AlnMgr2GetNthSeqIdPtr(sap, 1);
1782 if (!sip1) goto end;
1783 dip->sip1=sip1;
1784 bsp1=BioseqLockById(sip1);
1785 AlnMgr2GetNthSeqRangeInSA(sap, 1, &start, &stop);
1786 }
1787 else {
1788 dip->sap = NULL;
1789 bsp1 = igvp->bsp;
1790 sip1 = bsp1->id;
1791 dip->sip1 = sip1;
1792 start = 0;
1793 stop = bsp1->length - 1;
1794 strand = Seq_strand_plus;
1795 }
1796
1797 if (bsp1){
1798 MemSet((Pointer)lenbuf, '\0', sizeof(lenbuf));
1799 sprintf(lenbuf, "Query len = %d", bsp1->length);
1800 }
1801 else goto end;
1802
1803 MemSet((Pointer)szbuf, '\0', sizeof(szbuf));
1804 SeqIdWrite(sip1, szbuf, PRINTID_FASTA_SHORT,41);
1805 d=HiddenGroup(DlgW, 1, 4, NULL);
1806 SetGroupMargins(d, 10, 10);
1807 SetGroupSpacing(d, 10, 20);
1808
1809 g_top = NormalGroup(d,1, 2, lenbuf, NULL, NULL);
1810 SetGroupMargins(g_top, 10, 10);
1811 SetGroupSpacing(g_top, 10, 20);
1812
1813 g=HiddenGroup(g_top, 5, 1, NULL);
1814 StaticPrompt(g, szbuf,0,0,programFont,'l');
1815 StaticPrompt(g, "from:", 0, 0, programFont, 'l');
1816 sprintf(szbuf, "%d", start);
1817 dip->from1 = DialogText(g, szbuf, 5, (TxtActnProc) NULL);
1818 StaticPrompt(g, " to:", 0, 0, programFont, 'l');
1819 sprintf(szbuf, "%d", stop);
1820 dip->to1 = DialogText(g, szbuf, 5, (TxtActnProc) NULL);
1821 BioseqUnlock(bsp1);
1822
1823 if (sap != NULL){
1824 sip2=AlnMgr2GetNthSeqIdPtr(sap, 2);
1825 if (!sip2) goto end;
1826 dip->sip2=sip2;
1827 bsp2=BioseqLockById(sip2);
1828 AlnMgr2GetNthSeqRangeInSA(sap, 2, &start, &stop);
1829 }
1830 else {
1831 if (!StringHasNoText(path)){
1832 fp = FileOpen(path, "r");
1833 if (!fp) goto end;
1834 while (dataptr = ReadAsnFastaOrFlatFile(fp, &datatype, NULL, FALSE, FALSE, TRUE, FALSE))
1835 {
1836 if (datatype == OBJ_BIOSEQ){
1837 bsp2 = (BioseqPtr)dataptr;
1838 }
1839 else if (datatype == OBJ_SEQENTRY){
1840 sep=(SeqEntryPtr)dataptr;
1841 bsp2=(BioseqPtr)sep->data.ptrvalue;
1842 }
1843 else {
1844 Message (MSG_OK, "File is not a bioseq or seqentry");
1845 return;
1846 }
1847 }
1848 }
1849 else if (GI_list){
1850 ptr = strtok(GI_list, " ");
1851 while(ptr != NULL)
1852 {
1853 bsp2 = Ing_GetBspFromGIOrAcc(ptr);
1854 if (bsp2!=NULL)
1855 {
1856 if (!ISA_na(bsp2->mol)){
1857 Message (MSG_OK, "Sequence is not nucleotide");
1858 return;
1859 }
1860 }
1861 ptr = strtok(NULL, " ");
1862 }
1863 }
1864 sip2 = bsp2->id;
1865 dip->sip2 = sip2;
1866 start = 0;
1867 stop = bsp2->length - 1;
1868 }
1869
1870 if (bsp2){
1871 MemSet((Pointer)lenbuf, '\0', sizeof(lenbuf));
1872 sprintf(lenbuf, "Subject len = %d", bsp2->length);
1873 }
1874 else goto end;
1875
1876 MemSet((Pointer)szbuf, '\0', sizeof(szbuf));
1877 SeqIdWrite(sip2, szbuf, PRINTID_FASTA_SHORT,41);
1878
1879 if (start>bsp2->length)
1880 start=0;
1881 if (stop>bsp2->length)
1882 stop=bsp2->length-1;
1883 BioseqUnlock(bsp2);
1884
1885 g_top = NormalGroup(d,1, 1, lenbuf, NULL, NULL);
1886 SetGroupMargins(g_top, 10, 10);
1887 SetGroupSpacing(g_top, 10, 20);
1888
1889 g=HiddenGroup(g_top, 5, 1, NULL);
1890 StaticPrompt(g, szbuf,0,0,programFont,'l');
1891 StaticPrompt(g, " from:", 0, 0, programFont, 'l');
1892 sprintf(szbuf, "%d", start);
1893 dip->from2 = DialogText(g, szbuf, 5, (TxtActnProc) NULL);
1894 StaticPrompt(g, " to:", 0, 0, programFont, 'l');
1895 sprintf(szbuf, "%d", stop);
1896 dip->to2 = DialogText(g, szbuf, 5, (TxtActnProc) NULL);
1897
1898 g_top = NormalGroup(d,1, 1, "Dot Plot parameters", NULL, NULL);
1899 SetGroupMargins(g_top, 10, 10);
1900 SetGroupSpacing(g_top, 10, 20);
1901
1902 g=HiddenGroup(g_top, 2, 3, NULL);
1903 StaticPrompt(g, "Word size:", 0, 0, programFont, 'l');
1904 dip->wordsize = DialogText(g, "11", 5, (TxtActnProc) NULL);
1905 StaticPrompt(g, "Max # of hits", 0, 0, programFont, 'l');
1906 dip->numhits = DialogText(g, "1000000", 5, (TxtActnProc) NULL);
1907 StaticPrompt(g, "plus-plus=1/plus-minus=2", 0, 0, programFont, 'l');
1908 if (strand == Seq_strand_minus)
1909 dip->strand = DialogText(g, "2", 5, (TxtActnProc) NULL);
1910 else
1911 dip->strand = DialogText(g, "1", 5, (TxtActnProc) NULL);
1912
1913 g = HiddenGroup(d, 2, 1, NULL);
1914 b=DefaultButton(g, "Accept", Ing_DotMatrixAccept);
1915 Enable(b);
1916 PushButton(g, "Cancel", Ing_StdCancelProc);
1917
1918 SetObjectExtra(b, (Pointer)dip, StdCleanupExtraProc);
1919 SetObjectExtra(DlgW, (Pointer)igvp, NULL);
1920
1921
1922 RealizeWindow(DlgW);
1923 Select(DlgW);
1924 Show(DlgW);
1925 return;
1926 end:
1927 Message (MSG_OK, "Invalid alignment");
1928
1929 }
1930
1931
1932 extern void Ing_GetFileForDotMatrix(IteM i)
1933 {
1934 IngGenomeViewerPtr igvp;
1935
1936 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(i));
1937 igvp->filetype=Ing_DOTMATRIX;
1938 Ing_OpenFromFileORNetwork(igvp);
1939
1940 }
1941
1942 /***************************************************
1943
1944 Function : Spidey Related Functions
1945
1946 Purpose : read mRNA sequences, run spidey, display
1947 results and delete structure
1948
1949 ***************************************************/
1950
1951 static void Ing_AddSpideyAlignsToBioseq(SPI_mRNAPtr spidp, Uint2 entityID, IngGenomeViewerPtr igvp, BioseqPtr bsp_genomic, Boolean isExons)
1952 {
1953 SPI_mRNAPtr spidp_head = NULL;
1954 SPI_mRNAPtr spidp_next = NULL;
1955 SeqAnnotPtr sanp = NULL;
1956
1957
1958 spidp_head=spidp;
1959 while(spidp){
1960 if (!isExons)
1961 sanp = SeqAnnotForSeqAlign(spidp->continuous);
1962 else
1963 sanp = SeqAnnotForSeqAlign(spidp->parent);
1964 sanp->name=StringSave("Spidey");
1965 Ing_AttachSeqAnnotToSeqEntry(entityID, (SeqAnnotPtr)sanp, bsp_genomic);
1966 SeqMgrIndexFeatures (entityID, NULL);
1967 spidp=spidp->next;
1968 }
1969 spidp=spidp_head;
1970
1971 /* store new spidp to end of linked list */
1972
1973 if (igvp->data){
1974 spidp_head=(SPI_mRNAPtr)igvp->data;
1975 spidp_next=spidp_head;
1976 while(spidp_next->next!=NULL){
1977 spidp_next=spidp_next->next;
1978 }
1979 spidp_next->next = spidp;
1980 }
1981 else {
1982 igvp->data=(Pointer)spidp;
1983 Enable(igvp->d_Win->mrnaorexons);
1984 }
1985
1986 }
1987
1988
1989 static void Ing_RunSpidey(BioseqPtr bsp_genomic, BioseqPtr bsp_mRNA, IngGenomeViewerPtr igvp, Uint2 entityID, SPI_OptionsPtr spot)
1990 {
1991 SPI_mRNAPtr spidp = NULL;
1992 SPI_mRNAPtr spidp_head = NULL;
1993 SPI_mRNAPtr spidp_next = NULL;
1994 SeqAnnotPtr sanp = NULL;
1995 Char str[31]={""}, buf[40]={""};
1996
1997 Ing_WinTimerProc(igvp->hMain);
1998 spidp=SPI_AlignmRNAToGenomic(bsp_genomic, bsp_mRNA, spot);
1999
2000 SeqIdWrite(bsp_mRNA->id, str, PRINTID_FASTA_LONG,30);
2001
2002 if (!spidp) {
2003 sprintf(buf, "Spidey returned NULL for %s", str);
2004 Message (MSG_OK, buf);
2005 return;
2006 }
2007 Ing_AddSpideyAlignsToBioseq(spidp, entityID, igvp, bsp_genomic, igvp->isExons);
2008 Enable(igvp->d_Win->mrnaorexons);
2009 Ing_WinTimerProc(igvp->hMain);
2010
2011 return;
2012 }
2013
2014
2015 static void Ing_ReadmRNAs_ext(FILE * fp, IngGenomeViewerPtr igvp, CharPtr GI_list, SPI_OptionsPtr spot)
2016 {
2017 BioseqPtr bsp_mRNA = NULL;
2018 Pointer dataptr = NULL;
2019 Uint2 datatype = 0;
2020 CharPtr ptr=NULL;
2021 SeqEntryPtr sep;
2022
2023
2024 if (fp != NULL){
2025 while (dataptr = ReadAsnFastaOrFlatFile(fp, &datatype, NULL, FALSE, FALSE, TRUE, FALSE))
2026 {
2027 if (datatype == OBJ_BIOSEQ)
2028 {
2029 bsp_mRNA = (BioseqPtr)dataptr;
2030 }
2031 else if (datatype == OBJ_SEQENTRY){
2032 sep=(SeqEntryPtr)dataptr;
2033 if (sep->choice == 1) /* bioseq */
2034 bsp_mRNA=(BioseqPtr)sep->data.ptrvalue;
2035 else if (sep->choice == 2)
2036 {
2037 Message (MSG_OK, "File is a bioseq-set");
2038 return;
2039 }
2040 }
2041 else {
2042 Message (MSG_OK, "File is not a bioseq or seqentry");
2043 return;
2044 }
2045 if (bsp_mRNA->mol == 0)
2046 bsp_mRNA->mol = Seq_mol_rna;
2047 if (bsp_mRNA && (ISA_na(bsp_mRNA->mol)))
2048 {
2049 Ing_RunSpidey(igvp->bsp, bsp_mRNA, igvp, igvp->entityID, spot);
2050 }
2051 }
2052 }
2053 else if (GI_list){
2054
2055 ptr = strtok(GI_list, " ");
2056 while(ptr != NULL)
2057 {
2058 bsp_mRNA = Ing_GetBspFromGIOrAcc(ptr);
2059 if (bsp_mRNA!=NULL)
2060 {
2061 if (bsp_mRNA)
2062 {
2063 if (!ISA_na(bsp_mRNA->mol)){
2064 Message (MSG_OK, "Sequence is not nucleotide");
2065 return;
2066 }
2067 Ing_RunSpidey(igvp->bsp, bsp_mRNA, igvp, igvp->entityID, spot);
2068 }
2069 BioseqUnlock(bsp_mRNA);
2070 }
2071 ptr = strtok(NULL, " ");
2072 }
2073 }
2074 }
2075
2076
2077 extern void Ing_ReadmRNAs (FILE * fp, IngGenomeViewerPtr igvp, CharPtr GI_list)
2078 {
2079 Ing_ReadmRNAs_ext(fp, igvp, GI_list, NULL);
2080 }
2081
2082
2083 static Boolean LIBCALLBACK Ing_SpideyCallback (SPI_ProgressPtr progress)
2084 {
2085 IngGenomeViewerPtr igvp=NULL;
2086
2087
2088 switch (progress->returncode) {
2089 case SPI_START:
2090 return TRUE;
2091 case SPI_PROGRESS:
2092 if (progressW != NULL) {
2093 igvp=(IngGenomeViewerPtr)GetObjectExtra(progressW);
2094 if (!igvp)
2095 return TRUE;
2096 if (progress->percentdone>0){
2097 sprintf(igvp->progress_counter, "Completed %d%%", progress->percentdone);
2098 }
2099 Ing_WinTimerProc(progressW);
2100 }
2101 return TRUE;
2102 case SPI_FINISHED:
2103 return TRUE;
2104 default:
2105 break;
2106 }
2107 return FALSE;
2108 }
2109
2110 static FloatHi Ing_GetFloatValue (TexT t)
2111 {
2112 Char str[20];
2113 FloatHi val;
2114
2115 GetTitle (t, str, sizeof(str));
2116 if (StringHasNoText(str))
2117 {
2118 ErrPostEx (SEV_WARNING, 0, 0, "%s", "missing parameter(s)");
2119 ErrShow();
2120 return 0.0;
2121 }
2122
2123 val=atof(str);
2124
2125 return val;
2126 }
2127
2128 static void Ing_DoSpidey(ButtoN b)
2129 {
2130 WindoW w;
2131 IngSpideyFormPtr sfp=NULL;
2132 SPI_OptionsPtr spot=NULL;
2133 IngGenomeViewerPtr igvp=NULL;
2134 FILE * fp=NULL;
2135 Int4 start, stop, temp;
2136
2137 w=(WindoW)ParentWindow(b);
2138 WatchCursor();
2139 sfp = (IngSpideyFormPtr)GetObjectExtra(b);
2140 if (sfp == NULL || sfp->bsp1 == NULL)
2141 goto end;
2142 igvp=(IngGenomeViewerPtr)GetObjectExtra(w);
2143 if (igvp==NULL) goto end;
2144 Ing_ProgressNew(igvp, "Running Spidey...");
2145
2146 Hide(w);
2147
2148 spot = (SPI_OptionsPtr)MemNew(sizeof(SPI_Options));
2149 spot->firstpasseval = Ing_GetFloatValue(sfp->firstpasseval);
2150 spot->secpasseval = Ing_GetFloatValue(sfp->secondpasseval);
2151 spot->thirdpasseval = Ing_GetFloatValue(sfp->thirdpasseval);
2152 spot->numreturns = Ing_GetValue(sfp->numreturns);
2153 spot->printaln = TRUE;
2154 spot->printasn = FALSE;
2155 spot->idcutoff = Ing_GetValue(sfp->idcutoff);
2156 spot->lencutoff = Ing_GetValue(sfp->lencutoff);
2157 spot->interspecies = (Boolean) GetValue(sfp->inters);
2158 spot->organism=GetValue(sfp->org);
2159 spot->callback= Ing_SpideyCallback;
2160
2161 start = Ing_GetValue(sfp->from);
2162 stop = Ing_GetValue(sfp->to);
2163 if (start>stop){
2164 temp = start;
2165 start = stop;
2166 stop = temp;
2167 }
2168 if (start<0)
2169 start = 0;
2170 if (stop > igvp->bsp->length-1)
2171 stop = igvp->bsp->length-1;
2172 spot->from = start;
2173 spot->to = stop;
2174
2175 if (sfp->path){
2176 fp=FileOpen(sfp->path, "r");
2177 Ing_ReadmRNAs_ext(fp, igvp, NULL, spot);
2178 MemFree(sfp->path);
2179 }
2180 else if (sfp->GI_list){
2181 Ing_ReadmRNAs_ext(NULL, igvp, sfp->GI_list, spot);
2182 MemFree(sfp->GI_list);
2183 }
2184 MemFree(spot);
2185 Remove(w);
2186 igvp->talign.update = TRUE;
2187 Ing_PopulateOverviewPage((Pointer)igvp, FALSE);
2188 Ing_PopulateDetailedPage((Pointer)igvp);
2189
2190 end:
2191 ArrowCursor();
2192 Ing_ProgressEnd(igvp);
2193 return;
2194
2195 }
2196
2197 static void Ing_MarkSeqAnnotbyName(SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
2198 {
2199 BioseqPtr bsp=NULL;
2200 BioseqSetPtr bssp=NULL;
2201 SeqAnnotPtr sanp=NULL;
2202 CharPtr name=NULL;
2203
2204 name=(CharPtr)mydata;
2205 if (IS_Bioseq(sep)) {
2206 bsp = (BioseqPtr)sep->data.ptrvalue;
2207 sanp = bsp->annot;
2208 } else if (IS_Bioseq_set(sep)) {
2209 bssp = (BioseqSetPtr)sep->data.ptrvalue;
2210 sanp = bssp->annot;
2211 } else return;
2212
2213 while (sanp != NULL) {
2214 if (sanp->type == 2 && (StringCmp(sanp->name, name)==0)) {
2215 sanp->data=NULL;
2216 sanp->idx.deleteme=1;
2217 }
2218 sanp=sanp->next;
2219 }
2220 }
2221
2222
2223
2224 extern void Ing_DeleteSpidey(IngGenomeViewerPtr igvp, Int4 index)
2225 {
2226
2227 SPI_mRNAPtr spidp = NULL;
2228 SPI_mRNAPtr spidp_head = NULL;
2229 SPI_mRNAPtr prev_sp, cur_sp, next_sp;
2230 Int4 i;
2231
2232 spidp = (SPI_mRNAPtr) igvp->data;
2233 if (! spidp) return;
2234
2235 spidp_head = spidp;
2236
2237 if (!spidp->next){
2238 if (igvp->isExons){
2239 spidp->numexons = 0;
2240 spidp->parent = NULL;
2241 }
2242 else {
2243 spidp->continuous = NULL;
2244 }
2245 SPI_mRNAFree(spidp);
2246 igvp->data = NULL;
2247 return;
2248 }
2249
2250 for (i=2; i<index; i++)
2251 spidp = spidp->next;
2252 prev_sp = spidp;
2253 cur_sp = spidp->next;
2254 if (!cur_sp->next){
2255 if (igvp->isExons){
2256 cur_sp->numexons = 0;
2257 cur_sp->parent = NULL;
2258 }
2259 else {
2260 cur_sp->continuous = NULL;
2261 }
2262 SPI_mRNAFree(cur_sp);
2263 prev_sp->next = NULL;
2264 igvp->data = (Pointer) spidp_head;
2265 return;
2266 }
2267
2268 next_sp = cur_sp->next;
2269 prev_sp->next = next_sp;
2270 if (igvp->isExons){
2271 cur_sp->numexons = 0;
2272 cur_sp->parent = NULL;
2273 }
2274 else {
2275 cur_sp->continuous = NULL;
2276 }
2277 SPI_mRNAFree(cur_sp);
2278
2279 igvp->data = (Pointer) spidp_head;
2280 return;
2281
2282 }
2283
2284
2285 static void Ing_ClearSpideyAligns(IngGenomeViewerPtr igvp)
2286 {
2287 SeqEntryPtr sep=NULL;
2288 CharPtr name=NULL;
2289
2290 /* re-init arrays */
2291 Ing_InitAlignArrays(&igvp->talign, FALSE);
2292
2293 /* delete all spidey alignments */
2294 name = StringSave("Spidey");
2295 sep = GetTopSeqEntryForEntityID(igvp->entityID);
2296 SeqEntryExplore(sep,(Pointer)name, Ing_MarkSeqAnnotbyName);
2297 DeleteMarkedObjects(igvp->entityID, OBJ_SEQENTRY, (Pointer)sep);
2298
2299 }
2300
2301
2302 extern void Ing_mRNAOrExons(IteM item)
2303 {
2304 IngGenomeViewerPtr igvp = NULL;
2305 SPI_mRNAPtr spidp = NULL;
2306 IngReportPtr Report = NULL;
2307 SelStructPtr ssp=NULL;
2308
2309 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(item));
2310 if (!igvp) return;
2311
2312 ssp = ObjMgrGetSelected();
2313 if (ssp)
2314 ObjMgrDeSelectAll();
2315 spidp = (SPI_mRNAPtr)igvp->data;
2316 if (spidp == NULL) return;
2317 igvp->data = NULL;
2318 Ing_ClearSpideyAligns(igvp);
2319 if (igvp->isExons){
2320 igvp->isExons=FALSE;
2321 SetTitle(igvp->d_Win->mrnaorexons, "Spidey - as Exons");
2322 }
2323 else {
2324 igvp->isExons=TRUE;
2325 SetTitle(igvp->d_Win->mrnaorexons, "Spidey - as mRNA");
2326 }
2327
2328 Ing_AddSpideyAlignsToBioseq(spidp, igvp->entityID, igvp, igvp->bsp, igvp->isExons);
2329
2330 ObjMgrSetDirtyFlag (igvp->entityID, TRUE);
2331 ObjMgrSendMsg (OM_MSG_UPDATE, igvp->entityID, 0, 0);
2332 if (igvp->hReport){
2333 Report = (IngReportPtr)GetObjectExtra(igvp->hReport);
2334 if (Report){
2335 Ing_PopulateReport(Report, igvp);
2336 }
2337 }
2338 }
2339
2340
2341 SPI_mRNAPtr Ing_FindSpidpGivenParent(SPI_mRNAPtr spidp_head, SeqAlignPtr sap, Boolean bExons)
2342 {
2343 SPI_mRNAPtr spidp_temp = NULL;
2344
2345 if (!spidp_head) return NULL;
2346
2347 spidp_temp = spidp_head;
2348
2349 if (bExons){
2350 while (spidp_temp){
2351 if (spidp_temp->parent == sap){
2352 return spidp_temp;
2353 }
2354 spidp_temp = spidp_temp->next;
2355 }
2356 }
2357 else {
2358 while (spidp_temp){
2359 if (spidp_temp->continuous == sap){
2360 return spidp_temp;
2361 }
2362 spidp_temp = spidp_temp->next;
2363 }
2364 }
2365 return NULL;
2366 }
2367
2368
2369 extern SeqLocPtr Ing_MakeLocListFromSpidp(Pointer userdata, SeqAlignPtr parent, Boolean gap_split)
2370 {
2371 SeqIdPtr sip;
2372 SeqLocPtr slp = NULL, slp_head = NULL;
2373 SeqAlignPtr child = NULL;
2374 SPI_mRNAPtr spidp = NULL, spidp_head = NULL;
2375 Int4 i, c;
2376
2377 spidp_head = (SPI_mRNAPtr) userdata;
2378 spidp = Ing_FindSpidpGivenParent(spidp_head, parent, FALSE);
2379 if (!spidp) return NULL;
2380
2381 child = (SeqAlignPtr) parent->segs;
2382 sip = AlnMgr2GetNthSeqIdPtr(child, 1);
2383 if (gap_split){
2384 for (i = 0; i < spidp->numexons; i++){
2385 if (spidp->strand == Seq_strand_minus)
2386 c = spidp->numexons - i - 1;
2387 else
2388 c = i;
2389
2390 slp=SeqLocIntNew(spidp->gstarts[c]-1, spidp->gstops[c]-1, spidp->strand, sip);
2391 SeqLocAdd(&slp_head, slp, TRUE, FALSE);
2392 }
2393 }
2394 else {
2395 slp = SeqLocIntNew(spidp->gstarts[0]-1, spidp->gstops[spidp->numexons-1]-1, spidp->strand, sip);
2396 SeqLocAdd(&slp_head, slp, TRUE, FALSE);
2397 }
2398
2399 return slp_head;
2400 }
2401
2402 static SPI_ExonProfPtr Ing_NumMismatches(SPI_ExonProfPtr epp_head, Int4 exon, Int4Ptr nmis)
2403 {
2404 SPI_ExonProfPtr epp;
2405
2406 epp=epp_head;
2407 while(epp){
2408 if (epp->exonnum==exon){
2409 *nmis=epp->nummismatches;
2410 return (epp);
2411 }
2412 epp=epp->next;
2413 }
2414 return NULL;
2415 }
2416
2417
2418 static Int4 Ing_get_rightend(SeqAlignPtr sap, Int4 mismatch, Int4 row, Int4Ptr nleftp, Int4Ptr nrightp)
2419 {
2420 Int4 insert_pos = -1, i = 0, j = -1, k = 0;
2421
2422 while(insert_pos == -1){
2423 i++;
2424 insert_pos = AlnMgr2MapBioseqToSeqAlign(sap, mismatch + i, row);
2425 }
2426 while (j == -1 && (mismatch - k) > 0){
2427 k++;
2428 j = AlnMgr2MapBioseqToSeqAlign(sap, mismatch - k, row);
2429 }
2430 if (nleftp != NULL)
2431 *nleftp = k - 1;
2432 if (nrightp != NULL)
2433 *nrightp = i -1;
2434
2435 return (insert_pos);
2436 }
2437
2438 static Boolean Ing_IsinRange(Int4 gleft, Int4 gright, Int4 start, Int4 stop)
2439 {
2440 if (start > gleft || stop < gright)
2441 return FALSE;
2442 else
2443 return TRUE;
2444 }
2445
2446
2447 static void Ing_ReplaceGapInGenomic(SeqAlignPtr sap, Int4 mmis)
2448 {
2449 DenseSegPtr dsp_new = NULL, dsp = NULL;
2450 Int4 i, j;
2451 Int4 seg_start, seg_stop;
2452 Int2 offset = 0;
2453 Boolean found = FALSE;
2454 Boolean gap_filled = FALSE;
2455
2456
2457 dsp = (DenseSegPtr)(sap->segs);
2458
2459 dsp_new = DenseSegNew();
2460 dsp_new->dim = 2;
2461 dsp_new->numseg = dsp->numseg - 2;
2462 dsp_new->ids = dsp->ids;
2463 dsp->ids = NULL;
2464 dsp_new->starts = (Int4Ptr)MemNew((dsp_new->numseg)*2*sizeof(Int4));
2465 dsp_new->lens = (Int4Ptr)MemNew((dsp_new->numseg)*sizeof(Int4));
2466 dsp_new->strands = (Uint1Ptr)MemNew((dsp_new->numseg)*2*sizeof(Uint1));
2467
2468 for (i = 0, j = 0; i < dsp->numseg; i++){
2469
2470 if (dsp->starts[i*2] == -1){
2471 seg_start = dsp->starts[i*2+1];
2472 seg_stop = dsp->starts[i*2+1] + dsp->lens[i] - 1;
2473 if (seg_start <= mmis && seg_stop >= mmis){
2474 found = TRUE;
2475 }
2476 else
2477 found = FALSE;
2478 }
2479
2480 if (!found || gap_filled){
2481 if (dsp->starts[i*2] != -1)
2482 dsp_new->starts[j*2] = dsp->starts[i*2] + offset;
2483 else
2484 dsp_new->starts[j*2] = dsp->starts[i*2];
2485 dsp_new->starts[j*2+1] = dsp->starts[i*2+1];
2486 dsp_new->strands[j*2] = dsp->strands[i*2];
2487 dsp_new->strands[j*2+1] = dsp->strands[i*2+1];
2488 dsp_new->lens[j] = dsp->lens[i];
2489 j++;
2490 }
2491 else if (!gap_filled){
2492 /* extend previous segment over the gap */
2493 offset += dsp->lens[i];
2494 if (dsp->strands[i*2+1] == Seq_strand_minus){
2495 /* if (dsp->starts[(i+1)*2] == -1) */
2496 /* dsp_new->starts[(j-1)*2] = dsp->starts[(i+1)*2] + offset; */
2497 /* else */
2498 /* dsp_new->starts[(j-1)*2] = dsp->starts[(i+1)*2]; */
2499 dsp_new->starts[(j-1)*2+1] = dsp->starts[(i+1)*2+1];
2500 dsp_new->strands[(j-1)*2+1] = dsp->strands[(i+1)*2+1];
2501 }
2502 dsp_new->lens[j-1] = dsp->lens[i+1] + dsp->lens[i] + dsp->lens[i-1];
2503
2504 i++;
2505 gap_filled = TRUE;
2506 }
2507
2508 }
2509 sap->segs = (Pointer)dsp_new;
2510 DenseSegFree(dsp);
2511 SAIndexFree(sap->saip);
2512 sap->saip = NULL;
2513 AlnMgr2IndexSingleChildSeqAlign(sap);
2514
2515 }
2516
2517 static void Ing_DeleteInsertInGenomic(SeqAlignPtr sap, Int4 gmis)
2518 {
2519 DenseSegPtr dsp_new = NULL, dsp = NULL;
2520 Int4 i, j;
2521 Int4 seg_start, seg_stop;
2522 Int2 newsegs = 0, offset = 0;
2523 Boolean found = FALSE;
2524 Boolean gap_filled = FALSE;
2525
2526
2527 dsp = (DenseSegPtr)(sap->segs);
2528
2529 dsp_new = DenseSegNew();
2530 dsp_new->dim = 2;
2531 dsp_new->numseg = dsp->numseg - 2;
2532 dsp_new->ids = dsp->ids;
2533 dsp->ids = NULL;
2534 dsp_new->starts = (Int4Ptr)MemNew((dsp_new->numseg)*2*sizeof(Int4));
2535 dsp_new->lens = (Int4Ptr)MemNew((dsp_new->numseg)*sizeof(Int4));
2536 dsp_new->strands = (Uint1Ptr)MemNew((dsp_new->numseg)*2*sizeof(Uint1));
2537
2538 for (i = 0, j = 0; i < dsp->numseg; i++){
2539
2540 if (dsp->starts[i*2+1] == -1){
2541 seg_start = dsp->starts[i*2];
2542 seg_stop = dsp->starts[i*2] + dsp->lens[i] - 1;
2543 if (seg_start <= gmis && seg_stop >= gmis)
2544 found = TRUE;
2545 else
2546 found = FALSE;
2547 }
2548
2549 if (!found || gap_filled){
2550 if (dsp->starts[i*2] > 0)
2551 dsp_new->starts[j*2] = dsp->starts[i*2] - offset;
2552 else
2553 dsp_new->starts[j*2] = dsp->starts[i*2];
2554 dsp_new->starts[j*2+1] = dsp->starts[i*2+1];
2555 dsp_new->strands[j*2] = dsp->strands[i*2];
2556 dsp_new->strands[j*2+1] = dsp->strands[i*2+1];
2557 dsp_new->lens[j] = dsp->lens[i];
2558 j++;
2559 }
2560 else if (!gap_filled){
2561 /* extend previous segment over the insert */
2562 offset += dsp->lens[i];
2563 if (dsp->strands[i*2+1] == Seq_strand_minus){
2564 dsp_new->starts[(j-1)*2+1] = dsp->starts[(i+1)*2+1];
2565 dsp_new->strands[(j-1)*2+1] = dsp->strands[(i+1)*2+1];
2566 }
2567 dsp_new->lens[j-1] = dsp->lens[i+1] + dsp->lens[i-1];
2568 i++;
2569 gap_filled = TRUE;
2570 }
2571 }
2572 sap->segs = (Pointer)dsp_new;
2573 DenseSegFree(dsp);
2574 SAIndexFree(dsp);
2575 sap->saip = NULL;
2576 AlnMgr2IndexSingleChildSeqAlign(sap);
2577
2578 }
2579
2580 static void Ing_FillGap(SPI_mRNAPtr spidp, SeqIdPtr gsip, SeqIdPtr msip, Int4 gmis, Int4 mmis, Uint1 mstrand, Int4 nleft, Int4 nright, Int4 i, SeqAlignPtr sap_exon, SeqAlignPtr sap_continuous){
2581
2582 Int4 ntotal;
2583
2584 ntotal = nleft + nright + 1;
2585 BioseqInsert(msip, mmis - nleft, mmis + nright, mstrand, gsip, gmis, FALSE, FALSE, FALSE);
2586 spidp->exongaps[i] -= ntotal;
2587 if (spidp->exongaps[i] < 0)
2588 spidp->exongaps[i] = 0;
2589 Ing_ReplaceGapInGenomic(sap_exon, mmis);
2590 Ing_ReplaceGapInGenomic(sap_continuous, mmis);
2591
2592 }
2593
2594 static void Ing_DelInsert(SPI_mRNAPtr spidp, SeqIdPtr gsip, Int4 gmis, Int4 nleft, Int4 nright, Int4 i, SeqAlignPtr sap_exon, SeqAlignPtr sap_continuous)
2595 {
2596 Int4 ntotal;
2597
2598 ntotal = nleft + nright + 1;
2599 BioseqDelete(gsip, gmis - nleft, gmis + nright, TRUE, FALSE);
2600 spidp->exongaps[i] -= ntotal;
2601 if (spidp->exongaps[i] < 0)
2602 spidp->exongaps[i] = 0;
2603 Ing_DeleteInsertInGenomic(sap_exon, gmis);
2604 Ing_DeleteInsertInGenomic(sap_continuous, gmis);
2605
2606 }
2607
2608 extern void Ing_ReplaceAllMismatchedInLocation(IngGenomeViewerPtr igvp, SeqAlignPtr sap, Int4 start, Int4 stop, Boolean All, Boolean fillGaps, Boolean delInserts)
2609 {
2610 SPI_mRNAPtr spidp = NULL;
2611 SPI_ExonProfPtr epp = NULL, epp_cur = NULL;
2612 AMAlignIndex2Ptr amaip = NULL;
2613 SeqIdPtr gsip = NULL, msip = NULL;
2614 Uint1 gstrand, mstrand;
2615 Char str[200] = {""};
2616 Int4 exon_count = 0, j, i, k, m;
2617 Int4 gmis, mmis, nmismatches, nkeep = 0;
2618 Int4 nleft = 0, nright = 0, ntotal = 0;
2619 Int4Ptr mismatches, keep = NULL, tmp;
2620 Boolean always_false = FALSE;
2621 SeqAlignPtr parent = NULL;
2622 SeqAlignPtr sap_exon = NULL, sap_continuous = NULL;
2623
2624 parent = AlnMgr2GetParent(sap);
2625 if (parent == NULL) return;
2626
2627 spidp = Ing_FindSpidpGivenParent((SPI_mRNAPtr)igvp->data, parent, igvp->isExons);
2628 if (!spidp) return;
2629
2630 epp = spidp->epp;
2631
2632 gsip = AlnMgr2GetNthSeqIdPtr(spidp->saps[0], 1);
2633 msip = AlnMgr2GetNthSeqIdPtr(spidp->saps[0], 2);
2634 gstrand = AlnMgr2GetNthStrand(spidp->saps[0], 1);
2635 mstrand = AlnMgr2GetNthStrand(spidp->saps[0], 2);
2636 sap_continuous = (SeqAlignPtr) spidp->continuous->segs;
2637
2638 /* replace only single exon */
2639 if (igvp->isExons == TRUE){
2640 exon_count = 1;
2641 for (j = 0; j< spidp->numexons; j++){
2642 if (spidp->saps[j] == sap)
2643 break;
2644 exon_count++;
2645 }
2646 /* replace mismatch */
2647 epp_cur = Ing_NumMismatches(epp, exon_count, &nmismatches);
2648 if (nmismatches > 0){
2649 sap_exon = spidp->saps[exon_count - 1];
2650 mismatches = epp_cur->mismatches;
2651 for (j = 0; j < nmismatches; j++){
2652 gmis = AlnMgr2MapBioseqToSeqAlign(sap_exon, mismatches[j], 1);
2653 mmis = AlnMgr2MapBioseqToSeqAlign(sap_exon, mismatches[j], 2);
2654
2655 if (gmis == -1) /* gap on genomic */ {
2656 gmis = Ing_get_rightend(sap_exon, mismatches[j], 1, &nleft, &nright);
2657 ntotal = nleft + nright + 1;
2658
2659 if (!All)
2660 if (!Ing_IsinRange(gmis - nleft, gmis + nright, start, stop))
2661 goto keep_exon;
2662
2663 if (fillGaps){
2664 Ing_FillGap(spidp, gsip, msip, gmis, mmis, mstrand, nleft, nright, (exon_count - 1), sap_exon, sap_continuous);
2665 }
2666 else {
2667 goto keep_exon;
2668 }
2669 }
2670 else if (mmis == -1) /* gap on mRNA */ {
2671 Ing_get_rightend(sap_exon, mismatches[j], 2, &nleft, &nright);
2672 ntotal = nleft + nright + 1;
2673 if (!All)
2674 if (!Ing_IsinRange(gmis - nleft, gmis + nright, start, stop))
2675 goto keep_exon;
2676
2677 if (delInserts){
2678 Ing_DelInsert(spidp, gsip, gmis, nleft, nright, (exon_count - 1), sap_exon, sap_continuous);
2679
2680 /* update mismatch coordinates */
2681 for(k = j+1; k < nmismatches; k++)
2682 mismatches[k] -= ntotal;
2683 }
2684 else {
2685 goto keep_exon;
2686 }
2687 }
2688 else {
2689 ntotal = 1;
2690 if (!All)
2691 if (!Ing_IsinRange(gmis, gmis, start, stop)){
2692 ntotal = 1;
2693 goto keep_exon;
2694 }
2695 SeqLocReplace(msip, mmis, mmis, mstrand, gsip, gmis, gmis, gstrand);
2696 }
2697
2698 if (always_false){
2699 keep_exon:
2700
2701 if (keep != NULL){
2702 tmp = (Int4Ptr)MemNew(sizeof(Int4)*(nkeep + ntotal));
2703 for (k = 0; k < nkeep; k++)
2704 tmp[k] = keep[k];
2705 MemFree(keep);
2706 keep = tmp;
2707 }
2708 else {
2709 keep = (Int4Ptr)MemNew(sizeof(Int4)*(nkeep + ntotal));
2710 k = 0;
2711 }
2712 /* add the latest kept mismatches */
2713 for (m = j; k < nkeep + ntotal; k++, m++)
2714 keep[k] = mismatches[m];
2715
2716 nkeep += ntotal;
2717 }
2718
2719 j += (ntotal - 1);
2720 }
2721 MemFree(epp_cur->mismatches);
2722 epp_cur->mismatches = keep;
2723 epp_cur->nummismatches = nkeep;
2724 nkeep = 0;
2725 keep = NULL;
2726 }
2727 }
2728 else {
2729 epp_cur = spidp->epp;
2730 sap_continuous = (SeqAlignPtr)spidp->continuous->segs;
2731 while (epp_cur){
2732 nmismatches = epp_cur->nummismatches;
2733
2734 if (nmismatches > 0){
2735 mismatches = epp_cur->mismatches;
2736 i = epp_cur->exonnum - 1;
2737 sap_exon = spidp->saps[i];
2738 for (j = 0; j < nmismatches; j++){
2739 gmis = AlnMgr2MapBioseqToSeqAlign(sap_exon, mismatches[j], 1);
2740 mmis = AlnMgr2MapBioseqToSeqAlign(sap_exon, mismatches[j], 2);
2741
2742 if (gmis == -1) {
2743 gmis = Ing_get_rightend(sap_exon, mismatches[j], 1, &nleft, &nright);
2744 ntotal = nleft + nright + 1;
2745
2746 if (!All)
2747 if (!Ing_IsinRange(gmis-nleft, gmis+nright, start, stop))
2748 goto keep_continuous;
2749
2750 if (fillGaps){
2751 Ing_FillGap(spidp, gsip, msip, gmis, mmis, mstrand, nleft, nright, i, sap_exon, sap_continuous);
2752 }
2753 else {
2754 goto keep_continuous;
2755 }
2756 }
2757 else if (mmis == -1) {
2758 Ing_get_rightend(sap_exon, mismatches[j], 2, &nleft, &nright);
2759 ntotal = nleft + nright + 1;
2760 if (!All)
2761 if (!Ing_IsinRange(gmis-nleft, gmis+nright, start, stop))
2762 goto keep_continuous;
2763
2764 if (delInserts){
2765 Ing_DelInsert(spidp, gsip, gmis, nleft, nright, i, sap_exon, sap_continuous);
2766
2767 /* update mismatch coordinates */
2768 for (k = j+1; k < nmismatches; k++)
2769 mismatches[k] -= ntotal;
2770 }
2771 else {
2772 goto keep_continuous;
2773 }
2774 }
2775 else {
2776 ntotal = 1;
2777 if (!All)
2778 if (!Ing_IsinRange(gmis, gmis, start, stop)){
2779 goto keep_continuous;
2780 }
2781 SeqLocReplace(msip, mmis, mmis, mstrand, gsip, gmis, gmis, gstrand);
2782 }
2783
2784 if (always_false){
2785 keep_continuous:
2786
2787 if (keep != NULL){
2788 tmp = (Int4Ptr)MemNew(sizeof(Int4)*nkeep + ntotal);
2789 for (k = 0; k < nkeep; k++)
2790 tmp[k] = keep[k];
2791 MemFree(keep);
2792 keep = tmp;
2793 }
2794 else {
2795 keep = (Int4Ptr)MemNew(sizeof(Int4)*(nkeep + ntotal));
2796 k = 0;
2797 }
2798 /* add the latest kept mismatches */
2799 for (m = j; k < nkeep + ntotal; k++, m++)
2800 keep[k] = mismatches[m];
2801
2802 nkeep += ntotal;
2803 }
2804
2805 j += (ntotal-1);
2806 }
2807 MemFree(epp_cur->mismatches);
2808 epp_cur->mismatches = keep;
2809 epp_cur->nummismatches = nkeep;
2810 nkeep = 0;
2811 keep = NULL;
2812 }
2813 epp_cur = epp_cur->next;
2814 }
2815 }
2816
2817 ObjMgrSetDirtyFlag(igvp->entityID, TRUE);
2818 ObjMgrSendMsg(OM_MSG_UPDATE, igvp->entityID, 0, 0);
2819 }
2820
2821 /***************************************************
2822
2823 Function : Report Drawing Functions
2824
2825 Purpose : populate spidey report window
2826
2827 ***************************************************/
2828
2829 static IngReportPtr Ing_ReportNew(void)
2830 {
2831 IngReportPtr Report=NULL;
2832
2833 Report=(IngReportPtr)MemNew(sizeof(IngReport));
2834 /* initialize */
2835 Report->hMain=NULL;
2836 Report->Viewer=NULL;
2837 Report->Picture=NULL;
2838 Report->igvp=NULL;
2839 Report->isPrevSelected=FALSE;
2840 Report->last_segID=0;
2841 Report->vert_positions=NULL;
2842
2843 return Report;
2844 }
2845
2846
2847 #define MIS_NONSENSE 1
2848 #define MIS_SILENT 2
2849 #define MIS_FRAMESHIFT_by_insert 3 /* gap on mRNA sequence */
2850 #define MIS_FRAMESHIFT_by_delete 4 /* gap on genomic sequence */
2851 #define MIS_MISSENSE 5
2852 #define MIS_START 6 /* mismatch at start */
2853 #define MIS_STOP 7 /* mismatch at start */
2854 #define MIS_GREYZONE 8 /* downstream of frameshift mut */
2855 #define MIS_BLUEZONE 9 /* downstream of extended cds */
2856 #define MIS_BROWNZONE 10 /* downstream of nonsense mut */
2857 #define MIS_NOTINCDS 11
2858 #define MIS_NOTINCDS_genomic 12 /* gap in mRNA sequence in non-coding region */
2859 #define MIS_DELETE 13 /* gap on mrna sequence */
2860 #define MIS_INSERT 14 /* insert on mrna sequence */
2861 #define MIS_ISNOTAMIS 15
2862
2863 typedef struct ing_mislist {
2864 Int4 mism_pos;
2865 Uint1 mismtype;
2866 Char from_c;
2867 Char to_c;
2868 } IngMisList, PNTR IngMisListPtr;
2869
2870
2871 typedef struct ing_explore{
2872 Int4 cds_count;
2873 SeqAlignPtr sap;
2874 BioseqPtr bsp_gen, bsp_mrna;
2875 Int4Ptr mismatches;
2876 Int4 nmismatches;
2877 IngMisListPtr PNTR mismlist;
2878 Int4 grey_zone;
2879 Int4 blue_zone;
2880 Int4 brown_zone;
2881 } IngExplore;
2882
2883
2884 static IngMisListPtr PNTR Ing_MisListNew(Int4 nmismatches)
2885 {
2886 IngMisListPtr PNTR mislist;
2887 Int4 i;
2888
2889 mislist = (IngMisListPtr PNTR)MemNew(sizeof(IngMisListPtr) * nmismatches);
2890 for (i = 0; i<nmismatches; i++)
2891 mislist[i] = (IngMisListPtr)MemNew(sizeof(IngMisList));
2892
2893 return mislist;
2894 }
2895
2896 static IngMisListPtr PNTR Ing_MisListFree(IngMisListPtr PNTR mislist, Int4 nmismatches)
2897 {
2898 Int4 i;
2899
2900 for (i = 0; i<nmismatches; i++)
2901 MemFree(mislist[i]);
2902
2903 return MemFree(mislist);
2904 }
2905
2906 static Boolean Ing_is_frameshift(Int4Ptr mismatches, Int4 nmismatches, Int4 index, SeqAlignPtr sap, Int4 row)
2907 {
2908 Int4 mm, mm_orig;
2909 Int4 gm, gm_orig;
2910 Int4 i;
2911 Int4 gap_count = 1;
2912
2913 if (row == 1){
2914 mm_orig = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[index], 2);
2915 i = index - 1;
2916 while (i >= 0){
2917 gm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[i], 1);
2918 if (gm == -1){
2919 mm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[i], 2);
2920 if (ABS(mm - mm_orig) == 1)
2921 gap_count++;
2922 else
2923 break;
2924 }
2925 else
2926 break;
2927 i--;
2928 }
2929 i = index + 1;
2930 while (i < nmismatches){
2931 gm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[i], 1);
2932 if (gm == -1){
2933 mm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[i], 2);
2934 if (ABS(mm - mm_orig) == 1)
2935 gap_count++;
2936 else
2937 break;
2938 }
2939 else
2940 break;
2941 i++;
2942 }
2943 }
2944 else {
2945 gm_orig = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[index], 1);
2946 i = 0;
2947 while (i >= 0){
2948 mm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[index] - i, 2);
2949 if (mm == -1){
2950 gm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[index] - i, 1);
2951 if (ABS(gm - gm_orig) == 1)
2952 gap_count++;
2953 else
2954 break;
2955 }
2956 else
2957 break;
2958 i--;
2959 }
2960 i = 0;
2961 while (i < nmismatches){
2962 mm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[index] + i, 2);
2963 if (mm == -1){
2964 gm = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[index] + i, 1);
2965 if (ABS(gm - gm_orig) == 1)
2966 gap_count++;
2967 else
2968 break;
2969 }
2970 else
2971 break;
2972 i++;
2973 }
2974 }
2975
2976 if ((Boolean)(gap_count % 3))
2977 return TRUE; /* is frameshift */
2978 else
2979 return FALSE; /* gap is multiple of 3 */
2980 }
2981
2982 static Boolean Ing_range(SeqAlignPtr sap, Int4 mismatch, Int4 row)
2983 {
2984 Int4 pos;
2985 Int4 start, stop;
2986
2987 AlnMgr2GetNthSeqRangeInSA(sap, row, &start, &stop);
2988 pos = AlnMgr2MapBioseqToSeqAlign(sap, mismatch, row);
2989 if (pos >= start && pos <= stop)
2990 return TRUE;
2991 else
2992 return FALSE;
2993 }
2994
2995 static Int4 Ing_get_nearest(SeqAlignPtr sap, Int4 mismatch)
2996 {
2997 Int4 mm;
2998 Int4 i = 1;
2999
3000 while (Ing_range(sap, mismatch - i, 2) || Ing_range(sap, mismatch + i, 2)){
3001 mm = AlnMgr2MapBioseqToSeqAlign(sap, mismatch - i, 2);
3002 if (mm != -1)
3003 return mm;
3004 else {
3005 mm = AlnMgr2MapBioseqToSeqAlign(sap, mismatch + i, 2);
3006 if (mm != -1)
3007 return mm;
3008 }
3009 i++;
3010 }
3011 return 0;
3012 }
3013
3014 static Boolean LIBCALLBACK Ing_MismatchProc(SeqFeatPtr sfp, SeqMgrFeatContextPtr context)
3015 {
3016 IngExplore *iep;
3017 Int4Ptr mismatches = NULL;
3018 Int4Ptr ivals = NULL;
3019 Int4 mmis, gmis, mm;
3020 Int4 mstart, gstart;
3021 Int4 start, stop;
3022 Int4 i, j, k, pos;
3023 Int4 L1, L2, L3, R1, R2, R3;
3024 Int4 nmismatches;
3025 SeqIdPtr sip = NULL;
3026 BioseqPtr bsp_mrna = NULL, bsp_gen = NULL;
3027 SeqPortPtr spp_mrna = NULL, spp_gen = NULL;
3028 Uint1 gcodon[3], mcodon[3], aa_gen, aa_mrna;
3029 Uint1 strand;
3030 SeqAlignPtr sap = NULL;
3031 Boolean InRange = FALSE, AreSame = TRUE;
3032 CharPtr gcd, gcdi;
3033 GeneticCodePtr gcp;
3034 ValNodePtr vnp;
3035
3036
3037 if (context->featdeftype==FEATDEF_CDS){
3038 iep=(IngExplore *)context->userdata;
3039 iep->cds_count++;
3040 sap = iep->sap;
3041 nmismatches = iep->nmismatches;
3042 mismatches = iep->mismatches;
3043 strand = AlnMgr2GetNthStrand(sap, 2);
3044
3045 for (i = 0; i < nmismatches; i++){
3046 gmis = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[i], 1);
3047 mmis = AlnMgr2MapBioseqToSeqAlign(sap, mismatches[i], 2);
3048
3049 /* out of range */
3050 if (mmis != -1)
3051 mm = mmis;
3052 else
3053 mm = Ing_get_nearest(sap, mismatches[i]);
3054
3055 if (context->numivals == 1){
3056 if (mm > context->left && mm < context->right) {
3057 InRange = TRUE;
3058 }
3059 }
3060 else {
3061 ivals = context->ivals;
3062 for (k = 0; k < (context->numivals*2); k += 2){
3063 if (mmis > ivals[k] && mmis < ivals[k+1])
3064 InRange = TRUE;
3065 }
3066 }
3067 if (!InRange) {
3068 if (mmis != -1){
3069 iep->mismlist[i]->mism_pos = mmis;
3070 iep->mismlist[i]->mismtype = MIS_NOTINCDS;
3071 }
3072 else {
3073 iep->mismlist[i]->mism_pos = gmis;
3074 iep->mismlist[i]->mismtype = MIS_NOTINCDS_genomic;
3075 }
3076 continue;
3077 }
3078
3079 /* gap on mRNA sequence */
3080 if (mmis == -1){
3081 if (Ing_is_frameshift(mismatches, nmismatches, i, sap, 2)){
3082 iep->mismlist[i]->mism_pos = gmis;
3083 iep->mismlist[i]->mismtype = MIS_FRAMESHIFT_by_insert;
3084 continue;
3085 }
3086 else {
3087 iep->mismlist[i]->mism_pos = gmis;
3088 iep->mismlist[i]->mismtype = MIS_INSERT;
3089 continue;
3090 }
3091 }
3092 /* gap on genomic sequence */
3093 if (gmis == -1){
3094 if (Ing_is_frameshift(mismatches, nmismatches, i, sap,1)){
3095 iep->mismlist[i]->mism_pos = mmis;
3096 iep->mismlist[i]->mismtype = MIS_FRAMESHIFT_by_delete;
3097 continue;
3098 }
3099 else {
3100 iep->mismlist[i]->mism_pos = mmis;
3101 iep->mismlist[i]->mismtype = MIS_DELETE;
3102 continue;
3103 }
3104 }
3105
3106 /* downstream of frameshift */
3107 if (iep->grey_zone == iep->cds_count) {
3108 iep->mismlist[i]->mism_pos = mmis;
3109 iep->mismlist[i]->mismtype = MIS_GREYZONE;
3110 continue;
3111 }
3112 /* downstream of extension */
3113 if (iep->blue_zone == iep->cds_count) {
3114 iep->mismlist[i]->mism_pos = mmis;
3115 iep->mismlist[i]->mismtype = MIS_BLUEZONE;
3116 continue;
3117 }
3118 /* downstream of nonsense */
3119 if (iep->brown_zone == iep->cds_count) {
3120 iep->mismlist[i]->mism_pos = mmis;
3121 iep->mismlist[i]->mismtype = MIS_BROWNZONE;
3122 continue;
3123 }
3124
3125 bsp_mrna = iep->bsp_mrna;
3126 bsp_gen = iep->bsp_gen;
3127
3128 pos = mmis - context->left;
3129 if ((pos % 3) == 1) {
3130 mstart = mmis - 1;
3131 gstart = (strand == Seq_strand_minus)?gmis + 1 : gmis - 1;
3132 }
3133 else if ((pos % 3) == 2) {
3134 mstart = mmis - 2;
3135 gstart = (strand == Seq_strand_minus)?gmis + 2 : gmis - 2;
3136 }
3137 else if (!(Boolean)(pos % 3)) {
3138 mstart = mmis;
3139 gstart = gmis;
3140 }
3141 L1 = context->left;
3142 L2 = context->left + 1;
3143 L3 = context->left + 2;
3144 R1 = context->right;
3145 R2 = context->right-1;
3146 R3 = context->right-2;
3147
3148 /* get genetic code */
3149 gcp = GeneticCodeFind (1, NULL);
3150 if (gcp == NULL)
3151 return FALSE;
3152 gcd = gcdi = NULL;
3153 vnp = (ValNodePtr) gcp->data.ptrvalue;
3154 while (vnp != NULL){
3155 if (vnp->choice == 6) /* sncbieaa */
3156 gcdi = (CharPtr) vnp->data.ptrvalue;
3157 else if (vnp->choice == 3) /* ncbieaa */
3158 gcd = (CharPtr) vnp->data.ptrvalue;
3159 vnp = vnp->next;
3160 }
3161
3162 if (gcd == NULL){
3163 ErrPostEx (SEV_ERROR, 0, 105, "Could not get genetic code for translation");
3164 ErrShow ();
3165 return FALSE;
3166 }
3167
3168 AlnMgr2GetNthSeqRangeInSA(sap, 1, &start, &stop);
3169 if (strand == Seq_strand_minus)
3170 gstart = start + (stop - gstart);
3171
3172 spp_gen = SeqPortNew(bsp_gen, start, stop, strand, Seq_code_ncbi4na);
3173 SeqPortSeek(spp_gen, gstart-start, SEEK_SET);
3174 gcodon[0] = SeqPortGetResidue(spp_gen);
3175 gcodon[1] = SeqPortGetResidue(spp_gen);
3176 gcodon[2] = SeqPortGetResidue(spp_gen);
3177 aa_gen = AAForCodon(gcodon, gcd);
3178
3179 AlnMgr2GetNthSeqRangeInSA(sap, 2, &start, &stop);
3180 spp_mrna = SeqPortNew(bsp_mrna, start, stop, Seq_strand_plus, Seq_code_ncbi4na);
3181 SeqPortSeek(spp_mrna, mstart-start, SEEK_SET);
3182 mcodon[0] = SeqPortGetResidue(spp_mrna);
3183 mcodon[1] = SeqPortGetResidue(spp_mrna);
3184 mcodon[2] = SeqPortGetResidue(spp_mrna);
3185 aa_mrna = AAForCodon(mcodon, gcd);
3186
3187 for (j = 0; j < 3; j++)
3188 if (gcodon[j] != mcodon[j])
3189 AreSame = FALSE;
3190
3191 if (AreSame){
3192 iep->mismlist[i]->mism_pos = mmis;
3193 iep->mismlist[i]->mismtype = MIS_ISNOTAMIS;
3194 continue;
3195 }
3196 /* mismatch in start */
3197 if (mstart == L1 || mstart == L2 ||
3198 mstart == L3){
3199 if (aa_gen != 'M') {
3200 iep->mismlist[i]->mism_pos = mmis;
3201 iep->mismlist[i]->mismtype = MIS_START;
3202 iep->grey_zone = iep->cds_count;
3203 continue;
3204 }
3205 } /* mismatch in stop */
3206 else if (mstart == R1 || mstart == R2 || mstart == R3){
3207 if (aa_gen != '*'){
3208 iep->mismlist[i]->mism_pos = mmis;
3209 iep->mismlist[i]->mismtype = MIS_STOP;
3210 iep->blue_zone = iep->cds_count;
3211 continue;
3212 }
3213 }
3214 /* nonsense mismatch */
3215 if (aa_gen == '*') {
3216 iep->mismlist[i]->mism_pos = mmis;
3217 iep->mismlist[i]->mismtype = MIS_NONSENSE;
3218 iep->brown_zone = iep->cds_count;
3219 continue;
3220 }
3221
3222 /* missense */
3223 if (aa_gen != aa_mrna) {
3224 iep->mismlist[i]->mism_pos = mmis;
3225 iep->mismlist[i]->mismtype = MIS_MISSENSE;
3226 iep->mismlist[i]->from_c = (Char) aa_mrna;
3227 iep->mismlist[i]->to_c = (Char) aa_gen;
3228 }
3229 else { /* silent */
3230 iep->mismlist[i]->mism_pos = mmis;
3231 iep->mismlist[i]->mismtype = MIS_SILENT;
3232 }
3233 SeqPortFree(spp_mrna);
3234 SeqPortFree(spp_gen);
3235 }
3236 }
3237 return TRUE;
3238 }
3239
3240 static IngMisListPtr PNTR Ing_FillMismatchTypes(Int4Ptr mismatches, Int4 nmismatches, SeqAlignPtr sap, BioseqPtr bsp_mrna)
3241 {
3242 IngExplore iep;
3243 Boolean filter[FEATDEF_MAX];
3244
3245 iep.mismatches = mismatches;
3246 iep.nmismatches = nmismatches;
3247 iep.sap = sap;
3248 iep.grey_zone = 0;
3249 iep.blue_zone = 0;
3250 iep.brown_zone = 0;
3251 iep.cds_count = 0;
3252 iep.bsp_mrna = bsp_mrna;
3253 iep.bsp_gen = BioseqLockById(AlnMgr2GetNthSeqIdPtr(sap, 1));
3254 iep.mismlist = Ing_MisListNew(nmismatches);
3255
3256 /* only go through cds features */
3257 MemSet((Pointer)filter, FALSE, sizeof(filter));
3258 filter[FEATDEF_CDS] = TRUE;
3259 SeqMgrExploreFeatures(bsp_mrna, (Pointer)&iep, Ing_MismatchProc, NULL, NULL, NULL);
3260
3261 return (iep.mismlist);
3262 }
3263
3264 typedef struct ing_reportprg{
3265 CharPtr line;
3266 Boolean newline;
3267 struct ing_reportprg PNTR next;
3268 } IngReportPrg, PNTR IngReportPrgPtr;
3269
3270 static Int4 Ing_Print(SegmenT seg, Int4 row, Int4 nlines, Int4 nchars, CharPtr tmpstr, Uint2 primID)
3271 {
3272 CharPtr ch=NULL, end=NULL;
3273 CharPtr temp=NULL;
3274 Int4 i;
3275 Int4 strlen=0, leftover;
3276 Int4 lastPos=0;
3277
3278 strlen=StringLen(tmpstr);
3279 for (i=0; i<nlines; i++){
3280 temp=StringSave(tmpstr);
3281 ch=temp+(i*nchars);
3282 leftover=strlen-(i*nchars);
3283 if (leftover<nchars)
3284 nchars=leftover;
3285 end=ch+nchars;
3286 *end='\0';
3287 AddLabel(seg, 0, row*(-15), ch, SMALL_TEXT, 0, UPPER_RIGHT, primID);
3288 row++;
3289 if (i==nlines-1)
3290 lastPos=StringWidth(ch);
3291 MemFree(temp);
3292 }
3293
3294 return lastPos;
3295 }
3296 static void Ing_DrawShortLine(SegmenT seg, Int4 row, Int4 nchars)
3297 {
3298 CharPtr temp;
3299
3300 temp=StringSave(" ........................");
3301 Ing_Print(seg, row, 1, nchars, temp, 0);
3302 MemFree(temp);
3303 }
3304
3305 static void Ing_DrawLongLine(SegmenT seg, Int4 row, Int4 nchars)
3306 {
3307 CharPtr temp;
3308
3309 temp=StringSave("---------------------------------------------------------------------------------------------------------------------------------------");
3310 Ing_Print(seg, row, 1, nchars, temp, 0);
3311 MemFree(temp);
3312 }
3313
3314
3315 static Uint1Ptr Ing_MakeColor(Uint1 r, Uint1 g, Uint1 b){
3316 Uint1Ptr clr;
3317
3318 clr = (Uint1Ptr)MemNew(sizeof(Uint1)*3);
3319 clr[0]=r;
3320 clr[1]=g;
3321 clr[2]=b;
3322 return (clr);
3323 }
3324
3325 extern Int4 Ing_PrintText(CharPtr str, SegmenT seg, Int4 row, Int4 winsize, Uint1Ptr clr, Uint2 primID)
3326 {
3327 CharPtr temp = NULL;
3328 Int4 swidth, slen;
3329 Int2 nlines, nchars, cxChar;
3330
3331 AddAttribute(seg, COLOR_ATT, clr, 0, 0, 0, 0);
3332 temp=StringSave(str);
3333 swidth = StringWidth(temp);
3334 slen = StringLen(temp);
3335 cxChar = (Int2) ceil((float)swidth/slen);
3336 nchars = (Int2)((float)winsize/cxChar);
3337
3338 nlines = (Int2)ceil((float)swidth/winsize);
3339 Ing_Print(seg, row, nlines, nchars, temp, primID);
3340 MemFree(temp);
3341
3342 return nlines;
3343 }
3344
3345
3346 static void Ing_PrintColorCode(void)
3347 {
3348 Int4 row = 0;
3349 SegmenT seg;
3350 VieweR v;
3351 WindoW w;
3352 Uint1Ptr purple, red, lime, cyan, blue, dkblue;
3353 Uint1Ptr ltgrey, brown, curry, green, dkgreen;
3354
3355 /* create colors */
3356 purple = Ing_MakeColor(163, 52, 190);
3357 red = Ing_MakeColor(224, 0, 60);
3358 lime = Ing_MakeColor(224,224,0);
3359 cyan = Ing_MakeColor(0, 235, 245);
3360 ltgrey = Ing_MakeColor(127, 127, 127);
3361 brown = Ing_MakeColor(200,95,39);
3362 curry = Ing_MakeColor(210, 154, 14);
3363 green = Ing_MakeColor(0,200, 12);
3364 dkgreen = Ing_MakeColor(0,94, 0);
3365 blue = Ing_MakeColor(0, 125, 245);
3366 dkblue = Ing_MakeColor(0, 64, 194);
3367
3368 w = FixedWindow(-50, -90, -10, -10, "Mismatch Color Codes", StdCloseWindowProc);
3369 v=CreateViewer(w, 350, 300, FALSE, FALSE);
3370 seg=CreatePicture();
3371
3372 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3373 AddLabel(seg, 0, row*(-15), " -- Mismatch is in Coding Region -- ", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3374 row++;
3375
3376 AddAttribute(seg, COLOR_ATT, curry, 0, 0, 0, 0);
3377 AddLabel(seg, 0, row*(-15), "curry -- silent", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3378 row++;
3379
3380 AddAttribute(seg, COLOR_ATT, purple, 0, 0, 0, 0);
3381 AddLabel(seg, 0, row*(-15), "purple -- nonsense", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3382 row++;
3383
3384 AddAttribute(seg, COLOR_ATT, red, 0, 0, 0, 0);
3385 AddLabel(seg, 0, row*(-15), "red -- frame shift, gap on mRNA", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3386 row++;
3387
3388 AddAttribute(seg, COLOR_ATT, dkblue, 0, 0, 0, 0);
3389 AddLabel(seg, 0, row*(-15), "dkblue -- frame shift, gap on genomic", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3390 row++;
3391
3392 AddAttribute(seg, COLOR_ATT, lime, 0, 0, 0, 0);
3393 AddLabel(seg, 0, row*(-15),"yellow -- missense in start codon" , SMALL_TEXT, 0, UPPER_RIGHT, 0);
3394 row++;
3395
3396 AddAttribute(seg, COLOR_ATT, GREEN_COLOR, 0, 0, 0, 0);
3397 AddLabel(seg, 0, row*(-15),"bright green -- missense in stop codon" , SMALL_TEXT, 0, UPPER_RIGHT, 0);
3398 row++;
3399
3400 AddAttribute(seg, COLOR_ATT, cyan, 0, 0, 0, 0);
3401 AddLabel(seg, 0, row*(-15),"cyan -- missense" , SMALL_TEXT, 0, UPPER_RIGHT, 0);
3402 row++;
3403
3404 AddAttribute(seg, COLOR_ATT, MAGENTA_COLOR, 0, 0, 0, 0);
3405 AddLabel(seg, 0, row*(-15),"pink -- insertion on genomic (in genomic coords)" , SMALL_TEXT, 0, UPPER_RIGHT, 0);
3406 row++;
3407
3408 AddAttribute(seg, COLOR_ATT, green, 0, 0, 0, 0);
3409 AddLabel(seg, 0, row*(-15), "green -- deletion on genomic", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3410 row++;
3411
3412 AddAttribute(seg, COLOR_ATT, ltgrey, 0, 0, 0, 0);
3413 AddLabel(seg, 0, row*(-15), "grey -- downstream of frameshift mutation", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3414 row++;
3415
3416 AddAttribute(seg, COLOR_ATT, blue, 0, 0, 0, 0);
3417 AddLabel(seg, 0, row*(-15), "ltblue -- downstream of missense in stop", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3418 row++;
3419
3420 AddAttribute(seg, COLOR_ATT, brown, 0, 0, 0, 0);
3421 AddLabel(seg, 0, row*(-15), "brown -- downstream of nonsense mutation", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3422 row+=2;
3423
3424 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3425 AddLabel(seg, 0, row*(-15), " -- Mismatch is NOT in Coding Region -- ", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3426 row++;
3427
3428 AddAttribute(seg, COLOR_ATT, dkgreen, 0, 0, 0, 0);
3429 AddLabel(seg, 0, row*(-15), "[dkgreen] -- gap on mRNA (in genomic coords)", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3430 row++;
3431
3432 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3433 AddLabel(seg, 0, row*(-15), "black -- default", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3434 row++;
3435
3436
3437 AttachPicture (v, seg, INT4_MIN, INT4_MAX, UPPER_RIGHT, 1 , 1, NULL);
3438
3439 Show(w);
3440 /* free colors */
3441 MemFree(purple);
3442 MemFree(red);
3443 MemFree(lime);
3444 MemFree(cyan);
3445 MemFree(ltgrey);
3446 MemFree(blue);
3447 MemFree(brown);
3448 MemFree(curry);
3449 MemFree(green);
3450 MemFree(dkgreen);
3451 MemFree(dkblue);
3452
3453 }
3454
3455 static Int4 Ing_PrintSpideyReport(IngReportPtr Report, SegmenT seg, SPI_mRNAPtr spidp, BioseqPtr bsp_genomic, Int4 row, Int4 winsize, Int4 nchars, Boolean bSummary)
3456 {
3457 SPI_ExonProfPtr epp=NULL, epp_cur=NULL;
3458 Char tmpstr[500]={""};
3459 Char str4[7][100]={""};
3460 Char strG[25]={""}, strM[25]={""};
3461 CharPtr PNTR str3;
3462 Char defline[255]={""}, idstr[255]={""};
3463 Char mismatch_title[100] ={""};
3464 Char tmp[255]={""};
3465 CharPtr temp=NULL;
3466 Int4 i, j, splicedon=0, c;
3467 Int4 k;
3468 Int4 spliceacc=0;
3469 Int4 strpos;
3470 Int4 nmismatches = 0;
3471 Int4 mmis, gmis, miscount = 0;
3472 Int4 swidth, xstringPos=0;
3473 Int4 len=0;
3474 Int4 top;
3475 Int4Ptr mismatches = NULL;
3476 Uint1 gstrand, mstrand;
3477 Uint1Ptr DkGrey, DkGreen, purple;
3478 Uint1Ptr red, lime, cyan, blue, ltgrey;
3479 Uint1Ptr brown, curry, green, dkgreen, dkblue;
3480 Int2 cxChar=0, slen=0;
3481 Int2 nlines;
3482 SelStructPtr ssp=NULL, tssp=NULL;
3483 BioseqPtr bsp_mrna = NULL;
3484 SeqIdPtr sip = NULL;
3485 IngMisListPtr PNTR mismlist = NULL;
3486 IngMisListPtr mismp = NULL;
3487 enumPrimAddOrder oldOrder;
3488 Boolean bHighlight;
3489
3490 if (!spidp) return row;
3491
3492 ssp=ObjMgrGetSelected();
3493
3494 /* create colors */
3495 DkGrey = Ing_MakeColor(145, 145, 145);
3496 DkGreen = Ing_MakeColor(0, 192, 120);
3497 purple = Ing_MakeColor(163, 52, 190);
3498 red = Ing_MakeColor(224, 0, 60);
3499 lime = Ing_MakeColor(224,224,0);
3500 cyan = Ing_MakeColor(0, 235, 245);
3501 ltgrey = Ing_MakeColor(127, 127, 127);
3502 brown = Ing_MakeColor(200,95,39);
3503 curry = Ing_MakeColor(210, 154, 14);
3504 green = Ing_MakeColor(0,127, 12);
3505 dkgreen = Ing_MakeColor(0, 94, 0);
3506 blue = Ing_MakeColor(0, 125, 245);
3507 dkblue = Ing_MakeColor(0, 64, 194);
3508
3509 sip = AlnMgr2GetNthSeqIdPtr(spidp->saps[0], 2);
3510 bsp_mrna = BioseqLockById(sip);
3511 if (bsp_mrna==NULL) return row;
3512
3513 /* print analysis name */
3514 row++;
3515 MemSet((Pointer)tmpstr, '\0', sizeof(tmpstr));
3516 temp=StringSave("-- Spidey -- ");
3517 swidth=StringWidth(temp);
3518 slen=StringLen(temp);
3519 cxChar = (Int2)ceil((float)swidth/slen);
3520 nlines = (Int2)ceil((float)swidth/winsize);
3521 nchars = (Int2)ceil((float)winsize/cxChar);
3522 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
3523 Ing_Print(seg, row, nlines, nchars, temp, 0);
3524 MemFree(temp);
3525 row+=nlines + 1;
3526
3527 /* print defline */
3528
3529 epp=spidp->epp;
3530 FastaDefLine (bsp_genomic, defline, 200, NULL, NULL, 0);
3531 SeqIdWrite(bsp_genomic->id, idstr, PRINTID_FASTA_LONG, 41);
3532 MemSet((Pointer)tmpstr, '\0', sizeof(tmpstr));
3533 sprintf(tmpstr, "Genomic Sequence: %s ", idstr);
3534 sprintf(tmp, "%s, ", defline);
3535 StringCat(tmpstr, tmp);
3536 sprintf(tmp, "%d bp", bsp_genomic->length);
3537 StringCat(tmpstr, tmp);
3538 swidth=StringWidth(tmpstr);
3539 slen=StringLen(tmpstr);
3540 cxChar = (Int2)ceil((float)swidth/slen);
3541 nlines = (Int2)ceil((float)swidth/winsize);
3542 nchars = (Int2)ceil((float)winsize/cxChar);
3543 AddAttribute(seg, COLOR_ATT, BLUE_COLOR, 0, 0, 0, 0);
3544 temp=StringSave(tmpstr);
3545 Ing_Print(seg, row, nlines, nchars, temp, 0);
3546 MemFree(temp);
3547 row+=nlines;
3548 MemSet((Pointer)tmpstr, '\0', sizeof(tmpstr));
3549 FastaDefLine (bsp_mrna, defline, 200, NULL, NULL, 0);
3550 SeqIdWrite(bsp_mrna->id, idstr, PRINTID_FASTA_LONG, 41);
3551 sprintf(tmpstr, "mRNA Sequence: %s ", idstr);
3552 sprintf(tmp, "%s, ", defline);
3553 StringCat(tmpstr, tmp);
3554 sprintf(tmp, "%d bp", bsp_mrna->length);
3555 StringCat(tmpstr, tmp);
3556 swidth=StringWidth(tmpstr);
3557 nlines= (Int2)ceil((float)swidth/winsize);
3558 AddAttribute(seg, COLOR_ATT, DkGreen, 0, 0, 0, 0);
3559 temp=StringSave(tmpstr);
3560 Ing_Print(seg, row, nlines, nchars, temp, 0);
3561 MemFree(temp);
3562 row+=nlines;
3563 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3564 Ing_DrawShortLine(seg, row, nchars);
3565
3566 /* Print exon information */
3567
3568 if (bSummary){
3569 sprintf(str4[0], "Alignment is on %s strand of mRNA sequence.", (spidp->strand == Seq_strand_minus?"minus":"plus"));
3570 sprintf(tmp, "Number of exons: %d.", spidp->numexons);
3571 StringCat(str4[1], tmp);
3572 sprintf(tmp, (spidp->polyAtail==0?"No PolyA tail.":"Length of PolyA tail: %d. %s"), ABS(spidp->polyAtail), (spidp->polyAtail<0?"PolyA tail does align.":"PolyA tail doesn't align."));
3573 StringCat(str4[2], tmp);
3574
3575 sprintf(tmp, "mRNA coverage: %d%%.", spidp->mRNAcoverage);
3576 StringCat(str4[3], tmp);
3577 sprintf(tmp, "Overall percent identity: %.1f%%.", (FloatHi)(100) - spidp->mismatch);
3578 StringCat(str4[4], tmp);
3579 row++;
3580 for (i=0; i<5; i++){
3581 temp=StringSave(str4[i]);
3582 swidth=StringWidth(temp);
3583 nlines = (Int2)ceil((float)swidth/winsize);
3584 Ing_Print(seg, row, nlines, nchars, temp, 0);
3585 MemFree(temp);
3586 row+=nlines;
3587 }
3588 BioseqUnlock(bsp_mrna);
3589 return row;
3590 }
3591 else {
3592
3593 splicedon = 0;
3594 str3=(CharPtr PNTR)MemNew(sizeof(CharPtr)*(spidp->numexons+1));
3595
3596 /* columns */
3597 str3[0]=(CharPtr)MemNew(sizeof(Char)*255);
3598 sprintf(str3[0], "%-6s %-15s %-15s %-8s %-8s %-5s %-12s %-12s %-12s", "Exon", "Genomic", "mRNA", "length", "id", "Gaps", "Splice Acceptor", "Splice Donor", "Mismatches");
3599 /* content */
3600
3601 for (j=1, i=0; j<spidp->numexons+1; j++, i++)
3602 {
3603 if (spidp->strand == Seq_strand_minus)
3604 c = spidp->numexons - i - 1;
3605 else
3606 c = i;
3607 splicedon += spidp->splicedon[i];
3608 spliceacc += spidp->spliceacc[i];
3609 str3[j]=(CharPtr)MemNew(sizeof(Char)*255);
3610 nmismatches = 0;
3611 len=spidp->mstops[c]-spidp->mstarts[c]+1;
3612 epp_cur=Ing_NumMismatches(epp, c+1, &nmismatches);
3613 sprintf(strG, "%d-%d", spidp->gstarts[c], spidp->gstops[c]);
3614 sprintf(strM, "%d-%d", spidp->mstarts[c], spidp->mstops[c]);
3615 sprintf(str3[j], "%-6d %-15s %-15s %-8d %-2.1f%% %5d %12d %12d %12d", i+1, strG, strM, len, spidp->exonid[c], spidp->exongaps[c], spidp->spliceacc[c], spidp->splicedon[c], nmismatches);
3616 }
3617
3618 gstrand=spidp->strand;
3619 if (spidp->revcomp){
3620 mstrand=Seq_strand_plus;
3621 if (gstrand==Seq_strand_plus)
3622 mstrand=Seq_strand_minus;
3623 }
3624 else
3625 mstrand=gstrand;
3626
3627 sprintf(str4[0], "Alignment is on %s strand of genomic sequence and on %s strand of mRNA sequence", (gstrand==Seq_strand_minus?"minus":"plus"), (mstrand==Seq_strand_minus?"minus":"plus."));
3628 sprintf(tmp, "Number of exons: %d.", spidp->numexons);
3629 StringCat(str4[1], tmp);
3630 sprintf(tmp, "Number of splice donor sites: %d.", splicedon);
3631 StringCat(str4[2], tmp);
3632 sprintf(tmp, "Number of splice acceptor sites: %d.", spliceacc);
3633 StringCat(str4[3], tmp);
3634 sprintf(tmp, (spidp->polyAtail==0?"No PolyA tail.":"Length of PolyA tail: %d. %s"), ABS(spidp->polyAtail), (spidp->polyAtail<0?"PolyA tail does align.":"PolyA tail doesn't align."));
3635 StringCat(str4[4], tmp);
3636
3637 sprintf(tmp, "mRNA coverage: %d%%.", spidp->mRNAcoverage);
3638 StringCat(str4[5], tmp);
3639 sprintf(tmp, "Overall percent identity: %.1f%%.", (FloatHi)(100) - spidp->mismatch);
3640 StringCat(str4[6], tmp);
3641 row++;
3642 for (i=0; i<7; i++){
3643 temp=StringSave(str4[i]);
3644 swidth=StringWidth(temp);
3645 nlines = (Int2)ceil((float)swidth/winsize);
3646 Ing_Print(seg, row, nlines, nchars, temp, 0);
3647 MemFree(temp);
3648 row+=nlines;
3649 }
3650 }
3651
3652 Ing_DrawShortLine(seg, row, nchars);
3653 row++;
3654
3655 /* print mismatch title */
3656 top = row - 1;
3657 oldOrder=ChangeAddPrimOrder(ADD_TO_HEAD);
3658 sprintf(mismatch_title, " Mismatches are shown in mRNA coordinates - double click for color code - ");
3659 row += Ing_PrintText(mismatch_title, seg, row, winsize, WHITE_COLOR, 0);
3660 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
3661 AddRectangle(seg, 0, top*(-15), MIN(StringWidth(mismatch_title)+2, winsize + 5), (row - 1)*(-15), NO_ARROW,TRUE,1);
3662
3663 ChangeAddPrimOrder(oldOrder);
3664 row++;
3665
3666 /* print column headers */
3667 row += Ing_PrintText(str3[0], seg, row, winsize,BLUE_COLOR, 0);
3668 MemFree(str3[0]);
3669
3670 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3671
3672 for (k=1, i=0; k<spidp->numexons+1; k++, i++){
3673
3674 /* print exon information */
3675 swidth=StringWidth(str3[k]);
3676 nlines = (Int2)ceil((float)swidth/winsize);
3677 temp=StringSave(str3[k]);
3678 if (spidp->strand == Seq_strand_minus)
3679 c = spidp->numexons - k;
3680 else
3681 c = i;
3682
3683 /* if exon is selected, print in red */
3684 bHighlight = FALSE;
3685 if (ssp){
3686 tssp=ssp;
3687 while (tssp){
3688 if (tssp->itemID == spidp->saps[c]->idx.itemID){
3689 if (Report->igvp->isExons)
3690 bHighlight = TRUE;
3691 Report->last_segID=(Uint2)SegmentID(seg);
3692 Report->isPrevSelected=TRUE;
3693 }
3694 tssp=tssp->next;
3695 }
3696 }
3697 if (bHighlight == TRUE){
3698 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
3699 }
3700 else{
3701 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3702 }
3703 xstringPos=Ing_Print(seg, row, nlines, nchars, temp, 0);
3704 MemFree(temp);
3705 if (xstringPos==0)
3706 row+=nlines;
3707 else
3708 row+=nlines-1;
3709 nmismatches=0;
3710 epp_cur=Ing_NumMismatches(epp, c+1, &nmismatches);
3711 if (nmismatches>0){
3712 mismatches = epp_cur->mismatches;
3713 mismlist = Ing_FillMismatchTypes(epp_cur->mismatches, nmismatches, spidp->saps[c], bsp_mrna);
3714 row++;
3715 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3716 AddLabel(seg, 0, row*(-15), " Mismatches: ", SMALL_TEXT, 0, UPPER_RIGHT, 0);
3717 xstringPos=StringWidth(" Mismatches: ");
3718
3719 for (j=0; j<nmismatches; j++){
3720 miscount++;
3721 mismp = mismlist[j];
3722 if (mismp->mismtype == MIS_ISNOTAMIS)
3723 continue;
3724 mmis = mismp->mism_pos;
3725 gmis = AlnMgr2MapBioseqToSeqAlign(spidp->saps[c], mismatches[j], 1);
3726
3727 mmis++;
3728 switch (mismp->mismtype) {
3729 case MIS_NONSENSE:
3730 AddAttribute(seg, COLOR_ATT, purple, 0, 0, 0, 0);
3731 break;
3732 case MIS_SILENT:
3733 AddAttribute(seg, COLOR_ATT, curry, 0, 0, 0, 0);
3734 break;
3735 case MIS_FRAMESHIFT_by_insert:
3736 AddAttribute(seg, COLOR_ATT, red, 0, 0, 0, 0);
3737 break;
3738 case MIS_FRAMESHIFT_by_delete:
3739 AddAttribute(seg, COLOR_ATT, dkblue, 0, 0, 0, 0);
3740 break;
3741 case MIS_START:
3742 AddAttribute(seg, COLOR_ATT, lime, 0, 0, 0, 0);
3743 break;
3744 case MIS_STOP:
3745 AddAttribute(seg, COLOR_ATT, GREEN_COLOR, 0, 0, 0, 0);
3746 break;
3747 case MIS_MISSENSE:
3748 AddAttribute(seg, COLOR_ATT, cyan, 0, 0, 0, 0);
3749 break;
3750 case MIS_GREYZONE:
3751 AddAttribute(seg, COLOR_ATT, ltgrey, 0, 0, 0, 0);
3752 break;
3753 case MIS_BLUEZONE:
3754 AddAttribute(seg, COLOR_ATT, blue, 0, 0, 0, 0);
3755 break;
3756 case MIS_BROWNZONE:
3757 AddAttribute(seg, COLOR_ATT, brown, 0, 0, 0, 0);
3758 break;
3759 case MIS_NOTINCDS:
3760 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3761 break;
3762 case MIS_NOTINCDS_genomic:
3763 AddAttribute(seg, COLOR_ATT, dkgreen, 0, 0, 0, 0);
3764 break;
3765 case MIS_INSERT:
3766 AddAttribute(seg, COLOR_ATT, MAGENTA_COLOR, 0, 0, 0, 0);
3767 break;
3768 case MIS_DELETE:
3769 AddAttribute(seg, COLOR_ATT, green, 0, 0, 0, 0);
3770 break;
3771 }
3772
3773 MemSet ((Pointer)tmp, 0, sizeof(tmp));
3774 if (mismp->mismtype == MIS_MISSENSE)
3775 sprintf(tmp, " %d(%c->%c) ", mmis, mismp->from_c, mismp->to_c);
3776 else if (mismp->mismtype == MIS_NOTINCDS_genomic)
3777 sprintf(tmp, " [%d] ", mmis);
3778 else
3779 sprintf(tmp, " %d ", mmis);
3780
3781 /*
3782 MemSet ((Pointer)tmp, 0, sizeof(tmp));
3783 if (mismp->mismtype == MIS_MISSENSE)
3784 sprintf(tmp, " %d(%c->%c) ", gmis, mismp->from_c, mismp->to_c);
3785 else if (mismp->mismtype == MIS_NOTINCDS_genomic)
3786 sprintf(tmp, " [%d] ", gmis);
3787 else
3788 sprintf(tmp, " %d ", gmis);
3789 */
3790 strpos=xstringPos+StringWidth(tmp);
3791 if (strpos>winsize){
3792 row++;
3793 xstringPos=0;
3794 strpos=StringWidth(tmp);
3795 }
3796 AddLabel (seg, xstringPos, row*(-15), tmp, SMALL_TEXT, 0, UPPER_RIGHT, miscount);
3797 xstringPos=strpos;
3798 }
3799 Ing_MisListFree(mismlist, nmismatches);
3800 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3801 }
3802 MemFree(str3[k]);
3803 row+=2;
3804
3805 }
3806
3807 MemFree(str3);
3808 /* free colors */
3809 MemFree(DkGreen);
3810 MemFree(DkGrey);
3811 MemFree(purple);
3812 MemFree(red);
3813 MemFree(lime);
3814 MemFree(cyan);
3815 MemFree(ltgrey);
3816 MemFree(blue);
3817 MemFree(brown);
3818 MemFree(curry);
3819 MemFree(green);
3820 MemFree(dkgreen);
3821 MemFree(dkblue);
3822
3823 BioseqUnlock(bsp_mrna);
3824 return row;
3825 }
3826
3827
3828 static Int4 Ing_PrintBlastReport(IngReportPtr Report, SegmenT seg, SeqAlignPtr sap, BioseqPtr bsp_genomic, Int4 row, Int4 winsize, Int4 nchars, CharPtr name, Boolean bSummary)
3829 {
3830 Int4 num_mismatches = 0, num_gap_opens = 0;
3831 Int4 align_length = 0, num_ident = 0, tot_ident = 0;
3832 FloatHi per_ident;
3833 CharPtr eval_buff, bit_score_buff;
3834 SeqAlignPtr salp = NULL;
3835 Int4 i, j, k;
3836 AMAlignIndex2Ptr amaip = NULL;
3837 BioseqPtr bsp_mrna = NULL;
3838 SeqIdPtr sip = NULL;
3839 Uint1Ptr query_seq, subject_seq;
3840 Uint1 q_strand = 0, s_strand = 0;
3841 Char defline[255]={""}, idstr[255]={""};
3842 Char tmp[255]={""}, tmpstr[500]={""};
3843 CharPtr temp = NULL;
3844 Char contents[4][50]={""};
3845 Int4 swidth;
3846 Int2 cxChar, slen, nlines;
3847 Int4 len;
3848 Int4 from = 0, to = 0;
3849 Uint1 DkGreen[3];
3850 Uint1 DkGray[3];
3851 AlnMsg2Ptr amp1 = NULL;
3852 AlnMsg2Ptr amp2 = NULL;
3853 Boolean more = FALSE;
3854 SelStructPtr ssp = NULL;
3855 SelStructPtr tssp = NULL;
3856
3857
3858 amaip = (AMAlignIndex2Ptr)sap->saip;
3859 ssp = ObjMgrGetSelected();
3860
3861 DkGray[0]=145;
3862 DkGray[1]=145;
3863 DkGray[2]=145;
3864 DkGreen[0]=0;
3865 DkGreen[1]=192;
3866 DkGreen[2]=120;
3867
3868 sip=AlnMgr2GetNthSeqIdPtr(amaip->saps[0], 2);
3869 bsp_mrna=BioseqLockById(sip);
3870 if (bsp_mrna==NULL) return row;
3871
3872 /* print analysis name */
3873 row++;
3874 MemSet((Pointer)tmpstr, '\0', sizeof(tmpstr));
3875 sprintf(tmp, "-- %s -- ", name);
3876 temp=StringSave(tmp);
3877 swidth=StringWidth(temp);
3878 slen=StringLen(temp);
3879 cxChar = (Int2)ceil((float)swidth/slen);
3880 nlines = (Int2)ceil((float)swidth/winsize);
3881 nchars = (Int2)ceil((float)winsize/cxChar);
3882 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
3883 Ing_Print(seg, row, nlines, nchars, temp, 0);
3884 MemFree(temp);
3885 row+=nlines + 1;
3886
3887 /* print deflines */
3888
3889 FastaDefLine (bsp_genomic, defline, 200, NULL, NULL, 0);
3890 SeqIdWrite(bsp_genomic->id, idstr, PRINTID_FASTA_LONG, 41);
3891 MemSet((Pointer)tmpstr, '\0', sizeof(tmpstr));
3892 sprintf(tmpstr, "Genomic Sequence: %s ", idstr);
3893 sprintf(tmp, "%s, ", defline);
3894 StringCat(tmpstr, tmp);
3895 sprintf(tmp, "Length %d (1..%d)", bsp_genomic->length, bsp_mrna->length);
3896 StringCat(tmpstr, tmp);
3897 swidth=StringWidth(tmpstr);
3898 slen=StringLen(tmpstr);
3899 cxChar = (Int2)ceil((float)swidth/slen);
3900 nlines = (Int2)ceil((float)swidth/winsize);
3901 nchars = (Int2)ceil((float)winsize/cxChar);
3902 AddAttribute(seg, COLOR_ATT, BLUE_COLOR, 0, 0, 0, 0);
3903 temp=StringSave(tmpstr);
3904 Ing_Print(seg, row, nlines, nchars, temp, 0);
3905 MemFree(temp);
3906 row+=nlines;
3907 MemSet((Pointer)tmpstr, '\0', sizeof(tmpstr));
3908 FastaDefLine (bsp_mrna, defline, 200, NULL, NULL, 0);
3909 SeqIdWrite(bsp_mrna->id, idstr, PRINTID_FASTA_LONG, 41);
3910 sprintf(tmpstr, "mRNA Sequence: %s ", idstr);
3911 sprintf(tmp, "%s, ", defline);
3912 StringCat(tmpstr, tmp);
3913 sprintf(tmp, "Length %d (1..%d)", bsp_mrna->length, bsp_mrna->length);
3914 StringCat(tmpstr, tmp);
3915 swidth=StringWidth(tmpstr);
3916 nlines = (Int2)ceil((float)swidth/winsize);
3917 AddAttribute(seg, COLOR_ATT, DkGreen, 0, 0, 0, 0);
3918 temp=StringSave(tmpstr);
3919 Ing_Print(seg, row, nlines, nchars, temp, 0);
3920 MemFree(temp);
3921 row+=nlines;
3922 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3923 Ing_DrawShortLine(seg, row, nchars);
3924
3925 /* print blast output */
3926
3927 if (bSummary){
3928 return row;
3929 }
3930 else {
3931 if (!Report->igvp->seqbuf){
3932 query_seq = Ing_FillSeqBuffer(bsp_genomic, NULL, 0, bsp_genomic->length-1);
3933 }
3934 else {
3935 query_seq = Report->igvp->seqbuf;
3936 }
3937
3938 subject_seq = Ing_FillSeqBuffer(bsp_mrna, NULL, 0, bsp_mrna->length-1);
3939 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
3940 for (j = 0; j< amaip->numsaps; j++){
3941 salp = amaip->saps[j];
3942 if (ssp){
3943 tssp=ssp;
3944 while (tssp){
3945 if (tssp->itemID == salp->idx.itemID){
3946 AddAttribute(seg, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
3947 Report->last_segID=(Uint2)SegmentID(seg);
3948 Report->isPrevSelected=TRUE;
3949 }
3950 tssp=tssp->next;
3951 }
3952 }
3953
3954 Ing_DrawShortLine(seg, row, nchars);
3955 row++;
3956
3957 q_strand = AlnMgr2GetNthStrand(salp, 1);
3958 s_strand = AlnMgr2GetNthStrand(salp, 2);
3959 if (q_strand == Seq_strand_minus && s_strand == Seq_strand_minus)
3960 sprintf(contents[3], "Strand = minus / minus");
3961 else if (q_strand == Seq_strand_plus && s_strand == Seq_strand_minus)
3962 sprintf(contents[3], "Strand = plus / minus");
3963 else if (q_strand == Seq_strand_plus && s_strand == Seq_strand_plus)
3964 sprintf(contents[3], "Strand = plus / plus");
3965 else if (q_strand == Seq_strand_minus && s_strand == Seq_strand_plus)
3966 sprintf(contents[3], "Strand = minus / plus");
3967
3968 if (salp->score) {
3969 Ing_GetScoreAndEvalue(salp, &eval_buff, &bit_score_buff);
3970 sprintf(contents[0], "Score = %s Expect = %s", bit_score_buff, eval_buff);
3971 MemFree(bit_score_buff);
3972 MemFree(eval_buff);
3973 }
3974 else
3975 sprintf (contents[0], "score is not available");
3976
3977 amp1 = AlnMsgNew2();
3978 amp2 = AlnMsgNew2();
3979 amp1->from_aln = 0;
3980 amp1->to_aln = -1;
3981 amp1->row_num = 1;
3982 amp2->from_aln = 0;
3983 amp2->to_aln = -1;
3984 amp2->row_num = 2;
3985 i = 1;
3986 while(AlnMgr2GetNextAlnBit(salp, amp1) && AlnMgr2GetNextAlnBit(salp, amp2)){
3987 if (amp2->type == AM_SEQ && amp1->type == AM_SEQ){
3988 len = amp1->to_row - amp1->from_row + 1;
3989 num_ident = BlastGetNumIdentical(query_seq, subject_seq, amp1->from_row, amp2->from_row, len, FALSE);
3990 tot_ident += num_ident;
3991 AlnMgr2GetNthSegmentRange(salp, i, &from, &to);
3992 align_length += (to-from)+1;
3993 num_mismatches += len - num_ident;
3994 }
3995 else
3996 num_gap_opens++;
3997 i++;
3998 }
3999
4000 AlnMsgFree2(amp1);
4001 AlnMsgFree2(amp2);
4002 per_ident = (float)tot_ident / align_length * 100;
4003 sprintf(contents[1], "Identities = %d / %d (%.1f%%)", tot_ident, align_length, per_ident);
4004 sprintf(contents[2], "Mismatches = %d", num_mismatches);
4005 for (k = 0; k<4; k++){
4006 if (k == 2)
4007 continue;
4008 swidth=StringWidth(contents[k]);
4009 nlines = (Int2)ceil((float)swidth/winsize);
4010 temp = StringSave(contents[k]);
4011 Ing_Print(seg, row, nlines, nchars, temp, 0);
4012 MemFree(temp);
4013 row += nlines;
4014 }
4015 tot_ident = 0;
4016 num_mismatches = 0;
4017 AddAttribute(seg, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
4018 }
4019 }
4020
4021 BioseqUnlock(bsp_mrna);
4022
4023 return row;
4024 }
4025
4026
4027
4028 static MsgAnswer Ing_DoReplace(SeqAlignPtr sap, Int4 gm, Int4 mm, Uint1 gstrand, Uint1 mstrand, Int4 mismatch, Int4Ptr nleftp, Int4Ptr nrightp)
4029 {
4030 Char str[200]={""}, str2[200]={""};
4031 SeqPortPtr gspp = NULL, mspp = NULL;
4032 BioseqPtr gbsp, mbsp;
4033 SeqIdPtr gsip, msip;
4034 Int4 gstart, gstop;
4035 Int4 mstart, mstop;
4036 Int4 gmis, mmis, i;
4037 Int4 begin_at, mreal;
4038 Int4 nleft = 0, nright = 0;
4039 Int2 gstart_pos = 0;
4040 Int2 gstop_pos = 0, mstop_pos = 0;
4041 Uint1 strand;
4042 Uint1Ptr gcodon, mcodon;
4043 CharPtr letters[] = {"A", "C", "G", "T", "-"};
4044
4045
4046 AlnMgr2GetNthSeqRangeInSA(sap, 1, &gstart, &gstop);
4047 AlnMgr2GetNthSeqRangeInSA(sap, 2, &mstart, &mstop);
4048 gsip = AlnMgr2GetNthSeqIdPtr(sap, 1);
4049 msip = AlnMgr2GetNthSeqIdPtr(sap, 2);
4050 strand = AlnMgr2GetNthStrand(sap, 2);
4051
4052 gbsp = BioseqLockById(gsip);
4053 mbsp = BioseqLockById(msip);
4054
4055 gspp = SeqPortNew(gbsp, gstart, gstop, Seq_strand_plus, Seq_code_ncbi2na);
4056 mspp = SeqPortNew(mbsp, mstart, mstop, strand, Seq_code_ncbi2na);
4057
4058 if (gm == -1){
4059 gmis = Ing_get_rightend(sap, mismatch, 1, &nleft, &nright);
4060 mstop_pos = nleft + nright + 1;
4061 }
4062 else {
4063 gmis = gm;
4064 mstop_pos = 1;
4065 }
4066
4067 if (mm == -1){
4068 mmis = Ing_get_rightend(sap, mismatch, 2, &nleft, &nright);
4069 gstop_pos = 6 + nleft + nright +1;
4070 }
4071 else {
4072 mmis = mm;
4073 gstop_pos = 7;
4074 }
4075
4076 /* get genomic residues */
4077
4078 begin_at = (gmis - 3) - (gstart);
4079 if (begin_at > 0){
4080 SeqPortSeek(gspp, begin_at, SEEK_SET);
4081 gstart_pos = 0;
4082 }
4083 else {
4084 gstart_pos = (-1)*(begin_at);
4085 }
4086 gcodon = (Uint1Ptr)MemNew(sizeof(Uint1)*gstop_pos);
4087 for (i = gstart_pos; i < gstop_pos; i++){
4088 gcodon[i] = SeqPortGetResidue(gspp);
4089 }
4090
4091 /* get mRNA residues */
4092
4093 if (strand == Seq_strand_minus)
4094 mreal = mstart + (mstop - mmis);
4095 else
4096 mreal = mmis;
4097
4098 SeqPortSeek(mspp, mreal - mstart - nleft, SEEK_SET);
4099 mcodon = (Uint1Ptr)MemNew(sizeof(Uint1)*mstop_pos);
4100 for(i = 0; i < mstop_pos; i++)
4101 mcodon[i] = SeqPortGetResidue(mspp);
4102
4103
4104 if (gm == -1){
4105 sprintf(str, "Replace Gap before pos %d - %s%s%s",
4106 (mmis + nright) + 1, letters[gcodon[0]],
4107 letters[gcodon[1]], letters[gcodon[2]]);
4108
4109 for (i = 0; i < mstop_pos; i++)
4110 StringCat(str, "-");
4111
4112 sprintf(str2, "%s%s%s ---> %s%s%s[",
4113
4114 letters[gcodon[3]], letters[gcodon[4]],
4115 letters[gcodon[5]], letters[gcodon[0]],
4116 letters[gcodon[1]], letters[gcodon[2]]);
4117 StringCat(str, str2);
4118
4119 for (i = 0; i < mstop_pos; i++){
4120 sprintf(str2, "%s", letters[mcodon[i]]);
4121 StringCat(str, str2);
4122 }
4123
4124 sprintf(str2, "]%s%s%s ?",
4125 letters[gcodon[3]], letters[gcodon[4]],
4126 letters[gcodon[5]]);
4127 StringCat(str, str2);
4128
4129 }
4130 else if (mm == -1){
4131 if ((nleft + nright) > 0){
4132 sprintf(str, "Delete Insert between %d-%d - %s%s%s[",
4133 (mmis - nleft) + 1, (mmis + nright) + 1,
4134 letters[gcodon[0]], letters[gcodon[1]],
4135 letters[gcodon[2]]);
4136 }
4137 else {
4138 sprintf(str, "Delete Insert at %d - %s%s%s[",
4139 mmis + 1, letters[gcodon[0]],
4140 letters[gcodon[1]], letters[gcodon[2]]);
4141 }
4142 for (i = 3; i < gstop_pos-3; i++){
4143 sprintf(str2, "%s", letters[gcodon[i]]);
4144 StringCat(str, str2);
4145 }
4146
4147 sprintf(str2,"]%s%s%s ---> %s%s%s%s%s%s ?",
4148 letters[gcodon[gstop_pos-3]], letters[gcodon[gstop_pos-2]],
4149 letters[gcodon[gstop_pos-1]], letters[gcodon[0]],
4150 letters[gcodon[1]], letters[gcodon[2]],
4151 letters[gcodon[gstop_pos-3]], letters[gcodon[gstop_pos-2]],
4152 letters[gcodon[gstop_pos-1]]);
4153 StringCat(str, str2);
4154 }
4155 else {
4156 sprintf(str, "Replace Mismatch at pos %d - %s%s%s[%s]%s%s%s ---> %s%s%s[%s]%s%s%s ?",
4157 mmis + 1, letters[gcodon[0]],
4158 letters[gcodon[1]], letters[gcodon[2]],
4159 letters[gcodon[3]], letters[gcodon[4]],
4160 letters[gcodon[5]], letters[gcodon[6]],
4161 letters[gcodon[0]],
4162 letters[gcodon[1]], letters[gcodon[2]],
4163 letters[mcodon[0]], letters[gcodon[4]],
4164 letters[gcodon[5]], letters[gcodon[6]]);
4165 }
4166
4167
4168 *nleftp = nleft;
4169 *nrightp = nright;
4170
4171 MemFree(gcodon);
4172 MemFree(mcodon);
4173
4174 return (Message (MSG_YN, str));
4175 }
4176
4177 static Boolean Ing_ReplaceByExon(SPI_mRNAPtr spidp, Int4 c, SeqAlignPtr sap_exon, SeqAlignPtr sap_continuous, SPI_ExonProfPtr epp_cur, Int4 nmismatches, Uint2 primID)
4178 {
4179 Int4 miscount = 0, nkeep = 0;
4180 Int4 j, k, m;
4181 Int4 gmis, mmis, mismatch;
4182 Int4 nleft = 0, nright = 0, ntotal = 0;
4183 Int4 offset = 0;
4184 Int4Ptr mismatches, keep;
4185 Uint1 mstrand, gstrand;
4186 SeqIdPtr gsip, msip;
4187 MsgAnswer ans;
4188
4189 gstrand = AlnMgr2GetNthStrand(sap_exon, 1);
4190 mstrand = AlnMgr2GetNthStrand(sap_exon, 2);
4191 gsip = AlnMgr2GetNthSeqIdPtr(sap_exon, 1);
4192 msip = AlnMgr2GetNthSeqIdPtr(sap_exon, 2);
4193
4194 mismatches = epp_cur->mismatches;
4195 for (j=0; j<nmismatches; j++){
4196 miscount++;
4197 if (miscount == primID){
4198 gmis = AlnMgr2MapBioseqToSeqAlign(sap_exon, mismatches[j], 1);
4199 mmis = AlnMgr2MapBioseqToSeqAlign(sap_exon, mismatches[j], 2);
4200 if (gmis == -1){
4201 ans = Ing_DoReplace(sap_exon, gmis, mmis, gstrand, mstrand, mismatches[j], &nleft, &nright);
4202 if (ans == ANS_YES){
4203 gmis = Ing_get_rightend(sap_exon, mismatches[j], 1, &nleft, &nright);
4204 ntotal = nleft + nright + 1;
4205
4206 Ing_FillGap(spidp, gsip, msip, gmis, mmis, mstrand, nleft, nright, c, sap_exon, sap_continuous);
4207
4208 }
4209 }
4210 else if (mmis == -1){
4211 ans = Ing_DoReplace(sap_exon, gmis, mmis, gstrand, mstrand, mismatches[j], &nleft, &nright);
4212 if (ans == ANS_YES){
4213 ntotal = nleft + nright + 1;
4214
4215 Ing_DelInsert(spidp, gsip, gmis, nleft, nright, c, sap_exon, sap_continuous);
4216
4217 /* update mismatch coordinates */
4218 offset = ntotal;
4219 }
4220 }
4221 else {
4222 ans = Ing_DoReplace(sap_exon, gmis, mmis, gstrand, mstrand, mismatches[j], &nleft, &nright);
4223 if (ans == ANS_YES){
4224 SeqLocReplace(msip, mmis, mmis, mstrand, gsip, gmis, gmis, gstrand);
4225 ntotal = 1;
4226 }
4227 }
4228 /* j += (ntotal - 1); */
4229
4230 if (ans == ANS_YES){
4231 nkeep = nmismatches - ntotal;
4232 keep = (Int4Ptr)MemNew(sizeof(Int4)*nkeep);
4233 mismatch = mismatches[j];
4234 for (k = 0, m = 0; k<nmismatches; k++){
4235 if (!(mismatches[k] >= (mismatch - nleft) &&
4236 mismatches[k] <= (mismatch + nright))){
4237 if (mismatches[k] > (mismatch + nright))
4238 keep[m] = mismatches[k] - offset;
4239 else
4240 keep[m] = mismatches[k];
4241 m++;
4242 }
4243 }
4244 if (m != nkeep) /* problem! */
4245 return FALSE;
4246
4247 MemFree(epp_cur->mismatches);
4248 epp_cur->mismatches = keep;
4249 epp_cur->nummismatches = nkeep;
4250 }
4251 return TRUE;
4252 }
4253 }
4254 return FALSE;
4255 }
4256
4257 static void Ing_ReplaceMismatched(IngReportPtr Report, Uint2 segID, Uint2 primID)
4258 {
4259 IngGenomeViewerPtr igvp;
4260 SPI_mRNAPtr spidp;
4261 Int4 i, c;
4262 Int4 nmismatches;
4263 SeqAlignPtr sap_exon = NULL;
4264 SeqAlignPtr sap_continuous = NULL;
4265 SPI_ExonProfPtr epp=NULL, epp_cur=NULL;
4266
4267
4268
4269 igvp = Report->igvp;
4270 spidp = (SPI_mRNAPtr)igvp->data;
4271 /* get to the right spidey alignment */
4272 if (segID > 1){
4273 for (i= 0; i<segID - 1; i++)
4274 spidp = spidp->next;
4275 }
4276
4277 epp = spidp->epp;
4278
4279 sap_continuous = (SeqAlignPtr) spidp->continuous->segs;
4280 for(i=0; i<spidp->numexons; i++){
4281 if (spidp->strand == Seq_strand_minus)
4282 c = spidp->numexons - i - 1;
4283 else
4284 c = i;
4285 sap_exon = spidp->saps[c];
4286 epp_cur=Ing_NumMismatches(epp, c+1, &nmismatches);
4287 if (nmismatches == 0 || epp_cur == NULL)
4288 continue;
4289 if (Ing_ReplaceByExon(spidp, c, sap_exon, sap_continuous, epp_cur, nmismatches, primID)){
4290 ObjMgrSetDirtyFlag(igvp->entityID, TRUE);
4291 ObjMgrSendMsg(OM_MSG_UPDATE, igvp->entityID, 0, 0);
4292 return;
4293 }
4294 primID -= nmismatches;
4295 }
4296
4297 }
4298
4299
4300 static void Ing_ReportClickProc(VieweR v, SegmenT s, PoinT pt)
4301 {
4302 PrimitivE prim = NULL;
4303 Uint2 primID = 0, segID = 0;
4304 IngReportPtr Report = NULL;
4305
4306 Report = (IngReportPtr)GetObjectExtra(ParentWindow(v));
4307
4308 if (FindSegPrim(v, pt, NULL, NULL, &prim)){
4309 FindSegment(v, pt, &segID, &primID, NULL);
4310 if (!primID && dblClick) {
4311 Ing_PrintColorCode();
4312 }
4313 else if (primID && dblClick && segID){
4314 Ing_ReplaceMismatched(Report, segID, primID);
4315 /* Ing_PrintColorCode(); */
4316 }
4317 }
4318 }
4319
4320 extern void Ing_PopulateReport(IngReportPtr Report, IngGenomeViewerPtr igvp)
4321 {
4322 ValNodePtr vnp = NULL;
4323 CharPtr PNTR names = NULL;
4324 CharPtr temp = NULL;
4325 SeqAlignPtr sap = NULL;
4326 SPI_mRNAPtr spidp = NULL;
4327 SPI_mRNAPtr spidp_head = NULL;
4328 SeqIdPtr sip=NULL;
4329 BioseqPtr bsp_genomic=NULL;
4330 Int4 winsize;
4331 RecT rc;
4332 Int4 row=0, margin;
4333 Int4 segID=1;
4334 Int4 i=0;
4335 Int4 index = 0;
4336 SegmenT CurrentSeg;
4337 Int4 nchars;
4338 SelStructPtr ssp=NULL;
4339 Boolean bFirst = TRUE;
4340
4341
4342 WatchCursor();
4343 ssp = ObjMgrGetSelected();
4344
4345 Reset(Report->Viewer);
4346 DeletePicture(Report->Picture);
4347 Update();
4348
4349 Report->Picture=CreatePicture();
4350 margin=3*stdCharWidth;
4351 GetPosition(Report->Viewer, &rc);
4352 winsize=rc.right-rc.left-margin;
4353 SetSmallFont();
4354 nchars=winsize/stdCharWidth;
4355
4356 vnp = igvp->talign.showlist;
4357 while (vnp){
4358 index++;
4359 vnp = vnp->next;
4360 }
4361 vnp = igvp->talign.showlist;
4362 names = igvp->talign.namelist;
4363
4364 if (Report->vert_positions)
4365 MemFree(Report->vert_positions);
4366 Report->vert_positions=(Int4Ptr)MemNew(sizeof(Int4)*index+1);
4367 Report->vert_positions[0]=INT4_MAX;
4368
4369 if (!vnp){
4370 AddAttribute(Report->Picture, COLOR_ATT, RED_COLOR, 0, 0, 0, 0);
4371 AddLabel (Report->Picture, 0, 0, " -- No alignments in data --", SMALL_TEXT, 0, MIDDLE_CENTER, 0);
4372 goto end;
4373 }
4374 AddAttribute(Report->Picture, COLOR_ATT, BLACK_COLOR, 0, 0, 0, 0);
4375
4376 segID=1;
4377 i=0;
4378 if (igvp->data){
4379 spidp_head=(SPI_mRNAPtr)igvp->data;
4380 }
4381 bsp_genomic=GetBioseqGivenIDs (igvp->entityID, igvp->itemID, OBJ_BIOSEQ);
4382
4383 while (vnp){
4384 sap=(SeqAlignPtr)vnp->data.ptrvalue;
4385 if (!sap) goto next;
4386 CurrentSeg=CreateSegment(Report->Picture, segID, 0);
4387 if (row){
4388 Report->vert_positions[i+1]=(row+10)*(-15);
4389 }
4390 else
4391 Report->vert_positions[i]=0;
4392 if (StringCmp(names[i], "Spidey")==0){
4393 if (igvp->isExons)
4394 sap = AlnMgr2GetParent(sap);
4395
4396 spidp = Ing_FindSpidpGivenParent(spidp_head, sap, igvp->isExons);
4397 }
4398 if ((StringCmp(names[i], "Spidey")==0) && spidp != NULL){
4399 if (spidp && !bFirst){
4400 Ing_DrawLongLine(Report->Picture, row, nchars);
4401 row++;
4402 }
4403 else
4404 bFirst = FALSE;
4405 row=Ing_PrintSpideyReport(Report, CurrentSeg, spidp, bsp_genomic, row, winsize, nchars, Report->bSummary);
4406 row++;
4407 i++;
4408 segID++;
4409 spidp = spidp->next;
4410 }
4411 else {
4412 if (sap && !bFirst){
4413 Ing_DrawLongLine(Report->Picture, row, nchars);
4414 row++;
4415 }
4416 else
4417 bFirst = FALSE;
4418 row = Ing_PrintBlastReport(Report, CurrentSeg, sap, bsp_genomic, row, winsize, nchars, names[i], Report->bSummary);
4419 row++;
4420 i++;
4421 segID++;
4422 }
4423 next:
4424 vnp=vnp->next;
4425 }
4426
4427
4428 Ing_DrawLongLine(Report->Picture, row-1, nchars);
4429 end:
4430 AttachPicture (Report->Viewer, Report->Picture, INT4_MIN, Report->vert_positions[Report->last_segID], MIDDLE_CENTER, 1 , 1, NULL);
4431 SetViewerProcs(Report->Viewer,Ing_ReportClickProc,NULL,NULL, NULL);
4432 if (ssp && Report->isPrevSelected && Report->last_segID){
4433 Ing_HighlightReportWindow(Report, FRAME_SEGMENT, Report->last_segID, FALSE);
4434 }
4435 ArrowCursor();
4436 }
4437
4438
4439 /*******************************************************************************
4440
4441 Function : Report window functions
4442
4443 Purpose : create spidey report window
4444
4445 *******************************************************************************/
4446
4447 static void Ing_FreeReport(IngReportPtr r)
4448 {
4449 if (r->Viewer)DeleteViewer(r->Viewer);
4450 if (r->Picture)DeleteSegment(r->Picture);
4451 }
4452
4453 static void Ing_CloseReportWin(WindoW w)
4454 {
4455 IngReportPtr r;
4456
4457 r=GetObjectExtra(w);
4458 r->igvp->hReport=NULL;
4459 if (r) Ing_FreeReport(r);
4460 r=NULL;
4461 Remove(w);
4462 }
4463
4464 static void Ing_CloseReport(IteM i)
4465 {
4466 IngReportPtr r;
4467 WindoW w;
4468
4469 w=ParentWindow(i);
4470 r=GetObjectExtra(w);
4471 r->igvp->hReport=NULL;
4472 if (r) Ing_FreeReport(r);
4473 r=NULL;
4474 Remove(w);
4475 }
4476
4477
4478 static void Ing_ResizeReportWindow(IngReportPtr Report)
4479 {
4480 RecT rcW, rcR, rcVsb, rcHsb;
4481 Int2 height,width,gap,vsbWidth;
4482 Int2 hsbWidth,in;
4483 BaR vsb;
4484 BaR hsb;
4485
4486
4487 if (!Report) return;
4488 ObjectRect(Report->hMain, &rcW);
4489 width= rcW.right-rcW.left;
4490 height= rcW.bottom-rcW.top;
4491 SafeHide(Report->Viewer);
4492 Update();
4493
4494 vsb = GetSlateVScrollBar ((SlatE) Report->Viewer);
4495 hsb = GetSlateHScrollBar ((SlatE) Report->Viewer);
4496 GetPosition(Report->Viewer, &rcR);
4497 GetPosition(vsb, &rcVsb);
4498 GetPosition(vsb, &rcHsb);
4499 vsbWidth=rcVsb.right-rcVsb.left;
4500 hsbWidth=rcHsb.right-rcHsb.left;
4501
4502 gap=10;
4503 in=2;
4504
4505 rcR.right=rcR.left+width-in-vsbWidth;
4506 rcR.bottom=rcR.top+height-in-gap-hsbWidth;
4507 SetPosition(Report->Viewer, &rcR);
4508
4509 Ing_PopulateReport(Report, Report->igvp);
4510
4511 SafeShow(Report->Viewer);
4512 Update();
4513 }
4514
4515 static void Ing_ResizeReportWin(WindoW w)
4516 {
4517 IngReportPtr Report=NULL;
4518
4519
4520 Report=(IngReportPtr)GetObjectExtra(w);
4521 Ing_ResizeReportWindow(Report);
4522 }
4523
4524 static void Ing_Summary(IteM i)
4525 {
4526 IngReportPtr Report;
4527
4528 Report=(IngReportPtr)GetObjectExtra(ParentWindow(i));
4529 if (!Report->bSummary){
4530 Report->bSummary=TRUE;
4531 Ing_PopulateReport(Report, Report->igvp);
4532 }
4533 }
4534
4535 static void Ing_FullReport(IteM i)
4536 {
4537 IngReportPtr Report;
4538
4539 Report=(IngReportPtr)GetObjectExtra(ParentWindow(i));
4540 if (Report->bSummary){
4541 Report->bSummary=FALSE;
4542 Ing_PopulateReport(Report, Report->igvp);
4543 }
4544 }
4545
4546 static void Ing_CreatePostScript(IteM i)
4547 {
4548 }
4549
4550 static void Ing_SaveReport(IteM i)
4551 {
4552 }
4553
4554
4555 extern void Ing_ReportWindow(IteM i)
4556 {
4557 IngGenomeViewerPtr igvp;
4558 WindoW hReport;
4559 IngReportPtr Report;
4560 MenU m1;
4561 Int2 left_margin;
4562 Char str[250]={""};
4563
4564 left_margin=5*stdCharWidth;
4565 igvp=GetObjectExtra(ParentWindow(i));
4566 if (!igvp) return;
4567 if (igvp->hReport){
4568 Select(igvp->hReport);
4569 return;
4570 }
4571 sprintf(str, "%s", "Spidey Report -- ");
4572 StringCat(str, igvp->title);
4573 hReport = DocumentWindow(left_margin,(Int2) -65 ,(Int2) 550, (Int2) 250, str, Ing_CloseReportWin, Ing_ResizeReportWin);
4574 m1 = PulldownMenu (hReport, "File");
4575 CommandItem(m1, "Summary Version", Ing_Summary);
4576 CommandItem(m1, "Full Version", Ing_FullReport);
4577 SeparatorItem(m1);
4578 CommandItem(m1, "Print", Ing_CreatePostScript);
4579 CommandItem(m1, "Save", Ing_SaveReport);
4580 SeparatorItem(m1);
4581 CommandItem(m1, "Close Window", Ing_CloseReport);
4582
4583 Report=Ing_ReportNew();
4584 Report->hMain=hReport;
4585 igvp->hReport=hReport;
4586 Report->igvp=igvp;
4587 Report->Viewer=CreateViewer(hReport, 500 ,200, TRUE, TRUE);
4588 Report->Picture=CreatePicture();
4589 SetObjectExtra(hReport, (Pointer)Report, StdCleanupExtraProc);
4590 RealizeWindow(hReport);
4591 Report->bSummary=FALSE;
4592 Ing_ResizeReportWindow(Report);
4593 Show(hReport);
4594 Update();
4595 }
4596
4597
4598 /*******************************************************************************
4599
4600 Function : Highlight Report window Functions
4601
4602 Purpose : when the main window is clicked, highlight the spidey text output in the report window.
4603
4604 *******************************************************************************/
4605 typedef struct ing_selreport{
4606 VieweR viewer;
4607 Int1 highlight;
4608 Uint2 segID;
4609 } IngSelReport, PNTR IngSelReportPtr;
4610
4611
4612 static Boolean Ing_SelReport(SegmenT seg, PrimitivE prim, Uint2 segID, Uint2 primID, Uint2 primCt, VoidPtr userdata)
4613 {
4614 IngSelReportPtr spp;
4615
4616 spp=(IngSelReportPtr)userdata;
4617
4618 if (spp->segID==segID){
4619 HighlightSegment(spp->viewer, seg, spp->highlight);
4620 return FALSE;
4621 }
4622 return TRUE;
4623
4624 }
4625
4626 static Boolean Ing_DeSelReport(SegmenT seg, PrimitivE prim, Uint2 segID, Uint2 primID, Uint2 primCt, VoidPtr userdata)
4627 {
4628 IngSelReportPtr spp;
4629
4630 spp=(IngSelReportPtr)userdata;
4631 /* deselect all segments in report window */
4632 if (spp->segID==0){
4633 HighlightSegment(spp->viewer, seg, spp->highlight);
4634 }
4635 return TRUE;
4636 }
4637
4638 extern void Ing_HighlightReportWindow(IngReportPtr Report, Int1 highlight, Uint2 segID, Boolean rePopulate)
4639 {
4640 IngSelReport sp;
4641
4642 Report->last_segID=segID;
4643 if (rePopulate)
4644 Ing_PopulateReport(Report, Report->igvp);
4645 else
4646 AttachPicture (Report->Viewer, Report->Picture, INT4_MIN, Report->vert_positions[Report->last_segID], MIDDLE_CENTER, 1 , 1, NULL);
4647 SetViewerProcs(Report->Viewer,Ing_ReportClickProc,NULL,NULL, NULL);
4648
4649 sp.highlight=highlight;
4650 sp.segID=segID;
4651 sp.viewer=Report->Viewer;
4652 if (segID == 0 && highlight == PLAIN_SEGMENT)
4653 ExploreSegment(Report->Picture, (Pointer)&sp, Ing_DeSelReport);
4654 else
4655 ExploreSegment(Report->Picture, (Pointer)&sp, Ing_SelReport);
4656 }
4657
4658
4659 /*******************************************************************************
4660
4661 Function : Spidey Form functions
4662
4663 Purpose : create spidey input form and get mRNA sequences
4664
4665 *******************************************************************************/
4666
4667 extern Boolean Ing_DoesAlignmentCoverAll(Pointer data)
4668 {
4669 SPI_mRNAPtr spidp = NULL;
4670
4671 if (!data) return FALSE;
4672 spidp = (SPI_mRNAPtr) data;
4673 return (spidp->holes);
4674 }
4675
4676
4677 extern void Ing_CreateSpideyForm(IngGenomeViewerPtr igvp, BioseqPtr bsp1, CharPtr path, CharPtr GI_list)
4678 {
4679 IngSpideyFormPtr sfp;
4680 ButtoN b;
4681 ButtoN b1;
4682 GrouP maingroup, submitg;
4683 GrouP g, g2, g3, g4, g5;
4684 GrouP leng;
4685 WindoW w;
4686 Int4 start, stop;
4687 Char lenbuf[40]={""}, szbuf[40]={""};
4688
4689 if (!(sfp = (IngSpideyFormPtr)MemNew(sizeof(IngSpideyForm)))) return;
4690
4691 sfp->bsp1 = bsp1;
4692 if (!StringHasNoText(path)){
4693 sfp->path=StringSave(path);
4694 sfp->GI_list=NULL;
4695 }
4696 else{
4697 sfp->GI_list=StringSave(GI_list);
4698 sfp->path=NULL;
4699 }
4700 w = MovableModalWindow(-50, -33 ,-10, -10, "Spidey", NULL);
4701
4702 maingroup = HiddenGroup(w, 1, 3, NULL);
4703
4704
4705 MemSet((Pointer)lenbuf, '\0', sizeof(lenbuf));
4706 sprintf(lenbuf, "Query. length=%d", bsp1->length);
4707
4708 MemSet((Pointer)szbuf, '\0', sizeof(szbuf));
4709 SeqIdWrite(bsp1->id, szbuf, PRINTID_FASTA_SHORT,40);
4710
4711 leng = NormalGroup(maingroup,1, 2, lenbuf, NULL, NULL);
4712 SetGroupMargins(leng, 10, 10);
4713 SetGroupSpacing(leng, 10, 20);
4714
4715 StaticPrompt(leng, szbuf,0,0,programFont,'l');
4716
4717 g5=HiddenGroup(leng, 4, 1, NULL);
4718 StaticPrompt(g5, "from:", 0, 0, programFont, 'l');
4719 if (igvp->slp){
4720 start = SeqLocStart(igvp->slp);
4721 stop = SeqLocStop(igvp->slp);
4722 }
4723 else {
4724 start = 1;
4725 stop = bsp1->length;
4726 }
4727
4728 sprintf(szbuf, "%d", start);
4729 sfp->from = DialogText(g5, szbuf, 5, (TxtActnProc) NULL);
4730 StaticPrompt(g5, " to:", 0, 0, programFont, 'l');
4731 sprintf(szbuf, "%d", stop);
4732 sfp->to = DialogText(g5, szbuf, 5, (TxtActnProc) NULL);
4733
4734 g=HiddenGroup(maingroup, 1, 4, NULL);
4735 g2 = NormalGroup(g, 1,1, "Spidey Options...", programFont,NULL);
4736 g3=HiddenGroup(g2, 0, 2, NULL);
4737 sfp->inters = CheckBox(g3, "Interspecies", NULL);
4738 SetStatus(sfp->inters, FALSE);
4739
4740 g2 = NormalGroup(g, 1,1, "Organism...", programFont,NULL);
4741 sfp->org = PopupList (g2, TRUE, NULL);
4742 SetObjectExtra (sfp->org, sfp, NULL);
4743 PopupItem (sfp->org, "Vertebrate");
4744 PopupItem (sfp->org, "Fly");
4745 PopupItem (sfp->org, "Plant");
4746 PopupItem (sfp->org, "C. elegans");
4747 SetValue (sfp->org, 1);
4748
4749 g3 = NormalGroup(g, 1,1, "Parameters...", programFont,NULL);
4750 g4 = HiddenGroup(g3, 2, 5, NULL);
4751 StaticPrompt(g4, "Min % identity", 0, 0, programFont, 'l');
4752 sfp->idcutoff = DialogText(g4, "0", 5, NULL);
4753 StaticPrompt(g4, "Min % coverage", 0, 0, programFont, 'l');
4754 sfp->lencutoff = DialogText(g4, "0", 5, NULL);
4755 StaticPrompt(g4, "1st. pass eval", 0, 0, programFont, 'l');
4756 sfp->firstpasseval = DialogText(g4, "0.0000001", 5, NULL);
4757 StaticPrompt(g4, "2nd. pass eval", 0, 0, programFont, 'l');
4758 sfp->secondpasseval = DialogText(g4, "0.001", 5, NULL);
4759 StaticPrompt(g4, "3rd. pass eval", 0, 0, programFont, 'l');
4760 sfp->thirdpasseval = DialogText(g4, "1", 5, NULL);
4761 StaticPrompt(g4, "Num returns", 0, 0, programFont, 'l');
4762 sfp->numreturns = DialogText(g4, "1", 5, NULL);
4763 submitg=HiddenGroup(maingroup, 2, 0, NULL);
4764 b = DefaultButton(submitg, "Accept", Ing_DoSpidey);
4765 Enable(b);
4766 b1 = PushButton(submitg, "Cancel", Ing_StdCancelProc);
4767 SetObjectExtra(b1, (Pointer)sfp, NULL);
4768 SetObjectExtra(b, (Pointer)sfp, StdCleanupExtraProc);
4769 SetObjectExtra(w, (Pointer)igvp, NULL);
4770 Select(w);
4771 Show(w);
4772
4773 return;
4774
4775 }
4776
4777 extern void Ing_GetFileForSpidey(IteM i)
4778 {
4779 IngGenomeViewerPtr igvp;
4780
4781 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(i));
4782 igvp->filetype=Ing_SPIDEY;
4783 Ing_OpenFromFileORNetwork(igvp);
4784
4785 }
4786
4787
4788 /*******************************************************************************
4789
4790 Function : Ing_OpenUDV()
4791
4792 Purpose : Open UDV - sequence viewer
4793
4794 *******************************************************************************/
4795 extern void Ing_OpenUDV(IteM i)
4796 {
4797 ObjMgrPtr omp;
4798 OMProcControl ompc;
4799 ObjMgrProcPtr ompp;
4800 IngGenomeViewerPtr igvp;
4801 Int2 ret;
4802
4803 igvp=(IngGenomeViewerPtr)GetObjectExtra(ParentWindow(i));
4804 if (!igvp) return;
4805
4806 omp = ObjMgrReadLock();
4807 ompp = ObjMgrProcFind(omp, 0, "OneD-Viewer", 0);
4808 ObjMgrUnlock();
4809 WatchCursor();
4810
4811 if (ompp != NULL)
4812 {
4813 ompc.proc = ompp;
4814 ompc.input_entityID = igvp->entityID;
4815 ompc.input_itemtype = OBJ_BIOSEQ;
4816 ompc.input_itemID = igvp->itemID;
4817 ompc.input_data = (Pointer)igvp->bsp;
4818 ret = (*(ompp->func))((Pointer)&ompc);
4819 switch(ret)
4820 {
4821 case OM_MSG_RET_ERROR:
4822 ErrShow();
4823 break;
4824 default:
4825 break;
4826 }
4827 }
4828 ArrowCursor();
4829 return;
4830 }
4831
4832 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |